diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-03-23 11:26:12 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-03-23 11:26:12 -0300 |
commit | 6d0ae11c576106b490a53215c3f227b65ace2776 (patch) | |
tree | fcb09763cf7f81036ed277e65dc5c967d77deef4 /ltablib.c | |
parent | 3ca739b418243544ecc1098e34c71f2378bad915 (diff) | |
download | lua-6d0ae11c576106b490a53215c3f227b65ace2776.tar.gz lua-6d0ae11c576106b490a53215c3f227b65ace2776.tar.bz2 lua-6d0ae11c576106b490a53215c3f227b65ace2776.zip |
'context' added to suspendable calls
Diffstat (limited to 'ltablib.c')
-rw-r--r-- | ltablib.c | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltablib.c,v 1.44 2008/04/07 18:43:00 roberto Exp roberto $ | 2 | ** $Id: ltablib.c,v 1.45 2009/03/10 17:14:37 roberto Exp roberto $ |
3 | ** Library for Table Manipulation | 3 | ** Library for Table Manipulation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -20,14 +20,16 @@ | |||
20 | 20 | ||
21 | 21 | ||
22 | static int foreachi (lua_State *L) { | 22 | static int foreachi (lua_State *L) { |
23 | int i; | ||
24 | int n = aux_getn(L, 1); | 23 | int n = aux_getn(L, 1); |
24 | int i; | ||
25 | if (lua_getctx(L, &i) == LUA_YIELD) goto poscall; | ||
25 | luaL_checktype(L, 2, LUA_TFUNCTION); | 26 | luaL_checktype(L, 2, LUA_TFUNCTION); |
26 | for (i=1; i <= n; i++) { | 27 | for (i = 1; i <= n; i++) { |
27 | lua_pushvalue(L, 2); /* function */ | 28 | lua_pushvalue(L, 2); /* function */ |
28 | lua_pushinteger(L, i); /* 1st argument */ | 29 | lua_pushinteger(L, i); /* 1st argument */ |
29 | lua_rawgeti(L, 1, i); /* 2nd argument */ | 30 | lua_rawgeti(L, 1, i); /* 2nd argument */ |
30 | lua_call(L, 2, 1); | 31 | lua_callk(L, 2, 1, i, foreachi); |
32 | poscall: | ||
31 | if (!lua_isnil(L, -1)) | 33 | if (!lua_isnil(L, -1)) |
32 | return 1; | 34 | return 1; |
33 | lua_pop(L, 1); /* remove nil result */ | 35 | lua_pop(L, 1); /* remove nil result */ |
@@ -46,7 +48,7 @@ static int foreachcont (lua_State *L) { | |||
46 | lua_pushvalue(L, 2); /* function */ | 48 | lua_pushvalue(L, 2); /* function */ |
47 | lua_pushvalue(L, -3); /* key */ | 49 | lua_pushvalue(L, -3); /* key */ |
48 | lua_pushvalue(L, -3); /* value */ | 50 | lua_pushvalue(L, -3); /* value */ |
49 | lua_callcont(L, 2, 1, &foreachcont); | 51 | lua_callk(L, 2, 1, 0, foreachcont); |
50 | } | 52 | } |
51 | } | 53 | } |
52 | 54 | ||