summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--depends/lua/src/lbaselib.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/depends/lua/src/lbaselib.c b/depends/lua/src/lbaselib.c
index 2a4c079d..f927e563 100644
--- a/depends/lua/src/lbaselib.c
+++ b/depends/lua/src/lbaselib.c
@@ -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;
}