Changeset 490


Ignore:
Timestamp:
03/08/16 13:19:59 (9 years ago)
Author:
epyon
Message:
  • temporary Lua 5.1 hardcode
Location:
trunk
Files:
12 edited

Legend:

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

    r489 r490  
    3838//#define NV_LUA_SHARED
    3939
     40#define NV_LUA_VERSION 1
     41
     42
    4043#define NV_LUA_5C     0
    4144#define NV_LUA_51     1
  • trunk/nv/lua/lua_raw.hh

    r441 r490  
    1616void nlua_toflags_array( lua_State *L, int index, nv::uint8* data, nv::uint32 count );
    1717void nlua_toflags( lua_State *L, int index, nv::uint8* data, nv::uint32 count );
     18
     19inline int nlua_absindex( lua_State *L, int idx )
     20{
     21        return ( idx > 0 ? idx : idx + lua_gettop( L ) + 1 );
     22};
     23
     24inline void nlua_pushunsigned( lua_State* L, unsigned u )
     25{
     26        lua_pushinteger( L, static_cast<lua_Integer>( u ) );
     27}
     28
     29inline unsigned nlua_tounsigned( lua_State* L, int index )
     30{
     31        return static_cast<lua_Unsigned>( lua_tointeger( L, index ) );
     32}
     33
    1834
    1935inline nv::string_view nlua_tostringview( lua_State* L, int idx )
     
    4561void nlua_register( lua_State *L, const char* lname, const luaL_Reg *l );
    4662
     63void * nlua_testudata( lua_State *L, int ud, const char *tname );
     64void nlua_setmetatable( lua_State *L, const char *tname );
     65void nlua_requiref( lua_State *L, const char *modname, lua_CFunction openf, int glb );
     66
     67int nlua_rawlen( lua_State* L, int index );
     68void nlua_pushglobaltable( lua_State* L );
    4769
    4870
  • trunk/src/lua/lua_area.cc

    r454 r490  
    462462{
    463463        int stack = lua_gettop( L );
    464         luaL_requiref(L, "area", luaopen_area, 1);
     464        nlua_requiref(L, "area", luaopen_area, 1);
    465465        lua_settop( L, stack );
    466466}
  • trunk/src/lua/lua_aux.cc

    r395 r490  
    110110                        lua_Integer arg1 = luaL_checkinteger( L, 1 );
    111111                        if ( arg1 < 1 ) arg1 = 1;
    112                         lua_pushunsigned( L, nv::random::get().urange( 1, static_cast<nv::uint32>( arg1 ) ) );
     112                        nlua_pushunsigned( L, nv::random::get().urange( 1, static_cast<nv::uint32>( arg1 ) ) );
    113113                }
    114114                else
     
    125125static int nluaaux_math_randomseed( lua_State* L )
    126126{
    127         nv::random::get().set_seed( lua_tounsigned( L, 1 ) );
     127        nv::random::get().set_seed( nlua_tounsigned( L, 1 ) );
    128128        return 0;
    129129}
  • trunk/src/lua/lua_map_area.cc

    r452 r490  
    2121                return map->string_to_id( lua_tostring( L, index ) );
    2222        else
    23                 return lua_tounsigned( L, index );
     23                return nlua_tounsigned( L, index );
    2424}
    2525
     
    4949bool nv::lua::detail::is_map_area( lua_State* L, int index )
    5050{
    51         return luaL_testudata( L, index, NLUA_MAP_AREA_METATABLE ) != 0;
     51        return nlua_testudata( L, index, NLUA_MAP_AREA_METATABLE ) != 0;
    5252}
    5353
     
    151151{
    152152        nv::map_area* ma = to_map_area( L, 1 );
    153         lua_pushunsigned( L, ma->get_cell( to_coord( L, 2 ) ) );
     153        nlua_pushunsigned( L, ma->get_cell( to_coord( L, 2 ) ) );
    154154        return 1;
    155155}
     
    158158{
    159159        nv::map_area* ma = to_map_area( L, 1 );
    160         ma->set_cell( to_coord( L, 2 ), lua_tounsigned( L, 3 ) );
     160        ma->set_cell( to_coord( L, 2 ), nlua_tounsigned( L, 3 ) );
    161161        return 0;
    162162}
     
    173173        else
    174174        {
    175                 lua_pushunsigned( L, ma->get_cell( to_coord( L, 2 ) ) );
     175                nlua_pushunsigned( L, ma->get_cell( to_coord( L, 2 ) ) );
    176176        }
    177177        return 1;
     
    181181{
    182182        nv::map_area* ma = to_map_area( L, 1 );
    183         ma->set_cell( to_coord( L, 2 ), lua_tounsigned( L, 3 ) );
     183        ma->set_cell( to_coord( L, 2 ), nlua_tounsigned( L, 3 ) );
    184184        return 0;
    185185}
  • trunk/src/lua/lua_map_tile.cc

    r452 r490  
    4747        map_tile* result = reinterpret_cast<map_tile*>( lua_newuserdata( L, sizeof(map_tile) ) );
    4848        *result = tile;
    49         luaL_setmetatable( L, NLUA_MAP_TILE_METATABLE );
     49        nlua_setmetatable( L, NLUA_MAP_TILE_METATABLE );
    5050}
    5151
  • trunk/src/lua/lua_math.cc

    r487 r490  
    381381        int stack = lua_gettop( L );
    382382
    383         luaL_requiref(L, "coord", luaopen_vec<nv::ivec2>, 1);
    384         luaL_requiref(L, "ivec2", luaopen_vec<nv::ivec2>, 1);
    385         luaL_requiref(L, "ivec3", luaopen_vec<nv::ivec3>, 1);
    386         luaL_requiref(L, "ivec4", luaopen_vec<nv::ivec4>, 1);
    387         luaL_requiref(L, "vec2", luaopen_vec<nv::vec2>, 1);
    388         luaL_requiref(L, "vec3", luaopen_vec<nv::vec3>, 1);
    389         luaL_requiref(L, "vec4", luaopen_vec<nv::vec4>, 1);
     383        nlua_requiref(L, "coord", luaopen_vec<nv::ivec2>, 1);
     384        nlua_requiref(L, "ivec2", luaopen_vec<nv::ivec2>, 1);
     385        nlua_requiref(L, "ivec3", luaopen_vec<nv::ivec3>, 1);
     386        nlua_requiref(L, "ivec4", luaopen_vec<nv::ivec4>, 1);
     387        nlua_requiref(L, "vec2", luaopen_vec<nv::vec2>, 1);
     388        nlua_requiref(L, "vec3", luaopen_vec<nv::vec3>, 1);
     389        nlua_requiref(L, "vec4", luaopen_vec<nv::vec4>, 1);
    390390        lua_settop( L, stack );
    391391}
  • trunk/src/lua/lua_nova.cc

    r437 r490  
    5252static bool nova_check_type_raw( lua_State * L, int iid, int ifield, int ivalue, int itype )
    5353{
    54         iid    = lua_absindex( L, iid );
    55         ifield = lua_absindex( L, ifield );
    56         ivalue = lua_absindex( L, ivalue );
    57         itype  = lua_absindex( L, itype );
     54        iid    = nlua_absindex( L, iid );
     55        ifield = nlua_absindex( L, ifield );
     56        ivalue = nlua_absindex( L, ivalue );
     57        itype  = nlua_absindex( L, itype );
    5858
    5959        switch ( lua_type( L, itype ) )
     
    101101static void nova_apply_blueprint_values_raw( lua_State * L, int ibase, int iproto, int iset, int iid )
    102102{
    103         ibase  = lua_absindex( L, ibase );
    104         iproto = lua_absindex( L, iproto );
    105         iset   = lua_absindex( L, iset );
    106         iid    = lua_absindex( L, iid );
     103        ibase  = nlua_absindex( L, ibase );
     104        iproto = nlua_absindex( L, iproto );
     105        iset   = nlua_absindex( L, iset );
     106        iid    = nlua_absindex( L, iid );
    107107
    108108        lua_pushnil( L );
     
    110110        {
    111111                // Key -2, Value -1
    112                 int ikey   = lua_absindex( L, -2 );
    113                 int ivalue = lua_absindex( L, -1 );
     112                int ikey   = nlua_absindex( L, -2 );
     113                int ivalue = nlua_absindex( L, -1 );
    114114
    115115                // Base[Key]
     
    202202static void nova_apply_blueprint_raw( lua_State * L, int ibase, int iproto, int iid )
    203203{
    204         ibase    = lua_absindex( L, ibase );
    205         iproto   = lua_absindex( L, iproto );
    206         iid      = lua_absindex( L, iid );
     204        ibase    = nlua_absindex( L, ibase );
     205        iproto   = nlua_absindex( L, iproto );
     206        iid      = nlua_absindex( L, iid );
    207207        nlua_tokeyset( L, ibase );
    208         int iset = lua_absindex( L, -1 );
     208        int iset = nlua_absindex( L, -1 );
    209209
    210210        nova_apply_blueprint_values_raw( L, ibase, iproto, iset, iid );
     
    344344        if ( lua_gettop( L ) == 1 ) lua_pushboolean( L, false );
    345345        lua_settop( L, 2 );
    346         lua_pushglobaltable( L );
     346        nlua_pushglobaltable( L );
    347347        lua_insert( L, 1 );
    348348        lua_rawset( L, -3 );
     
    483483        if ( lua_type( L, -1 ) == LUA_TSTRING )
    484484        {
    485                 lua_pushglobaltable( L );
     485                nlua_pushglobaltable( L );
    486486                lua_pushvalue( L, -2 );
    487487                lua_rawget( L, -2 );
     
    680680        lua_settop( L, 3 );
    681681
    682         lua_pushglobaltable( L );
     682        nlua_pushglobaltable( L );
    683683        lua_pushvalue( L, 1 );
    684684        lua_rawget( L, -2 );
     
    731731        }
    732732        lua_settop( L, 3 );
    733         lua_pushglobaltable( L );
     733        nlua_pushglobaltable( L );
    734734
    735735        lua_pushvalue( L, 1 );
     
    806806        lua_setfield( L, LUA_REGISTRYINDEX, NV_BLUEPRINTS );
    807807
    808         luaL_requiref( L, "nova", luaopen_nova, 1 );
     808        nlua_requiref( L, "nova", luaopen_nova, 1 );
    809809        lua_settop( L, stack );
    810810}
  • trunk/src/lua/lua_path.cc

    r445 r490  
    4949{
    5050        if (m_count == 0) return false;
    51         if (global) lua_pushglobaltable( L );
     51        if (global) nlua_pushglobaltable( L );
    5252        for ( uint32 i = 0; i < m_count; ++i )
    5353        {
     
    6060                        else
    6161                        {
    62                                 lua_pushunsigned( L, m_elements[i].value );
     62                                nlua_pushunsigned( L, m_elements[i].value );
    6363                        }
    6464                        lua_gettable( L, -2 );
  • trunk/src/lua/lua_raw.cc

    r449 r490  
    3838void nlua_pushreversed( lua_State *L, int index )
    3939{
    40         index = lua_absindex( L, index );
    41         int len = static_cast<int>( lua_rawlen( L, index ) );
     40        index = nlua_absindex( L, index );
     41        int len = static_cast<int>( nlua_rawlen( L, index ) );
    4242        int i   = len;
    4343        lua_createtable( L, len, 0 );
     
    5353void nlua_shallowcopy( lua_State *L, int index )
    5454{
    55         index = lua_absindex( L, index );
     55        index = nlua_absindex( L, index );
    5656        lua_createtable( L, 0, 0 );
    5757        lua_pushnil( L );
     
    6767void nlua_shallowicopy( lua_State *L, int index )
    6868{
    69         index = lua_absindex( L, index );
     69        index = nlua_absindex( L, index );
    7070        lua_createtable( L, 0, 0 );
    7171        int i = 0;
     
    8585void nlua_shallowmerge( lua_State *L, int index )
    8686{
    87         index = lua_absindex( L, index );
     87        index = nlua_absindex( L, index );
    8888        lua_pushnil( L );
    8989
     
    9898void nlua_deepcopy( lua_State *L, int index )
    9999{
    100         index = lua_absindex( L, index );
     100        index = nlua_absindex( L, index );
    101101        lua_createtable( L, 0, 0 );
    102102        lua_pushnil( L );
     
    118118void nlua_toset( lua_State *L, int index )
    119119{
    120         index = lua_absindex( L, index );
     120        index = nlua_absindex( L, index );
    121121        lua_createtable( L, 0, 0 );
    122122        int i = 0;
     
    137137void nlua_tokeyset( lua_State *L, int index )
    138138{
    139         index = lua_absindex( L, index );
     139        index = nlua_absindex( L, index );
    140140        lua_createtable( L, 0, 0 );
    141141        lua_pushnil( L );
     
    151151void nlua_register( lua_State *L, const char* fname, lua_CFunction func, int index )
    152152{
    153         index = lua_absindex( L, index );
     153        index = nlua_absindex( L, index );
    154154        lua_pushstring( L, fname );
    155155        lua_pushcfunction( L, func );
     
    159159void nlua_register( lua_State *L, const luaL_Reg *l, int index )
    160160{
    161         index = lua_absindex( L, index );
     161        index = nlua_absindex( L, index );
    162162        for (; l->name != NULL; l++)
    163163        {
     
    200200void nlua_toflags( lua_State *L, int index, nv::uint8* data, nv::uint32 count )
    201201{
    202         index = lua_absindex( L, index );
     202        index = nlua_absindex( L, index );
    203203        nv::uint32 flag;
    204204        if ( lua_istable( L, index ) )
     
    222222void nlua_toflags_set( lua_State *L, int index, nv::uint8* data, nv::uint32 count )
    223223{
    224         index = lua_absindex( L, index );
     224        index = nlua_absindex( L, index );
    225225        nv::uint32 flag;
    226226        if ( lua_istable( L, index ) )
     
    241241void nlua_toflags_array( lua_State *L, int index, nv::uint8* data, nv::uint32 count )
    242242{
    243         index = lua_absindex( L, index );
     243        index = nlua_absindex( L, index );
    244244        nv::uint32 flag;
    245245        if ( lua_istable( L, index ) )
     
    260260nv::vector<nv::uint8> nlua_tobytearray( lua_State *L, int index )
    261261{
    262         index = lua_absindex( L, index );
     262        index = nlua_absindex( L, index );
    263263        nv::vector<nv::uint8> result;
    264264        if ( lua_istable( L, index ) )
     
    273273        return result;
    274274}
     275
     276void * nlua_testudata( lua_State *L, int ud, const char *tname )
     277{
     278        void *p = lua_touserdata( L, ud );
     279        if ( p != NULL )
     280        {
     281                if ( lua_getmetatable( L, ud ) )
     282                {
     283                        luaL_getmetatable( L, tname );
     284                        if ( !lua_rawequal( L, -1, -2 ) )
     285                                p = NULL;
     286                        lua_pop( L, 2 );
     287                        return p;
     288                }
     289        }
     290        return NULL;
     291}
     292
     293void nlua_setmetatable( lua_State *L, const char *tname )
     294{
     295        int only_works_for_51;
     296        luaL_getmetatable( L, tname );
     297        lua_setmetatable( L, -2 );
     298}
     299
     300void nlua_requiref( lua_State *L, const char *modname, lua_CFunction openf, int glb )
     301{
     302        int only_works_for_51;
     303        lua_pushcfunction( L, openf );
     304        lua_pushstring( L, modname );
     305        lua_call( L, 1, 1 );
     306        if ( glb != 0 )
     307        {
     308                lua_pushvalue( L, LUA_GLOBALSINDEX );
     309                lua_pushvalue( L, -2 );
     310                lua_setfield( L, -2, modname );
     311                lua_pop( L, 1 );
     312        }
     313}
     314
     315int nlua_rawlen( lua_State* L, int index )
     316{
     317        return lua_objlen( L, index );
     318}
     319
     320void nlua_pushglobaltable( lua_State* L )
     321{
     322        int only_works_for_51;
     323        lua_pushvalue( L, LUA_GLOBALSINDEX );
     324}
  • trunk/src/lua/lua_state.cc

    r486 r490  
    6767void nv::lua::state_wrapper::push_global_table()
    6868{
    69         lua_pushglobaltable( m_state );
     69        nlua_pushglobaltable( m_state );
    7070}
    7171
     
    173173nv::size_t lua::table_guard::get_size()
    174174{
    175         return lua_rawlen( m_state, -1 );
     175        return nlua_rawlen( m_state, -1 );
    176176}
    177177
     
    272272{
    273273        lua_getfield( m_state, -1, element.data() );
    274         char result = ( lua_type( m_state, -1 ) == LUA_TSTRING && lua_rawlen( m_state, -1 ) > 0 ) ? lua_tostring( m_state, -1 )[0] : defval;
     274        char result = ( lua_type( m_state, -1 ) == LUA_TSTRING && nlua_rawlen( m_state, -1 ) > 0 ) ? lua_tostring( m_state, -1 )[0] : defval;
    275275        lua_pop( m_state, 1 );
    276276        return result;
     
    288288{
    289289        lua_getfield( m_state, -1, element.data() );
    290         unsigned result = lua_type( m_state, -1 ) == LUA_TNUMBER ? lua_tounsigned( m_state, -1 ) : defval;
     290        unsigned result = lua_type( m_state, -1 ) == LUA_TNUMBER ? nlua_tounsigned( m_state, -1 ) : defval;
    291291        lua_pop( m_state, 1 );
    292292        return result;
     
    364364
    365365        lua_pushcfunction(m_state, luaopen_base);
    366         lua_pushliteral(m_state, LUA_TABLIBNAME);
     366        lua_pushliteral(m_state, "");
    367367        lua_call(m_state, 1, 0);
    368368
     
    524524void lua::state::deep_pointer_copy( int index, void* obj )
    525525{
    526         index = lua_absindex( m_state, index );
     526        index = nlua_absindex( m_state, index );
    527527        lua_newtable( m_state );
    528528        lua_pushnil( m_state );
  • trunk/src/lua/lua_values.cc

    r454 r490  
    2020bool nv::lua::detail::is_userdata( lua_State *L, int index, const char* metatable )
    2121{
    22         return luaL_testudata( L, index, metatable ) != 0;
     22        return nlua_testudata( L, index, metatable ) != 0;
    2323}
    2424
    2525void* nv::lua::detail::raw_check_userdata( lua_State *L, int index, const char* metatable )
    2626{
    27         return luaL_testudata( L, index, metatable );
     27        return nlua_testudata( L, index, metatable );
    2828}
    2929
     
    3131{
    3232        void* result = lua_newuserdata(L, size);
    33         luaL_setmetatable( L, metatable );
     33        nlua_setmetatable( L, metatable );
    3434        return result;
    3535}
     
    4747void nv::lua::detail::push_unsigned( lua_State *L, lunsigned v )
    4848{
    49         lua_pushunsigned( L, v );
     49        nlua_pushunsigned( L, v );
    5050}
    5151
     
    8383lunsigned   nv::lua::detail::to_unsigned( lua_State *L, int index )
    8484{
    85         return lua_tounsigned( L, index );
     85        return nlua_tounsigned( L, index );
    8686}
    8787
     
    131131lunsigned   nv::lua::detail::to_unsigned( lua_State *L, int index, lunsigned def )
    132132{
    133         return ( lua_type( L, index ) == LUA_TNUMBER ? lua_tounsigned( L, index ) : def );
     133        return ( lua_type( L, index ) == LUA_TNUMBER ? nlua_tounsigned( L, index ) : def );
    134134}
    135135
Note: See TracChangeset for help on using the changeset viewer.