Changeset 406 for trunk/src/lua
- Timestamp:
- 06/20/15 00:05:17 (10 years ago)
- Location:
- trunk/src/lua
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lua/lua_function.cc
r395 r406 5 5 // For conditions of distribution and use, see copying.txt file in root folder. 6 6 7 #include <nv/lua/lua_function.hh>7 #include "nv/lua/lua_function.hh" 8 8 9 #include <nv/lua/lua_raw.hh> 9 #include "nv/core/logging.hh" 10 #include "nv/lua/lua_raw.hh" 10 11 11 12 using namespace nv; 13 14 #define NV_LUA_ABORT( func, ... ) \ 15 NV_LOG_CRITICAL( "lua::" func " : ", __VA_ARGS__ ) \ 16 NV_ABORT( "lua::" func " : critical error!" ) 12 17 13 18 lua::function_base::function_base( lua_State* a_L, const path& a_path, bool a_global /*= true*/ ) : L(a_L) … … 16 21 { 17 22 lua_pop( L, 1 ); 18 throw std::runtime_error("not a valid path - " +a_path.to_string() );23 NV_LUA_ABORT( "function_base::function_base", "not a valid path - ", a_path.to_string() ); 19 24 } 20 25 … … 22 27 { 23 28 lua_pop( L, 1 ); 24 throw std::runtime_error("not a valid function - " +a_path.to_string() );29 NV_LUA_ABORT( "function_base::function_base", "not a valid function - ", a_path.to_string() ); 25 30 } 26 31 m_ref = luaL_ref( L, LUA_REGISTRYINDEX ); … … 61 66 std::string error = lua_tostring( L, -1 ); 62 67 lua_pop( L, 1 ); 63 throw std::runtime_error(error.c_str());68 NV_LUA_ABORT( "function_base::call", "call failed - ", error.c_str() ); 64 69 } 65 70 } -
trunk/src/lua/lua_glm.cc
r397 r406 11 11 #include "nv/stl/type_traits/common.hh" 12 12 13 static size_t nlua_swizzel_lookup[256];13 static int nlua_swizzel_lookup[256]; 14 14 15 15 using nv::lua::detail::is_vec; … … 18 18 using nv::lua::detail::push_vec; 19 19 20 inline bool nlua_is_swizzel( const unsigned char* str, size_t max )20 inline bool nlua_is_swizzel( const unsigned char* str, int max ) 21 21 { 22 22 while (*str) … … 155 155 { 156 156 if ( lua_type( L, 1 ) == LUA_TNUMBER ) 157 push_vec<T>( L, (typename T::value_type)(lua_tonumber( L, 1 )) + to_vec<T>( L, 2 ) );157 push_vec<T>( L, static_cast<typename T::value_type>(lua_tonumber( L, 1 )) + to_vec<T>( L, 2 ) ); 158 158 else 159 159 if ( lua_type( L, 2 ) == LUA_TNUMBER ) 160 push_vec<T>( L, to_vec<T>( L, 1 ) + (typename T::value_type)(lua_tonumber( L, 2 )) );160 push_vec<T>( L, to_vec<T>( L, 1 ) + static_cast<typename T::value_type>(lua_tonumber( L, 2 )) ); 161 161 else 162 162 push_vec<T>( L, to_vec<T>( L, 1 ) + to_vec<T>( L, 2 ) ); … … 168 168 { 169 169 if ( lua_type( L, 1 ) == LUA_TNUMBER ) 170 push_vec<T>( L, (typename T::value_type)(lua_tonumber( L, 1 )) - to_vec<T>( L, 2 ) );170 push_vec<T>( L, static_cast<typename T::value_type>(lua_tonumber( L, 1 )) - to_vec<T>( L, 2 ) ); 171 171 else 172 172 if ( lua_type( L, 2 ) == LUA_TNUMBER ) 173 push_vec<T>( L, to_vec<T>( L, 1 ) - (typename T::value_type)(lua_tonumber( L, 2 )) );173 push_vec<T>( L, to_vec<T>( L, 1 ) - static_cast<typename T::value_type>(lua_tonumber( L, 2 )) ); 174 174 else 175 175 push_vec<T>( L, to_vec<T>( L, 1 ) - to_vec<T>( L, 2 ) ); … … 181 181 { 182 182 if ( lua_type( L, 1 ) == LUA_TNUMBER ) 183 push_vec<T>( L, (typename T::value_type)(lua_tonumber( L, 1 )) * to_vec<T>( L, 2 ) );183 push_vec<T>( L, static_cast<typename T::value_type>(lua_tonumber( L, 1 )) * to_vec<T>( L, 2 ) ); 184 184 else 185 185 if ( lua_type( L, 2 ) == LUA_TNUMBER ) 186 push_vec<T>( L, to_vec<T>( L, 1 ) * (typename T::value_type)(lua_tonumber( L, 2 )) );186 push_vec<T>( L, to_vec<T>( L, 1 ) * static_cast<typename T::value_type>(lua_tonumber( L, 2 )) ); 187 187 else 188 188 push_vec<T>( L, to_vec<T>( L, 1 ) * to_vec<T>( L, 2 ) ); … … 194 194 { 195 195 if ( lua_type( L, 1 ) == LUA_TNUMBER ) 196 push_vec<T>( L, (typename T::value_type)(lua_tonumber( L, 1 )) / to_vec<T>( L, 2 ) );196 push_vec<T>( L, static_cast<typename T::value_type>(lua_tonumber( L, 1 )) / to_vec<T>( L, 2 ) ); 197 197 else 198 198 if ( lua_type( L, 2 ) == LUA_TNUMBER ) 199 push_vec<T>( L, to_vec<T>( L, 1 ) / (typename T::value_type)(lua_tonumber( L, 2 )) );199 push_vec<T>( L, to_vec<T>( L, 1 ) / static_cast<typename T::value_type>(lua_tonumber( L, 2 )) ); 200 200 else 201 201 push_vec<T>( L, to_vec<T>( L, 1 ) / to_vec<T>( L, 2 ) ); … … 226 226 T* v = to_pvec<T>( L, 1 ); 227 227 size_t len = 0; 228 size_t vlen = v->length();229 const unsigned char * key = (const unsigned char *)( lua_tolstring( L, 2, &len ) );230 size_t idx = 255;228 int vlen = v->length(); 229 const unsigned char * key = reinterpret_cast<const unsigned char *>( lua_tolstring( L, 2, &len ) ); 230 int idx = 255; 231 231 232 232 if ( len == 1 ) … … 264 264 T* v = to_pvec<T>( L, 1 ); 265 265 size_t len = 0; 266 size_t vlen = v->length();267 const unsigned char * key = (const unsigned char *)( lua_tolstring( L, 2, &len ) );268 size_t idx = 255;266 int vlen = v->length(); 267 const unsigned char * key = reinterpret_cast<const unsigned char *>( lua_tolstring( L, 2, &len ) ); 268 int idx = 255; 269 269 if( len == 1 ) 270 270 { … … 272 272 if ( idx < vlen ) 273 273 { 274 (*v)[idx] = (typename T::value_type)luaL_checknumber( L, 3);274 (*v)[idx] = static_cast<typename T::value_type>( luaL_checknumber( L, 3 ) ); 275 275 return 0; 276 276 } … … 279 279 { 280 280 switch (len) { 281 case 2 : { vec2 v2 = to_vec<vec2>(L,3); for ( size_t i = 0; i<len; ++i) (*v)[nlua_swizzel_lookup[key[i]]] = v2[i]; } return 0;282 case 3 : { vec3 v3 = to_vec<vec3>(L,3); for ( size_t i = 0; i<len; ++i) (*v)[nlua_swizzel_lookup[key[i]]] = v3[i]; } return 0;283 case 4 : { vec4 v4 = to_vec<vec4>(L,3); for ( size_t i = 0; i<len; ++i) (*v)[nlua_swizzel_lookup[key[i]]] = v4[i]; } return 0;281 case 2 : { vec2 v2 = to_vec<vec2>(L,3); for ( int i = 0; i<int( len ); ++i) (*v)[nlua_swizzel_lookup[key[i]]] = v2[i]; } return 0; 282 case 3 : { vec3 v3 = to_vec<vec3>(L,3); for ( int i = 0; i<int( len ); ++i) (*v)[nlua_swizzel_lookup[key[i]]] = v3[i]; } return 0; 283 case 4 : { vec4 v4 = to_vec<vec4>(L,3); for ( int i = 0; i<int( len ); ++i) (*v)[nlua_swizzel_lookup[key[i]]] = v4[i]; } return 0; 284 284 default: break; 285 285 } -
trunk/src/lua/lua_handle.cc
r395 r406 16 16 NV_LUA_STACK_ASSERT( L, +1 ); 17 17 lua_rawgeti( L, LUA_REGISTRYINDEX, pseudoindex ); // table 18 lua_rawgeti( L, -1, (int)index); // table, entry18 lua_rawgeti( L, -1, int( index ) ); // table, entry 19 19 if ( !lua_istable( L, -1 ) ) 20 20 { … … 58 58 lua_rawgeti( L, LUA_REGISTRYINDEX, pseudoindex ); 59 59 lua_insert( L, -2 ); 60 lua_rawseti( L, -2, (int)index);60 lua_rawseti( L, -2, int( index ) ); 61 61 lua_pop( L, 1 ); 62 62 } … … 67 67 lua_rawgeti( L, LUA_REGISTRYINDEX, pseudoindex ); // table 68 68 lua_pushinteger( L, 0 ); 69 lua_rawseti( L, -2, (int)index);69 lua_rawseti( L, -2, int( index ) ); 70 70 lua_pop( L, 1 ); 71 71 } -
trunk/src/lua/lua_map_area.cc
r395 r406 67 67 else 68 68 { 69 return * (nv::map_area**)luaL_checkudata( L, index, NLUA_MAP_AREA_METATABLE);69 return *reinterpret_cast<nv::map_area**>( luaL_checkudata( L, index, NLUA_MAP_AREA_METATABLE ) ); 70 70 } 71 71 return o; … … 88 88 void nv::lua::detail::push_map_area( lua_State* L, nv::map_area* c ) 89 89 { 90 nv::map_area** pm = (nv::map_area**) (lua_newuserdata(L, sizeof(nv::map_area*)));90 nv::map_area** pm = reinterpret_cast<nv::map_area**>( lua_newuserdata(L, sizeof(nv::map_area*) ) ); 91 91 *pm = c; 92 92 luaL_getmetatable( L, NLUA_MAP_AREA_METATABLE ); … … 237 237 lua_rawgeti( L, LUA_REGISTRYINDEX, object_index.get() ); 238 238 lua_pushliteral( L, "__map_area_ptr" ); 239 lua_pushlightuserdata( L, (map_area*)area );239 lua_pushlightuserdata( L, area ); 240 240 lua_rawset( L, -3 ); 241 241 lua_pop( L, 1 ); -
trunk/src/lua/lua_map_tile.cc
r395 r406 40 40 static map_tile* nlua_to_pmap_tile( lua_State* L, int index ) 41 41 { 42 return (map_tile*)luaL_checkudata( L, index, NLUA_MAP_TILE_METATABLE);42 return reinterpret_cast<map_tile*>( luaL_checkudata( L, index, NLUA_MAP_TILE_METATABLE ) ); 43 43 } 44 44 45 45 static void nlua_push_map_tile( lua_State* L, const map_tile& tile ) 46 46 { 47 map_tile* result = (map_tile*)lua_newuserdata( L, sizeof(map_tile) );47 map_tile* result = reinterpret_cast<map_tile*>( lua_newuserdata( L, sizeof(map_tile) ) ); 48 48 *result = tile; 49 49 luaL_setmetatable( L, NLUA_MAP_TILE_METATABLE ); … … 65 65 map_tile tile; 66 66 67 tile.size_y = (nv::uint16)( nv::count( code.begin(), code.end(), '\n' ) + 1 );68 tile.size_x = (nv::uint16)( code.find( '\n' ) );67 tile.size_y = nv::uint16( nv::count( code.begin(), code.end(), '\n' ) + 1 ); 68 tile.size_x = nv::uint16( code.find( '\n' ) ); 69 69 if ( tile.size_x == 0 ) 70 70 { 71 tile.size_x = (nv::uint16)code.length();71 tile.size_x = nv::uint16( code.length() ); 72 72 } 73 73 tile.data = new nv::uint8[ tile.size_x * tile.size_y ]; … … 85 85 if ( lua_isstring( L, -2 ) && lua_objlen( L, -2 ) == 1 ) 86 86 { 87 translation[ (nv::uint8)( lua_tostring( L, -2 )[0] ) ] = nv::uint8( map_area->string_to_id( lua_tostring( L, -1 ) ) );87 translation[ nv::uint8( lua_tostring( L, -2 )[0] ) ] = nv::uint8( map_area->string_to_id( lua_tostring( L, -1 ) ) ); 88 88 } 89 89 // removes 'value'; keeps 'key' for next iteration */ … … 95 95 for ( nv::uint16 row = 0; row < tile.size_y; row++ ) 96 96 { 97 nv::uchar8 gylph = (nv::uchar8)code[ row * ( tile.size_x + 1 ) + line ];97 nv::uchar8 gylph = nv::uchar8( code[ row * ( tile.size_x + 1 ) + line ] ); 98 98 // TODO: check for errors 99 99 tile.data[ row * tile.size_x + line ] = translation[ gylph ]; … … 108 108 { 109 109 map_tile* old_tile = nlua_to_pmap_tile( L, 1 ); 110 map_tile* new_tile = (map_tile*) lua_newuserdata( L, sizeof( map_tile) );110 map_tile* new_tile = reinterpret_cast<map_tile*>( lua_newuserdata( L, sizeof( map_tile ) ) ); 111 111 new_tile->size_x = old_tile->size_x; 112 112 new_tile->size_y = old_tile->size_y; … … 246 246 nv::uint16 org_x = tile->size_x; 247 247 nv::uint16 org_y = tile->size_y; 248 nv::uint16 new_x = ( nv::uint16 )nv::accumulate( sizes_x.begin(), sizes_x.end(), 0);249 nv::uint16 new_y = ( nv::uint16 )nv::accumulate( sizes_y.begin(), sizes_y.end(), 0);248 nv::uint16 new_x = nv::uint16( nv::accumulate( sizes_x.begin(), sizes_x.end(), 0 ) ); 249 nv::uint16 new_y = nv::uint16( nv::accumulate( sizes_y.begin(), sizes_y.end(), 0 ) ); 250 250 251 251 nv::uint8* data = new nv::uint8[ new_x * new_y ]; … … 274 274 static int nlua_map_tile_raw_get( lua_State* L ) 275 275 { 276 map_tile* tile = (map_tile*)lua_touserdata( L, 1);276 map_tile* tile = reinterpret_cast<map_tile*>( lua_touserdata( L, 1 ) ); 277 277 if ( lua_type( L, 2 ) == LUA_TNUMBER ) 278 278 { … … 289 289 static int nlua_map_tile_raw_set( lua_State* L ) 290 290 { 291 map_tile* tile = (map_tile*)lua_touserdata( L, 1);291 map_tile* tile = reinterpret_cast<map_tile*>( lua_touserdata( L, 1 ) ); 292 292 if ( lua_type( L, 2 ) == LUA_TNUMBER ) 293 293 { 294 tile->data[ ( lua_tointeger( L, 2 ) - 1 ) + ( lua_tointeger( L, 3 ) - 1 ) * tile->size_x ] = (nv::uint8)lua_tointeger( L, 3);294 tile->data[ ( lua_tointeger( L, 2 ) - 1 ) + ( lua_tointeger( L, 3 ) - 1 ) * tile->size_x ] = nv::uint8( lua_tointeger( L, 3 ) ); 295 295 } 296 296 else 297 297 { 298 298 nv::ivec2 coord = nv::lua::detail::to_coord( L, 2 ); 299 tile->data[ ( coord.x - 1 ) + ( coord.y - 1 ) * tile->size_x ] = (nv::uint8)lua_tointeger( L, 3);299 tile->data[ ( coord.x - 1 ) + ( coord.y - 1 ) * tile->size_x ] = nv::uint8( lua_tointeger( L, 3 ) ); 300 300 } 301 301 return 0; … … 304 304 static int nlua_map_tile_ascii_get( lua_State* L ) 305 305 { 306 map_tile* tile = (map_tile*)lua_touserdata( L, 1);306 map_tile* tile = reinterpret_cast<map_tile*>( lua_touserdata( L, 1 ) ); 307 307 if ( lua_type( L, 2 ) == LUA_TNUMBER ) 308 308 { … … 319 319 static int nlua_map_tile_ascii_set( lua_State* L ) 320 320 { 321 map_tile* tile = (map_tile*)lua_touserdata( L, 1);321 map_tile* tile = reinterpret_cast<map_tile*>( lua_touserdata( L, 1 ) ); 322 322 if ( lua_type( L, 2 ) == LUA_TNUMBER ) 323 323 { 324 tile->ascii[ ( lua_tointeger( L, 2 ) - 1 ) + ( lua_tointeger( L, 3 ) - 1 ) * tile->size_x ] = (nv::uint8)lua_tointeger( L, 3);324 tile->ascii[ ( lua_tointeger( L, 2 ) - 1 ) + ( lua_tointeger( L, 3 ) - 1 ) * tile->size_x ] = nv::uint8( lua_tointeger( L, 3 ) ); 325 325 } 326 326 else 327 327 { 328 328 nv::ivec2 coord = nv::lua::detail::to_coord( L, 2 ); 329 tile->ascii[ ( coord.x - 1 ) + ( coord.y - 1 ) * tile->size_x ] = (nv::uint8)lua_tointeger( L, 3);329 tile->ascii[ ( coord.x - 1 ) + ( coord.y - 1 ) * tile->size_x ] = nv::uint8( lua_tointeger( L, 3 ) ); 330 330 } 331 331 return 0; … … 334 334 static int nlua_map_tile_gc( lua_State* L ) 335 335 { 336 map_tile* tile = (map_tile*)lua_touserdata( L, 1);336 map_tile* tile = reinterpret_cast<map_tile*>( lua_touserdata( L, 1 ) ); 337 337 if ( tile != nullptr ) 338 338 { -
trunk/src/lua/lua_raw.cc
r395 r406 271 271 while ( lua_next( L, index ) != 0 ) 272 272 { 273 result.push_back( (nv::uint8) lua_tointeger( L, -1) );273 result.push_back( static_cast<nv::uint8>( lua_tointeger( L, -1 ) ) ); 274 274 lua_pop( L, 1 ); 275 275 } -
trunk/src/lua/lua_state.cc
r403 r406 258 258 { 259 259 lua_getfield( m_state, -1, element.data() ); 260 float result = lua_type( m_state, -1 ) == LUA_TNUMBER ? (float)lua_tonumber( m_state, -1) : defval;260 float result = lua_type( m_state, -1 ) == LUA_TNUMBER ? static_cast<float>( lua_tonumber( m_state, -1 ) ) : defval; 261 261 lua_pop( m_state, 1 ); 262 262 return result;
Note: See TracChangeset
for help on using the changeset viewer.