Mixing Lua Bindings between Ogre and CEGUI

Discussion regarding the development of CEGUI itself - as opposed to questions about CEGUI usage that should be in the help forums.

Moderators: CEGUI MVP, CEGUI Team

User avatar
drumicube
Not too shy to talk
Not too shy to talk
Posts: 43
Joined: Thu Nov 02, 2006 12:09
Location: France

Mixing Lua Bindings between Ogre and CEGUI

Postby drumicube » Sat Nov 04, 2006 00:41

Hi !
I just built the latest Ogre source code available (V1.2.3) with CEGUI 0.5 RC2, after a little patch in Ogre it worked really very well ;)
I can now use lua scripts to control cegui interface, and I must admit I really love this stuff...

My current problem comes from Lua integration with both API (cegui and Ogre):
I added to Ogre it's own Lua support, using the same tools as cegui script module, except it's running Lua5.1 instead of v0.52. I can control my 3d objects using Lua...
there's no conflict as I also renamed the needed dlls to tolua++cegui.dll and tolua++.dll for Ogre. I also have lua5.0.dll and lua5.1.dll in my exe folder are they're both needed...
I know it's really ugly :roll:

As you would guess, what I need is to update the Scripting Module to the same Lua version used by Ogre, but there's a more dramatic issue...
In the current state, it's impossible for my cegui Lua scripts to control my Ogre objects are they're not sharing their bindings:
For instance it's impossible in Lua script to rotate an Ogre 3D object when I press a cegui button.

My questions:
- Do you have planned to update your Script Module to Lua5.1 soon ? If someone as already done it, some problems to report ?
- What is the best way to share both CEGUI and Ogre API in only one binding ? Is it at least possible to do such a thing ?


Thanks a lot for all your contributions on those subjects.
BR

User avatar
lindquist
CEGUI Team (Retired)
Posts: 770
Joined: Mon Jan 24, 2005 21:20
Location: Copenhagen, Denmark

Postby lindquist » Sat Nov 04, 2006 11:57

There are currently no plans to upgrade, though it will definitely happen at some point. What we have talked about is creating a new lua module that uses 5.1.

There is no date set!

User avatar
drumicube
Not too shy to talk
Not too shy to talk
Posts: 43
Joined: Thu Nov 02, 2006 12:09
Location: France

Postby drumicube » Sat Nov 04, 2006 12:53

Thanks lindquist !

FYI, I just upgraded the CEGUI scripting module to Lua5.1:
What I needed to do was to replace the Lua header and library files with the one from V5.1 in the dependencies folder.
Then I simply needed to link Lua5.1.lib instead of Lua50.lib

Of course I also replace sur Lua50.dll with Lua5.1.dll in my exe folder:
Everything recompile fine and is working perfectly with the Demo8.Lua example!

It's not so surprising as tolua++ is designed to work with both Lua version.
tolua++ rocks so much! ;)

User avatar
lindquist
CEGUI Team (Retired)
Posts: 770
Joined: Mon Jan 24, 2005 21:20
Location: Copenhagen, Denmark

Postby lindquist » Sat Nov 04, 2006 13:00

Glad to hear there were no problems :)

User avatar
drumicube
Not too shy to talk
Not too shy to talk
Posts: 43
Joined: Thu Nov 02, 2006 12:09
Location: France

Postby drumicube » Wed Nov 08, 2006 00:38

Sorry, I forgot to report the only changed which was needed for Lua5.1:

Lua 5.1 init is not compatible with 5.0
In CEGUILua.cpp

Code: Select all

/*************************************************************************
   Constructor (creates Lua state)
*************************************************************************/
LuaScriptModule::LuaScriptModule()
{

   static const luaL_Reg lualibs[] = {
      {"", luaopen_base},
      {LUA_LOADLIBNAME, luaopen_package},
      {LUA_TABLIBNAME, luaopen_table},
      {LUA_IOLIBNAME, luaopen_io},
      {LUA_OSLIBNAME, luaopen_os},
      {LUA_STRLIBNAME, luaopen_string},
      {LUA_MATHLIBNAME, luaopen_math},
#if defined(DEBUG) || defined (_DEBUG)
      {LUA_DBLIBNAME, luaopen_debug},
#endif
      {NULL, NULL}
   };

   // create a lua state
   d_ownsState = true;
   d_state = lua_open();

   // init all standard libraries (lua 5.1 new version)
   
   const luaL_Reg *lib = lualibs;
   for (; lib->func; lib++)
   {
      lua_pushcfunction(d_state, lib->func);
      lua_pushstring(d_state, lib->name);
      lua_call(d_state, 1, 0);
   }

   setModuleIdentifierString();
}


To merge your own Ogre binding to the CEGUI existing one,
In your ogre project:

Code: Select all

   // Just override the mandatory create scene method
   void createScene(void)
   {
      // setup GUI system
      mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow,Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mSceneMgr);
      
      cegui_script = new CEGUI::LuaScriptModule();
      mGUISystem = new CEGUI::System(mGUIRenderer,0,0,cegui_script);
      
      CEGUI::Logger::getSingleton().setLoggingLevel(CEGUI::Informative);
      lua_State* cegui_state = cegui_script->getLuaState();
      tolua_MyOgreBinding_open(cegui_state);
      cegui_script->executeScriptFile("myscript.lua","");

   }


Of course , you will need to link the CEGUI tolua++.lib in your ogre project, and add the necessary header files.
The tolua version you use under ogre, must be the same as the one used in CEGUI, which is not a bad thing, as only one version is needed for both project! ;)
All this was tested, and it works really very well for me.


Return to “CEGUI Library Development Discussion”

Who is online

Users browsing this forum: No registered users and 6 guests