Changeset 217


Ignore:
Timestamp:
09/10/13 18:11:39 (12 years ago)
Author:
epyon
Message:
  • lua/nova - almost complete reimplementation of "core" from FPC Valkyrie
  • lua/state - nova loaded by default
  • object - prototype reference caching
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/lua/lua_state.hh

    r215 r217  
    168168                };
    169169
    170 
    171 
    172170                class table_guard;
    173171                class state : public state_wrapper
     
    175173                        friend class stack_guard;
    176174                        friend class table_guard;
     175
    177176                public:
    178177                        explicit state( bool load_libs = false );
     
    187186                        reference register_object( object * o );
    188187                        reference register_object( object * o, const char* lua_name );
     188                        reference register_proto( object * o, const char* storage );
    189189
    190190                        template< typename TYPE >
  • trunk/nv/object.hh

    r187 r217  
    178178
    179179        protected:
    180                 void register_with_lua( const char* lua_name = nullptr );
     180                void register_with_lua( const char* lua_name, const char* storage );
    181181
    182182        protected:
    183                 root*   m_root;        ///< pointer to root
    184                 string  m_id;          ///< id type of the object
    185                 string  m_name;        ///< name of the object
    186                 uid     m_uid;         ///< uid of the object
    187                 int     m_lua_index;   ///< lua reference
    188                 object* m_parent;      ///< pointer to parent
    189                 list    m_children;    ///< children objects
    190                 size_t  m_child_count; ///< number of children
     183                root*   m_root;            ///< pointer to root
     184                string  m_id;              ///< id type of the object
     185                string  m_name;            ///< name of the object
     186                uid     m_uid;             ///< uid of the object
     187                int     m_lua_index;       ///< lua reference
     188                int     m_lua_proto_index; ///< lua reference
     189                object* m_parent;          ///< pointer to parent
     190                list    m_children;        ///< children objects
     191                size_t  m_child_count;     ///< number of children
    191192        };
    192193
  • trunk/src/lua/lua_state.cc

    r216 r217  
    88
    99#include "nv/lua/lua_raw.hh"
     10#include "nv/lua/lua_nova.hh"
    1011#include "nv/logging.hh"
    1112#include "nv/string.hh"
     
    235236                        lib->func( m_state );
    236237                }
     238                register_nova( this );
    237239        }
    238240
     
    337339        }
    338340        deep_pointer_copy( -1, o );
     341        return luaL_ref( m_state, LUA_REGISTRYINDEX );
     342}
     343
     344lua::reference lua::state::register_proto( object * o, const char* storage )
     345{
     346        stack_guard guard( this );
     347        lua_getglobal( m_state, storage );
     348        if ( lua_isnil( m_state, -1 ) )
     349        {
     350                NV_THROW( runtime_error, std::string( storage ) + " storage not registered!" );
     351        }
     352        lua_getfield( m_state, -1, o->get_id().c_str() );
     353        if ( lua_isnil( m_state, -1 ) )
     354        {
     355                NV_THROW( runtime_error, std::string( o->get_id() ) + " not found in " + std::string( storage ) + " storage!" );
     356        }
    339357        return luaL_ref( m_state, LUA_REGISTRYINDEX );
    340358}
  • trunk/src/object.cc

    r187 r217  
    1616
    1717object::object()
    18         : m_root( nullptr ), m_id(), m_name(), m_uid(0), m_lua_index(lua::ref_none), m_parent( nullptr ), m_children(), m_child_count(0)
     18        : m_root( nullptr )
     19        , m_id()
     20        , m_name()
     21        , m_uid(0)
     22        , m_lua_index(lua::ref_none)
     23        , m_lua_proto_index(lua::ref_none)
     24        , m_parent( nullptr )
     25        , m_children()
     26        , m_child_count(0)
    1927{
    2028}
    2129
    2230object::object( root* aroot, const string& aid )
    23         : m_root( aroot ), m_id(aid), m_name(), m_uid( 0 ), m_lua_index(lua::ref_none), m_parent( nullptr ), m_children(), m_child_count(0)
     31        : m_root( aroot )
     32        , m_id( aid )
     33        , m_name()
     34        , m_uid(0)
     35        , m_lua_index(lua::ref_none)
     36        , m_lua_proto_index(lua::ref_none)
     37        , m_parent( nullptr )
     38        , m_children()
     39        , m_child_count(0)
    2440{
    2541        if ( m_root )
     
    191207}
    192208
    193 void nv::object::register_with_lua( const char* lua_name /*= nullptr*/ )
     209void nv::object::register_with_lua( const char* lua_name, const char* storage )
    194210{
    195211        lua::state* state = get_root()->get_lua_state();
     
    198214                if ( lua_name != nullptr )
    199215                {
    200                         m_lua_index = state->register_object( this, lua_name );
    201                 }
    202                 else
    203                 {
    204                         m_lua_index = state->register_object( this );
    205                 }
    206         }
    207 }
     216                        m_lua_index       = state->register_object( this, lua_name );
     217                }
     218                if ( storage != nullptr )
     219                {
     220                        m_lua_proto_index = state->register_proto( this, storage );
     221                }
     222        }
     223}
Note: See TracChangeset for help on using the changeset viewer.