Changeset 3849


Ignore:
Timestamp:
Mar 2, 2015, 7:00:39 AM (7 years ago)
Author:
touky
Message:

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

Location:
trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/application/application.cpp

    r3846 r3849  
    7373{
    7474    data = new ApplicationData(name, resolution, framerate);
    75 
    7675    g_world.ExecLua("lua/init.lua");
    77     float gravity = g_world.GetLuaNumber("gravity");
    78     gravity = g_world.GetVar<float>("gravity");
    79     gravity = gravity;
    8076}
    8177
  • trunk/src/application/baselua.cpp

    r3845 r3849  
    9494
    9595//-----------------------------------------------------------------------------
    96 double LuaLoader::GetLuaNumber(String const &var)
    97 {
    98     double ret;
    99     lua_getglobal(m_lua_state, var.C());
    100     ret = lua_tonumber(m_lua_state, -1);
    101     lua_pop(m_lua_state, 1);
    102     return ret;
    103 }
    104 
    105 //-----------------------------------------------------------------------------
    10696lua_State* LuaLoader::GetLuaState()
    10797{
  • trunk/src/application/baselua.h

    r3846 r3849  
    2121
    2222//-----------------------------------------------------------------------------
     23// Class available to link C++ class to Lua methods
     24//--
    2325class LuaObject
    2426{
     
    2830    {
    2931        LuaLibrary() { }
    30         void LoadTo(lua_State* l) { luaW_register<T>(l, name, statics, methods, ctor); }
     32        void LoadTo(lua_State* l)
     33        {
     34#define LOLUA_WRAPPER 1
     35#if LOLUA_WRAPPER
     36            luaW_register<T>(l, name, statics, methods, ctor);
     37#else
     38            luaL_newlib(L, statics);
     39            luaL_newlib(L, methods);
     40#endif
     41        }
    3142    };
    3243};
    3344
    3445//-----------------------------------------------------------------------------
     46//
     47//--
    3548struct LuaFunction
    3649{
     
    107120
    108121    bool ExecLua(String const &lua);
    109     double GetLuaNumber(String const &var);
    110122
    111123    template<typename T>
  • trunk/src/world.cpp

    r3845 r3849  
    3737 */
    3838
    39 const luaL_Reg test1Lua::m_statics[] = { { "getTest", getTest }, { NULL, NULL } };
     39const luaL_Reg test1Lua::m_statics[] = { { "getTest", test1Lua::getTest }, { NULL, NULL } };
    4040const luaL_Reg test1Lua::m_methods[] = { { NULL, NULL } };
    4141const char     test1Lua::m_class[]   = "test1";
     
    4545{
    4646    g_world_data.m_lua_state = GetLuaState();
     47    //------ DEBUG TEST
    4748    //m_test1.LoadTo(GetLuaState());
    4849    //luaL_loadfile(GetLuaState(), "lua/init.lua");
    4950    //LuaVar<int32_t> var(GetLuaState(), 1);
    5051    //test1Lua::Library m_test1(GetLuaState());
     52    //------ DEBUG TEST
    5153
    5254}
  • trunk/src/world.h

    r3845 r3849  
    3939        return new test1();
    4040    }
     41    static int getTest(lua_State* L)
     42    {
     43        LuaVar<int> i1(L, 1);
     44        LuaVar<String> s2(L, 2);
     45        LuaVar<int64_t> res = (int64_t)test1::getTest(i1.V(), s2.V());
     46        return res.Return(L);
     47    }
    4148
    4249private:
     
    4855    typedef LuaLibrary<test1, m_class, m_statics, m_methods, test1Lua::New> Library;
    4956};
    50 static int getTest(lua_State* L)
    51 {
    52     LuaVar<int> i1(L, 1);
    53     LuaVar<String> s2(L, 2);
    54     LuaVar<int64_t> res = (int64_t)test1::getTest(i1.V(), s2.V());
    55     return res.Return(L);
    56 }
    5757
    5858class World : public LuaLoader
Note: See TracChangeset for help on using the changeset viewer.