diff options
| author | Li Jin <dragon-fly@qq.com> | 2025-06-04 11:38:34 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2025-06-04 11:38:34 +0800 |
| commit | 548ab1d9ff5b831050f14f1355a3314a41163ad6 (patch) | |
| tree | d84b6b64b4e547070c7c43db53821b83b819ab8e /spec/outputs/destructure.lua | |
| parent | 98be64dd52df92f7fdd40bae225c279db1676cab (diff) | |
| download | yuescript-548ab1d9ff5b831050f14f1355a3314a41163ad6.tar.gz yuescript-548ab1d9ff5b831050f14f1355a3314a41163ad6.tar.bz2 yuescript-548ab1d9ff5b831050f14f1355a3314a41163ad6.zip | |
Added new syntax.
- Slice Expression.
- Reversed Indexing,.
- Range Destructuring.
- Table Range Matching.
Diffstat (limited to 'spec/outputs/destructure.lua')
| -rw-r--r-- | spec/outputs/destructure.lua | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/spec/outputs/destructure.lua b/spec/outputs/destructure.lua index 44da58b..216d921 100644 --- a/spec/outputs/destructure.lua +++ b/spec/outputs/destructure.lua | |||
| @@ -621,4 +621,94 @@ do | |||
| 621 | print(meta_field, abc, def) | 621 | print(meta_field, abc, def) |
| 622 | end | 622 | end |
| 623 | end | 623 | end |
| 624 | do | ||
| 625 | local clients = { | ||
| 626 | "VIP_Alice", | ||
| 627 | "User_Bob", | ||
| 628 | "User_Clara", | ||
| 629 | "VIP_Eva" | ||
| 630 | } | ||
| 631 | local vipStart, regulars, vipEnd = clients[1], (function() | ||
| 632 | local _accum_0 = { } | ||
| 633 | local _len_0 = 1 | ||
| 634 | local _max_0 = -2 | ||
| 635 | for _index_0 = 2, _max_0 < 0 and #clients + _max_0 + 1 or _max_0 do | ||
| 636 | local _item_0 = clients[_index_0] | ||
| 637 | _accum_0[_len_0] = _item_0 | ||
| 638 | _len_0 = _len_0 + 1 | ||
| 639 | end | ||
| 640 | return _accum_0 | ||
| 641 | end)(), clients[#clients] | ||
| 642 | print(vipStart) | ||
| 643 | print(regulars) | ||
| 644 | print(vipEnd) | ||
| 645 | end | ||
| 646 | do | ||
| 647 | local setupMeeting | ||
| 648 | setupMeeting = function(participants) | ||
| 649 | local chair, secretary = participants[1], participants[#participants] | ||
| 650 | return print(chair, secretary) | ||
| 651 | end | ||
| 652 | setupMeeting({ | ||
| 653 | "Alice", | ||
| 654 | "Bob", | ||
| 655 | "Charlie", | ||
| 656 | "David" | ||
| 657 | }) | ||
| 658 | end | ||
| 659 | do | ||
| 660 | local getTransactions | ||
| 661 | getTransactions = function() | ||
| 662 | return { | ||
| 663 | { | ||
| 664 | id = "T1", | ||
| 665 | amount = 100 | ||
| 666 | }, | ||
| 667 | { | ||
| 668 | id = "T2", | ||
| 669 | amount = 200 | ||
| 670 | }, | ||
| 671 | { | ||
| 672 | id = "T3", | ||
| 673 | amount = 300 | ||
| 674 | } | ||
| 675 | } | ||
| 676 | end | ||
| 677 | local id, amount | ||
| 678 | do | ||
| 679 | local _item_0 = getTransactions() | ||
| 680 | local _obj_0 = _item_0[#_item_0] | ||
| 681 | id, amount = _obj_0.id, _obj_0.amount | ||
| 682 | end | ||
| 683 | assert(id == "T3") | ||
| 684 | assert(amount == 300) | ||
| 685 | end | ||
| 686 | do | ||
| 687 | local middle | ||
| 688 | local _accum_0 = { } | ||
| 689 | local _len_0 = 1 | ||
| 690 | local _list_0 = tb | ||
| 691 | local _max_0 = -2 | ||
| 692 | for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 + 1 or _max_0 do | ||
| 693 | local _item_0 = _list_0[_index_0] | ||
| 694 | _accum_0[_len_0] = _item_0 | ||
| 695 | _len_0 = _len_0 + 1 | ||
| 696 | end | ||
| 697 | middle = _accum_0 | ||
| 698 | end | ||
| 699 | do | ||
| 700 | local a, abc, b, def, sub, d, e | ||
| 701 | local _obj_0 = tb | ||
| 702 | a, abc, b, def, sub, d, e = _obj_0[1], _obj_0.abc, _obj_0[2], _obj_0.def, (function() | ||
| 703 | local _accum_0 = { } | ||
| 704 | local _len_0 = 1 | ||
| 705 | local _max_0 = -3 | ||
| 706 | for _index_0 = 3, _max_0 < 0 and #_obj_0 + _max_0 + 1 or _max_0 do | ||
| 707 | local _item_0 = _obj_0[_index_0] | ||
| 708 | _accum_0[_len_0] = _item_0 | ||
| 709 | _len_0 = _len_0 + 1 | ||
| 710 | end | ||
| 711 | return _accum_0 | ||
| 712 | end)(), _obj_0[#_obj_0 - 1], _obj_0[#_obj_0] | ||
| 713 | end | ||
| 624 | return nil | 714 | return nil |
