lua-users home
lua-l archive

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


Am 23.10.2014 um 10:01 schröbte Michele Alessandrini:
Hello to everyone.

Hi!

When executing Lua from a C program, errors occurring in Lua code are
reported as a string pushed on the stack. At least it's my understanding
that this is the only way.
Is there a way to get a more "structured" error information? Like for
example, separate the error code, the line number, the offending
variable, the offending value, etc.

`xpcall` and `lua_pcall[k]` can take a message handler function which can replace or extend the original error message in any way. The message handler receives the old error message as argument and returns the new error message/value.

The formatted string makes it difficult to implement things like
localized error messages, or different program behavior according to the
kind of error.
I tried investigating the debug interface, but it does not seem to help
in this regard.

See the implementation of `luaL_traceback` in `lauxlib.c` for pointers.

Bye and thanks everybody for your work.
Michele


Philipp