Changeset 188


Ignore:
Timestamp:
08/04/13 06:37:00 (12 years ago)
Author:
epyon
Message:
  • lua/path - bugfix
  • lua/state - added is_defined(path)
  • lua/table_guard - added is_defined(path), get_unsigned, get_size
Location:
trunk
Files:
3 edited

Legend:

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

    r181 r188  
    3535
    3636                        template < typename T1, typename T2 >
    37                         path( const T1& p1, const T2& p2 )
     37                        path( const T1& p1, const T2& p2 ) : m_count( 0 )
    3838                        {
    3939                                const size_t l1 = string_length<T1>::get( p1 );
  • trunk/nv/lua/lua_state.hh

    r187 r188  
    4848                        table_guard( state* lstate, const path& p, bool global = true );
    4949                        table_guard( const table_guard& parent, const path& p );
     50                        size_t get_size();
    5051                        bool has_field( const std::string& element );
    5152                        std::string get_string( const std::string& element, const std::string& defval = "" );
    5253                        char get_char( const std::string& element, char defval = ' ' );
    5354                        int get_integer( const std::string& element, int defval = 0 );
     55                        unsigned get_unsigned( const std::string& element, unsigned defval = 0 );
    5456                        double get_double( const std::string& element, double defval = 0.0 );
    5557                        bool get_boolean( const std::string& element, bool defval = false );
     58                        bool is_defined( const path& p );
    5659
    5760                        template< typename R, typename T >
     
    173176                        int get_stack_size();
    174177                        void log_stack();
     178                        bool is_defined( const path& p, bool global = true );
    175179                        lua_State* get_raw();
    176180                        reference register_object( object * o );
  • trunk/src/lua/lua_state.cc

    r187 r188  
    216216}
    217217
     218size_t lua::table_guard::get_size()
     219{
     220        return lua_rawlen( L->get_raw(), -1 );
     221}
     222
     223
    218224bool lua::table_guard::has_field( const string& element )
    219225{
     
    248254}
    249255
     256unsigned lua::table_guard::get_unsigned( const string& element, unsigned defval /*= "" */ )
     257{
     258        lua_getfield( L->L, -1, element.c_str() );
     259        int result = lua_type( L->L, -1 ) == LUA_TNUMBER ? lua_tounsigned( L->L, -1 ) : defval;
     260        lua_pop( L->L, 1 );
     261        return result;
     262}
     263
    250264double lua::table_guard::get_double( const string& element, double defval /*= "" */ )
    251265{
     
    274288}
    275289
     290bool nv::lua::table_guard::is_defined( const path& p )
     291{
     292        return L->is_defined( p, false );
     293}
    276294
    277295void lua::table_guard::get_raw_flags( const std::string& element, uint8* data, uint32 count )
     
    393411}
    394412
     413
     414bool nv::lua::state::is_defined( const path& p, bool global )
     415{
     416        if ( !p.resolve( L, global ) )
     417        {
     418                return false;
     419        }
     420        bool result = !lua_isnil( L, -1 );
     421        lua_pop( L, 1 );
     422        return result;
     423}
     424
    395425int lua::state::call_function( int nargs, int nresults )
    396426{
Note: See TracChangeset for help on using the changeset viewer.