lua-users home
lua-l archive

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




On Tue, Sep 3, 2019 at 2:27 PM Sven Olsen <sven2718@gmail.com> wrote:
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

NLua is the "spiritual successor" to LuaInterface, though I'm not sure if there is better debugging capabilities. I've also used NeoLua which is written on top of the .Net dynamic runtime. I know that NeoLua has debugging features that you need to explicitly turn on in order to use (which I have not). 

Either way, both NLua and NeoLua are currently supported so you might have better luck getting support?

For what it's worth,
Russ