I've seen a lot scripts using "tostring". I was trying to understand what it means but I didn't figured out yet. Help please.
It makes things into strings
As a cat, I prefer yarn.
tostring
simply takes something and returns the string interpretation of it. It's used behind the scenes for print
, and isn't necessary in a lot of cases because most things have implicit typecasting in Lua.
Tables and userdata both have their __tostring
metamethod invoked if applicable, and it uses the string interpretation of whatever is returned. I'm unsure of whether nil
being returned is turned into 'nil'
or whether it just gets the memory value for the object at that point, however.