Created
January 14, 2015 07:47
-
-
Save xebecnan/1c5bca9b92be6c235790 to your computer and use it in GitHub Desktop.
check if a lua table is an array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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