How do I pass a LuaTable between two Lua states using LuaInterface?
Posted
by user316675
on Stack Overflow
See other posts from Stack Overflow
or by user316675
Published on 2010-04-14T23:26:33Z
Indexed on
2010/04/14
23:33 UTC
Read the original article
Hit count: 330
c#
|luainterface
I've been trying to pass a LuaTable class between two Lua states, like so:
LuaManager L1 = new Lua();
LuaManager L2 = new Lua();
LuaTable table = L1.DoString("return {apple = 25}")[0];
L2["tbl"] = table;
double results = L2.DoString("return tbl[\"apple\"]")[0];
Assert.AreEqual(25.0, results);
The above test fails; I receive a return value of nil. Using the Immediate Window confirms that "table" is a non-null object, and that table["apple"] returns 25; it's something that's being lost in translation to L2.
Interestingly, when the object is loaded back into the same state, the test works, like so:
//Succeeds
LuaManager lua = new Lua();
LuaTable table = lua.DoString("return {apple = 25}")[0];
lua["tbl"] = table;
double results = lua.DoString("return tbl[\"apple\"]")[0];
Assert.AreEqual(25.0, results);
How can I safely pass the LuaTables without hassles? Thanks in advance!
© Stack Overflow or respective owner