|
|
|
@ -236,10 +236,17 @@ static int luaB_next (lua_State *L) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int luaB_pairs (lua_State *L) {
|
|
|
|
|
luaL_checktype(L, 1, LUA_TTABLE);
|
|
|
|
|
lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */
|
|
|
|
|
lua_pushvalue(L, 1); /* state, */
|
|
|
|
|
lua_pushnil(L); /* and initial value */
|
|
|
|
|
luaL_checkany(L, 1);
|
|
|
|
|
if (luaL_getmetafield(L, 1, "__pairs")) {
|
|
|
|
|
lua_pushvalue(L, 1);
|
|
|
|
|
lua_call(L, 1, 3);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
luaL_checktype(L, 1, LUA_TTABLE);
|
|
|
|
|
lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */
|
|
|
|
|
lua_pushvalue(L, 1); /* state, */
|
|
|
|
|
lua_pushnil(L); /* and initial value */
|
|
|
|
|
}
|
|
|
|
|
return 3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -255,10 +262,17 @@ static int ipairsaux (lua_State *L) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int luaB_ipairs (lua_State *L) {
|
|
|
|
|
luaL_checktype(L, 1, LUA_TTABLE);
|
|
|
|
|
lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */
|
|
|
|
|
lua_pushvalue(L, 1); /* state, */
|
|
|
|
|
lua_pushinteger(L, 0); /* and initial value */
|
|
|
|
|
luaL_checkany(L, 1);
|
|
|
|
|
if (luaL_getmetafield(L, 1, "__ipairs")) {
|
|
|
|
|
lua_pushvalue(L, 1);
|
|
|
|
|
lua_call(L, 1, 3);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
luaL_checktype(L, 1, LUA_TTABLE);
|
|
|
|
|
lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */
|
|
|
|
|
lua_pushvalue(L, 1); /* state, */
|
|
|
|
|
lua_pushinteger(L, 0); /* and initial value */
|
|
|
|
|
}
|
|
|
|
|
return 3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|