mirror of
https://github.com/lua/lua
synced 2025-03-25 15:12:51 +03:00
references must start after predefined values in the registry
This commit is contained in:
parent
67cae2854c
commit
99182c6872
16
lauxlib.c
16
lauxlib.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lauxlib.c,v 1.189 2009/07/15 17:26:14 roberto Exp roberto $
|
** $Id: lauxlib.c,v 1.190 2009/07/15 17:47:34 roberto Exp roberto $
|
||||||
** Auxiliary functions for building Lua libraries
|
** Auxiliary functions for building Lua libraries
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -443,9 +443,7 @@ LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* number of prereserved references (for internal use) */
|
/* number of prereserved references (for internal use) */
|
||||||
#define RESERVED_REFS 1 /* only FREELIST_REF is reserved */
|
#define FREELIST_REF (LUA_RIDX_LAST + 1) /* free list of references */
|
||||||
|
|
||||||
#define FREELIST_REF 1 /* free list of references */
|
|
||||||
|
|
||||||
|
|
||||||
LUALIB_API int luaL_ref (lua_State *L, int t) {
|
LUALIB_API int luaL_ref (lua_State *L, int t) {
|
||||||
@ -463,10 +461,12 @@ LUALIB_API int luaL_ref (lua_State *L, int t) {
|
|||||||
lua_rawseti(L, t, FREELIST_REF); /* (t[FREELIST_REF] = t[ref]) */
|
lua_rawseti(L, t, FREELIST_REF); /* (t[FREELIST_REF] = t[ref]) */
|
||||||
}
|
}
|
||||||
else { /* no free elements */
|
else { /* no free elements */
|
||||||
ref = (int)lua_objlen(L, t);
|
ref = (int)lua_objlen(L, t) + 1; /* get a new reference */
|
||||||
if (ref < RESERVED_REFS)
|
if (ref == FREELIST_REF) { /* FREELIST_REF not initialized? */
|
||||||
ref = RESERVED_REFS; /* skip reserved references */
|
lua_pushinteger(L, 0);
|
||||||
ref++; /* create new reference */
|
lua_rawseti(L, t, FREELIST_REF);
|
||||||
|
ref = FREELIST_REF + 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
lua_rawseti(L, t, ref);
|
lua_rawseti(L, t, ref);
|
||||||
return ref;
|
return ref;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user