Check if empty
📝 LuaThis function returns true when a Lua table or string contains no elements or characters.
Lua
function isEmpty(value) if type(value) == "table" then return next(value) == nil elseif type(value) == "string" then return value == "" else return false end
end
Comments
Yeah, empty string and empty table both being truthy in Lua can trip people up, especially since {} is often used as a default argument. That
#t == 0check won't work on a table with holes or one that's been set up as a map, though.