aboutsummaryrefslogtreecommitdiff
path: root/lauxlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-10-20 16:32:55 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-10-20 16:32:55 -0200
commit97b838d9ab5621f99263b81b591c98da935c8a6c (patch)
tree63eca0cae93f86d03eead653e2968e459ee2cd03 /lauxlib.c
parentc51bcf4796d1e39bb9840825a72085c9a51ec402 (diff)
downloadlua-97b838d9ab5621f99263b81b591c98da935c8a6c.tar.gz
lua-97b838d9ab5621f99263b81b591c98da935c8a6c.tar.bz2
lua-97b838d9ab5621f99263b81b591c98da935c8a6c.zip
new semantics for setn/getn (no more changes to `n')
Diffstat (limited to 'lauxlib.c')
-rw-r--r--lauxlib.c25
1 files changed, 9 insertions, 16 deletions
diff --git a/lauxlib.c b/lauxlib.c
index 6aab9a3c..d441f4fe 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.105 2003/10/07 20:13:41 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.106 2003/10/10 12:57:55 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*/
@@ -291,30 +291,23 @@ static void getsizes (lua_State *L) {
291 291
292void luaL_setn (lua_State *L, int t, int n) { 292void luaL_setn (lua_State *L, int t, int n) {
293 t = abs_index(L, t); 293 t = abs_index(L, t);
294 lua_getfield(L, t, "n"); 294 getsizes(L);
295 if (checkint(L, 1) >= 0) { /* is there a numeric field `n'? */ 295 lua_pushvalue(L, t);
296 lua_pushinteger(L, n); 296 lua_pushinteger(L, n);
297 lua_setfield(L, t, "n"); 297 lua_rawset(L, -3); /* sizes[t] = n */
298 } 298 lua_pop(L, 1); /* remove `sizes' */
299 else { /* use `sizes' */
300 getsizes(L);
301 lua_pushvalue(L, t);
302 lua_pushinteger(L, n);
303 lua_rawset(L, -3); /* sizes[t] = n */
304 lua_pop(L, 1); /* remove `sizes' */
305 }
306} 299}
307 300
308 301
309int luaL_getn (lua_State *L, int t) { 302int luaL_getn (lua_State *L, int t) {
310 int n; 303 int n;
311 t = abs_index(L, t); 304 t = abs_index(L, t);
312 lua_getfield(L, t, "n"); /* try t.n */ 305 getsizes(L); /* try sizes[t] */
313 if ((n = checkint(L, 1)) >= 0) return n;
314 getsizes(L); /* else try sizes[t] */
315 lua_pushvalue(L, t); 306 lua_pushvalue(L, t);
316 lua_rawget(L, -2); 307 lua_rawget(L, -2);
317 if ((n = checkint(L, 2)) >= 0) return n; 308 if ((n = checkint(L, 2)) >= 0) return n;
309 lua_getfield(L, t, "n"); /* else try t.n */
310 if ((n = checkint(L, 1)) >= 0) return n;
318 for (n = 1; ; n++) { /* else must count elements */ 311 for (n = 1; ; n++) { /* else must count elements */
319 lua_rawgeti(L, t, n); 312 lua_rawgeti(L, t, n);
320 if (lua_isnil(L, -1)) break; 313 if (lua_isnil(L, -1)) break;