Changeset 74 for trunk/src


Ignore:
Timestamp:
06/01/13 17:07:09 (12 years ago)
Author:
epyon
Message:
  • lua::state - removed notion of global state
  • lua_glm - fixed stack pollution at registration
  • lualib_test - made use of lua::state
Location:
trunk/src/lua
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lua/lua_glm.cc

    r53 r74  
    335335        nlua_swizzel_lookup['v'] = 0;
    336336        nlua_swizzel_lookup['3'] = 3;
     337        int stack = lua_gettop( L );
    337338        luaL_requiref(L, "ivec2", luaopen_vec<glm::ivec2>, 1);
    338339        luaL_requiref(L, "ivec3", luaopen_vec<glm::ivec3>, 1);
     
    341342        luaL_requiref(L, "vec3", luaopen_vec<glm::vec3>, 1);
    342343        luaL_requiref(L, "vec4", luaopen_vec<glm::vec4>, 1);
    343 }
    344 
     344        lua_settop( L, stack );
     345}
     346
  • trunk/src/lua/lua_state.cc

    r51 r74  
    2424}
    2525
    26 lua::state::state( bool is_main /*= false*/ )
    27 {
     26lua::state::state( bool load_libs /*= false*/ )
     27{
     28        load_lua_library();
    2829        m_owner = true;
    2930        L = luaL_newstate( );
     
    3334        lua_call(L, 1, 0);
    3435
    35         if (is_main)
    36         {
    37                 NV_ASSERT( this == get(), "lua_state : another main state created!" );
     36        if ( load_libs )
     37        {
    3838                stack_guard guard( this );
    39                 luaopen_base( L );
    40                 luaopen_string( L );
    41                 luaopen_table( L );
    42                 luaopen_math( L );
    43         }
    44 
    45         NV_LOG( nv::LOG_TRACE, is_main ? "Main Lua state created" : "Secondary Lua state created");
     39                static const luaL_Reg lualibs[] =
     40                {
     41                        { "string", luaopen_string },
     42                        { "table",  luaopen_table },
     43                        { "math",   luaopen_math },
     44                        { NULL, NULL}
     45                };
     46                const luaL_Reg *lib = lualibs;
     47                for(; lib->func != NULL; lib++)
     48                {
     49                        lib->func( L );
     50                }
     51        }
     52
     53        NV_LOG( nv::LOG_TRACE, "Lua state created" );
    4654}
    4755
     
    121129}
    122130
    123 lua::state* lua::state::get()
    124 {
    125         static lua::state main_state(true);
    126         return &main_state;
    127 }
    128 
    129131bool lua::state::push( const std::string& path, bool global )
    130132{
     
    275277        for ( int i = 0; i < top; ++i )
    276278        {
    277                 NV_LOG( LOG_DEBUG, "#" << i+1 << " - " << lua_typename(L, i+1) << " = " << nlua_typecontent(L, i+1) );
     279                NV_LOG( LOG_DEBUG, "#" << i+1 << " - " << lua_typename(L, lua_type(L, i+1) ) << " = " << nlua_typecontent(L, i+1) );
    278280        }
    279281}
Note: See TracChangeset for help on using the changeset viewer.