我很难尝试获取我的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)