lua-users home
lua-l archive

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


On 17 October 2014 12:46, Dirk Laurie <dirk.laurie@gmail.com> wrote:
I have a program with many instances of

    error(msg)

where msg is each time some _expression_.
If this _expression_ evaluates to a non-string,
the error message is merely

    lua: (error object is not a string)

There are obviously plenty of easy workarounds,
but is there some deep reason why the traceback
is omitted?


Calling `tostring()` on errors was added/fixed in lua 5.2.
However, tracebacks are not added.

    $ lua5.1 -e'function foo() error(setmetatable({},{__tostring=function() return"foo" end})) end; foo()'
    lua5.1: (error object is not a string)

    $ lua5.2 -e'function foo() error(setmetatable({},{__tostring=function() return"foo" end})) end; foo()'
    lua5.2: foo