/** * @brief Creates a mission hook to a certain stack. * * Basically a generic approach to hooking. * * @param L Lua state. * @param stack Stack to put the hook in. * @param pos Position in the stack of the function name. * @return The hook ID or 0 on error. */ static unsigned int hook_generic( lua_State *L, const char* stack, int pos ) { int i; const char *func; /* Last parameter must be function to hook */ func = luaL_checkstring(L,pos); if (running_mission != NULL) { /* make sure mission is a player mission */ for (i=0; i<MISSION_MAX; i++) if (player_missions[i].id == running_mission->id) break; if (i>=MISSION_MAX) { WARN("Mission not in stack trying to hook"); return 0; } return hook_addMisn( running_mission->id, func, stack ); } else if (running_event != NULL) { return hook_addEvent( running_event->id, func, stack ); } NLUA_ERROR(L,"No hook target was set."); return 0; }
/** * @brief Creates a mission hook to a certain stack. * * Basically a generic approach to hooking. * * @param L Lua state. * @param stack Stack to put the hook in. * @param ms Milliseconds to delay (pass stack as NULL to set as timer). * @param pos Position in the stack of the function name. * @return The hook ID or 0 on error. */ static unsigned int hook_generic( lua_State *L, const char* stack, double ms, int pos, ntime_t date ) { int i; const char *func; unsigned int h; Event_t *running_event; Mission *running_mission; /* Last parameter must be function to hook */ func = luaL_checkstring(L,pos); /* Get stuff. */ running_event = event_getFromLua(L); running_mission = misn_getFromLua(L); h = 0; if (running_mission != NULL) { /* make sure mission is a player mission */ for (i=0; i<MISSION_MAX; i++) if (player_missions[i].id == running_mission->id) break; if (i>=MISSION_MAX) { WARN("Mission not in stack trying to hook, forgot to run misn.accept()?"); return 0; } if (stack != NULL) h = hook_addMisn( running_mission->id, func, stack ); else if (date != 0) h = hook_addDateMisn( running_mission->id, func, date ); else h = hook_addTimerMisn( running_mission->id, func, ms ); } else if (running_event != NULL) { if (stack != NULL) h = hook_addEvent( running_event->id, func, stack ); else if (date != 0) h = hook_addDateEvt( running_event->id, func, date ); else h = hook_addTimerEvt( running_event->id, func, ms ); } if (h == 0) { NLUA_ERROR(L,"No hook target was set."); return 0; } /* Check parameter. */ if (!lua_isnil(L,pos+1)) hookL_setarg( L, h, pos+1 ); return h; }