lua-users home
lua-l archive

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

In the #lua irc channel today an interesting issue came up:

    > t = setmetatable({},{__tostring=function(self) return self end});
    > print(type(t), type(tostring(t)), type(tostring(tostring(t))))
    table table table

If __tostring returns a non-string non-number, then it is returned to
the caller.

This breaks the assumed invariant that 'tostring' will return a string or nil.
e.g. print will error with: 'tostring' must return a string to 'print'

Please check your programs to make sure you handle this reasonably!