2

I am new to LuaInterface and have a very simple question: How can I access data from a multi dimensional lua table from c#? I managed to read strings and integer values but was not lucky with tables. My goal is to display the content of a multidimensional lua table in a (virtual) GridView.

Sorry, I think this is a really simple question but I was unable to find neither a good documentation nor a compileable example project. You can also point me to the documentation if you think I should RTFM first before asking here - but I could not find any.

thanks, Michael

greatwolf
  • 20,287
  • 13
  • 71
  • 105

1 Answers1

0

LuaInterface wrapped the Table type to LuaTable. So, if you define a multi dimensional table in Lua

t = {}
t[1] = {}
t[1][1] = 888
ShowTable(t)     -- assume ShowTable is a C# function

You can use the code below to access lua table in C#

public void ShowTable(LuaTable t)
{
    LuaTable t1 = t[1];
    Console.WriteLine(t1[1]);   // should display 888
    t.Dispose();                  // Don't forget to Dispose the table sent from Lua to C#, or memory leak happens!
}
WAKU
  • 290
  • 3
  • 17