diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-08-03 17:21:16 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-08-03 17:21:16 -0300 |
commit | cd6c276e412227c57c36679692b93ac57bfd5562 (patch) | |
tree | f49c710d21174ea7927f145911563157f80fe204 | |
parent | fd4b4a2a68992259ffd91299f68b41de4759d8f0 (diff) | |
download | lua-cd6c276e412227c57c36679692b93ac57bfd5562.tar.gz lua-cd6c276e412227c57c36679692b93ac57bfd5562.tar.bz2 lua-cd6c276e412227c57c36679692b93ac57bfd5562.zip |
use index 0 for header of list of free references
-rw-r--r-- | lauxlib.c | 14 |
1 files changed, 7 insertions, 7 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.218 2010/07/02 12:01:53 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.219 2010/07/28 15:51:59 roberto Exp roberto $ |
3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -434,7 +434,7 @@ LUALIB_API char *luaL_buffinitsize (lua_State *L, luaL_Buffer *B, size_t sz) { | |||
434 | */ | 434 | */ |
435 | 435 | ||
436 | /* index of free-list header */ | 436 | /* index of free-list header */ |
437 | #define freelist "lua-freelist" | 437 | #define freelist 0 |
438 | 438 | ||
439 | 439 | ||
440 | LUALIB_API int luaL_ref (lua_State *L, int t) { | 440 | LUALIB_API int luaL_ref (lua_State *L, int t) { |
@@ -444,12 +444,12 @@ LUALIB_API int luaL_ref (lua_State *L, int t) { | |||
444 | lua_pop(L, 1); /* remove from stack */ | 444 | lua_pop(L, 1); /* remove from stack */ |
445 | return LUA_REFNIL; /* `nil' has a unique fixed reference */ | 445 | return LUA_REFNIL; /* `nil' has a unique fixed reference */ |
446 | } | 446 | } |
447 | lua_getfield(L, t, freelist); /* get first free element */ | 447 | lua_rawgeti(L, t, freelist); /* get first free element */ |
448 | ref = (int)lua_tointeger(L, -1); /* ref = t[FREELIST_REF] */ | 448 | ref = (int)lua_tointeger(L, -1); /* ref = t[freelist] */ |
449 | lua_pop(L, 1); /* remove it from stack */ | 449 | lua_pop(L, 1); /* remove it from stack */ |
450 | if (ref != 0) { /* any free element? */ | 450 | if (ref != 0) { /* any free element? */ |
451 | lua_rawgeti(L, t, ref); /* remove it from list */ | 451 | lua_rawgeti(L, t, ref); /* remove it from list */ |
452 | lua_setfield(L, t, freelist); /* (t[freelist] = t[ref]) */ | 452 | lua_rawseti(L, t, freelist); /* (t[freelist] = t[ref]) */ |
453 | } | 453 | } |
454 | else /* no free elements */ | 454 | else /* no free elements */ |
455 | ref = (int)lua_rawlen(L, t) + 1; /* get a new reference */ | 455 | ref = (int)lua_rawlen(L, t) + 1; /* get a new reference */ |
@@ -461,10 +461,10 @@ LUALIB_API int luaL_ref (lua_State *L, int t) { | |||
461 | LUALIB_API void luaL_unref (lua_State *L, int t, int ref) { | 461 | LUALIB_API void luaL_unref (lua_State *L, int t, int ref) { |
462 | if (ref >= 0) { | 462 | if (ref >= 0) { |
463 | t = lua_absindex(L, t); | 463 | t = lua_absindex(L, t); |
464 | lua_getfield(L, t, freelist); | 464 | lua_rawgeti(L, t, freelist); |
465 | lua_rawseti(L, t, ref); /* t[ref] = t[freelist] */ | 465 | lua_rawseti(L, t, ref); /* t[ref] = t[freelist] */ |
466 | lua_pushinteger(L, ref); | 466 | lua_pushinteger(L, ref); |
467 | lua_setfield(L, t, freelist); /* t[freelist] = ref */ | 467 | lua_rawseti(L, t, freelist); /* t[freelist] = ref */ |
468 | } | 468 | } |
469 | } | 469 | } |
470 | 470 | ||