|
`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.
See the implementation of `luaL_traceback` in `lauxlib.c` for pointers.
Sorry, but this does not address the problem. All these methods receive strings that are already formatted to be human-readable.
For example you get:"[string "print("hello world")..."]:70: attempt to perform arithmetic on global 'x' (a nil value)"
What would be useful is a struct with data similar to these (invented by me):
error = LUA_ARITHMETIC_INVALID_OPERAND file = "....." line = 70 object = LUA_GLOBAL_VARIABLE objectname = "x" objecttype = LUA_TNILThis way the program could manage an error in more sophisticated ways, or format an error string in whatever is more appropriate for the application. With strings you should do an heavy parsing, and know all the possible generated strings, and hope they don't change at every revision.
Bye Michele