Quirrel4.41.0

types.Table.tostring

Method on every table
tostring(): any

Returns a string that names the type and identity of the table.

Return value

A string shaped like (table : 0x...). The address is the table's own identity, not its contents: two tables with the same keys and values print two different addresses, and the same table prints the same address every time.

Notes

Takes no arguments; t.tostring(1) throws wrong number of parameters passed to native closure 'tostring' (2 passed, 1 required).

Because the address changes from run to run, code must never compare or print tostring() of a table for anything other than a human to eyeball while debugging.

Example

examples/types/table/tostring.nut
let t = {a=1}
let s = t.tostring()
// the address varies run to run, so only check the fixed prefix
println("s.slice(0, 8) =", s.slice(0, 8))
println("typeof s =", typeof s)

// two different tables never print the same tostring()
let u = {a=1}
println("t.tostring() == u.tostring():", t.tostring() == u.tostring())
Output:
s.slice(0, 8) = (table :
typeof s = string
t.tostring() == u.tostring(): false

See also

cloneReturns a shallow copy of the table.
is_frozenReports whether this reference to the table was frozen with freeze().
weakrefReturns a weak reference to the table.
tableclass index