I store an object by a function call from Lua to C++ in first script in my application and after that I'll try to pass that object to other scripts and vice versa.
A part of script class in C++:
void script::set_property(lua_State* L, luabind::argument const& value)
{
this->property_field = luabind::object(L, value);
}
luabind::object script::get_property(lua_State* L)
{
return this->property_field;
}
Then in my script which is Script1.lua I do this:
script1:set_property(a table or a userdata or a string)
print(type(script1:get_property()))
The problem is, values sent by scripts are distinct in different Lua states because every script in my application has its own lua_State
. The above code works fine when I call script::get_property
from Script1.lua
.
Since all of my scripts have access to other scripts in their contexts when I try to do this in other scripts like Script2.lua or Script3.lua or others:
print(type(script1:get_property()))
It won't print data type here properly and it'll return a number instead, which is a wrong result and the reason is script1:get_property()
is returning a value that is only understood by script1
and not in other scripts.
I understand values that have been registered in script1
are only registered into that script's stack and registry table particularly and no one else, but my question is, is there any way to transfer these values between different Lua states?
Thanks.
luabind::object
is for its generic behavior. The whole thing that I've presented here is just an example of what I'm trying to express because the actual project is more complex than this. And, I don't think there would be any flaw in here. \$\endgroup\$