lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,

Has anyone got a better idea for getting the address of a table with a __tostring in its metatable than this?

> a = setmetatable({}, { __tostring = function() return "pretty but no address" end})
> print(a)
pretty but no address
> function rawtostring(t) local mt = getmetatable(t) setmetatable(t, nil) local r = tostring(t) setmetatable(t, mt) return r end
> print(a, rawtostring(a), a)
pretty but no address	table: 0x115150	pretty but no address

It works, but it's a bit mucky.

Cheers,
Geoff