Advertisement Jump to content
Sign in to follow this  

tolua++ and passing tables back to C++

This topic is 1887 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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")
function ProfileMenu:OnConnected(reader)


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)
 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;
  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));
  if (!self) tolua_error(tolua_S,"invalid 'self' in function 'RegisterNetworkMessage'", NULL);
 return 0;
 tolua_error(tolua_S,"#ferror in function 'RegisterNetworkMessage'.",&tolua_err);
 return 0;
#endif //#ifndef TOLUA_DISABLE

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!