diff options
| author | Li Jin <dragon-fly@qq.com> | 2025-09-15 18:20:15 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2025-09-15 18:20:15 +0800 |
| commit | 55149f8864c6c3e1c1fff9268384f8302dc5488d (patch) | |
| tree | 83dcb6ce5d1eb17294ec9032e807d1ad0120d008 /spec/outputs/lists.lua | |
| parent | f7269a635e31e075c45ec9d10e4c1df5cf9f8a33 (diff) | |
| download | yuescript-55149f8864c6c3e1c1fff9268384f8302dc5488d.tar.gz yuescript-55149f8864c6c3e1c1fff9268384f8302dc5488d.tar.bz2 yuescript-55149f8864c6c3e1c1fff9268384f8302dc5488d.zip | |
Fixed issue for reversed indexing.
Diffstat (limited to 'spec/outputs/lists.lua')
| -rw-r--r-- | spec/outputs/lists.lua | 339 |
1 files changed, 337 insertions, 2 deletions
diff --git a/spec/outputs/lists.lua b/spec/outputs/lists.lua index 2ed7b95..2dd19e5 100644 --- a/spec/outputs/lists.lua +++ b/spec/outputs/lists.lua | |||
| @@ -470,8 +470,11 @@ do | |||
| 470 | end)()) | 470 | end)()) |
| 471 | end | 471 | end |
| 472 | local _anon_func_0 = function(globalTB) | 472 | local _anon_func_0 = function(globalTB) |
| 473 | local _item_0 = globalTB | 473 | local _call_0 |
| 474 | local _call_0 = _item_0[#_item_0] | 474 | do |
| 475 | local _item_0 = globalTB | ||
| 476 | _call_0 = _item_0[#_item_0] | ||
| 477 | end | ||
| 475 | return _call_0["end"](_call_0, 123) | 478 | return _call_0["end"](_call_0, 123) |
| 476 | end | 479 | end |
| 477 | local _anon_func_1 = function(a) | 480 | local _anon_func_1 = function(a) |
| @@ -522,4 +525,336 @@ do | |||
| 522 | return print(_anon_func_0(globalTB), _anon_func_1(a), _anon_func_2(x)) | 525 | return print(_anon_func_0(globalTB), _anon_func_1(a), _anon_func_2(x)) |
| 523 | end | 526 | end |
| 524 | end | 527 | end |
| 528 | do | ||
| 529 | local tb = { | ||
| 530 | 1, | ||
| 531 | 2, | ||
| 532 | 3 | ||
| 533 | } | ||
| 534 | tb[#tb] = 40 | ||
| 535 | tb[#tb - 1] = 20 | ||
| 536 | end | ||
| 537 | do | ||
| 538 | a = "x" | ||
| 539 | b = a | ||
| 540 | c = a | ||
| 541 | local lst = { } | ||
| 542 | lst[#lst] = a | ||
| 543 | lst[#lst - 1] = b | ||
| 544 | end | ||
| 545 | do | ||
| 546 | local y, z | ||
| 547 | x, y, z = 1, 2, 3 | ||
| 548 | local arr = { } | ||
| 549 | local head | ||
| 550 | arr[#arr], head = x, y | ||
| 551 | arr[#arr] = z | ||
| 552 | end | ||
| 553 | do | ||
| 554 | local triple = { | ||
| 555 | "keep", | ||
| 556 | "skip", | ||
| 557 | "tail" | ||
| 558 | } | ||
| 559 | local head, tailv = triple[1], triple[3] | ||
| 560 | local buf = { } | ||
| 561 | buf[#buf] = head | ||
| 562 | buf[#buf] = tailv | ||
| 563 | end | ||
| 564 | do | ||
| 565 | local src = { | ||
| 566 | "a", | ||
| 567 | "", | ||
| 568 | "c", | ||
| 569 | nil, | ||
| 570 | "d" | ||
| 571 | } | ||
| 572 | local collected = { } | ||
| 573 | for _index_0 = 1, #src do | ||
| 574 | local item = src[_index_0] | ||
| 575 | if item and #item > 0 then | ||
| 576 | collected[#collected] = item | ||
| 577 | end | ||
| 578 | end | ||
| 579 | end | ||
| 580 | do | ||
| 581 | local nums = { | ||
| 582 | 1, | ||
| 583 | 2, | ||
| 584 | 3, | ||
| 585 | 4, | ||
| 586 | 5 | ||
| 587 | } | ||
| 588 | local last_two | ||
| 589 | do | ||
| 590 | local _accum_0 = { } | ||
| 591 | local _len_0 = 1 | ||
| 592 | for _index_0 = 1, #nums do | ||
| 593 | local v = nums[_index_0] | ||
| 594 | if v > 3 then | ||
| 595 | _accum_0[_len_0] = v | ||
| 596 | _len_0 = _len_0 + 1 | ||
| 597 | end | ||
| 598 | end | ||
| 599 | last_two = _accum_0 | ||
| 600 | end | ||
| 601 | nums[#nums] = last_two[1] | ||
| 602 | nums[#nums] = last_two[2] | ||
| 603 | end | ||
| 604 | do | ||
| 605 | local store = { } | ||
| 606 | store[#store] = { | ||
| 607 | meta = { | ||
| 608 | id = 1, | ||
| 609 | ok = true | ||
| 610 | }, | ||
| 611 | payload = { | ||
| 612 | 10, | ||
| 613 | 20 | ||
| 614 | } | ||
| 615 | } | ||
| 616 | store[#store] = { | ||
| 617 | meta = { | ||
| 618 | id = 1, | ||
| 619 | ok = false | ||
| 620 | }, | ||
| 621 | payload = { | ||
| 622 | 10, | ||
| 623 | 20, | ||
| 624 | 30 | ||
| 625 | } | ||
| 626 | } | ||
| 627 | end | ||
| 628 | local _anon_func_3 = function(tb) | ||
| 629 | local _item_0 = tb.tmp | ||
| 630 | return _item_0[#_item_0] | ||
| 631 | end | ||
| 632 | do | ||
| 633 | local f | ||
| 634 | f = function() | ||
| 635 | local q = { } | ||
| 636 | do | ||
| 637 | local _accum_0 = { } | ||
| 638 | local _len_0 = 1 | ||
| 639 | for n = 1, 4 do | ||
| 640 | _accum_0[_len_0] = n | ||
| 641 | _len_0 = _len_0 + 1 | ||
| 642 | end | ||
| 643 | tb.tmp = _accum_0 | ||
| 644 | end | ||
| 645 | if #tb.tmp >= 3 then | ||
| 646 | q[#q] = { | ||
| 647 | head = tb.tmp[1], | ||
| 648 | tail = _anon_func_3(tb) | ||
| 649 | } | ||
| 650 | end | ||
| 651 | end | ||
| 652 | end | ||
| 653 | do | ||
| 654 | local make_pair | ||
| 655 | make_pair = function(a, b) | ||
| 656 | return { | ||
| 657 | a, | ||
| 658 | b | ||
| 659 | } | ||
| 660 | end | ||
| 661 | local pairs = { } | ||
| 662 | local p1 = make_pair(7, 8) | ||
| 663 | pairs[#pairs] = p1 | ||
| 664 | local k, v = "key", 42 | ||
| 665 | pairs[#pairs] = { | ||
| 666 | k = k, | ||
| 667 | v = v | ||
| 668 | } | ||
| 669 | end | ||
| 670 | do | ||
| 671 | local cfg = { | ||
| 672 | mode = "safe", | ||
| 673 | tags = { } | ||
| 674 | } | ||
| 675 | if cfg.mode == "safe" then | ||
| 676 | cfg.mode = "fast" | ||
| 677 | local _obj_0 = cfg.tags | ||
| 678 | _obj_0[#_obj_0] = "newbie" | ||
| 679 | end | ||
| 680 | end | ||
| 681 | do | ||
| 682 | local mat = { | ||
| 683 | { | ||
| 684 | 1, | ||
| 685 | 2 | ||
| 686 | }, | ||
| 687 | { | ||
| 688 | 3, | ||
| 689 | 4 | ||
| 690 | }, | ||
| 691 | { | ||
| 692 | 5, | ||
| 693 | 6 | ||
| 694 | } | ||
| 695 | } | ||
| 696 | local last_row = mat[#mat] | ||
| 697 | local rows = { } | ||
| 698 | rows[#rows] = last_row[1] | ||
| 699 | end | ||
| 700 | do | ||
| 701 | local kv = { } | ||
| 702 | kv[#kv] = { | ||
| 703 | k = "a", | ||
| 704 | v = 1 | ||
| 705 | } | ||
| 706 | kv[#kv] = { | ||
| 707 | k = "b", | ||
| 708 | v = 2 | ||
| 709 | } | ||
| 710 | local pair_last = kv[#kv] | ||
| 711 | local dict = { } | ||
| 712 | dict[pair_last.k] = pair_last.v | ||
| 713 | dict[pair_last.k] = 3 | ||
| 714 | end | ||
| 715 | do | ||
| 716 | local base | ||
| 717 | do | ||
| 718 | local _accum_0 = { } | ||
| 719 | local _len_0 = 1 | ||
| 720 | for i = 1, 4 do | ||
| 721 | _accum_0[_len_0] = i | ||
| 722 | _len_0 = _len_0 + 1 | ||
| 723 | end | ||
| 724 | base = _accum_0 | ||
| 725 | end | ||
| 726 | local pack = { } | ||
| 727 | pack[#pack] = { | ||
| 728 | base[1], | ||
| 729 | base[#base] | ||
| 730 | } | ||
| 731 | pack[#pack] = { | ||
| 732 | first = base[1], | ||
| 733 | last = base[#base] | ||
| 734 | } | ||
| 735 | end | ||
| 736 | do | ||
| 737 | local opts = { | ||
| 738 | limit = 10 | ||
| 739 | } | ||
| 740 | local limit, offset = opts.limit, opts.offset | ||
| 741 | if offset == nil then | ||
| 742 | offset = 0 | ||
| 743 | end | ||
| 744 | local pages = { } | ||
| 745 | pages[#pages] = { | ||
| 746 | limit = limit, | ||
| 747 | offset = offset | ||
| 748 | } | ||
| 749 | end | ||
| 750 | do | ||
| 751 | local chain = { | ||
| 752 | a = { | ||
| 753 | b = { | ||
| 754 | c = 0 | ||
| 755 | } | ||
| 756 | }, | ||
| 757 | list = { | ||
| 758 | { | ||
| 759 | x = 0 | ||
| 760 | }, | ||
| 761 | { | ||
| 762 | x = 0 | ||
| 763 | } | ||
| 764 | } | ||
| 765 | } | ||
| 766 | chain.a.b.c = 1 | ||
| 767 | chain.list[1].x = 10; | ||
| 768 | ((function() | ||
| 769 | local _item_0 = chain.list | ||
| 770 | return _item_0[#_item_0] | ||
| 771 | end)()).x = 20 | ||
| 772 | local _obj_0 = chain.list | ||
| 773 | _obj_0[#_obj_0 - 1] = { | ||
| 774 | x = 30 | ||
| 775 | } | ||
| 776 | end | ||
| 777 | do | ||
| 778 | local node = { | ||
| 779 | left = { | ||
| 780 | v = 0 | ||
| 781 | }, | ||
| 782 | right = { | ||
| 783 | v = 0 | ||
| 784 | } | ||
| 785 | } | ||
| 786 | local bag = { } | ||
| 787 | local left, right = node.left, node.right | ||
| 788 | bag[#bag], left.v, right.v = "k", 1, 2 | ||
| 789 | end | ||
| 790 | do | ||
| 791 | local a1, a2, a3 = 100, 200, 300 | ||
| 792 | local mix = { } | ||
| 793 | local meta | ||
| 794 | mix[#mix], mix[#mix], meta = a1, a2, { | ||
| 795 | tag = "ok" | ||
| 796 | } | ||
| 797 | end | ||
| 798 | do | ||
| 799 | local cfg2 = { | ||
| 800 | limit = 5, | ||
| 801 | opts = { | ||
| 802 | flag = false | ||
| 803 | } | ||
| 804 | } | ||
| 805 | local lim, opt2 = cfg2.limit, cfg2.opts | ||
| 806 | local bucket = { | ||
| 807 | xs = { } | ||
| 808 | } | ||
| 809 | local _obj_0 = bucket.xs | ||
| 810 | _obj_0[#_obj_0] = lim | ||
| 811 | bucket.flag = true | ||
| 812 | local _obj_1 = opt2.flags | ||
| 813 | _obj_1[#_obj_1 + 1] = 123 | ||
| 814 | end | ||
| 815 | do | ||
| 816 | local ret2 | ||
| 817 | ret2 = function() | ||
| 818 | return 7, 8 | ||
| 819 | end | ||
| 820 | local box = { } | ||
| 821 | local x1 | ||
| 822 | box[#box], x1 = ret2() | ||
| 823 | end | ||
| 824 | do | ||
| 825 | local q = { | ||
| 826 | 1, | ||
| 827 | 2 | ||
| 828 | } | ||
| 829 | local lastq = q[#q] | ||
| 830 | q[#q - 1] = lastq * 10 | ||
| 831 | end | ||
| 832 | do | ||
| 833 | local mat2 = [[9,8], [7,6]] | ||
| 834 | local t = { | ||
| 835 | hold = nil | ||
| 836 | } | ||
| 837 | t.hold = mat2[#mat2][1] | ||
| 838 | end | ||
| 839 | do | ||
| 840 | local f | ||
| 841 | f = function() | ||
| 842 | local _obj_0 | ||
| 843 | do | ||
| 844 | local _item_0 = globalTB | ||
| 845 | _obj_0 = _item_0[#_item_0] | ||
| 846 | end | ||
| 847 | _obj_0[#_obj_0] = 1 | ||
| 848 | end | ||
| 849 | local f1 | ||
| 850 | f1 = function() | ||
| 851 | do | ||
| 852 | local _item_0 = globalTB | ||
| 853 | do | ||
| 854 | local _item_1 = _item_0[#_item_0] | ||
| 855 | return _item_1[#_item_1 - 1] | ||
| 856 | end | ||
| 857 | end | ||
| 858 | end | ||
| 859 | end | ||
| 525 | return nil | 860 | return nil |
