I want to make a module function called ‘len’ that detects if the object is a table or a string and gets its length. I do know about the hashtag operator and the string.len() function, I want to combine them into one function.
Current Code:
function pylua.len(object)
if type(object) == {} then
return #object
else if type(object) == "string" then
return string.len(object)
else
return print("DataTypeError: Given object is not a string or a table.")
end
end
end
However, it returns the “DataTypeError” when the object is a table.
I have also used the typeof function, but it does the same thing.
How can I do this?