Crazy Eddie's GUI System  0.8.7
ScriptModules/Lua/ScriptModule.h
1 /***********************************************************************
2  created: 16/3/2005
3  author: Tomas Lindquist Olsen
4 
5  purpose: Defines interface for LuaScriptModule class
6 *************************************************************************/
7 /***************************************************************************
8  * Copyright (C) 2004 - 2008 Paul D Turner & The CEGUI Development Team
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining
11  * a copy of this software and associated documentation files (the
12  * "Software"), to deal in the Software without restriction, including
13  * without limitation the rights to use, copy, modify, merge, publish,
14  * distribute, sublicense, and/or sell copies of the Software, and to
15  * permit persons to whom the Software is furnished to do so, subject to
16  * the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be
19  * included in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27  * OTHER DEALINGS IN THE SOFTWARE.
28  ***************************************************************************/
29 #ifndef _CEGUILua_h_
30 #define _CEGUILua_h_
31 
32 
33 /*************************************************************************
34  Import / Export control macros
35 *************************************************************************/
36 #if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUI_STATIC)
37 # ifdef CEGUILUASCRIPTMODULE_EXPORTS
38 # define CEGUILUA_API __declspec(dllexport)
39 # else
40 # define CEGUILUA_API __declspec(dllimport)
41 # endif
42 #else
43 # define CEGUILUA_API
44 #endif
45 
46 
47 #include "CEGUI/ScriptModule.h"
48 
49 struct lua_State;
50 
51 // Start of CEGUI namespace section
52 namespace CEGUI
53 {
54 
59 class CEGUILUA_API LuaScriptModule : public CEGUI::ScriptModule
60 {
61 public:
62  /*************************************************************************
63  Construction and Destruction
64  *************************************************************************/
73  static LuaScriptModule& create(lua_State* state = 0);
74 
76  static void destroy(LuaScriptModule& mod);
77 
78 
79  /*************************************************************************
80  Script Execution Functions
81  *************************************************************************/
94  void executeScriptFile(const String& filename, const String& resourceGroup);
95 
113  void executeScriptFile(const String& filename,
114  const String& resourceGroup,
115  const String& error_handler);
116 
134  void executeScriptFile(const String& filename,
135  const String& resourceGroup,
136  const int error_handler);
137 
150  int executeScriptGlobal(const String& function_name);
151 
169  int executeScriptGlobal(const String& function_name,
170  const String& error_handler);
171 
189  int executeScriptGlobal(const String& function_name,
190  const int error_handler);
191 
192 
211  bool executeScriptedEventHandler(const String& handler_name,
212  const EventArgs& e);
213 
237  bool executeScriptedEventHandler(const String& handler_name,
238  const EventArgs& e,
239  const String& error_handler);
240 
264  bool executeScriptedEventHandler(const String& handler_name,
265  const EventArgs& e,
266  const int error_handler);
267 
278  void executeString(const String& str);
279 
295  void executeString(const String& str, const String& error_handler);
296 
312  void executeString(const String& str, const int error_handler);
313 
314  /*************************************************************************
315  Event subscription
316  *************************************************************************/
335  Event::Connection subscribeEvent(EventSet* target, const String& name,
336  const String& subscriber_name);
337 
361  Event::Connection subscribeEvent(EventSet* target, const String& name,
362  const String& subscriber_name,
363  const String& error_handler);
364 
388  Event::Connection subscribeEvent(EventSet* target, const String& name,
389  const String& subscriber_name,
390  const int error_handler);
391 
414  Event::Connection subscribeEvent(EventSet* target, const String& name,
415  Event::Group group,
416  const String& subscriber_name);
417 
445  Event::Connection subscribeEvent(EventSet* target, const String& name,
446  Event::Group group,
447  const String& subscriber_name,
448  const String& error_handler);
449 
477  Event::Connection subscribeEvent(EventSet* target, const String& name,
478  Event::Group group,
479  const String& subscriber_name,
480  const int error_handler);
481 
482  /*************************************************************************
483  Bindings creation / destruction
484  *************************************************************************/
495  void createBindings(void);
496 
507  void destroyBindings(void);
508 
509  /*************************************************************************
510  Accessor type functions
511  *************************************************************************/
520  lua_State* getLuaState(void) const {return d_state;}
521 
522  /*************************************************************************
523  Lua error handler related functions
524  *************************************************************************/
535  void setDefaultPCallErrorHandler(const String& error_handler_function);
536 
546  void setDefaultPCallErrorHandler(int function_reference);
547 
562  const String& getActivePCallErrorHandlerString() const;
563 
586  int getActivePCallErrorHandlerReference() const;
587 
588 private:
589  /*************************************************************************
590  Implementation Functions
591  *************************************************************************/
600  LuaScriptModule(lua_State* state);
601 
603  ~LuaScriptModule();
604 
605 
606  void setModuleIdentifierString();
611  int initErrorHandlerFunc();
616  int initErrorHandlerFunc(const String func_name);
621  int initErrorHandlerFunc(int func);
622 
628  void cleanupErrorHandlerFunc();
629 
631  void unrefErrorFunc();
632 
634  void executeScriptFile_impl(const String& filename,
635  const String& resourceGroup,
636  const int err_idx, const int top);
637 
639  int executeScriptGlobal_impl(const String& function_name,
640  const int err_idx, const int top);
641 
643  bool executeScriptedEventHandler_impl(const String& handler_name,
644  const EventArgs& e,
645  const int err_idx, const int top);
646 
648  void executeString_impl(const String& str, const int err_idx, const int top);
649 
650  /*************************************************************************
651  Implementation Data
652  *************************************************************************/
654  bool d_ownsState;
656  lua_State* d_state;
658  String d_errFuncName;
660  int d_errFuncIndex;
664  String d_activeErrFuncName;
668  int d_activeErrFuncIndex;
669 };
670 
671 } // namespace CEGUI
672 
673 #endif // end of guard _CEGUILua_h_
Abstract interface required for all scripting support modules to be used with the CEGUI system...
Definition: ScriptModule.h:45
Main namespace for Crazy Eddie's GUI Library.
Definition: arch_overview.dox:1
Base class used as the argument to all subscribers Event object.
Definition: EventArgs.h:49
Interface for the LuaScriptModule class.
Definition: ScriptModules/Lua/ScriptModule.h:59
lua_State * getLuaState(void) const
Method used to get a pointer to the lua_State that the script module is attached to.
Definition: ScriptModules/Lua/ScriptModule.h:520
Interface providing event signaling and handling.
Definition: EventSet.h:166
unsigned int Group
Type for a subscriber group. You can use the subscriber group to order calls to multiple subscribers...
Definition: Event.h:84
String class used within the GUI system.
Definition: String.h:62