From 2a9343149f5061a88ef500dded78dfe823d59cef Mon Sep 17 00:00:00 2001 From: jakubg1 <24206305+jakubg1@users.noreply.github.com> Date: Wed, 1 Apr 2026 02:37:58 +0200 Subject: [PATCH] Fix Lua memcell API - Fixed the `api.memcell_update` and `api.memcell_update_n` functions to accept the `memcell_values` structure instead of three separate values. - Additionally, also fixed the error message for when the memcell is not found. --- scripting/lua.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/scripting/lua.cpp b/scripting/lua.cpp index 91fb8df2..1c79b1c1 100644 --- a/scripting/lua.cpp +++ b/scripting/lua.cpp @@ -326,9 +326,7 @@ int lua::scriptapi_memcell_read_n(lua_State *L) int lua::scriptapi_memcell_update(lua_State *L) { auto *mc = static_cast(lua_touserdata(L, 1)); - std::string str = lua_tostring(L, 2); - double num1 = lua_tonumber(L, 3); - double num2 = lua_tonumber(L, 4); + auto [str, num1, num2] = get_memcell_values(L); if (mc) mc->UpdateValues(str, num1, num2, basic_event::flags::text | basic_event::flags::value1 | basic_event::flags::value2); @@ -338,15 +336,13 @@ int lua::scriptapi_memcell_update(lua_State *L) int lua::scriptapi_memcell_update_n(lua_State *L) { std::string mstr = lua_tostring(L, 1); - std::string str = lua_tostring(L, 2); - double num1 = lua_tonumber(L, 3); - double num2 = lua_tonumber(L, 4); + auto [str, num1, num2] = get_memcell_values(L); TMemCell *mc = simulation::Memory.find(mstr); if (mc) mc->UpdateValues(str, num1, num2, basic_event::flags::text | basic_event::flags::value1 | basic_event::flags::value2); else - ErrorLog("lua: missing memcell: " + str); + ErrorLog("lua: missing memcell: " + mstr); return 0; }