Changeset 75


Ignore:
Timestamp:
06/01/13 22:22:22 (12 years ago)
Author:
epyon
Message:
  • lua_glm - uses own naming scheme, made independent of nv/types.hh and it's type system
  • lua_glm - metatable lookup properly tied to registering table, custom naming possible again
Location:
trunk
Files:
2 edited

Legend:

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

    r53 r75  
    77#define NV_LUA_GLM_HH
    88
     9#include <new>
     10#include <glm/glm.hpp>
    911#include <nv/common.hh>
    1012#include <nv/lib/lua.hh>
    11 #include <glm/glm.hpp>
    1213
    1314void nlua_register_glm( lua_State* L );
     15
     16template< typename T > inline const char* nlua_metatable_name() { static_assert(sizeof(T) == 0, "Type not implemented!"); return NULL; }
    1417
    1518template< typename T >
    1619bool nlua_is_vec( lua_State* L, int index )
    1720{
    18         return luaL_testudata( L, index, nv::get_type_name<T>() ) != 0;
     21        return luaL_testudata( L, index, nlua_metatable_name<T>() ) != 0;
    1922}
    2023
     
    2225T nlua_to_vec( lua_State* L, int index )
    2326{
    24         return *(T*)luaL_checkudata( L, index, nv::get_type_name<T>() );
     27        return *(T*)luaL_checkudata( L, index, nlua_metatable_name<T>() );
    2528}
    2629
     
    2831T* nlua_to_pvec( lua_State* L, int index )
    2932{
    30         return (T*)luaL_checkudata( L, index, nv::get_type_name<T>() );
     33        return (T*)luaL_checkudata( L, index, nlua_metatable_name<T>() );
    3134}
    3235
     
    3538{
    3639        new (lua_newuserdata(L, sizeof(T))) T(v);
    37         luaL_setmetatable( L, nv::get_type_name<T>() );
     40        luaL_setmetatable( L, nlua_metatable_name<T>() );
    3841}
    3942
     43template<> inline const char* nlua_metatable_name< glm::ivec2 >() { return "ivec2"; }
     44template<> inline const char* nlua_metatable_name< glm::ivec3 >() { return "ivec3"; }
     45template<> inline const char* nlua_metatable_name< glm::ivec4 >() { return "ivec4"; }
     46template<> inline const char* nlua_metatable_name< glm::vec2  >() { return "vec2"; }
     47template<> inline const char* nlua_metatable_name< glm::vec3  >() { return "vec3"; }
     48template<> inline const char* nlua_metatable_name< glm::vec4  >() { return "vec4"; }
     49
    4050#endif // NV_LUA_GLM_HH
  • trunk/src/lua/lua_glm.cc

    r74 r75  
    66
    77#include "nv/lua/lua_glm.hh"
    8 #include "nv/types.hh"
    98#include "nv/string.hh"
    10 #include <new>
    119
    1210static size_t nlua_swizzel_lookup[256];
     
    224222        }
    225223
    226         lua_getglobal( L, nv::get_type_name<T>() );
    227         lua_pushvalue( L, -2 );
     224        lua_getmetatable( L, 1 );
     225        lua_getfield( L, -1, "__base" );
     226        lua_pushvalue( L, 2 );
    228227        lua_rawget( L, -2 );
    229 
    230228        return 1;
    231229}
     
    306304        };
    307305
    308         luaL_newmetatable( L, nv::get_type_name<T>() );
     306        luaL_newmetatable( L, nlua_metatable_name<T>() );
    309307        luaL_setfuncs( L, nlua_vec_m, 0 );
    310         lua_pop(L,1);
    311308        luaL_newlib(L, nlua_vec_f);
    312         lua_newtable( L );
     309        lua_pushvalue(L, -1);
     310        lua_setfield(L, -3, "__base" );
     311        lua_replace(L, -2);
     312    lua_newtable( L );
    313313        luaL_setfuncs( L, nlua_vec_fm, 0 );
    314314        lua_setmetatable( L, -2 );
     
    336336        nlua_swizzel_lookup['3'] = 3;
    337337        int stack = lua_gettop( L );
     338
    338339        luaL_requiref(L, "ivec2", luaopen_vec<glm::ivec2>, 1);
    339340        luaL_requiref(L, "ivec3", luaopen_vec<glm::ivec3>, 1);
Note: See TracChangeset for help on using the changeset viewer.