Skip to content

Instantly share code, notes, and snippets.

@xebecnan
Created January 14, 2015 07:47
Show Gist options
  • Save xebecnan/1c5bca9b92be6c235790 to your computer and use it in GitHub Desktop.
Save xebecnan/1c5bca9b92be6c235790 to your computer and use it in GitHub Desktop.
check if a lua table is an array
local _cache = {}
local function is_array(t)
local count = #t
if count == 0 then
return false
end
for i=1,count do
local v = t[i]
if v == nil then
return false
end
t[i] = nil
_cache[i] = v
end
if next(t) then
return false
end
for i=1,count do
t[i] = _cache[i]
_cache[i] = nil
end
return true
end
return is_array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment