diff --git a/src/application/application.cpp b/src/application/application.cpp index 6302926e..b14bf6bb 100644 --- a/src/application/application.cpp +++ b/src/application/application.cpp @@ -72,11 +72,7 @@ static void AppCallback() Application::Application(char const *name, ivec2 resolution, float framerate) { data = new ApplicationData(name, resolution, framerate); - g_world.ExecLua("lua/init.lua"); - float gravity = g_world.GetLuaNumber("gravity"); - gravity = g_world.GetVar("gravity"); - gravity = gravity; } bool Application::MustTick() diff --git a/src/application/baselua.cpp b/src/application/baselua.cpp index 02d97f8e..6ce13280 100644 --- a/src/application/baselua.cpp +++ b/src/application/baselua.cpp @@ -92,16 +92,6 @@ bool LuaLoader::ExecLua(String const &lua) return status == 0; } -//----------------------------------------------------------------------------- -double LuaLoader::GetLuaNumber(String const &var) -{ - double ret; - lua_getglobal(m_lua_state, var.C()); - ret = lua_tonumber(m_lua_state, -1); - lua_pop(m_lua_state, 1); - return ret; -} - //----------------------------------------------------------------------------- lua_State* LuaLoader::GetLuaState() { diff --git a/src/application/baselua.h b/src/application/baselua.h index f0ddfe07..759771b8 100644 --- a/src/application/baselua.h +++ b/src/application/baselua.h @@ -20,6 +20,8 @@ namespace lol { //----------------------------------------------------------------------------- +// Class available to link C++ class to Lua methods +//-- class LuaObject { protected: @@ -27,11 +29,22 @@ protected: struct LuaLibrary { LuaLibrary() { } - void LoadTo(lua_State* l) { luaW_register(l, name, statics, methods, ctor); } + void LoadTo(lua_State* l) + { +#define LOLUA_WRAPPER 1 +#if LOLUA_WRAPPER + luaW_register(l, name, statics, methods, ctor); +#else + luaL_newlib(L, statics); + luaL_newlib(L, methods); +#endif + } }; }; //----------------------------------------------------------------------------- +// +//-- struct LuaFunction { LuaFunction(lua_State* l, const char* name, int (*function)(lua_State*)) @@ -106,7 +119,6 @@ public: virtual ~LuaLoader(); bool ExecLua(String const &lua); - double GetLuaNumber(String const &var); template T GetVar(String const &name) diff --git a/src/world.cpp b/src/world.cpp index b1523174..a9181d4c 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -36,7 +36,7 @@ World g_world; * Public World class */ -const luaL_Reg test1Lua::m_statics[] = { { "getTest", getTest }, { NULL, NULL } }; +const luaL_Reg test1Lua::m_statics[] = { { "getTest", test1Lua::getTest }, { NULL, NULL } }; const luaL_Reg test1Lua::m_methods[] = { { NULL, NULL } }; const char test1Lua::m_class[] = "test1"; @@ -44,10 +44,12 @@ World::World() : LuaLoader() { g_world_data.m_lua_state = GetLuaState(); + //------ DEBUG TEST //m_test1.LoadTo(GetLuaState()); //luaL_loadfile(GetLuaState(), "lua/init.lua"); //LuaVar var(GetLuaState(), 1); //test1Lua::Library m_test1(GetLuaState()); + //------ DEBUG TEST } diff --git a/src/world.h b/src/world.h index df69a145..c2dca298 100644 --- a/src/world.h +++ b/src/world.h @@ -38,6 +38,13 @@ public: { return new test1(); } + static int getTest(lua_State* L) + { + LuaVar i1(L, 1); + LuaVar s2(L, 2); + LuaVar res = (int64_t)test1::getTest(i1.V(), s2.V()); + return res.Return(L); + } private: static const luaL_Reg m_statics[]; @@ -47,13 +54,6 @@ private: public: typedef LuaLibrary Library; }; -static int getTest(lua_State* L) -{ - LuaVar i1(L, 1); - LuaVar s2(L, 2); - LuaVar res = (int64_t)test1::getTest(i1.V(), s2.V()); - return res.Return(L); -} class World : public LuaLoader {