Read nested Lua table who key is a System.Double
Posted
by Robert Kerr
on Stack Overflow
See other posts from Stack Overflow
or by Robert Kerr
Published on 2010-03-26T22:57:10Z
Indexed on
2010/03/26
23:03 UTC
Read the original article
Hit count: 386
Using C# and LuaInterface, I am trying to read a nested table, but am getting a null LuaTable when I try to open the key containing the table.
The .lua file:
DB = {
["inventory"] = {
[10001] = {
["row"] = 140,
["count"] = 20,
},
[10021] = {
["row"] = 83,
["count"] = 3,
},
[10075] = {
["row"] = 927,
["count"] = 15,
},
}
}
I can successfully foreach the entries under inventory, by opening that table with:
LuaTable tbl = lua.GetTable("DB.inventory");
foreach (DictionaryEntry de in tbl)
...
What I cannot do is open an inventory item and enumerate its entries the same way. Is this because the key is a System.Double
type? This fails:
LuaTable tbl = lua.GetTable("DB.inventory.10001");
foreach (DictionaryEntry de in tbl)
with an exception, because tbl is null.
Effectively, once I enumerate the keys (inventory items), I then want to drill down into the nested table and work with those contents. As you can see, I am not able to get a reference to the nested table the way I am doing it.
© Stack Overflow or respective owner