make inspect work without rawget (#63)

This commit is contained in:
Enrique García Cota 2023-01-22 22:03:37 +01:00 committed by GitHub
parent b738a52e35
commit 8686162bce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -54,6 +54,13 @@ local char = string.char
local gsub = string.gsub
local fmt = string.format
local _rawget
if rawget then
_rawget = rawget
else
_rawget = function(t, k) return t[k] end
end
local function rawpairs(t)
return next, t, nil
end
@ -149,7 +156,7 @@ end
local function getKeys(t)
local seqLen = 1
while rawget(t, seqLen) ~= nil do
while _rawget(t, seqLen) ~= nil do
seqLen = seqLen + 1
end
seqLen = seqLen - 1

View File

@ -54,6 +54,13 @@ local char = string.char
local gsub = string.gsub
local fmt = string.format
local _rawget: function(table, any): any
if rawget then
_rawget = rawget
else
_rawget = function(t: table, k: any): any return t[k] end
end
local function rawpairs(t: table): function, table, nil
return next, t, nil
end
@ -149,7 +156,7 @@ end
local function getKeys(t: table): {any}, integer, integer
-- seqLen counts the "array-like" keys
local seqLen: integer = 1
while rawget(t, seqLen) ~= nil do
while _rawget(t, seqLen) ~= nil do
seqLen = seqLen + 1
end
seqLen = seqLen - 1