Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/ceguilua/ceguilua-0.6.2/ceguilua/CEGUILuaFunctor.h @ 2710

Last change on this file since 2710 was 2710, checked in by rgrieder, 15 years ago

Merged buildsystem3 containing buildsystem2 containing Adi's buildsystem branch back to the trunk.
Please update the media directory if you were not using buildsystem3 before.

  • Property svn:eol-style set to native
File size: 3.9 KB
Line 
1/***********************************************************************
2    filename: CEGUILuaFunctor.h
3    created:  Thu Jan 26 2006
4    author:   Tomas Lindquist Olsen <tomas@famolsen.dk>
5
6    purpose:  Defines interface for LuaFunctor 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 _CEGUILuaFunctor_h_
31#define _CEGUILuaFunctor_h_
32
33#include "CEGUIEventSet.h"
34#include "CEGUIScriptWindowHelper.h"
35
36struct lua_State;
37
38// Start of CEGUI namespace section
39namespace CEGUI
40{
41
42// forward declaration
43class LuaScriptModule;
44
45/*!
46\brief
47    Functor class used for subscribing Lua functions to CEGUI events
48*/
49class LuaFunctor
50{
51public:
52    LuaFunctor(lua_State* state, int func, int selfIndex);
53    LuaFunctor(lua_State* state, const String& func, int selfIndex);
54
55    LuaFunctor(lua_State* state, const int func, const int selfIndex,
56               const String& error_handler);
57    LuaFunctor(lua_State* state, const String& func, const int selfIndex,
58               const String& error_handler);
59    LuaFunctor(lua_State* state, const int func, const int selfIndex,
60               const int error_handler);
61    LuaFunctor(lua_State* state, const String& func, const int selfIndex,
62               const int error_handler);
63
64    LuaFunctor(const LuaFunctor& cp);
65    ~LuaFunctor();
66
67    bool operator()(const EventArgs& args) const;
68
69    /*!
70    \brief
71        function used to subscribe any Lua function as event handler.
72        References using the Lua registry.
73        To be called from Lua only.
74    */
75    static Event::Connection SubscribeEvent(EventSet* self,
76                                            const String& eventName,
77                                            const int funcIndex,
78                                            const int selfIndex,
79                                            const int error_handler,
80                                            lua_State* L);
81
82    /*!
83    \brief
84        Pushes the Lua function named \param name on top of the Lua stack.
85        The name may contain '.' (dots) character for (nested) table values.
86    */
87    static void pushNamedFunction(lua_State* L, const String& name);
88
89private:
90    lua_State* L;
91    mutable int index;
92    int self;
93    mutable bool needs_lookup;
94    mutable String function_name;
95
96    //! Error handler function to pass to lua_pcall.
97    mutable String d_errFuncName;
98    //! registry index of the function to pass to lua_pcall.
99    mutable int d_errFuncIndex;
100    //! signfies whether we made the reference index at d_errFuncIndex.
101    mutable bool d_ourErrFuncIndex;
102
103    friend class LuaScriptModule;
104};
105
106} // namespace CEGUI
107
108#endif // end of guard _CEGUILuaFunctor_h_
Note: See TracBrowser for help on using the repository browser.