Adding LuaScriptModule to Sample FirstWindow

From CEGUI Wiki - Crazy Eddie's GUI System (Open Source)
Revision as of 00:39, 2 March 2011 by Kulik (Talk | contribs) (testing obsolete warning)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Written for CEGUI 0.3

Works with versions 0.3.x (obsolete)

Obsolete warning: This article has been written for an old version of CEGUI and likely doesn't apply to current stable!

This applies to the CEGUI 0.3.0 Release.

Enable logging

Lua scripts get a lot of bugs. Without logging, you will never know why your application simply quits without stepping through every line of code.

In CEGuiSample.cpp

 bool CEGuiSample::initialise()
      . . .
          // TODO: Throw exception or something!
 +        return false;
 -        break;
 +    CEGUI::Logger *logger = &CEGUI::Logger::getSingleton();
 +    logger->setLoggingLevel( CEGUI::Informative );
 +#if defined( __WIN32__ ) || defined( _WIN32 )
 +    logger->setLogFilename( "C:\\Sample_FirstWindow.log", true );
 +#elif defined(linux)
 +    logger->setLogFilename( "~/Sample_FirstWindow.log", true );
 +    logger->setLogFilename( "Sample_FirstWindow.log", true );
      // execute the base application (which sets up the demo via 'this' and runs it.
     if (d_sampleApp->execute(this))

Create a Lua State

In Sample_FirstWindow.cpp

   #include "CEGUI.h"
 + #include "../ScriptingModules/CEGUILua/LuaScriptModule/include/LuaScriptModule.h"

In Sample_FirstWindow.cpp

 bool FirstWindowSample::initialiseSample()
     using namespace CEGUI;
 +   // create a lua_state by using [[User:Lindquist|Lindquist]]'s awesome LuaScriptModule
 +   LuaScriptModule* lua = new LuaScriptModule();
 +   // create the CEGUI namespace in the Lua environment
 +   lua->createBindings();
     . . .
     // DefaultWindow which we will be using as the root of the displayed gui.
 +   // call a script from our the datafiles
 +   lua->executeScriptFile("../datafiles/scripts/sample.lua", "test");

Create a Lua Script

In the Samples\datafiles directory Create a scripts directory

Create sample.lua

 -- get the GUI sheet
 local sheet = CEGUI.WindowManager:getSingleton():getWindow("Root");
 -- create a FrameWindow
 local fw = CEGUI.WindowManager:getSingleton():createWindow ("TaharezLook/FrameWindow","framewnd");
 -- add it to the sheet
 -- set its size and position
 local sz = CEGUI.Size:new_local(0.5,0.5)
 local pos = CEGUI.Point:new_local(0.2,0.1)
 fw:setText("Lua says Hello World!")
 -- disable user sizing


Now just compile and run.