lua-users home
lua-l archive

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


Is there a way I can find out the script line number where it hit the error, or maybe the lua file line number where it hit the error ?

As per mentioned in this stackoverflow thread, there are at least two different ways of making this happen.  Either you can mod your copy of the lua source code to implicitly append a stack trace to any error message, or, you can define an error handler callback and use it with xpcall/lua_pcall, and potentially get a stack-trace extended message that way. I don't know anything about LuaInterface though -- so I'm not sure whether either of these would be applicable in your situation.

I've found patching the lua source to append stack traces to all error messages to be easy enough -- you basically just need to define an append_stack_trace(L) function, and then call it from ldebug.c:luaG_runerror() (and a few other places, like luaL_error, if you want the stack traces implicitly appended to errors thrown from your own code).  But, if you're not fluent in C, or don't have access to the sources for your lua interpretor, this approach may be non-trivial...  

If you don't want to start hacking your lua sources, just making a custom error handler function that does the stack trace append and then making sure you wrap whatever you're doing in either an xpcall/lua_pcall invocation that references said error handler is probably the faster/easier solution.

-Sven