1
0
mirror of https://github.com/lua/lua.git synced 2025-01-28 06:03:00 +08:00

compat code should keep compatibility

This commit is contained in:
Roberto Ierusalimschy 2006-01-16 10:42:21 -02:00
parent a666752b1d
commit 73ebc5d8f6

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lauxlib.c,v 1.156 2005/10/21 13:47:42 roberto Exp roberto $ ** $Id: lauxlib.c,v 1.157 2005/12/29 15:32:11 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
*/ */
@ -295,23 +295,33 @@ static void getsizes (lua_State *L) {
LUALIB_API void luaL_setn (lua_State *L, int t, int n) { LUALIB_API void luaL_setn (lua_State *L, int t, int n) {
t = abs_index(L, t); t = abs_index(L, t);
getsizes(L); lua_pushliteral(L, "n");
lua_pushvalue(L, t); lua_rawget(L, t);
lua_pushinteger(L, n); if (checkint(L, 1) >= 0) { /* is there a numeric field `n'? */
lua_rawset(L, -3); /* sizes[t] = n */ lua_pushliteral(L, "n"); /* use it */
lua_pop(L, 1); /* remove `sizes' */ lua_pushinteger(L, n);
lua_rawset(L, t);
}
else { /* use `sizes' */
getsizes(L);
lua_pushvalue(L, t);
lua_pushinteger(L, n);
lua_rawset(L, -3); /* sizes[t] = n */
lua_pop(L, 1); /* remove `sizes' */
}
} }
LUALIB_API int luaL_getn (lua_State *L, int t) { LUALIB_API int luaL_getn (lua_State *L, int t) {
int n; int n;
t = abs_index(L, t); t = abs_index(L, t);
getsizes(L); /* try sizes[t] */ lua_pushliteral(L, "n"); /* try t.n */
lua_rawget(L, t);
if ((n = checkint(L, 1)) >= 0) return n;
getsizes(L); /* else try sizes[t] */
lua_pushvalue(L, t); lua_pushvalue(L, t);
lua_rawget(L, -2); lua_rawget(L, -2);
if ((n = checkint(L, 2)) >= 0) return n; if ((n = checkint(L, 2)) >= 0) return n;
lua_getfield(L, t, "n"); /* else try t.n */
if ((n = checkint(L, 1)) >= 0) return n;
return (int)lua_objlen(L, t); return (int)lua_objlen(L, t);
} }