Best way to integrate Luabind with ToLua++?

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

Pfhreak
Just popping in
Just popping in
Posts: 4
Joined: Fri Jun 13, 2008 05:35

Best way to integrate Luabind with ToLua++?

Postby Pfhreak » Fri Jun 13, 2008 05:54

I've played with both toLua++ and luabind a fair bit recently, and I've come to the conclusion that I prefer working with luabind, while Cegui uses tolua++. That's totally cool, to each their own.

It seems CEGUI has had a ton of work done to support lua fairly extensively, and rather than try and recreate all that effort in luabind (which would be an enormous undertaking), I'll just build on top of the work that exists.

The question I have is what is the best approach here? I'm building in Ogre, so I'm thinking I'll have to do the following:

1.) Grab the latest version of CEGUI from the SVN. Which version of lua is this built against?
2.) Rebuild CEGUI, and have my Ogre project use the rebuilt version, rather than the version that 'ships' with Ogre. Will this cause any known instabilities with the latest stable release of Ogre?
3.) Instantiate my lua_State somehow, and pass it around between all my tools. The question is, how is this best approached? Should I run all the CEGUI toLua++ stuff first, and simply retrieve the lua_State from that, then follow up with my luabind methods?

Any recommendations from people who have done this in the past? I hate to run into problems that have already been solved along the way.

Thanks.

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Postby CrazyEddie » Fri Jun 13, 2008 08:34

Hi, and welcome :)

With regards to SVN, I recommend the more stable cegui_mk2/branches/v0-6 branch over trunk. Of course you are free to use whichever code you like, though trunk has a changed directory structure and will be receiving other large mods in the coming weeks :)

Anyway, to get back onto topic...

1) The CEGUI scripting module for lua should build okay with either the 5.0.x or 5.1.x series of Lua releases. If you're on Windows, you'll need to set an appropriate value in the config.lua file. If you're using the configure/make approach, the correct version of Lua is detected in most cases.

2) You will also need to rebuild Ogre to get the updated GUI renderer module. When you do this it is essential that all traces of any previous CEGUI version are removed (basically, for MSVC, delete the CEGUI stuff from the dependencies and replace with the new versions. If you use the Xerces XML parser, remember to use the updated .xsd schema files (from XMLRefSchema directory). Once all this is done correctly, there should be no major issues.

3) I'm not aware of anyone having mixed luabind and tolua++ with CEGUI previously (though someone else might know better!). I don't believe it should not matter if you pass an existing lua_State to the constructor of the scripting module, or extract the automatically created one for use elsewhere.

Some or all of this info could be wrong!! But at the time of writing I believe it to be correct :P

HTH

CE.

Pfhreak
Just popping in
Just popping in
Posts: 4
Joined: Fri Jun 13, 2008 05:35

Postby Pfhreak » Tue Jun 17, 2008 18:29

Well, I finally had a chance to play with this on sunday, and after spending all afternoon fussing with my existing installations (2 versions of lua, 2 versions of luabind, 2 versions of CEGUI, Ogre, etc) and getting nowhere, I decided to start clean and I got everything working wonderfully. For those who are interested, here's how I did it.

First, I downloaded the following:
Lua 5.1.3
Luabind SVN (June 2008) [Do not use version .7]
CEGUI .6 and Dependencies
Ogre 1.4.7 (This should work with a later version)
Boost 1.33 (Needed for luabind) [At time of writing, Luabind worked only with this version of Boost]

I expanded all the packages to their respective folders. Then I set about removing libraries that were already in the various dependencies folders. I removed any and all CEGUI libs and header files in the Ogre folders. Be careful to get them all! There are some in the Samples/Common/bin folders! I removed any and all lua libs and header files from the CEGUI dependencies folder. (This isn't the cleanest way to do this, but...) I dropped the recently built library into the CEGUI dependencies, and Ogre dependencies folders, and I copied over the header files I'd need.

Then I built the lua library, including everything except lua.c, luac.c, and print.c. Next I built the Luabind using the lua library I just built. I dropped the library and appropriate headers into the Ogre dependencies folder.

Next I built the release and debug versions of CEGUI, and I copied over toLua++, CEGUIBase and CEGUILua libs to the dependencies folder in Ogre. I also copied over the headers to Ogre.

From there I rebuilt Ogre and ran several of the demos to make sure everything worked. Sure enough, everything compiles and runs just fine. I had to replace a number of dlls in the Samples/Common/Bin folders, but Ogre will let you know which ones are missing.

Now I can do some very awesome things with lua in my game. For example, in my lua scripts, I have all of the power of CEGUI readily available, but I can also easily call custom functions with luabind.

Code: Select all

// I can make C++ funcs available to lua easily
// Here I send the function ' void greet()' to lua
void greet()
{
  std::cout<<"Hello world!" << std::endl;
}

void BindLuaFuncs(lua_State * lState)
{
  luabind::module(lState)[
    def("GreetLog", &greet)
  ];
}
// I can easily call lua functions from C++ by name
// Here's part of an AI update method
...
int priority = luabind::call_function<int>(lua_State, "GetAIPriority");
...
// This way anywhere I want to make a call out to lua, I only need one line of code


So it allows me to do some very powerful calls to lua without having to add much (if any) complexity to the code.

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Postby CrazyEddie » Wed Jun 18, 2008 08:39

I'm glad you managed to get this to work.

Your post is very interesting and, I believe, should be useful to anyone wishing to do something that's remotely similar - so thanks very much for taking the time to post your experiences :)

CE.

User avatar
Das Gurke
Not too shy to talk
Not too shy to talk
Posts: 31
Joined: Sat Sep 02, 2006 15:45

Postby Das Gurke » Sat Jul 05, 2008 07:03

Yes, tons of thanks four your description! I was in a similar situation and am glad, that I found something I could follow in order to integreate my luabind bindings with CEGUI / tolua++.


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 9 guests