| 629 | |
| 630 | template <bool make_copy> |
| 631 | static int treverse (lua_State *L) { |
| 632 | luaL_checktype(L, 1, LUA_TTABLE); |
| 633 | |
| 634 | if (make_copy) { |
| 635 | lua_settop(L, 1); |
| 636 | lua_newtable(L); |
| 637 | } |
| 638 | const lua_Unsigned l = lua_rawlen(L, 1); |
| 639 | for (lua_Unsigned i = 1; i <= l/2; ++i) { |
| 640 | lua_pushinteger(L, l - i + 1); |
| 641 | lua_pushinteger(L, i); |
| 642 | lua_rawget(L, 1); |
| 643 | lua_pushinteger(L, i); |
| 644 | lua_pushinteger(L, l - i + 1); |
| 645 | lua_rawget(L, 1); |
| 646 | lua_rawset(L, make_copy ? 2 : 1); |
| 647 | lua_rawset(L, make_copy ? 2 : 1); |
| 648 | } |
| 649 | if (make_copy && (l % 2 != 0)) { |
| 650 | /* for oddly sized tables, we need to manually copy the element in the middle */ |
| 651 | lua_pushinteger(L, l/2+1); |
| 652 | lua_pushinteger(L, l/2+1); |
| 653 | lua_rawget(L, 1); |
| 654 | lua_rawset(L, 2); |
| 655 | } |
| 656 | return 1; |
| 657 | } |
| 658 | |
| 659 | |
| 660 | TValue *index2value (lua_State *L, int idx); |
nothing calls this directly
no test coverage detected