Skip to content

Commit 8686162

Browse files
authored
make inspect work without rawget (#63)
1 parent b738a52 commit 8686162

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

inspect.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ local char = string.char
5454
local gsub = string.gsub
5555
local fmt = string.format
5656

57+
local _rawget
58+
if rawget then
59+
_rawget = rawget
60+
else
61+
_rawget = function(t, k) return t[k] end
62+
end
63+
5764
local function rawpairs(t)
5865
return next, t, nil
5966
end
@@ -149,7 +156,7 @@ end
149156
local function getKeys(t)
150157

151158
local seqLen = 1
152-
while rawget(t, seqLen) ~= nil do
159+
while _rawget(t, seqLen) ~= nil do
153160
seqLen = seqLen + 1
154161
end
155162
seqLen = seqLen - 1

inspect.tl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ local char = string.char
5454
local gsub = string.gsub
5555
local fmt = string.format
5656

57+
local _rawget: function(table, any): any
58+
if rawget then
59+
_rawget = rawget
60+
else
61+
_rawget = function(t: table, k: any): any return t[k] end
62+
end
63+
5764
local function rawpairs(t: table): function, table, nil
5865
return next, t, nil
5966
end
@@ -149,7 +156,7 @@ end
149156
local function getKeys(t: table): {any}, integer, integer
150157
-- seqLen counts the "array-like" keys
151158
local seqLen: integer = 1
152-
while rawget(t, seqLen) ~= nil do
159+
while _rawget(t, seqLen) ~= nil do
153160
seqLen = seqLen + 1
154161
end
155162
seqLen = seqLen - 1

0 commit comments

Comments
 (0)