Changeset 3845


Ignore:
Timestamp:
Mar 1, 2015, 6:26:00 AM (7 years ago)
Author:
touky
Message:

Added first pass for Base Lua setup

Location:
trunk/src
Files:
3 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/Makefile.am

    r3844 r3845  
    1111    entity.cpp entity.h ticker.cpp ticker.h lolgl.h \
    1212    tileset.cpp tileset.h forge.cpp forge.h video.cpp video.h \
     13    baselua.cpp baselua.h \
    1314    world.cpp world.h sample.cpp sample.h sampler.cpp sampler.h \
    1415    profiler.cpp profiler.h text.cpp text.h emitter.cpp emitter.h \
  • trunk/src/application/application.cpp

    r3776 r3845  
    7575
    7676    g_world.ExecLua("lua/init.lua");
     77    int32_t gravity = g_world.GetVar<int32_t>("gravity");
    7778}
    7879
  • trunk/src/easymesh/easymeshinternal.cpp

    r3844 r3845  
    6161    if (duplicate)
    6262    {
     63        int vbase = (int)m_vert.Count();
     64        AddDupVertex(base + i1);
     65        AddDupVertex(base + i2);
     66        AddDupVertex(base + i3);
     67        AddDupVertex(base + i4);
     68
     69        AddQuad(0, 1, 2, 3, vbase);
     70    }
     71    else
     72    {
    6373        if (BD()->IsEnabled(MeshBuildOperation::QuadWeighting) &&
    6474            !BD()->IsEnabled(MeshBuildOperation::IgnoreQuadWeighting))
     
    94104        }
    95105    }
     106}
     107
     108//-----------------------------------------------------------------------------
     109void EasyMesh::AddTriangle(int i1, int i2, int i3, int base, bool duplicate)
     110{
     111    if (duplicate)
     112    {
     113        m_indices << (uint16_t)m_vert.Count(); AddDupVertex(base + i1);
     114        m_indices << (uint16_t)m_vert.Count(); AddDupVertex(base + i2);
     115        m_indices << (uint16_t)m_vert.Count(); AddDupVertex(base + i3);
     116    }
    96117    else
    97     {
    98         int vbase = (int)m_vert.Count();
    99         AddDupVertex(base + i1);
    100         AddDupVertex(base + i2);
    101         AddDupVertex(base + i3);
    102         AddDupVertex(base + i4);
    103 
    104         AddQuad(0, 1, 2, 3, vbase);
    105     }
    106 }
    107 
    108 //-----------------------------------------------------------------------------
    109 void EasyMesh::AddTriangle(int i1, int i2, int i3, int base, bool duplicate)
    110 {
    111     if (duplicate)
    112118    {
    113119        m_indices << base + i1;
    114120        m_indices << base + i2;
    115121        m_indices << base + i3;
    116     }
    117     else
    118     {
    119         m_indices << (uint16_t)m_vert.Count(); AddDupVertex(base + i1);
    120         m_indices << (uint16_t)m_vert.Count(); AddDupVertex(base + i2);
    121         m_indices << (uint16_t)m_vert.Count(); AddDupVertex(base + i3);
    122122    }
    123123}
  • trunk/src/lol/extras.h

    r3580 r3845  
    4444#include <lol/../text.h>
    4545#include <lol/../tileset.h>
     46#include <lol/../application/baselua.h>
    4647#include <lol/../world.h>
    4748
  • trunk/src/lolcore.vcxproj

    r3844 r3845  
    8989  <ItemGroup>
    9090    <ClCompile Include="application\application.cpp" />
     91    <ClCompile Include="application\baselua.cpp" />
    9192    <ClCompile Include="audio.cpp" />
    9293    <ClCompile Include="camera.cpp" />
     
    232233  <ItemGroup>
    233234    <ClInclude Include="application\application.h" />
     235    <ClInclude Include="application\baselua.h" />
    234236    <ClInclude Include="audio.h" />
    235237    <ClInclude Include="camera.h" />
  • trunk/src/lolcore.vcxproj.filters

    r3844 r3845  
    404404      <Filter>easymesh</Filter>
    405405    </ClCompile>
     406    <ClCompile Include="application\baselua.cpp">
     407      <Filter>application</Filter>
     408    </ClCompile>
    406409  </ItemGroup>
    407410  <ItemGroup>
     
    754757    <ClInclude Include="lol\algorithm\portal.h">
    755758      <Filter>lol\algorithm</Filter>
     759    </ClInclude>
     760    <ClInclude Include="application\baselua.h">
     761      <Filter>application</Filter>
    756762    </ClInclude>
    757763  </ItemGroup>
  • trunk/src/lua/lollua.vcxproj

    r3776 r3845  
    119119    <ClInclude Include="lua.hpp" />
    120120    <ClInclude Include="lualib.h" />
     121    <ClInclude Include="luawrapper.hpp" />
    121122    <ClInclude Include="lundump.h" />
    122123    <ClInclude Include="lvm.h" />
  • trunk/src/world.cpp

    r3577 r3845  
    1515#include <ctype.h>
    1616
    17 #include "lua/lua.hpp"
     17//#include "lua/lua.hpp"
    1818
    1919namespace lol
     
    2727{
    2828    friend class World;
    29 
    30     static int LuaPanic(lua_State* L)
    31     {
    32         char const *message = lua_tostring(L, -1);
    33         Log::Error("%s\n", message);
    34         DebugAbort();
    35         return 0;
    36     }
    37 
    38     static int LuaDoFile(lua_State *L)
    39     {
    40         if (lua_isnoneornil(L, 1))
    41             return LUA_ERRFILE;
    42 
    43         char const *filename = lua_tostring(L, 1);
    44         int status = LUA_ERRFILE;
    45 
    46         array<String> pathlist = System::GetPathList(filename);
    47         File f;
    48         for (int i = 0; i < pathlist.Count(); ++i)
    49         {
    50             f.Open(pathlist[i], FileAccess::Read);
    51             if (f.IsValid())
    52             {
    53                 String s = f.ReadString();
    54                 f.Close();
    55 
    56                 Log::Debug("loading Lua file %s\n", pathlist[i].C());
    57                 status = luaL_dostring(L, s.C());
    58                 break;
    59             }
    60         }
    61 
    62         if (status == LUA_ERRFILE)
    63            Log::Error("could not find Lua file %s\n", filename);
    64 
    65         lua_pop(L, 1);
    66 
    67         return status;
    68     }
    69 
    7029    lua_State *m_lua_state;
    7130};
     
    7837 */
    7938
     39const luaL_Reg test1Lua::m_statics[] = { { "getTest", getTest }, { NULL, NULL } };
     40const luaL_Reg test1Lua::m_methods[] = { { NULL, NULL } };
     41const char     test1Lua::m_class[]   = "test1";
     42
    8043World::World()
     44    : LuaLoader()
    8145{
    82     /* Initialise the Lua engine */
    83     g_world_data.m_lua_state = luaL_newstate();
    84     lua_atpanic(g_world_data.m_lua_state, WorldData::LuaPanic);
    85     luaL_openlibs(g_world_data.m_lua_state);
     46    g_world_data.m_lua_state = GetLuaState();
     47    //m_test1.LoadTo(GetLuaState());
     48    //luaL_loadfile(GetLuaState(), "lua/init.lua");
     49    //LuaVar<int32_t> var(GetLuaState(), 1);
     50    //test1Lua::Library m_test1(GetLuaState());
    8651
    87     /* Override dofile() */
    88     lua_pushcfunction(g_world_data.m_lua_state, WorldData::LuaDoFile);
    89     lua_setglobal(g_world_data.m_lua_state, "dofile");
    9052}
    9153
    9254World::~World()
    9355{
    94     lua_close(g_world_data.m_lua_state);
    95 }
    96 
    97 bool World::ExecLua(String const &lua)
    98 {
    99     lua_pushstring(g_world_data.m_lua_state, lua.C());
    100     int status = WorldData::LuaDoFile(g_world_data.m_lua_state);
    101     return status == 0;
    102 }
    103 
    104 double World::GetLuaNumber(String const &var)
    105 {
    106     double ret;
    107     lua_getglobal(g_world_data.m_lua_state, var.C());
    108     ret = lua_tonumber(g_world_data.m_lua_state, -1);
    109     lua_pop(g_world_data.m_lua_state, 1);
    110     return ret;
    11156}
    11257
  • trunk/src/world.h

    r3580 r3845  
    1919{
    2020
    21 class World
     21class test1
    2222{
    2323public:
    24     bool ExecLua(String const &lua);
    25     double GetLuaNumber(String const &var);
     24    test1() {}
     25    static int getTest(int i1, String s2)
     26    {
     27        return -1;
     28    }
     29};
    2630
    27 //private:
     31class test1Lua : public LuaObject
     32{
     33public:
     34    test1Lua()
     35    {
     36    }
     37    static test1* New(lua_State* L)
     38    {
     39        return new test1();
     40    }
     41
     42private:
     43    static const luaL_Reg m_statics[];
     44    static const luaL_Reg m_methods[];
     45    static const char m_class[];
     46
     47public:
     48    typedef LuaLibrary<test1, m_class, m_statics, m_methods, test1Lua::New> Library;
     49};
     50static 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}
     57
     58class World : public LuaLoader
     59{
     60public:
    2861    World();
    29     ~World();
     62    virtual ~World();
     63
     64protected:
     65    test1Lua::Library m_test1;
    3066};
    3167
Note: See TracChangeset for help on using the changeset viewer.