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 - 2006 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 ) |
---|
38 | # ifdef CEGUILUA_EXPORTS |
---|
39 | # define CEGUILUA_API __declspec(dllexport) |
---|
40 | # else |
---|
41 | # if defined( __MINGW32__ ) |
---|
42 | # define CEGUILUA_API |
---|
43 | # else |
---|
44 | # define CEGUILUA_API __declspec(dllimport) |
---|
45 | # endif |
---|
46 | # endif |
---|
47 | #else |
---|
48 | # define CEGUILUA_API |
---|
49 | #endif |
---|
50 | |
---|
51 | |
---|
52 | #include "CEGUIScriptModule.h" |
---|
53 | |
---|
54 | struct lua_State; |
---|
55 | |
---|
56 | // Start of CEGUI namespace section |
---|
57 | namespace CEGUI |
---|
58 | { |
---|
59 | |
---|
60 | /*! |
---|
61 | \brief |
---|
62 | Interface for the LuaScriptModule class |
---|
63 | */ |
---|
64 | class CEGUILUA_API LuaScriptModule : public CEGUI::ScriptModule |
---|
65 | { |
---|
66 | public: |
---|
67 | /************************************************************************* |
---|
68 | Construction and Destruction |
---|
69 | *************************************************************************/ |
---|
70 | /*! |
---|
71 | \brief |
---|
72 | Constructor for LuaScriptModule class which create a lua_State |
---|
73 | */ |
---|
74 | LuaScriptModule(); |
---|
75 | |
---|
76 | |
---|
77 | /*! |
---|
78 | \brief |
---|
79 | Constructor for LuaScriptModule class which takes a lua_State |
---|
80 | |
---|
81 | \param state |
---|
82 | Pointer to the lua_State that the script module should attach to. |
---|
83 | */ |
---|
84 | LuaScriptModule(lua_State* state); |
---|
85 | |
---|
86 | |
---|
87 | /*! |
---|
88 | \brief |
---|
89 | Destructor for LuaScriptModule class. |
---|
90 | */ |
---|
91 | ~LuaScriptModule(); |
---|
92 | |
---|
93 | |
---|
94 | /************************************************************************* |
---|
95 | Script Execution Functions |
---|
96 | *************************************************************************/ |
---|
97 | /*! |
---|
98 | \brief |
---|
99 | Execute a script file. |
---|
100 | |
---|
101 | \param filename |
---|
102 | String object holding the filename of the script file that is to be executed |
---|
103 | |
---|
104 | \param resourceGroup |
---|
105 | Resource group idendifier to be passed to the ResourceProvider when loading the script file. |
---|
106 | */ |
---|
107 | void executeScriptFile(const String& filename, const String& resourceGroup); |
---|
108 | |
---|
109 | |
---|
110 | /*! |
---|
111 | \brief |
---|
112 | Execute a scripted global function. The function should not take any parameters and should return an integer. |
---|
113 | |
---|
114 | \param function_name |
---|
115 | String object holding the name of the function, in the global script environment, that |
---|
116 | is to be executed. |
---|
117 | |
---|
118 | \return |
---|
119 | The integer value returned from the script function. |
---|
120 | */ |
---|
121 | int executeScriptGlobal(const String& function_name); |
---|
122 | |
---|
123 | |
---|
124 | /*! |
---|
125 | \brief |
---|
126 | Execute a scripted global 'event handler' function by looking it up by name. |
---|
127 | |
---|
128 | \param handler_name |
---|
129 | String object holding the name of the scripted handler function. |
---|
130 | If this string contains dots '.' it will be parsed as tables containing a function field. |
---|
131 | For example: 'mytable.subtable.func' |
---|
132 | |
---|
133 | \param e |
---|
134 | EventArgs based object that should be passed, by any appropriate means, to the scripted function. |
---|
135 | |
---|
136 | \return |
---|
137 | - true if the event was handled. |
---|
138 | - false if the event was not handled. |
---|
139 | */ |
---|
140 | bool executeScriptedEventHandler(const String& handler_name, const EventArgs& e); |
---|
141 | |
---|
142 | |
---|
143 | /*! |
---|
144 | \brief |
---|
145 | Execute script code contained in the given CEGUI::String object. |
---|
146 | |
---|
147 | \param str |
---|
148 | String object holding the valid script code that should be executed. |
---|
149 | |
---|
150 | \return |
---|
151 | Nothing. |
---|
152 | */ |
---|
153 | void executeString(const String& str); |
---|
154 | |
---|
155 | /************************************************************************* |
---|
156 | Event subscription |
---|
157 | *************************************************************************/ |
---|
158 | /*! |
---|
159 | \brief |
---|
160 | Subscribes the named Event to a scripted funtion |
---|
161 | |
---|
162 | \param target |
---|
163 | The target EventSet for the subscription. |
---|
164 | |
---|
165 | \param name |
---|
166 | String object containing the name of the Event to subscribe to. |
---|
167 | |
---|
168 | \param subscriber_name |
---|
169 | String object containing the name of the script funtion that is to be subscribed to the Event. |
---|
170 | |
---|
171 | \return |
---|
172 | Connection object that can be used to check the status of the Event connection and to disconnect (unsubscribe) from the Event. |
---|
173 | |
---|
174 | \exception UnknownObjectException Thrown if an Event named \a name is not in the EventSet |
---|
175 | */ |
---|
176 | Event::Connection subscribeEvent(EventSet* target, const String& name, const String& subscriber_name); |
---|
177 | |
---|
178 | /*! |
---|
179 | \brief |
---|
180 | Subscribes the specified group of the named Event to a scripted funtion. |
---|
181 | |
---|
182 | \param target |
---|
183 | The target EventSet for the subscription. |
---|
184 | |
---|
185 | \param name |
---|
186 | String object containing the name of the Event to subscribe to. |
---|
187 | |
---|
188 | \param group |
---|
189 | Group which is to be subscribed to. Subscription groups are called in ascending order. |
---|
190 | |
---|
191 | \param subscriber_name |
---|
192 | String object containing the name of the script funtion that is to be subscribed to the Event. |
---|
193 | |
---|
194 | \return |
---|
195 | Connection object that can be used to check the status of the Event connection and to disconnect (unsubscribe) from the Event. |
---|
196 | |
---|
197 | \exception UnknownObjectException Thrown if an Event named \a name is not in the EventSet |
---|
198 | */ |
---|
199 | Event::Connection subscribeEvent(EventSet* target, const String& name, Event::Group group, const String& subscriber_name); |
---|
200 | |
---|
201 | /************************************************************************* |
---|
202 | Bindings creation / destruction |
---|
203 | *************************************************************************/ |
---|
204 | /*! |
---|
205 | \brief |
---|
206 | Method called during system initialisation, prior to running any scripts via the ScriptModule, to enable the ScriptModule |
---|
207 | to perform any operations required to complete initialisation or binding of the script language to the gui system objects. |
---|
208 | |
---|
209 | \return |
---|
210 | Nothing. |
---|
211 | */ |
---|
212 | void createBindings(void); |
---|
213 | |
---|
214 | |
---|
215 | /*! |
---|
216 | \brief |
---|
217 | Method called during system destruction, after all scripts have been run via the ScriptModule, to enable the ScriptModule |
---|
218 | to perform any operations required to cleanup bindings of the script language to the gui system objects, as set-up in the |
---|
219 | earlier createBindings call. |
---|
220 | |
---|
221 | \return |
---|
222 | Nothing. |
---|
223 | */ |
---|
224 | void destroyBindings(void); |
---|
225 | |
---|
226 | /************************************************************************* |
---|
227 | Accessor type functions |
---|
228 | *************************************************************************/ |
---|
229 | /*! |
---|
230 | \brief |
---|
231 | Method used to get a pointer to the lua_State that the script module is attached to. |
---|
232 | |
---|
233 | \return |
---|
234 | A pointer to the lua_State that the script module is attached to. |
---|
235 | */ |
---|
236 | lua_State* getLuaState(void) const {return d_state;} |
---|
237 | |
---|
238 | private: |
---|
239 | /************************************************************************* |
---|
240 | Implementation Functions |
---|
241 | *************************************************************************/ |
---|
242 | void setModuleIdentifierString(); |
---|
243 | |
---|
244 | /************************************************************************* |
---|
245 | Implementation Data |
---|
246 | *************************************************************************/ |
---|
247 | bool d_ownsState; //!< true when the attached lua_State was created by this script module |
---|
248 | lua_State* d_state; //!< The lua_State that this script module uses. |
---|
249 | }; |
---|
250 | |
---|
251 | } // namespace CEGUI |
---|
252 | |
---|
253 | #endif // end of guard _CEGUILua_h_ |
---|