static void handle(int sig) { if(!signal_queue) { /* Store the existing debug hook (if any) and its parameters */ Hsig = lua_gethook(Lsig); Hmask = lua_gethookmask(Lsig); Hcount = lua_gethookcount(Lsig); signal_queue = malloc(sizeof(struct signal_event)); signal_queue->Nsig = sig; signal_queue->next_event = NULL; last_event = signal_queue; /* Set our new debug hook */ lua_sethook(Lsig, sighook, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1); } else { last_event->next_event = malloc(sizeof(struct signal_event)); last_event->next_event->Nsig = sig; last_event->next_event->next_event = NULL; last_event = last_event->next_event; } }
lua_Hook lua_setlinehook (lua_State *L, lua_Hook func) { lua_Hook old_hook = lua_gethook(L); lua_sethook (L, func, LUA_MASKLINE, 0); return old_hook; }
int luaQ_tracebackskip(struct lua_State *L, int skip) { // stack: msg luaQ_getfield(L, LUA_GLOBALSINDEX, "debug"); luaQ_getfield(L, -1, "traceback"); // stack: traceback debug msg lua_remove(L, -2); // stack: traceback msg if (! lua_isfunction(L, -1)) { lua_pop(L, 1); } else { lua_pushvalue(L, -2); lua_pushinteger(L, skip+1); // save hook lua_Hook hf = lua_gethook(L); int hm = lua_gethookmask(L); int hc = lua_gethookcount(L); lua_sethook(L, 0, 0, 0); // stack: skip msg traceback msg if (lua_pcall(L, 2, 1, 0)) // stack: err msg lua_remove(L, -1); else // stack: msg msg lua_remove(L, -2); // restore hook lua_sethook(L, hf, hm, hc); } // stack: msg return 1; }
static void vx_sighandler(int sig) { sign = sig; sigh = lua_gethook(GL); hcnt = lua_gethookcount(GL); hmask = lua_gethookmask(GL); lua_sethook(GL, vx_sighook, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1); }
static void l_signal(int i) { /* assert(i==SIGALRM); */ signal(i,SIG_DFL); oldhook=lua_gethook(LL); oldmask=lua_gethookmask(LL); oldcount=lua_gethookcount(LL); lua_sethook(LL,l_handler,LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT,1); }
lua_Hook lua_setcallhook (lua_State *L, lua_Hook func) { lua_Hook old_hook = lua_gethook(L); lua_sethook (L, func, LUA_MASKCALL, 0); return old_hook; }
static void handle (int sig) { assert(ML != NULL); if (old_hook.hook == NULL) /* replace it */ { old_hook.hook = lua_gethook(ML); old_hook.mask = lua_gethookmask(ML); old_hook.count = lua_gethookcount(ML); lua_sethook(ML, hook, LUA_MASKCOUNT, 1); } signal_stack[sig]++; }
static void signal_handler(int sig) { if (q.size == 0) { old_hook = lua_gethook(gL); old_mask = lua_gethookmask(gL); old_count = lua_gethookcount(gL); lua_sethook(gL, lua_signal_handler, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1); } enqueue(&q, sig); }
static int gethook (lua_State *L) { char buff[5]; int mask = lua_gethookmask(L); lua_Hook hook = lua_gethook(L); if (hook != NULL && hook != hookf) /* external hook? */ lua_pushliteral(L, "external hook"); else { lua_pushlightuserdata(L, (void *)&KEY_HOOK); lua_rawget(L, LUA_REGISTRYINDEX); /* get hook */ } lua_pushstring(L, unmakemask(mask, buff)); lua_pushnumber(L, (lua_Number)lua_gethookcount(L)); return 3; }
static int db_gethook (lua_State *L) { int arg; lua_State *L1 = getthread(L, &arg); char buff[5]; int mask = lua_gethookmask(L1); lua_Hook hook = lua_gethook(L1); if (hook != NULL && hook != hookf) /* external hook? */ lua_pushliteral(L, "external hook"); else { gethooktable(L); lua_rawgetp(L, -1, L1); /* get hook */ lua_remove(L, -2); /* remove hook table */ } lua_pushstring(L, unmakemask(mask, buff)); lua_pushinteger(L, lua_gethookcount(L1)); return 3; }
void luaQ_getfield(struct lua_State *L, int index, const char *name) { lua_pushvalue(L, index); lua_pushcfunction(L, luaQ_gettable); lua_insert(L, -2); lua_pushstring(L, name); lua_Hook hf = lua_gethook(L); int hm = lua_gethookmask(L); int hc = lua_gethookcount(L); lua_sethook(L, 0, 0, 0); if (lua_pcall(L, 2, 1, 0)) { lua_pop(L, 1); lua_pushnil(L); } lua_sethook(L, hf, hm, hc); }
static int profiler_start( lua_State * L) { if(lua_gethook(L)) { lua_pushstring(L,"has been started"); lua_error(L); return 0; } #ifdef _WIN32 QueryPerformanceFrequency(&liFreq); #endif totalstatcount = 0; s_rec.clear(); funcIds.clear(); funcIds.reserve(50); lua_sethook(L,profiler_hook,LUA_MASKCALL | LUA_MASKRET ,0); return 0; }
static int db_gethook (lua_State *L) { int arg; lua_State *L1 = getthread(L, &arg); char buff[5]; int mask = lua_gethookmask(L1); lua_Hook hook = lua_gethook(L1); if (hook == NULL) /* no hook? */ lua_pushnil(L); else if (hook != hookf) /* external hook? */ lua_pushliteral(L, "external hook"); else { /* hook table must exist */ lua_rawgetp(L, LUA_REGISTRYINDEX, &HOOKKEY); lua_pushthread(L1); lua_xmove(L1, L, 1); lua_rawget(L, -2); /* 1st result = hooktable[L1] */ lua_remove(L, -2); /* remove hook table */ } lua_pushstring(L, unmakemask(mask, buff)); /* 2nd result = mask */ lua_pushinteger(L, lua_gethookcount(L1)); /* 3rd result = count */ return 3; }
lua_Hook LuaDebug::GetHook() const { return lua_gethook(L()); }
void threading_setup(lua_State *L) { threading_old_hook = lua_gethook(L); }