Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make inspect work without rawget #63

Merged
merged 1 commit into from Jan 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion inspect.lua
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion inspect.tl
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down