0

I have seen a few other posts, but they are the opposite of what I want to do. I simply have an array of ints in my lua file, and I want to know how I change that into a c# array. Using lua ["ints[1]"] throws an exception.

I think this would be very useful to know for many people, as it could be used for tilemaps, or many things really.

Osuology
  • 1
  • 1
  • Could You please provide full code example and the exception itself? – Kamiccolo Dec 13 '16 at 13:12
  • [Here](http://pastebin.com/NTmpW7Bn) I am just trying to read id's from a file into a 2D array in the same order, using a lua file. But, using the lua ["codeid"] with lua arrays causes an NullReferenceError. – Osuology Dec 14 '16 at 16:49

1 Answers1

0

The array of integers you have on the Lua side is just a Lua table and on the C# side it's a LuaTable type.

Do this:

lua.DoString(@"
    my_array = { 1, 2, 3, 4 }
");

LuaTable myArray = (LuaTable) lua["my_array"];

foreach(var val in myArray.Values)
{
    Console.WriteLine(val);
}

Result:

enter image description here

Frank Hale
  • 1,886
  • 1
  • 17
  • 31