Difference between revisions of "Adding LuaScriptModule to Sample FirstWindow"
From CEGUI Wiki - Crazy Eddie's GUI System (Open Source)
(testing lua syntax highlighting) |
|||
Line 8: | Line 8: | ||
In CEGuiSample.cpp | In CEGuiSample.cpp | ||
+ | <syntaxhighlight lang="cpp"> | ||
bool CEGuiSample::initialise() | bool CEGuiSample::initialise() | ||
{ | { | ||
Line 27: | Line 28: | ||
// 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)) | ||
+ | </syntaxhighlight> | ||
== Create a Lua State == | == Create a Lua State == | ||
In Sample_FirstWindow.cpp | In Sample_FirstWindow.cpp | ||
+ | <syntaxhighlight lang="cpp"> | ||
#include "CEGUI.h" | #include "CEGUI.h" | ||
+ #include "../ScriptingModules/CEGUILua/LuaScriptModule/include/LuaScriptModule.h" | + #include "../ScriptingModules/CEGUILua/LuaScriptModule/include/LuaScriptModule.h" | ||
− | + | </syntaxhighlight> | |
In Sample_FirstWindow.cpp | In Sample_FirstWindow.cpp | ||
+ | <syntaxhighlight lang="cpp"> | ||
bool FirstWindowSample::initialiseSample() | bool FirstWindowSample::initialiseSample() | ||
{ | { | ||
Line 49: | Line 53: | ||
+ // 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"); | ||
− | + | </syntaxhighlight> | |
== Create a Lua Script == | == Create a Lua Script == | ||
Line 56: | Line 60: | ||
Create sample.lua | Create sample.lua | ||
+ | <syntaxhighlight 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 77: | ||
-- disable user sizing | -- disable user sizing | ||
fw:setProperty("SizingEnabled","False") | fw:setProperty("SizingEnabled","False") | ||
+ | </syntaxhighlight> | ||
== Running == | == Running == | ||
Now just compile and run. | Now just compile and run. |
Revision as of 14:14, 27 February 2011
Written for CEGUI 0.3
Works with versions 0.3.x (obsolete)
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.