diff options
Diffstat (limited to 'spec/outputs/codes_from_doc.lua')
| -rw-r--r-- | spec/outputs/codes_from_doc.lua | 3916 |
1 files changed, 1972 insertions, 1944 deletions
diff --git a/spec/outputs/codes_from_doc.lua b/spec/outputs/codes_from_doc.lua index b8985e7..889105a 100644 --- a/spec/outputs/codes_from_doc.lua +++ b/spec/outputs/codes_from_doc.lua | |||
| @@ -76,6 +76,123 @@ end | |||
| 76 | local _u1f31b = "月之脚本" | 76 | local _u1f31b = "月之脚本" |
| 77 | _module_0["🌛"] = _u1f31b | 77 | _module_0["🌛"] = _u1f31b |
| 78 | return _module_0 | 78 | return _module_0 |
| 79 | local _module_0 = { } | ||
| 80 | local p, to_lua | ||
| 81 | do | ||
| 82 | local _obj_0 = require("yue") | ||
| 83 | p, to_lua = _obj_0.p, _obj_0.to_lua | ||
| 84 | end | ||
| 85 | local inventory = { | ||
| 86 | equipment = { | ||
| 87 | "sword", | ||
| 88 | "shield" | ||
| 89 | }, | ||
| 90 | items = { | ||
| 91 | { | ||
| 92 | name = "potion", | ||
| 93 | count = 10 | ||
| 94 | }, | ||
| 95 | { | ||
| 96 | name = "bread", | ||
| 97 | count = 3 | ||
| 98 | } | ||
| 99 | } | ||
| 100 | } | ||
| 101 | local map | ||
| 102 | map = function(arr, action) | ||
| 103 | local _accum_0 = { } | ||
| 104 | local _len_0 = 1 | ||
| 105 | for _index_0 = 1, #arr do | ||
| 106 | local item = arr[_index_0] | ||
| 107 | _accum_0[_len_0] = action(item) | ||
| 108 | _len_0 = _len_0 + 1 | ||
| 109 | end | ||
| 110 | return _accum_0 | ||
| 111 | end | ||
| 112 | local filter | ||
| 113 | filter = function(arr, cond) | ||
| 114 | local _accum_0 = { } | ||
| 115 | local _len_0 = 1 | ||
| 116 | for _index_0 = 1, #arr do | ||
| 117 | local item = arr[_index_0] | ||
| 118 | if cond(item) then | ||
| 119 | _accum_0[_len_0] = item | ||
| 120 | _len_0 = _len_0 + 1 | ||
| 121 | end | ||
| 122 | end | ||
| 123 | return _accum_0 | ||
| 124 | end | ||
| 125 | local reduce | ||
| 126 | reduce = function(arr, init, action) | ||
| 127 | for _index_0 = 1, #arr do | ||
| 128 | local item = arr[_index_0] | ||
| 129 | init = action(init, item) | ||
| 130 | end | ||
| 131 | return init | ||
| 132 | end | ||
| 133 | print(reduce(filter(map({ | ||
| 134 | 1, | ||
| 135 | 2, | ||
| 136 | 3 | ||
| 137 | }, function(x) | ||
| 138 | return x * 2 | ||
| 139 | end), function(x) | ||
| 140 | return x > 4 | ||
| 141 | end), 0, function(a, b) | ||
| 142 | return a + b | ||
| 143 | end)) | ||
| 144 | local apple = setmetatable({ | ||
| 145 | size = 15, | ||
| 146 | }, { | ||
| 147 | __index = { | ||
| 148 | color = 0x00ffff | ||
| 149 | } | ||
| 150 | }) | ||
| 151 | if (getmetatable(apple) ~= nil) then | ||
| 152 | p(apple.size, apple.color, getmetatable(apple).__index) | ||
| 153 | end | ||
| 154 | local _u1f31b = "月之脚本" | ||
| 155 | _module_0["🌛"] = _u1f31b | ||
| 156 | return _module_0 | ||
| 157 | local area = 6.2831853071796 * 5 | ||
| 158 | print('hello world') | ||
| 159 | do | ||
| 160 | assert(item ~= nil) | ||
| 161 | end | ||
| 162 | local value = item | ||
| 163 | if (f1() and f2() and f3()) then | ||
| 164 | print("OK") | ||
| 165 | end | ||
| 166 | do | ||
| 167 | local funcA | ||
| 168 | funcA = function() end | ||
| 169 | end | ||
| 170 | local funcA | ||
| 171 | funcA = function() | ||
| 172 | return "fail to assign to the Yue macro defined variable" | ||
| 173 | end | ||
| 174 | do | ||
| 175 | local function funcB() end | ||
| 176 | end | ||
| 177 | local funcB | ||
| 178 | funcB = function() | ||
| 179 | return "fail to assign to the Lua macro defined variable" | ||
| 180 | end | ||
| 181 | do | ||
| 182 | -- raw Lua codes insertion | ||
| 183 | if cond then | ||
| 184 | print("output") | ||
| 185 | end | ||
| 186 | end | ||
| 187 | print("yuescript") | ||
| 188 | print(2) | ||
| 189 | print("Valid enum type:", "Static") | ||
| 190 | do | ||
| 191 | print(123, "hello") | ||
| 192 | end | ||
| 193 | do | ||
| 194 | print(123, "hello") | ||
| 195 | end | ||
| 79 | local area = 6.2831853071796 * 5 | 196 | local area = 6.2831853071796 * 5 |
| 80 | print('hello world') | 197 | print('hello world') |
| 81 | do | 198 | do |
| @@ -408,6 +525,430 @@ local tb = { | |||
| 408 | } | 525 | } |
| 409 | } | 526 | } |
| 410 | } | 527 | } |
| 528 | if tb ~= nil then | ||
| 529 | tb:func() | ||
| 530 | end | ||
| 531 | if tb ~= nil then | ||
| 532 | tb:func() | ||
| 533 | end | ||
| 534 | print(1 < 2 and 2 <= 2 and 2 < 3 and 3 == 3 and 3 > 2 and 2 >= 1 and 1 == 1 and 1 < 3 and 3 ~= 5) | ||
| 535 | local a = 5 | ||
| 536 | print(1 <= a and a <= 10) | ||
| 537 | local v | ||
| 538 | v = function(x) | ||
| 539 | print(x) | ||
| 540 | return x | ||
| 541 | end | ||
| 542 | print((function() | ||
| 543 | local _cond_0 = v(2) | ||
| 544 | if not (v(1) < _cond_0) then | ||
| 545 | return false | ||
| 546 | else | ||
| 547 | return _cond_0 <= v(3) | ||
| 548 | end | ||
| 549 | end)()) | ||
| 550 | print((function() | ||
| 551 | local _cond_0 = v(2) | ||
| 552 | if not (v(1) > _cond_0) then | ||
| 553 | return false | ||
| 554 | else | ||
| 555 | return _cond_0 <= v(3) | ||
| 556 | end | ||
| 557 | end)()) | ||
| 558 | local tab = { } | ||
| 559 | tab[#tab + 1] = "Value" | ||
| 560 | local tbA = { | ||
| 561 | 1, | ||
| 562 | 2, | ||
| 563 | 3 | ||
| 564 | } | ||
| 565 | local tbB = { | ||
| 566 | 4, | ||
| 567 | 5, | ||
| 568 | 6 | ||
| 569 | } | ||
| 570 | local _len_0 = #tbA + 1 | ||
| 571 | for _index_0 = 1, #tbB do | ||
| 572 | local _elm_0 = tbB[_index_0] | ||
| 573 | tbA[_len_0], _len_0 = _elm_0, _len_0 + 1 | ||
| 574 | end | ||
| 575 | local parts = { | ||
| 576 | "shoulders", | ||
| 577 | "knees" | ||
| 578 | } | ||
| 579 | local lyrics | ||
| 580 | do | ||
| 581 | local _tab_0 = { | ||
| 582 | "head" | ||
| 583 | } | ||
| 584 | local _idx_0 = 1 | ||
| 585 | for _key_0, _value_0 in pairs(parts) do | ||
| 586 | if _idx_0 == _key_0 then | ||
| 587 | _tab_0[#_tab_0 + 1] = _value_0 | ||
| 588 | _idx_0 = _idx_0 + 1 | ||
| 589 | else | ||
| 590 | _tab_0[_key_0] = _value_0 | ||
| 591 | end | ||
| 592 | end | ||
| 593 | _tab_0[#_tab_0 + 1] = "and" | ||
| 594 | _tab_0[#_tab_0 + 1] = "toes" | ||
| 595 | lyrics = _tab_0 | ||
| 596 | end | ||
| 597 | local copy | ||
| 598 | do | ||
| 599 | local _tab_0 = { } | ||
| 600 | local _idx_0 = 1 | ||
| 601 | for _key_0, _value_0 in pairs(other) do | ||
| 602 | if _idx_0 == _key_0 then | ||
| 603 | _tab_0[#_tab_0 + 1] = _value_0 | ||
| 604 | _idx_0 = _idx_0 + 1 | ||
| 605 | else | ||
| 606 | _tab_0[_key_0] = _value_0 | ||
| 607 | end | ||
| 608 | end | ||
| 609 | copy = _tab_0 | ||
| 610 | end | ||
| 611 | local a = { | ||
| 612 | 1, | ||
| 613 | 2, | ||
| 614 | 3, | ||
| 615 | x = 1 | ||
| 616 | } | ||
| 617 | local b = { | ||
| 618 | 4, | ||
| 619 | 5, | ||
| 620 | y = 1 | ||
| 621 | } | ||
| 622 | local merge | ||
| 623 | local _tab_0 = { } | ||
| 624 | local _idx_0 = 1 | ||
| 625 | for _key_0, _value_0 in pairs(a) do | ||
| 626 | if _idx_0 == _key_0 then | ||
| 627 | _tab_0[#_tab_0 + 1] = _value_0 | ||
| 628 | _idx_0 = _idx_0 + 1 | ||
| 629 | else | ||
| 630 | _tab_0[_key_0] = _value_0 | ||
| 631 | end | ||
| 632 | end | ||
| 633 | local _idx_1 = 1 | ||
| 634 | for _key_0, _value_0 in pairs(b) do | ||
| 635 | if _idx_1 == _key_0 then | ||
| 636 | _tab_0[#_tab_0 + 1] = _value_0 | ||
| 637 | _idx_1 = _idx_1 + 1 | ||
| 638 | else | ||
| 639 | _tab_0[_key_0] = _value_0 | ||
| 640 | end | ||
| 641 | end | ||
| 642 | merge = _tab_0 | ||
| 643 | local last | ||
| 644 | do | ||
| 645 | local _item_0 = data.items | ||
| 646 | last = _item_0[#_item_0] | ||
| 647 | end | ||
| 648 | local second_last | ||
| 649 | do | ||
| 650 | local _item_0 = data.items | ||
| 651 | second_last = _item_0[#_item_0 - 1] | ||
| 652 | end | ||
| 653 | local _obj_0 = data.items | ||
| 654 | _obj_0[#_obj_0] = 1 | ||
| 655 | local mt = { } | ||
| 656 | local add | ||
| 657 | add = function(self, right) | ||
| 658 | return setmetatable({ | ||
| 659 | value = self.value + right.value | ||
| 660 | }, mt) | ||
| 661 | end | ||
| 662 | mt.__add = add | ||
| 663 | local a = setmetatable({ | ||
| 664 | value = 1 | ||
| 665 | }, mt) | ||
| 666 | local b = setmetatable({ | ||
| 667 | value = 2 | ||
| 668 | }, { | ||
| 669 | __add = add | ||
| 670 | }) | ||
| 671 | local c = setmetatable({ | ||
| 672 | value = 3 | ||
| 673 | }, { | ||
| 674 | __add = mt.__add | ||
| 675 | }) | ||
| 676 | local d = a + b + c | ||
| 677 | print(d.value) | ||
| 678 | local _ <close> = setmetatable({ }, { | ||
| 679 | __close = function() | ||
| 680 | return print("out of scope") | ||
| 681 | end | ||
| 682 | }) | ||
| 683 | local tb = setmetatable({ }, { | ||
| 684 | ["value"] = 123 | ||
| 685 | }) | ||
| 686 | getmetatable(tb).__index = getmetatable(tb) | ||
| 687 | print(tb.value) | ||
| 688 | setmetatable(tb, { | ||
| 689 | __index = { | ||
| 690 | item = "hello" | ||
| 691 | } | ||
| 692 | }) | ||
| 693 | print(tb.item) | ||
| 694 | local item, new, close, getter | ||
| 695 | do | ||
| 696 | local _obj_0 = tb | ||
| 697 | item, new = _obj_0[1], _obj_0.new | ||
| 698 | do | ||
| 699 | local _obj_1 = getmetatable(_obj_0) | ||
| 700 | close, getter = _obj_1.__close, _obj_1.__index | ||
| 701 | end | ||
| 702 | end | ||
| 703 | print(item, new, close, getter) | ||
| 704 | do | ||
| 705 | local _obj_0 = func | ||
| 706 | if _obj_0 ~= nil then | ||
| 707 | _obj_0() | ||
| 708 | end | ||
| 709 | end | ||
| 710 | print((function() | ||
| 711 | local _obj_0 = abc | ||
| 712 | if _obj_0 ~= nil then | ||
| 713 | local _obj_1 = _obj_0["hello world"] | ||
| 714 | if _obj_1 ~= nil then | ||
| 715 | return _obj_1.xyz | ||
| 716 | end | ||
| 717 | return nil | ||
| 718 | end | ||
| 719 | return nil | ||
| 720 | end)()) | ||
| 721 | local x | ||
| 722 | do | ||
| 723 | local _obj_0 = tab | ||
| 724 | if _obj_0 ~= nil then | ||
| 725 | x = _obj_0.value | ||
| 726 | end | ||
| 727 | end | ||
| 728 | local len = (function() | ||
| 729 | local _obj_0 = utf8 | ||
| 730 | if _obj_0 ~= nil then | ||
| 731 | return _obj_0.len | ||
| 732 | end | ||
| 733 | return nil | ||
| 734 | end)() or (function() | ||
| 735 | local _obj_0 = string | ||
| 736 | if _obj_0 ~= nil then | ||
| 737 | return _obj_0.len | ||
| 738 | end | ||
| 739 | return nil | ||
| 740 | end)() or function(o) | ||
| 741 | return #o | ||
| 742 | end | ||
| 743 | if print and (x ~= nil) then | ||
| 744 | print(x) | ||
| 745 | end | ||
| 746 | local _with_0 = io.open("test.txt", "w") | ||
| 747 | if _with_0 ~= nil then | ||
| 748 | _with_0:write("hello") | ||
| 749 | _with_0:close() | ||
| 750 | end | ||
| 751 | print("hello") | ||
| 752 | print(1, 2) | ||
| 753 | print(1, 2, 3) | ||
| 754 | print(render(emit(parse(extract(readFile("example.txt"), language, { }), language)))) | ||
| 755 | local a, b, c, d | ||
| 756 | if b ~= nil then | ||
| 757 | a = b | ||
| 758 | else | ||
| 759 | if c ~= nil then | ||
| 760 | a = c | ||
| 761 | else | ||
| 762 | a = d | ||
| 763 | end | ||
| 764 | end | ||
| 765 | func((function() | ||
| 766 | if a ~= nil then | ||
| 767 | return a | ||
| 768 | else | ||
| 769 | return { } | ||
| 770 | end | ||
| 771 | end)()) | ||
| 772 | if a == nil then | ||
| 773 | a = false | ||
| 774 | end | ||
| 775 | local list = { | ||
| 776 | 1, | ||
| 777 | 2, | ||
| 778 | 3 | ||
| 779 | } | ||
| 780 | func({ | ||
| 781 | 1, | ||
| 782 | 2, | ||
| 783 | 3 | ||
| 784 | }) | ||
| 785 | local f | ||
| 786 | f = function() | ||
| 787 | return { | ||
| 788 | 1, | ||
| 789 | 2, | ||
| 790 | 3 | ||
| 791 | } | ||
| 792 | end | ||
| 793 | local tb = { | ||
| 794 | name = "abc", | ||
| 795 | values = { | ||
| 796 | "a", | ||
| 797 | "b", | ||
| 798 | "c" | ||
| 799 | }, | ||
| 800 | objects = { | ||
| 801 | { | ||
| 802 | name = "a", | ||
| 803 | value = 1, | ||
| 804 | func = function(self) | ||
| 805 | return self.value + 1 | ||
| 806 | end, | ||
| 807 | tb = { | ||
| 808 | fieldA = 1 | ||
| 809 | } | ||
| 810 | }, | ||
| 811 | { | ||
| 812 | name = "b", | ||
| 813 | value = 2, | ||
| 814 | func = function(self) | ||
| 815 | return self.value + 2 | ||
| 816 | end, | ||
| 817 | tb = { } | ||
| 818 | } | ||
| 819 | } | ||
| 820 | } | ||
| 821 | do | ||
| 822 | local insert, concat = table.insert, table.concat | ||
| 823 | local C, Ct, Cmt | ||
| 824 | do | ||
| 825 | local _obj_0 = require("lpeg") | ||
| 826 | C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt | ||
| 827 | end | ||
| 828 | local x, y, z | ||
| 829 | do | ||
| 830 | local _obj_0 = require('mymodule') | ||
| 831 | x, y, z = _obj_0.x, _obj_0.y, _obj_0.z | ||
| 832 | end | ||
| 833 | local a, b, c | ||
| 834 | local _obj_0 = require('module') | ||
| 835 | a, b, c = _obj_0.a, _obj_0.b, _obj_0.c | ||
| 836 | end | ||
| 837 | do | ||
| 838 | local module = require('module') | ||
| 839 | local module_x = require('module_x') | ||
| 840 | local d_a_s_h_e_s = require("d-a-s-h-e-s") | ||
| 841 | local part = require("module.part") | ||
| 842 | end | ||
| 843 | do | ||
| 844 | local PlayerModule = require("player") | ||
| 845 | local C, Ct, Cmt | ||
| 846 | do | ||
| 847 | local _obj_0 = require("lpeg") | ||
| 848 | C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt | ||
| 849 | end | ||
| 850 | local one, two, ch | ||
| 851 | local _obj_0 = require("export") | ||
| 852 | one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] | ||
| 853 | end | ||
| 854 | do | ||
| 855 | local tostring <const> = tostring | ||
| 856 | local concat <const> = table.concat | ||
| 857 | print(concat({ | ||
| 858 | "a", | ||
| 859 | tostring(1) | ||
| 860 | })) | ||
| 861 | end | ||
| 862 | do | ||
| 863 | local print <const> = print | ||
| 864 | local math <const> = math | ||
| 865 | print("hello") | ||
| 866 | math.random(3) | ||
| 867 | end | ||
| 868 | do | ||
| 869 | local print <const> = print | ||
| 870 | print(FLAG) | ||
| 871 | FLAG = 123 | ||
| 872 | end | ||
| 873 | local _module_0 = { } | ||
| 874 | local a, b, c = 1, 2, 3 | ||
| 875 | _module_0["a"], _module_0["b"], _module_0["c"] = a, b, c | ||
| 876 | local cool = "cat" | ||
| 877 | _module_0["cool"] = cool | ||
| 878 | local What | ||
| 879 | if this then | ||
| 880 | What = "abc" | ||
| 881 | else | ||
| 882 | What = "def" | ||
| 883 | end | ||
| 884 | _module_0["What"] = What | ||
| 885 | local y | ||
| 886 | y = function() | ||
| 887 | local hallo = 3434 | ||
| 888 | end | ||
| 889 | _module_0["y"] = y | ||
| 890 | local Something | ||
| 891 | local _class_0 | ||
| 892 | local _base_0 = { | ||
| 893 | umm = "cool" | ||
| 894 | } | ||
| 895 | if _base_0.__index == nil then | ||
| 896 | _base_0.__index = _base_0 | ||
| 897 | end | ||
| 898 | _class_0 = setmetatable({ | ||
| 899 | __init = function() end, | ||
| 900 | __base = _base_0, | ||
| 901 | __name = "Something" | ||
| 902 | }, { | ||
| 903 | __index = _base_0, | ||
| 904 | __call = function(cls, ...) | ||
| 905 | local _self_0 = setmetatable({ }, _base_0) | ||
| 906 | cls.__init(_self_0, ...) | ||
| 907 | return _self_0 | ||
| 908 | end | ||
| 909 | }) | ||
| 910 | _base_0.__class = _class_0 | ||
| 911 | Something = _class_0 | ||
| 912 | _module_0["Something"] = Something | ||
| 913 | return _module_0 | ||
| 914 | local _module_0 = { } | ||
| 915 | local loadstring, tolua | ||
| 916 | do | ||
| 917 | local _obj_0 = yue | ||
| 918 | loadstring, tolua = _obj_0.loadstring, _obj_0.to_lua | ||
| 919 | end | ||
| 920 | _module_0["loadstring"], _module_0["tolua"] = loadstring, tolua | ||
| 921 | local fieldA = tb.itemA.fieldA | ||
| 922 | if fieldA == nil then | ||
| 923 | fieldA = 'default' | ||
| 924 | end | ||
| 925 | _module_0["fieldA"] = fieldA | ||
| 926 | return _module_0 | ||
| 927 | local _module_0 = setmetatable({ }, { }) | ||
| 928 | _module_0.itemA = tb | ||
| 929 | getmetatable(_module_0).__index = items | ||
| 930 | _module_0["a-b-c"] = 123 | ||
| 931 | return _module_0 | ||
| 932 | local _module_0 = { } | ||
| 933 | local d, e, f = 3, 2, 1 | ||
| 934 | _module_0[#_module_0 + 1] = d | ||
| 935 | _module_0[#_module_0 + 1] = e | ||
| 936 | _module_0[#_module_0 + 1] = f | ||
| 937 | if this then | ||
| 938 | _module_0[#_module_0 + 1] = 123 | ||
| 939 | else | ||
| 940 | _module_0[#_module_0 + 1] = 456 | ||
| 941 | end | ||
| 942 | local _with_0 = tmp | ||
| 943 | local j = 2000 | ||
| 944 | _module_0[#_module_0 + 1] = _with_0 | ||
| 945 | return _module_0 | ||
| 946 | local _module_0 = nil | ||
| 947 | _module_0 = function() | ||
| 948 | print("hello") | ||
| 949 | return 123 | ||
| 950 | end | ||
| 951 | return _module_0 | ||
| 411 | do | 952 | do |
| 412 | local insert, concat = table.insert, table.concat | 953 | local insert, concat = table.insert, table.concat |
| 413 | local C, Ct, Cmt | 954 | local C, Ct, Cmt |
| @@ -590,6 +1131,57 @@ do | |||
| 590 | B = 2 | 1131 | B = 2 |
| 591 | local Temp = "a local value" | 1132 | local Temp = "a local value" |
| 592 | end | 1133 | end |
| 1134 | local hello = "world" | ||
| 1135 | local a, b, c = 1, 2, 3 | ||
| 1136 | hello = 123 | ||
| 1137 | local x = 1 | ||
| 1138 | x = x + 1 | ||
| 1139 | x = x - 1 | ||
| 1140 | x = x * 10 | ||
| 1141 | x = x / 10 | ||
| 1142 | x = x % 10 | ||
| 1143 | local s = s .. "world" | ||
| 1144 | local arg = arg or "default value" | ||
| 1145 | local a = 0 | ||
| 1146 | local b = 0 | ||
| 1147 | local c = 0 | ||
| 1148 | local d = 0 | ||
| 1149 | local e = 0 | ||
| 1150 | local x = f() | ||
| 1151 | local y = x | ||
| 1152 | local z = x | ||
| 1153 | do | ||
| 1154 | local a = 1 | ||
| 1155 | local x, y, z | ||
| 1156 | print("forward declare all variables as locals") | ||
| 1157 | x = function() | ||
| 1158 | return 1 + y + z | ||
| 1159 | end | ||
| 1160 | y, z = 2, 3 | ||
| 1161 | instance = Item:new() | ||
| 1162 | end | ||
| 1163 | do | ||
| 1164 | local X = 1 | ||
| 1165 | local B | ||
| 1166 | print("only forward declare upper case variables") | ||
| 1167 | local a = 1 | ||
| 1168 | B = 2 | ||
| 1169 | end | ||
| 1170 | do | ||
| 1171 | a = 1 | ||
| 1172 | print("declare all variables as globals") | ||
| 1173 | x = function() | ||
| 1174 | return 1 + y + z | ||
| 1175 | end | ||
| 1176 | y, z = 2, 3 | ||
| 1177 | end | ||
| 1178 | do | ||
| 1179 | X = 1 | ||
| 1180 | print("only declare upper case variables as globals") | ||
| 1181 | local a = 1 | ||
| 1182 | B = 2 | ||
| 1183 | local Temp = "a local value" | ||
| 1184 | end | ||
| 593 | local thing = { | 1185 | local thing = { |
| 594 | 1, | 1186 | 1, |
| 595 | 2 | 1187 | 2 |
| @@ -707,6 +1299,155 @@ for _index_0 = 1, #tuples do | |||
| 707 | local left, right = _des_0[1], _des_0[2] | 1299 | local left, right = _des_0[1], _des_0[2] |
| 708 | print(left, right) | 1300 | print(left, right) |
| 709 | end | 1301 | end |
| 1302 | local thing = { | ||
| 1303 | 1, | ||
| 1304 | 2 | ||
| 1305 | } | ||
| 1306 | local a, b = thing[1], thing[2] | ||
| 1307 | print(a, b) | ||
| 1308 | local obj = { | ||
| 1309 | hello = "world", | ||
| 1310 | day = "tuesday", | ||
| 1311 | length = 20 | ||
| 1312 | } | ||
| 1313 | local hello, the_day = obj.hello, obj.day | ||
| 1314 | print(hello, the_day) | ||
| 1315 | local day = obj.day | ||
| 1316 | local obj2 = { | ||
| 1317 | numbers = { | ||
| 1318 | 1, | ||
| 1319 | 2, | ||
| 1320 | 3, | ||
| 1321 | 4 | ||
| 1322 | }, | ||
| 1323 | properties = { | ||
| 1324 | color = "green", | ||
| 1325 | height = 13.5 | ||
| 1326 | } | ||
| 1327 | } | ||
| 1328 | local first, second = obj2.numbers[1], obj2.numbers[2] | ||
| 1329 | print(first, second, color) | ||
| 1330 | local first, second, color | ||
| 1331 | local _obj_0 = obj2 | ||
| 1332 | first, second, color = _obj_0.numbers[1], _obj_0.numbers[2], _obj_0.properties.color | ||
| 1333 | local concat, insert | ||
| 1334 | local _obj_0 = table | ||
| 1335 | concat, insert = _obj_0.concat, _obj_0.insert | ||
| 1336 | local mix, max, rand | ||
| 1337 | local _obj_0 = math | ||
| 1338 | mix, max, rand = _obj_0.mix, _obj_0.max, _obj_0.random | ||
| 1339 | local name, job | ||
| 1340 | local _obj_0 = person | ||
| 1341 | name, job = _obj_0.name, _obj_0.job | ||
| 1342 | if name == nil then | ||
| 1343 | name = "nameless" | ||
| 1344 | end | ||
| 1345 | if job == nil then | ||
| 1346 | job = "jobless" | ||
| 1347 | end | ||
| 1348 | local two, four | ||
| 1349 | local _obj_0 = items | ||
| 1350 | two, four = _obj_0[2], _obj_0[4] | ||
| 1351 | local orders = { | ||
| 1352 | "first", | ||
| 1353 | "second", | ||
| 1354 | "third", | ||
| 1355 | "fourth", | ||
| 1356 | "last" | ||
| 1357 | } | ||
| 1358 | local first, bulk, last = orders[1], (function() | ||
| 1359 | local _accum_0 = { } | ||
| 1360 | local _len_0 = 1 | ||
| 1361 | local _max_0 = #orders + -2 + 1 | ||
| 1362 | for _index_0 = 2, _max_0 do | ||
| 1363 | local _item_0 = orders[_index_0] | ||
| 1364 | _accum_0[_len_0] = _item_0 | ||
| 1365 | _len_0 = _len_0 + 1 | ||
| 1366 | end | ||
| 1367 | return _accum_0 | ||
| 1368 | end)(), orders[#orders] | ||
| 1369 | print(first) | ||
| 1370 | print(bulk) | ||
| 1371 | print(last) | ||
| 1372 | local first, rest | ||
| 1373 | do | ||
| 1374 | local _obj_0 = orders | ||
| 1375 | first, rest = _obj_0[1], (function() | ||
| 1376 | local _accum_0 = { } | ||
| 1377 | local _len_0 = 1 | ||
| 1378 | local _max_0 = #_obj_0 | ||
| 1379 | for _index_0 = 2, _max_0 do | ||
| 1380 | local _item_0 = _obj_0[_index_0] | ||
| 1381 | _accum_0[_len_0] = _item_0 | ||
| 1382 | _len_0 = _len_0 + 1 | ||
| 1383 | end | ||
| 1384 | return _accum_0 | ||
| 1385 | end)() | ||
| 1386 | end | ||
| 1387 | local start, last | ||
| 1388 | do | ||
| 1389 | local _obj_0 = orders | ||
| 1390 | start, last = (function() | ||
| 1391 | local _accum_0 = { } | ||
| 1392 | local _len_0 = 1 | ||
| 1393 | local _max_0 = #_obj_0 + -2 + 1 | ||
| 1394 | for _index_0 = 1, _max_0 do | ||
| 1395 | local _item_0 = _obj_0[_index_0] | ||
| 1396 | _accum_0[_len_0] = _item_0 | ||
| 1397 | _len_0 = _len_0 + 1 | ||
| 1398 | end | ||
| 1399 | return _accum_0 | ||
| 1400 | end)(), _obj_0[#_obj_0] | ||
| 1401 | end | ||
| 1402 | local _obj_0 = orders | ||
| 1403 | first, last = _obj_0[1], _obj_0[#_obj_0] | ||
| 1404 | local tuples = { | ||
| 1405 | { | ||
| 1406 | "hello", | ||
| 1407 | "world" | ||
| 1408 | }, | ||
| 1409 | { | ||
| 1410 | "egg", | ||
| 1411 | "head" | ||
| 1412 | } | ||
| 1413 | } | ||
| 1414 | for _index_0 = 1, #tuples do | ||
| 1415 | local _des_0 = tuples[_index_0] | ||
| 1416 | local left, right = _des_0[1], _des_0[2] | ||
| 1417 | print(left, right) | ||
| 1418 | end | ||
| 1419 | local user = database.find_user("moon") | ||
| 1420 | if user then | ||
| 1421 | print(user.name) | ||
| 1422 | end | ||
| 1423 | local hello = os.getenv("hello") | ||
| 1424 | if hello then | ||
| 1425 | print("You have hello", hello) | ||
| 1426 | else | ||
| 1427 | local world = os.getenv("world") | ||
| 1428 | if world then | ||
| 1429 | print("you have world", world) | ||
| 1430 | else | ||
| 1431 | print("nothing :(") | ||
| 1432 | end | ||
| 1433 | end | ||
| 1434 | do | ||
| 1435 | local success, result = pcall(function() | ||
| 1436 | return "get result without problems" | ||
| 1437 | end) | ||
| 1438 | if success then | ||
| 1439 | print(result) | ||
| 1440 | end | ||
| 1441 | end | ||
| 1442 | print("OK") | ||
| 1443 | repeat | ||
| 1444 | local byte = stream:read_one() | ||
| 1445 | if byte then | ||
| 1446 | print(byte) | ||
| 1447 | else | ||
| 1448 | break | ||
| 1449 | end | ||
| 1450 | until false | ||
| 710 | local user = database.find_user("moon") | 1451 | local user = database.find_user("moon") |
| 711 | if user then | 1452 | if user then |
| 712 | print(user.name) | 1453 | print(user.name) |
| @@ -756,6 +1497,31 @@ end | |||
| 756 | local first = select(1, ...) | 1497 | local first = select(1, ...) |
| 757 | return print(ok, count, first) | 1498 | return print(ok, count, first) |
| 758 | end)(fn(true)) | 1499 | end)(fn(true)) |
| 1500 | local list = { | ||
| 1501 | 1, | ||
| 1502 | 2, | ||
| 1503 | 3, | ||
| 1504 | 4, | ||
| 1505 | 5 | ||
| 1506 | } | ||
| 1507 | local fn | ||
| 1508 | fn = function(ok) | ||
| 1509 | return ok, table.unpack(list) | ||
| 1510 | end | ||
| 1511 | (function(_arg_0, ...) | ||
| 1512 | local ok = _arg_0 | ||
| 1513 | local count = select('#', ...) | ||
| 1514 | local first = select(1, ...) | ||
| 1515 | return print(ok, count, first) | ||
| 1516 | end)(fn(true)) | ||
| 1517 | local a = 1 | ||
| 1518 | local b = 2 | ||
| 1519 | print(a + b) | ||
| 1520 | Rx.Observable.fromRange(1, 8):filter(function(x) | ||
| 1521 | return x % 2 == 0 | ||
| 1522 | end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) | ||
| 1523 | return value .. '!' | ||
| 1524 | end):subscribe(print) | ||
| 759 | local a = 1 | 1525 | local a = 1 |
| 760 | local b = 2 | 1526 | local b = 2 |
| 761 | print(a + b) | 1527 | print(a + b) |
| @@ -766,6 +1532,88 @@ end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) | |||
| 766 | end):subscribe(print) | 1532 | end):subscribe(print) |
| 767 | local str = strA .. strB .. strC | 1533 | local str = strA .. strB .. strC |
| 768 | func(3000, "192.168.1.1") | 1534 | func(3000, "192.168.1.1") |
| 1535 | local str = strA .. strB .. strC | ||
| 1536 | func(3000, "192.168.1.1") | ||
| 1537 | xpcall(function() | ||
| 1538 | return func(1, 2, 3) | ||
| 1539 | end, function(err) | ||
| 1540 | return print(yue.traceback(err)) | ||
| 1541 | end) | ||
| 1542 | local success, result = xpcall(function() | ||
| 1543 | return func(1, 2, 3) | ||
| 1544 | end, function(err) | ||
| 1545 | return yue.traceback(err) | ||
| 1546 | end) | ||
| 1547 | xpcall(function() | ||
| 1548 | return func(1, 2, 3) | ||
| 1549 | end, function(err) | ||
| 1550 | return print(yue.traceback(err)) | ||
| 1551 | end) | ||
| 1552 | success, result = pcall(function() | ||
| 1553 | return func(1, 2, 3) | ||
| 1554 | end) | ||
| 1555 | pcall(function() | ||
| 1556 | print("trying") | ||
| 1557 | return func(1, 2, 3) | ||
| 1558 | end) | ||
| 1559 | success, result = xpcall(function() | ||
| 1560 | return func(1, 2, 3) | ||
| 1561 | end, function(err) | ||
| 1562 | return print(yue.traceback(err)) | ||
| 1563 | end) | ||
| 1564 | if success then | ||
| 1565 | print(result) | ||
| 1566 | end | ||
| 1567 | local a, b, c | ||
| 1568 | do | ||
| 1569 | local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function() | ||
| 1570 | return func() | ||
| 1571 | end) | ||
| 1572 | if _ok_0 then | ||
| 1573 | a, b, c = _ret_0, _ret_1, _ret_2 | ||
| 1574 | end | ||
| 1575 | end | ||
| 1576 | do | ||
| 1577 | local _exp_0 = ((function() | ||
| 1578 | return (function(_arg_0, ...) | ||
| 1579 | local _ok_0 = _arg_0 | ||
| 1580 | if _ok_0 then | ||
| 1581 | return ... | ||
| 1582 | end | ||
| 1583 | end)(pcall(function() | ||
| 1584 | return func() | ||
| 1585 | end)) | ||
| 1586 | end)()) | ||
| 1587 | if _exp_0 ~= nil then | ||
| 1588 | a = _exp_0 | ||
| 1589 | else | ||
| 1590 | a = "default" | ||
| 1591 | end | ||
| 1592 | end | ||
| 1593 | f((function() | ||
| 1594 | return (function(_arg_0, ...) | ||
| 1595 | local _ok_0 = _arg_0 | ||
| 1596 | if _ok_0 then | ||
| 1597 | return ... | ||
| 1598 | end | ||
| 1599 | end)(pcall(function() | ||
| 1600 | return func() | ||
| 1601 | end)) | ||
| 1602 | end)()) | ||
| 1603 | f((function() | ||
| 1604 | return (function(_arg_0, ...) | ||
| 1605 | local _ok_0 = _arg_0 | ||
| 1606 | if _ok_0 then | ||
| 1607 | return ... | ||
| 1608 | end | ||
| 1609 | end)(xpcall(function() | ||
| 1610 | print(123) | ||
| 1611 | return func() | ||
| 1612 | end, function(e) | ||
| 1613 | print(e) | ||
| 1614 | return e | ||
| 1615 | end)) | ||
| 1616 | end)()) | ||
| 769 | xpcall(function() | 1617 | xpcall(function() |
| 770 | return func(1, 2, 3) | 1618 | return func(1, 2, 3) |
| 771 | end, function(err) | 1619 | end, function(err) |
| @@ -856,6 +1704,28 @@ local a, b, c, d | |||
| 856 | local _obj_0 = tb | 1704 | local _obj_0 = tb |
| 857 | a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] | 1705 | a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] |
| 858 | Constant = 123 | 1706 | Constant = 123 |
| 1707 | local a <const> = 123 | ||
| 1708 | local _ <close> = setmetatable({ }, { | ||
| 1709 | __close = function() | ||
| 1710 | return print("Out of scope.") | ||
| 1711 | end | ||
| 1712 | }) | ||
| 1713 | local a, b, c, d | ||
| 1714 | local _obj_0 = tb | ||
| 1715 | a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] | ||
| 1716 | Constant = 123 | ||
| 1717 | local some_string = "Here is a string\n that has a line break in it." | ||
| 1718 | print("I am " .. tostring(math.random() * 100) .. "% sure.") | ||
| 1719 | local integer = 1000000 | ||
| 1720 | local hex = 0xEFBBBF | ||
| 1721 | local binary = 19 | ||
| 1722 | local str = "key: value\nlist:\n - item1\n - " .. tostring(expr) | ||
| 1723 | local fn | ||
| 1724 | fn = function() | ||
| 1725 | local str = "foo:\n bar: baz" | ||
| 1726 | return str | ||
| 1727 | end | ||
| 1728 | local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'" | ||
| 859 | local some_string = "Here is a string\n that has a line break in it." | 1729 | local some_string = "Here is a string\n that has a line break in it." |
| 860 | print("I am " .. tostring(math.random() * 100) .. "% sure.") | 1730 | print("I am " .. tostring(math.random() * 100) .. "% sure.") |
| 861 | local integer = 1000000 | 1731 | local integer = 1000000 |
| @@ -1052,8 +1922,192 @@ process = function(...) | |||
| 1052 | return sum | 1922 | return sum |
| 1053 | end | 1923 | end |
| 1054 | process(1, nil, 3, nil, 5) | 1924 | process(1, nil, 3, nil, 5) |
| 1055 | f(function() | 1925 | local my_function |
| 1056 | return print("hello") | 1926 | my_function = function() end |
| 1927 | my_function() | ||
| 1928 | local func_a | ||
| 1929 | func_a = function() | ||
| 1930 | return print("hello world") | ||
| 1931 | end | ||
| 1932 | local func_b | ||
| 1933 | func_b = function() | ||
| 1934 | local value = 100 | ||
| 1935 | return print("The value:", value) | ||
| 1936 | end | ||
| 1937 | func_a() | ||
| 1938 | func_b() | ||
| 1939 | local sum | ||
| 1940 | sum = function(x, y) | ||
| 1941 | return print("sum", x + y) | ||
| 1942 | end | ||
| 1943 | sum(10, 20) | ||
| 1944 | print(sum(10, 20)) | ||
| 1945 | a(b(c("a", "b", "c"))) | ||
| 1946 | print("x:", sum(10, 20), "y:", sum(30, 40)) | ||
| 1947 | local sum | ||
| 1948 | sum = function(x, y) | ||
| 1949 | return x + y | ||
| 1950 | end | ||
| 1951 | print("The sum is ", sum(10, 20)) | ||
| 1952 | local sum | ||
| 1953 | sum = function(x, y) | ||
| 1954 | return x + y | ||
| 1955 | end | ||
| 1956 | local mystery | ||
| 1957 | mystery = function(x, y) | ||
| 1958 | return x + y, x - y | ||
| 1959 | end | ||
| 1960 | local a, b = mystery(10, 20) | ||
| 1961 | local func | ||
| 1962 | func = function(self, num) | ||
| 1963 | return self.value + num | ||
| 1964 | end | ||
| 1965 | local my_function | ||
| 1966 | my_function = function(name, height) | ||
| 1967 | if name == nil then | ||
| 1968 | name = "something" | ||
| 1969 | end | ||
| 1970 | if height == nil then | ||
| 1971 | height = 100 | ||
| 1972 | end | ||
| 1973 | print("Hello I am", name) | ||
| 1974 | return print("My height is", height) | ||
| 1975 | end | ||
| 1976 | local some_args | ||
| 1977 | some_args = function(x, y) | ||
| 1978 | if x == nil then | ||
| 1979 | x = 100 | ||
| 1980 | end | ||
| 1981 | if y == nil then | ||
| 1982 | y = x + 1000 | ||
| 1983 | end | ||
| 1984 | return print(x + y) | ||
| 1985 | end | ||
| 1986 | local a = x - 10 | ||
| 1987 | local b = x - 10 | ||
| 1988 | local c = x(-y) | ||
| 1989 | local d = x - z | ||
| 1990 | local x = func("hello") + 100 | ||
| 1991 | local y = func("hello" + 100) | ||
| 1992 | my_func(5, 4, 3, 8, 9, 10) | ||
| 1993 | cool_func(1, 2, 3, 4, 5, 6, 7, 8) | ||
| 1994 | my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4) | ||
| 1995 | local x = { | ||
| 1996 | 1, | ||
| 1997 | 2, | ||
| 1998 | 3, | ||
| 1999 | 4, | ||
| 2000 | a_func(4, 5, 5, 6), | ||
| 2001 | 8, | ||
| 2002 | 9, | ||
| 2003 | 10 | ||
| 2004 | } | ||
| 2005 | local y = { | ||
| 2006 | my_func(1, 2, 3, 4, 5), | ||
| 2007 | 5, | ||
| 2008 | 6, | ||
| 2009 | 7 | ||
| 2010 | } | ||
| 2011 | if func(1, 2, 3, "hello", "world") then | ||
| 2012 | print("hello") | ||
| 2013 | print("I am inside if") | ||
| 2014 | end | ||
| 2015 | if func(1, 2, 3, "hello", "world") then | ||
| 2016 | print("hello") | ||
| 2017 | print("I am inside if") | ||
| 2018 | end | ||
| 2019 | local f1 | ||
| 2020 | f1 = function(_arg_0) | ||
| 2021 | local a, b, c | ||
| 2022 | a, b, c = _arg_0.a, _arg_0.b, _arg_0.c | ||
| 2023 | return print(a, b, c) | ||
| 2024 | end | ||
| 2025 | f1({ | ||
| 2026 | a = 1, | ||
| 2027 | b = "2", | ||
| 2028 | c = { } | ||
| 2029 | }) | ||
| 2030 | local f2 | ||
| 2031 | f2 = function(_arg_0, c) | ||
| 2032 | local a1, b | ||
| 2033 | a1, b = _arg_0.a, _arg_0.b | ||
| 2034 | if a1 == nil then | ||
| 2035 | a1 = 123 | ||
| 2036 | end | ||
| 2037 | if b == nil then | ||
| 2038 | b = 'abc' | ||
| 2039 | end | ||
| 2040 | if c == nil then | ||
| 2041 | c = { } | ||
| 2042 | end | ||
| 2043 | end | ||
| 2044 | print(a1, b, c) | ||
| 2045 | local arg1 = { | ||
| 2046 | a = 0 | ||
| 2047 | } | ||
| 2048 | f2(arg1, arg2) | ||
| 2049 | local findFirstEven | ||
| 2050 | findFirstEven = function(list) | ||
| 2051 | for _index_0 = 1, #list do | ||
| 2052 | local item = list[_index_0] | ||
| 2053 | if type(item) == "table" then | ||
| 2054 | for _index_1 = 1, #item do | ||
| 2055 | local sub = item[_index_1] | ||
| 2056 | if sub % 2 == 0 then | ||
| 2057 | return sub | ||
| 2058 | end | ||
| 2059 | end | ||
| 2060 | end | ||
| 2061 | end | ||
| 2062 | return nil | ||
| 2063 | end | ||
| 2064 | local findFirstEven | ||
| 2065 | findFirstEven = function(list) | ||
| 2066 | for _index_0 = 1, #list do | ||
| 2067 | local item = list[_index_0] | ||
| 2068 | if type(item) == "table" then | ||
| 2069 | for _index_1 = 1, #item do | ||
| 2070 | local sub = item[_index_1] | ||
| 2071 | if sub % 2 == 0 then | ||
| 2072 | return sub | ||
| 2073 | end | ||
| 2074 | end | ||
| 2075 | end | ||
| 2076 | end | ||
| 2077 | return nil | ||
| 2078 | end | ||
| 2079 | local f | ||
| 2080 | f = function(...) | ||
| 2081 | local t = { | ||
| 2082 | n = select("#", ...), | ||
| 2083 | ... | ||
| 2084 | } | ||
| 2085 | print("argument count:", t.n) | ||
| 2086 | print("table length:", #t) | ||
| 2087 | for i = 1, t.n do | ||
| 2088 | print(t[i]) | ||
| 2089 | end | ||
| 2090 | end | ||
| 2091 | f(1, 2, 3) | ||
| 2092 | f("a", "b", "c", "d") | ||
| 2093 | f() | ||
| 2094 | local process | ||
| 2095 | process = function(...) | ||
| 2096 | local args = { | ||
| 2097 | n = select("#", ...), | ||
| 2098 | ... | ||
| 2099 | } | ||
| 2100 | local sum = 0 | ||
| 2101 | for i = 1, args.n do | ||
| 2102 | if args[i] ~= nil and type(args[i]) == "number" then | ||
| 2103 | sum = sum + args[i] | ||
| 2104 | end | ||
| 2105 | end | ||
| 2106 | return sum | ||
| 2107 | end | ||
| 2108 | process(1, nil, 3, nil, 5) | ||
| 2109 | f(function(x) | ||
| 2110 | return print("hello" .. x) | ||
| 1057 | end) | 2111 | end) |
| 1058 | f(function(self) | 2112 | f(function(self) |
| 1059 | return print(self.value) | 2113 | return print(self.value) |
| @@ -1075,6 +2129,97 @@ do | |||
| 1075 | end) | 2129 | end) |
| 1076 | end | 2130 | end |
| 1077 | print(result, msg) | 2131 | print(result, msg) |
| 2132 | f(function(x) | ||
| 2133 | return print("hello" .. x) | ||
| 2134 | end) | ||
| 2135 | f(function(self) | ||
| 2136 | return print(self.value) | ||
| 2137 | end) | ||
| 2138 | map(function(x) | ||
| 2139 | return x * 2 | ||
| 2140 | end, { | ||
| 2141 | 1, | ||
| 2142 | 2, | ||
| 2143 | 3 | ||
| 2144 | }) | ||
| 2145 | local result, msg | ||
| 2146 | do | ||
| 2147 | result, msg = readAsync("filename.txt", function(data) | ||
| 2148 | print(data) | ||
| 2149 | return processAsync(data, function(info) | ||
| 2150 | return check(info) | ||
| 2151 | end) | ||
| 2152 | end) | ||
| 2153 | end | ||
| 2154 | print(result, msg) | ||
| 2155 | local some_values = { | ||
| 2156 | 1, | ||
| 2157 | 2, | ||
| 2158 | 3, | ||
| 2159 | 4 | ||
| 2160 | } | ||
| 2161 | local some_values = { | ||
| 2162 | name = "Bill", | ||
| 2163 | age = 200, | ||
| 2164 | ["favorite food"] = "rice" | ||
| 2165 | } | ||
| 2166 | local profile = { | ||
| 2167 | height = "4 feet", | ||
| 2168 | shoe_size = 13, | ||
| 2169 | favorite_foods = { | ||
| 2170 | "ice cream", | ||
| 2171 | "donuts" | ||
| 2172 | } | ||
| 2173 | } | ||
| 2174 | local values = { | ||
| 2175 | 1, | ||
| 2176 | 2, | ||
| 2177 | 3, | ||
| 2178 | 4, | ||
| 2179 | 5, | ||
| 2180 | 6, | ||
| 2181 | 7, | ||
| 2182 | 8, | ||
| 2183 | name = "superman", | ||
| 2184 | occupation = "crime fighting" | ||
| 2185 | } | ||
| 2186 | my_function({ | ||
| 2187 | dance = "Tango", | ||
| 2188 | partner = "none" | ||
| 2189 | }) | ||
| 2190 | local y = { | ||
| 2191 | type = "dog", | ||
| 2192 | legs = 4, | ||
| 2193 | tails = 1 | ||
| 2194 | } | ||
| 2195 | local tbl = { | ||
| 2196 | ["do"] = "something", | ||
| 2197 | ["end"] = "hunger" | ||
| 2198 | } | ||
| 2199 | local hair = "golden" | ||
| 2200 | local height = 200 | ||
| 2201 | local person = { | ||
| 2202 | hair = hair, | ||
| 2203 | height = height, | ||
| 2204 | shoe_size = 40 | ||
| 2205 | } | ||
| 2206 | print_table({ | ||
| 2207 | hair = hair, | ||
| 2208 | height = height | ||
| 2209 | }) | ||
| 2210 | local t = { | ||
| 2211 | [1 + 2] = "hello", | ||
| 2212 | ["hello world"] = true | ||
| 2213 | } | ||
| 2214 | local some_values = { | ||
| 2215 | 1, | ||
| 2216 | 2, | ||
| 2217 | 3, | ||
| 2218 | 4 | ||
| 2219 | } | ||
| 2220 | local list_with_one_element = { | ||
| 2221 | 1 | ||
| 2222 | } | ||
| 1078 | local some_values = { | 2223 | local some_values = { |
| 1079 | 1, | 2224 | 1, |
| 1080 | 2, | 2225 | 2, |
| @@ -1341,15 +2486,250 @@ for _index_0 = _min_0, 1, -1 do | |||
| 1341 | end | 2486 | end |
| 1342 | reverse_slice = _accum_0 | 2487 | reverse_slice = _accum_0 |
| 1343 | local sub_list | 2488 | local sub_list |
| 2489 | do | ||
| 2490 | local _accum_0 = { } | ||
| 2491 | local _len_0 = 1 | ||
| 2492 | local _list_0 = items | ||
| 2493 | for _index_0 = 2, 4 do | ||
| 2494 | local _item_0 = _list_0[_index_0] | ||
| 2495 | _accum_0[_len_0] = _item_0 | ||
| 2496 | _len_0 = _len_0 + 1 | ||
| 2497 | end | ||
| 2498 | sub_list = _accum_0 | ||
| 2499 | end | ||
| 2500 | local last_four_items | ||
| 1344 | local _accum_0 = { } | 2501 | local _accum_0 = { } |
| 1345 | local _len_0 = 1 | 2502 | local _len_0 = 1 |
| 1346 | local _list_0 = items | 2503 | local _list_0 = items |
| 1347 | for _index_0 = 2, 4 do | 2504 | local _min_0 = #_list_0 + -4 + 1 |
| 2505 | local _max_0 = #_list_0 + -1 + 1 | ||
| 2506 | for _index_0 = _min_0, _max_0 do | ||
| 1348 | local _item_0 = _list_0[_index_0] | 2507 | local _item_0 = _list_0[_index_0] |
| 1349 | _accum_0[_len_0] = _item_0 | 2508 | _accum_0[_len_0] = _item_0 |
| 1350 | _len_0 = _len_0 + 1 | 2509 | _len_0 = _len_0 + 1 |
| 1351 | end | 2510 | end |
| 1352 | sub_list = _accum_0 | 2511 | last_four_items = _accum_0 |
| 2512 | local items = { | ||
| 2513 | 1, | ||
| 2514 | 2, | ||
| 2515 | 3, | ||
| 2516 | 4 | ||
| 2517 | } | ||
| 2518 | local doubled | ||
| 2519 | local _accum_0 = { } | ||
| 2520 | local _len_0 = 1 | ||
| 2521 | for i, item in ipairs(items) do | ||
| 2522 | _accum_0[_len_0] = item * 2 | ||
| 2523 | _len_0 = _len_0 + 1 | ||
| 2524 | end | ||
| 2525 | doubled = _accum_0 | ||
| 2526 | local slice | ||
| 2527 | local _accum_0 = { } | ||
| 2528 | local _len_0 = 1 | ||
| 2529 | for i, item in ipairs(items) do | ||
| 2530 | if i > 1 and i < 3 then | ||
| 2531 | _accum_0[_len_0] = item | ||
| 2532 | _len_0 = _len_0 + 1 | ||
| 2533 | end | ||
| 2534 | end | ||
| 2535 | slice = _accum_0 | ||
| 2536 | local doubled | ||
| 2537 | local _accum_0 = { } | ||
| 2538 | local _len_0 = 1 | ||
| 2539 | local _list_0 = items | ||
| 2540 | for _index_0 = 1, #_list_0 do | ||
| 2541 | local item = _list_0[_index_0] | ||
| 2542 | _accum_0[_len_0] = item * 2 | ||
| 2543 | _len_0 = _len_0 + 1 | ||
| 2544 | end | ||
| 2545 | doubled = _accum_0 | ||
| 2546 | local data = { | ||
| 2547 | a = { | ||
| 2548 | 1, | ||
| 2549 | 2, | ||
| 2550 | 3 | ||
| 2551 | }, | ||
| 2552 | b = { | ||
| 2553 | 4, | ||
| 2554 | 5, | ||
| 2555 | 6 | ||
| 2556 | } | ||
| 2557 | } | ||
| 2558 | local flat | ||
| 2559 | local _accum_0 = { } | ||
| 2560 | for k, v in pairs(data) do | ||
| 2561 | local _len_0 = #_accum_0 + 1 | ||
| 2562 | for _index_0 = 1, #v do | ||
| 2563 | local _elm_0 = v[_index_0] | ||
| 2564 | _accum_0[_len_0], _len_0 = _elm_0, _len_0 + 1 | ||
| 2565 | end | ||
| 2566 | end | ||
| 2567 | flat = _accum_0 | ||
| 2568 | local x_coords = { | ||
| 2569 | 4, | ||
| 2570 | 5, | ||
| 2571 | 6, | ||
| 2572 | 7 | ||
| 2573 | } | ||
| 2574 | local y_coords = { | ||
| 2575 | 9, | ||
| 2576 | 2, | ||
| 2577 | 3 | ||
| 2578 | } | ||
| 2579 | local points | ||
| 2580 | local _accum_0 = { } | ||
| 2581 | local _len_0 = 1 | ||
| 2582 | for _index_0 = 1, #x_coords do | ||
| 2583 | local x = x_coords[_index_0] | ||
| 2584 | for _index_1 = 1, #y_coords do | ||
| 2585 | local y = y_coords[_index_1] | ||
| 2586 | _accum_0[_len_0] = { | ||
| 2587 | x, | ||
| 2588 | y | ||
| 2589 | } | ||
| 2590 | _len_0 = _len_0 + 1 | ||
| 2591 | end | ||
| 2592 | end | ||
| 2593 | points = _accum_0 | ||
| 2594 | local evens | ||
| 2595 | local _accum_0 = { } | ||
| 2596 | local _len_0 = 1 | ||
| 2597 | for i = 1, 100 do | ||
| 2598 | if i % 2 == 0 then | ||
| 2599 | _accum_0[_len_0] = i | ||
| 2600 | _len_0 = _len_0 + 1 | ||
| 2601 | end | ||
| 2602 | end | ||
| 2603 | evens = _accum_0 | ||
| 2604 | local thing = { | ||
| 2605 | color = "red", | ||
| 2606 | name = "fast", | ||
| 2607 | width = 123 | ||
| 2608 | } | ||
| 2609 | local thing_copy | ||
| 2610 | local _tbl_0 = { } | ||
| 2611 | for k, v in pairs(thing) do | ||
| 2612 | _tbl_0[k] = v | ||
| 2613 | end | ||
| 2614 | thing_copy = _tbl_0 | ||
| 2615 | local no_color | ||
| 2616 | local _tbl_0 = { } | ||
| 2617 | for k, v in pairs(thing) do | ||
| 2618 | if k ~= "color" then | ||
| 2619 | _tbl_0[k] = v | ||
| 2620 | end | ||
| 2621 | end | ||
| 2622 | no_color = _tbl_0 | ||
| 2623 | local numbers = { | ||
| 2624 | 1, | ||
| 2625 | 2, | ||
| 2626 | 3, | ||
| 2627 | 4 | ||
| 2628 | } | ||
| 2629 | local sqrts | ||
| 2630 | local _tbl_0 = { } | ||
| 2631 | for _index_0 = 1, #numbers do | ||
| 2632 | local i = numbers[_index_0] | ||
| 2633 | _tbl_0[i] = math.sqrt(i) | ||
| 2634 | end | ||
| 2635 | sqrts = _tbl_0 | ||
| 2636 | local tuples = { | ||
| 2637 | { | ||
| 2638 | "hello", | ||
| 2639 | "world" | ||
| 2640 | }, | ||
| 2641 | { | ||
| 2642 | "foo", | ||
| 2643 | "bar" | ||
| 2644 | } | ||
| 2645 | } | ||
| 2646 | local tbl | ||
| 2647 | local _tbl_0 = { } | ||
| 2648 | for _index_0 = 1, #tuples do | ||
| 2649 | local tuple = tuples[_index_0] | ||
| 2650 | local _key_0, _val_0 = unpack(tuple) | ||
| 2651 | _tbl_0[_key_0] = _val_0 | ||
| 2652 | end | ||
| 2653 | tbl = _tbl_0 | ||
| 2654 | local slice | ||
| 2655 | local _accum_0 = { } | ||
| 2656 | local _len_0 = 1 | ||
| 2657 | local _list_0 = items | ||
| 2658 | for _index_0 = 1, 5 do | ||
| 2659 | local item = _list_0[_index_0] | ||
| 2660 | _accum_0[_len_0] = item | ||
| 2661 | _len_0 = _len_0 + 1 | ||
| 2662 | end | ||
| 2663 | slice = _accum_0 | ||
| 2664 | local slice | ||
| 2665 | local _accum_0 = { } | ||
| 2666 | local _len_0 = 1 | ||
| 2667 | local _list_0 = items | ||
| 2668 | local _max_0 = #_list_0 | ||
| 2669 | for _index_0 = 2, _max_0 do | ||
| 2670 | local item = _list_0[_index_0] | ||
| 2671 | _accum_0[_len_0] = item | ||
| 2672 | _len_0 = _len_0 + 1 | ||
| 2673 | end | ||
| 2674 | slice = _accum_0 | ||
| 2675 | local slice | ||
| 2676 | local _accum_0 = { } | ||
| 2677 | local _len_0 = 1 | ||
| 2678 | local _list_0 = items | ||
| 2679 | local _max_0 = #_list_0 | ||
| 2680 | for _index_0 = 1, _max_0, 2 do | ||
| 2681 | local item = _list_0[_index_0] | ||
| 2682 | _accum_0[_len_0] = item | ||
| 2683 | _len_0 = _len_0 + 1 | ||
| 2684 | end | ||
| 2685 | slice = _accum_0 | ||
| 2686 | local slice | ||
| 2687 | local _accum_0 = { } | ||
| 2688 | local _len_0 = 1 | ||
| 2689 | local _list_0 = items | ||
| 2690 | local _min_0 = #_list_0 + -4 + 1 | ||
| 2691 | local _max_0 = #_list_0 + -1 + 1 | ||
| 2692 | for _index_0 = _min_0, _max_0 do | ||
| 2693 | local item = _list_0[_index_0] | ||
| 2694 | _accum_0[_len_0] = item | ||
| 2695 | _len_0 = _len_0 + 1 | ||
| 2696 | end | ||
| 2697 | slice = _accum_0 | ||
| 2698 | local reverse_slice | ||
| 2699 | local _accum_0 = { } | ||
| 2700 | local _len_0 = 1 | ||
| 2701 | local _list_0 = items | ||
| 2702 | local _min_0 = #_list_0 + -1 + 1 | ||
| 2703 | for _index_0 = _min_0, 1, -1 do | ||
| 2704 | local item = _list_0[_index_0] | ||
| 2705 | _accum_0[_len_0] = item | ||
| 2706 | _len_0 = _len_0 + 1 | ||
| 2707 | end | ||
| 2708 | reverse_slice = _accum_0 | ||
| 2709 | local sub_list | ||
| 2710 | do | ||
| 2711 | local _accum_0 = { } | ||
| 2712 | local _len_0 = 1 | ||
| 2713 | local _list_0 = items | ||
| 2714 | for _index_0 = 2, 4 do | ||
| 2715 | local _item_0 = _list_0[_index_0] | ||
| 2716 | _accum_0[_len_0] = _item_0 | ||
| 2717 | _len_0 = _len_0 + 1 | ||
| 2718 | end | ||
| 2719 | sub_list = _accum_0 | ||
| 2720 | end | ||
| 2721 | local last_four_items | ||
| 2722 | local _accum_0 = { } | ||
| 2723 | local _len_0 = 1 | ||
| 2724 | local _list_0 = items | ||
| 2725 | local _min_0 = #_list_0 + -4 + 1 | ||
| 2726 | local _max_0 = #_list_0 + -1 + 1 | ||
| 2727 | for _index_0 = _min_0, _max_0 do | ||
| 2728 | local _item_0 = _list_0[_index_0] | ||
| 2729 | _accum_0[_len_0] = _item_0 | ||
| 2730 | _len_0 = _len_0 + 1 | ||
| 2731 | end | ||
| 2732 | last_four_items = _accum_0 | ||
| 1353 | for i = 10, 20 do | 2733 | for i = 10, 20 do |
| 1354 | print(i) | 2734 | print(i) |
| 1355 | end | 2735 | end |
| @@ -1414,6 +2794,86 @@ func_b = function() | |||
| 1414 | end | 2794 | end |
| 1415 | print(func_a()) | 2795 | print(func_a()) |
| 1416 | print(func_b()) | 2796 | print(func_b()) |
| 2797 | for i = 10, 20 do | ||
| 2798 | print(i) | ||
| 2799 | end | ||
| 2800 | for k = 1, 15, 2 do | ||
| 2801 | print(k) | ||
| 2802 | end | ||
| 2803 | for key, value in pairs(object) do | ||
| 2804 | print(key, value) | ||
| 2805 | end | ||
| 2806 | local _list_0 = items | ||
| 2807 | for _index_0 = 2, 4 do | ||
| 2808 | local item = _list_0[_index_0] | ||
| 2809 | print(item) | ||
| 2810 | end | ||
| 2811 | local _list_0 = items | ||
| 2812 | for _index_0 = 1, #_list_0 do | ||
| 2813 | local item = _list_0[_index_0] | ||
| 2814 | print(item) | ||
| 2815 | end | ||
| 2816 | for j = 1, 10, 3 do | ||
| 2817 | print(j) | ||
| 2818 | end | ||
| 2819 | local doubled_evens | ||
| 2820 | local _accum_0 = { } | ||
| 2821 | local _len_0 = 1 | ||
| 2822 | for i = 1, 20 do | ||
| 2823 | if i % 2 == 0 then | ||
| 2824 | _accum_0[_len_0] = i * 2 | ||
| 2825 | _len_0 = _len_0 + 1 | ||
| 2826 | else | ||
| 2827 | _accum_0[_len_0] = i | ||
| 2828 | _len_0 = _len_0 + 1 | ||
| 2829 | end | ||
| 2830 | end | ||
| 2831 | doubled_evens = _accum_0 | ||
| 2832 | local first_large | ||
| 2833 | local _accum_0 | ||
| 2834 | local _list_0 = numbers | ||
| 2835 | for _index_0 = 1, #_list_0 do | ||
| 2836 | local n = _list_0[_index_0] | ||
| 2837 | if n > 10 then | ||
| 2838 | _accum_0 = n | ||
| 2839 | break | ||
| 2840 | end | ||
| 2841 | end | ||
| 2842 | first_large = _accum_0 | ||
| 2843 | local func_a | ||
| 2844 | func_a = function() | ||
| 2845 | for i = 1, 10 do | ||
| 2846 | print(i) | ||
| 2847 | end | ||
| 2848 | end | ||
| 2849 | local func_b | ||
| 2850 | func_b = function() | ||
| 2851 | local _accum_0 = { } | ||
| 2852 | local _len_0 = 1 | ||
| 2853 | for i = 1, 10 do | ||
| 2854 | _accum_0[_len_0] = i | ||
| 2855 | _len_0 = _len_0 + 1 | ||
| 2856 | end | ||
| 2857 | return _accum_0 | ||
| 2858 | end | ||
| 2859 | print(func_a()) | ||
| 2860 | print(func_b()) | ||
| 2861 | local i = 10 | ||
| 2862 | while i > 0 do | ||
| 2863 | print(i) | ||
| 2864 | i = i - 1 | ||
| 2865 | end | ||
| 2866 | while running == true do | ||
| 2867 | my_function() | ||
| 2868 | end | ||
| 2869 | local i = 10 | ||
| 2870 | while not (i == 0) do | ||
| 2871 | print(i) | ||
| 2872 | i = i - 1 | ||
| 2873 | end | ||
| 2874 | while not (running == false) do | ||
| 2875 | my_function() | ||
| 2876 | end | ||
| 1417 | local i = 10 | 2877 | local i = 10 |
| 1418 | repeat | 2878 | repeat |
| 1419 | print(i) | 2879 | print(i) |
| @@ -1435,6 +2895,41 @@ end | |||
| 1435 | while not (running == false) do | 2895 | while not (running == false) do |
| 1436 | my_function() | 2896 | my_function() |
| 1437 | end | 2897 | end |
| 2898 | local i = 10 | ||
| 2899 | repeat | ||
| 2900 | print(i) | ||
| 2901 | i = i - 1 | ||
| 2902 | until i == 0 | ||
| 2903 | local i = 0 | ||
| 2904 | while i < 10 do | ||
| 2905 | i = i + 1 | ||
| 2906 | if i % 2 == 0 then | ||
| 2907 | goto _continue_0 | ||
| 2908 | end | ||
| 2909 | print(i) | ||
| 2910 | ::_continue_0:: | ||
| 2911 | end | ||
| 2912 | local my_numbers = { | ||
| 2913 | 1, | ||
| 2914 | 2, | ||
| 2915 | 3, | ||
| 2916 | 4, | ||
| 2917 | 5, | ||
| 2918 | 6 | ||
| 2919 | } | ||
| 2920 | local odds | ||
| 2921 | local _accum_0 = { } | ||
| 2922 | local _len_0 = 1 | ||
| 2923 | for _index_0 = 1, #my_numbers do | ||
| 2924 | local x = my_numbers[_index_0] | ||
| 2925 | if x % 2 == 1 then | ||
| 2926 | goto _continue_0 | ||
| 2927 | end | ||
| 2928 | _accum_0[_len_0] = x | ||
| 2929 | _len_0 = _len_0 + 1 | ||
| 2930 | ::_continue_0:: | ||
| 2931 | end | ||
| 2932 | odds = _accum_0 | ||
| 1438 | local i = 0 | 2933 | local i = 0 |
| 1439 | while i < 10 do | 2934 | while i < 10 do |
| 1440 | i = i + 1 | 2935 | i = i + 1 |
| @@ -1524,6 +3019,79 @@ end | |||
| 1524 | if not (math.random() > 0.1) then | 3019 | if not (math.random() > 0.1) then |
| 1525 | print("You're lucky!") | 3020 | print("You're lucky!") |
| 1526 | end | 3021 | end |
| 3022 | local have_coins = false | ||
| 3023 | if have_coins then | ||
| 3024 | print("Got coins") | ||
| 3025 | else | ||
| 3026 | print("No coins") | ||
| 3027 | end | ||
| 3028 | local have_coins = false | ||
| 3029 | if have_coins then | ||
| 3030 | print("Got coins") | ||
| 3031 | else | ||
| 3032 | print("No coins") | ||
| 3033 | end | ||
| 3034 | local have_coins = false | ||
| 3035 | print((function() | ||
| 3036 | if have_coins then | ||
| 3037 | return "Got coins" | ||
| 3038 | else | ||
| 3039 | return "No coins" | ||
| 3040 | end | ||
| 3041 | end)()) | ||
| 3042 | local is_tall | ||
| 3043 | is_tall = function(name) | ||
| 3044 | if name == "Rob" then | ||
| 3045 | return true | ||
| 3046 | else | ||
| 3047 | return false | ||
| 3048 | end | ||
| 3049 | end | ||
| 3050 | local message | ||
| 3051 | if is_tall("Rob") then | ||
| 3052 | message = "I am very tall" | ||
| 3053 | else | ||
| 3054 | message = "I am not so tall" | ||
| 3055 | end | ||
| 3056 | print(message) | ||
| 3057 | if not (os.date("%A") == "Monday") then | ||
| 3058 | print("it is not Monday!") | ||
| 3059 | end | ||
| 3060 | if not (math.random() > 0.1) then | ||
| 3061 | print("You're lucky!") | ||
| 3062 | end | ||
| 3063 | local a = 5 | ||
| 3064 | if (1 == a or 3 == a or 5 == a or 7 == a) then | ||
| 3065 | print("checking equality with discrete values") | ||
| 3066 | end | ||
| 3067 | if (function() | ||
| 3068 | local _check_0 = list | ||
| 3069 | for _index_0 = 1, #_check_0 do | ||
| 3070 | if _check_0[_index_0] == a then | ||
| 3071 | return true | ||
| 3072 | end | ||
| 3073 | end | ||
| 3074 | return false | ||
| 3075 | end)() then | ||
| 3076 | print("checking if `a` is in a list") | ||
| 3077 | end | ||
| 3078 | if not (math.random() > 0.1) then | ||
| 3079 | print("You're lucky!") | ||
| 3080 | end | ||
| 3081 | if name == "Rob" then | ||
| 3082 | print("hello world") | ||
| 3083 | end | ||
| 3084 | local _list_0 = items | ||
| 3085 | for _index_0 = 1, #_list_0 do | ||
| 3086 | local item = _list_0[_index_0] | ||
| 3087 | print("item: ", item) | ||
| 3088 | end | ||
| 3089 | while game:isRunning() do | ||
| 3090 | game:update() | ||
| 3091 | end | ||
| 3092 | while not reader:eof() do | ||
| 3093 | reader:parse_line() | ||
| 3094 | end | ||
| 1527 | if name == "Rob" then | 3095 | if name == "Rob" then |
| 1528 | print("hello world") | 3096 | print("hello world") |
| 1529 | end | 3097 | end |
| @@ -1830,6 +3398,298 @@ if _tab_0 then | |||
| 1830 | print("Action:", action) | 3398 | print("Action:", action) |
| 1831 | end | 3399 | end |
| 1832 | end | 3400 | end |
| 3401 | local name = "Dan" | ||
| 3402 | if "Robert" == name then | ||
| 3403 | print("You are Robert") | ||
| 3404 | elseif "Dan" == name or "Daniel" == name then | ||
| 3405 | print("Your name, it's Dan") | ||
| 3406 | else | ||
| 3407 | print("I don't know about you with name " .. tostring(name)) | ||
| 3408 | end | ||
| 3409 | local b = 1 | ||
| 3410 | local next_number | ||
| 3411 | if 1 == b then | ||
| 3412 | next_number = 2 | ||
| 3413 | elseif 2 == b then | ||
| 3414 | next_number = 3 | ||
| 3415 | else | ||
| 3416 | next_number = error("can't count that high!") | ||
| 3417 | end | ||
| 3418 | local msg | ||
| 3419 | local _exp_0 = math.random(1, 5) | ||
| 3420 | if 1 == _exp_0 then | ||
| 3421 | msg = "you are lucky" | ||
| 3422 | elseif 2 == _exp_0 then | ||
| 3423 | msg = "you are almost lucky" | ||
| 3424 | else | ||
| 3425 | msg = "not so lucky" | ||
| 3426 | end | ||
| 3427 | do | ||
| 3428 | local _exp_0 = math.random(1, 5) | ||
| 3429 | if 1 == _exp_0 then | ||
| 3430 | print("you are lucky") | ||
| 3431 | else | ||
| 3432 | print("not so lucky") | ||
| 3433 | end | ||
| 3434 | end | ||
| 3435 | local _exp_0 = math.random(1, 5) | ||
| 3436 | if 1 == _exp_0 then | ||
| 3437 | print("you are lucky") | ||
| 3438 | else | ||
| 3439 | print("not so lucky") | ||
| 3440 | end | ||
| 3441 | local items = { | ||
| 3442 | { | ||
| 3443 | x = 100, | ||
| 3444 | y = 200 | ||
| 3445 | }, | ||
| 3446 | { | ||
| 3447 | width = 300, | ||
| 3448 | height = 400 | ||
| 3449 | } | ||
| 3450 | } | ||
| 3451 | for _index_0 = 1, #items do | ||
| 3452 | local item = items[_index_0] | ||
| 3453 | local _type_0 = type(item) | ||
| 3454 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 3455 | local _match_0 = false | ||
| 3456 | if _tab_0 then | ||
| 3457 | local x = item.x | ||
| 3458 | local y = item.y | ||
| 3459 | if x ~= nil and y ~= nil then | ||
| 3460 | _match_0 = true | ||
| 3461 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) | ||
| 3462 | end | ||
| 3463 | end | ||
| 3464 | if not _match_0 then | ||
| 3465 | if _tab_0 then | ||
| 3466 | local width = item.width | ||
| 3467 | local height = item.height | ||
| 3468 | if width ~= nil and height ~= nil then | ||
| 3469 | print("size " .. tostring(width) .. ", " .. tostring(height)) | ||
| 3470 | end | ||
| 3471 | end | ||
| 3472 | end | ||
| 3473 | end | ||
| 3474 | local item = { } | ||
| 3475 | local x, y = item.pos.x, item.pos.y | ||
| 3476 | if x == nil then | ||
| 3477 | x = 50 | ||
| 3478 | end | ||
| 3479 | if y == nil then | ||
| 3480 | y = 200 | ||
| 3481 | end | ||
| 3482 | local _type_0 = type(item) | ||
| 3483 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 3484 | if _tab_0 then | ||
| 3485 | do | ||
| 3486 | local _obj_0 = item.pos | ||
| 3487 | local _type_1 = type(_obj_0) | ||
| 3488 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 3489 | x = _obj_0.x | ||
| 3490 | end | ||
| 3491 | end | ||
| 3492 | do | ||
| 3493 | local _obj_0 = item.pos | ||
| 3494 | local _type_1 = type(_obj_0) | ||
| 3495 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 3496 | y = _obj_0.y | ||
| 3497 | end | ||
| 3498 | end | ||
| 3499 | if x == nil then | ||
| 3500 | x = 50 | ||
| 3501 | end | ||
| 3502 | if y == nil then | ||
| 3503 | y = 200 | ||
| 3504 | end | ||
| 3505 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) | ||
| 3506 | end | ||
| 3507 | local _exp_0 = tb | ||
| 3508 | local _type_0 = type(_exp_0) | ||
| 3509 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 3510 | local _match_0 = false | ||
| 3511 | if _tab_0 then | ||
| 3512 | if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then | ||
| 3513 | _match_0 = true | ||
| 3514 | print("1, 2, 3") | ||
| 3515 | end | ||
| 3516 | end | ||
| 3517 | if not _match_0 then | ||
| 3518 | local _match_1 = false | ||
| 3519 | if _tab_0 then | ||
| 3520 | local b = _exp_0[2] | ||
| 3521 | if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then | ||
| 3522 | _match_1 = true | ||
| 3523 | print("1, " .. tostring(b) .. ", 3") | ||
| 3524 | end | ||
| 3525 | end | ||
| 3526 | if not _match_1 then | ||
| 3527 | if _tab_0 then | ||
| 3528 | local b = _exp_0[3] | ||
| 3529 | if b == nil then | ||
| 3530 | b = 3 | ||
| 3531 | end | ||
| 3532 | if 1 == _exp_0[1] and 2 == _exp_0[2] then | ||
| 3533 | print("1, 2, " .. tostring(b)) | ||
| 3534 | end | ||
| 3535 | end | ||
| 3536 | end | ||
| 3537 | end | ||
| 3538 | local _exp_0 = tb | ||
| 3539 | local _type_0 = type(_exp_0) | ||
| 3540 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 3541 | local _match_0 = false | ||
| 3542 | if _tab_0 then | ||
| 3543 | local result = _exp_0.result | ||
| 3544 | if true == _exp_0.success and result ~= nil then | ||
| 3545 | _match_0 = true | ||
| 3546 | print("success", result) | ||
| 3547 | end | ||
| 3548 | end | ||
| 3549 | if not _match_0 then | ||
| 3550 | local _match_1 = false | ||
| 3551 | if _tab_0 then | ||
| 3552 | if false == _exp_0.success then | ||
| 3553 | _match_1 = true | ||
| 3554 | print("failed", result) | ||
| 3555 | end | ||
| 3556 | end | ||
| 3557 | if not _match_1 then | ||
| 3558 | print("invalid") | ||
| 3559 | end | ||
| 3560 | end | ||
| 3561 | local _exp_0 = tb | ||
| 3562 | local _type_0 = type(_exp_0) | ||
| 3563 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 3564 | local _match_0 = false | ||
| 3565 | if _tab_0 then | ||
| 3566 | local content | ||
| 3567 | do | ||
| 3568 | local _obj_0 = _exp_0.data | ||
| 3569 | local _type_1 = type(_obj_0) | ||
| 3570 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 3571 | content = _obj_0.content | ||
| 3572 | end | ||
| 3573 | end | ||
| 3574 | local _val_0 | ||
| 3575 | do | ||
| 3576 | local _obj_0 = _exp_0.data | ||
| 3577 | if _obj_0 ~= nil then | ||
| 3578 | _val_0 = _obj_0.type | ||
| 3579 | end | ||
| 3580 | end | ||
| 3581 | if "success" == _val_0 and content ~= nil then | ||
| 3582 | _match_0 = true | ||
| 3583 | print("success", content) | ||
| 3584 | end | ||
| 3585 | end | ||
| 3586 | if not _match_0 then | ||
| 3587 | local _match_1 = false | ||
| 3588 | if _tab_0 then | ||
| 3589 | local content | ||
| 3590 | do | ||
| 3591 | local _obj_0 = _exp_0.data | ||
| 3592 | local _type_1 = type(_obj_0) | ||
| 3593 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 3594 | content = _obj_0.content | ||
| 3595 | end | ||
| 3596 | end | ||
| 3597 | local _val_0 | ||
| 3598 | do | ||
| 3599 | local _obj_0 = _exp_0.data | ||
| 3600 | if _obj_0 ~= nil then | ||
| 3601 | _val_0 = _obj_0.type | ||
| 3602 | end | ||
| 3603 | end | ||
| 3604 | if "error" == _val_0 and content ~= nil then | ||
| 3605 | _match_1 = true | ||
| 3606 | print("failed", content) | ||
| 3607 | end | ||
| 3608 | end | ||
| 3609 | if not _match_1 then | ||
| 3610 | print("invalid") | ||
| 3611 | end | ||
| 3612 | end | ||
| 3613 | local _exp_0 = tb | ||
| 3614 | local _type_0 = type(_exp_0) | ||
| 3615 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 3616 | if _tab_0 then | ||
| 3617 | local fourth = _exp_0[4] | ||
| 3618 | local _val_0 | ||
| 3619 | do | ||
| 3620 | local _obj_0 = _exp_0[1] | ||
| 3621 | if _obj_0 ~= nil then | ||
| 3622 | _val_0 = _obj_0.a | ||
| 3623 | end | ||
| 3624 | end | ||
| 3625 | local _val_1 | ||
| 3626 | do | ||
| 3627 | local _obj_0 = _exp_0[1] | ||
| 3628 | if _obj_0 ~= nil then | ||
| 3629 | _val_1 = _obj_0.b | ||
| 3630 | end | ||
| 3631 | end | ||
| 3632 | local _val_2 | ||
| 3633 | do | ||
| 3634 | local _obj_0 = _exp_0[2] | ||
| 3635 | if _obj_0 ~= nil then | ||
| 3636 | _val_2 = _obj_0.a | ||
| 3637 | end | ||
| 3638 | end | ||
| 3639 | local _val_3 | ||
| 3640 | do | ||
| 3641 | local _obj_0 = _exp_0[2] | ||
| 3642 | if _obj_0 ~= nil then | ||
| 3643 | _val_3 = _obj_0.b | ||
| 3644 | end | ||
| 3645 | end | ||
| 3646 | local _val_4 | ||
| 3647 | do | ||
| 3648 | local _obj_0 = _exp_0[3] | ||
| 3649 | if _obj_0 ~= nil then | ||
| 3650 | _val_4 = _obj_0.a | ||
| 3651 | end | ||
| 3652 | end | ||
| 3653 | local _val_5 | ||
| 3654 | do | ||
| 3655 | local _obj_0 = _exp_0[3] | ||
| 3656 | if _obj_0 ~= nil then | ||
| 3657 | _val_5 = _obj_0.b | ||
| 3658 | end | ||
| 3659 | end | ||
| 3660 | if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then | ||
| 3661 | print("matched", fourth) | ||
| 3662 | end | ||
| 3663 | end | ||
| 3664 | local segments = { | ||
| 3665 | "admin", | ||
| 3666 | "users", | ||
| 3667 | "logs", | ||
| 3668 | "view" | ||
| 3669 | } | ||
| 3670 | local _type_0 = type(segments) | ||
| 3671 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 3672 | if _tab_0 then | ||
| 3673 | local groups | ||
| 3674 | do | ||
| 3675 | local _accum_0 = { } | ||
| 3676 | local _len_0 = 1 | ||
| 3677 | local _max_0 = #segments + -3 + 1 | ||
| 3678 | for _index_0 = 1, _max_0 do | ||
| 3679 | local _item_0 = segments[_index_0] | ||
| 3680 | _accum_0[_len_0] = _item_0 | ||
| 3681 | _len_0 = _len_0 + 1 | ||
| 3682 | end | ||
| 3683 | groups = _accum_0 | ||
| 3684 | end | ||
| 3685 | local resource = segments[#segments - 1] | ||
| 3686 | local action = segments[#segments] | ||
| 3687 | if resource ~= nil and action ~= nil then | ||
| 3688 | print("Group:", groups) | ||
| 3689 | print("Resource:", resource) | ||
| 3690 | print("Action:", action) | ||
| 3691 | end | ||
| 3692 | end | ||
| 1833 | local Inventory | 3693 | local Inventory |
| 1834 | local _class_0 | 3694 | local _class_0 |
| 1835 | local _base_0 = { | 3695 | local _base_0 = { |
| @@ -2450,1946 +4310,6 @@ end | |||
| 2450 | local y = Y() | 4310 | local y = Y() |
| 2451 | y:func() | 4311 | y:func() |
| 2452 | assert(y.__class.__parent ~= X) | 4312 | assert(y.__class.__parent ~= X) |
| 2453 | local _with_0 = Person() | ||
| 2454 | _with_0.name = "Oswald" | ||
| 2455 | _with_0:add_relative(my_dad) | ||
| 2456 | _with_0:save() | ||
| 2457 | print(_with_0.name) | ||
| 2458 | local file | ||
| 2459 | local _with_0 = File("favorite_foods.txt") | ||
| 2460 | _with_0:set_encoding("utf8") | ||
| 2461 | file = _with_0 | ||
| 2462 | local create_person | ||
| 2463 | create_person = function(name, relatives) | ||
| 2464 | local _with_0 = Person() | ||
| 2465 | _with_0.name = name | ||
| 2466 | for _index_0 = 1, #relatives do | ||
| 2467 | local relative = relatives[_index_0] | ||
| 2468 | _with_0:add_relative(relative) | ||
| 2469 | end | ||
| 2470 | return _with_0 | ||
| 2471 | end | ||
| 2472 | local me = create_person("Leaf", { | ||
| 2473 | dad, | ||
| 2474 | mother, | ||
| 2475 | sister | ||
| 2476 | }) | ||
| 2477 | local str = "Hello" | ||
| 2478 | print("original:", str) | ||
| 2479 | print("upper:", str:upper()) | ||
| 2480 | local _with_0 = tb | ||
| 2481 | _with_0[1] = 1 | ||
| 2482 | print(_with_0[2]) | ||
| 2483 | do | ||
| 2484 | local _with_1 = _with_0[abc] | ||
| 2485 | _with_1[3] = _with_1[2]:func() | ||
| 2486 | _with_1["key-name"] = value | ||
| 2487 | end | ||
| 2488 | _with_0[#_with_0 + 1] = "abc" | ||
| 2489 | local _with_0 = obj | ||
| 2490 | if _with_0 ~= nil then | ||
| 2491 | print(obj.name) | ||
| 2492 | end | ||
| 2493 | do | ||
| 2494 | local var = "hello" | ||
| 2495 | print(var) | ||
| 2496 | end | ||
| 2497 | print(var) | ||
| 2498 | local counter | ||
| 2499 | do | ||
| 2500 | local i = 0 | ||
| 2501 | counter = function() | ||
| 2502 | i = i + 1 | ||
| 2503 | return i | ||
| 2504 | end | ||
| 2505 | end | ||
| 2506 | print(counter()) | ||
| 2507 | print(counter()) | ||
| 2508 | local tbl = { | ||
| 2509 | key = (function() | ||
| 2510 | print("assigning key!") | ||
| 2511 | return 1234 | ||
| 2512 | end)() | ||
| 2513 | } | ||
| 2514 | local my_object = { | ||
| 2515 | value = 1000, | ||
| 2516 | write = function(self) | ||
| 2517 | return print("the value:", self.value) | ||
| 2518 | end | ||
| 2519 | } | ||
| 2520 | local run_callback | ||
| 2521 | run_callback = function(func) | ||
| 2522 | print("running callback...") | ||
| 2523 | return func() | ||
| 2524 | end | ||
| 2525 | run_callback(my_object.write) | ||
| 2526 | run_callback((function() | ||
| 2527 | local _base_0 = my_object | ||
| 2528 | local _fn_0 = _base_0.write | ||
| 2529 | return _fn_0 and function(...) | ||
| 2530 | return _fn_0(_base_0, ...) | ||
| 2531 | end | ||
| 2532 | end)()) | ||
| 2533 | local i = 100 | ||
| 2534 | local my_func | ||
| 2535 | my_func = function() | ||
| 2536 | i = 10 | ||
| 2537 | while i > 0 do | ||
| 2538 | print(i) | ||
| 2539 | i = i - 1 | ||
| 2540 | end | ||
| 2541 | end | ||
| 2542 | my_func() | ||
| 2543 | print(i) | ||
| 2544 | local i = 100 | ||
| 2545 | local my_func | ||
| 2546 | my_func = function() | ||
| 2547 | local i = "hello" | ||
| 2548 | end | ||
| 2549 | my_func() | ||
| 2550 | print(i) | ||
| 2551 | local tmp = 1213 | ||
| 2552 | local i, k = 100, 50 | ||
| 2553 | local my_func | ||
| 2554 | my_func = function(add) | ||
| 2555 | local tmp = tmp + add | ||
| 2556 | i = i + tmp | ||
| 2557 | k = k + tmp | ||
| 2558 | end | ||
| 2559 | my_func(22) | ||
| 2560 | print(i, k) | ||
| 2561 | local _module_0 = { } | ||
| 2562 | local p, to_lua | ||
| 2563 | do | ||
| 2564 | local _obj_0 = require("yue") | ||
| 2565 | p, to_lua = _obj_0.p, _obj_0.to_lua | ||
| 2566 | end | ||
| 2567 | local inventory = { | ||
| 2568 | equipment = { | ||
| 2569 | "sword", | ||
| 2570 | "shield" | ||
| 2571 | }, | ||
| 2572 | items = { | ||
| 2573 | { | ||
| 2574 | name = "potion", | ||
| 2575 | count = 10 | ||
| 2576 | }, | ||
| 2577 | { | ||
| 2578 | name = "bread", | ||
| 2579 | count = 3 | ||
| 2580 | } | ||
| 2581 | } | ||
| 2582 | } | ||
| 2583 | local map | ||
| 2584 | map = function(arr, action) | ||
| 2585 | local _accum_0 = { } | ||
| 2586 | local _len_0 = 1 | ||
| 2587 | for _index_0 = 1, #arr do | ||
| 2588 | local item = arr[_index_0] | ||
| 2589 | _accum_0[_len_0] = action(item) | ||
| 2590 | _len_0 = _len_0 + 1 | ||
| 2591 | end | ||
| 2592 | return _accum_0 | ||
| 2593 | end | ||
| 2594 | local filter | ||
| 2595 | filter = function(arr, cond) | ||
| 2596 | local _accum_0 = { } | ||
| 2597 | local _len_0 = 1 | ||
| 2598 | for _index_0 = 1, #arr do | ||
| 2599 | local item = arr[_index_0] | ||
| 2600 | if cond(item) then | ||
| 2601 | _accum_0[_len_0] = item | ||
| 2602 | _len_0 = _len_0 + 1 | ||
| 2603 | end | ||
| 2604 | end | ||
| 2605 | return _accum_0 | ||
| 2606 | end | ||
| 2607 | local reduce | ||
| 2608 | reduce = function(arr, init, action) | ||
| 2609 | for _index_0 = 1, #arr do | ||
| 2610 | local item = arr[_index_0] | ||
| 2611 | init = action(init, item) | ||
| 2612 | end | ||
| 2613 | return init | ||
| 2614 | end | ||
| 2615 | print(reduce(filter(map({ | ||
| 2616 | 1, | ||
| 2617 | 2, | ||
| 2618 | 3 | ||
| 2619 | }, function(x) | ||
| 2620 | return x * 2 | ||
| 2621 | end), function(x) | ||
| 2622 | return x > 4 | ||
| 2623 | end), 0, function(a, b) | ||
| 2624 | return a + b | ||
| 2625 | end)) | ||
| 2626 | local apple = setmetatable({ | ||
| 2627 | size = 15, | ||
| 2628 | }, { | ||
| 2629 | __index = { | ||
| 2630 | color = 0x00ffff | ||
| 2631 | } | ||
| 2632 | }) | ||
| 2633 | if (getmetatable(apple) ~= nil) then | ||
| 2634 | p(apple.size, apple.color, getmetatable(apple).__index) | ||
| 2635 | end | ||
| 2636 | local _u1f31b = "月之脚本" | ||
| 2637 | _module_0["🌛"] = _u1f31b | ||
| 2638 | return _module_0 | ||
| 2639 | local area = 6.2831853071796 * 5 | ||
| 2640 | print('hello world') | ||
| 2641 | do | ||
| 2642 | assert(item ~= nil) | ||
| 2643 | end | ||
| 2644 | local value = item | ||
| 2645 | if (f1() and f2() and f3()) then | ||
| 2646 | print("OK") | ||
| 2647 | end | ||
| 2648 | do | ||
| 2649 | local funcA | ||
| 2650 | funcA = function() end | ||
| 2651 | end | ||
| 2652 | local funcA | ||
| 2653 | funcA = function() | ||
| 2654 | return "fail to assign to the Yue macro defined variable" | ||
| 2655 | end | ||
| 2656 | do | ||
| 2657 | local function funcB() end | ||
| 2658 | end | ||
| 2659 | local funcB | ||
| 2660 | funcB = function() | ||
| 2661 | return "fail to assign to the Lua macro defined variable" | ||
| 2662 | end | ||
| 2663 | do | ||
| 2664 | -- raw Lua codes insertion | ||
| 2665 | if cond then | ||
| 2666 | print("output") | ||
| 2667 | end | ||
| 2668 | end | ||
| 2669 | print("yuescript") | ||
| 2670 | print(2) | ||
| 2671 | print("Valid enum type:", "Static") | ||
| 2672 | do | ||
| 2673 | print(123, "hello") | ||
| 2674 | end | ||
| 2675 | do | ||
| 2676 | print(123, "hello") | ||
| 2677 | end | ||
| 2678 | if tb ~= nil then | ||
| 2679 | tb:func() | ||
| 2680 | end | ||
| 2681 | if tb ~= nil then | ||
| 2682 | tb:func() | ||
| 2683 | end | ||
| 2684 | print(1 < 2 and 2 <= 2 and 2 < 3 and 3 == 3 and 3 > 2 and 2 >= 1 and 1 == 1 and 1 < 3 and 3 ~= 5) | ||
| 2685 | local a = 5 | ||
| 2686 | print(1 <= a and a <= 10) | ||
| 2687 | local v | ||
| 2688 | v = function(x) | ||
| 2689 | print(x) | ||
| 2690 | return x | ||
| 2691 | end | ||
| 2692 | print((function() | ||
| 2693 | local _cond_0 = v(2) | ||
| 2694 | if not (v(1) < _cond_0) then | ||
| 2695 | return false | ||
| 2696 | else | ||
| 2697 | return _cond_0 <= v(3) | ||
| 2698 | end | ||
| 2699 | end)()) | ||
| 2700 | print((function() | ||
| 2701 | local _cond_0 = v(2) | ||
| 2702 | if not (v(1) > _cond_0) then | ||
| 2703 | return false | ||
| 2704 | else | ||
| 2705 | return _cond_0 <= v(3) | ||
| 2706 | end | ||
| 2707 | end)()) | ||
| 2708 | local tab = { } | ||
| 2709 | tab[#tab + 1] = "Value" | ||
| 2710 | local tbA = { | ||
| 2711 | 1, | ||
| 2712 | 2, | ||
| 2713 | 3 | ||
| 2714 | } | ||
| 2715 | local tbB = { | ||
| 2716 | 4, | ||
| 2717 | 5, | ||
| 2718 | 6 | ||
| 2719 | } | ||
| 2720 | local _len_0 = #tbA + 1 | ||
| 2721 | for _index_0 = 1, #tbB do | ||
| 2722 | local _elm_0 = tbB[_index_0] | ||
| 2723 | tbA[_len_0], _len_0 = _elm_0, _len_0 + 1 | ||
| 2724 | end | ||
| 2725 | local parts = { | ||
| 2726 | "shoulders", | ||
| 2727 | "knees" | ||
| 2728 | } | ||
| 2729 | local lyrics | ||
| 2730 | do | ||
| 2731 | local _tab_0 = { | ||
| 2732 | "head" | ||
| 2733 | } | ||
| 2734 | local _idx_0 = 1 | ||
| 2735 | for _key_0, _value_0 in pairs(parts) do | ||
| 2736 | if _idx_0 == _key_0 then | ||
| 2737 | _tab_0[#_tab_0 + 1] = _value_0 | ||
| 2738 | _idx_0 = _idx_0 + 1 | ||
| 2739 | else | ||
| 2740 | _tab_0[_key_0] = _value_0 | ||
| 2741 | end | ||
| 2742 | end | ||
| 2743 | _tab_0[#_tab_0 + 1] = "and" | ||
| 2744 | _tab_0[#_tab_0 + 1] = "toes" | ||
| 2745 | lyrics = _tab_0 | ||
| 2746 | end | ||
| 2747 | local copy | ||
| 2748 | do | ||
| 2749 | local _tab_0 = { } | ||
| 2750 | local _idx_0 = 1 | ||
| 2751 | for _key_0, _value_0 in pairs(other) do | ||
| 2752 | if _idx_0 == _key_0 then | ||
| 2753 | _tab_0[#_tab_0 + 1] = _value_0 | ||
| 2754 | _idx_0 = _idx_0 + 1 | ||
| 2755 | else | ||
| 2756 | _tab_0[_key_0] = _value_0 | ||
| 2757 | end | ||
| 2758 | end | ||
| 2759 | copy = _tab_0 | ||
| 2760 | end | ||
| 2761 | local a = { | ||
| 2762 | 1, | ||
| 2763 | 2, | ||
| 2764 | 3, | ||
| 2765 | x = 1 | ||
| 2766 | } | ||
| 2767 | local b = { | ||
| 2768 | 4, | ||
| 2769 | 5, | ||
| 2770 | y = 1 | ||
| 2771 | } | ||
| 2772 | local merge | ||
| 2773 | local _tab_0 = { } | ||
| 2774 | local _idx_0 = 1 | ||
| 2775 | for _key_0, _value_0 in pairs(a) do | ||
| 2776 | if _idx_0 == _key_0 then | ||
| 2777 | _tab_0[#_tab_0 + 1] = _value_0 | ||
| 2778 | _idx_0 = _idx_0 + 1 | ||
| 2779 | else | ||
| 2780 | _tab_0[_key_0] = _value_0 | ||
| 2781 | end | ||
| 2782 | end | ||
| 2783 | local _idx_1 = 1 | ||
| 2784 | for _key_0, _value_0 in pairs(b) do | ||
| 2785 | if _idx_1 == _key_0 then | ||
| 2786 | _tab_0[#_tab_0 + 1] = _value_0 | ||
| 2787 | _idx_1 = _idx_1 + 1 | ||
| 2788 | else | ||
| 2789 | _tab_0[_key_0] = _value_0 | ||
| 2790 | end | ||
| 2791 | end | ||
| 2792 | merge = _tab_0 | ||
| 2793 | local last | ||
| 2794 | do | ||
| 2795 | local _item_0 = data.items | ||
| 2796 | last = _item_0[#_item_0] | ||
| 2797 | end | ||
| 2798 | local second_last | ||
| 2799 | do | ||
| 2800 | local _item_0 = data.items | ||
| 2801 | second_last = _item_0[#_item_0 - 1] | ||
| 2802 | end | ||
| 2803 | local _obj_0 = data.items | ||
| 2804 | _obj_0[#_obj_0] = 1 | ||
| 2805 | local mt = { } | ||
| 2806 | local add | ||
| 2807 | add = function(self, right) | ||
| 2808 | return setmetatable({ | ||
| 2809 | value = self.value + right.value | ||
| 2810 | }, mt) | ||
| 2811 | end | ||
| 2812 | mt.__add = add | ||
| 2813 | local a = setmetatable({ | ||
| 2814 | value = 1 | ||
| 2815 | }, mt) | ||
| 2816 | local b = setmetatable({ | ||
| 2817 | value = 2 | ||
| 2818 | }, { | ||
| 2819 | __add = add | ||
| 2820 | }) | ||
| 2821 | local c = setmetatable({ | ||
| 2822 | value = 3 | ||
| 2823 | }, { | ||
| 2824 | __add = mt.__add | ||
| 2825 | }) | ||
| 2826 | local d = a + b + c | ||
| 2827 | print(d.value) | ||
| 2828 | local _ <close> = setmetatable({ }, { | ||
| 2829 | __close = function() | ||
| 2830 | return print("out of scope") | ||
| 2831 | end | ||
| 2832 | }) | ||
| 2833 | local tb = setmetatable({ }, { | ||
| 2834 | ["value"] = 123 | ||
| 2835 | }) | ||
| 2836 | getmetatable(tb).__index = getmetatable(tb) | ||
| 2837 | print(tb.value) | ||
| 2838 | setmetatable(tb, { | ||
| 2839 | __index = { | ||
| 2840 | item = "hello" | ||
| 2841 | } | ||
| 2842 | }) | ||
| 2843 | print(tb.item) | ||
| 2844 | local item, new, close, getter | ||
| 2845 | do | ||
| 2846 | local _obj_0 = tb | ||
| 2847 | item, new = _obj_0[1], _obj_0.new | ||
| 2848 | do | ||
| 2849 | local _obj_1 = getmetatable(_obj_0) | ||
| 2850 | close, getter = _obj_1.__close, _obj_1.__index | ||
| 2851 | end | ||
| 2852 | end | ||
| 2853 | print(item, new, close, getter) | ||
| 2854 | do | ||
| 2855 | local _obj_0 = func | ||
| 2856 | if _obj_0 ~= nil then | ||
| 2857 | _obj_0() | ||
| 2858 | end | ||
| 2859 | end | ||
| 2860 | print((function() | ||
| 2861 | local _obj_0 = abc | ||
| 2862 | if _obj_0 ~= nil then | ||
| 2863 | local _obj_1 = _obj_0["hello world"] | ||
| 2864 | if _obj_1 ~= nil then | ||
| 2865 | return _obj_1.xyz | ||
| 2866 | end | ||
| 2867 | return nil | ||
| 2868 | end | ||
| 2869 | return nil | ||
| 2870 | end)()) | ||
| 2871 | local x | ||
| 2872 | do | ||
| 2873 | local _obj_0 = tab | ||
| 2874 | if _obj_0 ~= nil then | ||
| 2875 | x = _obj_0.value | ||
| 2876 | end | ||
| 2877 | end | ||
| 2878 | local len = (function() | ||
| 2879 | local _obj_0 = utf8 | ||
| 2880 | if _obj_0 ~= nil then | ||
| 2881 | return _obj_0.len | ||
| 2882 | end | ||
| 2883 | return nil | ||
| 2884 | end)() or (function() | ||
| 2885 | local _obj_0 = string | ||
| 2886 | if _obj_0 ~= nil then | ||
| 2887 | return _obj_0.len | ||
| 2888 | end | ||
| 2889 | return nil | ||
| 2890 | end)() or function(o) | ||
| 2891 | return #o | ||
| 2892 | end | ||
| 2893 | if print and (x ~= nil) then | ||
| 2894 | print(x) | ||
| 2895 | end | ||
| 2896 | local _with_0 = io.open("test.txt", "w") | ||
| 2897 | if _with_0 ~= nil then | ||
| 2898 | _with_0:write("hello") | ||
| 2899 | _with_0:close() | ||
| 2900 | end | ||
| 2901 | print("hello") | ||
| 2902 | print(1, 2) | ||
| 2903 | print(1, 2, 3) | ||
| 2904 | print(render(emit(parse(extract(readFile("example.txt"), language, { }), language)))) | ||
| 2905 | local a, b, c, d | ||
| 2906 | if b ~= nil then | ||
| 2907 | a = b | ||
| 2908 | else | ||
| 2909 | if c ~= nil then | ||
| 2910 | a = c | ||
| 2911 | else | ||
| 2912 | a = d | ||
| 2913 | end | ||
| 2914 | end | ||
| 2915 | func((function() | ||
| 2916 | if a ~= nil then | ||
| 2917 | return a | ||
| 2918 | else | ||
| 2919 | return { } | ||
| 2920 | end | ||
| 2921 | end)()) | ||
| 2922 | if a == nil then | ||
| 2923 | a = false | ||
| 2924 | end | ||
| 2925 | local list = { | ||
| 2926 | 1, | ||
| 2927 | 2, | ||
| 2928 | 3 | ||
| 2929 | } | ||
| 2930 | func({ | ||
| 2931 | 1, | ||
| 2932 | 2, | ||
| 2933 | 3 | ||
| 2934 | }) | ||
| 2935 | local f | ||
| 2936 | f = function() | ||
| 2937 | return { | ||
| 2938 | 1, | ||
| 2939 | 2, | ||
| 2940 | 3 | ||
| 2941 | } | ||
| 2942 | end | ||
| 2943 | local tb = { | ||
| 2944 | name = "abc", | ||
| 2945 | values = { | ||
| 2946 | "a", | ||
| 2947 | "b", | ||
| 2948 | "c" | ||
| 2949 | }, | ||
| 2950 | objects = { | ||
| 2951 | { | ||
| 2952 | name = "a", | ||
| 2953 | value = 1, | ||
| 2954 | func = function(self) | ||
| 2955 | return self.value + 1 | ||
| 2956 | end, | ||
| 2957 | tb = { | ||
| 2958 | fieldA = 1 | ||
| 2959 | } | ||
| 2960 | }, | ||
| 2961 | { | ||
| 2962 | name = "b", | ||
| 2963 | value = 2, | ||
| 2964 | func = function(self) | ||
| 2965 | return self.value + 2 | ||
| 2966 | end, | ||
| 2967 | tb = { } | ||
| 2968 | } | ||
| 2969 | } | ||
| 2970 | } | ||
| 2971 | do | ||
| 2972 | local insert, concat = table.insert, table.concat | ||
| 2973 | local C, Ct, Cmt | ||
| 2974 | do | ||
| 2975 | local _obj_0 = require("lpeg") | ||
| 2976 | C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt | ||
| 2977 | end | ||
| 2978 | local x, y, z | ||
| 2979 | do | ||
| 2980 | local _obj_0 = require('mymodule') | ||
| 2981 | x, y, z = _obj_0.x, _obj_0.y, _obj_0.z | ||
| 2982 | end | ||
| 2983 | local a, b, c | ||
| 2984 | local _obj_0 = require('module') | ||
| 2985 | a, b, c = _obj_0.a, _obj_0.b, _obj_0.c | ||
| 2986 | end | ||
| 2987 | do | ||
| 2988 | local module = require('module') | ||
| 2989 | local module_x = require('module_x') | ||
| 2990 | local d_a_s_h_e_s = require("d-a-s-h-e-s") | ||
| 2991 | local part = require("module.part") | ||
| 2992 | end | ||
| 2993 | do | ||
| 2994 | local PlayerModule = require("player") | ||
| 2995 | local C, Ct, Cmt | ||
| 2996 | do | ||
| 2997 | local _obj_0 = require("lpeg") | ||
| 2998 | C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt | ||
| 2999 | end | ||
| 3000 | local one, two, ch | ||
| 3001 | local _obj_0 = require("export") | ||
| 3002 | one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] | ||
| 3003 | end | ||
| 3004 | do | ||
| 3005 | local tostring <const> = tostring | ||
| 3006 | local concat <const> = table.concat | ||
| 3007 | print(concat({ | ||
| 3008 | "a", | ||
| 3009 | tostring(1) | ||
| 3010 | })) | ||
| 3011 | end | ||
| 3012 | do | ||
| 3013 | local print <const> = print | ||
| 3014 | local math <const> = math | ||
| 3015 | print("hello") | ||
| 3016 | math.random(3) | ||
| 3017 | end | ||
| 3018 | do | ||
| 3019 | local print <const> = print | ||
| 3020 | print(FLAG) | ||
| 3021 | FLAG = 123 | ||
| 3022 | end | ||
| 3023 | local _module_0 = { } | ||
| 3024 | local a, b, c = 1, 2, 3 | ||
| 3025 | _module_0["a"], _module_0["b"], _module_0["c"] = a, b, c | ||
| 3026 | local cool = "cat" | ||
| 3027 | _module_0["cool"] = cool | ||
| 3028 | local What | ||
| 3029 | if this then | ||
| 3030 | What = "abc" | ||
| 3031 | else | ||
| 3032 | What = "def" | ||
| 3033 | end | ||
| 3034 | _module_0["What"] = What | ||
| 3035 | local y | ||
| 3036 | y = function() | ||
| 3037 | local hallo = 3434 | ||
| 3038 | end | ||
| 3039 | _module_0["y"] = y | ||
| 3040 | local Something | ||
| 3041 | local _class_0 | ||
| 3042 | local _base_0 = { | ||
| 3043 | umm = "cool" | ||
| 3044 | } | ||
| 3045 | if _base_0.__index == nil then | ||
| 3046 | _base_0.__index = _base_0 | ||
| 3047 | end | ||
| 3048 | _class_0 = setmetatable({ | ||
| 3049 | __init = function() end, | ||
| 3050 | __base = _base_0, | ||
| 3051 | __name = "Something" | ||
| 3052 | }, { | ||
| 3053 | __index = _base_0, | ||
| 3054 | __call = function(cls, ...) | ||
| 3055 | local _self_0 = setmetatable({ }, _base_0) | ||
| 3056 | cls.__init(_self_0, ...) | ||
| 3057 | return _self_0 | ||
| 3058 | end | ||
| 3059 | }) | ||
| 3060 | _base_0.__class = _class_0 | ||
| 3061 | Something = _class_0 | ||
| 3062 | _module_0["Something"] = Something | ||
| 3063 | return _module_0 | ||
| 3064 | local _module_0 = { } | ||
| 3065 | local loadstring, tolua | ||
| 3066 | do | ||
| 3067 | local _obj_0 = yue | ||
| 3068 | loadstring, tolua = _obj_0.loadstring, _obj_0.to_lua | ||
| 3069 | end | ||
| 3070 | _module_0["loadstring"], _module_0["tolua"] = loadstring, tolua | ||
| 3071 | local fieldA = tb.itemA.fieldA | ||
| 3072 | if fieldA == nil then | ||
| 3073 | fieldA = 'default' | ||
| 3074 | end | ||
| 3075 | _module_0["fieldA"] = fieldA | ||
| 3076 | return _module_0 | ||
| 3077 | local _module_0 = setmetatable({ }, { }) | ||
| 3078 | _module_0.itemA = tb | ||
| 3079 | getmetatable(_module_0).__index = items | ||
| 3080 | _module_0["a-b-c"] = 123 | ||
| 3081 | return _module_0 | ||
| 3082 | local _module_0 = { } | ||
| 3083 | local d, e, f = 3, 2, 1 | ||
| 3084 | _module_0[#_module_0 + 1] = d | ||
| 3085 | _module_0[#_module_0 + 1] = e | ||
| 3086 | _module_0[#_module_0 + 1] = f | ||
| 3087 | if this then | ||
| 3088 | _module_0[#_module_0 + 1] = 123 | ||
| 3089 | else | ||
| 3090 | _module_0[#_module_0 + 1] = 456 | ||
| 3091 | end | ||
| 3092 | local _with_0 = tmp | ||
| 3093 | local j = 2000 | ||
| 3094 | _module_0[#_module_0 + 1] = _with_0 | ||
| 3095 | return _module_0 | ||
| 3096 | local _module_0 = nil | ||
| 3097 | _module_0 = function() | ||
| 3098 | print("hello") | ||
| 3099 | return 123 | ||
| 3100 | end | ||
| 3101 | return _module_0 | ||
| 3102 | local hello = "world" | ||
| 3103 | local a, b, c = 1, 2, 3 | ||
| 3104 | hello = 123 | ||
| 3105 | local x = 1 | ||
| 3106 | x = x + 1 | ||
| 3107 | x = x - 1 | ||
| 3108 | x = x * 10 | ||
| 3109 | x = x / 10 | ||
| 3110 | x = x % 10 | ||
| 3111 | local s = s .. "world" | ||
| 3112 | local arg = arg or "default value" | ||
| 3113 | local a = 0 | ||
| 3114 | local b = 0 | ||
| 3115 | local c = 0 | ||
| 3116 | local d = 0 | ||
| 3117 | local e = 0 | ||
| 3118 | local x = f() | ||
| 3119 | local y = x | ||
| 3120 | local z = x | ||
| 3121 | do | ||
| 3122 | local a = 1 | ||
| 3123 | local x, y, z | ||
| 3124 | print("forward declare all variables as locals") | ||
| 3125 | x = function() | ||
| 3126 | return 1 + y + z | ||
| 3127 | end | ||
| 3128 | y, z = 2, 3 | ||
| 3129 | instance = Item:new() | ||
| 3130 | end | ||
| 3131 | do | ||
| 3132 | local X = 1 | ||
| 3133 | local B | ||
| 3134 | print("only forward declare upper case variables") | ||
| 3135 | local a = 1 | ||
| 3136 | B = 2 | ||
| 3137 | end | ||
| 3138 | do | ||
| 3139 | a = 1 | ||
| 3140 | print("declare all variables as globals") | ||
| 3141 | x = function() | ||
| 3142 | return 1 + y + z | ||
| 3143 | end | ||
| 3144 | y, z = 2, 3 | ||
| 3145 | end | ||
| 3146 | do | ||
| 3147 | X = 1 | ||
| 3148 | print("only declare upper case variables as globals") | ||
| 3149 | local a = 1 | ||
| 3150 | B = 2 | ||
| 3151 | local Temp = "a local value" | ||
| 3152 | end | ||
| 3153 | local thing = { | ||
| 3154 | 1, | ||
| 3155 | 2 | ||
| 3156 | } | ||
| 3157 | local a, b = thing[1], thing[2] | ||
| 3158 | print(a, b) | ||
| 3159 | local obj = { | ||
| 3160 | hello = "world", | ||
| 3161 | day = "tuesday", | ||
| 3162 | length = 20 | ||
| 3163 | } | ||
| 3164 | local hello, the_day = obj.hello, obj.day | ||
| 3165 | print(hello, the_day) | ||
| 3166 | local day = obj.day | ||
| 3167 | local obj2 = { | ||
| 3168 | numbers = { | ||
| 3169 | 1, | ||
| 3170 | 2, | ||
| 3171 | 3, | ||
| 3172 | 4 | ||
| 3173 | }, | ||
| 3174 | properties = { | ||
| 3175 | color = "green", | ||
| 3176 | height = 13.5 | ||
| 3177 | } | ||
| 3178 | } | ||
| 3179 | local first, second = obj2.numbers[1], obj2.numbers[2] | ||
| 3180 | print(first, second, color) | ||
| 3181 | local first, second, color | ||
| 3182 | local _obj_0 = obj2 | ||
| 3183 | first, second, color = _obj_0.numbers[1], _obj_0.numbers[2], _obj_0.properties.color | ||
| 3184 | local concat, insert | ||
| 3185 | local _obj_0 = table | ||
| 3186 | concat, insert = _obj_0.concat, _obj_0.insert | ||
| 3187 | local mix, max, rand | ||
| 3188 | local _obj_0 = math | ||
| 3189 | mix, max, rand = _obj_0.mix, _obj_0.max, _obj_0.random | ||
| 3190 | local name, job | ||
| 3191 | local _obj_0 = person | ||
| 3192 | name, job = _obj_0.name, _obj_0.job | ||
| 3193 | if name == nil then | ||
| 3194 | name = "nameless" | ||
| 3195 | end | ||
| 3196 | if job == nil then | ||
| 3197 | job = "jobless" | ||
| 3198 | end | ||
| 3199 | local two, four | ||
| 3200 | local _obj_0 = items | ||
| 3201 | two, four = _obj_0[2], _obj_0[4] | ||
| 3202 | local orders = { | ||
| 3203 | "first", | ||
| 3204 | "second", | ||
| 3205 | "third", | ||
| 3206 | "fourth", | ||
| 3207 | "last" | ||
| 3208 | } | ||
| 3209 | local first, bulk, last = orders[1], (function() | ||
| 3210 | local _accum_0 = { } | ||
| 3211 | local _len_0 = 1 | ||
| 3212 | local _max_0 = #orders + -2 + 1 | ||
| 3213 | for _index_0 = 2, _max_0 do | ||
| 3214 | local _item_0 = orders[_index_0] | ||
| 3215 | _accum_0[_len_0] = _item_0 | ||
| 3216 | _len_0 = _len_0 + 1 | ||
| 3217 | end | ||
| 3218 | return _accum_0 | ||
| 3219 | end)(), orders[#orders] | ||
| 3220 | print(first) | ||
| 3221 | print(bulk) | ||
| 3222 | print(last) | ||
| 3223 | local first, rest | ||
| 3224 | do | ||
| 3225 | local _obj_0 = orders | ||
| 3226 | first, rest = _obj_0[1], (function() | ||
| 3227 | local _accum_0 = { } | ||
| 3228 | local _len_0 = 1 | ||
| 3229 | local _max_0 = #_obj_0 | ||
| 3230 | for _index_0 = 2, _max_0 do | ||
| 3231 | local _item_0 = _obj_0[_index_0] | ||
| 3232 | _accum_0[_len_0] = _item_0 | ||
| 3233 | _len_0 = _len_0 + 1 | ||
| 3234 | end | ||
| 3235 | return _accum_0 | ||
| 3236 | end)() | ||
| 3237 | end | ||
| 3238 | local start, last | ||
| 3239 | do | ||
| 3240 | local _obj_0 = orders | ||
| 3241 | start, last = (function() | ||
| 3242 | local _accum_0 = { } | ||
| 3243 | local _len_0 = 1 | ||
| 3244 | local _max_0 = #_obj_0 + -2 + 1 | ||
| 3245 | for _index_0 = 1, _max_0 do | ||
| 3246 | local _item_0 = _obj_0[_index_0] | ||
| 3247 | _accum_0[_len_0] = _item_0 | ||
| 3248 | _len_0 = _len_0 + 1 | ||
| 3249 | end | ||
| 3250 | return _accum_0 | ||
| 3251 | end)(), _obj_0[#_obj_0] | ||
| 3252 | end | ||
| 3253 | local _obj_0 = orders | ||
| 3254 | first, last = _obj_0[1], _obj_0[#_obj_0] | ||
| 3255 | local tuples = { | ||
| 3256 | { | ||
| 3257 | "hello", | ||
| 3258 | "world" | ||
| 3259 | }, | ||
| 3260 | { | ||
| 3261 | "egg", | ||
| 3262 | "head" | ||
| 3263 | } | ||
| 3264 | } | ||
| 3265 | for _index_0 = 1, #tuples do | ||
| 3266 | local _des_0 = tuples[_index_0] | ||
| 3267 | local left, right = _des_0[1], _des_0[2] | ||
| 3268 | print(left, right) | ||
| 3269 | end | ||
| 3270 | local user = database.find_user("moon") | ||
| 3271 | if user then | ||
| 3272 | print(user.name) | ||
| 3273 | end | ||
| 3274 | local hello = os.getenv("hello") | ||
| 3275 | if hello then | ||
| 3276 | print("You have hello", hello) | ||
| 3277 | else | ||
| 3278 | local world = os.getenv("world") | ||
| 3279 | if world then | ||
| 3280 | print("you have world", world) | ||
| 3281 | else | ||
| 3282 | print("nothing :(") | ||
| 3283 | end | ||
| 3284 | end | ||
| 3285 | do | ||
| 3286 | local success, result = pcall(function() | ||
| 3287 | return "get result without problems" | ||
| 3288 | end) | ||
| 3289 | if success then | ||
| 3290 | print(result) | ||
| 3291 | end | ||
| 3292 | end | ||
| 3293 | print("OK") | ||
| 3294 | repeat | ||
| 3295 | local byte = stream:read_one() | ||
| 3296 | if byte then | ||
| 3297 | print(byte) | ||
| 3298 | else | ||
| 3299 | break | ||
| 3300 | end | ||
| 3301 | until false | ||
| 3302 | local list = { | ||
| 3303 | 1, | ||
| 3304 | 2, | ||
| 3305 | 3, | ||
| 3306 | 4, | ||
| 3307 | 5 | ||
| 3308 | } | ||
| 3309 | local fn | ||
| 3310 | fn = function(ok) | ||
| 3311 | return ok, table.unpack(list) | ||
| 3312 | end | ||
| 3313 | (function(_arg_0, ...) | ||
| 3314 | local ok = _arg_0 | ||
| 3315 | local count = select('#', ...) | ||
| 3316 | local first = select(1, ...) | ||
| 3317 | return print(ok, count, first) | ||
| 3318 | end)(fn(true)) | ||
| 3319 | local a = 1 | ||
| 3320 | local b = 2 | ||
| 3321 | print(a + b) | ||
| 3322 | Rx.Observable.fromRange(1, 8):filter(function(x) | ||
| 3323 | return x % 2 == 0 | ||
| 3324 | end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) | ||
| 3325 | return value .. '!' | ||
| 3326 | end):subscribe(print) | ||
| 3327 | local str = strA .. strB .. strC | ||
| 3328 | func(3000, "192.168.1.1") | ||
| 3329 | xpcall(function() | ||
| 3330 | return func(1, 2, 3) | ||
| 3331 | end, function(err) | ||
| 3332 | return print(yue.traceback(err)) | ||
| 3333 | end) | ||
| 3334 | local success, result = xpcall(function() | ||
| 3335 | return func(1, 2, 3) | ||
| 3336 | end, function(err) | ||
| 3337 | return yue.traceback(err) | ||
| 3338 | end) | ||
| 3339 | xpcall(function() | ||
| 3340 | return func(1, 2, 3) | ||
| 3341 | end, function(err) | ||
| 3342 | return print(yue.traceback(err)) | ||
| 3343 | end) | ||
| 3344 | success, result = pcall(function() | ||
| 3345 | return func(1, 2, 3) | ||
| 3346 | end) | ||
| 3347 | pcall(function() | ||
| 3348 | print("trying") | ||
| 3349 | return func(1, 2, 3) | ||
| 3350 | end) | ||
| 3351 | success, result = xpcall(function() | ||
| 3352 | return func(1, 2, 3) | ||
| 3353 | end, function(err) | ||
| 3354 | return print(yue.traceback(err)) | ||
| 3355 | end) | ||
| 3356 | if success then | ||
| 3357 | print(result) | ||
| 3358 | end | ||
| 3359 | local a, b, c | ||
| 3360 | do | ||
| 3361 | local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function() | ||
| 3362 | return func() | ||
| 3363 | end) | ||
| 3364 | if _ok_0 then | ||
| 3365 | a, b, c = _ret_0, _ret_1, _ret_2 | ||
| 3366 | end | ||
| 3367 | end | ||
| 3368 | do | ||
| 3369 | local _exp_0 = ((function() | ||
| 3370 | return (function(_arg_0, ...) | ||
| 3371 | local _ok_0 = _arg_0 | ||
| 3372 | if _ok_0 then | ||
| 3373 | return ... | ||
| 3374 | end | ||
| 3375 | end)(pcall(function() | ||
| 3376 | return func() | ||
| 3377 | end)) | ||
| 3378 | end)()) | ||
| 3379 | if _exp_0 ~= nil then | ||
| 3380 | a = _exp_0 | ||
| 3381 | else | ||
| 3382 | a = "default" | ||
| 3383 | end | ||
| 3384 | end | ||
| 3385 | f((function() | ||
| 3386 | return (function(_arg_0, ...) | ||
| 3387 | local _ok_0 = _arg_0 | ||
| 3388 | if _ok_0 then | ||
| 3389 | return ... | ||
| 3390 | end | ||
| 3391 | end)(pcall(function() | ||
| 3392 | return func() | ||
| 3393 | end)) | ||
| 3394 | end)()) | ||
| 3395 | f((function() | ||
| 3396 | return (function(_arg_0, ...) | ||
| 3397 | local _ok_0 = _arg_0 | ||
| 3398 | if _ok_0 then | ||
| 3399 | return ... | ||
| 3400 | end | ||
| 3401 | end)(xpcall(function() | ||
| 3402 | print(123) | ||
| 3403 | return func() | ||
| 3404 | end, function(e) | ||
| 3405 | print(e) | ||
| 3406 | return e | ||
| 3407 | end)) | ||
| 3408 | end)()) | ||
| 3409 | local a <const> = 123 | ||
| 3410 | local _ <close> = setmetatable({ }, { | ||
| 3411 | __close = function() | ||
| 3412 | return print("Out of scope.") | ||
| 3413 | end | ||
| 3414 | }) | ||
| 3415 | local a, b, c, d | ||
| 3416 | local _obj_0 = tb | ||
| 3417 | a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] | ||
| 3418 | Constant = 123 | ||
| 3419 | local some_string = "Here is a string\n that has a line break in it." | ||
| 3420 | print("I am " .. tostring(math.random() * 100) .. "% sure.") | ||
| 3421 | local integer = 1000000 | ||
| 3422 | local hex = 0xEFBBBF | ||
| 3423 | local binary = 19 | ||
| 3424 | local str = "key: value\nlist:\n - item1\n - " .. tostring(expr) | ||
| 3425 | local fn | ||
| 3426 | fn = function() | ||
| 3427 | local str = "foo:\n bar: baz" | ||
| 3428 | return str | ||
| 3429 | end | ||
| 3430 | local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'" | ||
| 3431 | local my_function | ||
| 3432 | my_function = function() end | ||
| 3433 | my_function() | ||
| 3434 | local func_a | ||
| 3435 | func_a = function() | ||
| 3436 | return print("hello world") | ||
| 3437 | end | ||
| 3438 | local func_b | ||
| 3439 | func_b = function() | ||
| 3440 | local value = 100 | ||
| 3441 | return print("The value:", value) | ||
| 3442 | end | ||
| 3443 | func_a() | ||
| 3444 | func_b() | ||
| 3445 | local sum | ||
| 3446 | sum = function(x, y) | ||
| 3447 | return print("sum", x + y) | ||
| 3448 | end | ||
| 3449 | sum(10, 20) | ||
| 3450 | print(sum(10, 20)) | ||
| 3451 | a(b(c("a", "b", "c"))) | ||
| 3452 | print("x:", sum(10, 20), "y:", sum(30, 40)) | ||
| 3453 | local sum | ||
| 3454 | sum = function(x, y) | ||
| 3455 | return x + y | ||
| 3456 | end | ||
| 3457 | print("The sum is ", sum(10, 20)) | ||
| 3458 | local sum | ||
| 3459 | sum = function(x, y) | ||
| 3460 | return x + y | ||
| 3461 | end | ||
| 3462 | local mystery | ||
| 3463 | mystery = function(x, y) | ||
| 3464 | return x + y, x - y | ||
| 3465 | end | ||
| 3466 | local a, b = mystery(10, 20) | ||
| 3467 | local func | ||
| 3468 | func = function(self, num) | ||
| 3469 | return self.value + num | ||
| 3470 | end | ||
| 3471 | local my_function | ||
| 3472 | my_function = function(name, height) | ||
| 3473 | if name == nil then | ||
| 3474 | name = "something" | ||
| 3475 | end | ||
| 3476 | if height == nil then | ||
| 3477 | height = 100 | ||
| 3478 | end | ||
| 3479 | print("Hello I am", name) | ||
| 3480 | return print("My height is", height) | ||
| 3481 | end | ||
| 3482 | local some_args | ||
| 3483 | some_args = function(x, y) | ||
| 3484 | if x == nil then | ||
| 3485 | x = 100 | ||
| 3486 | end | ||
| 3487 | if y == nil then | ||
| 3488 | y = x + 1000 | ||
| 3489 | end | ||
| 3490 | return print(x + y) | ||
| 3491 | end | ||
| 3492 | local a = x - 10 | ||
| 3493 | local b = x - 10 | ||
| 3494 | local c = x(-y) | ||
| 3495 | local d = x - z | ||
| 3496 | local x = func("hello") + 100 | ||
| 3497 | local y = func("hello" + 100) | ||
| 3498 | my_func(5, 4, 3, 8, 9, 10) | ||
| 3499 | cool_func(1, 2, 3, 4, 5, 6, 7, 8) | ||
| 3500 | my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4) | ||
| 3501 | local x = { | ||
| 3502 | 1, | ||
| 3503 | 2, | ||
| 3504 | 3, | ||
| 3505 | 4, | ||
| 3506 | a_func(4, 5, 5, 6), | ||
| 3507 | 8, | ||
| 3508 | 9, | ||
| 3509 | 10 | ||
| 3510 | } | ||
| 3511 | local y = { | ||
| 3512 | my_func(1, 2, 3, 4, 5), | ||
| 3513 | 5, | ||
| 3514 | 6, | ||
| 3515 | 7 | ||
| 3516 | } | ||
| 3517 | if func(1, 2, 3, "hello", "world") then | ||
| 3518 | print("hello") | ||
| 3519 | print("I am inside if") | ||
| 3520 | end | ||
| 3521 | if func(1, 2, 3, "hello", "world") then | ||
| 3522 | print("hello") | ||
| 3523 | print("I am inside if") | ||
| 3524 | end | ||
| 3525 | local f1 | ||
| 3526 | f1 = function(_arg_0) | ||
| 3527 | local a, b, c | ||
| 3528 | a, b, c = _arg_0.a, _arg_0.b, _arg_0.c | ||
| 3529 | return print(a, b, c) | ||
| 3530 | end | ||
| 3531 | f1({ | ||
| 3532 | a = 1, | ||
| 3533 | b = "2", | ||
| 3534 | c = { } | ||
| 3535 | }) | ||
| 3536 | local f2 | ||
| 3537 | f2 = function(_arg_0, c) | ||
| 3538 | local a1, b | ||
| 3539 | a1, b = _arg_0.a, _arg_0.b | ||
| 3540 | if a1 == nil then | ||
| 3541 | a1 = 123 | ||
| 3542 | end | ||
| 3543 | if b == nil then | ||
| 3544 | b = 'abc' | ||
| 3545 | end | ||
| 3546 | if c == nil then | ||
| 3547 | c = { } | ||
| 3548 | end | ||
| 3549 | end | ||
| 3550 | print(a1, b, c) | ||
| 3551 | local arg1 = { | ||
| 3552 | a = 0 | ||
| 3553 | } | ||
| 3554 | f2(arg1, arg2) | ||
| 3555 | local findFirstEven | ||
| 3556 | findFirstEven = function(list) | ||
| 3557 | for _index_0 = 1, #list do | ||
| 3558 | local item = list[_index_0] | ||
| 3559 | if type(item) == "table" then | ||
| 3560 | for _index_1 = 1, #item do | ||
| 3561 | local sub = item[_index_1] | ||
| 3562 | if sub % 2 == 0 then | ||
| 3563 | return sub | ||
| 3564 | end | ||
| 3565 | end | ||
| 3566 | end | ||
| 3567 | end | ||
| 3568 | return nil | ||
| 3569 | end | ||
| 3570 | local findFirstEven | ||
| 3571 | findFirstEven = function(list) | ||
| 3572 | for _index_0 = 1, #list do | ||
| 3573 | local item = list[_index_0] | ||
| 3574 | if type(item) == "table" then | ||
| 3575 | for _index_1 = 1, #item do | ||
| 3576 | local sub = item[_index_1] | ||
| 3577 | if sub % 2 == 0 then | ||
| 3578 | return sub | ||
| 3579 | end | ||
| 3580 | end | ||
| 3581 | end | ||
| 3582 | end | ||
| 3583 | return nil | ||
| 3584 | end | ||
| 3585 | local f | ||
| 3586 | f = function(...) | ||
| 3587 | local t = { | ||
| 3588 | n = select("#", ...), | ||
| 3589 | ... | ||
| 3590 | } | ||
| 3591 | print("argument count:", t.n) | ||
| 3592 | print("table length:", #t) | ||
| 3593 | for i = 1, t.n do | ||
| 3594 | print(t[i]) | ||
| 3595 | end | ||
| 3596 | end | ||
| 3597 | f(1, 2, 3) | ||
| 3598 | f("a", "b", "c", "d") | ||
| 3599 | f() | ||
| 3600 | local process | ||
| 3601 | process = function(...) | ||
| 3602 | local args = { | ||
| 3603 | n = select("#", ...), | ||
| 3604 | ... | ||
| 3605 | } | ||
| 3606 | local sum = 0 | ||
| 3607 | for i = 1, args.n do | ||
| 3608 | if args[i] ~= nil and type(args[i]) == "number" then | ||
| 3609 | sum = sum + args[i] | ||
| 3610 | end | ||
| 3611 | end | ||
| 3612 | return sum | ||
| 3613 | end | ||
| 3614 | process(1, nil, 3, nil, 5) | ||
| 3615 | f(function() | ||
| 3616 | return print("hello") | ||
| 3617 | end) | ||
| 3618 | f(function(self) | ||
| 3619 | return print(self.value) | ||
| 3620 | end) | ||
| 3621 | map(function(x) | ||
| 3622 | return x * 2 | ||
| 3623 | end, { | ||
| 3624 | 1, | ||
| 3625 | 2, | ||
| 3626 | 3 | ||
| 3627 | }) | ||
| 3628 | local result, msg | ||
| 3629 | do | ||
| 3630 | result, msg = readAsync("filename.txt", function(data) | ||
| 3631 | print(data) | ||
| 3632 | return processAsync(data, function(info) | ||
| 3633 | return check(info) | ||
| 3634 | end) | ||
| 3635 | end) | ||
| 3636 | end | ||
| 3637 | print(result, msg) | ||
| 3638 | local some_values = { | ||
| 3639 | 1, | ||
| 3640 | 2, | ||
| 3641 | 3, | ||
| 3642 | 4 | ||
| 3643 | } | ||
| 3644 | local some_values = { | ||
| 3645 | name = "Bill", | ||
| 3646 | age = 200, | ||
| 3647 | ["favorite food"] = "rice" | ||
| 3648 | } | ||
| 3649 | local profile = { | ||
| 3650 | height = "4 feet", | ||
| 3651 | shoe_size = 13, | ||
| 3652 | favorite_foods = { | ||
| 3653 | "ice cream", | ||
| 3654 | "donuts" | ||
| 3655 | } | ||
| 3656 | } | ||
| 3657 | local values = { | ||
| 3658 | 1, | ||
| 3659 | 2, | ||
| 3660 | 3, | ||
| 3661 | 4, | ||
| 3662 | 5, | ||
| 3663 | 6, | ||
| 3664 | 7, | ||
| 3665 | 8, | ||
| 3666 | name = "superman", | ||
| 3667 | occupation = "crime fighting" | ||
| 3668 | } | ||
| 3669 | my_function({ | ||
| 3670 | dance = "Tango", | ||
| 3671 | partner = "none" | ||
| 3672 | }) | ||
| 3673 | local y = { | ||
| 3674 | type = "dog", | ||
| 3675 | legs = 4, | ||
| 3676 | tails = 1 | ||
| 3677 | } | ||
| 3678 | local tbl = { | ||
| 3679 | ["do"] = "something", | ||
| 3680 | ["end"] = "hunger" | ||
| 3681 | } | ||
| 3682 | local hair = "golden" | ||
| 3683 | local height = 200 | ||
| 3684 | local person = { | ||
| 3685 | hair = hair, | ||
| 3686 | height = height, | ||
| 3687 | shoe_size = 40 | ||
| 3688 | } | ||
| 3689 | print_table({ | ||
| 3690 | hair = hair, | ||
| 3691 | height = height | ||
| 3692 | }) | ||
| 3693 | local t = { | ||
| 3694 | [1 + 2] = "hello", | ||
| 3695 | ["hello world"] = true | ||
| 3696 | } | ||
| 3697 | local some_values = { | ||
| 3698 | 1, | ||
| 3699 | 2, | ||
| 3700 | 3, | ||
| 3701 | 4 | ||
| 3702 | } | ||
| 3703 | local list_with_one_element = { | ||
| 3704 | 1 | ||
| 3705 | } | ||
| 3706 | local items = { | ||
| 3707 | 1, | ||
| 3708 | 2, | ||
| 3709 | 3, | ||
| 3710 | 4 | ||
| 3711 | } | ||
| 3712 | local doubled | ||
| 3713 | local _accum_0 = { } | ||
| 3714 | local _len_0 = 1 | ||
| 3715 | for i, item in ipairs(items) do | ||
| 3716 | _accum_0[_len_0] = item * 2 | ||
| 3717 | _len_0 = _len_0 + 1 | ||
| 3718 | end | ||
| 3719 | doubled = _accum_0 | ||
| 3720 | local slice | ||
| 3721 | local _accum_0 = { } | ||
| 3722 | local _len_0 = 1 | ||
| 3723 | for i, item in ipairs(items) do | ||
| 3724 | if i > 1 and i < 3 then | ||
| 3725 | _accum_0[_len_0] = item | ||
| 3726 | _len_0 = _len_0 + 1 | ||
| 3727 | end | ||
| 3728 | end | ||
| 3729 | slice = _accum_0 | ||
| 3730 | local doubled | ||
| 3731 | local _accum_0 = { } | ||
| 3732 | local _len_0 = 1 | ||
| 3733 | local _list_0 = items | ||
| 3734 | for _index_0 = 1, #_list_0 do | ||
| 3735 | local item = _list_0[_index_0] | ||
| 3736 | _accum_0[_len_0] = item * 2 | ||
| 3737 | _len_0 = _len_0 + 1 | ||
| 3738 | end | ||
| 3739 | doubled = _accum_0 | ||
| 3740 | local data = { | ||
| 3741 | a = { | ||
| 3742 | 1, | ||
| 3743 | 2, | ||
| 3744 | 3 | ||
| 3745 | }, | ||
| 3746 | b = { | ||
| 3747 | 4, | ||
| 3748 | 5, | ||
| 3749 | 6 | ||
| 3750 | } | ||
| 3751 | } | ||
| 3752 | local flat | ||
| 3753 | local _accum_0 = { } | ||
| 3754 | for k, v in pairs(data) do | ||
| 3755 | local _len_0 = #_accum_0 + 1 | ||
| 3756 | for _index_0 = 1, #v do | ||
| 3757 | local _elm_0 = v[_index_0] | ||
| 3758 | _accum_0[_len_0], _len_0 = _elm_0, _len_0 + 1 | ||
| 3759 | end | ||
| 3760 | end | ||
| 3761 | flat = _accum_0 | ||
| 3762 | local x_coords = { | ||
| 3763 | 4, | ||
| 3764 | 5, | ||
| 3765 | 6, | ||
| 3766 | 7 | ||
| 3767 | } | ||
| 3768 | local y_coords = { | ||
| 3769 | 9, | ||
| 3770 | 2, | ||
| 3771 | 3 | ||
| 3772 | } | ||
| 3773 | local points | ||
| 3774 | local _accum_0 = { } | ||
| 3775 | local _len_0 = 1 | ||
| 3776 | for _index_0 = 1, #x_coords do | ||
| 3777 | local x = x_coords[_index_0] | ||
| 3778 | for _index_1 = 1, #y_coords do | ||
| 3779 | local y = y_coords[_index_1] | ||
| 3780 | _accum_0[_len_0] = { | ||
| 3781 | x, | ||
| 3782 | y | ||
| 3783 | } | ||
| 3784 | _len_0 = _len_0 + 1 | ||
| 3785 | end | ||
| 3786 | end | ||
| 3787 | points = _accum_0 | ||
| 3788 | local evens | ||
| 3789 | local _accum_0 = { } | ||
| 3790 | local _len_0 = 1 | ||
| 3791 | for i = 1, 100 do | ||
| 3792 | if i % 2 == 0 then | ||
| 3793 | _accum_0[_len_0] = i | ||
| 3794 | _len_0 = _len_0 + 1 | ||
| 3795 | end | ||
| 3796 | end | ||
| 3797 | evens = _accum_0 | ||
| 3798 | local thing = { | ||
| 3799 | color = "red", | ||
| 3800 | name = "fast", | ||
| 3801 | width = 123 | ||
| 3802 | } | ||
| 3803 | local thing_copy | ||
| 3804 | local _tbl_0 = { } | ||
| 3805 | for k, v in pairs(thing) do | ||
| 3806 | _tbl_0[k] = v | ||
| 3807 | end | ||
| 3808 | thing_copy = _tbl_0 | ||
| 3809 | local no_color | ||
| 3810 | local _tbl_0 = { } | ||
| 3811 | for k, v in pairs(thing) do | ||
| 3812 | if k ~= "color" then | ||
| 3813 | _tbl_0[k] = v | ||
| 3814 | end | ||
| 3815 | end | ||
| 3816 | no_color = _tbl_0 | ||
| 3817 | local numbers = { | ||
| 3818 | 1, | ||
| 3819 | 2, | ||
| 3820 | 3, | ||
| 3821 | 4 | ||
| 3822 | } | ||
| 3823 | local sqrts | ||
| 3824 | local _tbl_0 = { } | ||
| 3825 | for _index_0 = 1, #numbers do | ||
| 3826 | local i = numbers[_index_0] | ||
| 3827 | _tbl_0[i] = math.sqrt(i) | ||
| 3828 | end | ||
| 3829 | sqrts = _tbl_0 | ||
| 3830 | local tuples = { | ||
| 3831 | { | ||
| 3832 | "hello", | ||
| 3833 | "world" | ||
| 3834 | }, | ||
| 3835 | { | ||
| 3836 | "foo", | ||
| 3837 | "bar" | ||
| 3838 | } | ||
| 3839 | } | ||
| 3840 | local tbl | ||
| 3841 | local _tbl_0 = { } | ||
| 3842 | for _index_0 = 1, #tuples do | ||
| 3843 | local tuple = tuples[_index_0] | ||
| 3844 | local _key_0, _val_0 = unpack(tuple) | ||
| 3845 | _tbl_0[_key_0] = _val_0 | ||
| 3846 | end | ||
| 3847 | tbl = _tbl_0 | ||
| 3848 | local slice | ||
| 3849 | local _accum_0 = { } | ||
| 3850 | local _len_0 = 1 | ||
| 3851 | local _list_0 = items | ||
| 3852 | for _index_0 = 1, 5 do | ||
| 3853 | local item = _list_0[_index_0] | ||
| 3854 | _accum_0[_len_0] = item | ||
| 3855 | _len_0 = _len_0 + 1 | ||
| 3856 | end | ||
| 3857 | slice = _accum_0 | ||
| 3858 | local slice | ||
| 3859 | local _accum_0 = { } | ||
| 3860 | local _len_0 = 1 | ||
| 3861 | local _list_0 = items | ||
| 3862 | local _max_0 = #_list_0 | ||
| 3863 | for _index_0 = 2, _max_0 do | ||
| 3864 | local item = _list_0[_index_0] | ||
| 3865 | _accum_0[_len_0] = item | ||
| 3866 | _len_0 = _len_0 + 1 | ||
| 3867 | end | ||
| 3868 | slice = _accum_0 | ||
| 3869 | local slice | ||
| 3870 | local _accum_0 = { } | ||
| 3871 | local _len_0 = 1 | ||
| 3872 | local _list_0 = items | ||
| 3873 | local _max_0 = #_list_0 | ||
| 3874 | for _index_0 = 1, _max_0, 2 do | ||
| 3875 | local item = _list_0[_index_0] | ||
| 3876 | _accum_0[_len_0] = item | ||
| 3877 | _len_0 = _len_0 + 1 | ||
| 3878 | end | ||
| 3879 | slice = _accum_0 | ||
| 3880 | local slice | ||
| 3881 | local _accum_0 = { } | ||
| 3882 | local _len_0 = 1 | ||
| 3883 | local _list_0 = items | ||
| 3884 | local _min_0 = #_list_0 + -4 + 1 | ||
| 3885 | local _max_0 = #_list_0 + -1 + 1 | ||
| 3886 | for _index_0 = _min_0, _max_0 do | ||
| 3887 | local item = _list_0[_index_0] | ||
| 3888 | _accum_0[_len_0] = item | ||
| 3889 | _len_0 = _len_0 + 1 | ||
| 3890 | end | ||
| 3891 | slice = _accum_0 | ||
| 3892 | local reverse_slice | ||
| 3893 | local _accum_0 = { } | ||
| 3894 | local _len_0 = 1 | ||
| 3895 | local _list_0 = items | ||
| 3896 | local _min_0 = #_list_0 + -1 + 1 | ||
| 3897 | for _index_0 = _min_0, 1, -1 do | ||
| 3898 | local item = _list_0[_index_0] | ||
| 3899 | _accum_0[_len_0] = item | ||
| 3900 | _len_0 = _len_0 + 1 | ||
| 3901 | end | ||
| 3902 | reverse_slice = _accum_0 | ||
| 3903 | local sub_list | ||
| 3904 | local _accum_0 = { } | ||
| 3905 | local _len_0 = 1 | ||
| 3906 | local _list_0 = items | ||
| 3907 | for _index_0 = 2, 4 do | ||
| 3908 | local _item_0 = _list_0[_index_0] | ||
| 3909 | _accum_0[_len_0] = _item_0 | ||
| 3910 | _len_0 = _len_0 + 1 | ||
| 3911 | end | ||
| 3912 | sub_list = _accum_0 | ||
| 3913 | for i = 10, 20 do | ||
| 3914 | print(i) | ||
| 3915 | end | ||
| 3916 | for k = 1, 15, 2 do | ||
| 3917 | print(k) | ||
| 3918 | end | ||
| 3919 | for key, value in pairs(object) do | ||
| 3920 | print(key, value) | ||
| 3921 | end | ||
| 3922 | local _list_0 = items | ||
| 3923 | for _index_0 = 2, 4 do | ||
| 3924 | local item = _list_0[_index_0] | ||
| 3925 | print(item) | ||
| 3926 | end | ||
| 3927 | local _list_0 = items | ||
| 3928 | for _index_0 = 1, #_list_0 do | ||
| 3929 | local item = _list_0[_index_0] | ||
| 3930 | print(item) | ||
| 3931 | end | ||
| 3932 | for j = 1, 10, 3 do | ||
| 3933 | print(j) | ||
| 3934 | end | ||
| 3935 | local doubled_evens | ||
| 3936 | local _accum_0 = { } | ||
| 3937 | local _len_0 = 1 | ||
| 3938 | for i = 1, 20 do | ||
| 3939 | if i % 2 == 0 then | ||
| 3940 | _accum_0[_len_0] = i * 2 | ||
| 3941 | _len_0 = _len_0 + 1 | ||
| 3942 | else | ||
| 3943 | _accum_0[_len_0] = i | ||
| 3944 | _len_0 = _len_0 + 1 | ||
| 3945 | end | ||
| 3946 | end | ||
| 3947 | doubled_evens = _accum_0 | ||
| 3948 | local first_large | ||
| 3949 | local _accum_0 | ||
| 3950 | local _list_0 = numbers | ||
| 3951 | for _index_0 = 1, #_list_0 do | ||
| 3952 | local n = _list_0[_index_0] | ||
| 3953 | if n > 10 then | ||
| 3954 | _accum_0 = n | ||
| 3955 | break | ||
| 3956 | end | ||
| 3957 | end | ||
| 3958 | first_large = _accum_0 | ||
| 3959 | local func_a | ||
| 3960 | func_a = function() | ||
| 3961 | for i = 1, 10 do | ||
| 3962 | print(i) | ||
| 3963 | end | ||
| 3964 | end | ||
| 3965 | local func_b | ||
| 3966 | func_b = function() | ||
| 3967 | local _accum_0 = { } | ||
| 3968 | local _len_0 = 1 | ||
| 3969 | for i = 1, 10 do | ||
| 3970 | _accum_0[_len_0] = i | ||
| 3971 | _len_0 = _len_0 + 1 | ||
| 3972 | end | ||
| 3973 | return _accum_0 | ||
| 3974 | end | ||
| 3975 | print(func_a()) | ||
| 3976 | print(func_b()) | ||
| 3977 | local i = 10 | ||
| 3978 | repeat | ||
| 3979 | print(i) | ||
| 3980 | i = i - 1 | ||
| 3981 | until i == 0 | ||
| 3982 | local i = 10 | ||
| 3983 | while i > 0 do | ||
| 3984 | print(i) | ||
| 3985 | i = i - 1 | ||
| 3986 | end | ||
| 3987 | while running == true do | ||
| 3988 | my_function() | ||
| 3989 | end | ||
| 3990 | local i = 10 | ||
| 3991 | while not (i == 0) do | ||
| 3992 | print(i) | ||
| 3993 | i = i - 1 | ||
| 3994 | end | ||
| 3995 | while not (running == false) do | ||
| 3996 | my_function() | ||
| 3997 | end | ||
| 3998 | local i = 0 | ||
| 3999 | while i < 10 do | ||
| 4000 | i = i + 1 | ||
| 4001 | if i % 2 == 0 then | ||
| 4002 | goto _continue_0 | ||
| 4003 | end | ||
| 4004 | print(i) | ||
| 4005 | ::_continue_0:: | ||
| 4006 | end | ||
| 4007 | local my_numbers = { | ||
| 4008 | 1, | ||
| 4009 | 2, | ||
| 4010 | 3, | ||
| 4011 | 4, | ||
| 4012 | 5, | ||
| 4013 | 6 | ||
| 4014 | } | ||
| 4015 | local odds | ||
| 4016 | local _accum_0 = { } | ||
| 4017 | local _len_0 = 1 | ||
| 4018 | for _index_0 = 1, #my_numbers do | ||
| 4019 | local x = my_numbers[_index_0] | ||
| 4020 | if x % 2 == 1 then | ||
| 4021 | goto _continue_0 | ||
| 4022 | end | ||
| 4023 | _accum_0[_len_0] = x | ||
| 4024 | _len_0 = _len_0 + 1 | ||
| 4025 | ::_continue_0:: | ||
| 4026 | end | ||
| 4027 | odds = _accum_0 | ||
| 4028 | local have_coins = false | ||
| 4029 | if have_coins then | ||
| 4030 | print("Got coins") | ||
| 4031 | else | ||
| 4032 | print("No coins") | ||
| 4033 | end | ||
| 4034 | local have_coins = false | ||
| 4035 | if have_coins then | ||
| 4036 | print("Got coins") | ||
| 4037 | else | ||
| 4038 | print("No coins") | ||
| 4039 | end | ||
| 4040 | local have_coins = false | ||
| 4041 | print((function() | ||
| 4042 | if have_coins then | ||
| 4043 | return "Got coins" | ||
| 4044 | else | ||
| 4045 | return "No coins" | ||
| 4046 | end | ||
| 4047 | end)()) | ||
| 4048 | local is_tall | ||
| 4049 | is_tall = function(name) | ||
| 4050 | if name == "Rob" then | ||
| 4051 | return true | ||
| 4052 | else | ||
| 4053 | return false | ||
| 4054 | end | ||
| 4055 | end | ||
| 4056 | local message | ||
| 4057 | if is_tall("Rob") then | ||
| 4058 | message = "I am very tall" | ||
| 4059 | else | ||
| 4060 | message = "I am not so tall" | ||
| 4061 | end | ||
| 4062 | print(message) | ||
| 4063 | if not (os.date("%A") == "Monday") then | ||
| 4064 | print("it is not Monday!") | ||
| 4065 | end | ||
| 4066 | if not (math.random() > 0.1) then | ||
| 4067 | print("You're lucky!") | ||
| 4068 | end | ||
| 4069 | local a = 5 | ||
| 4070 | if (1 == a or 3 == a or 5 == a or 7 == a) then | ||
| 4071 | print("checking equality with discrete values") | ||
| 4072 | end | ||
| 4073 | if (function() | ||
| 4074 | local _check_0 = list | ||
| 4075 | for _index_0 = 1, #_check_0 do | ||
| 4076 | if _check_0[_index_0] == a then | ||
| 4077 | return true | ||
| 4078 | end | ||
| 4079 | end | ||
| 4080 | return false | ||
| 4081 | end)() then | ||
| 4082 | print("checking if `a` is in a list") | ||
| 4083 | end | ||
| 4084 | if not (math.random() > 0.1) then | ||
| 4085 | print("You're lucky!") | ||
| 4086 | end | ||
| 4087 | if name == "Rob" then | ||
| 4088 | print("hello world") | ||
| 4089 | end | ||
| 4090 | local _list_0 = items | ||
| 4091 | for _index_0 = 1, #_list_0 do | ||
| 4092 | local item = _list_0[_index_0] | ||
| 4093 | print("item: ", item) | ||
| 4094 | end | ||
| 4095 | while game:isRunning() do | ||
| 4096 | game:update() | ||
| 4097 | end | ||
| 4098 | while not reader:eof() do | ||
| 4099 | reader:parse_line() | ||
| 4100 | end | ||
| 4101 | local name = "Dan" | ||
| 4102 | if "Robert" == name then | ||
| 4103 | print("You are Robert") | ||
| 4104 | elseif "Dan" == name or "Daniel" == name then | ||
| 4105 | print("Your name, it's Dan") | ||
| 4106 | else | ||
| 4107 | print("I don't know about you with name " .. tostring(name)) | ||
| 4108 | end | ||
| 4109 | local b = 1 | ||
| 4110 | local next_number | ||
| 4111 | if 1 == b then | ||
| 4112 | next_number = 2 | ||
| 4113 | elseif 2 == b then | ||
| 4114 | next_number = 3 | ||
| 4115 | else | ||
| 4116 | next_number = error("can't count that high!") | ||
| 4117 | end | ||
| 4118 | local msg | ||
| 4119 | local _exp_0 = math.random(1, 5) | ||
| 4120 | if 1 == _exp_0 then | ||
| 4121 | msg = "you are lucky" | ||
| 4122 | elseif 2 == _exp_0 then | ||
| 4123 | msg = "you are almost lucky" | ||
| 4124 | else | ||
| 4125 | msg = "not so lucky" | ||
| 4126 | end | ||
| 4127 | do | ||
| 4128 | local _exp_0 = math.random(1, 5) | ||
| 4129 | if 1 == _exp_0 then | ||
| 4130 | print("you are lucky") | ||
| 4131 | else | ||
| 4132 | print("not so lucky") | ||
| 4133 | end | ||
| 4134 | end | ||
| 4135 | local _exp_0 = math.random(1, 5) | ||
| 4136 | if 1 == _exp_0 then | ||
| 4137 | print("you are lucky") | ||
| 4138 | else | ||
| 4139 | print("not so lucky") | ||
| 4140 | end | ||
| 4141 | local items = { | ||
| 4142 | { | ||
| 4143 | x = 100, | ||
| 4144 | y = 200 | ||
| 4145 | }, | ||
| 4146 | { | ||
| 4147 | width = 300, | ||
| 4148 | height = 400 | ||
| 4149 | } | ||
| 4150 | } | ||
| 4151 | for _index_0 = 1, #items do | ||
| 4152 | local item = items[_index_0] | ||
| 4153 | local _type_0 = type(item) | ||
| 4154 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 4155 | local _match_0 = false | ||
| 4156 | if _tab_0 then | ||
| 4157 | local x = item.x | ||
| 4158 | local y = item.y | ||
| 4159 | if x ~= nil and y ~= nil then | ||
| 4160 | _match_0 = true | ||
| 4161 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) | ||
| 4162 | end | ||
| 4163 | end | ||
| 4164 | if not _match_0 then | ||
| 4165 | if _tab_0 then | ||
| 4166 | local width = item.width | ||
| 4167 | local height = item.height | ||
| 4168 | if width ~= nil and height ~= nil then | ||
| 4169 | print("size " .. tostring(width) .. ", " .. tostring(height)) | ||
| 4170 | end | ||
| 4171 | end | ||
| 4172 | end | ||
| 4173 | end | ||
| 4174 | local item = { } | ||
| 4175 | local x, y = item.pos.x, item.pos.y | ||
| 4176 | if x == nil then | ||
| 4177 | x = 50 | ||
| 4178 | end | ||
| 4179 | if y == nil then | ||
| 4180 | y = 200 | ||
| 4181 | end | ||
| 4182 | local _type_0 = type(item) | ||
| 4183 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 4184 | if _tab_0 then | ||
| 4185 | do | ||
| 4186 | local _obj_0 = item.pos | ||
| 4187 | local _type_1 = type(_obj_0) | ||
| 4188 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 4189 | x = _obj_0.x | ||
| 4190 | end | ||
| 4191 | end | ||
| 4192 | do | ||
| 4193 | local _obj_0 = item.pos | ||
| 4194 | local _type_1 = type(_obj_0) | ||
| 4195 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 4196 | y = _obj_0.y | ||
| 4197 | end | ||
| 4198 | end | ||
| 4199 | if x == nil then | ||
| 4200 | x = 50 | ||
| 4201 | end | ||
| 4202 | if y == nil then | ||
| 4203 | y = 200 | ||
| 4204 | end | ||
| 4205 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) | ||
| 4206 | end | ||
| 4207 | local _exp_0 = tb | ||
| 4208 | local _type_0 = type(_exp_0) | ||
| 4209 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 4210 | local _match_0 = false | ||
| 4211 | if _tab_0 then | ||
| 4212 | if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then | ||
| 4213 | _match_0 = true | ||
| 4214 | print("1, 2, 3") | ||
| 4215 | end | ||
| 4216 | end | ||
| 4217 | if not _match_0 then | ||
| 4218 | local _match_1 = false | ||
| 4219 | if _tab_0 then | ||
| 4220 | local b = _exp_0[2] | ||
| 4221 | if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then | ||
| 4222 | _match_1 = true | ||
| 4223 | print("1, " .. tostring(b) .. ", 3") | ||
| 4224 | end | ||
| 4225 | end | ||
| 4226 | if not _match_1 then | ||
| 4227 | if _tab_0 then | ||
| 4228 | local b = _exp_0[3] | ||
| 4229 | if b == nil then | ||
| 4230 | b = 3 | ||
| 4231 | end | ||
| 4232 | if 1 == _exp_0[1] and 2 == _exp_0[2] then | ||
| 4233 | print("1, 2, " .. tostring(b)) | ||
| 4234 | end | ||
| 4235 | end | ||
| 4236 | end | ||
| 4237 | end | ||
| 4238 | local _exp_0 = tb | ||
| 4239 | local _type_0 = type(_exp_0) | ||
| 4240 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 4241 | local _match_0 = false | ||
| 4242 | if _tab_0 then | ||
| 4243 | local result = _exp_0.result | ||
| 4244 | if true == _exp_0.success and result ~= nil then | ||
| 4245 | _match_0 = true | ||
| 4246 | print("success", result) | ||
| 4247 | end | ||
| 4248 | end | ||
| 4249 | if not _match_0 then | ||
| 4250 | local _match_1 = false | ||
| 4251 | if _tab_0 then | ||
| 4252 | if false == _exp_0.success then | ||
| 4253 | _match_1 = true | ||
| 4254 | print("failed", result) | ||
| 4255 | end | ||
| 4256 | end | ||
| 4257 | if not _match_1 then | ||
| 4258 | print("invalid") | ||
| 4259 | end | ||
| 4260 | end | ||
| 4261 | local _exp_0 = tb | ||
| 4262 | local _type_0 = type(_exp_0) | ||
| 4263 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 4264 | local _match_0 = false | ||
| 4265 | if _tab_0 then | ||
| 4266 | local content | ||
| 4267 | do | ||
| 4268 | local _obj_0 = _exp_0.data | ||
| 4269 | local _type_1 = type(_obj_0) | ||
| 4270 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 4271 | content = _obj_0.content | ||
| 4272 | end | ||
| 4273 | end | ||
| 4274 | local _val_0 | ||
| 4275 | do | ||
| 4276 | local _obj_0 = _exp_0.data | ||
| 4277 | if _obj_0 ~= nil then | ||
| 4278 | _val_0 = _obj_0.type | ||
| 4279 | end | ||
| 4280 | end | ||
| 4281 | if "success" == _val_0 and content ~= nil then | ||
| 4282 | _match_0 = true | ||
| 4283 | print("success", content) | ||
| 4284 | end | ||
| 4285 | end | ||
| 4286 | if not _match_0 then | ||
| 4287 | local _match_1 = false | ||
| 4288 | if _tab_0 then | ||
| 4289 | local content | ||
| 4290 | do | ||
| 4291 | local _obj_0 = _exp_0.data | ||
| 4292 | local _type_1 = type(_obj_0) | ||
| 4293 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 4294 | content = _obj_0.content | ||
| 4295 | end | ||
| 4296 | end | ||
| 4297 | local _val_0 | ||
| 4298 | do | ||
| 4299 | local _obj_0 = _exp_0.data | ||
| 4300 | if _obj_0 ~= nil then | ||
| 4301 | _val_0 = _obj_0.type | ||
| 4302 | end | ||
| 4303 | end | ||
| 4304 | if "error" == _val_0 and content ~= nil then | ||
| 4305 | _match_1 = true | ||
| 4306 | print("failed", content) | ||
| 4307 | end | ||
| 4308 | end | ||
| 4309 | if not _match_1 then | ||
| 4310 | print("invalid") | ||
| 4311 | end | ||
| 4312 | end | ||
| 4313 | local _exp_0 = tb | ||
| 4314 | local _type_0 = type(_exp_0) | ||
| 4315 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 4316 | if _tab_0 then | ||
| 4317 | local fourth = _exp_0[4] | ||
| 4318 | local _val_0 | ||
| 4319 | do | ||
| 4320 | local _obj_0 = _exp_0[1] | ||
| 4321 | if _obj_0 ~= nil then | ||
| 4322 | _val_0 = _obj_0.a | ||
| 4323 | end | ||
| 4324 | end | ||
| 4325 | local _val_1 | ||
| 4326 | do | ||
| 4327 | local _obj_0 = _exp_0[1] | ||
| 4328 | if _obj_0 ~= nil then | ||
| 4329 | _val_1 = _obj_0.b | ||
| 4330 | end | ||
| 4331 | end | ||
| 4332 | local _val_2 | ||
| 4333 | do | ||
| 4334 | local _obj_0 = _exp_0[2] | ||
| 4335 | if _obj_0 ~= nil then | ||
| 4336 | _val_2 = _obj_0.a | ||
| 4337 | end | ||
| 4338 | end | ||
| 4339 | local _val_3 | ||
| 4340 | do | ||
| 4341 | local _obj_0 = _exp_0[2] | ||
| 4342 | if _obj_0 ~= nil then | ||
| 4343 | _val_3 = _obj_0.b | ||
| 4344 | end | ||
| 4345 | end | ||
| 4346 | local _val_4 | ||
| 4347 | do | ||
| 4348 | local _obj_0 = _exp_0[3] | ||
| 4349 | if _obj_0 ~= nil then | ||
| 4350 | _val_4 = _obj_0.a | ||
| 4351 | end | ||
| 4352 | end | ||
| 4353 | local _val_5 | ||
| 4354 | do | ||
| 4355 | local _obj_0 = _exp_0[3] | ||
| 4356 | if _obj_0 ~= nil then | ||
| 4357 | _val_5 = _obj_0.b | ||
| 4358 | end | ||
| 4359 | end | ||
| 4360 | if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then | ||
| 4361 | print("matched", fourth) | ||
| 4362 | end | ||
| 4363 | end | ||
| 4364 | local segments = { | ||
| 4365 | "admin", | ||
| 4366 | "users", | ||
| 4367 | "logs", | ||
| 4368 | "view" | ||
| 4369 | } | ||
| 4370 | local _type_0 = type(segments) | ||
| 4371 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 4372 | if _tab_0 then | ||
| 4373 | local groups | ||
| 4374 | do | ||
| 4375 | local _accum_0 = { } | ||
| 4376 | local _len_0 = 1 | ||
| 4377 | local _max_0 = #segments + -3 + 1 | ||
| 4378 | for _index_0 = 1, _max_0 do | ||
| 4379 | local _item_0 = segments[_index_0] | ||
| 4380 | _accum_0[_len_0] = _item_0 | ||
| 4381 | _len_0 = _len_0 + 1 | ||
| 4382 | end | ||
| 4383 | groups = _accum_0 | ||
| 4384 | end | ||
| 4385 | local resource = segments[#segments - 1] | ||
| 4386 | local action = segments[#segments] | ||
| 4387 | if resource ~= nil and action ~= nil then | ||
| 4388 | print("Group:", groups) | ||
| 4389 | print("Resource:", resource) | ||
| 4390 | print("Action:", action) | ||
| 4391 | end | ||
| 4392 | end | ||
| 4393 | local Inventory | 4313 | local Inventory |
| 4394 | local _class_0 | 4314 | local _class_0 |
| 4395 | local _base_0 = { | 4315 | local _base_0 = { |
| @@ -5050,6 +4970,46 @@ local _with_0 = obj | |||
| 5050 | if _with_0 ~= nil then | 4970 | if _with_0 ~= nil then |
| 5051 | print(obj.name) | 4971 | print(obj.name) |
| 5052 | end | 4972 | end |
| 4973 | local _with_0 = Person() | ||
| 4974 | _with_0.name = "Oswald" | ||
| 4975 | _with_0:add_relative(my_dad) | ||
| 4976 | _with_0:save() | ||
| 4977 | print(_with_0.name) | ||
| 4978 | local file | ||
| 4979 | local _with_0 = File("favorite_foods.txt") | ||
| 4980 | _with_0:set_encoding("utf8") | ||
| 4981 | file = _with_0 | ||
| 4982 | local create_person | ||
| 4983 | create_person = function(name, relatives) | ||
| 4984 | local _with_0 = Person() | ||
| 4985 | _with_0.name = name | ||
| 4986 | for _index_0 = 1, #relatives do | ||
| 4987 | local relative = relatives[_index_0] | ||
| 4988 | _with_0:add_relative(relative) | ||
| 4989 | end | ||
| 4990 | return _with_0 | ||
| 4991 | end | ||
| 4992 | local me = create_person("Leaf", { | ||
| 4993 | dad, | ||
| 4994 | mother, | ||
| 4995 | sister | ||
| 4996 | }) | ||
| 4997 | local str = "Hello" | ||
| 4998 | print("original:", str) | ||
| 4999 | print("upper:", str:upper()) | ||
| 5000 | local _with_0 = tb | ||
| 5001 | _with_0[1] = 1 | ||
| 5002 | print(_with_0[2]) | ||
| 5003 | do | ||
| 5004 | local _with_1 = _with_0[abc] | ||
| 5005 | _with_1[3] = _with_1[2]:func() | ||
| 5006 | _with_1["key-name"] = value | ||
| 5007 | end | ||
| 5008 | _with_0[#_with_0 + 1] = "abc" | ||
| 5009 | local _with_0 = obj | ||
| 5010 | if _with_0 ~= nil then | ||
| 5011 | print(obj.name) | ||
| 5012 | end | ||
| 5053 | do | 5013 | do |
| 5054 | local var = "hello" | 5014 | local var = "hello" |
| 5055 | print(var) | 5015 | print(var) |
| @@ -5071,6 +5031,46 @@ local tbl = { | |||
| 5071 | return 1234 | 5031 | return 1234 |
| 5072 | end)() | 5032 | end)() |
| 5073 | } | 5033 | } |
| 5034 | do | ||
| 5035 | local var = "hello" | ||
| 5036 | print(var) | ||
| 5037 | end | ||
| 5038 | print(var) | ||
| 5039 | local counter | ||
| 5040 | do | ||
| 5041 | local i = 0 | ||
| 5042 | counter = function() | ||
| 5043 | i = i + 1 | ||
| 5044 | return i | ||
| 5045 | end | ||
| 5046 | end | ||
| 5047 | print(counter()) | ||
| 5048 | print(counter()) | ||
| 5049 | local tbl = { | ||
| 5050 | key = (function() | ||
| 5051 | print("assigning key!") | ||
| 5052 | return 1234 | ||
| 5053 | end)() | ||
| 5054 | } | ||
| 5055 | local my_object = { | ||
| 5056 | value = 1000, | ||
| 5057 | write = function(self) | ||
| 5058 | return print("the value:", self.value) | ||
| 5059 | end | ||
| 5060 | } | ||
| 5061 | local run_callback | ||
| 5062 | run_callback = function(func) | ||
| 5063 | print("running callback...") | ||
| 5064 | return func() | ||
| 5065 | end | ||
| 5066 | run_callback(my_object.write) | ||
| 5067 | run_callback((function() | ||
| 5068 | local _base_0 = my_object | ||
| 5069 | local _fn_0 = _base_0.write | ||
| 5070 | return _fn_0 and function(...) | ||
| 5071 | return _fn_0(_base_0, ...) | ||
| 5072 | end | ||
| 5073 | end)()) | ||
| 5074 | local my_object = { | 5074 | local my_object = { |
| 5075 | value = 1000, | 5075 | value = 1000, |
| 5076 | write = function(self) | 5076 | write = function(self) |
| @@ -5118,3 +5118,31 @@ my_func = function(add) | |||
| 5118 | end | 5118 | end |
| 5119 | my_func(22) | 5119 | my_func(22) |
| 5120 | print(i, k) | 5120 | print(i, k) |
| 5121 | local i = 100 | ||
| 5122 | local my_func | ||
| 5123 | my_func = function() | ||
| 5124 | i = 10 | ||
| 5125 | while i > 0 do | ||
| 5126 | print(i) | ||
| 5127 | i = i - 1 | ||
| 5128 | end | ||
| 5129 | end | ||
| 5130 | my_func() | ||
| 5131 | print(i) | ||
| 5132 | local i = 100 | ||
| 5133 | local my_func | ||
| 5134 | my_func = function() | ||
| 5135 | local i = "hello" | ||
| 5136 | end | ||
| 5137 | my_func() | ||
| 5138 | print(i) | ||
| 5139 | local tmp = 1213 | ||
| 5140 | local i, k = 100, 50 | ||
| 5141 | local my_func | ||
| 5142 | my_func = function(add) | ||
| 5143 | local tmp = tmp + add | ||
| 5144 | i = i + tmp | ||
| 5145 | k = k + tmp | ||
| 5146 | end | ||
| 5147 | my_func(22) | ||
| 5148 | print(i, k) | ||
