0

I set up the following method to reproduce a problem I am having where passing a table from one lua state through a function parameter in another results in the table being null.

In this case the table seems to be being interpreted as a function. I have no idea why.

Lua scope = new Lua();
Lua scope2 = new Lua();
scope2.DoString("t = { Data = 3 }");
scope.DoString("function values(key, model) return key, model end");
var func = (LuaFunction)scope["values"];
var t = (LuaTable)scope2["t"];
object[] results = func.Call("Hello", t);
var tableFunc = results[1] as LuaFunction;
var tableTable = results[1] as LuaTable;
object[] tableFuncResult = tableFunc.Call();

The value of tableFuncResult after running this snippet is an object array { null, null }. tableTable is null. Instead tableFunc should be null and tableTable should contain the table defined in scope2.

Kelson Ball
  • 948
  • 1
  • 13
  • 30
  • Isn't the point of states that they're fully separate? Does the documentation say this should work? – user253751 Aug 02 '16 at 02:36
  • @immibis The project does not seem fully spec'd. There does appear to be an integer reference id in the private data of the LuaTable type that is probably causing the conflict. If it points to reference 1 in scope1, and reference 1 in scope2 is the function 'values', then calling values with no parameters would return { null, null }. Copying data rather than passing a reference between scopes might solve my issue. Thank you! – Kelson Ball Aug 02 '16 at 04:09

0 Answers0