diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-06-26 16:28:44 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-06-26 16:28:44 -0300 |
commit | f67ccfbdeb9595b0549a733d229a02a7c3205ddc (patch) | |
tree | b59a5afc174ac338e23ad58dc564640324ba6b19 /lauxlib.c | |
parent | cfcf2008069fc2d5574e10303dbe4f1ea3188636 (diff) | |
download | lua-f67ccfbdeb9595b0549a733d229a02a7c3205ddc.tar.gz lua-f67ccfbdeb9595b0549a733d229a02a7c3205ddc.tar.bz2 lua-f67ccfbdeb9595b0549a733d229a02a7c3205ddc.zip |
no more `lua_getn' function
Diffstat (limited to 'lauxlib.c')
-rw-r--r-- | lauxlib.c | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.75 2002/06/18 15:19:27 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.76 2002/06/25 19:15:21 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 | */ |
@@ -272,17 +272,20 @@ LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) { | |||
272 | LUALIB_API int luaL_ref (lua_State *L, int t) { | 272 | LUALIB_API int luaL_ref (lua_State *L, int t) { |
273 | int ref; | 273 | int ref; |
274 | lua_rawgeti(L, t, 0); /* get first free element */ | 274 | lua_rawgeti(L, t, 0); /* get first free element */ |
275 | ref = (int)lua_tonumber(L, -1); | 275 | ref = (int)lua_tonumber(L, -1); /* ref = t[0] */ |
276 | lua_pop(L, 1); /* remove it from stack */ | 276 | lua_pop(L, 1); /* remove it from stack */ |
277 | if (ref != 0) { /* any free element? */ | 277 | if (ref != 0) { /* any free element? */ |
278 | lua_rawgeti(L, t, ref); /* remove it from list */ | 278 | lua_rawgeti(L, t, ref); /* remove it from list */ |
279 | lua_rawseti(L, t, 0); | 279 | lua_rawseti(L, t, 0); /* (that is, t[0] = t[ref]) */ |
280 | } | 280 | } |
281 | else { /* no free elements */ | 281 | else { /* no free elements */ |
282 | ref = lua_getn(L, t) + 1; /* use next `n' */ | ||
283 | lua_pushliteral(L, "n"); | 282 | lua_pushliteral(L, "n"); |
283 | lua_pushvalue(L, -1); | ||
284 | lua_rawget(L, t); /* get t.n */ | ||
285 | ref = (int)lua_tonumber(L, -1) + 1; /* ref = t.n + 1 */ | ||
286 | lua_pop(L, 1); /* pop t.n */ | ||
284 | lua_pushnumber(L, ref); | 287 | lua_pushnumber(L, ref); |
285 | lua_rawset(L, t); /* n = n+1 */ | 288 | lua_rawset(L, t); /* t.n = t.n + 1 */ |
286 | } | 289 | } |
287 | lua_rawseti(L, t, ref); | 290 | lua_rawseti(L, t, ref); |
288 | return ref; | 291 | return ref; |
@@ -292,9 +295,9 @@ LUALIB_API int luaL_ref (lua_State *L, int t) { | |||
292 | LUALIB_API void luaL_unref (lua_State *L, int t, int ref) { | 295 | LUALIB_API void luaL_unref (lua_State *L, int t, int ref) { |
293 | if (ref >= 0) { | 296 | if (ref >= 0) { |
294 | lua_rawgeti(L, t, 0); | 297 | lua_rawgeti(L, t, 0); |
298 | lua_rawseti(L, t, ref); /* t[ref] = t[0] */ | ||
295 | lua_pushnumber(L, ref); | 299 | lua_pushnumber(L, ref); |
296 | lua_rawseti(L, t, 0); | 300 | lua_rawseti(L, t, 0); /* t[0] = ref */ |
297 | lua_rawseti(L, t, ref); | ||
298 | } | 301 | } |
299 | } | 302 | } |
300 | 303 | ||