Skip to content

Instantly share code, notes, and snippets.

@uga-rosa
Last active October 20, 2021 13:18
Show Gist options
  • Save uga-rosa/9be272f29522deaa826780f4ff806040 to your computer and use it in GitHub Desktop.
Save uga-rosa/9be272f29522deaa826780f4ff806040 to your computer and use it in GitHub Desktop.
Chacks if t is an array
local function tbl_copy(t)
if type(t) ~= "table" then
return t
end
local res = {}
for k, v in pairs(t) do
res[k] = tbl_copy(v)
end
return setmetatable(res, getmetatable(t))
end
local function is_array(t)
local _t = tbl_copy(t)
for i = 1, #t do
if _t[i] == nil then
return false
end
_t[i] = nil
end
if next(_t) then
return false
end
return true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment