It looks like you're new here. If you want to get involved, click one of these buttons!
NSMutableDictionary* luaTableToDictionary(lua_State* L,int stack_index) { NSMutableDictionary *dict = [NSMutableDictionary dictionary]; // STACK { Table } lua_pushnil(L); // STACK { Table Nil } while (lua_next(L, stack_index) != 0) { // STACK { Table key Value } id key = nil; switch(lua_type(L,-2)) { case LUA_TNUMBER: { int value = lua_tonumber(L, -2); NSNumber *number = [NSNumber numberWithInt:value]; key = number; break; } case LUA_TSTRING: { NSString *value = [NSString stringWithUTF8String:luaL_checkstring(L, -2)]; key = value; break; } } id value = nil; switch (lua_type(L, -1)) { case LUA_TNUMBER: { int val = lua_tonumber(L, -1); NSNumber *number = [NSNumber numberWithInt:val]; value = number; break; } case LUA_TBOOLEAN: { int val = lua_toboolean(L, -1); NSNumber *number = [NSNumber numberWithBool:val]; value = number; break; } case LUA_TSTRING: { NSString *val = [NSString stringWithUTF8String:luaL_checkstring(L, -1)]; value = val; break; } case LUA_TTABLE: { NSMutableDictionary *dict = luaTableToDictionary(L,stack_index+2); value = dict; break; } default : { lua_pop(L, 1); continue; } } [dict setObject:value forKey:key]; lua_pop(L, 1); } return dict; } |
Comments
Well... I used it in the UINotifications plugin here.
http://www.giderosmobile.com/forum/discussion/1103/uinotifications-plugin-local-notifications-for-iphone#Item_1
Accessing the stack everytime was driving me crazy