Changeset 305 for trunk


Ignore:
Timestamp:
08/12/14 01:51:21 (11 years ago)
Author:
epyon
Message:
  • lua_state - state_wrapper::get functions with default values
  • lua_values - support for value get with default
  • lua_state - table error logging (need real handling)
Location:
trunk
Files:
3 edited

Legend:

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

    r296 r305  
    130130                        }
    131131
     132                        template< typename R >
     133                        R get( const path& p, const R& def )
     134                        {
     135                                if ( p.resolve( m_state, m_global ) )
     136                                {
     137                                        return detail::pop_return_value<R>( m_state, def );
     138                                }
     139                                return R();
     140                        }
     141
     142                        template< typename R, typename T >
     143                        R get( const T& key, const R& def )
     144                        {
     145                                if ( m_global ) push_global_table();
     146                                detail::push_value( m_state, key );
     147                                call_get();
     148                                if ( m_global ) pop_global_table();
     149                                return detail::pop_return_value<R>( m_state, def );
     150                        }
     151
     152                        template< typename R, typename T >
     153                        R raw_get( const T& key, const R& def )
     154                        {
     155                                if ( m_global ) push_global_table();
     156                                detail::push_value( m_state, key );
     157                                call_get_raw();
     158                                if ( m_global ) pop_global_table();
     159                                return detail::pop_return_value<R>( m_state, def );
     160                        }
    132161                        bool is_defined( const path& p ) { return is_defined( p, m_global ); }
    133162                        void register_native_function( lfunction f, const char* name );
  • trunk/nv/lua/lua_values.hh

    r265 r305  
    247247
    248248                        template < typename T >
     249                        inline void pop_value( lua_State *L, T& p, const T& def )
     250                        {
     251                                typedef typename type_degrade<T>::type degraded;
     252                                p = (T)pass_traits<degraded>::to( L, -1, def );
     253                                detail::pop_and_discard(L, 1);
     254                        }
     255                        template < typename T >
     256                        inline T pop_return_value( lua_State *L, const T& def )
     257                        {
     258                                typedef typename type_degrade<T>::type degraded;
     259                                T ret;
     260                                ret = (T)pass_traits<degraded>::to( L, -1, def );
     261                                detail::pop_and_discard(L, 1);
     262                                return ret;
     263                        }
     264
     265                        template < typename T >
    249266                        inline typename std::remove_reference<T>::type get_value( lua_State *L, int index )
    250267                        {
  • trunk/src/lua/lua_state.cc

    r296 r305  
    118118        m_global = false;
    119119        m_level  = lua_gettop( m_state );
    120         if ( !p.resolve( m_state, global ) )
    121         {
     120        if ( !p.resolve( m_state, global ) || lua_type(m_state, -1) != LUA_TTABLE )
     121        {
     122                NV_LOG( LOG_ERROR, "Could not resolve table!" );
    122123                // TODO : error handling
    123124        }
     
    129130        m_global = false;
    130131        m_level  = lua_gettop( m_state );
    131         if ( !p.resolve( m_state, false ) )
    132         {
     132        if ( !p.resolve( m_state, false ) || lua_type(m_state, -1) != LUA_TTABLE )
     133        {
     134                NV_LOG( LOG_ERROR, "Could not resolve table!" );
    133135                // TODO : error handling
    134136        }
Note: See TracChangeset for help on using the changeset viewer.