- Timestamp:
- 03/08/16 13:19:59 (9 years ago)
- Location:
- trunk
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/lib/lua.hh
r489 r490 38 38 //#define NV_LUA_SHARED 39 39 40 #define NV_LUA_VERSION 1 41 42 40 43 #define NV_LUA_5C 0 41 44 #define NV_LUA_51 1 -
trunk/nv/lua/lua_raw.hh
r441 r490 16 16 void nlua_toflags_array( lua_State *L, int index, nv::uint8* data, nv::uint32 count ); 17 17 void nlua_toflags( lua_State *L, int index, nv::uint8* data, nv::uint32 count ); 18 19 inline int nlua_absindex( lua_State *L, int idx ) 20 { 21 return ( idx > 0 ? idx : idx + lua_gettop( L ) + 1 ); 22 }; 23 24 inline void nlua_pushunsigned( lua_State* L, unsigned u ) 25 { 26 lua_pushinteger( L, static_cast<lua_Integer>( u ) ); 27 } 28 29 inline unsigned nlua_tounsigned( lua_State* L, int index ) 30 { 31 return static_cast<lua_Unsigned>( lua_tointeger( L, index ) ); 32 } 33 18 34 19 35 inline nv::string_view nlua_tostringview( lua_State* L, int idx ) … … 45 61 void nlua_register( lua_State *L, const char* lname, const luaL_Reg *l ); 46 62 63 void * nlua_testudata( lua_State *L, int ud, const char *tname ); 64 void nlua_setmetatable( lua_State *L, const char *tname ); 65 void nlua_requiref( lua_State *L, const char *modname, lua_CFunction openf, int glb ); 66 67 int nlua_rawlen( lua_State* L, int index ); 68 void nlua_pushglobaltable( lua_State* L ); 47 69 48 70 -
trunk/src/lua/lua_area.cc
r454 r490 462 462 { 463 463 int stack = lua_gettop( L ); 464 luaL_requiref(L, "area", luaopen_area, 1);464 nlua_requiref(L, "area", luaopen_area, 1); 465 465 lua_settop( L, stack ); 466 466 } -
trunk/src/lua/lua_aux.cc
r395 r490 110 110 lua_Integer arg1 = luaL_checkinteger( L, 1 ); 111 111 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 ) ) ); 113 113 } 114 114 else … … 125 125 static int nluaaux_math_randomseed( lua_State* L ) 126 126 { 127 nv::random::get().set_seed( lua_tounsigned( L, 1 ) );127 nv::random::get().set_seed( nlua_tounsigned( L, 1 ) ); 128 128 return 0; 129 129 } -
trunk/src/lua/lua_map_area.cc
r452 r490 21 21 return map->string_to_id( lua_tostring( L, index ) ); 22 22 else 23 return lua_tounsigned( L, index );23 return nlua_tounsigned( L, index ); 24 24 } 25 25 … … 49 49 bool nv::lua::detail::is_map_area( lua_State* L, int index ) 50 50 { 51 return luaL_testudata( L, index, NLUA_MAP_AREA_METATABLE ) != 0;51 return nlua_testudata( L, index, NLUA_MAP_AREA_METATABLE ) != 0; 52 52 } 53 53 … … 151 151 { 152 152 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 ) ) ); 154 154 return 1; 155 155 } … … 158 158 { 159 159 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 ) ); 161 161 return 0; 162 162 } … … 173 173 else 174 174 { 175 lua_pushunsigned( L, ma->get_cell( to_coord( L, 2 ) ) );175 nlua_pushunsigned( L, ma->get_cell( to_coord( L, 2 ) ) ); 176 176 } 177 177 return 1; … … 181 181 { 182 182 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 ) ); 184 184 return 0; 185 185 } -
trunk/src/lua/lua_map_tile.cc
r452 r490 47 47 map_tile* result = reinterpret_cast<map_tile*>( lua_newuserdata( L, sizeof(map_tile) ) ); 48 48 *result = tile; 49 luaL_setmetatable( L, NLUA_MAP_TILE_METATABLE );49 nlua_setmetatable( L, NLUA_MAP_TILE_METATABLE ); 50 50 } 51 51 -
trunk/src/lua/lua_math.cc
r487 r490 381 381 int stack = lua_gettop( L ); 382 382 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); 390 390 lua_settop( L, stack ); 391 391 } -
trunk/src/lua/lua_nova.cc
r437 r490 52 52 static bool nova_check_type_raw( lua_State * L, int iid, int ifield, int ivalue, int itype ) 53 53 { 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 ); 58 58 59 59 switch ( lua_type( L, itype ) ) … … 101 101 static void nova_apply_blueprint_values_raw( lua_State * L, int ibase, int iproto, int iset, int iid ) 102 102 { 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 ); 107 107 108 108 lua_pushnil( L ); … … 110 110 { 111 111 // 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 ); 114 114 115 115 // Base[Key] … … 202 202 static void nova_apply_blueprint_raw( lua_State * L, int ibase, int iproto, int iid ) 203 203 { 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 ); 207 207 nlua_tokeyset( L, ibase ); 208 int iset = lua_absindex( L, -1 );208 int iset = nlua_absindex( L, -1 ); 209 209 210 210 nova_apply_blueprint_values_raw( L, ibase, iproto, iset, iid ); … … 344 344 if ( lua_gettop( L ) == 1 ) lua_pushboolean( L, false ); 345 345 lua_settop( L, 2 ); 346 lua_pushglobaltable( L );346 nlua_pushglobaltable( L ); 347 347 lua_insert( L, 1 ); 348 348 lua_rawset( L, -3 ); … … 483 483 if ( lua_type( L, -1 ) == LUA_TSTRING ) 484 484 { 485 lua_pushglobaltable( L );485 nlua_pushglobaltable( L ); 486 486 lua_pushvalue( L, -2 ); 487 487 lua_rawget( L, -2 ); … … 680 680 lua_settop( L, 3 ); 681 681 682 lua_pushglobaltable( L );682 nlua_pushglobaltable( L ); 683 683 lua_pushvalue( L, 1 ); 684 684 lua_rawget( L, -2 ); … … 731 731 } 732 732 lua_settop( L, 3 ); 733 lua_pushglobaltable( L );733 nlua_pushglobaltable( L ); 734 734 735 735 lua_pushvalue( L, 1 ); … … 806 806 lua_setfield( L, LUA_REGISTRYINDEX, NV_BLUEPRINTS ); 807 807 808 luaL_requiref( L, "nova", luaopen_nova, 1 );808 nlua_requiref( L, "nova", luaopen_nova, 1 ); 809 809 lua_settop( L, stack ); 810 810 } -
trunk/src/lua/lua_path.cc
r445 r490 49 49 { 50 50 if (m_count == 0) return false; 51 if (global) lua_pushglobaltable( L );51 if (global) nlua_pushglobaltable( L ); 52 52 for ( uint32 i = 0; i < m_count; ++i ) 53 53 { … … 60 60 else 61 61 { 62 lua_pushunsigned( L, m_elements[i].value );62 nlua_pushunsigned( L, m_elements[i].value ); 63 63 } 64 64 lua_gettable( L, -2 ); -
trunk/src/lua/lua_raw.cc
r449 r490 38 38 void nlua_pushreversed( lua_State *L, int index ) 39 39 { 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 ) ); 42 42 int i = len; 43 43 lua_createtable( L, len, 0 ); … … 53 53 void nlua_shallowcopy( lua_State *L, int index ) 54 54 { 55 index = lua_absindex( L, index );55 index = nlua_absindex( L, index ); 56 56 lua_createtable( L, 0, 0 ); 57 57 lua_pushnil( L ); … … 67 67 void nlua_shallowicopy( lua_State *L, int index ) 68 68 { 69 index = lua_absindex( L, index );69 index = nlua_absindex( L, index ); 70 70 lua_createtable( L, 0, 0 ); 71 71 int i = 0; … … 85 85 void nlua_shallowmerge( lua_State *L, int index ) 86 86 { 87 index = lua_absindex( L, index );87 index = nlua_absindex( L, index ); 88 88 lua_pushnil( L ); 89 89 … … 98 98 void nlua_deepcopy( lua_State *L, int index ) 99 99 { 100 index = lua_absindex( L, index );100 index = nlua_absindex( L, index ); 101 101 lua_createtable( L, 0, 0 ); 102 102 lua_pushnil( L ); … … 118 118 void nlua_toset( lua_State *L, int index ) 119 119 { 120 index = lua_absindex( L, index );120 index = nlua_absindex( L, index ); 121 121 lua_createtable( L, 0, 0 ); 122 122 int i = 0; … … 137 137 void nlua_tokeyset( lua_State *L, int index ) 138 138 { 139 index = lua_absindex( L, index );139 index = nlua_absindex( L, index ); 140 140 lua_createtable( L, 0, 0 ); 141 141 lua_pushnil( L ); … … 151 151 void nlua_register( lua_State *L, const char* fname, lua_CFunction func, int index ) 152 152 { 153 index = lua_absindex( L, index );153 index = nlua_absindex( L, index ); 154 154 lua_pushstring( L, fname ); 155 155 lua_pushcfunction( L, func ); … … 159 159 void nlua_register( lua_State *L, const luaL_Reg *l, int index ) 160 160 { 161 index = lua_absindex( L, index );161 index = nlua_absindex( L, index ); 162 162 for (; l->name != NULL; l++) 163 163 { … … 200 200 void nlua_toflags( lua_State *L, int index, nv::uint8* data, nv::uint32 count ) 201 201 { 202 index = lua_absindex( L, index );202 index = nlua_absindex( L, index ); 203 203 nv::uint32 flag; 204 204 if ( lua_istable( L, index ) ) … … 222 222 void nlua_toflags_set( lua_State *L, int index, nv::uint8* data, nv::uint32 count ) 223 223 { 224 index = lua_absindex( L, index );224 index = nlua_absindex( L, index ); 225 225 nv::uint32 flag; 226 226 if ( lua_istable( L, index ) ) … … 241 241 void nlua_toflags_array( lua_State *L, int index, nv::uint8* data, nv::uint32 count ) 242 242 { 243 index = lua_absindex( L, index );243 index = nlua_absindex( L, index ); 244 244 nv::uint32 flag; 245 245 if ( lua_istable( L, index ) ) … … 260 260 nv::vector<nv::uint8> nlua_tobytearray( lua_State *L, int index ) 261 261 { 262 index = lua_absindex( L, index );262 index = nlua_absindex( L, index ); 263 263 nv::vector<nv::uint8> result; 264 264 if ( lua_istable( L, index ) ) … … 273 273 return result; 274 274 } 275 276 void * 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 293 void 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 300 void 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 315 int nlua_rawlen( lua_State* L, int index ) 316 { 317 return lua_objlen( L, index ); 318 } 319 320 void 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 67 67 void nv::lua::state_wrapper::push_global_table() 68 68 { 69 lua_pushglobaltable( m_state );69 nlua_pushglobaltable( m_state ); 70 70 } 71 71 … … 173 173 nv::size_t lua::table_guard::get_size() 174 174 { 175 return lua_rawlen( m_state, -1 );175 return nlua_rawlen( m_state, -1 ); 176 176 } 177 177 … … 272 272 { 273 273 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; 275 275 lua_pop( m_state, 1 ); 276 276 return result; … … 288 288 { 289 289 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; 291 291 lua_pop( m_state, 1 ); 292 292 return result; … … 364 364 365 365 lua_pushcfunction(m_state, luaopen_base); 366 lua_pushliteral(m_state, LUA_TABLIBNAME);366 lua_pushliteral(m_state, ""); 367 367 lua_call(m_state, 1, 0); 368 368 … … 524 524 void lua::state::deep_pointer_copy( int index, void* obj ) 525 525 { 526 index = lua_absindex( m_state, index );526 index = nlua_absindex( m_state, index ); 527 527 lua_newtable( m_state ); 528 528 lua_pushnil( m_state ); -
trunk/src/lua/lua_values.cc
r454 r490 20 20 bool nv::lua::detail::is_userdata( lua_State *L, int index, const char* metatable ) 21 21 { 22 return luaL_testudata( L, index, metatable ) != 0;22 return nlua_testudata( L, index, metatable ) != 0; 23 23 } 24 24 25 25 void* nv::lua::detail::raw_check_userdata( lua_State *L, int index, const char* metatable ) 26 26 { 27 return luaL_testudata( L, index, metatable );27 return nlua_testudata( L, index, metatable ); 28 28 } 29 29 … … 31 31 { 32 32 void* result = lua_newuserdata(L, size); 33 luaL_setmetatable( L, metatable );33 nlua_setmetatable( L, metatable ); 34 34 return result; 35 35 } … … 47 47 void nv::lua::detail::push_unsigned( lua_State *L, lunsigned v ) 48 48 { 49 lua_pushunsigned( L, v );49 nlua_pushunsigned( L, v ); 50 50 } 51 51 … … 83 83 lunsigned nv::lua::detail::to_unsigned( lua_State *L, int index ) 84 84 { 85 return lua_tounsigned( L, index );85 return nlua_tounsigned( L, index ); 86 86 } 87 87 … … 131 131 lunsigned nv::lua::detail::to_unsigned( lua_State *L, int index, lunsigned def ) 132 132 { 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 ); 134 134 } 135 135
Note: See TracChangeset
for help on using the changeset viewer.