Changeset 174


Ignore:
Timestamp:
07/25/13 15:07:48 (12 years ago)
Author:
epyon
Message:
  • lua/glm - breaking functions into module (static) functions and methods
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lua/lua_glm.cc

    r172 r174  
    108108int nlua_vec_new( lua_State* L )
    109109{
    110         nlua_push_vec( L, nlua_vec_constructor<T,sizeof( T ) / sizeof( typename T::value_type )>::construct( L, 1 ) );
    111         return 1;
    112 }
     110        nlua_push_vec<T>( L, nlua_vec_constructor<T,sizeof( T ) / sizeof( typename T::value_type )>::construct( L, 1 ) );
     111        return 1;
     112}
     113
     114template< typename T >
     115int nlua_vec_clone( lua_State* L )
     116{
     117        nlua_push_vec<T>( L, nlua_to_vec<T>( L, 1 ) );
     118        return 1;
     119}
     120
    113121
    114122template< typename T >
    115123int nlua_vec_call( lua_State* L )
    116124{
    117         nlua_push_vec( L, nlua_vec_constructor<T,sizeof( T ) / sizeof( typename T::value_type )>::construct( L, 2 ) );
     125        nlua_push_vec<T>( L, nlua_vec_constructor<T,sizeof( T ) / sizeof( typename T::value_type )>::construct( L, 2 ) );
    118126        return 1;
    119127}
     
    224232        }
    225233
    226         luaL_getmetafield( L, 1, "__base" );
     234        luaL_getmetafield( L, 1, "__functions" );
    227235        lua_pushvalue( L, 2 );
    228236        lua_rawget( L, -2 );
     
    281289int luaopen_vec( lua_State * L )
    282290{
     291        static const struct luaL_Reg nlua_vec_sf [] = {
     292                { "new",            nlua_vec_new<T> },
     293                {NULL, NULL}
     294        };
     295
    283296        static const struct luaL_Reg nlua_vec_f [] = {
    284                 { "new",            nlua_vec_new<T> },
     297                { "clone",          nlua_vec_clone<T> },
    285298                { "get",            nlua_vec_get<T> },
    286299                {NULL, NULL}
    287300        };
    288301
    289         static const struct luaL_Reg nlua_vec_fm [] = {
     302        static const struct luaL_Reg nlua_vec_sm [] = {
    290303                { "__call",         nlua_vec_call<T> },
    291304                {NULL, NULL}
     
    309322        lua_createtable( L, 0, 0 );
    310323        nlua_register( L, nlua_vec_f, -1 );
    311         lua_pushvalue(L, -1);
    312         lua_setfield(L, -3, "__base" );
    313         lua_replace(L, -2);
     324        lua_setfield(L, -2, "__functions" );
     325        lua_pop( L, 1 );
     326
    314327        lua_createtable( L, 0, 0 );
    315         nlua_register( L, nlua_vec_fm, -1 );
     328        nlua_register( L, nlua_vec_sf, -1 );
     329        lua_createtable( L, 0, 0 );
     330        nlua_register( L, nlua_vec_sm, -1 );
    316331        lua_setmetatable( L, -2 );
    317332        return 1;
Note: See TracChangeset for help on using the changeset viewer.