diff options
author | Mike Pall <mike> | 2021-09-19 17:38:49 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2021-09-19 17:38:49 +0200 |
commit | c6f5ef649b645db9cf3d11d1b5c63602c49c6411 (patch) | |
tree | 4d299528ff4e77c2f9059b8e24c50755ff638d2d /src/lj_api.c | |
parent | 4e0ea654a81e68b1bcd20ddc2026ff1bc9288b84 (diff) | |
download | luajit-c6f5ef649b645db9cf3d11d1b5c63602c49c6411.tar.gz luajit-c6f5ef649b645db9cf3d11d1b5c63602c49c6411.tar.bz2 luajit-c6f5ef649b645db9cf3d11d1b5c63602c49c6411.zip |
Refactor table traversal.
Sponsored by OpenResty Inc.
Diffstat (limited to 'src/lj_api.c')
-rw-r--r-- | src/lj_api.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/lj_api.c b/src/lj_api.c index 18a7ecbc..8c60c058 100644 --- a/src/lj_api.c +++ b/src/lj_api.c | |||
@@ -893,11 +893,13 @@ LUA_API int lua_next(lua_State *L, int idx) | |||
893 | cTValue *t = index2adr(L, idx); | 893 | cTValue *t = index2adr(L, idx); |
894 | int more; | 894 | int more; |
895 | lj_checkapi(tvistab(t), "stack slot %d is not a table", idx); | 895 | lj_checkapi(tvistab(t), "stack slot %d is not a table", idx); |
896 | more = lj_tab_next(L, tabV(t), L->top-1); | 896 | more = lj_tab_next(tabV(t), L->top-1, L->top-1); |
897 | if (more) { | 897 | if (more > 0) { |
898 | incr_top(L); /* Return new key and value slot. */ | 898 | incr_top(L); /* Return new key and value slot. */ |
899 | } else { /* End of traversal. */ | 899 | } else if (!more) { /* End of traversal. */ |
900 | L->top--; /* Remove key slot. */ | 900 | L->top--; /* Remove key slot. */ |
901 | } else { | ||
902 | lj_err_msg(L, LJ_ERR_NEXTIDX); | ||
901 | } | 903 | } |
902 | return more; | 904 | return more; |
903 | } | 905 | } |