Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Lua integration with C++ objects


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
5 replies to this topic

#1 Joshhua5   Members   -  Reputation: 454

Like
0Likes
Like

Posted 03 May 2014 - 05:49 AM

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



Sponsor:

#2 vstrakh   Members   -  Reputation: 459

Like
1Likes
Like

Posted 03 May 2014 - 12:53 PM


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.



#3 Joshhua5   Members   -  Reputation: 454

Like
0Likes
Like

Posted 03 May 2014 - 08:09 PM

That pretty much answers all my questions, Thank you.



#4 Joshhua5   Members   -  Reputation: 454

Like
0Likes
Like

Posted 03 May 2014 - 11:43 PM

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

#5 vstrakh   Members   -  Reputation: 459

Like
1Likes
Like

Posted 04 May 2014 - 03:10 AM

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.



#6 Joshhua5   Members   -  Reputation: 454

Like
0Likes
Like

Posted 04 May 2014 - 03:39 AM

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.






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