lua-users home
lua-l archive

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


Hi all,

I would like to change the default behaviour of
Lua when representing a table through the
tostring() function ; I would prefer to have something
more like in Python for example (instead of having
"table: 0x8062ac0", I would like to see the contents,
for example { 1, 2, 3 }).

So first of all I tried to set a new metatable for tables,
and have its __tostring function returning an arbitrary
string but it did not work at all :

Lua 5.1  Copyright (C) 1994-2006 Lua.org, PUC-Rio
> setmetatable({}, { __tostring = function (t) print("hello") end })
> print({})
table: 0x8091e30

Did someone already tried to do something similar ?

Cheers,
M.