• Advertisement
Sign in to follow this  

Lua integration with C++ objects

This topic is 1358 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

In my previous post I was going to just use pointers in Lua and have them passed when needed, this was the wrong path for what I wanted to be on.

 

Now I'm trying to expose the classes and their functions to Lua, where a function called on an object will take affect on the instance on the object, but since Lua functions are static, how do I get it to affect the instance of the object?

 

I looked at the luawrapper, but I didn't want to use it because of it's dependence on the boost library and I didn't want to include that just for the wrapper.

 

any help would be appreciated thank you :)

Share this post


Link to post
Share on other sites
Advertisement


but since Lua functions are static, how do I get it to affect the instance of the object?

 

Typically you will use colon syntax when calling object's methods.

Pointer to object will be implicitly passed as first argument to that static function, so you can grab pointer to c++ object from there.

Share this post


Link to post
Share on other sites

Yes, it will be at -3.

But considering dynamic nature of Lua, you'd better check absolute positive indices, not negative relative to stack top.

First argument will be always at index 1, regardless of the number of arguments passed.

Share this post


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

  • Advertisement