From 6d02aac2103da321ebf3e7414357e096a613113f Mon Sep 17 00:00:00 2001 From: toaster Date: Fri, 31 Mar 2023 14:36:16 +0100 Subject: [PATCH] Hardcode assist, part 1 - Add read-only `string` field to several info table metatables already available in Lua. - mobjinfo[i].name - states[i].name - sfxinfo[i].string --- src/lua_infolib.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/lua_infolib.c b/src/lua_infolib.c index 0b8359065..1982a5af8 100644 --- a/src/lua_infolib.c +++ b/src/lua_infolib.c @@ -43,7 +43,8 @@ enum sfxinfo_read { sfxinfor_flags, // "pitch" sfxinfor_volume, sfxinfor_caption, - sfxinfor_skinsound + sfxinfor_skinsound, + sfxinfor_string, }; const char *const sfxinfo_ropt[] = { "name", @@ -53,6 +54,7 @@ const char *const sfxinfo_ropt[] = { "volume", "caption", "skinsound", + "string", NULL}; enum sfxinfo_write { @@ -923,6 +925,24 @@ static int state_get(lua_State *L) number = st->var2; else if (fastcmp(field,"nextstate")) number = st->nextstate; + else if (fastcmp(field,"string")) + { + statenum_t id = st-states; + if (id < S_FIRSTFREESLOT) + { + lua_pushstring(L, STATE_LIST[id]+2); + return 1; + } + + id -= S_FIRSTFREESLOT; + if (id < NUMSTATEFREESLOTS && FREE_STATES[id]) + { + lua_pushstring(L, FREE_STATES[id]); + return 1; + } + + return 0; + } else if (devparm) return luaL_error(L, LUA_QL("state_t") " has no field named " LUA_QS, field); else @@ -1188,6 +1208,23 @@ static int mobjinfo_get(lua_State *L) lua_pushinteger(L, info->flags); else if (fastcmp(field,"raisestate")) lua_pushinteger(L, info->raisestate); + else if (fastcmp(field,"string")) { + mobjtype_t id = info-mobjinfo; + if (id < MT_FIRSTFREESLOT) + { + lua_pushstring(L, MOBJTYPE_LIST[id]+3); + return 1; + } + + id -= MT_FIRSTFREESLOT; + if (id < NUMMOBJFREESLOTS && FREE_MOBJS[id]) + { + lua_pushstring(L, FREE_MOBJS[id]); + return 1; + } + + return 0; + } else { lua_getfield(L, LUA_REGISTRYINDEX, LREG_EXTVARS); I_Assert(lua_istable(L, -1)); @@ -1411,6 +1448,10 @@ static int sfxinfo_get(lua_State *L) case sfxinfor_skinsound: lua_pushinteger(L, sfx->skinsound); return 1; + case sfxinfor_string: { + lua_pushstring(L, sfx->name); + return 1; + } default: return luaL_error(L, "Field does not exist in sfxinfo_t"); }