As the title says, what function or check can I do to find out if a lua element is a table or not?
local elem = {['1'] = test, ['2'] = testtwo}
if (elem is table?) // <== should return true
As the title says, what function or check can I do to find out if a lua element is a table or not?
local elem = {['1'] = test, ['2'] = testtwo}
if (elem is table?) // <== should return true
print(type(elem)) -->table
the type function in Lua returns what datatype it's first parameter is (string)
In the context of the original question,
local elem = {['1'] = test, ['2'] = testtwo}
if (type(elem) == "table") then
-- do stuff
else
-- do other stuff instead
end
Hope this helps.
You may find this helps readability:
local function istable(t) return type(t) == 'table' end