Lua integration with C++ objects

Started by
4 comments, last by JoshuaWaring 9 years, 11 months ago

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 :)

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.

That pretty much answers all my questions, Thank you.

One quick question does that mean if I passed 2 arguments it would be at -3 on the stack?

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.

I was confused at first until I finally read this:

http://www.lua.org/pil/26.html

it all makes so much sense now.

Thank you.

This topic is closed to new replies.

Advertisement