I am at a complete loss with the syntax to parse a LuaTable. I have a table that follows the following structure:
mission =
{
["coalition"] =
{
["blue"] =
{
["bullseye"] =
{
["y"] = -378451.53125,
["x"] = -178644.117188,
}, -- end of ["bullseye"]
["country"] =
{
[1] =
{
["plane"] =
{
["group"] =
{
[1] =
{
["hiddenOnPlanner"] = false,
["tasks"] = {},
["radioSet"] = false,
["task"] = "AFAC",
["uncontrolled"] = false,
["hiddenOnMFD"] = false,
["taskSelected"] = true,
["route"] =
{..............
and I am doing the following in my Winforms C# application (just a button triggering this code to test):
private void button29_Click_1(object sender, EventArgs e)
{
Lua lua = new Lua();
string s = File.ReadAllText("C:\\Users\\username\\Desktop\\mission");
lua.DoString(s);
var res = lua["mission.coalition.blue.country"];
var bluePlanes = lua["mission.coalition.blue.country.1"];
LuaTable tb = (LuaTable)res;
Dictionary<object, object> dict = lua.GetTableDict(tb);
Console.WriteLine("First chunk of code:");
foreach (KeyValuePair<object, object> de in dict)
{
Console.WriteLine("{0} {1}", de.Key.ToString(), de.Value.ToString());
}
tb = (LuaTable)bluePlanes ;
dict = lua.GetTableDict(tb);
Console.WriteLine("Second chunk of code:");
foreach (KeyValuePair<object, object> de in dict)
{
Console.WriteLine("{0} {1}", de.Key.ToString(), de.Value.ToString());
}
}
The first chunk works but as soon as I stumble upon one of the elements in square brackets without quotes (e.g. [1]) null is returned. I have checked that manually adding the quotes solves this, but In the Watch view, I can see there are keys and values, just that I cannot index those. Any suggestion?
This is the console output:
First chunk of code:
1 table
Exception thrown: 'System.ArgumentNullException' in NLua.dll
Value cannot be null.
However, the information is shown in the Watch window: [![Watch window screenshot][1]][1]
Additionally, I thought of converting the table to JSON and using a C# class, but I cannot manage to do that from C# (tried using NLua to run a script in Lua that converts the table to JSON, but unsuccessfully, as I did not manage to reference the required Lua libraries)
Edit: adding a minimal structure to show the issue as requested in comments
["coalition"] =
{
["blue"] =
{
["country"] =
{
[1] =
{
}
}
}
}
With this minimal structure, I am able to address up to coalition.blue.country, but would not be able to access the contenta under [1] which is the only element without double quotes [1]: https://i.sstatic.net/263XtjsM.png