Lua: How to find out if an element is a table instead of a string/number?

unwise guy picture unwise guy · Jul 21, 2012 · Viewed 35k times · Source

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

Answer

Nathan picture Nathan · Jul 21, 2012
print(type(elem)) -->table

the type function in Lua returns what datatype it's first parameter is (string)