Crazy Eddies GUI System  0.6.2
CEGUILua.h
1 /***********************************************************************
2  filename: CEGUILua.h
3  created: 16/3/2005
4  author: Tomas Lindquist Olsen
5 
6  purpose: Defines interface for LuaScriptModule class
7 *************************************************************************/
8 /***************************************************************************
9  * Copyright (C) 2004 - 2008 Paul D Turner & The CEGUI Development Team
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining
12  * a copy of this software and associated documentation files (the
13  * "Software"), to deal in the Software without restriction, including
14  * without limitation the rights to use, copy, modify, merge, publish,
15  * distribute, sublicense, and/or sell copies of the Software, and to
16  * permit persons to whom the Software is furnished to do so, subject to
17  * the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be
20  * included in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
26  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
27  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28  * OTHER DEALINGS IN THE SOFTWARE.
29  ***************************************************************************/
30 #ifndef _CEGUILua_h_
31 #define _CEGUILua_h_
32 
33 
34 /*************************************************************************
35  Import / Export control macros
36 *************************************************************************/
37 #if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUI_STATIC)
38 # ifdef CEGUILUA_EXPORTS
39 # define CEGUILUA_API __declspec(dllexport)
40 # else
41 # define CEGUILUA_API __declspec(dllimport)
42 # endif
43 #else
44 # define CEGUILUA_API
45 #endif
46 
47 
48 #include "CEGUIScriptModule.h"
49 
50 struct lua_State;
51 
52 // Start of CEGUI namespace section
53 namespace CEGUI
54 {
55 
60 class CEGUILUA_API LuaScriptModule : public CEGUI::ScriptModule
61 {
62 public:
63  /*************************************************************************
64  Construction and Destruction
65  *************************************************************************/
71 
72 
80  LuaScriptModule(lua_State* state);
81 
82 
87  ~LuaScriptModule();
88 
89 
90  /*************************************************************************
91  Script Execution Functions
92  *************************************************************************/
105  void executeScriptFile(const String& filename, const String& resourceGroup);
106 
124  void executeScriptFile(const String& filename,
125  const String& resourceGroup,
126  const String& error_handler);
127 
145  void executeScriptFile(const String& filename,
146  const String& resourceGroup,
147  const int error_handler);
148 
161  int executeScriptGlobal(const String& function_name);
162 
180  int executeScriptGlobal(const String& function_name,
181  const String& error_handler);
182 
200  int executeScriptGlobal(const String& function_name,
201  const int error_handler);
202 
203 
222  bool executeScriptedEventHandler(const String& handler_name,
223  const EventArgs& e);
224 
248  bool executeScriptedEventHandler(const String& handler_name,
249  const EventArgs& e,
250  const String& error_handler);
251 
275  bool executeScriptedEventHandler(const String& handler_name,
276  const EventArgs& e,
277  const int error_handler);
278 
289  void executeString(const String& str);
290 
306  void executeString(const String& str, const String& error_handler);
307 
323  void executeString(const String& str, const int error_handler);
324 
325  /*************************************************************************
326  Event subscription
327  *************************************************************************/
346  Event::Connection subscribeEvent(EventSet* target, const String& name,
347  const String& subscriber_name);
348 
372  Event::Connection subscribeEvent(EventSet* target, const String& name,
373  const String& subscriber_name,
374  const String& error_handler);
375 
399  Event::Connection subscribeEvent(EventSet* target, const String& name,
400  const String& subscriber_name,
401  const int error_handler);
402 
425  Event::Connection subscribeEvent(EventSet* target, const String& name,
426  Event::Group group,
427  const String& subscriber_name);
428 
456  Event::Connection subscribeEvent(EventSet* target, const String& name,
457  Event::Group group,
458  const String& subscriber_name,
459  const String& error_handler);
460 
488  Event::Connection subscribeEvent(EventSet* target, const String& name,
489  Event::Group group,
490  const String& subscriber_name,
491  const int error_handler);
492 
493  /*************************************************************************
494  Bindings creation / destruction
495  *************************************************************************/
506  void createBindings(void);
507 
518  void destroyBindings(void);
519 
520  /*************************************************************************
521  Accessor type functions
522  *************************************************************************/
531  lua_State* getLuaState(void) const {return d_state;}
532 
533  /*************************************************************************
534  Lua error handler related functions
535  *************************************************************************/
546  void setDefaultPCallErrorHandler(const String& error_handler_function);
547 
557  void setDefaultPCallErrorHandler(int function_reference);
558 
573  const String& getActivePCallErrorHandlerString() const;
574 
597  int getActivePCallErrorHandlerReference() const;
598 
599 private:
600  /*************************************************************************
601  Implementation Functions
602  *************************************************************************/
603  void setModuleIdentifierString();
608  int initErrorHandlerFunc();
613  int initErrorHandlerFunc(const String func_name);
618  int initErrorHandlerFunc(int func);
619 
625  void cleanupErrorHandlerFunc();
626 
628  void unrefErrorFunc();
629 
631  void executeScriptFile_impl(const String& filename,
632  const String& resourceGroup,
633  const int err_idx, const int top);
634 
636  int executeScriptGlobal_impl(const String& function_name,
637  const int err_idx, const int top);
638 
640  bool executeScriptedEventHandler_impl(const String& handler_name,
641  const EventArgs& e,
642  const int err_idx, const int top);
643 
645  void executeString_impl(const String& str, const int err_idx, const int top);
646 
647  /*************************************************************************
648  Implementation Data
649  *************************************************************************/
651  bool d_ownsState;
653  lua_State* d_state;
655  String d_errFuncName;
657  int d_errFuncIndex;
661  String d_activeErrFuncName;
665  int d_activeErrFuncIndex;
666 };
667 
668 } // namespace CEGUI
669 
670 #endif // end of guard _CEGUILua_h_