Jump to content
  • Advertisement
Sign in to follow this  
McFury

Luabind and class initialization

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

Hi, I just needed some help with luabind class initialization if anyone know abouts it. Firstly I have created a base class in c++ (I have also created a wrapper for it with luabind::wrap_base) and I set up the correct modules to expose them. Secondly I have created a class inside a lua script that derives from this c++ base class. Now I wish to be able to create an instance of this lua class from c++ and use it, but I do not know how to do this. Example: base_class (c++) derived_class (lua script) I wish to be able to make an instance of that derived class inside c++: derived_class der; der.print(); Any help would be great, thank you.

Share this post


Link to post
Share on other sites
Advertisement
Hi again,

Is there anyone that could help me with an answer to this question? I'm still rather stuck on it. Even if the answer is just a simple "thats not possible".

thank you.

Share this post


Link to post
Share on other sites
Hello,

I'm defining a derived class in lua like this:

class "CDerivedClass" (CBaseClass)

-- base-class constructor args would go into the braces after "super"
function CDerivedClass:__init() super()
-- code goes here!
end

function CDerivedClass:DoStuff()
-- code goes here!
end

-- define other class funcs here

Then you can intialize it like every other class

Share this post


Link to post
Share on other sites
Hi,

Thank you for your reply! I'm glad to see that it is possible.

One question remains to me though, when you say that I can initialize it like any other class, can i initialize instances of it in cpp code? or would the initialization need to be in a LUA script because the class is made there.

If its possible to initialize a copy in c++ is the code be tricky? I know that once the class script is read in then LUA knows what it is, but I am not sure how to use it.

Sorry if I am asking too many questions, thanks again for your response. :)

Share this post


Link to post
Share on other sites
Hi again,

I am still stuck on this issue, if anyone could help me with what I stated in my last post (about initializing copies of LUA classes inside C++, or if its even possible) I would be very very thankful.

Share this post


Link to post
Share on other sites
From reading the documentation it seems this is possible, perhaps using the Luabind objects. I've only looked briefly at Luabind, instead going with another binding library ( more light weight but not as full featured as Luabind, MLuabind ). I'll try to track down some samples for ya, if i can find them.

Worse case u can just do a luaL_dostring and that will execute a string as if it was Lua code, allowing you to bascially do anyhting you want in C++. You'll just have to build the string dynamically, which shouldn't be too much trouble.

-ddn

Share this post


Link to post
Share on other sites
I used this tutorial to set up lua and luabind in my project, see if it helps you at all:
http://www.nuclex.org/articles/quick-introduction-to-luabind

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!