Changeset 177 for trunk/src/lua
- Timestamp:
- 07/27/13 16:31:34 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lua/lua_glm.cc
r174 r177 9 9 #include "nv/lua/lua_raw.hh" 10 10 #include "nv/string.hh" 11 #include "nv/random.hh" 11 12 12 13 static size_t nlua_swizzel_lookup[256]; … … 24 25 template < typename T, size_t k > 25 26 struct nlua_vec_constructor { 27 static inline T unit() { return T(); } 26 28 static inline T construct( lua_State*, int ) { 27 29 return T(); … … 30 32 31 33 template < typename T > struct nlua_vec_constructor< T, 1 > { 34 static inline T unit() { return T( 1 ); } 32 35 static inline T construct( lua_State* L, int index ) { 33 36 return T( lua_tonumber( L, index ) ); … … 36 39 37 40 template < typename T > struct nlua_vec_constructor< T, 2 > { 41 static inline T unit() { return T( 1, 1 ); } 38 42 static inline T construct( lua_State* L, int index ) { 39 43 if ( lua_type( L, index ) == LUA_TUSERDATA ) … … 45 49 46 50 template < typename T > struct nlua_vec_constructor< T, 3 > { 51 static inline T unit() { return T( 1, 1, 1 ); } 47 52 static inline T construct( lua_State* L, int index ) { 48 53 typedef glm::detail::tvec2<typename T::value_type> vec2; … … 65 70 66 71 template < typename T > struct nlua_vec_constructor< T, 4 > { 72 static inline T unit() { return T( 1, 1, 1, 1 ); } 67 73 static inline T construct( lua_State* L, int index ) { 68 74 typedef glm::detail::tvec2<typename T::value_type> vec2; … … 113 119 114 120 template< typename T > 121 int nlua_vec_random( lua_State* L ) 122 { 123 nlua_push_vec<T>( L, nv::random::get().range( nlua_to_vec<T>( L, 1 ), nlua_to_vec<T>( L, 2 ) ) ); 124 return 1; 125 } 126 127 template< typename T > 115 128 int nlua_vec_clone( lua_State* L ) 116 129 { … … 118 131 return 1; 119 132 } 120 121 133 122 134 template< typename T > … … 291 303 static const struct luaL_Reg nlua_vec_sf [] = { 292 304 { "new", nlua_vec_new<T> }, 305 { "random", nlua_vec_random<T> }, 293 306 {NULL, NULL} 294 307 }; … … 297 310 { "clone", nlua_vec_clone<T> }, 298 311 { "get", nlua_vec_get<T> }, 312 { "tostring", nlua_vec_tostring<T> }, 299 313 {NULL, NULL} 300 314 }; … … 330 344 nlua_register( L, nlua_vec_sm, -1 ); 331 345 lua_setmetatable( L, -2 ); 346 347 nlua_push_vec( L, T() ); 348 lua_setfield( L, -2, "ZERO" ); 349 nlua_push_vec( L, nlua_vec_constructor<T,sizeof( T ) / sizeof( typename T::value_type )>::unit() ); 350 lua_setfield( L, -2, "UNIT" ); 332 351 return 1; 333 352 }
Note: See TracChangeset
for help on using the changeset viewer.