summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-09-18 15:58:45 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-09-18 15:58:45 -0300
commit99182c6872f173e8e91426a0dba1468769818681 (patch)
treedab91ce2ee27bfd90121096f9f32404bd680b601
parent67cae2854cd2f90ff0cd91d641ab0b76417a1302 (diff)
downloadlua-99182c6872f173e8e91426a0dba1468769818681.tar.gz
lua-99182c6872f173e8e91426a0dba1468769818681.tar.bz2
lua-99182c6872f173e8e91426a0dba1468769818681.zip
references must start after predefined values in the registry
-rw-r--r--lauxlib.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/lauxlib.c b/lauxlib.c
index 41251c1b..bdbe576c 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.189 2009/07/15 17:26:14 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.190 2009/07/15 17:47:34 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*/
@@ -443,9 +443,7 @@ LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) {
443*/ 443*/
444 444
445/* number of prereserved references (for internal use) */ 445/* number of prereserved references (for internal use) */
446#define RESERVED_REFS 1 /* only FREELIST_REF is reserved */ 446#define FREELIST_REF (LUA_RIDX_LAST + 1) /* free list of references */
447
448#define FREELIST_REF 1 /* free list of references */
449 447
450 448
451LUALIB_API int luaL_ref (lua_State *L, int t) { 449LUALIB_API int luaL_ref (lua_State *L, int t) {
@@ -463,10 +461,12 @@ LUALIB_API int luaL_ref (lua_State *L, int t) {
463 lua_rawseti(L, t, FREELIST_REF); /* (t[FREELIST_REF] = t[ref]) */ 461 lua_rawseti(L, t, FREELIST_REF); /* (t[FREELIST_REF] = t[ref]) */
464 } 462 }
465 else { /* no free elements */ 463 else { /* no free elements */
466 ref = (int)lua_objlen(L, t); 464 ref = (int)lua_objlen(L, t) + 1; /* get a new reference */
467 if (ref < RESERVED_REFS) 465 if (ref == FREELIST_REF) { /* FREELIST_REF not initialized? */
468 ref = RESERVED_REFS; /* skip reserved references */ 466 lua_pushinteger(L, 0);
469 ref++; /* create new reference */ 467 lua_rawseti(L, t, FREELIST_REF);
468 ref = FREELIST_REF + 1;
469 }
470 } 470 }
471 lua_rawseti(L, t, ref); 471 lua_rawseti(L, t, ref);
472 return ref; 472 return ref;