From 5203133f72480023247fc13d41938770ce09d749 Mon Sep 17 00:00:00 2001 From: Lactozilla Date: Thu, 30 Nov 2023 19:13:26 -0300 Subject: [PATCH] Remove Lua lighttable --- src/lua_baselib.c | 1 - src/lua_colorlib.c | 48 ++-------------------------------------------- src/lua_libs.h | 1 - 3 files changed, 2 insertions(+), 48 deletions(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 9c723353b..35798e688 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -214,7 +214,6 @@ static const struct { {META_PATCH, "patch_t"}, {META_COLORMAP, "colormap"}, {META_EXTRACOLORMAP,"extracolormap_t"}, - {META_LIGHTTABLE, "lighttable_t"}, {META_CAMERA, "camera_t"}, {META_ACTION, "action"}, diff --git a/src/lua_colorlib.c b/src/lua_colorlib.c index 1e6e82333..bf9c33886 100644 --- a/src/lua_colorlib.c +++ b/src/lua_colorlib.c @@ -93,8 +93,7 @@ enum extracolormap_e { extracolormap_fade_alpha, extracolormap_fade_color, extracolormap_fade_start, - extracolormap_fade_end, - extracolormap_colormap + extracolormap_fade_end }; static const char *const extracolormap_opt[] = { @@ -110,7 +109,6 @@ static const char *const extracolormap_opt[] = { "fade_color", "fade_start", "fade_end", - "colormap", NULL}; static int extracolormap_get(lua_State *L) @@ -162,9 +160,6 @@ static int extracolormap_get(lua_State *L) case extracolormap_fade_end: lua_pushinteger(L, exc->fadeend); break; - case extracolormap_colormap: - LUA_PushUserdata(L, exc->colormap, META_LIGHTTABLE); - break; } return 1; } @@ -272,8 +267,6 @@ static int extracolormap_set(lua_State *L) return luaL_error(L, "fade end %d out of range (0 - 31)", val); exc->fadeend = val; break; - case extracolormap_colormap: - return luaL_error(L, LUA_QL("extracolormap_t") " field " LUA_QS " should not be set directly.", extracolormap_opt[field]); } #undef val @@ -287,46 +280,9 @@ static int extracolormap_set(lua_State *L) return 0; } -static int lighttable_get(lua_State *L) -{ - void **userdata; - - lighttable_t *table = *((lighttable_t **)luaL_checkudata(L, 1, META_LIGHTTABLE)); - UINT32 row = luaL_checkinteger(L, 2); - if (row < 1 || row > 34) - return luaL_error(L, "lighttable row %d out of range (1 - %d)", row, 34); - - userdata = lua_newuserdata(L, sizeof(void *)); - *userdata = &table[256 * (row - 1)]; - luaL_getmetatable(L, META_COLORMAP); - lua_setmetatable(L, -2); - - return 1; -} - -static int lighttable_len(lua_State *L) -{ - lua_pushinteger(L, NUM_PALETTE_ENTRIES); - return 1; -} - int LUA_ColorLib(lua_State *L) { - luaL_newmetatable(L, META_EXTRACOLORMAP); - lua_pushcfunction(L, extracolormap_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, extracolormap_set); - lua_setfield(L, -2, "__newindex"); - lua_pop(L, 1); - - luaL_newmetatable(L, META_LIGHTTABLE); - lua_pushcfunction(L, lighttable_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, lighttable_len); - lua_setfield(L, -2, "__len"); - lua_pop(L, 1); + LUA_RegisterUserdataMetatable(L, META_EXTRACOLORMAP, extracolormap_get, extracolormap_set, NULL); return 0; } diff --git a/src/lua_libs.h b/src/lua_libs.h index 26f919ad8..a90d8ac7f 100644 --- a/src/lua_libs.h +++ b/src/lua_libs.h @@ -86,7 +86,6 @@ extern boolean ignoregameinputs; #define META_PATCH "PATCH_T*" #define META_COLORMAP "COLORMAP" #define META_EXTRACOLORMAP "EXTRACOLORMAP_T*" -#define META_LIGHTTABLE "LIGHTTABLE_T*" #define META_CAMERA "CAMERA_T*" #define META_ACTION "ACTIONF_T*"