Jump to content

C++ and Lua


ZioRed
 Share

Recommended Posts

Is there any documentation somewhere about how to use C++ and Lua together?

 

What I'd like to know is (from a C++ point of view, basically I use empty Lua scripts just as placeholder and then initialize my component system on scene load):

  • how to know what is the script class that is attached to an entity in the scene (and if it's possible to set it at runtime)
  • how to access to the members and methods attached to the script
  • how to call C++ methods from a Lua script

Thanks

?? FRANCESCO CROCETTI ??

http://skaredcreations.com

Link to comment
Share on other sites

This is an advanced topic that isn't well documented. The interpreter class has analogs for most Lua commands, and ToLua++ can be used to generate your own binding code for Lua. In the future I hope to have more built-in tools to support this.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

What I'd like to know is (from a C++ point of view, basically I use empty Lua scripts just as placeholder and then initialize my component system on scene load):

 

An easier way to do this instead of figuring out what script is attached to an entity would be to have your empty script actually take some kind of text data. This data would id what you want done in C++. Inside the Start() method of the script is where you would set the entity key to this text data, then in C++ you loop over the loaded entities reading this key and then branch what classes you want to associate the entity too.

 

wtf, these tags on this site get so screwed up sometimes *sigh* Why do we get all this font **** to show up sometimes when I'm making code tags?

 

The above was a rough example. A better example would be to make a factory system so you can just have the factory create an instance of the class directly from the string name instead of a big if statement.

 

I did the above with LE 2 and the C# bindings but I used reflection to make the class instances where the type string was the actual class name. I then make a plugin system in C# that dynamically loaded DLL's. It was pretty cool because to add new functionality with a given class template I didn't have to adjust the main game exe, but just create a DLL and in the editor assign an entity this "type" string. Doing that in C++ is a little more difficult because of C++ objs, compilers, and DLL not playing nice together.

  • Upvote 1
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...