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
etc.
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:
FrontEndMenu.lua
Code: Select all
local frontEndMenu = nil
function load_FrontEndMenu()
-- initalize necessary Lua objects that represent the FrontEndMenu
end
function unload_FrontEndMenu()
-- destroy the menu by setting it to nil
frontEndMenu = nil
end
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.