Difference between revisions of "Adding LuaScriptModule to Sample FirstWindow"

From CEGUI Wiki - Crazy Eddie's GUI System (Open Source)
Jump to: navigation, search
m (testing obsolete warning)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
{{VersionBadge|0.3}}
 
{{VersionBadge|0.3}}
 +
{{ObsoleteWarning}}
  
 
This applies to the CEGUI 0.3.0 Release.
 
This applies to the CEGUI 0.3.0 Release.
Line 5: Line 6:
 
== Enable logging ==
 
== 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.
+
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
 
In CEGuiSample.cpp
 +
<source lang="cpp">
 
  bool CEGuiSample::initialise()
 
  bool CEGuiSample::initialise()
 
  {
 
  {
Line 27: Line 29:
 
       // execute the base application (which sets up the demo via 'this' and runs it.
 
       // execute the base application (which sets up the demo via 'this' and runs it.
 
     if (d_sampleApp->execute(this))
 
     if (d_sampleApp->execute(this))
 +
</source>
  
 
== Create a Lua State ==
 
== Create a Lua State ==
  
 
In Sample_FirstWindow.cpp
 
In Sample_FirstWindow.cpp
 +
<source lang="cpp">
 
   #include "CEGUI.h"
 
   #include "CEGUI.h"
 
  + #include "../ScriptingModules/CEGUILua/LuaScriptModule/include/LuaScriptModule.h"
 
  + #include "../ScriptingModules/CEGUILua/LuaScriptModule/include/LuaScriptModule.h"
 
+
</source>
  
 
In Sample_FirstWindow.cpp
 
In Sample_FirstWindow.cpp
 +
<source lang="cpp">
 
  bool FirstWindowSample::initialiseSample()
 
  bool FirstWindowSample::initialiseSample()
 
  {
 
  {
Line 49: Line 54:
 
  +  // call a script from our the datafiles
 
  +  // call a script from our the datafiles
 
  +  lua->executeScriptFile("../datafiles/scripts/sample.lua", "test");
 
  +  lua->executeScriptFile("../datafiles/scripts/sample.lua", "test");
 
+
</source>
 
== Create a Lua Script ==
 
== Create a Lua Script ==
  
Line 56: Line 61:
  
 
Create sample.lua
 
Create sample.lua
 +
<source lang="lua">
 
  -- get the GUI sheet
 
  -- get the GUI sheet
 
  local sheet = CEGUI.WindowManager:getSingleton():getWindow("Root");
 
  local sheet = CEGUI.WindowManager:getSingleton():getWindow("Root");
Line 72: Line 78:
 
  -- disable user sizing
 
  -- disable user sizing
 
  fw:setProperty("SizingEnabled","False")
 
  fw:setProperty("SizingEnabled","False")
 +
</source>
  
 
== Running ==
 
== Running ==
  
 
Now just compile and run.
 
Now just compile and run.

Latest revision as of 00:39, 2 March 2011

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()
 {
      . . .
      default:
          // 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 );
 +#else
 +    logger->setLogFilename( "Sample_FirstWindow.log", true );
 +#endif
      // 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.
     root->addChildWindow(wnd);     
 +   // 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
 sheet:addChildWindow(fw)
 
 -- 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:setSize(sz)
 fw:setPosition(pos)
 fw:setText("Lua says Hello World!")
 -- disable user sizing
 fw:setProperty("SizingEnabled","False")

Running

Now just compile and run.