lua-users home
lua-l archive

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



Am 11.12.2012 um 16:31 schrieb Jerome Vuarand:

2012/12/11 Philipp Kraus <philipp.kraus@flashpixx.de>:
I have a set of Lua scripts, that are stored in a database. On another host
system (cluster) a MPI spawned process get the scripts and run the Lua
code some million times. Each script / function is a independend system
in this process. At the moment I'm developing this system, so
I need a debug interface for my Lua codes. I would run the Lua code from C/C++
push values and functions to the stack and read the result.
The information which is needed by this process is "which function is called and
what data is put in / get out", so I need a stack trace during running.
The programm throws exception on error, but I catch the exceptions, log the error
and do the next step. The program need not to break, only the error must be logged
with a trace in user-friendly representation to database.

Do you have got an idea for a good error log creation?

Depending on how you call your Lua scripts, you may already have the
Lua call trace in the error messages. If that's not the case, you need
to use the last argument to lua_pcall, and have it point to
debug.traceback. If that's not clear enough you need to send us the
part of the code that leads to the lua_pcall, and we can show you how
to modify it to make use of debug.traceback.

I create the Lua pointer state, use a own lua_panic function for creating
my exception and load the script with luaL_loadstring. 

My panic function shows:

std::string l_error = lua_tostring(p_lua, -1);
lua_pop(p_lua, 1);
throw exception::RuntimeError(_("Lua error ["+l_error+"]"));

can I get the full stack trace within the panic function?


The resulting traceback string will contain a line for each call
frame, with the script name, line number and function name. If for
some reason this information is wrong or incomplete in your stack
traces, it may be because of the way you create your scripts. If you
use luaL_loadstring, you might want to consider using luaL_loadbuffer
or lua_load directly, and properly set the "name" argument.

Did I understand this correct, that I can get only the stack trace after an error
occurs? I will create a stack trace before and after the Lua script is run for logging
at the moment during developing. I need both a "manual stack trace" if I need it
and a stack trace on errors

Phil