~ubuntu-branches/debian/sid/ember/sid

« back to all changes in this revision

Viewing changes to src/components/ogre/scripting/bindings/lua/helpers/LuaConnector.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-10-22 23:21:17 UTC
  • mfrom: (1.1.1 upstream) (2.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20091022232117-isr8u3402qmu7ilo
Tags: 0.5.7-1
* New upstream release.
  - Compile against current ogre (Closes: #551431)
  - Removed debian/patches/ember-gcc4.4.patch. Merged upstream.
  - Updated Depends on ember-media.
* Add libboost-thread-dev tp Build-Depends.
* Make debian/rules independent from upstream version.
* Updated watch file to allow automatic download of new upstream
  tarballs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//
2
2
// C++ Implementation: LuaConnectors
3
3
//
4
 
// Description: 
 
4
// Description:
5
5
//
6
6
//
7
7
// Author: Erik Hjortsberg <erik.hjortsberg@gmail.com>, (C) 2005
10
10
// it under the terms of the GNU General Public License as published by
11
11
// the Free Software Foundation; either version 2 of the License, or
12
12
// (at your option) any later version.
13
 
// 
 
13
//
14
14
// This program is distributed in the hope that it will be useful,
15
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
17
// GNU General Public License for more details.
18
 
// 
 
18
//
19
19
// You should have received a copy of the GNU General Public License
20
20
// along with this program; if not, write to the Free Software
21
21
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.//
25
25
#endif
26
26
 
27
27
#include "LuaConnector.h"
28
 
#include "LuaConnectorHelper.h"
29
 
 
30
 
#include "../../../luaobject.h"
 
28
#include "components/lua/LuaHelper.h"
 
29
#include "components/lua/luaobject.h"
31
30
 
32
31
#include "framework/Exception.h"
33
32
#include "services/EmberServices.h"
36
35
 
37
36
#include "components/ogre/MousePicker.h"
38
37
#include "components/ogre/EntityWorldPickListener.h"
39
 
#include "components/ogre/scripting/LuaHelper.h"
40
38
 
41
39
#include <Eris/Task.h>
42
40
 
46
44
 
47
45
using namespace Ember;
48
46
 
49
 
namespace EmberOgre {
50
 
 
51
 
namespace LuaConnectors {
52
 
 
53
 
ConnectorBase::ConnectorBase()
54
 
: mLuaFunctionIndex(LUA_NOREF)
55
 
{
56
 
}
57
 
 
58
 
 
59
 
ConnectorBase::ConnectorBase(const LuaTypeStore& luaTypeNames)
60
 
: mLuaTypeNames(luaTypeNames), mLuaFunctionIndex(LUA_NOREF)
61
 
{
62
 
}
63
 
 
64
 
ConnectorBase::~ConnectorBase() 
 
47
namespace EmberOgre
 
48
{
 
49
 
 
50
namespace LuaConnectors
 
51
{
 
52
 
 
53
ConnectorBase::ConnectorBase() :
 
54
        mLuaFunctionIndex(LUA_NOREF)
 
55
{
 
56
}
 
57
 
 
58
ConnectorBase::ConnectorBase(const LuaTypeStore& luaTypeNames) :
 
59
        mLuaTypeNames(luaTypeNames), mLuaFunctionIndex(LUA_NOREF)
 
60
{
 
61
}
 
62
 
 
63
ConnectorBase::~ConnectorBase()
65
64
{
66
65
        mConnection.disconnect();
67
66
}
71
70
        mConnection.disconnect();
72
71
}
73
72
 
74
 
 
75
73
void ConnectorBase::connect(const std::string & luaMethod)
76
74
{
77
75
        mLuaMethod = luaMethod;
82
80
        mLuaFunctionIndex = luaMethod;
83
81
}
84
82
 
85
 
 
86
83
void ConnectorBase::pushNamedFunction(lua_State* state)
87
84
{
88
 
        LuaConnectorHelper::pushNamedFunction(state, mLuaMethod);
 
85
        LuaHelper::pushNamedFunction(state, mLuaMethod);
89
86
}
90
87
 
91
88
//template<> void ConnectorBase::callLuaMethod(std::string t0, std::string t1, Empty t2, Empty t3);
92
 
template <typename Treturn, typename T0, typename T1, typename T2, typename T3> Treturn ConnectorBase::callLuaMethod(T0 t0, T1 t1, T2 t2, T3 t3)
 
89
template<typename Treturn, typename T0, typename T1, typename T2, typename T3> Treturn ConnectorBase::callLuaMethod(T0 t0, T1 t1, T2 t2, T3 t3)
93
90
{
94
 
        int numberOfArguments = static_cast<int>(mLuaTypeNames.size());
 
91
        int numberOfArguments = static_cast<int> (mLuaTypeNames.size());
95
92
        lua_State* state = EmberOgre::LuaConnector::getState();
96
93
        int top = lua_gettop(state);
97
94
        try {
98
 
        
 
95
 
99
96
                if (mLuaFunctionIndex == LUA_NOREF || Ember::EmberServices::getSingleton().getScriptingService()->getAlwaysLookup()) {
100
97
                        pushNamedFunction(state);
101
98
                        mLuaFunctionIndex = luaL_ref(state, LUA_REGISTRYINDEX);
103
100
 
104
101
                ///get the lua function
105
102
                lua_rawgeti(state, LUA_REGISTRYINDEX, mLuaFunctionIndex);
106
 
        
 
103
 
107
104
                LuaTypeStore::const_iterator I = mLuaTypeNames.begin();
108
 
                if (I != mLuaTypeNames.end()) 
 
105
                if (I != mLuaTypeNames.end())
109
106
                        EmberOgre::LuaConnector::pushValue(t0, (*I++));
110
 
                if (I != mLuaTypeNames.end()) 
 
107
                if (I != mLuaTypeNames.end())
111
108
                        EmberOgre::LuaConnector::pushValue(t1, (*I++));
112
 
                if (I != mLuaTypeNames.end()) 
 
109
                if (I != mLuaTypeNames.end())
113
110
                        EmberOgre::LuaConnector::pushValue(t2, (*I++));
114
 
                if (I != mLuaTypeNames.end()) 
 
111
                if (I != mLuaTypeNames.end())
115
112
                        EmberOgre::LuaConnector::pushValue(t3, (*I++));
116
 
                
 
113
 
117
114
                ///push our error handling method before calling the code
118
115
                int error_index = lua_gettop(state) - numberOfArguments;
119
 
                #if LUA51
120
 
                lua_pushcfunction(state, ::EmberOgre::Scripting::LuaHelper::luaErrorHandler);
121
 
                #else
 
116
#if LUA51
 
117
                lua_pushcfunction(state, LuaHelper::luaErrorHandler);
 
118
#else
122
119
                lua_pushliteral(state, "_TRACEBACK");
123
 
                lua_rawget(state, LUA_GLOBALSINDEX);  /* get traceback function */
124
 
                #endif
 
120
                lua_rawget(state, LUA_GLOBALSINDEX); /* get traceback function */
 
121
#endif
125
122
                lua_insert(state, error_index);/* put it under chunk and args */
126
 
                
 
123
 
127
124
                luaPop pop(state, 1); // pops error handler on exit
128
 
                
 
125
 
129
126
                /// call it
130
 
                int error = lua_pcall(state,numberOfArguments,LUA_MULTRET,error_index);
131
 
                        
 
127
                int error = lua_pcall(state, numberOfArguments, LUA_MULTRET, error_index);
 
128
 
132
129
                /// handle errors
133
 
                if ( error )
134
 
                {
 
130
                if (error) {
135
131
                        const std::string& msg = lua_tostring(state,-1);
136
 
                        lua_settop(state, top );
137
 
//                      lua_pop(state,numberOfArguments);
 
132
                        lua_settop(state, top);
 
133
                        //                      lua_pop(state,numberOfArguments);
138
134
                        throw Ember::Exception(msg);
139
135
                }
140
 
                
141
 
//              Treturn& returnValue(0);
 
136
 
 
137
                //              Treturn& returnValue(0);
142
138
                //return (Treturn)returnValueFromLua(state);
143
139
                //return returnValue;
144
140
 
145
 
        }
146
 
        catch( const CEGUI::String& str )
147
 
        {
148
 
                lua_settop(state, top );
 
141
        } catch (const CEGUI::String& str) {
 
142
                lua_settop(state, top);
149
143
                S_LOG_FAILURE("(LuaScriptModule) Unable to execute scripted event handler: "<<mLuaMethod<<"\n"<<str.c_str());
150
 
        }
151
 
        catch( const CEGUI::Exception& ex )
152
 
        {
153
 
                lua_settop(state, top );
 
144
        } catch (const CEGUI::Exception& ex) {
 
145
                lua_settop(state, top);
154
146
                S_LOG_FAILURE("(LuaScriptModule) Unable to execute scripted event handler: "<<mLuaMethod<<"\n"<<ex.getMessage().c_str());
155
 
        }
156
 
        catch(const std::exception& ex )
157
 
        {
158
 
                lua_settop(state, top );
159
 
                S_LOG_FAILURE("(LuaScriptModule) Unable to execute scripted event handler: " << mLuaMethod << "\n" << ex.what());
160
 
        } catch (...) 
161
 
        {
162
 
                lua_settop(state, top );
163
 
                S_LOG_FAILURE("Unspecified error when executing: " << mLuaMethod  );
164
 
        }
165
 
/*      void* test(0);
166
 
        return (Treturn)*test;*/
 
147
        } catch (const std::exception& ex) {
 
148
                lua_settop(state, top);
 
149
                S_LOG_FAILURE("(LuaScriptModule) Unable to execute scripted event handler '" << mLuaMethod << "'." << ex);
 
150
        } catch (...) {
 
151
                lua_settop(state, top);
 
152
                S_LOG_FAILURE("Unspecified error when executing: " << mLuaMethod );
 
153
        }
 
154
        /*      void* test(0);
 
155
         return (Treturn)*test;*/
167
156
}
168
157
 
169
 
template<typename Treturn> 
 
158
template<typename Treturn>
170
159
Treturn ConnectorBase::returnValueFromLua(lua_State* state)
171
160
{
172
 
        return static_cast<Treturn>(lua_touserdata(state,-1));
 
161
        return static_cast<Treturn> (lua_touserdata(state, -1));
173
162
}
174
163
 
175
164
// void ConnectorBase::returnValueFromLua(lua_State* state, bool& returnValueHolder)
176
165
// {
177
166
//      returnValueHolder = lua_toboolean(state,-1);
178
167
// }
179
 
// 
 
168
//
180
169
// void returnValueFromLua(lua_State* state)
181
170
// {
182
171
// }
183
172
 
184
 
template <typename Treturn> 
185
 
ConnectorZero<Treturn>::ConnectorZero(sigc::signal<Treturn>& signal) :  ConnectorBase(), mSignal(signal)
 
173
template<typename Treturn>
 
174
ConnectorZero<Treturn>::ConnectorZero(sigc::signal<Treturn>& signal) :
 
175
        ConnectorBase(), mSignal(signal)
186
176
{
187
177
        mConnection = mSignal.connect(sigc::mem_fun(*this, &ConnectorZero<Treturn>::signal_recieve));
188
178
}
189
179
 
190
 
template <typename Treturn, typename T0> 
191
 
ConnectorOne<Treturn, T0>::ConnectorOne(sigc::signal<Treturn, T0>& signal, const LuaTypeStore& luaTypeNames) :  ConnectorBase(luaTypeNames), mSignal(signal)
 
180
template<typename Treturn, typename T0>
 
181
ConnectorOne<Treturn, T0>::ConnectorOne(sigc::signal<Treturn, T0>& signal, const LuaTypeStore& luaTypeNames) :
 
182
        ConnectorBase(luaTypeNames), mSignal(signal)
192
183
{
193
184
        mConnection = mSignal.connect(sigc::mem_fun(*this, &ConnectorOne<Treturn, T0>::signal_recieve));
194
185
}
195
186
 
196
 
// template <typename Treturn, typename T0> 
 
187
// template <typename Treturn, typename T0>
197
188
// ConnectorOne<Treturn, T0>::ConnectorOne(SigC::Signal1<Treturn, T0>& signal, const LuaTypeStore& luaTypeNames) :
198
189
//  ConnectorBase(luaTypeNames), mSignal_old(signal)
199
190
// {
200
191
//      mConnection = mSignal_old.connect(sigc::mem_fun(*this, &ConnectorOne<Treturn, T0>::signal_recieve));
201
192
// }
202
193
 
203
 
template <typename Treturn, typename T0, typename T1> 
204
 
ConnectorTwo<Treturn, T0, T1>::ConnectorTwo(sigc::signal<Treturn, T0, T1>& signal, const LuaTypeStore& luaTypeNames) :  ConnectorBase(luaTypeNames), mSignal(signal)
 
194
template<typename Treturn, typename T0, typename T1>
 
195
ConnectorTwo<Treturn, T0, T1>::ConnectorTwo(sigc::signal<Treturn, T0, T1>& signal, const LuaTypeStore& luaTypeNames) :
 
196
        ConnectorBase(luaTypeNames), mSignal(signal)
205
197
{
206
198
        mConnection = mSignal.connect(sigc::mem_fun(*this, &ConnectorTwo<Treturn, T0, T1>::signal_recieve));
207
199
}
208
200
 
209
 
template <typename Treturn, typename T0, typename T1, typename T2> 
210
 
ConnectorThree<Treturn, T0, T1, T2>::ConnectorThree(sigc::signal<Treturn, T0, T1, T2>& signal, const LuaTypeStore& luaTypeNames) :  ConnectorBase(luaTypeNames), mSignal(signal)
 
201
template<typename Treturn, typename T0, typename T1, typename T2>
 
202
ConnectorThree<Treturn, T0, T1, T2>::ConnectorThree(sigc::signal<Treturn, T0, T1, T2>& signal, const LuaTypeStore& luaTypeNames) :
 
203
        ConnectorBase(luaTypeNames), mSignal(signal)
211
204
{
212
205
        mConnection = mSignal.connect(sigc::mem_fun(*this, &ConnectorThree<Treturn, T0, T1, T2>::signal_recieve));
213
206
}
214
207
 
215
 
template <typename Treturn, typename T0, typename T1, typename T2, typename T3> 
216
 
ConnectorFour<Treturn, T0, T1, T2, T3>::ConnectorFour(sigc::signal<Treturn, T0, T1, T2, T3>& signal, const LuaTypeStore& luaTypeNames) :  ConnectorBase(luaTypeNames), mSignal(signal)
 
208
template<typename Treturn, typename T0, typename T1, typename T2, typename T3>
 
209
ConnectorFour<Treturn, T0, T1, T2, T3>::ConnectorFour(sigc::signal<Treturn, T0, T1, T2, T3>& signal, const LuaTypeStore& luaTypeNames) :
 
210
        ConnectorBase(luaTypeNames), mSignal(signal)
217
211
{
218
212
        mConnection = mSignal.connect(sigc::mem_fun(*this, &ConnectorFour<Treturn, T0, T1, T2, T3>::signal_recieve));
219
213
}
220
214
 
221
 
 
222
 
template <typename Treturn>
 
215
template<typename Treturn>
223
216
Treturn ConnectorZero<Treturn>::signal_recieve()
224
217
{
225
 
        return callLuaMethod<Treturn, Empty, Empty, Empty, Empty>(Empty(), Empty(), Empty(), Empty());
 
218
        return callLuaMethod<Treturn, Empty, Empty, Empty, Empty> (Empty(), Empty(), Empty(), Empty());
226
219
}
227
220
 
228
 
template <typename Treturn, typename T0>
 
221
template<typename Treturn, typename T0>
229
222
Treturn ConnectorOne<Treturn, T0>::signal_recieve(T0 t0)
230
223
{
231
 
        return callLuaMethod<Treturn, T0, Empty, Empty, Empty>(t0, Empty(), Empty(), Empty());
 
224
        return callLuaMethod<Treturn, T0, Empty, Empty, Empty> (t0, Empty(), Empty(), Empty());
232
225
}
233
226
 
234
 
template <typename Treturn, typename T0, typename T1>
 
227
template<typename Treturn, typename T0, typename T1>
235
228
Treturn ConnectorTwo<Treturn, T0, T1>::signal_recieve(T0 t0, T1 t1)
236
229
{
237
 
        return callLuaMethod<Treturn, T0, T1, Empty, Empty>(t0, t1, Empty(), Empty());
 
230
        return callLuaMethod<Treturn, T0, T1, Empty, Empty> (t0, t1, Empty(), Empty());
238
231
}
239
232
 
240
 
template <typename Treturn, typename T0, typename T1, typename T2>
 
233
template<typename Treturn, typename T0, typename T1, typename T2>
241
234
Treturn ConnectorThree<Treturn, T0, T1, T2>::signal_recieve(T0 t0, T1 t1, T2 t2)
242
235
{
243
 
        return callLuaMethod<Treturn, T0, T1, T2, Empty>(t0, t1, t2, Empty());
 
236
        return callLuaMethod<Treturn, T0, T1, T2, Empty> (t0, t1, t2, Empty());
244
237
}
245
238
 
246
 
template <typename Treturn, typename T0, typename T1, typename T2, typename T3>
 
239
template<typename Treturn, typename T0, typename T1, typename T2, typename T3>
247
240
Treturn ConnectorFour<Treturn, T0, T1, T2, T3>::signal_recieve(T0 t0, T1 t1, T2 t2, T3 t3)
248
241
{
249
 
        return callLuaMethod<Treturn, T0, T1, T2, T3>(t0, t1, t2, t3);
250
 
}
251
 
 
252
 
 
253
 
};
254
 
 
255
 
template <typename T>
 
242
        return callLuaMethod<Treturn, T0, T1, T2, T3> (t0, t1, t2, t3);
 
243
}
 
244
 
 
245
}
 
246
;
 
247
 
 
248
template<typename T>
256
249
void LuaConnector::pushValue(T theValue, const std::string& luaTypename)
257
250
{
258
 
//      tolua_pushusertype(EmberOgre::LuaConnector::getState(),(void*)&theValue, luaTypename.c_str());
259
 
        tolua_pushusertype(EmberOgre::LuaConnector::getState(),(void*)theValue, luaTypename.c_str());
 
251
        //      tolua_pushusertype(EmberOgre::LuaConnector::getState(),(void*)&theValue, luaTypename.c_str());
 
252
        tolua_pushusertype(EmberOgre::LuaConnector::getState(), (void*)theValue, luaTypename.c_str());
260
253
}
261
254
 
262
255
void LuaConnector::pushValue(const Eris::ServerInfo& theValue, const std::string& luaTypename)
263
256
{
264
 
        tolua_pushusertype(EmberOgre::LuaConnector::getState(),(void*)&theValue, luaTypename.c_str());
 
257
        pushUserTypeValue(theValue, luaTypename);
265
258
}
266
259
 
267
 
void LuaConnector::pushValue(const std::string& theValue, const std::string& luaTypename) 
 
260
void LuaConnector::pushValue(const std::string& theValue, const std::string& luaTypename)
268
261
{
269
 
        tolua_pushstring(EmberOgre::LuaConnector::getState(),theValue.c_str());
 
262
        tolua_pushstring(EmberOgre::LuaConnector::getState(), theValue.c_str());
270
263
}
271
264
 
272
 
void LuaConnector::pushValue(LuaConnectors::Empty theValue, const std::string& luaTypename) 
 
265
void LuaConnector::pushValue(LuaConnectors::Empty theValue, const std::string& luaTypename)
273
266
{
274
267
}
275
268
 
276
269
void LuaConnector::pushValue(const float& theValue, const std::string& luaTypename)
277
270
{
278
 
        tolua_pushnumber(EmberOgre::LuaConnector::getState(),theValue);
 
271
        tolua_pushnumber(EmberOgre::LuaConnector::getState(), theValue);
279
272
}
280
273
 
281
274
void LuaConnector::pushValue(const long& theValue, const std::string& luaTypename)
282
275
{
283
 
        tolua_pushnumber(EmberOgre::LuaConnector::getState(),theValue);
 
276
        tolua_pushnumber(EmberOgre::LuaConnector::getState(), theValue);
284
277
}
285
278
 
286
279
void LuaConnector::pushValue(const unsigned long& theValue, const std::string& luaTypename)
287
280
{
288
 
        tolua_pushnumber(EmberOgre::LuaConnector::getState(),theValue);
 
281
        tolua_pushnumber(EmberOgre::LuaConnector::getState(), theValue);
289
282
}
290
283
 
291
284
void LuaConnector::pushValue(const unsigned int& theValue, const std::string& luaTypename)
292
285
{
293
 
        tolua_pushnumber(EmberOgre::LuaConnector::getState(),theValue);
 
286
        tolua_pushnumber(EmberOgre::LuaConnector::getState(), theValue);
294
287
}
295
288
 
296
 
 
297
289
void LuaConnector::pushValue(const int& theValue, const std::string& luaTypename)
298
290
{
299
 
        tolua_pushnumber(EmberOgre::LuaConnector::getState(),theValue);
 
291
        tolua_pushnumber(EmberOgre::LuaConnector::getState(), theValue);
300
292
}
301
293
 
302
294
void LuaConnector::pushValue(const EntityPickResult& theValue, const std::string& luaTypename)
303
295
{
304
 
        tolua_pushusertype(EmberOgre::LuaConnector::getState(),(void*)&theValue, luaTypename.c_str());
 
296
        pushUserTypeValue(theValue, luaTypename);
305
297
}
306
298
 
307
299
void LuaConnector::pushValue(const MousePickerArgs& theValue, const std::string& luaTypename)
308
300
{
309
 
        tolua_pushusertype(EmberOgre::LuaConnector::getState(),(void*)&theValue, luaTypename.c_str());
 
301
        pushUserTypeValue(theValue, luaTypename);
310
302
}
311
303
 
312
304
void LuaConnector::pushValue(const Input::MouseButton& theValue, const std::string& luaTypename)
317
309
{
318
310
        tolua_pushnumber(EmberOgre::LuaConnector::getState(), theValue);
319
311
}
320
 
        
 
312
 
321
313
void LuaConnector::pushValue(const std::set<std::string>& theValue, const std::string& luaTypename)
322
314
{
323
 
        tolua_pushusertype(EmberOgre::LuaConnector::getState(),(void*)&theValue, luaTypename.c_str());
 
315
        pushUserTypeValue(theValue, luaTypename);
324
316
}
325
317
 
326
318
void LuaConnector::pushValue(const Atlas::Message::Element& theValue, const std::string& luaTypename)
327
319
{
328
 
        tolua_pushusertype(EmberOgre::LuaConnector::getState(),(void*)&theValue, luaTypename.c_str());
 
320
        pushUserTypeValue(theValue, luaTypename);
329
321
}
330
322
 
331
 
void LuaConnector::pushValue(const EmberOgre::AvatarMovementMode::Mode& theValue, const std::string& luaTypename)
 
323
void LuaConnector::pushValue(const EmberOgre::MovementControllerMode::Mode& theValue, const std::string& luaTypename)
332
324
{
333
325
        tolua_pushnumber(EmberOgre::LuaConnector::getState(), theValue);
334
326
}
335
327
 
336
 
void LuaConnector::pushValue(const  EmberOgre::Terrain::TerrainPage& theValue, const std::string& luaTypename)
337
 
{
338
 
        tolua_pushusertype(EmberOgre::LuaConnector::getState(),(void*)&theValue, luaTypename.c_str());
339
 
}
340
 
 
 
328
void LuaConnector::pushValue(const EmberOgre::Terrain::TerrainPage& theValue, const std::string& luaTypename)
 
329
{
 
330
        pushUserTypeValue(theValue, luaTypename);
 
331
}
 
332
void LuaConnector::pushValue(const EmberOgre::EmberEntity& theValue, const std::string& luaTypename)
 
333
{
 
334
        pushUserTypeValue(theValue, luaTypename);
 
335
}
 
336
void LuaConnector::pushValue(const Atlas::Objects::Root& theValue, const std::string& luaTypename)
 
337
{
 
338
        pushUserTypeValue(theValue, luaTypename);
 
339
}
 
340
 
 
341
void LuaConnector::pushValue(const std::vector<EmberOgre::EntityPickResult>& theValue, const std::string& luaTypename)
 
342
{
 
343
        pushUserTypeValue(theValue, luaTypename);
 
344
}
 
345
 
 
346
void LuaConnector::pushValue(const EmberOgre::Authoring::EntityMover& theValue, const std::string& luaTypename)
 
347
{
 
348
        pushUserTypeValue(theValue, luaTypename);
 
349
}
 
350
 
 
351
template<typename T>
 
352
void LuaConnector::pushUserTypeValue(T& theValue, const std::string& luaTypename)
 
353
{
 
354
        tolua_pushusertype(EmberOgre::LuaConnector::getState(), (void*)&theValue, luaTypename.c_str());
 
355
}
341
356
 
342
357
LuaConnector::~LuaConnector()
343
358
{
372
387
                S_LOG_WARNING("Tried to connect lua method to a non existent signal.");
373
388
        } else {
374
389
                ///we need to get the correct lua function
375
 
                int luaType = lua_type(sState,-1);
376
 
                if (luaType == LUA_TFUNCTION)
377
 
                {
 
390
                int luaType = lua_type(sState, -1);
 
391
                if (luaType == LUA_TFUNCTION) {
378
392
                        int index = luaL_ref(sState, LUA_REGISTRYINDEX);
379
393
                        mConnector->connect(index);
380
394
                } else {
392
406
        }
393
407
}
394
408
 
395
 
 
396
 
 
397
 
 
398
 
 
399
 
bool LuaConnector::checkSignalExistence(void* signal) {
 
409
bool LuaConnector::checkSignalExistence(void* signal)
 
410
{
400
411
        if (!signal) {
401
412
                S_LOG_WARNING("Tried to connect lua to a non existent signal.");
402
413
                mConnector = 0;
403
414
                return false;
404
415
        }
405
416
        return true;
406
 
        
 
417
 
407
418
}
408
419
 
409
 
 
410
420
LuaConnector::LuaConnector(sigc::signal<void>& signal)
411
421
{
412
422
        if (checkSignalExistence(&signal)) {
461
471
        }
462
472
}
463
473
 
 
474
LuaConnector::LuaConnector(sigc::signal<void, const std::vector<EmberOgre::EntityPickResult>&, const MousePickerArgs&>& signal)
 
475
{
 
476
        if (checkSignalExistence(&signal)) {
 
477
                LuaTypeStore luaTypes;
 
478
                luaTypes.push_back("std::vector<EmberOgre::EntityPickResult>");
 
479
                luaTypes.push_back("EmberOgre::MousePickerArgs");
 
480
                mConnector = new LuaConnectors::ConnectorTwo<void, const std::vector<EmberOgre::EntityPickResult>&, const MousePickerArgs&>(signal, luaTypes);
 
481
        }
 
482
}
 
483
 
464
484
LuaConnector::LuaConnector(sigc::signal<void, const MousePickerArgs&>& signal)
465
485
{
466
486
        if (checkSignalExistence(&signal)) {
497
517
                mConnector = new LuaConnectors::ConnectorOne<void, EmberEntityFactory*>(signal, luaTypes);
498
518
        }
499
519
}
500
 
LuaConnector::LuaConnector(sigc::signal<void, AvatarEmberEntity*>& signal)
501
 
{
502
 
        if (checkSignalExistence(&signal)) {
503
 
                LuaTypeStore luaTypes;
504
 
                luaTypes.push_back("EmberOgre::AvatarEmberEntity");
505
 
                mConnector = new LuaConnectors::ConnectorOne<void, AvatarEmberEntity*>(signal, luaTypes);
506
 
        }
507
 
}
508
520
LuaConnector::LuaConnector(sigc::signal<void, Jesus*>& signal)
509
521
{
510
522
        if (checkSignalExistence(&signal)) {
521
533
                mConnector = new LuaConnectors::ConnectorOne<void, EmberEntity*>(signal, luaTypes);
522
534
        }
523
535
}
 
536
LuaConnector::LuaConnector(sigc::signal<void, EmberEntity&>& signal)
 
537
{
 
538
        if (checkSignalExistence(&signal)) {
 
539
                LuaTypeStore luaTypes;
 
540
                luaTypes.push_back("EmberOgre::EmberEntity");
 
541
                mConnector = new LuaConnectors::ConnectorOne<void, EmberEntity&>(signal, luaTypes);
 
542
        }
 
543
}
 
544
 
 
545
LuaConnector::LuaConnector(sigc::signal<void, EmberEntity&, EmberOgre::Authoring::EntityMover&>& signal)
 
546
{
 
547
        if (checkSignalExistence(&signal)) {
 
548
                LuaTypeStore luaTypes;
 
549
                luaTypes.push_back("EmberOgre::EmberEntity");
 
550
                luaTypes.push_back("EmberOgre::Authoring::EntityMover");
 
551
                mConnector = new LuaConnectors::ConnectorTwo<void, EmberEntity&, EmberOgre::Authoring::EntityMover&>(signal, luaTypes);
 
552
        }
 
553
}
524
554
 
525
555
LuaConnector::LuaConnector(sigc::signal<void, const std::string&>& signal)
526
556
{
604
634
        }
605
635
}
606
636
 
607
 
LuaConnector::LuaConnector(sigc::signal<void, EmberOgre::AvatarMovementMode::Mode>& signal)
 
637
LuaConnector::LuaConnector(sigc::signal<void, EmberOgre::MovementControllerMode::Mode>& signal)
608
638
{
609
639
        if (checkSignalExistence(&signal)) {
610
640
                LuaTypeStore luaTypes;
611
641
                luaTypes.push_back("EmberOgre::AvatarMovementMode::Mode");
612
 
                mConnector = new LuaConnectors::ConnectorOne<void, EmberOgre::AvatarMovementMode::Mode>(signal, luaTypes);
 
642
                mConnector = new LuaConnectors::ConnectorOne<void, EmberOgre::MovementControllerMode::Mode>(signal, luaTypes);
613
643
        }
614
644
}
615
645
 
622
652
        }
623
653
}
624
654
 
625
 
 
626
 
 
627
 
 
628
 
 
629
 
 
630
 
 
631
 
};
 
655
LuaConnector::LuaConnector(sigc::signal<void, const Atlas::Objects::Root&>& signal)
 
656
{
 
657
        if (checkSignalExistence(&signal)) {
 
658
                LuaTypeStore luaTypes;
 
659
                luaTypes.push_back("Atlas::Objects::Root");
 
660
                mConnector = new LuaConnectors::ConnectorOne<void, const Atlas::Objects::Root&>(signal, luaTypes);
 
661
        }
 
662
}
 
663
 
 
664
}
 
665
;