Crazy Eddies GUI System
0.7.6
|
00001 /*********************************************************************** 00002 filename: CEGUILua.h 00003 created: 16/3/2005 00004 author: Tomas Lindquist Olsen 00005 00006 purpose: Defines interface for LuaScriptModule class 00007 *************************************************************************/ 00008 /*************************************************************************** 00009 * Copyright (C) 2004 - 2008 Paul D Turner & The CEGUI Development Team 00010 * 00011 * Permission is hereby granted, free of charge, to any person obtaining 00012 * a copy of this software and associated documentation files (the 00013 * "Software"), to deal in the Software without restriction, including 00014 * without limitation the rights to use, copy, modify, merge, publish, 00015 * distribute, sublicense, and/or sell copies of the Software, and to 00016 * permit persons to whom the Software is furnished to do so, subject to 00017 * the following conditions: 00018 * 00019 * The above copyright notice and this permission notice shall be 00020 * included in all copies or substantial portions of the Software. 00021 * 00022 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00023 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00024 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00025 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 00026 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00027 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00028 * OTHER DEALINGS IN THE SOFTWARE. 00029 ***************************************************************************/ 00030 #ifndef _CEGUILua_h_ 00031 #define _CEGUILua_h_ 00032 00033 00034 /************************************************************************* 00035 Import / Export control macros 00036 *************************************************************************/ 00037 #if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUI_STATIC) 00038 # ifdef CEGUILUA_EXPORTS 00039 # define CEGUILUA_API __declspec(dllexport) 00040 # else 00041 # define CEGUILUA_API __declspec(dllimport) 00042 # endif 00043 #else 00044 # define CEGUILUA_API 00045 #endif 00046 00047 00048 #include "../../CEGUIScriptModule.h" 00049 00050 struct lua_State; 00051 00052 // Start of CEGUI namespace section 00053 namespace CEGUI 00054 { 00055 00060 class CEGUILUA_API LuaScriptModule : public CEGUI::ScriptModule 00061 { 00062 public: 00063 /************************************************************************* 00064 Construction and Destruction 00065 *************************************************************************/ 00074 static LuaScriptModule& create(lua_State* state = 0); 00075 00077 static void destroy(LuaScriptModule& mod); 00078 00079 00080 /************************************************************************* 00081 Script Execution Functions 00082 *************************************************************************/ 00095 void executeScriptFile(const String& filename, const String& resourceGroup); 00096 00114 void executeScriptFile(const String& filename, 00115 const String& resourceGroup, 00116 const String& error_handler); 00117 00135 void executeScriptFile(const String& filename, 00136 const String& resourceGroup, 00137 const int error_handler); 00138 00151 int executeScriptGlobal(const String& function_name); 00152 00170 int executeScriptGlobal(const String& function_name, 00171 const String& error_handler); 00172 00190 int executeScriptGlobal(const String& function_name, 00191 const int error_handler); 00192 00193 00212 bool executeScriptedEventHandler(const String& handler_name, 00213 const EventArgs& e); 00214 00238 bool executeScriptedEventHandler(const String& handler_name, 00239 const EventArgs& e, 00240 const String& error_handler); 00241 00265 bool executeScriptedEventHandler(const String& handler_name, 00266 const EventArgs& e, 00267 const int error_handler); 00268 00279 void executeString(const String& str); 00280 00296 void executeString(const String& str, const String& error_handler); 00297 00313 void executeString(const String& str, const int error_handler); 00314 00315 /************************************************************************* 00316 Event subscription 00317 *************************************************************************/ 00336 Event::Connection subscribeEvent(EventSet* target, const String& name, 00337 const String& subscriber_name); 00338 00362 Event::Connection subscribeEvent(EventSet* target, const String& name, 00363 const String& subscriber_name, 00364 const String& error_handler); 00365 00389 Event::Connection subscribeEvent(EventSet* target, const String& name, 00390 const String& subscriber_name, 00391 const int error_handler); 00392 00415 Event::Connection subscribeEvent(EventSet* target, const String& name, 00416 Event::Group group, 00417 const String& subscriber_name); 00418 00446 Event::Connection subscribeEvent(EventSet* target, const String& name, 00447 Event::Group group, 00448 const String& subscriber_name, 00449 const String& error_handler); 00450 00478 Event::Connection subscribeEvent(EventSet* target, const String& name, 00479 Event::Group group, 00480 const String& subscriber_name, 00481 const int error_handler); 00482 00483 /************************************************************************* 00484 Bindings creation / destruction 00485 *************************************************************************/ 00496 void createBindings(void); 00497 00508 void destroyBindings(void); 00509 00510 /************************************************************************* 00511 Accessor type functions 00512 *************************************************************************/ 00521 lua_State* getLuaState(void) const {return d_state;} 00522 00523 /************************************************************************* 00524 Lua error handler related functions 00525 *************************************************************************/ 00536 void setDefaultPCallErrorHandler(const String& error_handler_function); 00537 00547 void setDefaultPCallErrorHandler(int function_reference); 00548 00563 const String& getActivePCallErrorHandlerString() const; 00564 00587 int getActivePCallErrorHandlerReference() const; 00588 00589 private: 00590 /************************************************************************* 00591 Implementation Functions 00592 *************************************************************************/ 00601 LuaScriptModule(lua_State* state); 00602 00604 ~LuaScriptModule(); 00605 00606 00607 void setModuleIdentifierString(); 00612 int initErrorHandlerFunc(); 00617 int initErrorHandlerFunc(const String func_name); 00622 int initErrorHandlerFunc(int func); 00623 00629 void cleanupErrorHandlerFunc(); 00630 00632 void unrefErrorFunc(); 00633 00635 void executeScriptFile_impl(const String& filename, 00636 const String& resourceGroup, 00637 const int err_idx, const int top); 00638 00640 int executeScriptGlobal_impl(const String& function_name, 00641 const int err_idx, const int top); 00642 00644 bool executeScriptedEventHandler_impl(const String& handler_name, 00645 const EventArgs& e, 00646 const int err_idx, const int top); 00647 00649 void executeString_impl(const String& str, const int err_idx, const int top); 00650 00651 /************************************************************************* 00652 Implementation Data 00653 *************************************************************************/ 00655 bool d_ownsState; 00657 lua_State* d_state; 00659 String d_errFuncName; 00661 int d_errFuncIndex; 00665 String d_activeErrFuncName; 00669 int d_activeErrFuncIndex; 00670 }; 00671 00672 } // namespace CEGUI 00673 00674 #endif // end of guard _CEGUILua_h_