mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 12:49:18 +02:00
Fix a segfault when calling api.dynobj_putvalues()
An undocumented change from the previous commit: - When the Lua script is not able to find an object, the message is now printed to `errors.txt`, not just to `log.txt`.
This commit is contained in:
@@ -98,6 +98,27 @@ void lua::push_memcell_values(lua_State *L, const TMemCell *mc)
|
|||||||
lua_settable(L, -3);
|
lua_settable(L, -3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memcell_values lua::get_memcell_values(lua_State *L)
|
||||||
|
{
|
||||||
|
memcell_values mc{nullptr, 0.0, 0.0};
|
||||||
|
lua_pushstring(L, "str");
|
||||||
|
lua_gettable(L, -2);
|
||||||
|
if (lua_isstring(L, -1))
|
||||||
|
mc.str = lua_tostring(L, -1);
|
||||||
|
lua_pop(L, 1);
|
||||||
|
lua_pushstring(L, "num1");
|
||||||
|
lua_gettable(L, -2);
|
||||||
|
if (lua_isnumber(L, -1))
|
||||||
|
mc.num1 = lua_tonumber(L, -1);
|
||||||
|
lua_pop(L, 1);
|
||||||
|
lua_pushstring(L, "num2");
|
||||||
|
lua_gettable(L, -2);
|
||||||
|
if (lua_isnumber(L, -1))
|
||||||
|
mc.num2 = lua_tonumber(L, -1);
|
||||||
|
lua_pop(L, 1);
|
||||||
|
return mc;
|
||||||
|
}
|
||||||
|
|
||||||
int lua::scriptapi_event_create(lua_State *L)
|
int lua::scriptapi_event_create(lua_State *L)
|
||||||
{
|
{
|
||||||
std::string name = lua_tostring(L, 1);
|
std::string name = lua_tostring(L, 1);
|
||||||
@@ -261,17 +282,14 @@ int lua::scriptapi_train_getname(lua_State *L)
|
|||||||
int lua::scriptapi_dynobj_putvalues(lua_State *L)
|
int lua::scriptapi_dynobj_putvalues(lua_State *L)
|
||||||
{
|
{
|
||||||
auto *dyn = static_cast<TDynamicObject *>(lua_touserdata(L, 1));
|
auto *dyn = static_cast<TDynamicObject *>(lua_touserdata(L, 1));
|
||||||
auto *mc = static_cast<memcell_values *>(lua_touserdata(L, 2));
|
auto [str, num1, num2] = get_memcell_values(L);
|
||||||
std::string str = mc->str;
|
|
||||||
double num1 = mc->num1;
|
|
||||||
double num2 = mc->num2;
|
|
||||||
if (!dyn)
|
if (!dyn)
|
||||||
return 0;
|
return 0;
|
||||||
TLocation loc{};
|
TLocation loc{};
|
||||||
if (dyn->Mechanik)
|
if (dyn->Mechanik)
|
||||||
dyn->Mechanik->PutCommand(std::string(str), num1, num2, loc);
|
dyn->Mechanik->PutCommand(str, num1, num2, loc);
|
||||||
else
|
else
|
||||||
dyn->MoverParameters->PutCommand(std::string(str), num1, num2, loc);
|
dyn->MoverParameters->PutCommand(str, num1, num2, loc);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
class basic_event;
|
class basic_event;
|
||||||
class TMemCell;
|
class TMemCell;
|
||||||
class TDynamicObject;
|
class TDynamicObject;
|
||||||
|
struct memcell_values { const char *str; double num1; double num2; };
|
||||||
|
|
||||||
class lua
|
class lua
|
||||||
{
|
{
|
||||||
@@ -44,6 +45,5 @@ public:
|
|||||||
static void unref(lua_State *L, int ref);
|
static void unref(lua_State *L, int ref);
|
||||||
static void dispatch_event(lua_State *L, int handler, basic_event *event, const TDynamicObject *activator);
|
static void dispatch_event(lua_State *L, int handler, basic_event *event, const TDynamicObject *activator);
|
||||||
static void push_memcell_values(lua_State *L, const TMemCell *mc);
|
static void push_memcell_values(lua_State *L, const TMemCell *mc);
|
||||||
|
static memcell_values get_memcell_values(lua_State *L);
|
||||||
struct memcell_values { const char *str; double num1; double num2; };
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user