diff --git a/polymer/eduke32/source/gameexec.c b/polymer/eduke32/source/gameexec.c index 2bf860913..ab16df75a 100644 --- a/polymer/eduke32/source/gameexec.c +++ b/polymer/eduke32/source/gameexec.c @@ -5112,6 +5112,7 @@ void A_Execute(int32_t iActor,int32_t iPlayer,int32_t lDist) { #ifdef LUNATIC double t; + int32_t killit=0; #endif vmstate_t tempvm = { iActor, iPlayer, lDist, &actor[iActor].t_data[0], &sprite[iActor], 0 @@ -5176,7 +5177,7 @@ void A_Execute(int32_t iActor,int32_t iPlayer,int32_t lDist) t = gethitickms(); if (L_IsInitialized(&g_ElState) && El_HaveActor(vm.g_sp->picnum)) - El_CallActor(&g_ElState, vm.g_sp->picnum, iActor, iPlayer, lDist); + killit = (El_CallActor(&g_ElState, vm.g_sp->picnum, iActor, iPlayer, lDist)==1); #endif insptr = 4 + (g_tile[vm.g_sp->picnum].execPtr); @@ -5188,7 +5189,11 @@ void A_Execute(int32_t iActor,int32_t iPlayer,int32_t lDist) g_actorCalls[vm.g_sp->picnum]++; #endif - if (vm.g_flags & VM_KILL) + if ((vm.g_flags & VM_KILL) +#ifdef LUNATIC + || killit +#endif + ) { // if player was set to squish, first stop that... if (vm.g_p >= 0 && g_player[vm.g_p].ps->actorsqu == vm.g_i) diff --git a/polymer/eduke32/source/lunatic/control.lua b/polymer/eduke32/source/lunatic/control.lua index 2fcaddbd6..6341edf02 100644 --- a/polymer/eduke32/source/lunatic/control.lua +++ b/polymer/eduke32/source/lunatic/control.lua @@ -159,6 +159,17 @@ end --- Exported functions +-- Non-local control flow. These ones call the original error(), not our +-- redefinition in defs.ilua. +function longjmp() + error(false) +end + +function killit() + -- TODO: guard against deletion of player sprite? + error(true) +end + -- The return value is true iff the ammo was at the weapon's max. -- In that case, no action is taken. function addammo(ps, weapon, amount) diff --git a/polymer/eduke32/source/lunatic/lunacon.lua b/polymer/eduke32/source/lunatic/lunacon.lua index 57dc0ef50..c3c0f4035 100644 --- a/polymer/eduke32/source/lunatic/lunacon.lua +++ b/polymer/eduke32/source/lunatic/lunacon.lua @@ -670,7 +670,8 @@ local Ci = { -- these can appear anywhere in the script ["break"] = cmd() / "do return end", -- TODO: more exact semantics - ["return"] = cmd(), + ["return"] = cmd() + / "_con.longjmp()", -- TODO: test with code from Wiki "return" entry state = cmd(I) / "%1()", -- TODO: mangle names @@ -846,7 +847,7 @@ local Ci = { getlastpal = cmd(), insertspriteq = cmd(), killit = cmd() - / "do return 2 end", -- exec SPECIAL HANDLING! + / "_con.killit()", -- exec SPECIAL HANDLING! mikesnd = cmd(), nullop = cmd(), pkick = cmd(), diff --git a/polymer/eduke32/source/lunatic/lunatic_game.c b/polymer/eduke32/source/lunatic/lunatic_game.c index 60badc33b..c9a965c1f 100644 --- a/polymer/eduke32/source/lunatic/lunatic_game.c +++ b/polymer/eduke32/source/lunatic/lunatic_game.c @@ -190,10 +190,17 @@ int32_t El_CallEvent(L_State *estate, int32_t eventidx, int32_t iActor, int32_t if (i == LUA_ERRRUN) { + if (lua_isboolean(L, -1)) + { + lua_pop(L, 1); + return 0; + } + + Bassert(lua_type(L, -1)==LUA_TSTRING); OSD_Printf("event \"%s\" (state \"%s\") runtime error: %s\n", EventNames[eventidx].text, estate->name, lua_tostring(L, -1)); // get err msg lua_pop(L, 1); - return 4; + return -1; } return 0; @@ -207,10 +214,18 @@ int32_t El_CallActor(L_State *estate, int32_t actortile, int32_t iActor, int32_t if (i == LUA_ERRRUN) { + if (lua_isboolean(L, -1)) + { + int32_t killit = lua_toboolean(L, -1); + lua_pop(L, 1); + return killit; + } + + Bassert(lua_type(L, -1)==LUA_TSTRING); OSD_Printf("actor %d (sprite %d, state \"%s\") runtime error: %s\n", actortile, iActor, estate->name, lua_tostring(L, -1)); // get err msg lua_pop(L, 1); - return 4; + return -1; } return 0; diff --git a/polymer/eduke32/source/lunatic/test.elua b/polymer/eduke32/source/lunatic/test.elua index 0c5fd133f..764a1316a 100644 --- a/polymer/eduke32/source/lunatic/test.elua +++ b/polymer/eduke32/source/lunatic/test.elua @@ -266,6 +266,10 @@ gameactor(1680, -- LIZTROOP -- Duke Vader / Anakin Nukewalker? actor[i]:set_action("TROOPFLINTCH") actor[i]:set_move("SHRUNKVELS") + + if (dist < 1024) then + con.killit() + end end end )