16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-18 00:49:19 +02:00

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.
This commit is contained in:
jakubg1
2026-04-01 02:37:58 +02:00
parent 686cab8184
commit 2a9343149f

View File

@@ -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<TMemCell *>(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;
}