diff --git a/src/lua_infolib.c b/src/lua_infolib.c index 25241f66f..555bf3196 100644 --- a/src/lua_infolib.c +++ b/src/lua_infolib.c @@ -268,20 +268,6 @@ static UINT8 GetPivotFrame(lua_State *L, int idx) return frame; } -static int PushCast(lua_State *L, const char *meta) -{ - // bypass LUA_PushUserdata - void **userdata = lua_newuserdata(L, sizeof(void *)); - - *userdata = lua_touserdata(L, 1); - - luaL_getmetatable(L, meta); - lua_setmetatable(L, -2); - - // stack is left with the userdata on top, as if getting it had originally succeeded. - return 1; -} - // spriteinfo[] static int lib_getSpriteInfo(lua_State *L) { @@ -470,15 +456,23 @@ static int lib_spriteinfolen(lua_State *L) // spriteinfo_t static int spriteinfo_get(lua_State *L) { + spriteinfo_t *sprinfo = *((spriteinfo_t **)luaL_checkudata(L, 1, META_SPRITEINFO)); const char *field = luaL_checkstring(L, 2); - luaL_checkudata(L, 1, META_SPRITEINFO); + I_Assert(sprinfo != NULL); // push spriteframepivot_t userdata if (fastcmp(field, "pivot")) - return PushCast(L, META_PIVOTLIST); - else if (fastcmp(field, "brightmap")) - return PushCast(L, META_SPRITEBRIGHTLIST); + { + // bypass LUA_PushUserdata + void **userdata = lua_newuserdata(L, sizeof(void *)); + *userdata = sprinfo; + luaL_getmetatable(L, META_PIVOTLIST); + lua_setmetatable(L, -2); + + // stack is left with the userdata on top, as if getting it had originally succeeded. + return 1; + } else return luaL_error(L, LUA_QL("spriteinfo_t") " has no field named " LUA_QS, field); @@ -648,29 +642,6 @@ static int framepivot_num(lua_State *L) return 1; } -static int brightlist_get(lua_State *L) -{ - const spriteinfo_t *sprinfo = *((spriteinfo_t **)luaL_checkudata(L, 1, META_SPRITEBRIGHTLIST)); - const UINT8 frame = GetPivotFrame(L, 2); - - lua_pushstring(L, sprinfo->bright[frame]); - - return 1; -} - -static int brightlist_set(lua_State *L) -{ - spriteinfo_t *sprinfo = *((spriteinfo_t **)luaL_checkudata(L, 1, META_SPRITEBRIGHTLIST)); - - const UINT8 frame = GetPivotFrame(L, 2); - const char *val = luaL_checkstring(L, 3); - - Z_Free(sprinfo->bright[frame]); - sprinfo->bright[frame] = Z_StrDup(val); - - return 0; -} - //////////////// // STATE INFO // //////////////// @@ -2125,17 +2096,6 @@ int LUA_InfoLib(lua_State *L) lua_setfield(L, -2, "__len"); lua_pop(L, 1); - luaL_newmetatable(L, META_SPRITEBRIGHTLIST); - lua_pushcfunction(L, brightlist_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, brightlist_set); - lua_setfield(L, -2, "__newindex"); - - lua_pushcfunction(L, pivotlist_num); - lua_setfield(L, -2, "__len"); - lua_pop(L, 1); - luaL_newmetatable(L, META_PRECIPPROPS); lua_pushcfunction(L, precipprops_get); lua_setfield(L, -2, "__index"); diff --git a/src/lua_libs.h b/src/lua_libs.h index 6a28e85fa..0cc818739 100644 --- a/src/lua_libs.h +++ b/src/lua_libs.h @@ -28,7 +28,6 @@ extern lua_State *gL; #define META_SPRITEINFO "SPRITEINFO_T*" #define META_PIVOTLIST "SPRITEFRAMEPIVOT_T[]" #define META_FRAMEPIVOT "SPRITEFRAMEPIVOT_T*" -#define META_SPRITEBRIGHTLIST "SPRITEBRIGHTMAP_T[]" #define META_PRECIPPROPS "PRECIPPROPS_T*" #define META_TAGLIST "TAGLIST"