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