Changeset 181


Ignore:
Timestamp:
07/30/13 04:44:15 (12 years ago)
Author:
epyon
Message:
  • string - string_length template
  • lua/path - power tool, universal lua path
  • lua_state - now uses lua/path for table_guard constructors
Location:
trunk
Files:
2 added
3 edited

Legend:

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

    r163 r181  
    1212#include <nv/common.hh>
    1313#include <nv/flags.hh>
     14#include <nv/lua/lua_path.hh>
    1415#include <string>
    1516
     
    4243                {
    4344                public:
    44                         table_guard( state* lstate, const std::string& table, bool global = true );
    45                         table_guard( state* lstate, const std::string& table, int index, bool global = true );
    46                         table_guard( state* lstate, const std::string& table, const std::string& index, bool global = true );
    47                         table_guard( const table_guard& parent, const std::string& index );
    48                         table_guard( const table_guard& parent, int index );
     45                        table_guard( state* lstate, const path& p, bool global = true );
     46                        table_guard( const table_guard& parent, const path& p );
    4947                        bool has_field( const std::string& element );
    5048                        std::string get_string( const std::string& element, const std::string& defval = "" );
  • trunk/nv/string.hh

    r133 r181  
    77
    88#include <string>
     9#include <cstring>
    910#include <sstream>
    1011#include <fstream>
     
    119120        }
    120121
     122        template< typename T >
     123        struct string_length
     124        {
     125                static const size_t get( T ) { return 0; }
     126        };
     127        template< size_t S >
     128        struct string_length< const char[S] >
     129        {
     130                static const size_t get( const char* ) { return S-1; }
     131        };
     132        template<>
     133        struct string_length< const char* >
     134        {
     135                static const size_t get( const char* s ) { return std::strlen( s ); }
     136        };
     137        template<>
     138        struct string_length< std::string >
     139        {
     140                static const size_t get( const std::string& s ) { return s.length(); }
     141        };
     142
    121143
    122144}
  • trunk/src/lua/lua_state.cc

    r163 r181  
    198198}
    199199
    200 lua::table_guard::table_guard( lua::state* lstate, const std::string& table, bool global )
     200lua::table_guard::table_guard( lua::state* lstate, const path& p, bool global )
    201201        : L(lstate), m_guard(lstate)
    202202{
    203         L->push( table, global );
    204 }
    205 
    206 lua::table_guard::table_guard( lua::state* lstate, const std::string& table, int index, bool global )
    207         : L(lstate), m_guard(lstate)
    208 {
    209         L->push( table, global );
    210         lua_rawgeti( L->L, -1, index );
    211 }
    212 
    213 lua::table_guard::table_guard( lua::state* lstate, const std::string& table, const std::string& index, bool global /*= true */ )
    214         : L(lstate), m_guard(lstate)
    215 {
    216         L->push( table, global );
    217         lua_pushstring( L->L, index.c_str() );
    218         lua_rawget( L->L, -2 );
    219 }
    220 
    221 lua::table_guard::table_guard( const table_guard& parent, const std::string& index )
     203        if ( !p.resolve( L->get_raw(), global ) )
     204        {
     205                // TODO : error handling
     206        }
     207}
     208
     209lua::table_guard::table_guard( const table_guard& parent, const path& p )
    222210        : L( parent.L ), m_guard( parent.L )
    223211{
    224         lua_getfield( L->L, -1, index.c_str() );
    225 }
    226 
    227 lua::table_guard::table_guard( const table_guard& parent, int index )
    228         : L( parent.L ), m_guard( parent.L )
    229 {
    230         lua_rawgeti( L->L, -1, index );
     212        if ( !p.resolve( L->get_raw(), false ) )
     213        {
     214                // TODO : error handling
     215        }
    231216}
    232217
Note: See TracChangeset for help on using the changeset viewer.