diff --git a/src/f_finale.h b/src/f_finale.h index c0c6360c3..29e9b4d8c 100644 --- a/src/f_finale.h +++ b/src/f_finale.h @@ -82,7 +82,6 @@ typedef enum // Current menu parameters -extern UINT8 titlemapinaction; extern mobj_t *titlemapcameraref; extern char curbgname[8]; extern SINT8 curfadevalue; diff --git a/src/g_state.h b/src/g_state.h index 76c9bd16f..7ee0cfb63 100644 --- a/src/g_state.h +++ b/src/g_state.h @@ -50,6 +50,7 @@ typedef enum } gameaction_t; extern gamestate_t gamestate; +extern UINT8 titlemapinaction; extern UINT8 ultimatemode; // was sk_insane extern gameaction_t gameaction; diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 1d69b238b..7592fdf48 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -33,7 +33,7 @@ #define NOHUD if (hud_running)\ return luaL_error(L, "HUD rendering code should not call this function!"); -#define INLEVEL if (gamestate != GS_LEVEL)\ +#define INLEVEL if (gamestate != GS_LEVEL && !titlemapinaction)\ return luaL_error(L, "This function can only be used in a level!"); boolean luaL_checkboolean(lua_State *L, int narg) { diff --git a/src/lua_consolelib.c b/src/lua_consolelib.c index 98d18d8db..ed0295ca1 100644 --- a/src/lua_consolelib.c +++ b/src/lua_consolelib.c @@ -29,7 +29,7 @@ return luaL_error(L, "HUD rendering code should not call this function!"); #define NOHOOK if (!lua_lumploading)\ return luaL_error(L, "This function cannot be called from within a hook or coroutine!"); // for functions only allowed within a level -#define INLEVEL if (gamestate != GS_LEVEL)\ +#define INLEVEL if (gamestate != GS_LEVEL && !titlemapinaction)\ return luaL_error(L, "This function can only be used in a level!"); static const char *cvname = NULL; diff --git a/src/lua_maplib.c b/src/lua_maplib.c index ded90daf0..1ab2828bf 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -29,6 +29,9 @@ #include "fastcmp.h" #include "doomstat.h" +#define INLEVEL if (gamestate != GS_LEVEL && !titlemapinaction)\ +return luaL_error(L, "This function can only be used in a level!"); + enum sector_e { sector_valid = 0, sector_floorheight, @@ -333,8 +336,7 @@ static int lib_iterateSectorThinglist(lua_State *L) mobj_t *state = NULL; mobj_t *thing = NULL; - if (gamestate != GS_LEVEL) - return luaL_error(L, "This function can only be used in a level!"); + INLEVEL if (lua_gettop(L) < 2) return luaL_error(L, "Don't call sector.thinglist() directly, use it as 'for rover in sector.thinglist do end'."); @@ -369,8 +371,7 @@ static int lib_iterateSectorFFloors(lua_State *L) ffloor_t *state = NULL; ffloor_t *ffloor = NULL; - if (gamestate != GS_LEVEL) - return luaL_error(L, "This function can only be used in a level!"); + INLEVEL if (lua_gettop(L) < 2) return luaL_error(L, "Don't call sector.ffloors() directly, use it as 'for rover in sector.ffloors do end'."); @@ -1251,8 +1252,7 @@ static int bbox_get(lua_State *L) static int lib_iterateSectors(lua_State *L) { size_t i = 0; - if (gamestate != GS_LEVEL) - return luaL_error(L, "This function can only be used in a level!"); + INLEVEL if (lua_gettop(L) < 2) return luaL_error(L, "Don't call sectors.iterate() directly, use it as 'for sector in sectors.iterate do end'."); lua_settop(L, 2); @@ -1270,8 +1270,7 @@ static int lib_iterateSectors(lua_State *L) static int lib_getSector(lua_State *L) { int field; - if (gamestate != GS_LEVEL) - return luaL_error(L, "You cannot access this outside of a level!"); + INLEVEL lua_settop(L, 2); lua_remove(L, 1); // dummy userdata table is unused. if (lua_isnumber(L, 1)) @@ -1305,8 +1304,7 @@ static int lib_numsectors(lua_State *L) static int lib_iterateSubsectors(lua_State *L) { size_t i = 0; - if (gamestate != GS_LEVEL) - return luaL_error(L, "This function can only be used in a level!"); + INLEVEL if (lua_gettop(L) < 2) return luaL_error(L, "Don't call subsectors.iterate() directly, use it as 'for subsector in subsectors.iterate do end'."); lua_settop(L, 2); @@ -1324,8 +1322,7 @@ static int lib_iterateSubsectors(lua_State *L) static int lib_getSubsector(lua_State *L) { int field; - if (gamestate != GS_LEVEL) - return luaL_error(L, "You cannot access this outside of a level!"); + INLEVEL lua_settop(L, 2); lua_remove(L, 1); // dummy userdata table is unused. if (lua_isnumber(L, 1)) @@ -1359,8 +1356,7 @@ static int lib_numsubsectors(lua_State *L) static int lib_iterateLines(lua_State *L) { size_t i = 0; - if (gamestate != GS_LEVEL) - return luaL_error(L, "This function can only be used in a level!"); + INLEVEL if (lua_gettop(L) < 2) return luaL_error(L, "Don't call lines.iterate() directly, use it as 'for line in lines.iterate do end'."); lua_settop(L, 2); @@ -1378,8 +1374,7 @@ static int lib_iterateLines(lua_State *L) static int lib_getLine(lua_State *L) { int field; - if (gamestate != GS_LEVEL) - return luaL_error(L, "You cannot access this outside of a level!"); + INLEVEL lua_settop(L, 2); lua_remove(L, 1); // dummy userdata table is unused. if (lua_isnumber(L, 1)) @@ -1413,8 +1408,7 @@ static int lib_numlines(lua_State *L) static int lib_iterateSides(lua_State *L) { size_t i = 0; - if (gamestate != GS_LEVEL) - return luaL_error(L, "This function can only be used in a level!"); + INLEVEL if (lua_gettop(L) < 2) return luaL_error(L, "Don't call sides.iterate() directly, use it as 'for side in sides.iterate do end'."); lua_settop(L, 2); @@ -1432,8 +1426,7 @@ static int lib_iterateSides(lua_State *L) static int lib_getSide(lua_State *L) { int field; - if (gamestate != GS_LEVEL) - return luaL_error(L, "You cannot access this outside of a level!"); + INLEVEL lua_settop(L, 2); lua_remove(L, 1); // dummy userdata table is unused. if (lua_isnumber(L, 1)) @@ -1467,8 +1460,7 @@ static int lib_numsides(lua_State *L) static int lib_iterateVertexes(lua_State *L) { size_t i = 0; - if (gamestate != GS_LEVEL) - return luaL_error(L, "This function can only be used in a level!"); + INLEVEL if (lua_gettop(L) < 2) return luaL_error(L, "Don't call vertexes.iterate() directly, use it as 'for vertex in vertexes.iterate do end'."); lua_settop(L, 2); @@ -1486,8 +1478,7 @@ static int lib_iterateVertexes(lua_State *L) static int lib_getVertex(lua_State *L) { int field; - if (gamestate != GS_LEVEL) - return luaL_error(L, "You cannot access this outside of a level!"); + INLEVEL lua_settop(L, 2); lua_remove(L, 1); // dummy userdata table is unused. if (lua_isnumber(L, 1)) @@ -1523,8 +1514,7 @@ static int lib_numvertexes(lua_State *L) static int lib_iterateSegs(lua_State *L) { size_t i = 0; - if (gamestate != GS_LEVEL) - return luaL_error(L, "This function can only be used in a level!"); + INLEVEL if (lua_gettop(L) < 2) return luaL_error(L, "Don't call segs.iterate() directly, use it as 'for seg in segs.iterate do end'."); lua_settop(L, 2); @@ -1542,8 +1532,7 @@ static int lib_iterateSegs(lua_State *L) static int lib_getSeg(lua_State *L) { int field; - if (gamestate != GS_LEVEL) - return luaL_error(L, "You cannot access this outside of a level!"); + INLEVEL lua_settop(L, 2); lua_remove(L, 1); // dummy userdata table is unused. if (lua_isnumber(L, 1)) @@ -1577,8 +1566,7 @@ static int lib_numsegs(lua_State *L) static int lib_iterateNodes(lua_State *L) { size_t i = 0; - if (gamestate != GS_LEVEL) - return luaL_error(L, "This function can only be used in a level!"); + INLEVEL if (lua_gettop(L) < 2) return luaL_error(L, "Don't call nodes.iterate() directly, use it as 'for node in nodes.iterate do end'."); lua_settop(L, 2); @@ -1596,8 +1584,7 @@ static int lib_iterateNodes(lua_State *L) static int lib_getNode(lua_State *L) { int field; - if (gamestate != GS_LEVEL) - return luaL_error(L, "You cannot access this outside of a level!"); + INLEVEL lua_settop(L, 2); lua_remove(L, 1); // dummy userdata table is unused. if (lua_isnumber(L, 1)) diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index 8bbbebe1d..5ddcb0ca7 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -22,6 +22,9 @@ #include "lua_libs.h" #include "lua_hud.h" // hud_running errors +#define INLEVEL if (gamestate != GS_LEVEL && !titlemapinaction)\ +return luaL_error(L, "This function can only be used in a level!"); + static const char *const array_opt[] ={"iterate",NULL}; enum mobj_e { @@ -816,8 +819,7 @@ static int mapthing_set(lua_State *L) static int lib_iterateMapthings(lua_State *L) { size_t i = 0; - if (gamestate != GS_LEVEL) - return luaL_error(L, "This function can only be used in a level!"); + INLEVEL if (lua_gettop(L) < 2) return luaL_error(L, "Don't call mapthings.iterate() directly, use it as 'for mapthing in mapthings.iterate do end'."); lua_settop(L, 2); @@ -835,8 +837,7 @@ static int lib_iterateMapthings(lua_State *L) static int lib_getMapthing(lua_State *L) { int field; - if (gamestate != GS_LEVEL) - return luaL_error(L, "You cannot access this outside of a level!"); + INLEVEL lua_settop(L, 2); lua_remove(L, 1); // dummy userdata table is unused. if (lua_isnumber(L, 1)) diff --git a/src/lua_playerlib.c b/src/lua_playerlib.c index 700dab211..c4b092c6f 100644 --- a/src/lua_playerlib.c +++ b/src/lua_playerlib.c @@ -22,11 +22,13 @@ #include "lua_libs.h" #include "lua_hud.h" // hud_running errors +#define INLEVEL if (gamestate != GS_LEVEL && !titlemapinaction)\ +return luaL_error(L, "This function can only be used in a level!"); + static int lib_iteratePlayers(lua_State *L) { INT32 i = -1; - if (gamestate != GS_LEVEL) - return luaL_error(L, "This function can only be used in a level!"); + INLEVEL if (lua_gettop(L) < 2) { //return luaL_error(L, "Don't call players.iterate() directly, use it as 'for player in players.iterate do end'."); @@ -53,8 +55,7 @@ static int lib_getPlayer(lua_State *L) { const char *field; // i -> players[i] - if (gamestate != GS_LEVEL) - return luaL_error(L, "You cannot access this outside of a level!"); + INLEVEL if (lua_type(L, 2) == LUA_TNUMBER) { lua_Integer i = luaL_checkinteger(L, 2); diff --git a/src/lua_thinkerlib.c b/src/lua_thinkerlib.c index 63eb15846..8fa2869c8 100644 --- a/src/lua_thinkerlib.c +++ b/src/lua_thinkerlib.c @@ -16,6 +16,9 @@ #include "lua_script.h" #include "lua_libs.h" +#define INLEVEL if (gamestate != GS_LEVEL && !titlemapinaction)\ +return luaL_error(L, "This function can only be used in a level!"); + #define META_ITERATIONSTATE "iteration state" /*static const char *const iter_opt[] = { @@ -56,8 +59,7 @@ static int lib_iterateThinkers(lua_State *L) thinker_t *th = NULL, *next = NULL; struct iterationState *it; - if (gamestate != GS_LEVEL) - return luaL_error(L, "This function can only be used in a level!"); + INLEVEL it = luaL_checkudata(L, 1, META_ITERATIONSTATE); @@ -112,8 +114,7 @@ static int lib_startIterate(lua_State *L) { struct iterationState *it; - if (gamestate != GS_LEVEL) - return luaL_error(L, "This function can only be used in a level!"); + INLEVEL lua_pushvalue(L, lua_upvalueindex(1)); it = lua_newuserdata(L, sizeof(struct iterationState));