From 0f2e063de018ab40502a438afcb52e791669a9f4 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 13 Sep 2020 21:38:16 +0100 Subject: [PATCH] Added the ability to modify parent, flags, translucency in polyobj_t (attempting to edit polyobj.angle just gives you an error message saying to use polyobj:rotate() instead) --- src/lua_polyobjlib.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/lua_polyobjlib.c b/src/lua_polyobjlib.c index b0f22e74f..c4dfa8ae4 100644 --- a/src/lua_polyobjlib.c +++ b/src/lua_polyobjlib.c @@ -333,7 +333,33 @@ static int polyobj_get(lua_State *L) static int polyobj_set(lua_State *L) { - return luaL_error(L, LUA_QL("polyobj_t") " struct cannot be edited by Lua."); // this is just temporary + polyobj_t *polyobj = *((polyobj_t **)luaL_checkudata(L, 1, META_POLYOBJ)); + enum polyobj_e field = luaL_checkoption(L, 2, NULL, polyobj_opt); + + if (!polyobj) + return LUA_ErrInvalid(L, "polyobj_t"); + + if (hud_running) + return luaL_error(L, "Do not alter polyobj_t in HUD rendering code!"); + + switch (field) + { + default: + return luaL_error(L, LUA_QL("polyobj_t") " field " LUA_QS " cannot be modified.", polyobj_opt[field]); + case polyobj_angle: + return luaL_error(L, LUA_QL("polyobj_t") " field " LUA_QS " should not be set directly. Use the function " LUA_QL("polyobj:rotate(angle)") " instead.", polyobj_opt[field]); + case polyobj_parent: + polyobj->parent = luaL_checkinteger(L, 3); + break; + case polyobj_flags: + polyobj->flags = luaL_checkinteger(L, 3); + break; + case polyobj_translucency: + polyobj->translucency = luaL_checkinteger(L, 3); + break; + } + + return 0; } static int polyobj_num(lua_State *L)