Hi,
I am trying to call lua event handler and pass table within a table as argument.
So, something like this:
– start of android native code:
Hashtable table = new Hashtable();
table.put(“name”, “on_message”);
table.put(“message”, "test message @ " + sdf.format(new Date()));
Hashtable innerTable = new Hashtable();
innerTable.put(“field0”, “value0”);
innerTable.put(“field1”, “value1”);
innerTable.put(“field2”, “value2”);
table.put(“inner_table”, innerTable);
CoronaLua.pushHashtable(luaState0, table);
When I print the argument table on the lua side I get
I/Corona ( 1821): message : test message @ 2014, Jan-022 14:28:09.439
I/Corona ( 1821): name : on_message
I/Corona ( 1821): inner_table: <nil>
I/Corona ( 1821): Type of the argument is expected to be table but was nil
So, I figured CoronaLua.pushHashtabledoes not deal with deep maps and I tried this -
luaState0.newTable(0, 3);
int luaTableStackIndex = luaState0.getTop();
luaState0.pushString(“on_message”);
luaState0.setField(luaTableStackIndex, “name”);
luaState0.pushString("test message @ " + sdf.format(new Date()));
luaState0.setField(luaTableStackIndex, “message”);
{
luaState0.newTable(0, 3);
int luaTableStackIndex1 = luaState0.getTop();
luaState0.pushString(“value1”);
luaState0.setField(luaTableStackIndex1, “field1”);
luaState0.pushString(“value2”);
luaState0.setField(luaTableStackIndex1, “field2”);
luaState0.pushString(“value3”);
luaState0.setField(luaTableStackIndex1, “field3”);
}
luaState0.setField(luaTableStackIndex, “inner_table”);
I would hope this’d create the inner table
{ name=“on_message”, message=“test message @ …”, inner_table = {
field1=“value1”, field2=“value2”, field3=“value3”
}}
this does not happen though. Any ay I could get this done? Any way to use canned lib to do so?
Cheers,
Alex.