Allow yields inside '__pairs'

This commit is contained in:
Roberto Ierusalimschy
2021-03-29 12:57:32 -03:00
parent bef250eb8d
commit bf10593a3a
2 changed files with 27 additions and 1 deletions

View File

@@ -261,6 +261,11 @@ static int luaB_next (lua_State *L) {
}
static int pairscont (lua_State *L, int status, lua_KContext k) {
(void)L; (void)status; (void)k; /* unused */
return 3;
}
static int luaB_pairs (lua_State *L) {
luaL_checkany(L, 1);
if (luaL_getmetafield(L, 1, "__pairs") == LUA_TNIL) { /* no metamethod? */
@@ -270,7 +275,7 @@ static int luaB_pairs (lua_State *L) {
}
else {
lua_pushvalue(L, 1); /* argument 'self' to metamethod */
lua_call(L, 1, 3); /* get 3 values from metamethod */
lua_callk(L, 1, 3, 0, pairscont); /* get 3 values from metamethod */
}
return 3;
}