Передача NestedStruct из С++ в LuaC++

Программы на C++. Форум разработчиков
Anonymous
Передача NestedStruct из С++ в Lua

Сообщение Anonymous »

Я пытаюсь сопоставить адрес функции С++ с помощью lua, чтобы можно было выполнить оперативное исправление, но я могу правильно передать вложенную структуру в lua (я думаю, потому что я печатаю таблицу перед вызовом функции lua), но я получил ошибку Lua: попытка вызвать нулевое значение. Что не так?

Код: Выделить всё

#include 
#include 
#include 
#include 

struct NestedData {
int a;
float b;
};

struct ComplexData {
int id;
std::string name;
NestedData nested;
};

void stack_struct(lua_State* L, const ComplexData& data) {
lua_newtable(L);

lua_pushstring(L, "id");
lua_pushinteger(L, data.id);
lua_settable(L, -3);

lua_pushstring(L, "name");
lua_pushstring(L, data.name.c_str());
lua_settable(L, -3);

lua_pushstring(L, "nested");
{
lua_newtable(L);

lua_pushstring(L, "a");
lua_pushinteger(L, data.nested.a);
lua_settable(L, -3);

lua_pushstring(L, "b");
lua_pushnumber(L, data.nested.b);
lua_settable(L, -3);

lua_settable(L, -3);
}
}

int main() {
lua_State* L = luaL_newstate();
luaL_openlibs(L);
std::unordered_map SkillMap;
std::string script_name = "register.lua";
std::string func_name = "WaterBall";
int64_t id = 100;
if (!L) {
std::cerr 

Подробнее здесь: [url]https://stackoverflow.com/questions/79261190/pass-nestedstruct-from-c-to-lua[/url]

Вернуться в «C++»