Quirrel4.41.0

types.String.tostring

Method on every string
pure tostring(): any

Returns str itself.

Return value

str unchanged: a string converted to a string is the same string.

Notes

Takes no arguments. The declaration mask for the hidden receiver is . (any type), so the VM's signature dump omits a receiver entirely and shows this as a bare tostring(): any with no string. prefix - the same binding backs "x".tostring(), [1].tostring() and every other type's .tostring(), they all point at the one shared native function.

Example

examples/types/string/tostring.nut
// a string converted to a string is the same string.
let s = "hello"
println("s.tostring() == s =", s.tostring() == s)

try { s.tostring(1) } catch (e) println("s.tostring(1) throws:", e)
Output:
s.tostring() == s = true
s.tostring(1) throws: wrong number of parameters passed to native closure 'tostring' (2 passed, 1 required)

See also

constructorConverts value to a string. This is what runs when types.String itself is called, types.String(value), the same way types.Integer(value) converts to an integer.
tointegerParses str as an integer.
stringclass index