From 7d5a8ac14b62378ed56b5e6e643ac3ecdb576d6d Mon Sep 17 00:00:00 2001 From: James R Date: Wed, 15 Jan 2020 19:13:41 -0800 Subject: [PATCH 1/3] Allow G_BuildMapName outside of levels --- src/lua_baselib.c | 21 +++++++++++++++++++-- src/lua_script.h | 5 ++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 2a82ec512..d4d6e1a6d 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -2772,11 +2772,28 @@ static int lib_gAddGametype(lua_State *L) return 0; } +static int Lcheckmapnumber (lua_State *L, int idx) +{ + if (ISINLEVEL) + return luaL_optinteger(L, idx, gamemap); + else + { + if (lua_isnoneornil(L, idx)) + { + return luaL_error(L, + "G_BuildMapName can only be used " + "without a parameter while in a level." + ); + } + else + return luaL_checkinteger(L, idx); + } +} + static int lib_gBuildMapName(lua_State *L) { - INT32 map = luaL_optinteger(L, 1, gamemap); + INT32 map = Lcheckmapnumber(L, 1); //HUDSAFE - INLEVEL lua_pushstring(L, G_BuildMapName(map)); return 1; } diff --git a/src/lua_script.h b/src/lua_script.h index 8f27dcb4c..7d8aaa282 100644 --- a/src/lua_script.h +++ b/src/lua_script.h @@ -100,7 +100,10 @@ void COM_Lua_f(void); // uncomment if you want seg_t/node_t in Lua // #define HAVE_LUA_SEGS -#define INLEVEL if (gamestate != GS_LEVEL && !titlemapinaction)\ +#define ISINLEVEL \ + (gamestate == GS_LEVEL || titlemapinaction) + +#define INLEVEL if (! ISINLEVEL)\ return luaL_error(L, "This can only be used in a level!"); #endif From 50b18acd3f08012d313ced34e946f7c30a2ea313 Mon Sep 17 00:00:00 2001 From: James R Date: Wed, 15 Jan 2020 20:04:50 -0800 Subject: [PATCH 2/3] Expose G_BuildMapTitle to Lua --- src/lua_baselib.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index d4d6e1a6d..106fcb761 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -2772,7 +2772,7 @@ static int lib_gAddGametype(lua_State *L) return 0; } -static int Lcheckmapnumber (lua_State *L, int idx) +static int Lcheckmapnumber (lua_State *L, int idx, const char *fun) { if (ISINLEVEL) return luaL_optinteger(L, idx, gamemap); @@ -2781,8 +2781,8 @@ static int Lcheckmapnumber (lua_State *L, int idx) if (lua_isnoneornil(L, idx)) { return luaL_error(L, - "G_BuildMapName can only be used " - "without a parameter while in a level." + "%s can only be used without a parameter while in a level.", + fun ); } else @@ -2792,12 +2792,30 @@ static int Lcheckmapnumber (lua_State *L, int idx) static int lib_gBuildMapName(lua_State *L) { - INT32 map = Lcheckmapnumber(L, 1); + INT32 map = Lcheckmapnumber(L, 1, "G_BuildMapName"); //HUDSAFE lua_pushstring(L, G_BuildMapName(map)); return 1; } +static int lib_gBuildMapTitle(lua_State *L) +{ + INT32 map = Lcheckmapnumber(L, 1, "G_BuoldMapTitle"); + char *name; + if (map < 1 || map > NUMMAPS) + { + return luaL_error(L, + "map number %d out of range (1 - %d)", + map, + NUMMAPS + ); + } + name = G_BuildMapTitle(map); + lua_pushstring(L, name); + Z_Free(name); + return 1; +} + static int lib_gDoReborn(lua_State *L) { INT32 playernum = luaL_checkinteger(L, 1); @@ -3174,6 +3192,7 @@ static luaL_Reg lib[] = { // g_game {"G_AddGametype", lib_gAddGametype}, {"G_BuildMapName",lib_gBuildMapName}, + {"G_BuildMapTitle",lib_gBuildMapTitle}, {"G_DoReborn",lib_gDoReborn}, {"G_SetCustomExitVars",lib_gSetCustomExitVars}, {"G_EnoughPlayersFinished",lib_gEnoughPlayersFinished}, From b7b24eb5d70bd738b27767fceb11514cddf519c8 Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 18 Jan 2020 15:56:03 -0800 Subject: [PATCH 3/3] Buold. --- src/lua_baselib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 106fcb761..35ea6db0c 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -2800,7 +2800,7 @@ static int lib_gBuildMapName(lua_State *L) static int lib_gBuildMapTitle(lua_State *L) { - INT32 map = Lcheckmapnumber(L, 1, "G_BuoldMapTitle"); + INT32 map = Lcheckmapnumber(L, 1, "G_BuildMapTitle"); char *name; if (map < 1 || map > NUMMAPS) {