Changeset 75
- Timestamp:
- 06/01/13 22:22:22 (12 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/lua/lua_glm.hh
r53 r75 7 7 #define NV_LUA_GLM_HH 8 8 9 #include <new> 10 #include <glm/glm.hpp> 9 11 #include <nv/common.hh> 10 12 #include <nv/lib/lua.hh> 11 #include <glm/glm.hpp>12 13 13 14 void nlua_register_glm( lua_State* L ); 15 16 template< typename T > inline const char* nlua_metatable_name() { static_assert(sizeof(T) == 0, "Type not implemented!"); return NULL; } 14 17 15 18 template< typename T > 16 19 bool nlua_is_vec( lua_State* L, int index ) 17 20 { 18 return luaL_testudata( L, index, n v::get_type_name<T>() ) != 0;21 return luaL_testudata( L, index, nlua_metatable_name<T>() ) != 0; 19 22 } 20 23 … … 22 25 T nlua_to_vec( lua_State* L, int index ) 23 26 { 24 return *(T*)luaL_checkudata( L, index, n v::get_type_name<T>() );27 return *(T*)luaL_checkudata( L, index, nlua_metatable_name<T>() ); 25 28 } 26 29 … … 28 31 T* nlua_to_pvec( lua_State* L, int index ) 29 32 { 30 return (T*)luaL_checkudata( L, index, n v::get_type_name<T>() );33 return (T*)luaL_checkudata( L, index, nlua_metatable_name<T>() ); 31 34 } 32 35 … … 35 38 { 36 39 new (lua_newuserdata(L, sizeof(T))) T(v); 37 luaL_setmetatable( L, n v::get_type_name<T>() );40 luaL_setmetatable( L, nlua_metatable_name<T>() ); 38 41 } 39 42 43 template<> inline const char* nlua_metatable_name< glm::ivec2 >() { return "ivec2"; } 44 template<> inline const char* nlua_metatable_name< glm::ivec3 >() { return "ivec3"; } 45 template<> inline const char* nlua_metatable_name< glm::ivec4 >() { return "ivec4"; } 46 template<> inline const char* nlua_metatable_name< glm::vec2 >() { return "vec2"; } 47 template<> inline const char* nlua_metatable_name< glm::vec3 >() { return "vec3"; } 48 template<> inline const char* nlua_metatable_name< glm::vec4 >() { return "vec4"; } 49 40 50 #endif // NV_LUA_GLM_HH -
trunk/src/lua/lua_glm.cc
r74 r75 6 6 7 7 #include "nv/lua/lua_glm.hh" 8 #include "nv/types.hh"9 8 #include "nv/string.hh" 10 #include <new>11 9 12 10 static size_t nlua_swizzel_lookup[256]; … … 224 222 } 225 223 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 ); 228 227 lua_rawget( L, -2 ); 229 230 228 return 1; 231 229 } … … 306 304 }; 307 305 308 luaL_newmetatable( L, n v::get_type_name<T>() );306 luaL_newmetatable( L, nlua_metatable_name<T>() ); 309 307 luaL_setfuncs( L, nlua_vec_m, 0 ); 310 lua_pop(L,1);311 308 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 ); 313 313 luaL_setfuncs( L, nlua_vec_fm, 0 ); 314 314 lua_setmetatable( L, -2 ); … … 336 336 nlua_swizzel_lookup['3'] = 3; 337 337 int stack = lua_gettop( L ); 338 338 339 luaL_requiref(L, "ivec2", luaopen_vec<glm::ivec2>, 1); 339 340 luaL_requiref(L, "ivec3", luaopen_vec<glm::ivec3>, 1);
Note: See TracChangeset
for help on using the changeset viewer.