Jump to content

  • Log In with Google      Sign In   
  • Create Account

tolua++ and passing tables back to C++


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 rpiller   Members   -  Reputation: 683

Like
0Likes
Like

Posted 20 November 2013 - 01:46 PM

Using tolua++ I've exposed a RakNet class to lua. One of the methods is to register a lua callback function. All my lua code is object oriented however so it's not just a function name, but a table as well that needs to go along with it.

 

Right now my C++ method looks like:

 

void RakNetNetwork::RegisterNetworkMessage(int msg, lua_Object obj, std::string func);

 

I'm calling this from lua from within a "class"/table function so I'm using self like:

 

function ProfileMenu:Enter()
    self.Network:RegisterNetworkMessage(15, self, "OnConnected")
end
 
function ProfileMenu:OnConnected(reader)
end

 

The issue I'm having is that tolua++'s bindings is giving me an error when it's checking the obj parameter. Here is the binding and I've marked with a comment where it's failing.

 

/* method: RegisterNetworkMessage of class  RakNetNetwork */
#ifndef TOLUA_DISABLE_tolua_luacommands_RakNetNetwork_RegisterNetworkMessage00
static int tolua_luacommands_RakNetNetwork_RegisterNetworkMessage00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
 tolua_Error tolua_err;
 if (
     !tolua_isusertype(tolua_S,1,"RakNetNetwork",0,&tolua_err) ||
     !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
     !tolua_iscppstring(tolua_S,3,0,&tolua_err) ||
     !tolua_isnoobj(tolua_S,4,0,&tolua_err)                                                           /// IT'S FAILING THIS CHECK
 )
  goto tolua_lerror;
 else
#endif
 {
  RakNetNetwork* self = (RakNetNetwork*)  tolua_tousertype(tolua_S,1,0);
  int msg = ((int)  tolua_tonumber(tolua_S,2,0));
  lua_Object obj = ((lua_Object)  tolua_tovalue(tolua_S,3,0));
  std::string func = ((std::string)  tolua_tocppstring(tolua_S,4,0));
#ifndef TOLUA_RELEASE
  if (!self) tolua_error(tolua_S,"invalid 'self' in function 'RegisterNetworkMessage'", NULL);
#endif
  {
   self->RegisterNetworkMessage(msg,obj,func);
  }
 }
 return 0;
#ifndef TOLUA_RELEASE
 tolua_lerror:
 tolua_error(tolua_S,"#ferror in function 'RegisterNetworkMessage'.",&tolua_err);
 return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE


Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS