Getting started with Lua script in CEGUI

Source: Internet
Author: User

HowCEGUIUsed inLua scriptThis document describes how to get started.Lua scriptLanguage inCEGUIFor more information about how to use it, see the details in this article.

CEGUIThe script used is based on Lua5.0.2 and tolua ++ 1.06pre2-1.

A large part of interface compilation can be implemented through scripts. We can modify scripts without re-compiling the entire program,

This saves us a lot of time to design the interface.

CurrentLua scriptThe module is still in the initial development stage. It supports the vast majority of kernel systems and grass-roots window classes. However, some special controls can only be set through the properties system currently.

OK. Let's get started! You must have a certain level of CEGUI basics, such as initialization and window creation. Of course, you must have a certain level of Lua basics.
Initialization

The Lua script module contains all management classes. Therefore, you can use the Lua script to initialize the CEGUI. For example:

 
 
  1. # Include "CEGUILua. h"
  2. CEGUI: YourRendererOfChoice * renderer = new YourRendererOfChoice;
  3. CEGUI: LuaScriptModule * script_module = new CEGUI: LuaScriptModule ();
  4.  
  5. // Set the xml Parser for the second parameter. 0 indicates the default parser.
  6. New CEGUI: System (renderer, 0, script_module );

Now the CEGUI: System has been created and the script module has been specified. At this point, the LuaScriptModule constructor automatically creates a lua_State for us. You can also pass a lua_State * to the LuaScriptModule constructor to use your own lua_State.

If you use a UDF in the initialization script, you need to do so. The Code is as follows:

 
 
  1. ...     
  2. lua_State* s = your_lua_state;     
  3. CEGUI::LuaScriptModule* script_module = new CEGUI::LuaScriptModule(s);     
  4. ...   

Initialization/exit script

CEGUIA configuration file is supported. Its file name is an optional parameter of the CEGUI: System constructor. The default value is "cegui. config ".

By setting this configuration file, you can control whether to execute a script during system creation and destruction. The content of the configuration file is similar to the following:

 
 
  1. <?xml version="1.0" ?>     
  2. <CEGUIConfig     
  3.     InitScript="../datafiles/scripts/init_script.lua"     
  4.     TerminateScript="../datafiles/scripts/exit_script.lua"     
  5. />   

Init_script.lua will be executed during system initializationLua scriptFile. The content can be as follows:

Obtain CEGUI singletons

 
 
  1. local logger = CEGUI.Logger:getSingleton()     
  2. logger:logEvent( ">>> Init script says hello" )     
  3. --logger:setLoggingLevel( CEGUI.Informative )    

Create a local variable for the singletons to be used)

 
 
  1. local system    = CEGUI.System:getSingleton()     
  2. local fontman   = CEGUI.FontManager:getSingleton()     
  3. local schememan = CEGUI.SchemeManager:getSingleton()    

Load schemes

 
 
  1. schememan:loadScheme( "../datafiles/schemes/TaharezLook.scheme" )     
  2. schememan:loadScheme( "../datafiles/schemes/WindowsLook.scheme" )    

Load default font

 
 
  1. local font = fontman:createFont( "../datafiles/fonts/Commonwealth-10.font" )    

Set Default mouse cursor

 
 
  1. system:setDefaultMouseCursor( "TaharezLook","MouseArrow" )     
  2.      
  3. logger:logEvent( "<<< Init script says goodbye" )   

Initialization and exit are not required at the same time.ScriptHowever, if you are initializingScriptIf you have applied for a globally used bucket, you must exitScriptTo release it or in other appropriate places ).

Summary: howCEGUIUsed inLua scriptI hope this article will be helpful to you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.