satoren / kaguya

C++ binding to Lua
Boost Software License 1.0
345 stars 70 forks source link

Passing a LuaRef from a kaguya::State to another kaguya::State #66

Closed Sygmei closed 7 years ago

Sygmei commented 7 years ago

How to pass a value from one state to another ? Using kaguya::LuaRef doesn't work, is there another way ?

kaguya::State luaP;
kaguya::State luaQ;
luaP("test = \"hello\"");
kaguya::LuaRef retainValue = luaP["test"];
luaQ["test"] = test;
luaQ("print(test)");

Doing it like that works but I want to store a kaguya::LuaRef or something like that

kaguya::State luaP;
kaguya::State luaQ;
luaP("test = \"hello\"");
luaQ["test"] = luaP["test"];
luaQ("print(test)");
Sygmei commented 7 years ago

I get the following error :

Assertion failed: util::toMainThread(state) == util::toMainThread(ref_.state()), file lua_ref_impl.hpp, line 297
satoren commented 7 years ago

Normally you can not. but you can try serialization.

https://www.lua.org/pil/12.1.html http://lua-users.org/wiki/TableSerialization

Remember that some type can not be serialized.(e.g function)

Sygmei commented 7 years ago

Then why passing from one LuaState to another works ?

luaP["something"] = luaQ["somethingelse"];
satoren commented 7 years ago

Lua has not that feature.

Sygmei commented 7 years ago

Okay, thanks :) Good job for your lib by the way, it's really comfortable to use