From 797b0adecd0534ae2616afbca74a1acff64a56ce Mon Sep 17 00:00:00 2001 From: GenericHeroGuy Date: Mon, 1 Dec 2025 22:42:43 +0100 Subject: [PATCH] Whoops, forgot about voices still being writable from kartvoice_t which means kartvoice_t no longer has any writable fields, so gut the setter --- src/lua_voicelib.c | 82 ++++++++-------------------------------------- 1 file changed, 13 insertions(+), 69 deletions(-) diff --git a/src/lua_voicelib.c b/src/lua_voicelib.c index 7e7e809bb..9fd9e628d 100644 --- a/src/lua_voicelib.c +++ b/src/lua_voicelib.c @@ -9,8 +9,8 @@ // terms of the GNU General Public License, version 2. // See the 'LICENSE' file for more details. //----------------------------------------------------------------------------- -/// \file lua_waypointslib.c -/// \brief wapoint structure library for Lua scripting +/// \file lua_voicelib.c +/// \brief voice structure library for Lua scripting #include "doomdef.h" #include "fastcmp.h" @@ -26,7 +26,7 @@ enum voicevars { voicevars_id = 0, - voicevars_name, // Not actually in kartvoice_t; returns the name of the voice + voicevars_name, voicevars_win, voicevars_lose, voicevars_pain, @@ -52,12 +52,7 @@ static const char *const voicevars_opt[] = { }; #define RNOFIELD luaL_error(L, LUA_QL("kartvoice_t") " has no field named " LUA_QS, field) - -#define RNOSET luaL_error(L, LUA_QL("kartvoice_t") " field " LUA_QS " cannot be set.", field) #define RNOGET luaL_error(L, LUA_QL("kartvoice_t") " field " LUA_QS " cannot be get.", field) -#define NOSET luaL_error(L, LUA_QL("kartvoice_t") " field " LUA_QS " should not be set directly.", field) - -#define UNIMPLEMENTED luaL_error(L, LUA_QL("kartvoice_t") " field " LUA_QS " is not implemented for Lua and cannot be accessed.", voicevars_opt[field]) static int voice_get(lua_State* L) { @@ -105,64 +100,6 @@ static int voice_get(lua_State* L) return 1; } -static int voice_set(lua_State* L) -{ - kartvoice_t* voice = *((kartvoice_t**)luaL_checkudata(L, 1, META_VOICE)); - enum voicevars field = luaL_checkoption(L, 2, voicevars_opt[0], voicevars_opt); - - // voices are always valid, only added, never removed - I_Assert(voice != NULL); - - if (hud_running) - return luaL_error(L, "Do not alter kartvoice_t in HUD rendering code!"); - if (hook_cmd_running) - return luaL_error(L, "Do not alter kartvoice_t in CMD building code!"); - - lua_Integer i, k; - - i = 0; - k = sfx_thok; - - switch (field) - { - case voicevars_id: - return RNOSET; - case voicevars_name: - return RNOSET; - case voicevars_win: - // For the actual sound values, you pass the actual sfxenum_t enums. - // Yes, I know what I said about skin structs literally just above. - voice->win = (sfxenum_t)luaL_checkinteger(L, 3); - break; - case voicevars_lose: - voice->lose = (sfxenum_t)luaL_checkinteger(L, 3); - break; - case voicevars_pain: - return NOSET; - case voicevars_attack: - return NOSET; - case voicevars_boost: - return NOSET; - case voicevars_overtake: - voice->overtake = (sfxenum_t)luaL_checkinteger(L, 3); - break; - case voicevars_hitem: - voice->hitem = (sfxenum_t)luaL_checkinteger(L, 3); - break; - case voicevars_power: - voice->power = (sfxenum_t)luaL_checkinteger(L, 3); - break; - default: - return RNOFIELD; - } - - return 0; -} - -#undef RNOSET -#undef RNOFIELD -#undef UNIMPLEMENTED - static int voice_num(lua_State* L) { kartvoice_t* voice = *((kartvoice_t**)luaL_checkudata(L, 1, META_VOICE)); @@ -192,6 +129,11 @@ static int voice_array_set(lua_State *L) sfxenum_t *voice_array = *((sfxenum_t **)luaL_checkudata(L, 1, META_VOICE_ARRAY)); INT32 i = luaL_checkinteger(L, 2); + if (hud_running) + return luaL_error(L, "Do not alter kartvoice_t.array[] in HUD rendering code!"); + if (hook_cmd_running) + return luaL_error(L, "Do not alter kartvoice_t.array[] in CMD building code!"); + if (i < 0 || i >= VOICEARRAYSIZE) return luaL_error(L, "index %d out of range (0 - %d)", i, VOICEARRAYSIZE-1); @@ -227,6 +169,11 @@ static int voice_array1_set(lua_State *L) sfxenum_t *voice_array = *((sfxenum_t **)luaL_checkudata(L, 1, META_VOICE_ARRAY1)); INT32 i = luaL_checkinteger(L, 2); + if (hud_running) + return luaL_error(L, "Do not alter kartvoice_t.array[1] in HUD rendering code!"); + if (hook_cmd_running) + return luaL_error(L, "Do not alter kartvoice_t.array[1] in CMD building code!"); + if (i < 0 || i >= 1) return luaL_error(L, "index %d out of range (0 - %d)", i, 1-1); @@ -247,9 +194,6 @@ int LUA_VoiceLib(lua_State* L) lua_pushcfunction(L, voice_get); lua_setfield(L, -2, "__index"); - lua_pushcfunction(L, voice_set); - lua_setfield(L, -2, "__newindex"); - lua_pushcfunction(L, voice_num); lua_setfield(L, -2, "__len"); lua_pop(L, 1);