104
101
///get the lua function
105
102
lua_rawgeti(state, LUA_REGISTRYINDEX, mLuaFunctionIndex);
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++));
117
114
///push our error handling method before calling the code
118
115
int error_index = lua_gettop(state) - numberOfArguments;
120
lua_pushcfunction(state, ::EmberOgre::Scripting::LuaHelper::luaErrorHandler);
117
lua_pushcfunction(state, LuaHelper::luaErrorHandler);
122
119
lua_pushliteral(state, "_TRACEBACK");
123
lua_rawget(state, LUA_GLOBALSINDEX); /* get traceback function */
120
lua_rawget(state, LUA_GLOBALSINDEX); /* get traceback function */
125
122
lua_insert(state, error_index);/* put it under chunk and args */
127
124
luaPop pop(state, 1); // pops error handler on exit
130
int error = lua_pcall(state,numberOfArguments,LUA_MULTRET,error_index);
127
int error = lua_pcall(state, numberOfArguments, LUA_MULTRET, error_index);
132
129
/// handle errors
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);
141
// Treturn& returnValue(0);
137
// Treturn& returnValue(0);
142
138
//return (Treturn)returnValueFromLua(state);
143
139
//return returnValue;
146
catch( const CEGUI::String& str )
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());
151
catch( const CEGUI::Exception& ex )
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());
156
catch(const std::exception& ex )
158
lua_settop(state, top );
159
S_LOG_FAILURE("(LuaScriptModule) Unable to execute scripted event handler: " << mLuaMethod << "\n" << ex.what());
162
lua_settop(state, top );
163
S_LOG_FAILURE("Unspecified error when executing: " << mLuaMethod );
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);
151
lua_settop(state, top);
152
S_LOG_FAILURE("Unspecified error when executing: " << mLuaMethod );
155
return (Treturn)*test;*/
169
template<typename Treturn>
158
template<typename Treturn>
170
159
Treturn ConnectorBase::returnValueFromLua(lua_State* state)
172
return static_cast<Treturn>(lua_touserdata(state,-1));
161
return static_cast<Treturn> (lua_touserdata(state, -1));
175
164
// void ConnectorBase::returnValueFromLua(lua_State* state, bool& returnValueHolder)
177
166
// returnValueHolder = lua_toboolean(state,-1);
180
169
// void returnValueFromLua(lua_State* state)
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)
187
177
mConnection = mSignal.connect(sigc::mem_fun(*this, &ConnectorZero<Treturn>::signal_recieve));
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)
193
184
mConnection = mSignal.connect(sigc::mem_fun(*this, &ConnectorOne<Treturn, T0>::signal_recieve));
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)
200
191
// mConnection = mSignal_old.connect(sigc::mem_fun(*this, &ConnectorOne<Treturn, T0>::signal_recieve));
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)
206
198
mConnection = mSignal.connect(sigc::mem_fun(*this, &ConnectorTwo<Treturn, T0, T1>::signal_recieve));
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)
212
205
mConnection = mSignal.connect(sigc::mem_fun(*this, &ConnectorThree<Treturn, T0, T1, T2>::signal_recieve));
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)
218
212
mConnection = mSignal.connect(sigc::mem_fun(*this, &ConnectorFour<Treturn, T0, T1, T2, T3>::signal_recieve));
222
template <typename Treturn>
215
template<typename Treturn>
223
216
Treturn ConnectorZero<Treturn>::signal_recieve()
225
return callLuaMethod<Treturn, Empty, Empty, Empty, Empty>(Empty(), Empty(), Empty(), Empty());
218
return callLuaMethod<Treturn, Empty, Empty, Empty, Empty> (Empty(), Empty(), Empty(), Empty());
228
template <typename Treturn, typename T0>
221
template<typename Treturn, typename T0>
229
222
Treturn ConnectorOne<Treturn, T0>::signal_recieve(T0 t0)
231
return callLuaMethod<Treturn, T0, Empty, Empty, Empty>(t0, Empty(), Empty(), Empty());
224
return callLuaMethod<Treturn, T0, Empty, Empty, Empty> (t0, Empty(), Empty(), Empty());
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)
237
return callLuaMethod<Treturn, T0, T1, Empty, Empty>(t0, t1, Empty(), Empty());
230
return callLuaMethod<Treturn, T0, T1, Empty, Empty> (t0, t1, Empty(), Empty());
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)
243
return callLuaMethod<Treturn, T0, T1, T2, Empty>(t0, t1, t2, Empty());
236
return callLuaMethod<Treturn, T0, T1, T2, Empty> (t0, t1, t2, Empty());
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)
249
return callLuaMethod<Treturn, T0, T1, T2, T3>(t0, t1, t2, t3);
255
template <typename T>
242
return callLuaMethod<Treturn, T0, T1, T2, T3> (t0, t1, t2, t3);
256
249
void LuaConnector::pushValue(T theValue, const std::string& luaTypename)
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());
262
255
void LuaConnector::pushValue(const Eris::ServerInfo& theValue, const std::string& luaTypename)
264
tolua_pushusertype(EmberOgre::LuaConnector::getState(),(void*)&theValue, luaTypename.c_str());
257
pushUserTypeValue(theValue, luaTypename);
267
void LuaConnector::pushValue(const std::string& theValue, const std::string& luaTypename)
260
void LuaConnector::pushValue(const std::string& theValue, const std::string& luaTypename)
269
tolua_pushstring(EmberOgre::LuaConnector::getState(),theValue.c_str());
262
tolua_pushstring(EmberOgre::LuaConnector::getState(), theValue.c_str());
272
void LuaConnector::pushValue(LuaConnectors::Empty theValue, const std::string& luaTypename)
265
void LuaConnector::pushValue(LuaConnectors::Empty theValue, const std::string& luaTypename)
276
269
void LuaConnector::pushValue(const float& theValue, const std::string& luaTypename)
278
tolua_pushnumber(EmberOgre::LuaConnector::getState(),theValue);
271
tolua_pushnumber(EmberOgre::LuaConnector::getState(), theValue);
281
274
void LuaConnector::pushValue(const long& theValue, const std::string& luaTypename)
283
tolua_pushnumber(EmberOgre::LuaConnector::getState(),theValue);
276
tolua_pushnumber(EmberOgre::LuaConnector::getState(), theValue);
286
279
void LuaConnector::pushValue(const unsigned long& theValue, const std::string& luaTypename)
288
tolua_pushnumber(EmberOgre::LuaConnector::getState(),theValue);
281
tolua_pushnumber(EmberOgre::LuaConnector::getState(), theValue);
291
284
void LuaConnector::pushValue(const unsigned int& theValue, const std::string& luaTypename)
293
tolua_pushnumber(EmberOgre::LuaConnector::getState(),theValue);
286
tolua_pushnumber(EmberOgre::LuaConnector::getState(), theValue);
297
289
void LuaConnector::pushValue(const int& theValue, const std::string& luaTypename)
299
tolua_pushnumber(EmberOgre::LuaConnector::getState(),theValue);
291
tolua_pushnumber(EmberOgre::LuaConnector::getState(), theValue);
302
294
void LuaConnector::pushValue(const EntityPickResult& theValue, const std::string& luaTypename)
304
tolua_pushusertype(EmberOgre::LuaConnector::getState(),(void*)&theValue, luaTypename.c_str());
296
pushUserTypeValue(theValue, luaTypename);
307
299
void LuaConnector::pushValue(const MousePickerArgs& theValue, const std::string& luaTypename)
309
tolua_pushusertype(EmberOgre::LuaConnector::getState(),(void*)&theValue, luaTypename.c_str());
301
pushUserTypeValue(theValue, luaTypename);
312
304
void LuaConnector::pushValue(const Input::MouseButton& theValue, const std::string& luaTypename)