Changeset 503 for trunk/src


Ignore:
Timestamp:
06/28/16 21:09:19 (9 years ago)
Author:
epyon
Message:
  • nv::random - support for different rng sources
  • nv::types - fixes and better support
  • nv::mesh_creator - full range transform
  • nv::context - buffer mask as separate type
  • nv::lua - initializations from lua::state instead of lua_State
  • nv::lua - initial support for rtti
Location:
trunk/src
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/random.cc

    r487 r503  
    1919#define NV_MT_TWIST(u, v)  ( (NV_MT_MIXBITS(u, v) >> 1) ^ ( (v) & 1UL ? mt_matrix_a : 0UL) )
    2020
    21 void random::mt_init( uint32 seed )
     21nv::random& random::get()
     22{
     23        static random default_rng;
     24        return default_rng;
     25}
     26
     27void random_mersenne::mt_init( uint32 seed )
    2228{
    2329        m_state[0] = static_cast<uint32>( seed & mt_full_mask );
     
    3440
    3541
    36 void random::mt_update()
     42void random_mersenne::mt_update()
    3743{
    3844        uint32 *p = m_state;
     
    5157
    5258
    53 uint32 random::mt_uint32()
     59uint32 random_mersenne::mt_uint32()
    5460{
    5561        uint32 r;
     
    7076}
    7177
    72 random::random( random::seed_type seed /*= 0 */ )
     78random_mersenne::random_mersenne( random_mersenne::seed_type seed /*= 0 */ )
    7379        : m_next( nullptr ), m_remaining( 0 ), m_seeded( 0 )
    7480{
    75         mt_init( seed == 0 ? randomized_seed() : seed );
    76 }
    77 
    78 random::seed_type random::set_seed( random::seed_type seed /*= 0 */ )
    79 {
    80         if ( seed == 0 ) seed = randomized_seed();
     81        mt_init( seed );
     82}
     83
     84random_mersenne::seed_type random_mersenne::set_seed( random_mersenne::seed_type seed /*= 0 */ )
     85{
    8186        mt_init( seed );
    8287        return seed;
    8388}
    8489
    85 nv::random& random::get()
    86 {
    87         static random default_rng;
    88         return default_rng;
    89 }
    90 
    91 random::result_type random::rand()
     90random_mersenne::result_type random_mersenne::rand()
    9291{
    9392        return mt_uint32();
    9493}
    9594
    96 uint32 random::urand( uint32 val )
    97 {
    98         uint32 x, max = mt_full_mask - ( mt_full_mask % val );
    99         while ( ( x = rand() ) >= max );
    100         return x / ( max / val );
    101 }
    102 
    103 random::seed_type random::randomized_seed()
     95random_base::seed_type random_base::randomized_seed()
    10496{
    10597        // TODO: this seems off, as it might often seed the same, use general time
     
    108100}
    109101
    110 nv::vec2 nv::random::precise_unit_vec2()
     102nv::vec2 nv::random_base::precise_unit_vec2()
    111103{
    112104        f32 angle = frand( math::pi<f32>() * 2.f );
     
    114106}
    115107
    116 nv::vec3 nv::random::precise_unit_vec3()
     108nv::vec3 nv::random_base::precise_unit_vec3()
    117109{
    118110        f32 cos_theta = frange( -1.0f, 1.0f );
     
    126118}
    127119
    128 nv::vec2 nv::random::fast_disk_point()
     120nv::vec2 nv::random_base::fast_disk_point()
    129121{
    130122        f32 r1 = frand();
     
    135127}
    136128
    137 nv::vec2 nv::random::precise_disk_point()
     129nv::vec2 nv::random_base::precise_disk_point()
    138130{
    139131        f32 r = sqrt( frand() );
     
    142134}
    143135
    144 nv::vec3 nv::random::fast_sphere_point()
     136nv::vec3 nv::random_base::fast_sphere_point()
    145137{
    146138        f32 rad     = frand();
     
    156148}
    157149
    158 nv::vec3 nv::random::precise_sphere_point()
     150nv::vec3 nv::random_base::precise_sphere_point()
    159151{
    160152        f32 radius = pow( frand(), 1.f/3.f );
     
    169161}
    170162
    171 nv::vec2 nv::random::precise_ellipse_point( const vec2& radii )
     163nv::vec2 nv::random_base::precise_ellipse_point( const vec2& radii )
    172164{
    173165        vec2 p = range( -radii, radii );
     
    184176}
    185177
    186 nv::vec3 nv::random::precise_ellipsoid_point( const vec3& radii )
     178nv::vec3 nv::random_base::precise_ellipsoid_point( const vec3& radii )
    187179{
    188180        vec3 p = range( -radii, radii );
     
    199191}
    200192
    201 nv::vec2 nv::random::fast_hollow_disk_point( f32 iradius, f32 oradius )
     193nv::vec2 nv::random_base::fast_hollow_disk_point( f32 iradius, f32 oradius )
    202194{
    203195        f32 idist2 = iradius * iradius;
     
    207199}
    208200
    209 nv::vec2 nv::random::precise_hollow_disk_point( f32 iradius, f32 oradius )
     201nv::vec2 nv::random_base::precise_hollow_disk_point( f32 iradius, f32 oradius )
    210202{
    211203        return fast_hollow_disk_point( iradius, oradius );
    212204}
    213205
    214 nv::vec3 nv::random::fast_hollow_sphere_point( f32 iradius, f32 oradius )
     206nv::vec3 nv::random_base::fast_hollow_sphere_point( f32 iradius, f32 oradius )
    215207{
    216208        f32 idist3 = iradius * iradius * iradius;
     
    220212}
    221213
    222 nv::vec3 nv::random::precise_hollow_sphere_point( f32 iradius, f32 oradius )
     214nv::vec3 nv::random_base::precise_hollow_sphere_point( f32 iradius, f32 oradius )
    223215{
    224216        return fast_hollow_sphere_point( iradius, oradius );
     
    226218
    227219
    228 nv::vec2 nv::random::fast_hollow_ellipse_point( const vec2& iradii, const vec2& oradii )
     220nv::vec2 nv::random_base::fast_hollow_ellipse_point( const vec2& iradii, const vec2& oradii )
    229221{
    230222        vec2 iradii2 = iradii * iradii;
     
    241233}
    242234
    243 nv::vec2 nv::random::precise_hollow_ellipse_point( const vec2& iradii, const vec2& oradii )
     235nv::vec2 nv::random_base::precise_hollow_ellipse_point( const vec2& iradii, const vec2& oradii )
    244236{
    245237        return fast_hollow_ellipse_point( iradii, oradii );
    246238}
    247239
    248 nv::vec3 nv::random::fast_hollow_ellipsoid_point( const vec3& iradii, const vec3& oradii )
     240nv::vec3 nv::random_base::fast_hollow_ellipsoid_point( const vec3& iradii, const vec3& oradii )
    249241{
    250242        vec3 iradii2 = iradii * iradii;
     
    267259}
    268260
    269 nv::vec3 nv::random::precise_hollow_ellipsoid_point( const vec3& iradii, const vec3& oradii )
     261nv::vec3 nv::random_base::precise_hollow_ellipsoid_point( const vec3& iradii, const vec3& oradii )
    270262{
    271263        return fast_hollow_ellipsoid_point( iradii, oradii );
    272264}
    273265
     266nv::random_xor128::random_xor128( seed_type seed /*= randomized_seed() */ )
     267{
     268        set_seed( seed );
     269}
     270
     271nv::random_base::seed_type nv::random_xor128::set_seed( seed_type seed /*= 0 */ )
     272{
     273        uint32 s = 4294967296 - seed;
     274        m_state[0] = 123456789 * s;
     275        m_state[1] = 362436069 * s;
     276        m_state[2] = 521288629 * s;
     277        m_state[3] = 88675123 * s;
     278        return seed;
     279}
     280
     281nv::random_base::result_type nv::random_xor128::rand()
     282{
     283        uint32 t = m_state[0];
     284        t ^= t << 11;
     285        t ^= t >> 8;
     286        m_state[0] = m_state[1]; m_state[1] = m_state[2]; m_state[2] = m_state[3];
     287        m_state[3] ^= m_state[3] >> 19;
     288        m_state[3] ^= t;
     289        return m_state[3];
     290}
  • trunk/src/gfx/mesh_creator.cc

    r491 r503  
    8888
    8989
    90 void nv::mesh_data_creator::transform( float scale, const mat3& r33 )
    91 {
    92         vec3 vertex_offset     = vec3();
    93         mat3 vertex_transform  = scale * r33;
    94         mat3 normal_transform  = r33;
     90void nv::mesh_data_creator::transform( const vec3& pos, const mat3& r33, float scale /*= 1.0f */ )
     91{
     92        vec3 vertex_offset = pos;
     93        mat3 vertex_transform = scale * r33;
     94        mat3 normal_transform = r33;
    9595
    9696        for ( uint32 c = 0; c < m_data->size(); ++c )
    9797        {
    9898                raw_data_channel_access channel( m_data, c );
    99                 const data_descriptor&  desc    = channel.descriptor();
     99                const data_descriptor&  desc = channel.descriptor();
    100100                uint8* raw_data = channel.raw_data();
    101101                uint32 vtx_size = desc.element_size();
     
    103103                int n_offset = -1;
    104104                int t_offset = -1;
    105                 for ( const auto& cslot : desc  )
     105                for ( const auto& cslot : desc )
    106106                        switch ( cslot.vslot )
    107107                        {
    108                                 case slot::POSITION : if ( cslot.etype == FLOAT_VECTOR_3 ) p_offset = int( cslot.offset ); break;
    109                                 case slot::NORMAL   : if ( cslot.etype == FLOAT_VECTOR_3 ) n_offset = int( cslot.offset ); break;
    110                                 case slot::TANGENT  : if ( cslot.etype == FLOAT_VECTOR_4 ) t_offset = int( cslot.offset ); break;
    111                                 default             : break;
     108                        case slot::POSITION: if ( cslot.etype == FLOAT_VECTOR_3 ) p_offset = int( cslot.offset ); break;
     109                        case slot::NORMAL: if ( cslot.etype == FLOAT_VECTOR_3 ) n_offset = int( cslot.offset ); break;
     110                        case slot::TANGENT: if ( cslot.etype == FLOAT_VECTOR_4 ) t_offset = int( cslot.offset ); break;
     111                        default: break;
    112112                        }
    113113
    114114                if ( p_offset != -1 )
    115                         for ( uint32 i = 0; i < channel.size(); i++)
     115                        for ( uint32 i = 0; i < channel.size(); i++ )
    116116                        {
    117117                                vec3& p = *reinterpret_cast<vec3*>( raw_data + vtx_size*i + p_offset );
     
    120120
    121121                if ( n_offset != -1 )
    122                         for ( uint32 i = 0; i < channel.size(); i++)
     122                        for ( uint32 i = 0; i < channel.size(); i++ )
    123123                        {
    124124                                vec3& n = *reinterpret_cast<vec3*>( raw_data + vtx_size*i + n_offset );
     
    126126                        }
    127127                if ( t_offset != -1 )
    128                         for ( uint32 i = 0; i < channel.size(); i++)
    129                         {
    130                                 vec4& t = *reinterpret_cast<vec4*>(raw_data + vtx_size*i + t_offset );
    131                                 t = vec4( math::normalize( normal_transform * vec3(t) ), t[3] );
    132                         }
    133         }
    134 }
     128                        for ( uint32 i = 0; i < channel.size(); i++ )
     129                        {
     130                                vec4& t = *reinterpret_cast<vec4*>( raw_data + vtx_size*i + t_offset );
     131                                t = vec4( math::normalize( normal_transform * vec3( t ) ), t[3] );
     132                        }
     133        }
     134}
     135
    135136
    136137struct vertex_g
  • trunk/src/gl/gl_context.cc

    r502 r503  
    201201}
    202202
    203 void nv::gl_context::blit( framebuffer f, clear_state::buffers_type mask, ivec2 src1, ivec2 src2, ivec2 dst1, ivec2 dst2 )
     203void nv::gl_context::blit( framebuffer f, buffer_mask mask, ivec2 src1, ivec2 src2, ivec2 dst1, ivec2 dst2 )
    204204{
    205205        gl_framebuffer_info* info  = m_framebuffers.get( f );
     
    207207        {
    208208                glBindFramebuffer( GL_FRAMEBUFFER, info->glid );
    209                 unsigned filter = mask == clear_state::COLOR_BUFFER ? GL_LINEAR : GL_NEAREST;
     209                unsigned filter = mask == buffer_mask::COLOR_BUFFER ? GL_LINEAR : GL_NEAREST;
    210210                glBlitFramebuffer( src1.x, src1.y, src2.x, src2.y, dst1.x, dst1.y, dst2.x, dst2.y, clear_state_buffers_to_mask( mask ), filter );
    211211        }
     
    213213
    214214
    215 void nv::gl_context::blit( framebuffer from, framebuffer to, clear_state::buffers_type mask, ivec2 src1, ivec2 src2, ivec2 dst1, ivec2 dst2 )
     215void nv::gl_context::blit( framebuffer from, framebuffer to, buffer_mask mask, ivec2 src1, ivec2 src2, ivec2 dst1, ivec2 dst2 )
    216216{
    217217        gl_framebuffer_info* finfo = m_framebuffers.get( from );
     
    221221                glBindFramebuffer( GL_READ_FRAMEBUFFER, finfo->glid );
    222222                glBindFramebuffer( GL_DRAW_FRAMEBUFFER, tinfo ? tinfo->glid : 0 );
    223                 unsigned filter = mask == clear_state::COLOR_BUFFER ? GL_LINEAR : GL_NEAREST;
     223                unsigned filter = mask == buffer_mask::COLOR_BUFFER ? GL_LINEAR : GL_NEAREST;
    224224                glBlitFramebuffer( src1.x, src1.y, src2.x, src2.y, dst1.x, dst1.y, dst2.x, dst2.y, clear_state_buffers_to_mask( mask ), filter );
    225225                glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 );
  • trunk/src/gl/gl_enum.cc

    r500 r503  
    2828}
    2929
    30 unsigned int nv::clear_state_buffers_to_mask( clear_state::buffers_type type )
     30unsigned int nv::clear_state_buffers_to_mask( buffer_mask type )
    3131{
    3232        unsigned int mask = 0;
    33         if ( (type & clear_state::COLOR_BUFFER) != 0 )   mask |= GL_COLOR_BUFFER_BIT;
    34         if ( (type & clear_state::DEPTH_BUFFER) != 0 )   mask |= GL_DEPTH_BUFFER_BIT;
    35         if ( (type & clear_state::STENCIL_BUFFER) != 0 ) mask |= GL_STENCIL_BUFFER_BIT;
     33        if ( (type & buffer_mask::COLOR_BUFFER) != 0 )   mask |= GL_COLOR_BUFFER_BIT;
     34        if ( (type & buffer_mask::DEPTH_BUFFER) != 0 )   mask |= GL_DEPTH_BUFFER_BIT;
     35        if ( (type & buffer_mask::STENCIL_BUFFER) != 0 ) mask |= GL_STENCIL_BUFFER_BIT;
    3636        return mask;
    3737}
  • trunk/src/lua/lua_area.cc

    r491 r503  
    459459}
    460460
    461 void nv::lua::register_area( lua_State* L )
    462 {
    463         int stack = lua_gettop( L );
    464         nlua_requiref(L, "area", luaopen_area, 1);
    465         lua_settop( L, stack );
    466 }
    467 
     461void nv::lua::register_area( lua::state* state )
     462{
     463        int stack = lua_gettop( state->get_raw() );
     464        nlua_requiref( state->get_raw(), "area", luaopen_area, 1);
     465        lua_settop( state->get_raw(), stack );
     466}
     467
  • trunk/src/lua/lua_aux.cc

    r490 r503  
    137137};
    138138
    139 void nv::lua::register_aux( lua_State* L )
     139void nv::lua::register_aux( lua::state* state )
    140140{
    141         nlua_register( L, "table", nluaaux_table_aux_f );
    142         nlua_register( L, "math", nluaaux_math_aux_f );
     141        nlua_register( state->get_raw(), "table", nluaaux_table_aux_f );
     142        nlua_register( state->get_raw(), "math", nluaaux_math_aux_f );
    143143}
    144144
  • trunk/src/lua/lua_map_area.cc

    r490 r503  
    223223}
    224224
    225 void nv::lua::register_map_area_interface( lua_State* L, int index )
    226 {
    227         nlua_register( L, nlua_map_area_f, index );
    228 }
    229 
    230 void nv::lua::register_map_area( lua_State* L )
    231 {
    232         luaopen_map_area(L);
    233 }
    234 
    235 void nv::lua::register_map_area_instance( lua_State* L, ref object_index, map_area* area )
    236 {
     225void nv::lua::register_map_area_interface( lua::state* state, int index )
     226{
     227        nlua_register( state->get_raw(), nlua_map_area_f, index );
     228}
     229
     230void nv::lua::register_map_area( lua::state* state )
     231{
     232        luaopen_map_area( state->get_raw() );
     233}
     234
     235void nv::lua::register_map_area_instance( lua::state* state, ref object_index, map_area* area )
     236{
     237        lua_State* L = state->get_raw();
    237238        lua_rawgeti( L, LUA_REGISTRYINDEX, object_index.get() );
    238239        lua_pushliteral( L, "__map_area_ptr" );
  • trunk/src/lua/lua_map_tile.cc

    r490 r503  
    366366};
    367367
    368 void nv::lua::register_map_tile( lua_State * L )
     368void nv::lua::register_map_tile( lua::state* state )
    369369{
    370370        // TODO: check if __gc is used!
     371        lua_State* L = state->get_raw();
    371372        luaL_newmetatable( L, NLUA_MAP_TILE_METATABLE );
    372373        lua_pushvalue( L, -1 );
  • trunk/src/lua/lua_math.cc

    r490 r503  
    359359}
    360360
    361 void nv::lua::register_math( lua_State* L )
     361template < typename T >
     362void nlua_rtti_vec_push( nv::lua::state* state, const nv::type_entry*, void* object )
     363{
     364        T* value = reinterpret_cast<T*>( object );
     365        push_vec<T>( state->get_raw(), *value );
     366}
     367
     368template < typename T >
     369bool nlua_rtti_vec_read( nv::lua::state* state, const nv::type_entry*, void* object, int index )
     370{
     371        T* value = reinterpret_cast<T*>( object );
     372        int type = lua_type( state->get_raw(), index );
     373        if ( type == LUA_TUSERDATA )
     374        {
     375                T* from = to_pvec<T>( state->get_raw(), index );
     376                if ( !from ) return false;
     377                *value = *from;
     378        }
     379//      else if ( type == LUA_TTABLE )
     380//      {
     381//
     382//      }
     383        else
     384                return false;
     385        int todo; int table_constructor;
     386        return true;
     387}
     388
     389void nv::lua::register_math( lua::state* state )
    362390{
    363391        for (size_t i = 0; i < 256; ++i ) nlua_swizzel_lookup[i] = 255;
     
    379407        nlua_swizzel_lookup[uchar8( 'v' )] = 0;
    380408        nlua_swizzel_lookup[uchar8( '3' )] = 3;
     409
     410        lua_State* L = state->get_raw();
    381411        int stack = lua_gettop( L );
    382412
     
    389419        nlua_requiref(L, "vec4", luaopen_vec<nv::vec4>, 1);
    390420        lua_settop( L, stack );
    391 }
    392 
     421
     422        state->register_rtti_type< nv::ivec2 >( nlua_rtti_vec_push<nv::ivec2>, nlua_rtti_vec_read<nv::ivec2> );
     423        state->register_rtti_type< nv::ivec3 >( nlua_rtti_vec_push<nv::ivec3>, nlua_rtti_vec_read<nv::ivec3> );
     424        state->register_rtti_type< nv::ivec4 >( nlua_rtti_vec_push<nv::ivec4>, nlua_rtti_vec_read<nv::ivec4> );
     425        state->register_rtti_type< nv::vec2 > ( nlua_rtti_vec_push<nv::vec2>,  nlua_rtti_vec_read<nv::vec2> );
     426        state->register_rtti_type< nv::vec3 > ( nlua_rtti_vec_push<nv::vec3>,  nlua_rtti_vec_read<nv::vec3> );
     427        state->register_rtti_type< nv::vec4 > ( nlua_rtti_vec_push<nv::vec4>,  nlua_rtti_vec_read<nv::vec4> );
     428}
     429
  • trunk/src/lua/lua_state.cc

    r490 r503  
    99#include "nv/lua/lua_raw.hh"
    1010#include "nv/lua/lua_nova.hh"
     11#include "nv/lua/lua_types.hh"
    1112#include "nv/core/logging.hh"
    1213#include "nv/stl/string.hh"
     
    143144
    144145lua::table_guard::table_guard( lua::state* lstate, const path& p, bool global )
    145         : state_wrapper( lstate->get_raw(), false ), m_level(0)
     146        : state_wrapper( lstate->get_raw(), lstate->m_lua_types, false ), m_parent( lstate ), m_level(0)
    146147{
    147148        m_global = false;
     
    155156
    156157lua::table_guard::table_guard( const table_guard& parent, const path& p )
    157         : state_wrapper( parent.m_state, false ), m_level(0)
     158        : state_wrapper( parent.m_state, parent.m_lua_types, false ), m_parent( parent.m_parent ), m_level(0)
    158159{
    159160        m_global = false;
     
    350351
    351352
     353bool nv::lua::table_guard::read( const string_view& element, const type_entry* entry, void* object )
     354{
     355        NV_ASSERT_ALWAYS( m_lua_types->get_type_database() == entry->type_db, "Type database mismatch between Lua and entry!" );
     356        lua_getfield( m_state, -1, element.data() );
     357        if ( lua_type( m_state, -1 ) != LUA_TTABLE )
     358        {
     359                lua_pop( m_state, 1 );
     360                return false;
     361        }
     362        if ( !nv::lua::read_rtti_type( m_parent, entry, object, -1 ) )
     363        {
     364                lua_pop( m_state, 1 );
     365                return false;
     366        }
     367        lua_pop( m_state, 1 );
     368        return true;
     369}
     370
    352371// state
    353372
    354 lua::state::state( lua_State* state ) : state_wrapper( state, false )
    355 {
    356 
    357 }
    358 
    359 lua::state::state( bool load_libs /*= false*/ ) : state_wrapper( nullptr, true )
     373lua::state::state( lua_State* state, type_database* types )
     374        : state_wrapper( state, new type_data( types ), false )
     375{
     376
     377}
     378
     379lua::state::state( bool load_libs /*= false*/, type_database* types )
     380        : state_wrapper( nullptr, new type_data( types ), true )
    360381{
    361382        load_lua_library();
     
    575596}
    576597
     598void nv::lua::state::register_rtti_type( thash64 tid, lua_rtti_push_function p, lua_rtti_read_function r )
     599{
     600        m_lua_types->insert( tid, p, r );
     601}
     602
    577603nv::lua::ref nv::lua::state::register_handle_component_impl( string_view id, bool empty )
    578604{
     
    626652}
    627653
     654nv::lua::state::~state()
     655{
     656        delete m_lua_types;
     657        m_lua_types = nullptr;
     658}
     659
     660template < typename T >
     661void nlua_rtti_signed_push( nv::lua::state* state, const type_entry*, void* object )
     662{
     663        T* value = reinterpret_cast<T*>( object );
     664        lua_pushinteger( state->get_raw(), lua_Integer( *value ) );
     665}
     666
     667template < typename T >
     668void nlua_rtti_unsigned_push( nv::lua::state* state, const type_entry*, void* object )
     669{
     670        T* value = reinterpret_cast<T*>( object );
     671        lua_pushinteger( state->get_raw(), lua_Unsigned( *value ) );
     672}
     673
     674template < typename T >
     675void nlua_rtti_floating_push( nv::lua::state* state, const type_entry*, void* object )
     676{
     677        T* value = reinterpret_cast< T* >( object );
     678        lua_pushnumber( state->get_raw(), lua_Number( *value ) );
     679}
     680
     681static void nlua_rtti_boolean_push( nv::lua::state* state, const type_entry*, void* object )
     682{
     683        bool* value = reinterpret_cast<bool*>( object );
     684        lua_pushboolean( state->get_raw(), *value );
     685}
     686
     687template < typename T >
     688bool nlua_rtti_signed_read( nv::lua::state* state, const type_entry*, void* object, int index )
     689{
     690        T* value = reinterpret_cast<T*>( object );
     691        if ( lua_type( state->get_raw(), index ) == LUA_TNUMBER )
     692        {
     693                *value = T( lua_tointeger( state->get_raw(), index ) );
     694                return true;
     695        }
     696        return false;
     697}
     698
     699template < typename T >
     700bool nlua_rtti_unsigned_read( nv::lua::state* state, const type_entry*, void* object, int index )
     701{
     702        T* value = reinterpret_cast<T*>( object );
     703        if ( lua_type( state->get_raw(), index ) == LUA_TNUMBER )
     704        {
     705                *value = T( lua_tointeger( state->get_raw(), index ) );
     706                return true;
     707        }
     708        return false;
     709}
     710
     711template < typename T >
     712bool nlua_rtti_floating_read( nv::lua::state* state, const type_entry*, void* object, int index )
     713{
     714        T* value = reinterpret_cast<T*>( object );
     715        if ( lua_type( state->get_raw(), index ) == LUA_TNUMBER )
     716        {
     717                *value = T( lua_tonumber( state->get_raw(), index ) );
     718                return true;
     719        }
     720        return false;
     721}
     722
     723static bool nlua_rtti_boolean_read( nv::lua::state* state, const type_entry*, void* object, int index )
     724{
     725        bool* value = reinterpret_cast<bool*>( object );
     726        if ( lua_type( state->get_raw(), index ) == LUA_TBOOLEAN )
     727        {
     728                *value = bool( lua_toboolean( state->get_raw(), index ) );
     729                return true;
     730        }
     731        return false;
     732}
     733
     734
     735void nv::lua::type_data::insert( thash64 tid, lua_rtti_push_function p, lua_rtti_read_function r )
     736{
     737        m_type_read.assign( tid, r );
     738        m_type_push.assign( tid, p );
     739}
     740
     741void nv::lua::type_data::register_standard_types()
     742{
     743        insert<bool>( nlua_rtti_boolean_push, nlua_rtti_boolean_read );
     744        insert<nv::sint8> ( nlua_rtti_signed_push<nv::sint8>,    nlua_rtti_signed_read<nv::sint8> );
     745        insert<nv::sint16>( nlua_rtti_signed_push<nv::sint16>,   nlua_rtti_signed_read<nv::sint16> );
     746        insert<nv::sint32>( nlua_rtti_signed_push<nv::sint32>,   nlua_rtti_signed_read<nv::sint32> );
     747        insert<nv::uint8> ( nlua_rtti_unsigned_push<nv::uint8>,  nlua_rtti_unsigned_read<nv::uint8> );
     748        insert<nv::uint16>( nlua_rtti_unsigned_push<nv::uint16>, nlua_rtti_unsigned_read<nv::uint16> );
     749        insert<nv::uint32>( nlua_rtti_unsigned_push<nv::uint32>, nlua_rtti_unsigned_read<nv::uint32> );
     750        insert<nv::f32>   ( nlua_rtti_floating_push<nv::f32>,    nlua_rtti_floating_read<nv::f32> );
     751        insert<nv::f64>   ( nlua_rtti_floating_push<nv::f64>,    nlua_rtti_floating_read<nv::f64> );
     752//      insert<nv::sint64>( nlua_rtti_floating_push<nv::sint64>, nlua_rtti_floating_read<nv::sint64> );
     753//      insert<nv::uint64>( nlua_rtti_floating_push<nv::uint64>, nlua_rtti_floating_read<nv::uint64> );
     754}
Note: See TracChangeset for help on using the changeset viewer.