diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-08-31 11:08:27 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-08-31 11:08:27 -0300 |
commit | 100bfec39a3de3029a97e645e7fe33877d7bbc2f (patch) | |
tree | 01c2c9bb63f71d3fb186b8f5be0b7577978f8a19 /lbuiltin.c | |
parent | a290b84c670bbf0770d76429e7282c555a80058e (diff) | |
download | lua-100bfec39a3de3029a97e645e7fe33877d7bbc2f.tar.gz lua-100bfec39a3de3029a97e645e7fe33877d7bbc2f.tar.bz2 lua-100bfec39a3de3029a97e645e7fe33877d7bbc2f.zip |
new implementation for `next'
Diffstat (limited to 'lbuiltin.c')
-rw-r--r-- | lbuiltin.c | 31 |
1 files changed, 13 insertions, 18 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbuiltin.c,v 1.123 2000/08/29 14:33:31 roberto Exp roberto $ | 2 | ** $Id: lbuiltin.c,v 1.124 2000/08/29 14:41:56 roberto Exp roberto $ |
3 | ** Built-in functions | 3 | ** Built-in functions |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -267,6 +267,18 @@ int luaB_type (lua_State *L) { | |||
267 | return 1; | 267 | return 1; |
268 | } | 268 | } |
269 | 269 | ||
270 | |||
271 | int luaB_next (lua_State *L) { | ||
272 | luaL_checktype(L, 1, "table"); | ||
273 | lua_settop(L, 2); /* create a 2nd argument if there isn't one */ | ||
274 | if (lua_next(L)) | ||
275 | return 2; | ||
276 | else { | ||
277 | lua_pushnil(L); | ||
278 | return 1; | ||
279 | } | ||
280 | } | ||
281 | |||
270 | /* }====================================================== */ | 282 | /* }====================================================== */ |
271 | 283 | ||
272 | 284 | ||
@@ -355,23 +367,6 @@ int luaB_call (lua_State *L) { | |||
355 | } | 367 | } |
356 | 368 | ||
357 | 369 | ||
358 | int luaB_next (lua_State *L) { | ||
359 | const Hash *a = gettable(L, 1); | ||
360 | int i; /* `luaA_next' gets first element after `i' */ | ||
361 | if (lua_isnull(L, 2) || lua_isnil(L, 2)) /* no index or nil index? */ | ||
362 | i = 0; /* get first */ | ||
363 | else { | ||
364 | i = luaH_pos(L, a, luaA_index(L, 2))+1; | ||
365 | luaL_arg_check(L, i != 0, 2, "key not found"); | ||
366 | } | ||
367 | if (luaA_next(L, a, i) != 0) | ||
368 | return 2; /* `luaA_next' left them on the stack */ | ||
369 | else { | ||
370 | lua_pushnil(L); | ||
371 | return 1; | ||
372 | } | ||
373 | } | ||
374 | |||
375 | 370 | ||
376 | int luaB_tostring (lua_State *L) { | 371 | int luaB_tostring (lua_State *L) { |
377 | char buff[64]; | 372 | char buff[64]; |