For what it’s worth, I just rewrote the PrintTableLuaFunction.java for iOS. Probably not the best rewrite but hopefully it helps someone!
[lua]
//check type. if it’s not a table it will throw an error/exception.
luaL_checktype(L, 1, LUA_TTABLE);
//print all of the key/value pairs in the Lua table
NSLog(@“printTable()”);
NSLog(@"{");
for (lua_pushnil(L); lua_next(L, 1); lua_pop(L, 1)) {
const char *keyName = NULL;
int luaType = lua_type(L, -2);
switch (luaType) {
case LUA_TSTRING:
// Fetch the table entry’s string key.
keyName = lua_tostring(L, -2);
break;
case LUA_TNUMBER:
// The key will be a number if the given Lua table is really an array.
// In this case, the key is an array index. Do not call lua_tostring() on the
// numeric key or else Lua will convert the key to a string from within the Lua table.
keyName = [[NSString stringWithFormat:@"%d", lua_tointeger(L, -2)] cStringUsingEncoding:NSASCIIStringEncoding];
break;
}
if (keyName == NULL) {
//a valid key was not found. skip this table entry.
continue;
}
//fetch the table entry’s value in string form.
//an index of -1 accesses the entry’s value that was pushed into the lua stack by lua_next() above.
const char *valueString = NULL;
luaType = lua_type(L, -1);
switch (luaType) {
case LUA_TSTRING:
valueString = lua_tostring(L, -1);
break;
case LUA_TBOOLEAN:
valueString = [[NSString stringWithFormat:@"%d", lua_toboolean(L, -1)] cStringUsingEncoding:NSASCIIStringEncoding];
break;
case LUA_TNUMBER:
valueString = [[NSString stringWithFormat:@"%f", lua_tonumber(L, -1)] cStringUsingEncoding:NSASCIIStringEncoding];
break;
}
if (valueString == NULL) {
valueString = “”;
}
NSLog(@"[%s] = %s", keyName, valueString);
}
NSLog(@"}");
[/lua]