Hello,
I'm current write a lua perftool like gperftools, it use
signals call back to set lua hook by lua_sethook, and in the hook
function get the lua call stack by lua_getinfo and save it, because some
lua C API running in signals call back can cause crash.
and in pure lua program it runs well.
but sometimes the program may like this:
while (true)
{
do_something_1();
do_something_2();
do_something_3();
......
call_lua_func("lua_main");
}
when
the signals trigged, it may running in C native code
"do_something_2()", and in the hook function I get the lua info will be
the "lua_main", it is not correct.
so I used an ugly code like:
static void SignalHandler(int sig, siginfo_t *sinfo, void *ucontext)
{
// L-nny == 0 && L-nCcalls == 0
unsigned short nny = *(unsigned short *)((char*)L+196);
unsigned short nCcalls = *(unsigned short *)((char*)L+198);
if (nny == 0 && nCcalls == 0)
{
return;
}
lua_sethook(gL, SignalHandlerHook, LUA_MASKCOUNT, 1);
}
so is there a C API can check VM is running?
ps, my code is in
https://github.com/esrrhs/pLuaRegards
Zhao Xin