@@ -72,11 +72,7 @@ static void AppCallback() | |||||
Application::Application(char const *name, ivec2 resolution, float framerate) | Application::Application(char const *name, ivec2 resolution, float framerate) | ||||
{ | { | ||||
data = new ApplicationData(name, resolution, framerate); | data = new ApplicationData(name, resolution, framerate); | ||||
g_world.ExecLua("lua/init.lua"); | g_world.ExecLua("lua/init.lua"); | ||||
float gravity = g_world.GetLuaNumber("gravity"); | |||||
gravity = g_world.GetVar<float>("gravity"); | |||||
gravity = gravity; | |||||
} | } | ||||
bool Application::MustTick() | bool Application::MustTick() | ||||
@@ -92,16 +92,6 @@ bool LuaLoader::ExecLua(String const &lua) | |||||
return status == 0; | 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() | lua_State* LuaLoader::GetLuaState() | ||||
{ | { | ||||
@@ -20,6 +20,8 @@ namespace lol | |||||
{ | { | ||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
// Class available to link C++ class to Lua methods | |||||
//-- | |||||
class LuaObject | class LuaObject | ||||
{ | { | ||||
protected: | protected: | ||||
@@ -27,11 +29,22 @@ protected: | |||||
struct LuaLibrary | struct LuaLibrary | ||||
{ | { | ||||
LuaLibrary() { } | LuaLibrary() { } | ||||
void LoadTo(lua_State* l) { luaW_register<T>(l, name, statics, methods, ctor); } | |||||
void LoadTo(lua_State* l) | |||||
{ | |||||
#define LOLUA_WRAPPER 1 | |||||
#if LOLUA_WRAPPER | |||||
luaW_register<T>(l, name, statics, methods, ctor); | |||||
#else | |||||
luaL_newlib(L, statics); | |||||
luaL_newlib(L, methods); | |||||
#endif | |||||
} | |||||
}; | }; | ||||
}; | }; | ||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
// | |||||
//-- | |||||
struct LuaFunction | struct LuaFunction | ||||
{ | { | ||||
LuaFunction(lua_State* l, const char* name, int (*function)(lua_State*)) | LuaFunction(lua_State* l, const char* name, int (*function)(lua_State*)) | ||||
@@ -106,7 +119,6 @@ public: | |||||
virtual ~LuaLoader(); | virtual ~LuaLoader(); | ||||
bool ExecLua(String const &lua); | bool ExecLua(String const &lua); | ||||
double GetLuaNumber(String const &var); | |||||
template<typename T> | template<typename T> | ||||
T GetVar(String const &name) | T GetVar(String const &name) | ||||
@@ -36,7 +36,7 @@ World g_world; | |||||
* Public World class | * 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 luaL_Reg test1Lua::m_methods[] = { { NULL, NULL } }; | ||||
const char test1Lua::m_class[] = "test1"; | const char test1Lua::m_class[] = "test1"; | ||||
@@ -44,10 +44,12 @@ World::World() | |||||
: LuaLoader() | : LuaLoader() | ||||
{ | { | ||||
g_world_data.m_lua_state = GetLuaState(); | g_world_data.m_lua_state = GetLuaState(); | ||||
//------ DEBUG TEST | |||||
//m_test1.LoadTo(GetLuaState()); | //m_test1.LoadTo(GetLuaState()); | ||||
//luaL_loadfile(GetLuaState(), "lua/init.lua"); | //luaL_loadfile(GetLuaState(), "lua/init.lua"); | ||||
//LuaVar<int32_t> var(GetLuaState(), 1); | //LuaVar<int32_t> var(GetLuaState(), 1); | ||||
//test1Lua::Library m_test1(GetLuaState()); | //test1Lua::Library m_test1(GetLuaState()); | ||||
//------ DEBUG TEST | |||||
} | } | ||||
@@ -38,6 +38,13 @@ public: | |||||
{ | { | ||||
return new test1(); | return new test1(); | ||||
} | } | ||||
static int getTest(lua_State* L) | |||||
{ | |||||
LuaVar<int> i1(L, 1); | |||||
LuaVar<String> s2(L, 2); | |||||
LuaVar<int64_t> res = (int64_t)test1::getTest(i1.V(), s2.V()); | |||||
return res.Return(L); | |||||
} | |||||
private: | private: | ||||
static const luaL_Reg m_statics[]; | static const luaL_Reg m_statics[]; | ||||
@@ -47,13 +54,6 @@ private: | |||||
public: | public: | ||||
typedef LuaLibrary<test1, m_class, m_statics, m_methods, test1Lua::New> Library; | typedef LuaLibrary<test1, m_class, m_statics, m_methods, test1Lua::New> Library; | ||||
}; | }; | ||||
static int getTest(lua_State* L) | |||||
{ | |||||
LuaVar<int> i1(L, 1); | |||||
LuaVar<String> s2(L, 2); | |||||
LuaVar<int64_t> res = (int64_t)test1::getTest(i1.V(), s2.V()); | |||||
return res.Return(L); | |||||
} | |||||
class World : public LuaLoader | class World : public LuaLoader | ||||
{ | { | ||||