How to properly use executeScriptFile()

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

Just popping in
Just popping in
Posts: 17
Joined: Thu Aug 20, 2009 21:02

How to properly use executeScriptFile()

Postby czuger » Thu Aug 20, 2009 21:57


I am implementing a UI system where all the logic is done in Lua.
As far as I can tell, each call to executeLuaScript() re-compiles all the Lua code contained in the provided script and grows the Lua stack.
The provided example ("demo8.lua") defines a variety of global functions that act as event handlers, and actually loads and shows the necessary windows via a bit of global code in the script.
It seems to me that each time executeLuaScript() is called loading such a file, each function will be pushed onto the Lua stack again, growing Lua stack indefintiley each time this particular set of windows is displayed.

In more complex examples, where state is actually kept for each dialog, instead of just callbacks as in the example, how is one expected to clean up?

One solution that I have in mind is to have a single Lua script, that would look like this:

Code: Select all

require FrontEndMenu
require OptionsMenu

The application would call this script each time any menu is to be displayed, Lua will ensure that it only loads the required files if necessary (which is what "require" does according to the Lua docs).
The actual UI lua scripts contents would look like:

Code: Select all

local frontEndMenu = nil
function load_FrontEndMenu()
 -- initalize necessary Lua objects that represent the FrontEndMenu

function unload_FrontEndMenu()
 -- destroy the menu by setting it to nil
 frontEndMenu = nil

The C++ code can now call the load_FrontEndMenu() function to show a particular window. Within the Lua code itself, once it has determined that the window needs to close, unload_FrontEndMenu() is called, causing it to clean up.

Does this approach make sense or am I missing something here? Debugging what executeLuaScript() does, the top of the Lua stack does grow on each call.
How does CEGUI expect UI implement in Lua to be shown repeatedly?

Thanks for any help.

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

Re: How to properly use executeScriptFile()

Postby CrazyEddie » Mon Aug 24, 2009 08:41

If you have files with global stuff in them, just execute them once (either the first time it's used if there's code to be executed, or ahead of time if it's just a bunch of functions). To subsequently invoke some global previously loaded you should use the ScriptModule::executeScriptGlobal function - not load the file again.



Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 9 guests