diff options
| author | Alexander Gavrilov | 2012-03-29 11:32:22 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2012-03-29 11:32:22 +0400 |
| commit | f6c6218909fd196a5bd293b7f41ceaf9c7d4267c (patch) | |
| tree | 55b83d8afe2e2c5184101c5a3792b4387292a45c /depends/lua | |
| parent | 17ff235c817048797c9e8d14c7215a6ad67de29d (diff) | |
| download | dfhack-f6c6218909fd196a5bd293b7f41ceaf9c7d4267c.tar.gz dfhack-f6c6218909fd196a5bd293b7f41ceaf9c7d4267c.tar.bz2 dfhack-f6c6218909fd196a5bd293b7f41ceaf9c7d4267c.tar.xz | |
Temporary tweak: patch in __pairs and __ipairs from 5.2 into lua 5.1.
Diffstat (limited to 'depends/lua')
| -rw-r--r-- | depends/lua/src/lbaselib.c | 30 |
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; } |
