Crazy Eddies GUI System  0.7.1
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  *************************************************************************/
74  static LuaScriptModule& create(lua_State* state = 0);
75 
77  static void destroy(LuaScriptModule& mod);
78 
79 
80  /*************************************************************************
81  Script Execution Functions
82  *************************************************************************/
95  void executeScriptFile(const String& filename, const String& resourceGroup);
96 
114  void executeScriptFile(const String& filename,
115  const String& resourceGroup,
116  const String& error_handler);
117 
135  void executeScriptFile(const String& filename,
136  const String& resourceGroup,
137  const int error_handler);
138 
151  int executeScriptGlobal(const String& function_name);
152 
170  int executeScriptGlobal(const String& function_name,
171  const String& error_handler);
172 
190  int executeScriptGlobal(const String& function_name,
191  const int error_handler);
192 
193 
212  bool executeScriptedEventHandler(const String& handler_name,
213  const EventArgs& e);
214 
238  bool executeScriptedEventHandler(const String& handler_name,
239  const EventArgs& e,
240  const String& error_handler);
241 
265  bool executeScriptedEventHandler(const String& handler_name,
266  const EventArgs& e,
267  const int error_handler);
268 
279  void executeString(const String& str);
280 
296  void executeString(const String& str, const String& error_handler);
297 
313  void executeString(const String& str, const int error_handler);
314 
315  /*************************************************************************
316  Event subscription
317  *************************************************************************/
336  Event::Connection subscribeEvent(EventSet* target, const String& name,
337  const String& subscriber_name);
338 
362  Event::Connection subscribeEvent(EventSet* target, const String& name,
363  const String& subscriber_name,
364  const String& error_handler);
365 
389  Event::Connection subscribeEvent(EventSet* target, const String& name,
390  const String& subscriber_name,
391  const int error_handler);
392 
415  Event::Connection subscribeEvent(EventSet* target, const String& name,
416  Event::Group group,
417  const String& subscriber_name);
418 
446  Event::Connection subscribeEvent(EventSet* target, const String& name,
447  Event::Group group,
448  const String& subscriber_name,
449  const String& error_handler);
450 
478  Event::Connection subscribeEvent(EventSet* target, const String& name,
479  Event::Group group,
480  const String& subscriber_name,
481  const int error_handler);
482 
483  /*************************************************************************
484  Bindings creation / destruction
485  *************************************************************************/
496  void createBindings(void);
497 
508  void destroyBindings(void);
509 
510  /*************************************************************************
511  Accessor type functions
512  *************************************************************************/
521  lua_State* getLuaState(void) const {return d_state;}
522 
523  /*************************************************************************
524  Lua error handler related functions
525  *************************************************************************/
536  void setDefaultPCallErrorHandler(const String& error_handler_function);
537 
547  void setDefaultPCallErrorHandler(int function_reference);
548 
563  const String& getActivePCallErrorHandlerString() const;
564 
587  int getActivePCallErrorHandlerReference() const;
588 
589 private:
590  /*************************************************************************
591  Implementation Functions
592  *************************************************************************/
601  LuaScriptModule(lua_State* state);
602 
604  ~LuaScriptModule();
605 
606 
607  void setModuleIdentifierString();
612  int initErrorHandlerFunc();
617  int initErrorHandlerFunc(const String func_name);
622  int initErrorHandlerFunc(int func);
623 
629  void cleanupErrorHandlerFunc();
630 
632  void unrefErrorFunc();
633 
635  void executeScriptFile_impl(const String& filename,
636  const String& resourceGroup,
637  const int err_idx, const int top);
638 
640  int executeScriptGlobal_impl(const String& function_name,
641  const int err_idx, const int top);
642 
644  bool executeScriptedEventHandler_impl(const String& handler_name,
645  const EventArgs& e,
646  const int err_idx, const int top);
647 
649  void executeString_impl(const String& str, const int err_idx, const int top);
650 
651  /*************************************************************************
652  Implementation Data
653  *************************************************************************/
655  bool d_ownsState;
657  lua_State* d_state;
659  String d_errFuncName;
661  int d_errFuncIndex;
665  String d_activeErrFuncName;
669  int d_activeErrFuncIndex;
670 };
671 
672 } // namespace CEGUI
673 
674 #endif // end of guard _CEGUILua_h_