diff options
Diffstat (limited to 'include/module/ModuleLoader.hpp')
-rwxr-xr-x | include/module/ModuleLoader.hpp | 73 |
1 files changed, 72 insertions, 1 deletions
diff --git a/include/module/ModuleLoader.hpp b/include/module/ModuleLoader.hpp index cf12a67..91fc4e8 100755 --- a/include/module/ModuleLoader.hpp +++ b/include/module/ModuleLoader.hpp @@ -22,6 +22,11 @@ #include "TypeList.hpp" #include "TypeInfo.hpp" +#ifdef WITH_LUA +#include "lua.hpp" +#include "LuaVM.hpp" +#endif + #ifndef _WIN32 typedef void * ModuleHandle; #else @@ -81,6 +86,11 @@ class BaseModuleLoader { mapType m_modules; int m_flags; + +#ifdef WITH_LUA + public: + lua_CFunction luaCreateFunc; +#endif public: @@ -190,7 +200,12 @@ class ModuleLoader< Interface, NullType > : public BaseModuleLoader< Interface, public: ModuleLoader< Interface >( const std::vector<std::string> files, int flags = DEFAULT_FLAGS, void *user_data = 0 ) - : BaseModuleLoader< Interface >( files, flags, user_data ) { } + : BaseModuleLoader< Interface >( files, flags, user_data ) + { +#ifdef WITH_LUA + BaseModuleLoader< Interface >::luaCreateFunc = &ModuleLoader< Interface, NullType >::lua_create; +#endif + } Interface *create( std::string subclass ) { @@ -209,6 +224,30 @@ class ModuleLoader< Interface, NullType > : public BaseModuleLoader< Interface, return obj; } + +#ifdef WITH_LUA + private: + static int lua_create( lua_State *l ) + { + ModuleLoader< Interface, NullType > *loader = + (ModuleLoader< Interface, NullType > *) + lua_touserdata( l, lua_upvalueindex( 1 ) ); + + size_t nofParams = lua_gettop( l ) - 1; + if( nofParams != 1 ) { + lua_pushnil( l ); + lua_pushstring( l, "expecting 1 class parameter, no ctor parameters" ); + return 2; + } + + LuaVM::dumpStack( l ); + std::string clazz = lua_tostring( l, -1 ); + + loader->create( clazz ); + + return 0; + } +#endif }; // one param @@ -238,6 +277,14 @@ class ModuleLoader< Interface, TYPELIST_1( T1 ) > : public BaseModuleLoader< Int return obj; } + +#ifdef WITH_LUA + private: + static int lua_create( lua_State * ) + { + return 0; + } +#endif }; // two params @@ -267,6 +314,14 @@ class ModuleLoader< Interface, TYPELIST_2( T1, T2 ) > : public BaseModuleLoader< return obj; } + +#ifdef WITH_LUA + private: + static int lua_create( lua_State * ) + { + return 0; + } +#endif }; // three params @@ -296,6 +351,14 @@ class ModuleLoader< Interface, TYPELIST_3( T1, T2, T3 ) > : public BaseModuleLoa return obj; } + +#ifdef WITH_LUA + private: + static int lua_create( lua_State * ) + { + return 0; + } +#endif }; // four params @@ -325,6 +388,14 @@ class ModuleLoader< Interface, TYPELIST_4( T1, T2, T3, T4 ) > : public BaseModul return obj; } + +#ifdef WITH_LUA + private: + static int lua_create( lua_State * ) + { + return 0; + } +#endif }; #endif |