Код: Выделить всё
#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]