Crazy Eddies GUI System  0.7.6
CEGUILuaFunctor.h
00001 /***********************************************************************
00002     filename: CEGUILuaFunctor.h
00003     created:  Thu Jan 26 2006
00004     author:   Tomas Lindquist Olsen <tomas@famolsen.dk>
00005 
00006     purpose:  Defines interface for LuaFunctor 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 _CEGUILuaFunctor_h_
00031 #define _CEGUILuaFunctor_h_
00032 
00033 #include "../../CEGUIEventSet.h"
00034 
00035 struct lua_State;
00036 
00037 // Start of CEGUI namespace section
00038 namespace CEGUI
00039 {
00040 
00041 // forward declaration
00042 class LuaScriptModule;
00043 
00048 class LuaFunctor
00049 {
00050 public:
00051     LuaFunctor(lua_State* state, int func, int selfIndex);
00052     LuaFunctor(lua_State* state, const String& func, int selfIndex);
00053 
00054     LuaFunctor(lua_State* state, const int func, const int selfIndex,
00055                const String& error_handler);
00056     LuaFunctor(lua_State* state, const String& func, const int selfIndex,
00057                const String& error_handler);
00058     LuaFunctor(lua_State* state, const int func, const int selfIndex,
00059                const int error_handler);
00060     LuaFunctor(lua_State* state, const String& func, const int selfIndex,
00061                const int error_handler);
00062 
00063     LuaFunctor(const LuaFunctor& cp);
00064     ~LuaFunctor();
00065 
00066     bool operator()(const EventArgs& args) const;
00067 
00074     static Event::Connection SubscribeEvent(EventSet* self,
00075                                             const String& eventName,
00076                                             const int funcIndex,
00077                                             const int selfIndex,
00078                                             const int error_handler,
00079                                             lua_State* L);
00080 
00086     static void pushNamedFunction(lua_State* L, const String& name);
00087 
00088 private:
00095     void invalidateLuaRefs();
00096 
00097     lua_State* L;
00098     mutable int index;
00099     int self;
00100     mutable bool needs_lookup;
00101     mutable String function_name;
00102 
00104     mutable String d_errFuncName;
00106     mutable int d_errFuncIndex;
00108     mutable bool d_ourErrFuncIndex;
00109 
00110     friend class LuaScriptModule;
00111 };
00112 
00113 } // namespace CEGUI
00114 
00115 #endif // end of guard _CEGUILuaFunctor_h_