From 8686162bce74913c4d3a577e7324642ddc4e21c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrique=20Garc=C3=ADa=20Cota?= Date: Sun, 22 Jan 2023 22:03:37 +0100 Subject: [PATCH] make inspect work without rawget (#63) --- inspect.lua | 9 ++++++++- inspect.tl | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/inspect.lua b/inspect.lua index 400229f..9900a0b 100644 --- a/inspect.lua +++ b/inspect.lua @@ -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 diff --git a/inspect.tl b/inspect.tl index 78b52e1..2229a3b 100644 --- a/inspect.tl +++ b/inspect.tl @@ -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