Changeset 406 for trunk/src/lua


Ignore:
Timestamp:
06/20/15 00:05:17 (10 years ago)
Author:
epyon
Message:
  • code compiles cleanly on maximum warning level
Location:
trunk/src/lua
Files:
7 edited

Legend:

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

    r395 r406  
    55// For conditions of distribution and use, see copying.txt file in root folder.
    66
    7 #include <nv/lua/lua_function.hh>
     7#include "nv/lua/lua_function.hh"
    88
    9 #include <nv/lua/lua_raw.hh>
     9#include "nv/core/logging.hh"
     10#include "nv/lua/lua_raw.hh"
    1011
    1112using namespace nv;
     13
     14#define NV_LUA_ABORT( func, ... ) \
     15        NV_LOG_CRITICAL( "lua::" func " : ", __VA_ARGS__ ) \
     16        NV_ABORT( "lua::" func " : critical error!" )
    1217
    1318lua::function_base::function_base( lua_State* a_L, const path& a_path, bool a_global /*= true*/ ) : L(a_L)
     
    1621        {
    1722                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() );
    1924        }
    2025
     
    2227        {
    2328                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() );
    2530        }
    2631        m_ref = luaL_ref( L, LUA_REGISTRYINDEX );
     
    6166                std::string error = lua_tostring( L, -1 );
    6267                lua_pop( L, 1 );
    63                 throw std::runtime_error(error.c_str());
     68                NV_LUA_ABORT( "function_base::call", "call failed - ", error.c_str() );
    6469        }
    6570}
  • trunk/src/lua/lua_glm.cc

    r397 r406  
    1111#include "nv/stl/type_traits/common.hh"
    1212
    13 static size_t nlua_swizzel_lookup[256];
     13static int nlua_swizzel_lookup[256];
    1414
    1515using nv::lua::detail::is_vec;
     
    1818using nv::lua::detail::push_vec;
    1919
    20 inline bool nlua_is_swizzel( const unsigned char* str, size_t max )
     20inline bool nlua_is_swizzel( const unsigned char* str, int max )
    2121{
    2222        while (*str)
     
    155155{
    156156        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 ) );
    158158        else
    159159                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 )) );
    161161                else
    162162                        push_vec<T>( L, to_vec<T>( L, 1 ) + to_vec<T>( L, 2 ) );
     
    168168{
    169169        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 ) );
    171171        else
    172172                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 )) );
    174174                else
    175175                        push_vec<T>( L, to_vec<T>( L, 1 ) - to_vec<T>( L, 2 ) );
     
    181181{
    182182        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 ) );
    184184        else
    185185                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 )) );
    187187                else
    188188                        push_vec<T>( L, to_vec<T>( L, 1 ) * to_vec<T>( L, 2 ) );
     
    194194{
    195195        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 ) );
    197197        else
    198198                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 )) );
    200200                else
    201201                        push_vec<T>( L, to_vec<T>( L, 1 ) / to_vec<T>( L, 2 ) );
     
    226226        T* v = to_pvec<T>( L, 1 );
    227227        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;
    231231
    232232        if ( len == 1 )
     
    264264        T* v = to_pvec<T>( L, 1 );
    265265        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;
    269269        if( len == 1 )
    270270        {
     
    272272                if ( idx < vlen )
    273273                {
    274                         (*v)[idx] = (typename T::value_type)luaL_checknumber( L, 3 );
     274                        (*v)[idx] = static_cast<typename T::value_type>( luaL_checknumber( L, 3 ) );
    275275                        return 0;
    276276                }
     
    279279        {
    280280                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;
    284284                default: break;
    285285                }
  • trunk/src/lua/lua_handle.cc

    r395 r406  
    1616        NV_LUA_STACK_ASSERT( L, +1 );
    1717        lua_rawgeti( L, LUA_REGISTRYINDEX, pseudoindex ); // table
    18         lua_rawgeti( L, -1, (int)index );                 // table, entry
     18        lua_rawgeti( L, -1, int( index ) );                 // table, entry
    1919        if ( !lua_istable( L, -1 ) )
    2020        {
     
    5858        lua_rawgeti( L, LUA_REGISTRYINDEX, pseudoindex );
    5959        lua_insert( L, -2 );
    60         lua_rawseti( L, -2, (int)index );
     60        lua_rawseti( L, -2, int( index ) );
    6161        lua_pop( L, 1 );
    6262}
     
    6767        lua_rawgeti( L, LUA_REGISTRYINDEX, pseudoindex ); // table
    6868        lua_pushinteger( L, 0 );
    69         lua_rawseti( L, -2, (int)index );
     69        lua_rawseti( L, -2, int( index ) );
    7070        lua_pop( L, 1 );
    7171}
  • trunk/src/lua/lua_map_area.cc

    r395 r406  
    6767        else
    6868        {
    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 ) );
    7070        }
    7171        return o;
     
    8888void nv::lua::detail::push_map_area( lua_State* L, nv::map_area* c )
    8989{
    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*) ) );
    9191        *pm = c;
    9292        luaL_getmetatable( L, NLUA_MAP_AREA_METATABLE );
     
    237237        lua_rawgeti( L, LUA_REGISTRYINDEX, object_index.get() );
    238238        lua_pushliteral( L, "__map_area_ptr" );
    239         lua_pushlightuserdata( L, (map_area*)area );
     239        lua_pushlightuserdata( L, area );
    240240        lua_rawset( L, -3 );
    241241        lua_pop( L, 1 );
  • trunk/src/lua/lua_map_tile.cc

    r395 r406  
    4040static map_tile* nlua_to_pmap_tile( lua_State* L, int index )
    4141{
    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 ) );
    4343}
    4444
    4545static void nlua_push_map_tile( lua_State* L, const map_tile& tile )
    4646{
    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) ) );
    4848        *result = tile;
    4949        luaL_setmetatable( L, NLUA_MAP_TILE_METATABLE );
     
    6565        map_tile tile;
    6666
    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' ) );
    6969        if ( tile.size_x == 0 )
    7070        {
    71                 tile.size_x = (nv::uint16)code.length();
     71                tile.size_x = nv::uint16( code.length() );
    7272        }
    7373        tile.data  = new nv::uint8[ tile.size_x * tile.size_y ];
     
    8585                        if ( lua_isstring( L, -2 ) && lua_objlen( L, -2 ) == 1 )
    8686                        {
    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 ) ) );
    8888                        }
    8989                        // removes 'value'; keeps 'key' for next iteration */
     
    9595                for ( nv::uint16 row = 0; row < tile.size_y; row++ )
    9696                {
    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 ] );
    9898                        // TODO: check for errors
    9999                        tile.data[ row * tile.size_x + line ] = translation[ gylph ];
     
    108108{
    109109        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 ) ) );
    111111        new_tile->size_x = old_tile->size_x;
    112112        new_tile->size_y = old_tile->size_y;
     
    246246        nv::uint16 org_x = tile->size_x;
    247247        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 ) );
    250250
    251251        nv::uint8* data = new nv::uint8[ new_x * new_y ];
     
    274274static int nlua_map_tile_raw_get( lua_State* L )
    275275{
    276         map_tile* tile = (map_tile*)lua_touserdata( L, 1 );
     276        map_tile* tile = reinterpret_cast<map_tile*>( lua_touserdata( L, 1 ) );
    277277        if ( lua_type( L, 2 ) == LUA_TNUMBER )
    278278        {
     
    289289static int nlua_map_tile_raw_set( lua_State* L )
    290290{
    291         map_tile* tile = (map_tile*)lua_touserdata( L, 1 );
     291        map_tile* tile = reinterpret_cast<map_tile*>( lua_touserdata( L, 1 ) );
    292292        if ( lua_type( L, 2 ) == LUA_TNUMBER )
    293293        {
    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 ) );
    295295        }
    296296        else
    297297        {
    298298                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 ) );
    300300        }
    301301        return 0;
     
    304304static int nlua_map_tile_ascii_get( lua_State* L )
    305305{
    306         map_tile* tile = (map_tile*)lua_touserdata( L, 1 );
     306        map_tile* tile = reinterpret_cast<map_tile*>( lua_touserdata( L, 1 ) );
    307307        if ( lua_type( L, 2 ) == LUA_TNUMBER )
    308308        {
     
    319319static int nlua_map_tile_ascii_set( lua_State* L )
    320320{
    321         map_tile* tile = (map_tile*)lua_touserdata( L, 1 );
     321        map_tile* tile = reinterpret_cast<map_tile*>( lua_touserdata( L, 1 ) );
    322322        if ( lua_type( L, 2 ) == LUA_TNUMBER )
    323323        {
    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 ) );
    325325        }
    326326        else
    327327        {
    328328                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 ) );
    330330        }
    331331        return 0;
     
    334334static int nlua_map_tile_gc( lua_State* L )
    335335{
    336         map_tile* tile = (map_tile*)lua_touserdata( L, 1 );
     336        map_tile* tile = reinterpret_cast<map_tile*>( lua_touserdata( L, 1 ) );
    337337        if ( tile != nullptr )
    338338        {
  • trunk/src/lua/lua_raw.cc

    r395 r406  
    271271                while ( lua_next( L, index ) != 0 )
    272272                {
    273                         result.push_back( (nv::uint8) lua_tointeger( L, -1 ) );
     273                        result.push_back( static_cast<nv::uint8>( lua_tointeger( L, -1 ) ) );
    274274                        lua_pop( L, 1 );
    275275                }
  • trunk/src/lua/lua_state.cc

    r403 r406  
    258258{
    259259        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;
    261261        lua_pop( m_state, 1 );
    262262        return result;
Note: See TracChangeset for help on using the changeset viewer.