11static int pilot_shipLmem(
const Pilot *p )
15 nlua_getenv(
naevL, p->ship->lua_env,
"mem" );
16 oldmem = luaL_ref(
naevL, LUA_REGISTRYINDEX );
18 lua_rawgeti(
naevL, LUA_REGISTRYINDEX, p->lua_ship_mem );
19 nlua_setenv(
naevL, p->ship->lua_env,
"mem" );
22static void pilot_shipLunmem(
const Pilot *p,
int oldmem )
24 lua_rawgeti(
naevL, LUA_REGISTRYINDEX, oldmem );
25 nlua_setenv(
naevL, p->ship->lua_env,
"mem" );
26 luaL_unref(
naevL, LUA_REGISTRYINDEX, oldmem );
28static void shipLRunWarning(
const Pilot *p,
const Ship *s,
const char *name,
31 WARN( _(
"Pilot '%s''s ship '%s' -> '%s':\n%s" ), p->name, s->
name, name,
44 if ( p->lua_ship_mem == LUA_NOREF ) {
45 lua_newtable(
naevL );
46 p->lua_ship_mem = luaL_ref(
naevL, LUA_REGISTRYINDEX );
49 if ( p->ship->lua_init == LUA_NOREF )
52 oldmem = pilot_shipLmem( p );
55 lua_rawgeti(
naevL, LUA_REGISTRYINDEX, p->ship->lua_init );
57 if ( nlua_pcall( p->ship->lua_env, 1, 0 ) ) {
58 shipLRunWarning( p, p->ship,
"init", lua_tostring(
naevL, -1 ) );
60 pilot_shipLunmem( p, oldmem );
63 pilot_shipLunmem( p, oldmem );
75 if ( p->ship->lua_cleanup != LUA_NOREF ) {
76 int oldmem = pilot_shipLmem( p );
79 lua_rawgeti(
naevL, LUA_REGISTRYINDEX, p->ship->lua_cleanup );
81 if ( nlua_pcall( p->ship->lua_env, 1, 0 ) ) {
82 shipLRunWarning( p, p->ship,
"cleanup", lua_tostring(
naevL, -1 ) );
84 pilot_shipLunmem( p, oldmem );
87 pilot_shipLunmem( p, oldmem );
91 if ( p->lua_ship_mem != LUA_NOREF ) {
92 luaL_unref(
naevL, LUA_REGISTRYINDEX, p->lua_ship_mem );
93 p->lua_ship_mem = LUA_NOREF;
108 if ( p->ship->lua_update == LUA_NOREF )
112 if ( p->ship->lua_dt > 0. ) {
113 p->lua_ship_timer -= dt;
114 if ( p->lua_ship_timer > 0. )
116 p->lua_ship_timer += p->ship->lua_dt;
119 oldmem = pilot_shipLmem( p );
122 lua_rawgeti(
naevL, LUA_REGISTRYINDEX, p->ship->lua_update );
124 lua_pushnumber(
naevL, dt );
125 if ( nlua_pcall( p->ship->lua_env, 2, 0 ) ) {
126 shipLRunWarning( p, p->ship,
"update", lua_tostring(
naevL, -1 ) );
128 pilot_shipLunmem( p, oldmem );
131 pilot_shipLunmem( p, oldmem );
144 if ( p->ship->lua_explode_init == LUA_NOREF )
146 oldmem = pilot_shipLmem( p );
149 lua_rawgeti(
naevL, LUA_REGISTRYINDEX, p->ship->lua_explode_init );
151 if ( nlua_pcall( p->ship->lua_env, 1, 0 ) ) {
152 shipLRunWarning( p, p->ship,
"explode_init", lua_tostring(
naevL, -1 ) );
154 pilot_shipLunmem( p, oldmem );
157 pilot_shipLunmem( p, oldmem );
171 if ( p->ship->lua_explode_update == LUA_NOREF )
173 oldmem = pilot_shipLmem( p );
176 lua_rawgeti(
naevL, LUA_REGISTRYINDEX, p->ship->lua_explode_update );
178 lua_pushnumber(
naevL, dt );
179 if ( nlua_pcall( p->ship->lua_env, 2, 0 ) ) {
180 shipLRunWarning( p, p->ship,
"explode_update",
181 lua_tostring(
naevL, -1 ) );
183 pilot_shipLunmem( p, oldmem );
186 pilot_shipLunmem( p, oldmem );
LuaPilot * lua_pushpilot(lua_State *L, LuaPilot pilot)
Pushes a pilot on the stack.
int pilot_shipLInit(Pilot *p)
Initializes the pilot ship Lua.
int pilot_shipLExplodeUpdate(Pilot *p, double dt)
Updates the pilot explosion Lua stuff.
int pilot_shipLUpdate(Pilot *p, double dt)
Updates the pilot Lua stuff.
int pilot_shipLCleanup(Pilot *p)
Cleans up the pilot ship Lua.
int pilot_shipLExplodeInit(Pilot *p)
Initializes the pilot explosion stuff.
The representation of an in-game pilot.