/*! * @file executor.h * Definition of a on-screen-shell */ #ifndef _EXECUTOR_LUA_H #define _EXECUTOR_LUA_H #include "executor.h" #include "compiler.h" #include "debug.h" #include "luaincl.h" template type fromLua(lua_State* state, int index); template<> bool fromLua(lua_State* state, int index); template<> int fromLua(lua_State* state, int index); template<> unsigned int fromLua(lua_State* state, int index); template<> float fromLua(lua_State* state, int index); template<> char fromLua(lua_State* state, int index); template<> const std::string& fromLua(lua_State* state, int index); template void toLua(lua_State* state, type value); template<> void toLua(lua_State* state, bool value); template<> void toLua(lua_State* state, int value); template<> void toLua(lua_State* state, unsigned int value); template<> void toLua(lua_State* state, float value); template<> void toLua(lua_State* state, char value); template<> void toLua(lua_State* state, const std::string& value); // FORWARD DECLARATION /////////////////////// ///// WITHOUT RET ///// /////////////////////// /////////// //// 0 //// /////////// //! Executes a Function with a lua_State* parameter. template class ExecutorLua0 : public Executor { public: /** * @brief Constructor of a ExecutorXML * @param function a Function to call */ ExecutorLua0(void(T::*function)()) : Executor(false) { this->functionPointer = function; } virtual void operator()(BaseObject* object, lua_State*& state) const { (dynamic_cast(object)->*(functionPointer))(); } /** * @returns a _new_ Copy of this Executor */ virtual Executor* clone () const { return new ExecutorLua0(ExecutorLua0(this->functionPointer)); } private: void (T::*functionPointer)(); }; /////////// //// 1 //// /////////// //! Executes a Function with a lua_State* parameter. template class ExecutorLua1 : public Executor { public: /** * @brief Constructor of a ExecutorXML * @param function a Function to call */ ExecutorLua1(void(T::*function)(type0)) : Executor(false, ExecutorParamType()) { this->functionPointer = function; } virtual void operator()(BaseObject* object, lua_State*& state) const { (dynamic_cast(object)->*(functionPointer))(fromLua(state, 1)); } /** * @returns a _new_ Copy of this Executor */ virtual Executor* clone () const { return new ExecutorLua1((this->functionPointer)); } private: void (T::*functionPointer)(type0); }; /////////// //// 2 //// /////////// //! Executes a Function with a lua_State* parameter. template class ExecutorLua2 : public Executor { public: /** * @brief Constructor of a ExecutorXML * @param function a Function to call */ ExecutorLua2(void(T::*function)(type0, type1)) : Executor(false, ExecutorParamType(), ExecutorParamType()) { this->functionPointer = function; } virtual void operator()(BaseObject* object, lua_State*& state) const { (dynamic_cast(object)->*(functionPointer))( fromLua(state, 1), fromLua(state, 2) ); } /** * @returns a _new_ Copy of this Executor */ virtual Executor* clone () const { return new ExecutorLua2(this->functionPointer); } private: void (T::*functionPointer)(type0, type1); }; /////////// //// 3 //// /////////// //! Executes a Function with a lua_State* parameter. template class ExecutorLua3 : public Executor { public: /** * @brief Constructor of a ExecutorXML * @param function a Function to call */ ExecutorLua3(void(T::*function)(type0, type1, type2)) : Executor(false, ExecutorParamType(), ExecutorParamType(), ExecutorParamType()) { this->functionPointer = function; } virtual void operator()(BaseObject* object, lua_State*& state) const { (dynamic_cast(object)->*(functionPointer))( fromLua(state, 1), fromLua(state, 2), fromLua(state, 3) ); } /** * @returns a _new_ Copy of this Executor */ virtual Executor* clone () const { return new ExecutorLua3(this->functionPointer); } private: void (T::*functionPointer)(type0, type1, type2); }; /////////// //// 4 //// /////////// //! Executes a Function with a lua_State* parameter. template class ExecutorLua4 : public Executor { public: /** * @brief Constructor of a ExecutorXML * @param function a Function to call */ ExecutorLua4(void(T::*function)(type0, type1, type2, type3)) : Executor(false, ExecutorParamType(), ExecutorParamType(), ExecutorParamType(), ExecutorParamType()) { this->functionPointer = function; } virtual void operator()(BaseObject* object, lua_State*& state) const { (dynamic_cast(object)->*(functionPointer))( fromLua(state, 1), fromLua(state, 2), fromLua(state, 3), fromLua(state, 4) ); } /** * @returns a _new_ Copy of this Executor */ virtual Executor* clone () const { return new ExecutorLua4(this->functionPointer); } private: void (T::*functionPointer)(type0, type1, type2, type3); }; //////////////////// ///// WITH RET ///// //////////////////// /////////// //// 0 //// /////////// //! Executes a Function with a lua_State* parameter. template class ExecutorLua0ret : public Executor { public: /** * @brief Constructor of a ExecutorXML * @param function a Function to call */ ExecutorLua0ret(ret (T::*function)()) : Executor(true) { this->functionPointer = function; } virtual void operator()(BaseObject* object, lua_State*& state) const { toLua(state, (dynamic_cast(object)->*(functionPointer))()); } /** * @returns a _new_ Copy of this Executor */ virtual Executor* clone () const { return new ExecutorLua0ret(this->functionPointer); } private: ret (T::*functionPointer)(); }; /////////// //// 1 //// /////////// //! Executes a Function with a lua_State* parameter. template class ExecutorLua1ret : public Executor { public: /** * @brief Constructor of a ExecutorXML * @param function a Function to call */ ExecutorLua1ret(ret (T::*function)(type0)) : Executor(true, ExecutorParamType()) { this->functionPointer = function; } virtual void operator()(BaseObject* object, lua_State*& state) const { toLua(state, (dynamic_cast(object)->*(functionPointer))( fromLua(state, 1))); } /** * @returns a _new_ Copy of this Executor */ virtual Executor* clone () const { return new ExecutorLua1ret(this->functionPointer); } private: ret (T::*functionPointer)(type0); }; /////////// //// 2 //// /////////// //! Executes a Function with a lua_State* parameter. template class ExecutorLua2ret : public Executor { public: /** * @brief Constructor of a ExecutorXML * @param function a Function to call */ ExecutorLua2ret(ret (T::*function)(type0, type1)) : Executor(true, ExecutorParamType(), ExecutorParamType()) { this->functionPointer = function; } virtual void operator()(BaseObject* object, lua_State*& state) const { toLua(state, (dynamic_cast(object)->*(functionPointer))( fromLua(state, 1), fromLua(state, 2) )); } /** * @returns a _new_ Copy of this Executor */ virtual Executor* clone () const { return new ExecutorLua2ret(this->functionPointer); } private: ret (T::*functionPointer)(type0, type1); }; /////////// //// 3 //// /////////// //! Executes a Function with a lua_State* parameter. template class ExecutorLua3ret : public Executor { public: /** * @brief Constructor of a ExecutorXML * @param function a Function to call */ ExecutorLua3ret(ret (T::*function)(type0, type1, type2)) : Executor(true, ExecutorParamType(), ExecutorParamType(), ExecutorParamType()) { this->functionPointer = function; } virtual void operator()(BaseObject* object, lua_State*& state) const { toLua(state, (dynamic_cast(object)->*(functionPointer))( fromLua(state, 1), fromLua(state, 2), fromLua(state, 3) )); } /** * @returns a _new_ Copy of this Executor */ virtual Executor* clone () const { return new ExecutorLua3ret(this->functionPointer); } private: ret (T::*functionPointer)(type0, type1, type2); }; /////////// //// 4 //// /////////// //! Executes a Function with a lua_State* parameter. template class ExecutorLua4ret : public Executor { public: /** * @brief Constructor of a ExecutorXML * @param function a Function to call */ ExecutorLua4ret(ret (T::*function)(type0, type1, type2, type3)) : Executor(true, ExecutorParamType(), ExecutorParamType(), ExecutorParamType(), ExecutorParamType()) { this->functionPointer = function; } virtual void operator()(BaseObject* object, lua_State*& state) const { toLua(state, (dynamic_cast(object)->*(functionPointer))( fromLua(state, 1), fromLua(state, 2), fromLua(state, 3), fromLua(state, 4) )); } /** * @returns a _new_ Copy of this Executor */ virtual Executor* clone () const { return new ExecutorLua4ret(this->functionPointer); } private: ret (T::*functionPointer)(type0, type1, type2, type3); }; /////////// //// 5 //// /////////// //! Executes a Function with a lua_State* parameter. template class ExecutorLua5ret : public Executor { public: /** * @brief Constructor of a ExecutorXML * @param function a Function to call */ ExecutorLua5ret(ret (T::*function)(type0, type1, type2, type3, type4)) : Executor(true, ExecutorParamType(), ExecutorParamType(), ExecutorParamType(), ExecutorParamType(), ExecutorParamType()) { this->functionPointer = function; } virtual void operator()(BaseObject* object, lua_State*& state) const { toLua(state, (dynamic_cast(object)->*(functionPointer))( fromLua(state, 1), fromLua(state, 2), fromLua(state, 3), fromLua(state, 4), fromLua(state, 5) )); } /** * @returns a _new_ Copy of this Executor */ virtual Executor* clone () const { return new ExecutorLua5ret(this->functionPointer); } private: ret (T::*functionPointer)(type0, type1, type2, type3, type4); }; /////////// //// 6 //// /////////// //! Executes a Function with a lua_State* parameter. template class ExecutorLua6ret : public Executor { public: /** * @brief Constructor of a ExecutorXML * @param function a Function to call */ ExecutorLua6ret(ret (T::*function)(type0, type1, type2, type3, type4, type5)) : Executor(true, ExecutorParamType(), ExecutorParamType(), ExecutorParamType(), ExecutorParamType(), ExecutorParamType(), ExecutorParamType()) { this->functionPointer = function; } virtual void operator()(BaseObject* object, lua_State*& state) const { toLua(state, (dynamic_cast(object)->*(functionPointer))( fromLua(state, 1), fromLua(state, 2), fromLua(state, 3), fromLua(state, 4), fromLua(state, 5), fromLua(state, 6) )); } /** * @returns a _new_ Copy of this Executor */ virtual Executor* clone () const { return new ExecutorLua6ret(this->functionPointer); } private: ret (T::*functionPointer)(type0, type1, type2, type3, type4, type5); }; /////////// //// 7 //// /////////// //! Executes a Function with a lua_State* parameter. template class ExecutorLua7ret : public Executor { public: /** * @brief Constructor of a ExecutorXML * @param function a Function to call */ ExecutorLua7ret(ret (T::*function)(type0, type1, type2, type3, type4, type5, type6)) : Executor(true, ExecutorParamType(), ExecutorParamType(), ExecutorParamType(), ExecutorParamType(), ExecutorParamType(), ExecutorParamType(), ExecutorParamType()) { this->functionPointer = function; } virtual void operator()(BaseObject* object, lua_State*& state) const { toLua(state, (dynamic_cast(object)->*(functionPointer))( fromLua(state, 1), fromLua(state, 2), fromLua(state, 3), fromLua(state, 4), fromLua(state, 5), fromLua(state, 6), fromLua(state, 7) )); } /** * @returns a _new_ Copy of this Executor */ virtual Executor* clone () const { return new ExecutorLua7ret(this->functionPointer); } private: ret (T::*functionPointer)(type0, type1, type2, type3, type4, type5, type6); }; #endif /* _EXECUTOR_LUA_H */