Tostring()

From Riftui Wiki

Jump to: navigation, search

Returns string representation of value. Tables can change return value of tostring by specifying __tostring function in their metatables.

Contents

Signature

tostring(value)

Parameters

value (any type) - value to convert to string

Return value

type (string) - the type of value

Examples

local foo = 1;
local bar = tostring(foo);
 
print(foo .. " in variable foo is " .. type(foo)); -- prints "1 in variable foo is number"
print(bar .. " in variable bar is " .. type(bar)); -- prints "1 in variable bar is string"
local foo = setmetatable({ }, { __tostring = function(t) return "bar"; end });
 
print(foo); -- will print "bar"
Personal tools
Namespaces
Variants
Actions
Menu
Wiki
Toolbox