Jump to content

lua table as parameter to C++ method


Rick
 Share

Recommended Posts

Any ideas on how I can pass & store a lua table to a C++ method and then bring it up and call a function in that table (by name, which I'll also store) it at a later time using LE's lua implementation? The name of the table is not know as I'll be passing 'self' to the C++ method. I just don't know what the C++ parameter should be and how to find it and make the call. Words can't explain how much I hate working with the stack in lua :)

Link to comment
Share on other sites

The table is created in Lua? You need to set it to a global variable and then put it back on the stack with PushString("variablename"). If you look at the source for App.cpp it gets a table by variable name, then calls the Start function, which is a member of the App table.

 

These are some pretty advanced topics. Usually I would expect data to flow the other way, from C++ to Lua.

 

 

Link to comment
Share on other sites

I can't really assign it to a global var. I'm setting up a callback system where I'm telling the C++ class the table function to be the callback. This will be done from within a lua class function.

 

function ProfileMenu:Enter()
self.Network:RegisterCallback(msgID, self, "Callback")
end

function ProfileMenu:Callback(reader)
end

 

I'm looking at code like the following but you don't expose some of these lua functions so I might have to bring in lua myself. What version of lua is being used in case I have to do this?

 

http://lua-users.org/files/wiki_insecure/users/ArielManzur/tolua++/tolua_base.h

 

As you can see lua_Object is a parameter type which is a table. You store some kind of reference from it and retrieve it later to call.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...