static void dohook (int ref) { lua_LHFunction oldlinehook = lua_setlinehook(NULL); lua_CHFunction oldcallhook = lua_setcallhook(NULL); lua_callfunction(lua_getref(ref)); lua_setlinehook(oldlinehook); lua_setcallhook(oldcallhook); }
static void setcallhook (void) { lua_Object f = lua_getparam(1); lua_unref(callhook); if (f == LUA_NOOBJECT) { callhook = -1; lua_setcallhook(NULL); } else { lua_pushobject(f); callhook = lua_ref(1); lua_setcallhook(callf); } }
static void laction (int i) { (void)i; /* to avoid warnings */ signal(SIGINT, SIG_DFL); /* if another SIGINT happens before lstop, terminate process (default action) */ old_linehook = lua_setlinehook(L, (lua_Hook)lstop); old_callhook = lua_setcallhook(L, (lua_Hook)lstop); }
static void profile_stop(lua_State *L) { check_start(L); lua_setcallhook(L, NULL); // disable hook free_array(get_metadata_array(L), STACK_INDEX); lua_unref(L, META_REF); // Remove the old reference (new block of memory). PROFILE_INIT = false; }
static void profile_start(lua_State *L) { if (PROFILE_INIT) return; // already started. lua_Object lobj = lua_getparam(L, 1); if (lobj > 0) { luaL_arg_check(L, lua_isnumber(L, lobj), 1, "Inform the minimum time results in float"); PROFILE_RECORD_TIME = (float) lua_getnumber(L, lobj); } Meta **meta = (Meta **) malloc(MEM_BLOCKSIZE * sizeof(Meta **)); lua_pushuserdata(L, meta); META_REF = lua_ref(L, 1); lua_setcallhook(L, callhook); PROFILE_START_TIME = clock(); PROFILE_INIT = true; }
static void laction (int i) { signal(SIGINT, SIG_DFL); /* if another SIGINT happens before lstop, terminate process (default action) */ old_linehook = lua_setlinehook((lua_LHFunction)lstop); old_callhook = lua_setcallhook((lua_CHFunction)lstop); }
static void lstop (void) { lua_setlinehook(old_linehook); lua_setcallhook(old_callhook); lreset(); lua_error("interrupted!"); }
static void lstop (lua_State *lua_state, lua_Debug *ar) { lua_setlinehook(lua_state, old_linehook); lua_setcallhook(lua_state, old_callhook); lreset(); make_lua_error(lua_state, "interrupted!"); }
void stop_trace(void) { lua_setlinehook(L,NULL); lua_setcallhook(L,NULL); fclose(LOG); }
void start_trace(FILE* logfile) { lua_setlinehook(L,linehook); lua_setcallhook(L,callhook); LOG=logfile; }