/////////////////////////////////////////////////////////////////////
| 606 | |
| 607 | ////////////////////////////////////////////////////////////////////////// |
| 608 | bool CScriptTable::MoveNext(Iterator& iter) |
| 609 | { |
| 610 | if (!iter.internal.nStackMarker1) |
| 611 | return false; |
| 612 | |
| 613 | int nTop; |
| 614 | if (iter.internal.nStackMarker2) |
| 615 | nTop = iter.internal.nStackMarker2 - 1; // already traversing the prototype table |
| 616 | else |
| 617 | nTop = iter.internal.nStackMarker1 - 1; // still traversing our own table |
| 618 | |
| 619 | //leave only the index into the stack |
| 620 | while ((lua_gettop(L) - (nTop + 1)) > 1) |
| 621 | { |
| 622 | lua_pop(L, 1); |
| 623 | } |
| 624 | bool bResult = lua_next(L, nTop + 1) != 0; |
| 625 | if (bResult) |
| 626 | { |
| 627 | iter.value.Clear(); |
| 628 | bResult = m_pSS->PopAny(iter.value); |
| 629 | // Get current key. |
| 630 | m_pSS->ToAny(iter.key, -1); |
| 631 | if (lua_type(L, -1) == LUA_TSTRING) |
| 632 | { |
| 633 | // String key. |
| 634 | iter.sKey = (const char*)lua_tostring(L, -1); |
| 635 | iter.nKey = -1; |
| 636 | } |
| 637 | else if (lua_type(L, -1) == LUA_TNUMBER) |
| 638 | { |
| 639 | // Number key. |
| 640 | iter.sKey = NULL; |
| 641 | iter.nKey = (int)lua_tonumber(L, -1); |
| 642 | } |
| 643 | else |
| 644 | { |
| 645 | iter.sKey = 0; |
| 646 | iter.nKey = -1; |
| 647 | } |
| 648 | } |
| 649 | if (!bResult) |
| 650 | { |
| 651 | if (iter.internal.nStackMarker1 && !iter.internal.nStackMarker2) |
| 652 | { |
| 653 | // just finished traversing our own table |
| 654 | // => now see if we have a prototype table attached by inspecting our potential metatable |
| 655 | // => if we don't have a metatable, or have a metatable but no prototype table attached, finish the whole iteration |
| 656 | |
| 657 | if (iter.internal.resolvePrototypeTableAsWell) |
| 658 | { |
| 659 | if (lua_getmetatable(L, -1)) |
| 660 | { |
| 661 | // yep, we have a metatable |
| 662 | lua_pushstring(L, "__index"); |
| 663 | lua_rawget(L, -2); |
| 664 | if (lua_type(L, -1) == LUA_TTABLE) |
| 665 | { |
no test coverage detected