小编kap*_*ser的帖子

lua_touserdata返回null

我很难尝试获取我的userInfo参考.我的一个方法是返回对象的实例.每次调用createUserInfo时,它都会将userInfoObject返回给lua.

但是,当我从Lua调用userInfo对象的方法时,我无法获取userInfo对象的引用(lua_touserdata(L,1))

static int getUserName (lua_State *L){
   UserInfo **userInfo = (UserInfo**)lua_touserdata(L,1);

   // The following is throwing null! Need help. 
   // Not able to access the userInfo object.
   NSLog(@"UserInfo Object: %@", *userInfo);       
}

static const luaL_reg userInstance_methods[] = {
  {"getUserName", getUserName},
  {NULL, NULL}
}

int createUserInfo(lua_State *L){

  UserInfo *userInfo = [[UserInfo alloc] init];
  UserInfoData **userInfoData = (UserInfoData **)lua_newuserdata(L, sizeof(userInfo*));
  *userInfoData = userInfo;

  luaL_openlib(L, "userInstance", userInstance_methods, 0);
  luaL_getmetatable(L, "userInfoMeta");
  lua_setmetatable(L, -2);

return 1;
}

// I have binded newUserInfo to …
Run Code Online (Sandbox Code Playgroud)

lua objective-c luac

6
推荐指数
1
解决办法
912
查看次数

标签 统计

lua ×1

luac ×1

objective-c ×1