Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
Plugin helper - Gideros Forum

Plugin helper

hoanhoan Member
edited April 2012 in Plugins
Hey guys,

Got running with my first plugin. I found this function which will push an arbritarily complex Objective-C object onto the lua stack.
 
 
void wax_fromInstance(lua_State *L, id instance) {
    //BEGIN_STACK_MODIFY(L)
 
    if (instance) {
        if ([instance isKindOfClass:[NSString class]]) {    
            lua_pushstring(L, [(NSString *)instance UTF8String]);
        }
        else if ([instance isKindOfClass:[NSNumber class]]) {
            lua_pushnumber(L, [instance doubleValue]);
        }
        else if ([instance isKindOfClass:[NSArray class]]) {
            lua_newtable(L);
            for (id obj in instance) {
                int i = lua_objlen(L, -1);
                wax_fromInstance(L, obj);
                lua_rawseti(L, -2, i + 1);
            }
        }
        else if ([instance isKindOfClass:[NSDictionary class]]) {
            lua_newtable(L);
            for (id key in instance) {
                wax_fromInstance(L, key);
                wax_fromInstance(L, [instance objectForKey:key]);
                lua_rawset(L, -3);
            }
        /*}                
        else if ([instance isKindOfClass:[NSValue class]]) {
            void *buffer = malloc(wax_sizeOfTypeDescription([instance objCType]));
            [instance getValue:buffer];
            wax_fromObjc(L, [instance objCType], buffer);
            free(buffer);
        }    
		else if ([instance isKindOfClass:[WaxFunction class]]) {
			wax_instance_pushUserdata(L, instance);
			if (lua_isnil(L, -1)) {
				luaL_error(L, "Could not get userdata associated with WaxFunction");
			}
			lua_getfield(L, -1, "function");*/
		}
        else {
            //wax_instance_create(L, instance, NO);
        }
    }
    else {
        lua_pushnil(L);
    }
 
 //   END_STACK_MODIFY(L, 1)
}
Use this if you have any data you want converted. Handles, NSString, NSNumber, NSArray, NSDictionary.
wax_fromInstance(L, objcobject);
Hoan
+1 -1 (+4 / -0 ) Share on Facebook

Comments

Sign In or Register to comment.