/* SLB - Simple Lua Binder Copyright (C) 2007 Jose L. Hidalgo ValiƱo (PpluX) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Jose L. Hidalgo (www.pplux.com) pplux@pplux.com */ #ifndef __SLB_FUNCCALL__ #define __SLB_FUNCCALL__ #include "Object.hpp" #include "Export.hpp" #include "SPP.hpp" #include "lua.hpp" #include #include namespace SLB { class SLB_EXPORT FuncCall : public Object { public: #define SLB_REPEAT(N) \ \ /* FunCall for class Methods */ \ template \ static FuncCall* create(R (C::*func)(SPP_ENUM_D(N,T)) ); \ \ /* FunCall for CONST class Methods */ \ template \ static FuncCall* create(R (C::*func)(SPP_ENUM_D(N,T)) const ); \ \ /* (explicit) FunCall for CONST class Methods */ \ template \ static FuncCall* createConst(R (C::*func)(SPP_ENUM_D(N,T)) const ); \ \ /* (explicit) FunCall for NON-CONST class Methods */ \ template \ static FuncCall* createNonConst(R (C::*func)(SPP_ENUM_D(N,T))); \ \ /* FunCall for C-functions */ \ template \ static FuncCall* create(R (func)(SPP_ENUM_D(N,T)) ); \ \ /* FunCall Class constructors */ \ template \ static FuncCall* classConstructor(); \ SPP_MAIN_REPEAT_Z(MAX,SLB_REPEAT) #undef SLB_REPEAT /* special case of a proper lua Function */ static FuncCall* create(lua_CFunction f); size_t getNumArguments() const { return _Targs.size(); } const std::type_info* getArgType(size_t p) const { return _Targs[p].first; } const std::string& getArgComment(size_t p) const { return _Targs[p].second; } const std::type_info* getReturnedType() const { return _Treturn; } void setArgComment(size_t p, const std::string& c); protected: FuncCall(); virtual ~FuncCall(); void pushImplementation(lua_State *L); virtual int call(lua_State *L) = 0; std::vector< std::pair > _Targs; const std::type_info* _Treturn; private: static int _call(lua_State *L); friend class Manager; friend class ClassInfo; }; } //end of SLB namespace //-------------------------------------------------------------------- // Inline implementations: //-------------------------------------------------------------------- #include "Private_FuncCall.hpp" #define SLB_REPEAT(N) \ \ template \ inline FuncCall* FuncCall::create(R (C::*func)(SPP_ENUM_D(N,T)) ) \ { \ return createNonConst(func); \ } \ \ template \ inline FuncCall* FuncCall::create(R (C::*func)(SPP_ENUM_D(N,T)) const ) \ { \ return createConst(func); \ } \ \ template \ inline FuncCall* FuncCall::createConst(R (C::*func)(SPP_ENUM_D(N,T)) const ) \ { \ return new Private::FC_ConstMethod(func); \ } \ template \ inline FuncCall* FuncCall::createNonConst(R (C::*func)(SPP_ENUM_D(N,T)) ) \ { \ return new Private::FC_Method(func); \ } \ \ template \ inline FuncCall* FuncCall::create(R (*func)(SPP_ENUM_D(N,T)) ) \ { \ return new Private::FC_Function(func);\ } \ \ template \ inline FuncCall* FuncCall::classConstructor() \ { \ return new Private::FC_ClassConstructor;\ } \ SPP_MAIN_REPEAT_Z(MAX,SLB_REPEAT) #undef SLB_REPEAT } #endif