瀏覽代碼

Lua integration second pass. Still doesn't work, though.

undefined
Benjamin ‘Touky’ Huet Sam Hocevar <sam@hocevar.net> 9 年之前
父節點
當前提交
0ac33c2da2
共有 5 個文件被更改,包括 24 次插入24 次删除
  1. +0
    -4
      src/application/application.cpp
  2. +0
    -10
      src/application/baselua.cpp
  3. +14
    -2
      src/application/baselua.h
  4. +3
    -1
      src/world.cpp
  5. +7
    -7
      src/world.h

+ 0
- 4
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<float>("gravity");
gravity = gravity;
}

bool Application::MustTick()


+ 0
- 10
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()
{


+ 14
- 2
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<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
{
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<typename T>
T GetVar(String const &name)


+ 3
- 1
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<int32_t> var(GetLuaState(), 1);
//test1Lua::Library m_test1(GetLuaState());
//------ DEBUG TEST

}



+ 7
- 7
src/world.h 查看文件

@@ -38,6 +38,13 @@ public:
{
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:
static const luaL_Reg m_statics[];
@@ -47,13 +54,6 @@ private:
public:
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
{


Loading…
取消
儲存