Skip to main content

tostring

Function tostring 

Source
pub fn tostring<T: tostring>(v: T) -> string
Expand description

Receives a value of any type and converts it to a string in a human-readable format.

If the metatable of v has a __tostring field, tostring calls the corresponding value with v as argument and uses the result. If it has a __name field with a string value, that string is used in the result. For full control of how numbers are converted, use string::format.

§Examples

print(tostring(42))       --> 42
print(tostring(nil))      --> nil
local pt = setmetatable({}, { __tostring = function() return "Point" end })
print(tostring(pt))       --> Point