diff options
| author | Li Jin <dragon-fly@qq.com> | 2026-02-04 16:18:19 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2026-02-04 16:18:19 +0800 |
| commit | ffa06586ba5b04bf9c223b41fe66cdb813ba1b34 (patch) | |
| tree | 600114d784edb8509fed20f70319ccbb778ba682 /spec | |
| parent | 8d2a049286131ad6920262a96d365813eca8b780 (diff) | |
| download | yuescript-ffa06586ba5b04bf9c223b41fe66cdb813ba1b34.tar.gz yuescript-ffa06586ba5b04bf9c223b41fe66cdb813ba1b34.tar.bz2 yuescript-ffa06586ba5b04bf9c223b41fe66cdb813ba1b34.zip | |
Splited docs.
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/inputs/compile_doc.yue | 101 | ||||
| -rw-r--r-- | spec/outputs/codes_from_doc.lua | 3916 | ||||
| -rw-r--r-- | spec/outputs/codes_from_doc_zh.lua | 3916 | ||||
| -rw-r--r-- | spec/outputs/compile_doc.lua | 135 |
4 files changed, 4128 insertions, 3940 deletions
diff --git a/spec/inputs/compile_doc.yue b/spec/inputs/compile_doc.yue index db0464b..45a0b16 100644 --- a/spec/inputs/compile_doc.yue +++ b/spec/inputs/compile_doc.yue | |||
| @@ -1,24 +1,83 @@ | |||
| 1 | outputFolder = ... | 1 | outputFolder = ... |
| 2 | for [compiledFile, docFile] in *[ | 2 | for [compiledFile, docFiles] in *[ |
| 3 | ["codes_from_doc.lua", "doc/docs/doc/index.md"] | 3 | ["codes_from_doc.lua", [ |
| 4 | ["codes_from_doc_zh.lua", "doc/docs/zh/doc/index.md"] | 4 | "doc/docs/doc/introduction.md" |
| 5 | "doc/docs/doc/macro.md" | ||
| 6 | "doc/docs/doc/operator.md" | ||
| 7 | "doc/docs/doc/module.md" | ||
| 8 | "doc/docs/doc/assignment.md" | ||
| 9 | "doc/docs/doc/destructuring-assignment.md" | ||
| 10 | "doc/docs/doc/if-assignment.md" | ||
| 11 | "doc/docs/doc/varargs-assignment.md" | ||
| 12 | "doc/docs/doc/whitespace.md" | ||
| 13 | "doc/docs/doc/comment.md" | ||
| 14 | "doc/docs/doc/try.md" | ||
| 15 | "doc/docs/doc/attributes.md" | ||
| 16 | "doc/docs/doc/literals.md" | ||
| 17 | "doc/docs/doc/function-literals.md" | ||
| 18 | "doc/docs/doc/backcalls.md" | ||
| 19 | "doc/docs/doc/table-literals.md" | ||
| 20 | "doc/docs/doc/comprehensions.md" | ||
| 21 | "doc/docs/doc/for-loop.md" | ||
| 22 | "doc/docs/doc/while-loop.md" | ||
| 23 | "doc/docs/doc/continue.md" | ||
| 24 | "doc/docs/doc/conditionals.md" | ||
| 25 | "doc/docs/doc/line-decorators.md" | ||
| 26 | "doc/docs/doc/switch.md" | ||
| 27 | "doc/docs/doc/object-oriented-programming.md" | ||
| 28 | "doc/docs/doc/with-statement.md" | ||
| 29 | "doc/docs/doc/do.md" | ||
| 30 | "doc/docs/doc/function-stubs.md" | ||
| 31 | "doc/docs/doc/the-using-clause-controlling-destructive-assignment.md" | ||
| 32 | ]] | ||
| 33 | ["codes_from_doc_zh.lua", [ | ||
| 34 | "doc/docs/zh/doc/introduction.md" | ||
| 35 | "doc/docs/zh/doc/macro.md" | ||
| 36 | "doc/docs/zh/doc/operator.md" | ||
| 37 | "doc/docs/zh/doc/module.md" | ||
| 38 | "doc/docs/zh/doc/assignment.md" | ||
| 39 | "doc/docs/zh/doc/destructuring-assignment.md" | ||
| 40 | "doc/docs/zh/doc/if-assignment.md" | ||
| 41 | "doc/docs/zh/doc/varargs-assignment.md" | ||
| 42 | "doc/docs/zh/doc/whitespace.md" | ||
| 43 | "doc/docs/zh/doc/comment.md" | ||
| 44 | "doc/docs/zh/doc/try.md" | ||
| 45 | "doc/docs/zh/doc/attributes.md" | ||
| 46 | "doc/docs/zh/doc/literals.md" | ||
| 47 | "doc/docs/zh/doc/function-literals.md" | ||
| 48 | "doc/docs/zh/doc/backcalls.md" | ||
| 49 | "doc/docs/zh/doc/table-literals.md" | ||
| 50 | "doc/docs/zh/doc/comprehensions.md" | ||
| 51 | "doc/docs/zh/doc/for-loop.md" | ||
| 52 | "doc/docs/zh/doc/while-loop.md" | ||
| 53 | "doc/docs/zh/doc/continue.md" | ||
| 54 | "doc/docs/zh/doc/conditionals.md" | ||
| 55 | "doc/docs/zh/doc/line-decorators.md" | ||
| 56 | "doc/docs/zh/doc/switch.md" | ||
| 57 | "doc/docs/zh/doc/object-oriented-programming.md" | ||
| 58 | "doc/docs/zh/doc/with-statement.md" | ||
| 59 | "doc/docs/zh/doc/do.md" | ||
| 60 | "doc/docs/zh/doc/function-stubs.md" | ||
| 61 | "doc/docs/zh/doc/the-using-clause-controlling-destructive-assignment.md" | ||
| 62 | ]] | ||
| 5 | ] | 63 | ] |
| 6 | close input = with? io.open docFile | 64 | codes = [] |
| 7 | import "yue" as :to_lua | 65 | for docFile in *docFiles |
| 8 | text = \read "*a" | 66 | close input = with? io.open docFile |
| 9 | codes = [] | 67 | import "yue" as :to_lua |
| 10 | for code in text\gmatch "```yuescript[\r\n]+(.-)```[^%w]" | 68 | text = \read "*a" |
| 11 | if result, err := to_lua code, implicit_return_root: false, reserve_line_number: false | 69 | for code in text\gmatch "```yuescript[\r\n]+(.-)```[^%w]" |
| 12 | codes[] = result | 70 | if result, err := to_lua code, implicit_return_root: false, reserve_line_number: false |
| 13 | elseif not err\match "macro exporting module only accepts macro definition" | 71 | codes[] = result |
| 14 | print err | 72 | elseif not err\match "macro exporting module only accepts macro definition" |
| 15 | os.exit 1 | 73 | print err |
| 16 | for code in text\gmatch "```yue[\r\n]+(.-)```[^%w]" | 74 | os.exit 1 |
| 17 | if result, err := to_lua code, implicit_return_root: false, reserve_line_number: false | 75 | for code in text\gmatch "```yue[\r\n]+(.-)```[^%w]" |
| 18 | codes[] = result | 76 | if result, err := to_lua code, implicit_return_root: false, reserve_line_number: false |
| 19 | else | 77 | codes[] = result |
| 20 | print err | 78 | else |
| 21 | os.exit 1 | 79 | print err |
| 22 | close output = with io.open "#{outputFolder}/#{compiledFile}", "w+" | 80 | os.exit 1 |
| 23 | \write table.concat codes | 81 | close output = with io.open "#{outputFolder}/#{compiledFile}", "w+" |
| 82 | \write table.concat codes | ||
| 24 | 83 | ||
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) | ||
diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua index 2aa354e..f4ef2c7 100644 --- a/spec/outputs/codes_from_doc_zh.lua +++ b/spec/outputs/codes_from_doc_zh.lua | |||
| @@ -76,6 +76,84 @@ 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 | ||
| 79 | local area = 6.2831853071796 * 5 | 157 | local area = 6.2831853071796 * 5 |
| 80 | print('你好 世界') | 158 | print('你好 世界') |
| 81 | do | 159 | do |
| @@ -115,6 +193,338 @@ end | |||
| 115 | do | 193 | do |
| 116 | print(123, "hello") | 194 | print(123, "hello") |
| 117 | end | 195 | end |
| 196 | local area = 6.2831853071796 * 5 | ||
| 197 | print('你好 世界') | ||
| 198 | do | ||
| 199 | assert(item ~= nil) | ||
| 200 | end | ||
| 201 | local value = item | ||
| 202 | if (f1() and f2() and f3()) then | ||
| 203 | print("OK") | ||
| 204 | end | ||
| 205 | do | ||
| 206 | local funcA | ||
| 207 | funcA = function() end | ||
| 208 | end | ||
| 209 | local funcA | ||
| 210 | funcA = function() | ||
| 211 | return "无法访问宏生成月之脚本里定义的变量" | ||
| 212 | end | ||
| 213 | do | ||
| 214 | local function funcB() end | ||
| 215 | end | ||
| 216 | local funcB | ||
| 217 | funcB = function() | ||
| 218 | return "无法访问宏生成 Lua 代码里定义的变量" | ||
| 219 | end | ||
| 220 | do | ||
| 221 | -- 插入原始Lua代码 | ||
| 222 | if cond then | ||
| 223 | print("输出") | ||
| 224 | end | ||
| 225 | end | ||
| 226 | print("yuescript") | ||
| 227 | print(2) | ||
| 228 | print("有效的枚举类型:", "Static") | ||
| 229 | do | ||
| 230 | print(123, "hello") | ||
| 231 | end | ||
| 232 | do | ||
| 233 | print(123, "hello") | ||
| 234 | end | ||
| 235 | if tb ~= nil then | ||
| 236 | tb:func() | ||
| 237 | end | ||
| 238 | if tb ~= nil then | ||
| 239 | tb:func() | ||
| 240 | end | ||
| 241 | 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) | ||
| 242 | local a = 5 | ||
| 243 | print(1 <= a and a <= 10) | ||
| 244 | local v | ||
| 245 | v = function(x) | ||
| 246 | print(x) | ||
| 247 | return x | ||
| 248 | end | ||
| 249 | print((function() | ||
| 250 | local _cond_0 = v(2) | ||
| 251 | if not (v(1) < _cond_0) then | ||
| 252 | return false | ||
| 253 | else | ||
| 254 | return _cond_0 <= v(3) | ||
| 255 | end | ||
| 256 | end)()) | ||
| 257 | print((function() | ||
| 258 | local _cond_0 = v(2) | ||
| 259 | if not (v(1) > _cond_0) then | ||
| 260 | return false | ||
| 261 | else | ||
| 262 | return _cond_0 <= v(3) | ||
| 263 | end | ||
| 264 | end)()) | ||
| 265 | local tab = { } | ||
| 266 | tab[#tab + 1] = "Value" | ||
| 267 | local tbA = { | ||
| 268 | 1, | ||
| 269 | 2, | ||
| 270 | 3 | ||
| 271 | } | ||
| 272 | local tbB = { | ||
| 273 | 4, | ||
| 274 | 5, | ||
| 275 | 6 | ||
| 276 | } | ||
| 277 | local _len_0 = #tbA + 1 | ||
| 278 | for _index_0 = 1, #tbB do | ||
| 279 | local _elm_0 = tbB[_index_0] | ||
| 280 | tbA[_len_0], _len_0 = _elm_0, _len_0 + 1 | ||
| 281 | end | ||
| 282 | local parts = { | ||
| 283 | "shoulders", | ||
| 284 | "knees" | ||
| 285 | } | ||
| 286 | local lyrics | ||
| 287 | do | ||
| 288 | local _tab_0 = { | ||
| 289 | "head" | ||
| 290 | } | ||
| 291 | local _idx_0 = 1 | ||
| 292 | for _key_0, _value_0 in pairs(parts) do | ||
| 293 | if _idx_0 == _key_0 then | ||
| 294 | _tab_0[#_tab_0 + 1] = _value_0 | ||
| 295 | _idx_0 = _idx_0 + 1 | ||
| 296 | else | ||
| 297 | _tab_0[_key_0] = _value_0 | ||
| 298 | end | ||
| 299 | end | ||
| 300 | _tab_0[#_tab_0 + 1] = "and" | ||
| 301 | _tab_0[#_tab_0 + 1] = "toes" | ||
| 302 | lyrics = _tab_0 | ||
| 303 | end | ||
| 304 | local copy | ||
| 305 | do | ||
| 306 | local _tab_0 = { } | ||
| 307 | local _idx_0 = 1 | ||
| 308 | for _key_0, _value_0 in pairs(other) do | ||
| 309 | if _idx_0 == _key_0 then | ||
| 310 | _tab_0[#_tab_0 + 1] = _value_0 | ||
| 311 | _idx_0 = _idx_0 + 1 | ||
| 312 | else | ||
| 313 | _tab_0[_key_0] = _value_0 | ||
| 314 | end | ||
| 315 | end | ||
| 316 | copy = _tab_0 | ||
| 317 | end | ||
| 318 | local a = { | ||
| 319 | 1, | ||
| 320 | 2, | ||
| 321 | 3, | ||
| 322 | x = 1 | ||
| 323 | } | ||
| 324 | local b = { | ||
| 325 | 4, | ||
| 326 | 5, | ||
| 327 | y = 1 | ||
| 328 | } | ||
| 329 | local merge | ||
| 330 | local _tab_0 = { } | ||
| 331 | local _idx_0 = 1 | ||
| 332 | for _key_0, _value_0 in pairs(a) do | ||
| 333 | if _idx_0 == _key_0 then | ||
| 334 | _tab_0[#_tab_0 + 1] = _value_0 | ||
| 335 | _idx_0 = _idx_0 + 1 | ||
| 336 | else | ||
| 337 | _tab_0[_key_0] = _value_0 | ||
| 338 | end | ||
| 339 | end | ||
| 340 | local _idx_1 = 1 | ||
| 341 | for _key_0, _value_0 in pairs(b) do | ||
| 342 | if _idx_1 == _key_0 then | ||
| 343 | _tab_0[#_tab_0 + 1] = _value_0 | ||
| 344 | _idx_1 = _idx_1 + 1 | ||
| 345 | else | ||
| 346 | _tab_0[_key_0] = _value_0 | ||
| 347 | end | ||
| 348 | end | ||
| 349 | merge = _tab_0 | ||
| 350 | local last | ||
| 351 | do | ||
| 352 | local _item_0 = data.items | ||
| 353 | last = _item_0[#_item_0] | ||
| 354 | end | ||
| 355 | local second_last | ||
| 356 | do | ||
| 357 | local _item_0 = data.items | ||
| 358 | second_last = _item_0[#_item_0 - 1] | ||
| 359 | end | ||
| 360 | local _obj_0 = data.items | ||
| 361 | _obj_0[#_obj_0] = 1 | ||
| 362 | local mt = { } | ||
| 363 | local add | ||
| 364 | add = function(self, right) | ||
| 365 | return setmetatable({ | ||
| 366 | value = self.value + right.value | ||
| 367 | }, mt) | ||
| 368 | end | ||
| 369 | mt.__add = add | ||
| 370 | local a = setmetatable({ | ||
| 371 | value = 1 | ||
| 372 | }, mt) | ||
| 373 | local b = setmetatable({ | ||
| 374 | value = 2 | ||
| 375 | }, { | ||
| 376 | __add = add | ||
| 377 | }) | ||
| 378 | local c = setmetatable({ | ||
| 379 | value = 3 | ||
| 380 | }, { | ||
| 381 | __add = mt.__add | ||
| 382 | }) | ||
| 383 | local d = a + b + c | ||
| 384 | print(d.value) | ||
| 385 | local _ <close> = setmetatable({ }, { | ||
| 386 | __close = function() | ||
| 387 | return print("超出范围") | ||
| 388 | end | ||
| 389 | }) | ||
| 390 | local tb = setmetatable({ }, { | ||
| 391 | ["value"] = 123 | ||
| 392 | }) | ||
| 393 | getmetatable(tb).__index = getmetatable(tb) | ||
| 394 | print(tb.value) | ||
| 395 | setmetatable(tb, { | ||
| 396 | __index = { | ||
| 397 | item = "hello" | ||
| 398 | } | ||
| 399 | }) | ||
| 400 | print(tb.item) | ||
| 401 | local item, new, close, getter | ||
| 402 | do | ||
| 403 | local _obj_0 = tb | ||
| 404 | item, new = _obj_0[1], _obj_0.new | ||
| 405 | do | ||
| 406 | local _obj_1 = getmetatable(_obj_0) | ||
| 407 | close, getter = _obj_1.__close, _obj_1.__index | ||
| 408 | end | ||
| 409 | end | ||
| 410 | print(item, new, close, getter) | ||
| 411 | do | ||
| 412 | local _obj_0 = func | ||
| 413 | if _obj_0 ~= nil then | ||
| 414 | _obj_0() | ||
| 415 | end | ||
| 416 | end | ||
| 417 | print((function() | ||
| 418 | local _obj_0 = abc | ||
| 419 | if _obj_0 ~= nil then | ||
| 420 | local _obj_1 = _obj_0["你好 世界"] | ||
| 421 | if _obj_1 ~= nil then | ||
| 422 | return _obj_1.xyz | ||
| 423 | end | ||
| 424 | return nil | ||
| 425 | end | ||
| 426 | return nil | ||
| 427 | end)()) | ||
| 428 | local x | ||
| 429 | do | ||
| 430 | local _obj_0 = tab | ||
| 431 | if _obj_0 ~= nil then | ||
| 432 | x = _obj_0.value | ||
| 433 | end | ||
| 434 | end | ||
| 435 | local len = (function() | ||
| 436 | local _obj_0 = utf8 | ||
| 437 | if _obj_0 ~= nil then | ||
| 438 | return _obj_0.len | ||
| 439 | end | ||
| 440 | return nil | ||
| 441 | end)() or (function() | ||
| 442 | local _obj_0 = string | ||
| 443 | if _obj_0 ~= nil then | ||
| 444 | return _obj_0.len | ||
| 445 | end | ||
| 446 | return nil | ||
| 447 | end)() or function(o) | ||
| 448 | return #o | ||
| 449 | end | ||
| 450 | if print and (x ~= nil) then | ||
| 451 | print(x) | ||
| 452 | end | ||
| 453 | local _with_0 = io.open("test.txt", "w") | ||
| 454 | if _with_0 ~= nil then | ||
| 455 | _with_0:write("你好") | ||
| 456 | _with_0:close() | ||
| 457 | end | ||
| 458 | print("你好") | ||
| 459 | print(1, 2) | ||
| 460 | print(1, 2, 3) | ||
| 461 | print(render(emit(parse(extract(readFile("example.txt"), language, { }), language)))) | ||
| 462 | local a, b, c, d | ||
| 463 | if b ~= nil then | ||
| 464 | a = b | ||
| 465 | else | ||
| 466 | if c ~= nil then | ||
| 467 | a = c | ||
| 468 | else | ||
| 469 | a = d | ||
| 470 | end | ||
| 471 | end | ||
| 472 | func((function() | ||
| 473 | if a ~= nil then | ||
| 474 | return a | ||
| 475 | else | ||
| 476 | return { } | ||
| 477 | end | ||
| 478 | end)()) | ||
| 479 | if a == nil then | ||
| 480 | a = false | ||
| 481 | end | ||
| 482 | local list = { | ||
| 483 | 1, | ||
| 484 | 2, | ||
| 485 | 3 | ||
| 486 | } | ||
| 487 | func({ | ||
| 488 | 1, | ||
| 489 | 2, | ||
| 490 | 3 | ||
| 491 | }) | ||
| 492 | local f | ||
| 493 | f = function() | ||
| 494 | return { | ||
| 495 | 1, | ||
| 496 | 2, | ||
| 497 | 3 | ||
| 498 | } | ||
| 499 | end | ||
| 500 | local tb = { | ||
| 501 | name = "abc", | ||
| 502 | values = { | ||
| 503 | "a", | ||
| 504 | "b", | ||
| 505 | "c" | ||
| 506 | }, | ||
| 507 | objects = { | ||
| 508 | { | ||
| 509 | name = "a", | ||
| 510 | value = 1, | ||
| 511 | func = function(self) | ||
| 512 | return self.value + 1 | ||
| 513 | end, | ||
| 514 | tb = { | ||
| 515 | fieldA = 1 | ||
| 516 | } | ||
| 517 | }, | ||
| 518 | { | ||
| 519 | name = "b", | ||
| 520 | value = 2, | ||
| 521 | func = function(self) | ||
| 522 | return self.value + 2 | ||
| 523 | end, | ||
| 524 | tb = { } | ||
| 525 | } | ||
| 526 | } | ||
| 527 | } | ||
| 118 | if tb ~= nil then | 528 | if tb ~= nil then |
| 119 | tb:func() | 529 | tb:func() |
| 120 | end | 530 | end |
| @@ -539,6 +949,188 @@ _module_0 = function() | |||
| 539 | return 123 | 949 | return 123 |
| 540 | end | 950 | end |
| 541 | return _module_0 | 951 | return _module_0 |
| 952 | do | ||
| 953 | local insert, concat = table.insert, table.concat | ||
| 954 | local C, Ct, Cmt | ||
| 955 | do | ||
| 956 | local _obj_0 = require("lpeg") | ||
| 957 | C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt | ||
| 958 | end | ||
| 959 | local x, y, z | ||
| 960 | do | ||
| 961 | local _obj_0 = require('mymodule') | ||
| 962 | x, y, z = _obj_0.x, _obj_0.y, _obj_0.z | ||
| 963 | end | ||
| 964 | local a, b, c | ||
| 965 | local _obj_0 = require('module') | ||
| 966 | a, b, c = _obj_0.a, _obj_0.b, _obj_0.c | ||
| 967 | end | ||
| 968 | do | ||
| 969 | local module = require('module') | ||
| 970 | local module_x = require('module_x') | ||
| 971 | local d_a_s_h_e_s = require("d-a-s-h-e-s") | ||
| 972 | local part = require("module.part") | ||
| 973 | end | ||
| 974 | do | ||
| 975 | local PlayerModule = require("player") | ||
| 976 | local C, Ct, Cmt | ||
| 977 | do | ||
| 978 | local _obj_0 = require("lpeg") | ||
| 979 | C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt | ||
| 980 | end | ||
| 981 | local one, two, ch | ||
| 982 | local _obj_0 = require("export") | ||
| 983 | one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] | ||
| 984 | end | ||
| 985 | do | ||
| 986 | local tostring <const> = tostring | ||
| 987 | local concat <const> = table.concat | ||
| 988 | print(concat({ | ||
| 989 | "a", | ||
| 990 | tostring(1) | ||
| 991 | })) | ||
| 992 | end | ||
| 993 | do | ||
| 994 | local print <const> = print | ||
| 995 | local math <const> = math | ||
| 996 | print("hello") | ||
| 997 | math.random(3) | ||
| 998 | end | ||
| 999 | do | ||
| 1000 | local print <const> = print | ||
| 1001 | print(FLAG) | ||
| 1002 | FLAG = 123 | ||
| 1003 | end | ||
| 1004 | local _module_0 = { } | ||
| 1005 | local a, b, c = 1, 2, 3 | ||
| 1006 | _module_0["a"], _module_0["b"], _module_0["c"] = a, b, c | ||
| 1007 | local cool = "cat" | ||
| 1008 | _module_0["cool"] = cool | ||
| 1009 | local What | ||
| 1010 | if this then | ||
| 1011 | What = "abc" | ||
| 1012 | else | ||
| 1013 | What = "def" | ||
| 1014 | end | ||
| 1015 | _module_0["What"] = What | ||
| 1016 | local y | ||
| 1017 | y = function() | ||
| 1018 | local hallo = 3434 | ||
| 1019 | end | ||
| 1020 | _module_0["y"] = y | ||
| 1021 | local Something | ||
| 1022 | local _class_0 | ||
| 1023 | local _base_0 = { | ||
| 1024 | umm = "cool" | ||
| 1025 | } | ||
| 1026 | if _base_0.__index == nil then | ||
| 1027 | _base_0.__index = _base_0 | ||
| 1028 | end | ||
| 1029 | _class_0 = setmetatable({ | ||
| 1030 | __init = function() end, | ||
| 1031 | __base = _base_0, | ||
| 1032 | __name = "Something" | ||
| 1033 | }, { | ||
| 1034 | __index = _base_0, | ||
| 1035 | __call = function(cls, ...) | ||
| 1036 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1037 | cls.__init(_self_0, ...) | ||
| 1038 | return _self_0 | ||
| 1039 | end | ||
| 1040 | }) | ||
| 1041 | _base_0.__class = _class_0 | ||
| 1042 | Something = _class_0 | ||
| 1043 | _module_0["Something"] = Something | ||
| 1044 | return _module_0 | ||
| 1045 | local _module_0 = { } | ||
| 1046 | local loadstring, tolua | ||
| 1047 | do | ||
| 1048 | local _obj_0 = yue | ||
| 1049 | loadstring, tolua = _obj_0.loadstring, _obj_0.to_lua | ||
| 1050 | end | ||
| 1051 | _module_0["loadstring"], _module_0["tolua"] = loadstring, tolua | ||
| 1052 | local fieldA = tb.itemA.fieldA | ||
| 1053 | if fieldA == nil then | ||
| 1054 | fieldA = '默认值' | ||
| 1055 | end | ||
| 1056 | _module_0["fieldA"] = fieldA | ||
| 1057 | return _module_0 | ||
| 1058 | local _module_0 = setmetatable({ }, { }) | ||
| 1059 | _module_0.itemA = tb | ||
| 1060 | getmetatable(_module_0).__index = items | ||
| 1061 | _module_0["a-b-c"] = 123 | ||
| 1062 | return _module_0 | ||
| 1063 | local _module_0 = { } | ||
| 1064 | local d, e, f = 3, 2, 1 | ||
| 1065 | _module_0[#_module_0 + 1] = d | ||
| 1066 | _module_0[#_module_0 + 1] = e | ||
| 1067 | _module_0[#_module_0 + 1] = f | ||
| 1068 | if this then | ||
| 1069 | _module_0[#_module_0 + 1] = 123 | ||
| 1070 | else | ||
| 1071 | _module_0[#_module_0 + 1] = 456 | ||
| 1072 | end | ||
| 1073 | local _with_0 = tmp | ||
| 1074 | local j = 2000 | ||
| 1075 | _module_0[#_module_0 + 1] = _with_0 | ||
| 1076 | return _module_0 | ||
| 1077 | local _module_0 = nil | ||
| 1078 | _module_0 = function() | ||
| 1079 | print("你好") | ||
| 1080 | return 123 | ||
| 1081 | end | ||
| 1082 | return _module_0 | ||
| 1083 | local hello = "world" | ||
| 1084 | local a, b, c = 1, 2, 3 | ||
| 1085 | hello = 123 | ||
| 1086 | local x = 1 | ||
| 1087 | x = x + 1 | ||
| 1088 | x = x - 1 | ||
| 1089 | x = x * 10 | ||
| 1090 | x = x / 10 | ||
| 1091 | x = x % 10 | ||
| 1092 | local s = s .. "world" | ||
| 1093 | local arg = arg or "默认值" | ||
| 1094 | local a = 0 | ||
| 1095 | local b = 0 | ||
| 1096 | local c = 0 | ||
| 1097 | local d = 0 | ||
| 1098 | local e = 0 | ||
| 1099 | local x = f() | ||
| 1100 | local y = x | ||
| 1101 | local z = x | ||
| 1102 | do | ||
| 1103 | local a = 1 | ||
| 1104 | local x, y, z | ||
| 1105 | print("预先声明后续所有变量为局部变量") | ||
| 1106 | x = function() | ||
| 1107 | return 1 + y + z | ||
| 1108 | end | ||
| 1109 | y, z = 2, 3 | ||
| 1110 | instance = Item:new() | ||
| 1111 | end | ||
| 1112 | do | ||
| 1113 | local X = 1 | ||
| 1114 | local B | ||
| 1115 | print("只预先声明后续大写的变量为局部变量") | ||
| 1116 | local a = 1 | ||
| 1117 | B = 2 | ||
| 1118 | end | ||
| 1119 | do | ||
| 1120 | a = 1 | ||
| 1121 | print("预先声明所有变量为全局变量") | ||
| 1122 | x = function() | ||
| 1123 | return 1 + y + z | ||
| 1124 | end | ||
| 1125 | y, z = 2, 3 | ||
| 1126 | end | ||
| 1127 | do | ||
| 1128 | x = 1 | ||
| 1129 | print("只预先声明大写的变量为全局变量") | ||
| 1130 | local a = 1 | ||
| 1131 | B = 2 | ||
| 1132 | local Temp = "一个局部值" | ||
| 1133 | end | ||
| 542 | local hello = "world" | 1134 | local hello = "world" |
| 543 | local a, b, c = 1, 2, 3 | 1135 | local a, b, c = 1, 2, 3 |
| 544 | hello = 123 | 1136 | hello = 123 |
| @@ -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("你有 hello", hello) | ||
| 1426 | else | ||
| 1427 | local world = os.getenv("world") | ||
| 1428 | if world then | ||
| 1429 | print("你有 world", world) | ||
| 1430 | else | ||
| 1431 | print("什么都没有 :(") | ||
| 1432 | end | ||
| 1433 | end | ||
| 1434 | do | ||
| 1435 | local success, result = pcall(function() | ||
| 1436 | return "无报错地获取结果" | ||
| 1437 | end) | ||
| 1438 | if success then | ||
| 1439 | print(result) | ||
| 1440 | end | ||
| 1441 | end | ||
| 1442 | print("好的") | ||
| 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,23 @@ 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)) | ||
| 759 | local a = 1 | 1517 | local a = 1 |
| 760 | local b = 2 | 1518 | local b = 2 |
| 761 | print(a + b) | 1519 | print(a + b) |
| @@ -764,6 +1522,16 @@ Rx.Observable.fromRange(1, 8):filter(function(x) | |||
| 764 | end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) | 1522 | end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) |
| 765 | return value .. '!' | 1523 | return value .. '!' |
| 766 | end):subscribe(print) | 1524 | end):subscribe(print) |
| 1525 | local a = 1 | ||
| 1526 | local b = 2 | ||
| 1527 | print(a + b) | ||
| 1528 | Rx.Observable.fromRange(1, 8):filter(function(x) | ||
| 1529 | return x % 2 == 0 | ||
| 1530 | end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) | ||
| 1531 | return value .. '!' | ||
| 1532 | end):subscribe(print) | ||
| 1533 | local str = strA .. strB .. strC | ||
| 1534 | func(3000, "192.168.1.1") | ||
| 767 | local str = strA .. strB .. strC | 1535 | local str = strA .. strB .. strC |
| 768 | func(3000, "192.168.1.1") | 1536 | func(3000, "192.168.1.1") |
| 769 | xpcall(function() | 1537 | xpcall(function() |
| @@ -846,6 +1614,96 @@ f((function() | |||
| 846 | return e | 1614 | return e |
| 847 | end)) | 1615 | end)) |
| 848 | end)()) | 1616 | end)()) |
| 1617 | xpcall(function() | ||
| 1618 | return func(1, 2, 3) | ||
| 1619 | end, function(err) | ||
| 1620 | return print(yue.traceback(err)) | ||
| 1621 | end) | ||
| 1622 | local success, result = xpcall(function() | ||
| 1623 | return func(1, 2, 3) | ||
| 1624 | end, function(err) | ||
| 1625 | return yue.traceback(err) | ||
| 1626 | end) | ||
| 1627 | xpcall(function() | ||
| 1628 | return func(1, 2, 3) | ||
| 1629 | end, function(err) | ||
| 1630 | return print(yue.traceback(err)) | ||
| 1631 | end) | ||
| 1632 | success, result = pcall(function() | ||
| 1633 | return func(1, 2, 3) | ||
| 1634 | end) | ||
| 1635 | pcall(function() | ||
| 1636 | print("尝试中") | ||
| 1637 | return func(1, 2, 3) | ||
| 1638 | end) | ||
| 1639 | success, result = xpcall(function() | ||
| 1640 | return func(1, 2, 3) | ||
| 1641 | end, function(err) | ||
| 1642 | return print(yue.traceback(err)) | ||
| 1643 | end) | ||
| 1644 | if success then | ||
| 1645 | print(result) | ||
| 1646 | end | ||
| 1647 | local a, b, c | ||
| 1648 | do | ||
| 1649 | local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function() | ||
| 1650 | return func() | ||
| 1651 | end) | ||
| 1652 | if _ok_0 then | ||
| 1653 | a, b, c = _ret_0, _ret_1, _ret_2 | ||
| 1654 | end | ||
| 1655 | end | ||
| 1656 | do | ||
| 1657 | local _exp_0 = ((function() | ||
| 1658 | return (function(_arg_0, ...) | ||
| 1659 | local _ok_0 = _arg_0 | ||
| 1660 | if _ok_0 then | ||
| 1661 | return ... | ||
| 1662 | end | ||
| 1663 | end)(pcall(function() | ||
| 1664 | return func() | ||
| 1665 | end)) | ||
| 1666 | end)()) | ||
| 1667 | if _exp_0 ~= nil then | ||
| 1668 | a = _exp_0 | ||
| 1669 | else | ||
| 1670 | a = "default" | ||
| 1671 | end | ||
| 1672 | end | ||
| 1673 | f((function() | ||
| 1674 | return (function(_arg_0, ...) | ||
| 1675 | local _ok_0 = _arg_0 | ||
| 1676 | if _ok_0 then | ||
| 1677 | return ... | ||
| 1678 | end | ||
| 1679 | end)(pcall(function() | ||
| 1680 | return func() | ||
| 1681 | end)) | ||
| 1682 | end)()) | ||
| 1683 | f((function() | ||
| 1684 | return (function(_arg_0, ...) | ||
| 1685 | local _ok_0 = _arg_0 | ||
| 1686 | if _ok_0 then | ||
| 1687 | return ... | ||
| 1688 | end | ||
| 1689 | end)(xpcall(function() | ||
| 1690 | print(123) | ||
| 1691 | return func() | ||
| 1692 | end, function(e) | ||
| 1693 | print(e) | ||
| 1694 | return e | ||
| 1695 | end)) | ||
| 1696 | end)()) | ||
| 1697 | local a <const> = 123 | ||
| 1698 | local _ <close> = setmetatable({ }, { | ||
| 1699 | __close = function() | ||
| 1700 | return print("超出范围。") | ||
| 1701 | end | ||
| 1702 | }) | ||
| 1703 | local a, b, c, d | ||
| 1704 | local _obj_0 = tb | ||
| 1705 | a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] | ||
| 1706 | Constant = 123 | ||
| 849 | local a <const> = 123 | 1707 | local a <const> = 123 |
| 850 | local _ <close> = setmetatable({ }, { | 1708 | local _ <close> = setmetatable({ }, { |
| 851 | __close = function() | 1709 | __close = function() |
| @@ -868,6 +1726,18 @@ fn = function() | |||
| 868 | return str | 1726 | return str |
| 869 | end | 1727 | end |
| 870 | local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'" | 1728 | local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'" |
| 1729 | local some_string = "这是一个字符串\n 并包括一个换行。" | ||
| 1730 | print("我有" .. tostring(math.random() * 100) .. "%的把握。") | ||
| 1731 | local integer = 1000000 | ||
| 1732 | local hex = 0xEFBBBF | ||
| 1733 | local binary = 19 | ||
| 1734 | local str = "key: value\nlist:\n - item1\n - " .. tostring(expr) | ||
| 1735 | local fn | ||
| 1736 | fn = function() | ||
| 1737 | local str = "foo:\n bar: baz" | ||
| 1738 | return str | ||
| 1739 | end | ||
| 1740 | local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'" | ||
| 871 | local my_function | 1741 | local my_function |
| 872 | my_function = function() end | 1742 | my_function = function() end |
| 873 | my_function() | 1743 | my_function() |
| @@ -929,6 +1799,12 @@ some_args = function(x, y) | |||
| 929 | end | 1799 | end |
| 930 | return print(x + y) | 1800 | return print(x + y) |
| 931 | end | 1801 | end |
| 1802 | local a = x - 10 | ||
| 1803 | local b = x - 10 | ||
| 1804 | local c = x(-y) | ||
| 1805 | local d = x - z | ||
| 1806 | local x = func("hello") + 100 | ||
| 1807 | local y = func("hello" + 100) | ||
| 932 | my_func(5, 4, 3, 8, 9, 10) | 1808 | my_func(5, 4, 3, 8, 9, 10) |
| 933 | cool_func(1, 2, 3, 4, 5, 6, 7, 8) | 1809 | cool_func(1, 2, 3, 4, 5, 6, 7, 8) |
| 934 | my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4) | 1810 | my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4) |
| @@ -1046,8 +1922,215 @@ process = function(...) | |||
| 1046 | return sum | 1922 | return sum |
| 1047 | end | 1923 | end |
| 1048 | process(1, nil, 3, nil, 5) | 1924 | process(1, nil, 3, nil, 5) |
| 1049 | f(function() | 1925 | local my_function |
| 1050 | return print("hello") | 1926 | my_function = function() end |
| 1927 | my_function() | ||
| 1928 | local func_a | ||
| 1929 | func_a = function() | ||
| 1930 | return print("你好,世界") | ||
| 1931 | end | ||
| 1932 | local func_b | ||
| 1933 | func_b = function() | ||
| 1934 | local value = 100 | ||
| 1935 | return print("这个值是:", value) | ||
| 1936 | end | ||
| 1937 | func_a() | ||
| 1938 | func_b() | ||
| 1939 | local sum | ||
| 1940 | sum = function(x, y) | ||
| 1941 | return print("数字的和", 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("数字的和是", 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 = "某物" | ||
| 1969 | end | ||
| 1970 | if height == nil then | ||
| 1971 | height = 100 | ||
| 1972 | end | ||
| 1973 | print("你好,我是", name) | ||
| 1974 | return print("我的高度是", 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, "你好", "世界") then | ||
| 2012 | print("你好") | ||
| 2013 | print("我在if内部") | ||
| 2014 | end | ||
| 2015 | if func(1, 2, 3, "你好", "世界") then | ||
| 2016 | print("你好") | ||
| 2017 | print("我在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 | return print(a1, b, c) | ||
| 2044 | end | ||
| 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("参数个数:", t.n) | ||
| 2086 | print("表长度:", #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) | ||
| 2111 | end) | ||
| 2112 | f(function(self) | ||
| 2113 | return print(self.value) | ||
| 2114 | end) | ||
| 2115 | map(function(x) | ||
| 2116 | return x * 2 | ||
| 2117 | end, { | ||
| 2118 | 1, | ||
| 2119 | 2, | ||
| 2120 | 3 | ||
| 2121 | }) | ||
| 2122 | local result, msg | ||
| 2123 | do | ||
| 2124 | result, msg = readAsync("文件名.txt", function(data) | ||
| 2125 | print(data) | ||
| 2126 | return processAsync(data, function(info) | ||
| 2127 | return check(info) | ||
| 2128 | end) | ||
| 2129 | end) | ||
| 2130 | end | ||
| 2131 | print(result, msg) | ||
| 2132 | f(function(x) | ||
| 2133 | return print("hello" .. x) | ||
| 1051 | end) | 2134 | end) |
| 1052 | f(function(self) | 2135 | f(function(self) |
| 1053 | return print(self.value) | 2136 | return print(self.value) |
| @@ -1137,6 +2220,74 @@ local some_values = { | |||
| 1137 | local list_with_one_element = { | 2220 | local list_with_one_element = { |
| 1138 | 1 | 2221 | 1 |
| 1139 | } | 2222 | } |
| 2223 | local some_values = { | ||
| 2224 | 1, | ||
| 2225 | 2, | ||
| 2226 | 3, | ||
| 2227 | 4 | ||
| 2228 | } | ||
| 2229 | local some_values = { | ||
| 2230 | name = "Bill", | ||
| 2231 | age = 200, | ||
| 2232 | ["favorite food"] = "rice" | ||
| 2233 | } | ||
| 2234 | local profile = { | ||
| 2235 | height = "4英尺", | ||
| 2236 | shoe_size = 13, | ||
| 2237 | favorite_foods = { | ||
| 2238 | "冰淇淋", | ||
| 2239 | "甜甜圈" | ||
| 2240 | } | ||
| 2241 | } | ||
| 2242 | local values = { | ||
| 2243 | 1, | ||
| 2244 | 2, | ||
| 2245 | 3, | ||
| 2246 | 4, | ||
| 2247 | 5, | ||
| 2248 | 6, | ||
| 2249 | 7, | ||
| 2250 | 8, | ||
| 2251 | name = "超人", | ||
| 2252 | occupation = "打击犯罪" | ||
| 2253 | } | ||
| 2254 | my_function({ | ||
| 2255 | dance = "探戈", | ||
| 2256 | partner = "无" | ||
| 2257 | }) | ||
| 2258 | local y = { | ||
| 2259 | type = "狗", | ||
| 2260 | legs = 4, | ||
| 2261 | tails = 1 | ||
| 2262 | } | ||
| 2263 | local tbl = { | ||
| 2264 | ["do"] = "某事", | ||
| 2265 | ["end"] = "饥饿" | ||
| 2266 | } | ||
| 2267 | local hair = "金色" | ||
| 2268 | local height = 200 | ||
| 2269 | local person = { | ||
| 2270 | hair = hair, | ||
| 2271 | height = height, | ||
| 2272 | shoe_size = 40 | ||
| 2273 | } | ||
| 2274 | print_table({ | ||
| 2275 | hair = hair, | ||
| 2276 | height = height | ||
| 2277 | }) | ||
| 2278 | local t = { | ||
| 2279 | [1 + 2] = "你好", | ||
| 2280 | ["你好 世界"] = true | ||
| 2281 | } | ||
| 2282 | local some_values = { | ||
| 2283 | 1, | ||
| 2284 | 2, | ||
| 2285 | 3, | ||
| 2286 | 4 | ||
| 2287 | } | ||
| 2288 | local list_with_one_element = { | ||
| 2289 | 1 | ||
| 2290 | } | ||
| 1140 | local items = { | 2291 | local items = { |
| 1141 | 1, | 2292 | 1, |
| 1142 | 2, | 2293 | 2, |
| @@ -1335,15 +2486,250 @@ for _index_0 = _min_0, 1, -1 do | |||
| 1335 | end | 2486 | end |
| 1336 | reverse_slice = _accum_0 | 2487 | reverse_slice = _accum_0 |
| 1337 | 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 | ||
| 1338 | local _accum_0 = { } | 2501 | local _accum_0 = { } |
| 1339 | local _len_0 = 1 | 2502 | local _len_0 = 1 |
| 1340 | local _list_0 = items | 2503 | local _list_0 = items |
| 1341 | 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 | ||
| 2507 | local _item_0 = _list_0[_index_0] | ||
| 2508 | _accum_0[_len_0] = _item_0 | ||
| 2509 | _len_0 = _len_0 + 1 | ||
| 2510 | end | ||
| 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 | ||
| 1342 | local _item_0 = _list_0[_index_0] | 2728 | local _item_0 = _list_0[_index_0] |
| 1343 | _accum_0[_len_0] = _item_0 | 2729 | _accum_0[_len_0] = _item_0 |
| 1344 | _len_0 = _len_0 + 1 | 2730 | _len_0 = _len_0 + 1 |
| 1345 | end | 2731 | end |
| 1346 | sub_list = _accum_0 | 2732 | last_four_items = _accum_0 |
| 1347 | for i = 10, 20 do | 2733 | for i = 10, 20 do |
| 1348 | print(i) | 2734 | print(i) |
| 1349 | end | 2735 | end |
| @@ -1408,6 +2794,86 @@ func_b = function() | |||
| 1408 | end | 2794 | end |
| 1409 | print(func_a()) | 2795 | print(func_a()) |
| 1410 | 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 | ||
| 1411 | local i = 10 | 2877 | local i = 10 |
| 1412 | repeat | 2878 | repeat |
| 1413 | print(i) | 2879 | print(i) |
| @@ -1429,6 +2895,11 @@ end | |||
| 1429 | while not (running == false) do | 2895 | while not (running == false) do |
| 1430 | my_function() | 2896 | my_function() |
| 1431 | end | 2897 | end |
| 2898 | local i = 10 | ||
| 2899 | repeat | ||
| 2900 | print(i) | ||
| 2901 | i = i - 1 | ||
| 2902 | until i == 0 | ||
| 1432 | local i = 0 | 2903 | local i = 0 |
| 1433 | while i < 10 do | 2904 | while i < 10 do |
| 1434 | i = i + 1 | 2905 | i = i + 1 |
| @@ -1459,6 +2930,95 @@ for _index_0 = 1, #my_numbers do | |||
| 1459 | ::_continue_0:: | 2930 | ::_continue_0:: |
| 1460 | end | 2931 | end |
| 1461 | odds = _accum_0 | 2932 | odds = _accum_0 |
| 2933 | local i = 0 | ||
| 2934 | while i < 10 do | ||
| 2935 | i = i + 1 | ||
| 2936 | if i % 2 == 0 then | ||
| 2937 | goto _continue_0 | ||
| 2938 | end | ||
| 2939 | print(i) | ||
| 2940 | ::_continue_0:: | ||
| 2941 | end | ||
| 2942 | local my_numbers = { | ||
| 2943 | 1, | ||
| 2944 | 2, | ||
| 2945 | 3, | ||
| 2946 | 4, | ||
| 2947 | 5, | ||
| 2948 | 6 | ||
| 2949 | } | ||
| 2950 | local odds | ||
| 2951 | local _accum_0 = { } | ||
| 2952 | local _len_0 = 1 | ||
| 2953 | for _index_0 = 1, #my_numbers do | ||
| 2954 | local x = my_numbers[_index_0] | ||
| 2955 | if x % 2 == 1 then | ||
| 2956 | goto _continue_0 | ||
| 2957 | end | ||
| 2958 | _accum_0[_len_0] = x | ||
| 2959 | _len_0 = _len_0 + 1 | ||
| 2960 | ::_continue_0:: | ||
| 2961 | end | ||
| 2962 | odds = _accum_0 | ||
| 2963 | local have_coins = false | ||
| 2964 | if have_coins then | ||
| 2965 | print("有硬币") | ||
| 2966 | else | ||
| 2967 | print("没有硬币") | ||
| 2968 | end | ||
| 2969 | local have_coins = false | ||
| 2970 | if have_coins then | ||
| 2971 | print("有硬币") | ||
| 2972 | else | ||
| 2973 | print("没有硬币") | ||
| 2974 | end | ||
| 2975 | local have_coins = false | ||
| 2976 | print((function() | ||
| 2977 | if have_coins then | ||
| 2978 | return "有硬币" | ||
| 2979 | else | ||
| 2980 | return "没有硬币" | ||
| 2981 | end | ||
| 2982 | end)()) | ||
| 2983 | local is_tall | ||
| 2984 | is_tall = function(name) | ||
| 2985 | if name == "Rob" then | ||
| 2986 | return true | ||
| 2987 | else | ||
| 2988 | return false | ||
| 2989 | end | ||
| 2990 | end | ||
| 2991 | local message | ||
| 2992 | if is_tall("Rob") then | ||
| 2993 | message = "我很高" | ||
| 2994 | else | ||
| 2995 | message = "我不是很高" | ||
| 2996 | end | ||
| 2997 | print(message) | ||
| 2998 | if not (os.date("%A") == "Monday") then | ||
| 2999 | print("今天不是星期一!") | ||
| 3000 | end | ||
| 3001 | if not (math.random() > 0.1) then | ||
| 3002 | print("你真幸运!") | ||
| 3003 | end | ||
| 3004 | local a = 5 | ||
| 3005 | if (1 == a or 3 == a or 5 == a or 7 == a) then | ||
| 3006 | print("检查离散值的相等性") | ||
| 3007 | end | ||
| 3008 | if (function() | ||
| 3009 | local _check_0 = list | ||
| 3010 | for _index_0 = 1, #_check_0 do | ||
| 3011 | if _check_0[_index_0] == a then | ||
| 3012 | return true | ||
| 3013 | end | ||
| 3014 | end | ||
| 3015 | return false | ||
| 3016 | end)() then | ||
| 3017 | print("检查`a`是否在列表中") | ||
| 3018 | end | ||
| 3019 | if not (math.random() > 0.1) then | ||
| 3020 | print("你很幸运!") | ||
| 3021 | end | ||
| 1462 | local have_coins = false | 3022 | local have_coins = false |
| 1463 | if have_coins then | 3023 | if have_coins then |
| 1464 | print("有硬币") | 3024 | print("有硬币") |
| @@ -1532,6 +3092,312 @@ end | |||
| 1532 | while not reader:eof() do | 3092 | while not reader:eof() do |
| 1533 | reader:parse_line() | 3093 | reader:parse_line() |
| 1534 | end | 3094 | end |
| 3095 | if name == "Rob" then | ||
| 3096 | print("你好,世界") | ||
| 3097 | end | ||
| 3098 | local _list_0 = items | ||
| 3099 | for _index_0 = 1, #_list_0 do | ||
| 3100 | local item = _list_0[_index_0] | ||
| 3101 | print("项目: ", item) | ||
| 3102 | end | ||
| 3103 | while game:isRunning() do | ||
| 3104 | game:update() | ||
| 3105 | end | ||
| 3106 | while not reader:eof() do | ||
| 3107 | reader:parse_line() | ||
| 3108 | end | ||
| 3109 | local name = "Dan" | ||
| 3110 | if "Robert" == name then | ||
| 3111 | print("你是Robert") | ||
| 3112 | elseif "Dan" == name or "Daniel" == name then | ||
| 3113 | print("你的名字是Dan") | ||
| 3114 | else | ||
| 3115 | print("我不认识你,你的名字是" .. tostring(name)) | ||
| 3116 | end | ||
| 3117 | local b = 1 | ||
| 3118 | local next_number | ||
| 3119 | if 1 == b then | ||
| 3120 | next_number = 2 | ||
| 3121 | elseif 2 == b then | ||
| 3122 | next_number = 3 | ||
| 3123 | else | ||
| 3124 | next_number = error("数字数得太大了!") | ||
| 3125 | end | ||
| 3126 | local msg | ||
| 3127 | local _exp_0 = math.random(1, 5) | ||
| 3128 | if 1 == _exp_0 then | ||
| 3129 | msg = "你很幸运" | ||
| 3130 | elseif 2 == _exp_0 then | ||
| 3131 | msg = "你差点很幸运" | ||
| 3132 | else | ||
| 3133 | msg = "不太幸运" | ||
| 3134 | end | ||
| 3135 | do | ||
| 3136 | local _exp_0 = math.random(1, 5) | ||
| 3137 | if 1 == _exp_0 then | ||
| 3138 | print("你很幸运") | ||
| 3139 | else | ||
| 3140 | print("不太幸运") | ||
| 3141 | end | ||
| 3142 | end | ||
| 3143 | local _exp_0 = math.random(1, 5) | ||
| 3144 | if 1 == _exp_0 then | ||
| 3145 | print("你很幸运") | ||
| 3146 | else | ||
| 3147 | print("不太幸运") | ||
| 3148 | end | ||
| 3149 | local items = { | ||
| 3150 | { | ||
| 3151 | x = 100, | ||
| 3152 | y = 200 | ||
| 3153 | }, | ||
| 3154 | { | ||
| 3155 | width = 300, | ||
| 3156 | height = 400 | ||
| 3157 | } | ||
| 3158 | } | ||
| 3159 | for _index_0 = 1, #items do | ||
| 3160 | local item = items[_index_0] | ||
| 3161 | local _type_0 = type(item) | ||
| 3162 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 3163 | local _match_0 = false | ||
| 3164 | if _tab_0 then | ||
| 3165 | local x = item.x | ||
| 3166 | local y = item.y | ||
| 3167 | if x ~= nil and y ~= nil then | ||
| 3168 | _match_0 = true | ||
| 3169 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) | ||
| 3170 | end | ||
| 3171 | end | ||
| 3172 | if not _match_0 then | ||
| 3173 | if _tab_0 then | ||
| 3174 | local width = item.width | ||
| 3175 | local height = item.height | ||
| 3176 | if width ~= nil and height ~= nil then | ||
| 3177 | print("尺寸 " .. tostring(width) .. ", " .. tostring(height)) | ||
| 3178 | end | ||
| 3179 | end | ||
| 3180 | end | ||
| 3181 | end | ||
| 3182 | local item = { } | ||
| 3183 | local x, y = item.pos.x, item.pos.y | ||
| 3184 | if x == nil then | ||
| 3185 | x = 50 | ||
| 3186 | end | ||
| 3187 | if y == nil then | ||
| 3188 | y = 200 | ||
| 3189 | end | ||
| 3190 | local _type_0 = type(item) | ||
| 3191 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 3192 | if _tab_0 then | ||
| 3193 | do | ||
| 3194 | local _obj_0 = item.pos | ||
| 3195 | local _type_1 = type(_obj_0) | ||
| 3196 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 3197 | x = _obj_0.x | ||
| 3198 | end | ||
| 3199 | end | ||
| 3200 | do | ||
| 3201 | local _obj_0 = item.pos | ||
| 3202 | local _type_1 = type(_obj_0) | ||
| 3203 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 3204 | y = _obj_0.y | ||
| 3205 | end | ||
| 3206 | end | ||
| 3207 | if x == nil then | ||
| 3208 | x = 50 | ||
| 3209 | end | ||
| 3210 | if y == nil then | ||
| 3211 | y = 200 | ||
| 3212 | end | ||
| 3213 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) | ||
| 3214 | end | ||
| 3215 | local _exp_0 = tb | ||
| 3216 | local _type_0 = type(_exp_0) | ||
| 3217 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 3218 | local _match_0 = false | ||
| 3219 | if _tab_0 then | ||
| 3220 | if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then | ||
| 3221 | _match_0 = true | ||
| 3222 | print("1, 2, 3") | ||
| 3223 | end | ||
| 3224 | end | ||
| 3225 | if not _match_0 then | ||
| 3226 | local _match_1 = false | ||
| 3227 | if _tab_0 then | ||
| 3228 | local b = _exp_0[2] | ||
| 3229 | if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then | ||
| 3230 | _match_1 = true | ||
| 3231 | print("1, " .. tostring(b) .. ", 3") | ||
| 3232 | end | ||
| 3233 | end | ||
| 3234 | if not _match_1 then | ||
| 3235 | if _tab_0 then | ||
| 3236 | local b = _exp_0[3] | ||
| 3237 | if b == nil then | ||
| 3238 | b = 3 | ||
| 3239 | end | ||
| 3240 | if 1 == _exp_0[1] and 2 == _exp_0[2] then | ||
| 3241 | print("1, 2, " .. tostring(b)) | ||
| 3242 | end | ||
| 3243 | end | ||
| 3244 | end | ||
| 3245 | end | ||
| 3246 | local _exp_0 = tb | ||
| 3247 | local _type_0 = type(_exp_0) | ||
| 3248 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 3249 | local _match_0 = false | ||
| 3250 | if _tab_0 then | ||
| 3251 | local result = _exp_0.result | ||
| 3252 | if true == _exp_0.success and result ~= nil then | ||
| 3253 | _match_0 = true | ||
| 3254 | print("成功", result) | ||
| 3255 | end | ||
| 3256 | end | ||
| 3257 | if not _match_0 then | ||
| 3258 | local _match_1 = false | ||
| 3259 | if _tab_0 then | ||
| 3260 | if false == _exp_0.success then | ||
| 3261 | _match_1 = true | ||
| 3262 | print("失败", result) | ||
| 3263 | end | ||
| 3264 | end | ||
| 3265 | if not _match_1 then | ||
| 3266 | print("无效值") | ||
| 3267 | end | ||
| 3268 | end | ||
| 3269 | local _exp_0 = tb | ||
| 3270 | local _type_0 = type(_exp_0) | ||
| 3271 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 3272 | local _match_0 = false | ||
| 3273 | if _tab_0 then | ||
| 3274 | local content | ||
| 3275 | do | ||
| 3276 | local _obj_0 = _exp_0.data | ||
| 3277 | local _type_1 = type(_obj_0) | ||
| 3278 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 3279 | content = _obj_0.content | ||
| 3280 | end | ||
| 3281 | end | ||
| 3282 | local _val_0 | ||
| 3283 | do | ||
| 3284 | local _obj_0 = _exp_0.data | ||
| 3285 | if _obj_0 ~= nil then | ||
| 3286 | _val_0 = _obj_0.type | ||
| 3287 | end | ||
| 3288 | end | ||
| 3289 | if "success" == _val_0 and content ~= nil then | ||
| 3290 | _match_0 = true | ||
| 3291 | print("成功", content) | ||
| 3292 | end | ||
| 3293 | end | ||
| 3294 | if not _match_0 then | ||
| 3295 | local _match_1 = false | ||
| 3296 | if _tab_0 then | ||
| 3297 | local content | ||
| 3298 | do | ||
| 3299 | local _obj_0 = _exp_0.data | ||
| 3300 | local _type_1 = type(_obj_0) | ||
| 3301 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 3302 | content = _obj_0.content | ||
| 3303 | end | ||
| 3304 | end | ||
| 3305 | local _val_0 | ||
| 3306 | do | ||
| 3307 | local _obj_0 = _exp_0.data | ||
| 3308 | if _obj_0 ~= nil then | ||
| 3309 | _val_0 = _obj_0.type | ||
| 3310 | end | ||
| 3311 | end | ||
| 3312 | if "error" == _val_0 and content ~= nil then | ||
| 3313 | _match_1 = true | ||
| 3314 | print("失败", content) | ||
| 3315 | end | ||
| 3316 | end | ||
| 3317 | if not _match_1 then | ||
| 3318 | print("无效值") | ||
| 3319 | end | ||
| 3320 | end | ||
| 3321 | local _exp_0 = tb | ||
| 3322 | local _type_0 = type(_exp_0) | ||
| 3323 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 3324 | if _tab_0 then | ||
| 3325 | local fourth = _exp_0[4] | ||
| 3326 | local _val_0 | ||
| 3327 | do | ||
| 3328 | local _obj_0 = _exp_0[1] | ||
| 3329 | if _obj_0 ~= nil then | ||
| 3330 | _val_0 = _obj_0.a | ||
| 3331 | end | ||
| 3332 | end | ||
| 3333 | local _val_1 | ||
| 3334 | do | ||
| 3335 | local _obj_0 = _exp_0[1] | ||
| 3336 | if _obj_0 ~= nil then | ||
| 3337 | _val_1 = _obj_0.b | ||
| 3338 | end | ||
| 3339 | end | ||
| 3340 | local _val_2 | ||
| 3341 | do | ||
| 3342 | local _obj_0 = _exp_0[2] | ||
| 3343 | if _obj_0 ~= nil then | ||
| 3344 | _val_2 = _obj_0.a | ||
| 3345 | end | ||
| 3346 | end | ||
| 3347 | local _val_3 | ||
| 3348 | do | ||
| 3349 | local _obj_0 = _exp_0[2] | ||
| 3350 | if _obj_0 ~= nil then | ||
| 3351 | _val_3 = _obj_0.b | ||
| 3352 | end | ||
| 3353 | end | ||
| 3354 | local _val_4 | ||
| 3355 | do | ||
| 3356 | local _obj_0 = _exp_0[3] | ||
| 3357 | if _obj_0 ~= nil then | ||
| 3358 | _val_4 = _obj_0.a | ||
| 3359 | end | ||
| 3360 | end | ||
| 3361 | local _val_5 | ||
| 3362 | do | ||
| 3363 | local _obj_0 = _exp_0[3] | ||
| 3364 | if _obj_0 ~= nil then | ||
| 3365 | _val_5 = _obj_0.b | ||
| 3366 | end | ||
| 3367 | end | ||
| 3368 | 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 | ||
| 3369 | print("匹配成功", fourth) | ||
| 3370 | end | ||
| 3371 | end | ||
| 3372 | local segments = { | ||
| 3373 | "admin", | ||
| 3374 | "users", | ||
| 3375 | "logs", | ||
| 3376 | "view" | ||
| 3377 | } | ||
| 3378 | local _type_0 = type(segments) | ||
| 3379 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 3380 | if _tab_0 then | ||
| 3381 | local groups | ||
| 3382 | do | ||
| 3383 | local _accum_0 = { } | ||
| 3384 | local _len_0 = 1 | ||
| 3385 | local _max_0 = #segments + -3 + 1 | ||
| 3386 | for _index_0 = 1, _max_0 do | ||
| 3387 | local _item_0 = segments[_index_0] | ||
| 3388 | _accum_0[_len_0] = _item_0 | ||
| 3389 | _len_0 = _len_0 + 1 | ||
| 3390 | end | ||
| 3391 | groups = _accum_0 | ||
| 3392 | end | ||
| 3393 | local resource = segments[#segments - 1] | ||
| 3394 | local action = segments[#segments] | ||
| 3395 | if resource ~= nil and action ~= nil then | ||
| 3396 | print("Group:", groups) | ||
| 3397 | print("Resource:", resource) | ||
| 3398 | print("Action:", action) | ||
| 3399 | end | ||
| 3400 | end | ||
| 1535 | local name = "Dan" | 3401 | local name = "Dan" |
| 1536 | if "Robert" == name then | 3402 | if "Robert" == name then |
| 1537 | print("你是Robert") | 3403 | print("你是Robert") |
| @@ -2444,1940 +4310,6 @@ end | |||
| 2444 | local y = Y() | 4310 | local y = Y() |
| 2445 | y:func() | 4311 | y:func() |
| 2446 | assert(y.__class.__parent ~= X) | 4312 | assert(y.__class.__parent ~= X) |
| 2447 | local _with_0 = Person() | ||
| 2448 | _with_0.name = "Oswald" | ||
| 2449 | _with_0:add_relative(my_dad) | ||
| 2450 | _with_0:save() | ||
| 2451 | print(_with_0.name) | ||
| 2452 | local file | ||
| 2453 | local _with_0 = File("favorite_foods.txt") | ||
| 2454 | _with_0:set_encoding("utf8") | ||
| 2455 | file = _with_0 | ||
| 2456 | local create_person | ||
| 2457 | create_person = function(name, relatives) | ||
| 2458 | local _with_0 = Person() | ||
| 2459 | _with_0.name = name | ||
| 2460 | for _index_0 = 1, #relatives do | ||
| 2461 | local relative = relatives[_index_0] | ||
| 2462 | _with_0:add_relative(relative) | ||
| 2463 | end | ||
| 2464 | return _with_0 | ||
| 2465 | end | ||
| 2466 | local me = create_person("Leaf", { | ||
| 2467 | dad, | ||
| 2468 | mother, | ||
| 2469 | sister | ||
| 2470 | }) | ||
| 2471 | local str = "你好" | ||
| 2472 | print("原始:", str) | ||
| 2473 | print("大写:", str:upper()) | ||
| 2474 | local _with_0 = tb | ||
| 2475 | _with_0[1] = 1 | ||
| 2476 | print(_with_0[2]) | ||
| 2477 | do | ||
| 2478 | local _with_1 = _with_0[abc] | ||
| 2479 | _with_1[3] = _with_1[2]:func() | ||
| 2480 | _with_1["key-name"] = value | ||
| 2481 | end | ||
| 2482 | _with_0[#_with_0 + 1] = "abc" | ||
| 2483 | local _with_0 = obj | ||
| 2484 | if _with_0 ~= nil then | ||
| 2485 | print(obj.name) | ||
| 2486 | end | ||
| 2487 | do | ||
| 2488 | local var = "hello" | ||
| 2489 | print(var) | ||
| 2490 | end | ||
| 2491 | print(var) | ||
| 2492 | local counter | ||
| 2493 | do | ||
| 2494 | local i = 0 | ||
| 2495 | counter = function() | ||
| 2496 | i = i + 1 | ||
| 2497 | return i | ||
| 2498 | end | ||
| 2499 | end | ||
| 2500 | print(counter()) | ||
| 2501 | print(counter()) | ||
| 2502 | local tbl = { | ||
| 2503 | key = (function() | ||
| 2504 | print("分配键值!") | ||
| 2505 | return 1234 | ||
| 2506 | end)() | ||
| 2507 | } | ||
| 2508 | local my_object = { | ||
| 2509 | value = 1000, | ||
| 2510 | write = function(self) | ||
| 2511 | return print("值为:", self.value) | ||
| 2512 | end | ||
| 2513 | } | ||
| 2514 | local run_callback | ||
| 2515 | run_callback = function(func) | ||
| 2516 | print("运行回调...") | ||
| 2517 | return func() | ||
| 2518 | end | ||
| 2519 | run_callback(my_object.write) | ||
| 2520 | run_callback((function() | ||
| 2521 | local _base_0 = my_object | ||
| 2522 | local _fn_0 = _base_0.write | ||
| 2523 | return _fn_0 and function(...) | ||
| 2524 | return _fn_0(_base_0, ...) | ||
| 2525 | end | ||
| 2526 | end)()) | ||
| 2527 | local i = 100 | ||
| 2528 | local my_func | ||
| 2529 | my_func = function() | ||
| 2530 | i = 10 | ||
| 2531 | while i > 0 do | ||
| 2532 | print(i) | ||
| 2533 | i = i - 1 | ||
| 2534 | end | ||
| 2535 | end | ||
| 2536 | my_func() | ||
| 2537 | print(i) | ||
| 2538 | local i = 100 | ||
| 2539 | local my_func | ||
| 2540 | my_func = function() | ||
| 2541 | local i = "hello" | ||
| 2542 | end | ||
| 2543 | my_func() | ||
| 2544 | print(i) | ||
| 2545 | local tmp = 1213 | ||
| 2546 | local i, k = 100, 50 | ||
| 2547 | local my_func | ||
| 2548 | my_func = function(add) | ||
| 2549 | local tmp = tmp + add | ||
| 2550 | i = i + tmp | ||
| 2551 | k = k + tmp | ||
| 2552 | end | ||
| 2553 | my_func(22) | ||
| 2554 | print(i, k) | ||
| 2555 | local _module_0 = { } | ||
| 2556 | local p, to_lua | ||
| 2557 | do | ||
| 2558 | local _obj_0 = require("yue") | ||
| 2559 | p, to_lua = _obj_0.p, _obj_0.to_lua | ||
| 2560 | end | ||
| 2561 | local inventory = { | ||
| 2562 | equipment = { | ||
| 2563 | "sword", | ||
| 2564 | "shield" | ||
| 2565 | }, | ||
| 2566 | items = { | ||
| 2567 | { | ||
| 2568 | name = "potion", | ||
| 2569 | count = 10 | ||
| 2570 | }, | ||
| 2571 | { | ||
| 2572 | name = "bread", | ||
| 2573 | count = 3 | ||
| 2574 | } | ||
| 2575 | } | ||
| 2576 | } | ||
| 2577 | local map | ||
| 2578 | map = function(arr, action) | ||
| 2579 | local _accum_0 = { } | ||
| 2580 | local _len_0 = 1 | ||
| 2581 | for _index_0 = 1, #arr do | ||
| 2582 | local item = arr[_index_0] | ||
| 2583 | _accum_0[_len_0] = action(item) | ||
| 2584 | _len_0 = _len_0 + 1 | ||
| 2585 | end | ||
| 2586 | return _accum_0 | ||
| 2587 | end | ||
| 2588 | local filter | ||
| 2589 | filter = function(arr, cond) | ||
| 2590 | local _accum_0 = { } | ||
| 2591 | local _len_0 = 1 | ||
| 2592 | for _index_0 = 1, #arr do | ||
| 2593 | local item = arr[_index_0] | ||
| 2594 | if cond(item) then | ||
| 2595 | _accum_0[_len_0] = item | ||
| 2596 | _len_0 = _len_0 + 1 | ||
| 2597 | end | ||
| 2598 | end | ||
| 2599 | return _accum_0 | ||
| 2600 | end | ||
| 2601 | local reduce | ||
| 2602 | reduce = function(arr, init, action) | ||
| 2603 | for _index_0 = 1, #arr do | ||
| 2604 | local item = arr[_index_0] | ||
| 2605 | init = action(init, item) | ||
| 2606 | end | ||
| 2607 | return init | ||
| 2608 | end | ||
| 2609 | print(reduce(filter(map({ | ||
| 2610 | 1, | ||
| 2611 | 2, | ||
| 2612 | 3 | ||
| 2613 | }, function(x) | ||
| 2614 | return x * 2 | ||
| 2615 | end), function(x) | ||
| 2616 | return x > 4 | ||
| 2617 | end), 0, function(a, b) | ||
| 2618 | return a + b | ||
| 2619 | end)) | ||
| 2620 | local apple = setmetatable({ | ||
| 2621 | size = 15, | ||
| 2622 | }, { | ||
| 2623 | __index = { | ||
| 2624 | color = 0x00ffff | ||
| 2625 | } | ||
| 2626 | }) | ||
| 2627 | if (getmetatable(apple) ~= nil) then | ||
| 2628 | p(apple.size, apple.color, getmetatable(apple).__index) | ||
| 2629 | end | ||
| 2630 | local _u1f31b = "月之脚本" | ||
| 2631 | _module_0["🌛"] = _u1f31b | ||
| 2632 | return _module_0 | ||
| 2633 | local area = 6.2831853071796 * 5 | ||
| 2634 | print('你好 世界') | ||
| 2635 | do | ||
| 2636 | assert(item ~= nil) | ||
| 2637 | end | ||
| 2638 | local value = item | ||
| 2639 | if (f1() and f2() and f3()) then | ||
| 2640 | print("OK") | ||
| 2641 | end | ||
| 2642 | do | ||
| 2643 | local funcA | ||
| 2644 | funcA = function() end | ||
| 2645 | end | ||
| 2646 | local funcA | ||
| 2647 | funcA = function() | ||
| 2648 | return "无法访问宏生成月之脚本里定义的变量" | ||
| 2649 | end | ||
| 2650 | do | ||
| 2651 | local function funcB() end | ||
| 2652 | end | ||
| 2653 | local funcB | ||
| 2654 | funcB = function() | ||
| 2655 | return "无法访问宏生成 Lua 代码里定义的变量" | ||
| 2656 | end | ||
| 2657 | do | ||
| 2658 | -- 插入原始Lua代码 | ||
| 2659 | if cond then | ||
| 2660 | print("输出") | ||
| 2661 | end | ||
| 2662 | end | ||
| 2663 | print("yuescript") | ||
| 2664 | print(2) | ||
| 2665 | print("有效的枚举类型:", "Static") | ||
| 2666 | do | ||
| 2667 | print(123, "hello") | ||
| 2668 | end | ||
| 2669 | do | ||
| 2670 | print(123, "hello") | ||
| 2671 | end | ||
| 2672 | if tb ~= nil then | ||
| 2673 | tb:func() | ||
| 2674 | end | ||
| 2675 | if tb ~= nil then | ||
| 2676 | tb:func() | ||
| 2677 | end | ||
| 2678 | 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) | ||
| 2679 | local a = 5 | ||
| 2680 | print(1 <= a and a <= 10) | ||
| 2681 | local v | ||
| 2682 | v = function(x) | ||
| 2683 | print(x) | ||
| 2684 | return x | ||
| 2685 | end | ||
| 2686 | print((function() | ||
| 2687 | local _cond_0 = v(2) | ||
| 2688 | if not (v(1) < _cond_0) then | ||
| 2689 | return false | ||
| 2690 | else | ||
| 2691 | return _cond_0 <= v(3) | ||
| 2692 | end | ||
| 2693 | end)()) | ||
| 2694 | print((function() | ||
| 2695 | local _cond_0 = v(2) | ||
| 2696 | if not (v(1) > _cond_0) then | ||
| 2697 | return false | ||
| 2698 | else | ||
| 2699 | return _cond_0 <= v(3) | ||
| 2700 | end | ||
| 2701 | end)()) | ||
| 2702 | local tab = { } | ||
| 2703 | tab[#tab + 1] = "Value" | ||
| 2704 | local tbA = { | ||
| 2705 | 1, | ||
| 2706 | 2, | ||
| 2707 | 3 | ||
| 2708 | } | ||
| 2709 | local tbB = { | ||
| 2710 | 4, | ||
| 2711 | 5, | ||
| 2712 | 6 | ||
| 2713 | } | ||
| 2714 | local _len_0 = #tbA + 1 | ||
| 2715 | for _index_0 = 1, #tbB do | ||
| 2716 | local _elm_0 = tbB[_index_0] | ||
| 2717 | tbA[_len_0], _len_0 = _elm_0, _len_0 + 1 | ||
| 2718 | end | ||
| 2719 | local parts = { | ||
| 2720 | "shoulders", | ||
| 2721 | "knees" | ||
| 2722 | } | ||
| 2723 | local lyrics | ||
| 2724 | do | ||
| 2725 | local _tab_0 = { | ||
| 2726 | "head" | ||
| 2727 | } | ||
| 2728 | local _idx_0 = 1 | ||
| 2729 | for _key_0, _value_0 in pairs(parts) do | ||
| 2730 | if _idx_0 == _key_0 then | ||
| 2731 | _tab_0[#_tab_0 + 1] = _value_0 | ||
| 2732 | _idx_0 = _idx_0 + 1 | ||
| 2733 | else | ||
| 2734 | _tab_0[_key_0] = _value_0 | ||
| 2735 | end | ||
| 2736 | end | ||
| 2737 | _tab_0[#_tab_0 + 1] = "and" | ||
| 2738 | _tab_0[#_tab_0 + 1] = "toes" | ||
| 2739 | lyrics = _tab_0 | ||
| 2740 | end | ||
| 2741 | local copy | ||
| 2742 | do | ||
| 2743 | local _tab_0 = { } | ||
| 2744 | local _idx_0 = 1 | ||
| 2745 | for _key_0, _value_0 in pairs(other) do | ||
| 2746 | if _idx_0 == _key_0 then | ||
| 2747 | _tab_0[#_tab_0 + 1] = _value_0 | ||
| 2748 | _idx_0 = _idx_0 + 1 | ||
| 2749 | else | ||
| 2750 | _tab_0[_key_0] = _value_0 | ||
| 2751 | end | ||
| 2752 | end | ||
| 2753 | copy = _tab_0 | ||
| 2754 | end | ||
| 2755 | local a = { | ||
| 2756 | 1, | ||
| 2757 | 2, | ||
| 2758 | 3, | ||
| 2759 | x = 1 | ||
| 2760 | } | ||
| 2761 | local b = { | ||
| 2762 | 4, | ||
| 2763 | 5, | ||
| 2764 | y = 1 | ||
| 2765 | } | ||
| 2766 | local merge | ||
| 2767 | local _tab_0 = { } | ||
| 2768 | local _idx_0 = 1 | ||
| 2769 | for _key_0, _value_0 in pairs(a) do | ||
| 2770 | if _idx_0 == _key_0 then | ||
| 2771 | _tab_0[#_tab_0 + 1] = _value_0 | ||
| 2772 | _idx_0 = _idx_0 + 1 | ||
| 2773 | else | ||
| 2774 | _tab_0[_key_0] = _value_0 | ||
| 2775 | end | ||
| 2776 | end | ||
| 2777 | local _idx_1 = 1 | ||
| 2778 | for _key_0, _value_0 in pairs(b) do | ||
| 2779 | if _idx_1 == _key_0 then | ||
| 2780 | _tab_0[#_tab_0 + 1] = _value_0 | ||
| 2781 | _idx_1 = _idx_1 + 1 | ||
| 2782 | else | ||
| 2783 | _tab_0[_key_0] = _value_0 | ||
| 2784 | end | ||
| 2785 | end | ||
| 2786 | merge = _tab_0 | ||
| 2787 | local last | ||
| 2788 | do | ||
| 2789 | local _item_0 = data.items | ||
| 2790 | last = _item_0[#_item_0] | ||
| 2791 | end | ||
| 2792 | local second_last | ||
| 2793 | do | ||
| 2794 | local _item_0 = data.items | ||
| 2795 | second_last = _item_0[#_item_0 - 1] | ||
| 2796 | end | ||
| 2797 | local _obj_0 = data.items | ||
| 2798 | _obj_0[#_obj_0] = 1 | ||
| 2799 | local mt = { } | ||
| 2800 | local add | ||
| 2801 | add = function(self, right) | ||
| 2802 | return setmetatable({ | ||
| 2803 | value = self.value + right.value | ||
| 2804 | }, mt) | ||
| 2805 | end | ||
| 2806 | mt.__add = add | ||
| 2807 | local a = setmetatable({ | ||
| 2808 | value = 1 | ||
| 2809 | }, mt) | ||
| 2810 | local b = setmetatable({ | ||
| 2811 | value = 2 | ||
| 2812 | }, { | ||
| 2813 | __add = add | ||
| 2814 | }) | ||
| 2815 | local c = setmetatable({ | ||
| 2816 | value = 3 | ||
| 2817 | }, { | ||
| 2818 | __add = mt.__add | ||
| 2819 | }) | ||
| 2820 | local d = a + b + c | ||
| 2821 | print(d.value) | ||
| 2822 | local _ <close> = setmetatable({ }, { | ||
| 2823 | __close = function() | ||
| 2824 | return print("超出范围") | ||
| 2825 | end | ||
| 2826 | }) | ||
| 2827 | local tb = setmetatable({ }, { | ||
| 2828 | ["value"] = 123 | ||
| 2829 | }) | ||
| 2830 | getmetatable(tb).__index = getmetatable(tb) | ||
| 2831 | print(tb.value) | ||
| 2832 | setmetatable(tb, { | ||
| 2833 | __index = { | ||
| 2834 | item = "hello" | ||
| 2835 | } | ||
| 2836 | }) | ||
| 2837 | print(tb.item) | ||
| 2838 | local item, new, close, getter | ||
| 2839 | do | ||
| 2840 | local _obj_0 = tb | ||
| 2841 | item, new = _obj_0[1], _obj_0.new | ||
| 2842 | do | ||
| 2843 | local _obj_1 = getmetatable(_obj_0) | ||
| 2844 | close, getter = _obj_1.__close, _obj_1.__index | ||
| 2845 | end | ||
| 2846 | end | ||
| 2847 | print(item, new, close, getter) | ||
| 2848 | do | ||
| 2849 | local _obj_0 = func | ||
| 2850 | if _obj_0 ~= nil then | ||
| 2851 | _obj_0() | ||
| 2852 | end | ||
| 2853 | end | ||
| 2854 | print((function() | ||
| 2855 | local _obj_0 = abc | ||
| 2856 | if _obj_0 ~= nil then | ||
| 2857 | local _obj_1 = _obj_0["你好 世界"] | ||
| 2858 | if _obj_1 ~= nil then | ||
| 2859 | return _obj_1.xyz | ||
| 2860 | end | ||
| 2861 | return nil | ||
| 2862 | end | ||
| 2863 | return nil | ||
| 2864 | end)()) | ||
| 2865 | local x | ||
| 2866 | do | ||
| 2867 | local _obj_0 = tab | ||
| 2868 | if _obj_0 ~= nil then | ||
| 2869 | x = _obj_0.value | ||
| 2870 | end | ||
| 2871 | end | ||
| 2872 | local len = (function() | ||
| 2873 | local _obj_0 = utf8 | ||
| 2874 | if _obj_0 ~= nil then | ||
| 2875 | return _obj_0.len | ||
| 2876 | end | ||
| 2877 | return nil | ||
| 2878 | end)() or (function() | ||
| 2879 | local _obj_0 = string | ||
| 2880 | if _obj_0 ~= nil then | ||
| 2881 | return _obj_0.len | ||
| 2882 | end | ||
| 2883 | return nil | ||
| 2884 | end)() or function(o) | ||
| 2885 | return #o | ||
| 2886 | end | ||
| 2887 | if print and (x ~= nil) then | ||
| 2888 | print(x) | ||
| 2889 | end | ||
| 2890 | local _with_0 = io.open("test.txt", "w") | ||
| 2891 | if _with_0 ~= nil then | ||
| 2892 | _with_0:write("你好") | ||
| 2893 | _with_0:close() | ||
| 2894 | end | ||
| 2895 | print("你好") | ||
| 2896 | print(1, 2) | ||
| 2897 | print(1, 2, 3) | ||
| 2898 | print(render(emit(parse(extract(readFile("example.txt"), language, { }), language)))) | ||
| 2899 | local a, b, c, d | ||
| 2900 | if b ~= nil then | ||
| 2901 | a = b | ||
| 2902 | else | ||
| 2903 | if c ~= nil then | ||
| 2904 | a = c | ||
| 2905 | else | ||
| 2906 | a = d | ||
| 2907 | end | ||
| 2908 | end | ||
| 2909 | func((function() | ||
| 2910 | if a ~= nil then | ||
| 2911 | return a | ||
| 2912 | else | ||
| 2913 | return { } | ||
| 2914 | end | ||
| 2915 | end)()) | ||
| 2916 | if a == nil then | ||
| 2917 | a = false | ||
| 2918 | end | ||
| 2919 | local list = { | ||
| 2920 | 1, | ||
| 2921 | 2, | ||
| 2922 | 3 | ||
| 2923 | } | ||
| 2924 | func({ | ||
| 2925 | 1, | ||
| 2926 | 2, | ||
| 2927 | 3 | ||
| 2928 | }) | ||
| 2929 | local f | ||
| 2930 | f = function() | ||
| 2931 | return { | ||
| 2932 | 1, | ||
| 2933 | 2, | ||
| 2934 | 3 | ||
| 2935 | } | ||
| 2936 | end | ||
| 2937 | local tb = { | ||
| 2938 | name = "abc", | ||
| 2939 | values = { | ||
| 2940 | "a", | ||
| 2941 | "b", | ||
| 2942 | "c" | ||
| 2943 | }, | ||
| 2944 | objects = { | ||
| 2945 | { | ||
| 2946 | name = "a", | ||
| 2947 | value = 1, | ||
| 2948 | func = function(self) | ||
| 2949 | return self.value + 1 | ||
| 2950 | end, | ||
| 2951 | tb = { | ||
| 2952 | fieldA = 1 | ||
| 2953 | } | ||
| 2954 | }, | ||
| 2955 | { | ||
| 2956 | name = "b", | ||
| 2957 | value = 2, | ||
| 2958 | func = function(self) | ||
| 2959 | return self.value + 2 | ||
| 2960 | end, | ||
| 2961 | tb = { } | ||
| 2962 | } | ||
| 2963 | } | ||
| 2964 | } | ||
| 2965 | do | ||
| 2966 | local insert, concat = table.insert, table.concat | ||
| 2967 | local C, Ct, Cmt | ||
| 2968 | do | ||
| 2969 | local _obj_0 = require("lpeg") | ||
| 2970 | C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt | ||
| 2971 | end | ||
| 2972 | local x, y, z | ||
| 2973 | do | ||
| 2974 | local _obj_0 = require('mymodule') | ||
| 2975 | x, y, z = _obj_0.x, _obj_0.y, _obj_0.z | ||
| 2976 | end | ||
| 2977 | local a, b, c | ||
| 2978 | local _obj_0 = require('module') | ||
| 2979 | a, b, c = _obj_0.a, _obj_0.b, _obj_0.c | ||
| 2980 | end | ||
| 2981 | do | ||
| 2982 | local module = require('module') | ||
| 2983 | local module_x = require('module_x') | ||
| 2984 | local d_a_s_h_e_s = require("d-a-s-h-e-s") | ||
| 2985 | local part = require("module.part") | ||
| 2986 | end | ||
| 2987 | do | ||
| 2988 | local PlayerModule = require("player") | ||
| 2989 | local C, Ct, Cmt | ||
| 2990 | do | ||
| 2991 | local _obj_0 = require("lpeg") | ||
| 2992 | C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt | ||
| 2993 | end | ||
| 2994 | local one, two, ch | ||
| 2995 | local _obj_0 = require("export") | ||
| 2996 | one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] | ||
| 2997 | end | ||
| 2998 | do | ||
| 2999 | local tostring <const> = tostring | ||
| 3000 | local concat <const> = table.concat | ||
| 3001 | print(concat({ | ||
| 3002 | "a", | ||
| 3003 | tostring(1) | ||
| 3004 | })) | ||
| 3005 | end | ||
| 3006 | do | ||
| 3007 | local print <const> = print | ||
| 3008 | local math <const> = math | ||
| 3009 | print("hello") | ||
| 3010 | math.random(3) | ||
| 3011 | end | ||
| 3012 | do | ||
| 3013 | local print <const> = print | ||
| 3014 | print(FLAG) | ||
| 3015 | FLAG = 123 | ||
| 3016 | end | ||
| 3017 | local _module_0 = { } | ||
| 3018 | local a, b, c = 1, 2, 3 | ||
| 3019 | _module_0["a"], _module_0["b"], _module_0["c"] = a, b, c | ||
| 3020 | local cool = "cat" | ||
| 3021 | _module_0["cool"] = cool | ||
| 3022 | local What | ||
| 3023 | if this then | ||
| 3024 | What = "abc" | ||
| 3025 | else | ||
| 3026 | What = "def" | ||
| 3027 | end | ||
| 3028 | _module_0["What"] = What | ||
| 3029 | local y | ||
| 3030 | y = function() | ||
| 3031 | local hallo = 3434 | ||
| 3032 | end | ||
| 3033 | _module_0["y"] = y | ||
| 3034 | local Something | ||
| 3035 | local _class_0 | ||
| 3036 | local _base_0 = { | ||
| 3037 | umm = "cool" | ||
| 3038 | } | ||
| 3039 | if _base_0.__index == nil then | ||
| 3040 | _base_0.__index = _base_0 | ||
| 3041 | end | ||
| 3042 | _class_0 = setmetatable({ | ||
| 3043 | __init = function() end, | ||
| 3044 | __base = _base_0, | ||
| 3045 | __name = "Something" | ||
| 3046 | }, { | ||
| 3047 | __index = _base_0, | ||
| 3048 | __call = function(cls, ...) | ||
| 3049 | local _self_0 = setmetatable({ }, _base_0) | ||
| 3050 | cls.__init(_self_0, ...) | ||
| 3051 | return _self_0 | ||
| 3052 | end | ||
| 3053 | }) | ||
| 3054 | _base_0.__class = _class_0 | ||
| 3055 | Something = _class_0 | ||
| 3056 | _module_0["Something"] = Something | ||
| 3057 | return _module_0 | ||
| 3058 | local _module_0 = { } | ||
| 3059 | local loadstring, tolua | ||
| 3060 | do | ||
| 3061 | local _obj_0 = yue | ||
| 3062 | loadstring, tolua = _obj_0.loadstring, _obj_0.to_lua | ||
| 3063 | end | ||
| 3064 | _module_0["loadstring"], _module_0["tolua"] = loadstring, tolua | ||
| 3065 | local fieldA = tb.itemA.fieldA | ||
| 3066 | if fieldA == nil then | ||
| 3067 | fieldA = '默认值' | ||
| 3068 | end | ||
| 3069 | _module_0["fieldA"] = fieldA | ||
| 3070 | return _module_0 | ||
| 3071 | local _module_0 = setmetatable({ }, { }) | ||
| 3072 | _module_0.itemA = tb | ||
| 3073 | getmetatable(_module_0).__index = items | ||
| 3074 | _module_0["a-b-c"] = 123 | ||
| 3075 | return _module_0 | ||
| 3076 | local _module_0 = { } | ||
| 3077 | local d, e, f = 3, 2, 1 | ||
| 3078 | _module_0[#_module_0 + 1] = d | ||
| 3079 | _module_0[#_module_0 + 1] = e | ||
| 3080 | _module_0[#_module_0 + 1] = f | ||
| 3081 | if this then | ||
| 3082 | _module_0[#_module_0 + 1] = 123 | ||
| 3083 | else | ||
| 3084 | _module_0[#_module_0 + 1] = 456 | ||
| 3085 | end | ||
| 3086 | local _with_0 = tmp | ||
| 3087 | local j = 2000 | ||
| 3088 | _module_0[#_module_0 + 1] = _with_0 | ||
| 3089 | return _module_0 | ||
| 3090 | local _module_0 = nil | ||
| 3091 | _module_0 = function() | ||
| 3092 | print("你好") | ||
| 3093 | return 123 | ||
| 3094 | end | ||
| 3095 | return _module_0 | ||
| 3096 | local hello = "world" | ||
| 3097 | local a, b, c = 1, 2, 3 | ||
| 3098 | hello = 123 | ||
| 3099 | local x = 1 | ||
| 3100 | x = x + 1 | ||
| 3101 | x = x - 1 | ||
| 3102 | x = x * 10 | ||
| 3103 | x = x / 10 | ||
| 3104 | x = x % 10 | ||
| 3105 | local s = s .. "world" | ||
| 3106 | local arg = arg or "默认值" | ||
| 3107 | local a = 0 | ||
| 3108 | local b = 0 | ||
| 3109 | local c = 0 | ||
| 3110 | local d = 0 | ||
| 3111 | local e = 0 | ||
| 3112 | local x = f() | ||
| 3113 | local y = x | ||
| 3114 | local z = x | ||
| 3115 | do | ||
| 3116 | local a = 1 | ||
| 3117 | local x, y, z | ||
| 3118 | print("预先声明后续所有变量为局部变量") | ||
| 3119 | x = function() | ||
| 3120 | return 1 + y + z | ||
| 3121 | end | ||
| 3122 | y, z = 2, 3 | ||
| 3123 | instance = Item:new() | ||
| 3124 | end | ||
| 3125 | do | ||
| 3126 | local X = 1 | ||
| 3127 | local B | ||
| 3128 | print("只预先声明后续大写的变量为局部变量") | ||
| 3129 | local a = 1 | ||
| 3130 | B = 2 | ||
| 3131 | end | ||
| 3132 | do | ||
| 3133 | a = 1 | ||
| 3134 | print("预先声明所有变量为全局变量") | ||
| 3135 | x = function() | ||
| 3136 | return 1 + y + z | ||
| 3137 | end | ||
| 3138 | y, z = 2, 3 | ||
| 3139 | end | ||
| 3140 | do | ||
| 3141 | x = 1 | ||
| 3142 | print("只预先声明大写的变量为全局变量") | ||
| 3143 | local a = 1 | ||
| 3144 | B = 2 | ||
| 3145 | local Temp = "一个局部值" | ||
| 3146 | end | ||
| 3147 | local thing = { | ||
| 3148 | 1, | ||
| 3149 | 2 | ||
| 3150 | } | ||
| 3151 | local a, b = thing[1], thing[2] | ||
| 3152 | print(a, b) | ||
| 3153 | local obj = { | ||
| 3154 | hello = "world", | ||
| 3155 | day = "tuesday", | ||
| 3156 | length = 20 | ||
| 3157 | } | ||
| 3158 | local hello, the_day = obj.hello, obj.day | ||
| 3159 | print(hello, the_day) | ||
| 3160 | local day = obj.day | ||
| 3161 | local obj2 = { | ||
| 3162 | numbers = { | ||
| 3163 | 1, | ||
| 3164 | 2, | ||
| 3165 | 3, | ||
| 3166 | 4 | ||
| 3167 | }, | ||
| 3168 | properties = { | ||
| 3169 | color = "green", | ||
| 3170 | height = 13.5 | ||
| 3171 | } | ||
| 3172 | } | ||
| 3173 | local first, second = obj2.numbers[1], obj2.numbers[2] | ||
| 3174 | print(first, second, color) | ||
| 3175 | local first, second, color | ||
| 3176 | local _obj_0 = obj2 | ||
| 3177 | first, second, color = _obj_0.numbers[1], _obj_0.numbers[2], _obj_0.properties.color | ||
| 3178 | local concat, insert | ||
| 3179 | local _obj_0 = table | ||
| 3180 | concat, insert = _obj_0.concat, _obj_0.insert | ||
| 3181 | local mix, max, rand | ||
| 3182 | local _obj_0 = math | ||
| 3183 | mix, max, rand = _obj_0.mix, _obj_0.max, _obj_0.random | ||
| 3184 | local name, job | ||
| 3185 | local _obj_0 = person | ||
| 3186 | name, job = _obj_0.name, _obj_0.job | ||
| 3187 | if name == nil then | ||
| 3188 | name = "nameless" | ||
| 3189 | end | ||
| 3190 | if job == nil then | ||
| 3191 | job = "jobless" | ||
| 3192 | end | ||
| 3193 | local two, four | ||
| 3194 | local _obj_0 = items | ||
| 3195 | two, four = _obj_0[2], _obj_0[4] | ||
| 3196 | local orders = { | ||
| 3197 | "first", | ||
| 3198 | "second", | ||
| 3199 | "third", | ||
| 3200 | "fourth", | ||
| 3201 | "last" | ||
| 3202 | } | ||
| 3203 | local first, bulk, last = orders[1], (function() | ||
| 3204 | local _accum_0 = { } | ||
| 3205 | local _len_0 = 1 | ||
| 3206 | local _max_0 = #orders + -2 + 1 | ||
| 3207 | for _index_0 = 2, _max_0 do | ||
| 3208 | local _item_0 = orders[_index_0] | ||
| 3209 | _accum_0[_len_0] = _item_0 | ||
| 3210 | _len_0 = _len_0 + 1 | ||
| 3211 | end | ||
| 3212 | return _accum_0 | ||
| 3213 | end)(), orders[#orders] | ||
| 3214 | print(first) | ||
| 3215 | print(bulk) | ||
| 3216 | print(last) | ||
| 3217 | local first, rest | ||
| 3218 | do | ||
| 3219 | local _obj_0 = orders | ||
| 3220 | first, rest = _obj_0[1], (function() | ||
| 3221 | local _accum_0 = { } | ||
| 3222 | local _len_0 = 1 | ||
| 3223 | local _max_0 = #_obj_0 | ||
| 3224 | for _index_0 = 2, _max_0 do | ||
| 3225 | local _item_0 = _obj_0[_index_0] | ||
| 3226 | _accum_0[_len_0] = _item_0 | ||
| 3227 | _len_0 = _len_0 + 1 | ||
| 3228 | end | ||
| 3229 | return _accum_0 | ||
| 3230 | end)() | ||
| 3231 | end | ||
| 3232 | local start, last | ||
| 3233 | do | ||
| 3234 | local _obj_0 = orders | ||
| 3235 | start, last = (function() | ||
| 3236 | local _accum_0 = { } | ||
| 3237 | local _len_0 = 1 | ||
| 3238 | local _max_0 = #_obj_0 + -2 + 1 | ||
| 3239 | for _index_0 = 1, _max_0 do | ||
| 3240 | local _item_0 = _obj_0[_index_0] | ||
| 3241 | _accum_0[_len_0] = _item_0 | ||
| 3242 | _len_0 = _len_0 + 1 | ||
| 3243 | end | ||
| 3244 | return _accum_0 | ||
| 3245 | end)(), _obj_0[#_obj_0] | ||
| 3246 | end | ||
| 3247 | local _obj_0 = orders | ||
| 3248 | first, last = _obj_0[1], _obj_0[#_obj_0] | ||
| 3249 | local tuples = { | ||
| 3250 | { | ||
| 3251 | "hello", | ||
| 3252 | "world" | ||
| 3253 | }, | ||
| 3254 | { | ||
| 3255 | "egg", | ||
| 3256 | "head" | ||
| 3257 | } | ||
| 3258 | } | ||
| 3259 | for _index_0 = 1, #tuples do | ||
| 3260 | local _des_0 = tuples[_index_0] | ||
| 3261 | local left, right = _des_0[1], _des_0[2] | ||
| 3262 | print(left, right) | ||
| 3263 | end | ||
| 3264 | local user = database.find_user("moon") | ||
| 3265 | if user then | ||
| 3266 | print(user.name) | ||
| 3267 | end | ||
| 3268 | local hello = os.getenv("hello") | ||
| 3269 | if hello then | ||
| 3270 | print("你有 hello", hello) | ||
| 3271 | else | ||
| 3272 | local world = os.getenv("world") | ||
| 3273 | if world then | ||
| 3274 | print("你有 world", world) | ||
| 3275 | else | ||
| 3276 | print("什么都没有 :(") | ||
| 3277 | end | ||
| 3278 | end | ||
| 3279 | do | ||
| 3280 | local success, result = pcall(function() | ||
| 3281 | return "无报错地获取结果" | ||
| 3282 | end) | ||
| 3283 | if success then | ||
| 3284 | print(result) | ||
| 3285 | end | ||
| 3286 | end | ||
| 3287 | print("好的") | ||
| 3288 | repeat | ||
| 3289 | local byte = stream:read_one() | ||
| 3290 | if byte then | ||
| 3291 | print(byte) | ||
| 3292 | else | ||
| 3293 | break | ||
| 3294 | end | ||
| 3295 | until false | ||
| 3296 | local list = { | ||
| 3297 | 1, | ||
| 3298 | 2, | ||
| 3299 | 3, | ||
| 3300 | 4, | ||
| 3301 | 5 | ||
| 3302 | } | ||
| 3303 | local fn | ||
| 3304 | fn = function(ok) | ||
| 3305 | return ok, table.unpack(list) | ||
| 3306 | end | ||
| 3307 | (function(_arg_0, ...) | ||
| 3308 | local ok = _arg_0 | ||
| 3309 | local count = select('#', ...) | ||
| 3310 | local first = select(1, ...) | ||
| 3311 | return print(ok, count, first) | ||
| 3312 | end)(fn(true)) | ||
| 3313 | local a = 1 | ||
| 3314 | local b = 2 | ||
| 3315 | print(a + b) | ||
| 3316 | Rx.Observable.fromRange(1, 8):filter(function(x) | ||
| 3317 | return x % 2 == 0 | ||
| 3318 | end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) | ||
| 3319 | return value .. '!' | ||
| 3320 | end):subscribe(print) | ||
| 3321 | local str = strA .. strB .. strC | ||
| 3322 | func(3000, "192.168.1.1") | ||
| 3323 | xpcall(function() | ||
| 3324 | return func(1, 2, 3) | ||
| 3325 | end, function(err) | ||
| 3326 | return print(yue.traceback(err)) | ||
| 3327 | end) | ||
| 3328 | local success, result = xpcall(function() | ||
| 3329 | return func(1, 2, 3) | ||
| 3330 | end, function(err) | ||
| 3331 | return yue.traceback(err) | ||
| 3332 | end) | ||
| 3333 | xpcall(function() | ||
| 3334 | return func(1, 2, 3) | ||
| 3335 | end, function(err) | ||
| 3336 | return print(yue.traceback(err)) | ||
| 3337 | end) | ||
| 3338 | success, result = pcall(function() | ||
| 3339 | return func(1, 2, 3) | ||
| 3340 | end) | ||
| 3341 | pcall(function() | ||
| 3342 | print("尝试中") | ||
| 3343 | return func(1, 2, 3) | ||
| 3344 | end) | ||
| 3345 | success, result = xpcall(function() | ||
| 3346 | return func(1, 2, 3) | ||
| 3347 | end, function(err) | ||
| 3348 | return print(yue.traceback(err)) | ||
| 3349 | end) | ||
| 3350 | if success then | ||
| 3351 | print(result) | ||
| 3352 | end | ||
| 3353 | local a, b, c | ||
| 3354 | do | ||
| 3355 | local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function() | ||
| 3356 | return func() | ||
| 3357 | end) | ||
| 3358 | if _ok_0 then | ||
| 3359 | a, b, c = _ret_0, _ret_1, _ret_2 | ||
| 3360 | end | ||
| 3361 | end | ||
| 3362 | do | ||
| 3363 | local _exp_0 = ((function() | ||
| 3364 | return (function(_arg_0, ...) | ||
| 3365 | local _ok_0 = _arg_0 | ||
| 3366 | if _ok_0 then | ||
| 3367 | return ... | ||
| 3368 | end | ||
| 3369 | end)(pcall(function() | ||
| 3370 | return func() | ||
| 3371 | end)) | ||
| 3372 | end)()) | ||
| 3373 | if _exp_0 ~= nil then | ||
| 3374 | a = _exp_0 | ||
| 3375 | else | ||
| 3376 | a = "default" | ||
| 3377 | end | ||
| 3378 | end | ||
| 3379 | f((function() | ||
| 3380 | return (function(_arg_0, ...) | ||
| 3381 | local _ok_0 = _arg_0 | ||
| 3382 | if _ok_0 then | ||
| 3383 | return ... | ||
| 3384 | end | ||
| 3385 | end)(pcall(function() | ||
| 3386 | return func() | ||
| 3387 | end)) | ||
| 3388 | end)()) | ||
| 3389 | f((function() | ||
| 3390 | return (function(_arg_0, ...) | ||
| 3391 | local _ok_0 = _arg_0 | ||
| 3392 | if _ok_0 then | ||
| 3393 | return ... | ||
| 3394 | end | ||
| 3395 | end)(xpcall(function() | ||
| 3396 | print(123) | ||
| 3397 | return func() | ||
| 3398 | end, function(e) | ||
| 3399 | print(e) | ||
| 3400 | return e | ||
| 3401 | end)) | ||
| 3402 | end)()) | ||
| 3403 | local a <const> = 123 | ||
| 3404 | local _ <close> = setmetatable({ }, { | ||
| 3405 | __close = function() | ||
| 3406 | return print("超出范围。") | ||
| 3407 | end | ||
| 3408 | }) | ||
| 3409 | local a, b, c, d | ||
| 3410 | local _obj_0 = tb | ||
| 3411 | a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] | ||
| 3412 | Constant = 123 | ||
| 3413 | local some_string = "这是一个字符串\n 并包括一个换行。" | ||
| 3414 | print("我有" .. tostring(math.random() * 100) .. "%的把握。") | ||
| 3415 | local integer = 1000000 | ||
| 3416 | local hex = 0xEFBBBF | ||
| 3417 | local binary = 19 | ||
| 3418 | local str = "key: value\nlist:\n - item1\n - " .. tostring(expr) | ||
| 3419 | local fn | ||
| 3420 | fn = function() | ||
| 3421 | local str = "foo:\n bar: baz" | ||
| 3422 | return str | ||
| 3423 | end | ||
| 3424 | local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'" | ||
| 3425 | local my_function | ||
| 3426 | my_function = function() end | ||
| 3427 | my_function() | ||
| 3428 | local func_a | ||
| 3429 | func_a = function() | ||
| 3430 | return print("你好,世界") | ||
| 3431 | end | ||
| 3432 | local func_b | ||
| 3433 | func_b = function() | ||
| 3434 | local value = 100 | ||
| 3435 | return print("这个值是:", value) | ||
| 3436 | end | ||
| 3437 | func_a() | ||
| 3438 | func_b() | ||
| 3439 | local sum | ||
| 3440 | sum = function(x, y) | ||
| 3441 | return print("数字的和", x + y) | ||
| 3442 | end | ||
| 3443 | sum(10, 20) | ||
| 3444 | print(sum(10, 20)) | ||
| 3445 | a(b(c("a", "b", "c"))) | ||
| 3446 | print("x:", sum(10, 20), "y:", sum(30, 40)) | ||
| 3447 | local sum | ||
| 3448 | sum = function(x, y) | ||
| 3449 | return x + y | ||
| 3450 | end | ||
| 3451 | print("数字的和是", sum(10, 20)) | ||
| 3452 | local sum | ||
| 3453 | sum = function(x, y) | ||
| 3454 | return x + y | ||
| 3455 | end | ||
| 3456 | local mystery | ||
| 3457 | mystery = function(x, y) | ||
| 3458 | return x + y, x - y | ||
| 3459 | end | ||
| 3460 | local a, b = mystery(10, 20) | ||
| 3461 | local func | ||
| 3462 | func = function(self, num) | ||
| 3463 | return self.value + num | ||
| 3464 | end | ||
| 3465 | local my_function | ||
| 3466 | my_function = function(name, height) | ||
| 3467 | if name == nil then | ||
| 3468 | name = "某物" | ||
| 3469 | end | ||
| 3470 | if height == nil then | ||
| 3471 | height = 100 | ||
| 3472 | end | ||
| 3473 | print("你好,我是", name) | ||
| 3474 | return print("我的高度是", height) | ||
| 3475 | end | ||
| 3476 | local some_args | ||
| 3477 | some_args = function(x, y) | ||
| 3478 | if x == nil then | ||
| 3479 | x = 100 | ||
| 3480 | end | ||
| 3481 | if y == nil then | ||
| 3482 | y = x + 1000 | ||
| 3483 | end | ||
| 3484 | return print(x + y) | ||
| 3485 | end | ||
| 3486 | my_func(5, 4, 3, 8, 9, 10) | ||
| 3487 | cool_func(1, 2, 3, 4, 5, 6, 7, 8) | ||
| 3488 | my_func(5, 6, 7, 6, another_func(6, 7, 8, 9, 1, 2), 5, 4) | ||
| 3489 | local x = { | ||
| 3490 | 1, | ||
| 3491 | 2, | ||
| 3492 | 3, | ||
| 3493 | 4, | ||
| 3494 | a_func(4, 5, 5, 6), | ||
| 3495 | 8, | ||
| 3496 | 9, | ||
| 3497 | 10 | ||
| 3498 | } | ||
| 3499 | local y = { | ||
| 3500 | my_func(1, 2, 3, 4, 5), | ||
| 3501 | 5, | ||
| 3502 | 6, | ||
| 3503 | 7 | ||
| 3504 | } | ||
| 3505 | if func(1, 2, 3, "你好", "世界") then | ||
| 3506 | print("你好") | ||
| 3507 | print("我在if内部") | ||
| 3508 | end | ||
| 3509 | if func(1, 2, 3, "你好", "世界") then | ||
| 3510 | print("你好") | ||
| 3511 | print("我在if内部") | ||
| 3512 | end | ||
| 3513 | local f1 | ||
| 3514 | f1 = function(_arg_0) | ||
| 3515 | local a, b, c | ||
| 3516 | a, b, c = _arg_0.a, _arg_0.b, _arg_0.c | ||
| 3517 | return print(a, b, c) | ||
| 3518 | end | ||
| 3519 | f1({ | ||
| 3520 | a = 1, | ||
| 3521 | b = "2", | ||
| 3522 | c = { } | ||
| 3523 | }) | ||
| 3524 | local f2 | ||
| 3525 | f2 = function(_arg_0, c) | ||
| 3526 | local a1, b | ||
| 3527 | a1, b = _arg_0.a, _arg_0.b | ||
| 3528 | if a1 == nil then | ||
| 3529 | a1 = 123 | ||
| 3530 | end | ||
| 3531 | if b == nil then | ||
| 3532 | b = 'abc' | ||
| 3533 | end | ||
| 3534 | if c == nil then | ||
| 3535 | c = { } | ||
| 3536 | end | ||
| 3537 | return print(a1, b, c) | ||
| 3538 | end | ||
| 3539 | local arg1 = { | ||
| 3540 | a = 0 | ||
| 3541 | } | ||
| 3542 | f2(arg1, arg2) | ||
| 3543 | local findFirstEven | ||
| 3544 | findFirstEven = function(list) | ||
| 3545 | for _index_0 = 1, #list do | ||
| 3546 | local item = list[_index_0] | ||
| 3547 | if type(item) == "table" then | ||
| 3548 | for _index_1 = 1, #item do | ||
| 3549 | local sub = item[_index_1] | ||
| 3550 | if sub % 2 == 0 then | ||
| 3551 | return sub | ||
| 3552 | end | ||
| 3553 | end | ||
| 3554 | end | ||
| 3555 | end | ||
| 3556 | return nil | ||
| 3557 | end | ||
| 3558 | local findFirstEven | ||
| 3559 | findFirstEven = function(list) | ||
| 3560 | for _index_0 = 1, #list do | ||
| 3561 | local item = list[_index_0] | ||
| 3562 | if type(item) == "table" then | ||
| 3563 | for _index_1 = 1, #item do | ||
| 3564 | local sub = item[_index_1] | ||
| 3565 | if sub % 2 == 0 then | ||
| 3566 | return sub | ||
| 3567 | end | ||
| 3568 | end | ||
| 3569 | end | ||
| 3570 | end | ||
| 3571 | return nil | ||
| 3572 | end | ||
| 3573 | local f | ||
| 3574 | f = function(...) | ||
| 3575 | local t = { | ||
| 3576 | n = select("#", ...), | ||
| 3577 | ... | ||
| 3578 | } | ||
| 3579 | print("参数个数:", t.n) | ||
| 3580 | print("表长度:", #t) | ||
| 3581 | for i = 1, t.n do | ||
| 3582 | print(t[i]) | ||
| 3583 | end | ||
| 3584 | end | ||
| 3585 | f(1, 2, 3) | ||
| 3586 | f("a", "b", "c", "d") | ||
| 3587 | f() | ||
| 3588 | local process | ||
| 3589 | process = function(...) | ||
| 3590 | local args = { | ||
| 3591 | n = select("#", ...), | ||
| 3592 | ... | ||
| 3593 | } | ||
| 3594 | local sum = 0 | ||
| 3595 | for i = 1, args.n do | ||
| 3596 | if args[i] ~= nil and type(args[i]) == "number" then | ||
| 3597 | sum = sum + args[i] | ||
| 3598 | end | ||
| 3599 | end | ||
| 3600 | return sum | ||
| 3601 | end | ||
| 3602 | process(1, nil, 3, nil, 5) | ||
| 3603 | f(function() | ||
| 3604 | return print("hello") | ||
| 3605 | end) | ||
| 3606 | f(function(self) | ||
| 3607 | return print(self.value) | ||
| 3608 | end) | ||
| 3609 | map(function(x) | ||
| 3610 | return x * 2 | ||
| 3611 | end, { | ||
| 3612 | 1, | ||
| 3613 | 2, | ||
| 3614 | 3 | ||
| 3615 | }) | ||
| 3616 | local result, msg | ||
| 3617 | do | ||
| 3618 | result, msg = readAsync("文件名.txt", function(data) | ||
| 3619 | print(data) | ||
| 3620 | return processAsync(data, function(info) | ||
| 3621 | return check(info) | ||
| 3622 | end) | ||
| 3623 | end) | ||
| 3624 | end | ||
| 3625 | print(result, msg) | ||
| 3626 | local some_values = { | ||
| 3627 | 1, | ||
| 3628 | 2, | ||
| 3629 | 3, | ||
| 3630 | 4 | ||
| 3631 | } | ||
| 3632 | local some_values = { | ||
| 3633 | name = "Bill", | ||
| 3634 | age = 200, | ||
| 3635 | ["favorite food"] = "rice" | ||
| 3636 | } | ||
| 3637 | local profile = { | ||
| 3638 | height = "4英尺", | ||
| 3639 | shoe_size = 13, | ||
| 3640 | favorite_foods = { | ||
| 3641 | "冰淇淋", | ||
| 3642 | "甜甜圈" | ||
| 3643 | } | ||
| 3644 | } | ||
| 3645 | local values = { | ||
| 3646 | 1, | ||
| 3647 | 2, | ||
| 3648 | 3, | ||
| 3649 | 4, | ||
| 3650 | 5, | ||
| 3651 | 6, | ||
| 3652 | 7, | ||
| 3653 | 8, | ||
| 3654 | name = "超人", | ||
| 3655 | occupation = "打击犯罪" | ||
| 3656 | } | ||
| 3657 | my_function({ | ||
| 3658 | dance = "探戈", | ||
| 3659 | partner = "无" | ||
| 3660 | }) | ||
| 3661 | local y = { | ||
| 3662 | type = "狗", | ||
| 3663 | legs = 4, | ||
| 3664 | tails = 1 | ||
| 3665 | } | ||
| 3666 | local tbl = { | ||
| 3667 | ["do"] = "某事", | ||
| 3668 | ["end"] = "饥饿" | ||
| 3669 | } | ||
| 3670 | local hair = "金色" | ||
| 3671 | local height = 200 | ||
| 3672 | local person = { | ||
| 3673 | hair = hair, | ||
| 3674 | height = height, | ||
| 3675 | shoe_size = 40 | ||
| 3676 | } | ||
| 3677 | print_table({ | ||
| 3678 | hair = hair, | ||
| 3679 | height = height | ||
| 3680 | }) | ||
| 3681 | local t = { | ||
| 3682 | [1 + 2] = "你好", | ||
| 3683 | ["你好 世界"] = true | ||
| 3684 | } | ||
| 3685 | local some_values = { | ||
| 3686 | 1, | ||
| 3687 | 2, | ||
| 3688 | 3, | ||
| 3689 | 4 | ||
| 3690 | } | ||
| 3691 | local list_with_one_element = { | ||
| 3692 | 1 | ||
| 3693 | } | ||
| 3694 | local items = { | ||
| 3695 | 1, | ||
| 3696 | 2, | ||
| 3697 | 3, | ||
| 3698 | 4 | ||
| 3699 | } | ||
| 3700 | local doubled | ||
| 3701 | local _accum_0 = { } | ||
| 3702 | local _len_0 = 1 | ||
| 3703 | for i, item in ipairs(items) do | ||
| 3704 | _accum_0[_len_0] = item * 2 | ||
| 3705 | _len_0 = _len_0 + 1 | ||
| 3706 | end | ||
| 3707 | doubled = _accum_0 | ||
| 3708 | local slice | ||
| 3709 | local _accum_0 = { } | ||
| 3710 | local _len_0 = 1 | ||
| 3711 | for i, item in ipairs(items) do | ||
| 3712 | if i > 1 and i < 3 then | ||
| 3713 | _accum_0[_len_0] = item | ||
| 3714 | _len_0 = _len_0 + 1 | ||
| 3715 | end | ||
| 3716 | end | ||
| 3717 | slice = _accum_0 | ||
| 3718 | local doubled | ||
| 3719 | local _accum_0 = { } | ||
| 3720 | local _len_0 = 1 | ||
| 3721 | local _list_0 = items | ||
| 3722 | for _index_0 = 1, #_list_0 do | ||
| 3723 | local item = _list_0[_index_0] | ||
| 3724 | _accum_0[_len_0] = item * 2 | ||
| 3725 | _len_0 = _len_0 + 1 | ||
| 3726 | end | ||
| 3727 | doubled = _accum_0 | ||
| 3728 | local data = { | ||
| 3729 | a = { | ||
| 3730 | 1, | ||
| 3731 | 2, | ||
| 3732 | 3 | ||
| 3733 | }, | ||
| 3734 | b = { | ||
| 3735 | 4, | ||
| 3736 | 5, | ||
| 3737 | 6 | ||
| 3738 | } | ||
| 3739 | } | ||
| 3740 | local flat | ||
| 3741 | local _accum_0 = { } | ||
| 3742 | for k, v in pairs(data) do | ||
| 3743 | local _len_0 = #_accum_0 + 1 | ||
| 3744 | for _index_0 = 1, #v do | ||
| 3745 | local _elm_0 = v[_index_0] | ||
| 3746 | _accum_0[_len_0], _len_0 = _elm_0, _len_0 + 1 | ||
| 3747 | end | ||
| 3748 | end | ||
| 3749 | flat = _accum_0 | ||
| 3750 | local x_coords = { | ||
| 3751 | 4, | ||
| 3752 | 5, | ||
| 3753 | 6, | ||
| 3754 | 7 | ||
| 3755 | } | ||
| 3756 | local y_coords = { | ||
| 3757 | 9, | ||
| 3758 | 2, | ||
| 3759 | 3 | ||
| 3760 | } | ||
| 3761 | local points | ||
| 3762 | local _accum_0 = { } | ||
| 3763 | local _len_0 = 1 | ||
| 3764 | for _index_0 = 1, #x_coords do | ||
| 3765 | local x = x_coords[_index_0] | ||
| 3766 | for _index_1 = 1, #y_coords do | ||
| 3767 | local y = y_coords[_index_1] | ||
| 3768 | _accum_0[_len_0] = { | ||
| 3769 | x, | ||
| 3770 | y | ||
| 3771 | } | ||
| 3772 | _len_0 = _len_0 + 1 | ||
| 3773 | end | ||
| 3774 | end | ||
| 3775 | points = _accum_0 | ||
| 3776 | local evens | ||
| 3777 | local _accum_0 = { } | ||
| 3778 | local _len_0 = 1 | ||
| 3779 | for i = 1, 100 do | ||
| 3780 | if i % 2 == 0 then | ||
| 3781 | _accum_0[_len_0] = i | ||
| 3782 | _len_0 = _len_0 + 1 | ||
| 3783 | end | ||
| 3784 | end | ||
| 3785 | evens = _accum_0 | ||
| 3786 | local thing = { | ||
| 3787 | color = "red", | ||
| 3788 | name = "fast", | ||
| 3789 | width = 123 | ||
| 3790 | } | ||
| 3791 | local thing_copy | ||
| 3792 | local _tbl_0 = { } | ||
| 3793 | for k, v in pairs(thing) do | ||
| 3794 | _tbl_0[k] = v | ||
| 3795 | end | ||
| 3796 | thing_copy = _tbl_0 | ||
| 3797 | local no_color | ||
| 3798 | local _tbl_0 = { } | ||
| 3799 | for k, v in pairs(thing) do | ||
| 3800 | if k ~= "color" then | ||
| 3801 | _tbl_0[k] = v | ||
| 3802 | end | ||
| 3803 | end | ||
| 3804 | no_color = _tbl_0 | ||
| 3805 | local numbers = { | ||
| 3806 | 1, | ||
| 3807 | 2, | ||
| 3808 | 3, | ||
| 3809 | 4 | ||
| 3810 | } | ||
| 3811 | local sqrts | ||
| 3812 | local _tbl_0 = { } | ||
| 3813 | for _index_0 = 1, #numbers do | ||
| 3814 | local i = numbers[_index_0] | ||
| 3815 | _tbl_0[i] = math.sqrt(i) | ||
| 3816 | end | ||
| 3817 | sqrts = _tbl_0 | ||
| 3818 | local tuples = { | ||
| 3819 | { | ||
| 3820 | "hello", | ||
| 3821 | "world" | ||
| 3822 | }, | ||
| 3823 | { | ||
| 3824 | "foo", | ||
| 3825 | "bar" | ||
| 3826 | } | ||
| 3827 | } | ||
| 3828 | local tbl | ||
| 3829 | local _tbl_0 = { } | ||
| 3830 | for _index_0 = 1, #tuples do | ||
| 3831 | local tuple = tuples[_index_0] | ||
| 3832 | local _key_0, _val_0 = unpack(tuple) | ||
| 3833 | _tbl_0[_key_0] = _val_0 | ||
| 3834 | end | ||
| 3835 | tbl = _tbl_0 | ||
| 3836 | local slice | ||
| 3837 | local _accum_0 = { } | ||
| 3838 | local _len_0 = 1 | ||
| 3839 | local _list_0 = items | ||
| 3840 | for _index_0 = 1, 5 do | ||
| 3841 | local item = _list_0[_index_0] | ||
| 3842 | _accum_0[_len_0] = item | ||
| 3843 | _len_0 = _len_0 + 1 | ||
| 3844 | end | ||
| 3845 | slice = _accum_0 | ||
| 3846 | local slice | ||
| 3847 | local _accum_0 = { } | ||
| 3848 | local _len_0 = 1 | ||
| 3849 | local _list_0 = items | ||
| 3850 | local _max_0 = #_list_0 | ||
| 3851 | for _index_0 = 2, _max_0 do | ||
| 3852 | local item = _list_0[_index_0] | ||
| 3853 | _accum_0[_len_0] = item | ||
| 3854 | _len_0 = _len_0 + 1 | ||
| 3855 | end | ||
| 3856 | slice = _accum_0 | ||
| 3857 | local slice | ||
| 3858 | local _accum_0 = { } | ||
| 3859 | local _len_0 = 1 | ||
| 3860 | local _list_0 = items | ||
| 3861 | local _max_0 = #_list_0 | ||
| 3862 | for _index_0 = 1, _max_0, 2 do | ||
| 3863 | local item = _list_0[_index_0] | ||
| 3864 | _accum_0[_len_0] = item | ||
| 3865 | _len_0 = _len_0 + 1 | ||
| 3866 | end | ||
| 3867 | slice = _accum_0 | ||
| 3868 | local slice | ||
| 3869 | local _accum_0 = { } | ||
| 3870 | local _len_0 = 1 | ||
| 3871 | local _list_0 = items | ||
| 3872 | local _min_0 = #_list_0 + -4 + 1 | ||
| 3873 | local _max_0 = #_list_0 + -1 + 1 | ||
| 3874 | for _index_0 = _min_0, _max_0 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 reverse_slice | ||
| 3881 | local _accum_0 = { } | ||
| 3882 | local _len_0 = 1 | ||
| 3883 | local _list_0 = items | ||
| 3884 | local _min_0 = #_list_0 + -1 + 1 | ||
| 3885 | for _index_0 = _min_0, 1, -1 do | ||
| 3886 | local item = _list_0[_index_0] | ||
| 3887 | _accum_0[_len_0] = item | ||
| 3888 | _len_0 = _len_0 + 1 | ||
| 3889 | end | ||
| 3890 | reverse_slice = _accum_0 | ||
| 3891 | local sub_list | ||
| 3892 | local _accum_0 = { } | ||
| 3893 | local _len_0 = 1 | ||
| 3894 | local _list_0 = items | ||
| 3895 | for _index_0 = 2, 4 do | ||
| 3896 | local _item_0 = _list_0[_index_0] | ||
| 3897 | _accum_0[_len_0] = _item_0 | ||
| 3898 | _len_0 = _len_0 + 1 | ||
| 3899 | end | ||
| 3900 | sub_list = _accum_0 | ||
| 3901 | for i = 10, 20 do | ||
| 3902 | print(i) | ||
| 3903 | end | ||
| 3904 | for k = 1, 15, 2 do | ||
| 3905 | print(k) | ||
| 3906 | end | ||
| 3907 | for key, value in pairs(object) do | ||
| 3908 | print(key, value) | ||
| 3909 | end | ||
| 3910 | local _list_0 = items | ||
| 3911 | for _index_0 = 2, 4 do | ||
| 3912 | local item = _list_0[_index_0] | ||
| 3913 | print(item) | ||
| 3914 | end | ||
| 3915 | local _list_0 = items | ||
| 3916 | for _index_0 = 1, #_list_0 do | ||
| 3917 | local item = _list_0[_index_0] | ||
| 3918 | print(item) | ||
| 3919 | end | ||
| 3920 | for j = 1, 10, 3 do | ||
| 3921 | print(j) | ||
| 3922 | end | ||
| 3923 | local doubled_evens | ||
| 3924 | local _accum_0 = { } | ||
| 3925 | local _len_0 = 1 | ||
| 3926 | for i = 1, 20 do | ||
| 3927 | if i % 2 == 0 then | ||
| 3928 | _accum_0[_len_0] = i * 2 | ||
| 3929 | _len_0 = _len_0 + 1 | ||
| 3930 | else | ||
| 3931 | _accum_0[_len_0] = i | ||
| 3932 | _len_0 = _len_0 + 1 | ||
| 3933 | end | ||
| 3934 | end | ||
| 3935 | doubled_evens = _accum_0 | ||
| 3936 | local first_large | ||
| 3937 | local _accum_0 | ||
| 3938 | local _list_0 = numbers | ||
| 3939 | for _index_0 = 1, #_list_0 do | ||
| 3940 | local n = _list_0[_index_0] | ||
| 3941 | if n > 10 then | ||
| 3942 | _accum_0 = n | ||
| 3943 | break | ||
| 3944 | end | ||
| 3945 | end | ||
| 3946 | first_large = _accum_0 | ||
| 3947 | local func_a | ||
| 3948 | func_a = function() | ||
| 3949 | for i = 1, 10 do | ||
| 3950 | print(i) | ||
| 3951 | end | ||
| 3952 | end | ||
| 3953 | local func_b | ||
| 3954 | func_b = function() | ||
| 3955 | local _accum_0 = { } | ||
| 3956 | local _len_0 = 1 | ||
| 3957 | for i = 1, 10 do | ||
| 3958 | _accum_0[_len_0] = i | ||
| 3959 | _len_0 = _len_0 + 1 | ||
| 3960 | end | ||
| 3961 | return _accum_0 | ||
| 3962 | end | ||
| 3963 | print(func_a()) | ||
| 3964 | print(func_b()) | ||
| 3965 | local i = 10 | ||
| 3966 | repeat | ||
| 3967 | print(i) | ||
| 3968 | i = i - 1 | ||
| 3969 | until i == 0 | ||
| 3970 | local i = 10 | ||
| 3971 | while i > 0 do | ||
| 3972 | print(i) | ||
| 3973 | i = i - 1 | ||
| 3974 | end | ||
| 3975 | while running == true do | ||
| 3976 | my_function() | ||
| 3977 | end | ||
| 3978 | local i = 10 | ||
| 3979 | while not (i == 0) do | ||
| 3980 | print(i) | ||
| 3981 | i = i - 1 | ||
| 3982 | end | ||
| 3983 | while not (running == false) do | ||
| 3984 | my_function() | ||
| 3985 | end | ||
| 3986 | local i = 0 | ||
| 3987 | while i < 10 do | ||
| 3988 | i = i + 1 | ||
| 3989 | if i % 2 == 0 then | ||
| 3990 | goto _continue_0 | ||
| 3991 | end | ||
| 3992 | print(i) | ||
| 3993 | ::_continue_0:: | ||
| 3994 | end | ||
| 3995 | local my_numbers = { | ||
| 3996 | 1, | ||
| 3997 | 2, | ||
| 3998 | 3, | ||
| 3999 | 4, | ||
| 4000 | 5, | ||
| 4001 | 6 | ||
| 4002 | } | ||
| 4003 | local odds | ||
| 4004 | local _accum_0 = { } | ||
| 4005 | local _len_0 = 1 | ||
| 4006 | for _index_0 = 1, #my_numbers do | ||
| 4007 | local x = my_numbers[_index_0] | ||
| 4008 | if x % 2 == 1 then | ||
| 4009 | goto _continue_0 | ||
| 4010 | end | ||
| 4011 | _accum_0[_len_0] = x | ||
| 4012 | _len_0 = _len_0 + 1 | ||
| 4013 | ::_continue_0:: | ||
| 4014 | end | ||
| 4015 | odds = _accum_0 | ||
| 4016 | local have_coins = false | ||
| 4017 | if have_coins then | ||
| 4018 | print("有硬币") | ||
| 4019 | else | ||
| 4020 | print("没有硬币") | ||
| 4021 | end | ||
| 4022 | local have_coins = false | ||
| 4023 | if have_coins then | ||
| 4024 | print("有硬币") | ||
| 4025 | else | ||
| 4026 | print("没有硬币") | ||
| 4027 | end | ||
| 4028 | local have_coins = false | ||
| 4029 | print((function() | ||
| 4030 | if have_coins then | ||
| 4031 | return "有硬币" | ||
| 4032 | else | ||
| 4033 | return "没有硬币" | ||
| 4034 | end | ||
| 4035 | end)()) | ||
| 4036 | local is_tall | ||
| 4037 | is_tall = function(name) | ||
| 4038 | if name == "Rob" then | ||
| 4039 | return true | ||
| 4040 | else | ||
| 4041 | return false | ||
| 4042 | end | ||
| 4043 | end | ||
| 4044 | local message | ||
| 4045 | if is_tall("Rob") then | ||
| 4046 | message = "我很高" | ||
| 4047 | else | ||
| 4048 | message = "我不是很高" | ||
| 4049 | end | ||
| 4050 | print(message) | ||
| 4051 | if not (os.date("%A") == "Monday") then | ||
| 4052 | print("今天不是星期一!") | ||
| 4053 | end | ||
| 4054 | if not (math.random() > 0.1) then | ||
| 4055 | print("你真幸运!") | ||
| 4056 | end | ||
| 4057 | local a = 5 | ||
| 4058 | if (1 == a or 3 == a or 5 == a or 7 == a) then | ||
| 4059 | print("检查离散值的相等性") | ||
| 4060 | end | ||
| 4061 | if (function() | ||
| 4062 | local _check_0 = list | ||
| 4063 | for _index_0 = 1, #_check_0 do | ||
| 4064 | if _check_0[_index_0] == a then | ||
| 4065 | return true | ||
| 4066 | end | ||
| 4067 | end | ||
| 4068 | return false | ||
| 4069 | end)() then | ||
| 4070 | print("检查`a`是否在列表中") | ||
| 4071 | end | ||
| 4072 | if not (math.random() > 0.1) then | ||
| 4073 | print("你很幸运!") | ||
| 4074 | end | ||
| 4075 | if name == "Rob" then | ||
| 4076 | print("你好,世界") | ||
| 4077 | end | ||
| 4078 | local _list_0 = items | ||
| 4079 | for _index_0 = 1, #_list_0 do | ||
| 4080 | local item = _list_0[_index_0] | ||
| 4081 | print("项目: ", item) | ||
| 4082 | end | ||
| 4083 | while game:isRunning() do | ||
| 4084 | game:update() | ||
| 4085 | end | ||
| 4086 | while not reader:eof() do | ||
| 4087 | reader:parse_line() | ||
| 4088 | end | ||
| 4089 | local name = "Dan" | ||
| 4090 | if "Robert" == name then | ||
| 4091 | print("你是Robert") | ||
| 4092 | elseif "Dan" == name or "Daniel" == name then | ||
| 4093 | print("你的名字是Dan") | ||
| 4094 | else | ||
| 4095 | print("我不认识你,你的名字是" .. tostring(name)) | ||
| 4096 | end | ||
| 4097 | local b = 1 | ||
| 4098 | local next_number | ||
| 4099 | if 1 == b then | ||
| 4100 | next_number = 2 | ||
| 4101 | elseif 2 == b then | ||
| 4102 | next_number = 3 | ||
| 4103 | else | ||
| 4104 | next_number = error("数字数得太大了!") | ||
| 4105 | end | ||
| 4106 | local msg | ||
| 4107 | local _exp_0 = math.random(1, 5) | ||
| 4108 | if 1 == _exp_0 then | ||
| 4109 | msg = "你很幸运" | ||
| 4110 | elseif 2 == _exp_0 then | ||
| 4111 | msg = "你差点很幸运" | ||
| 4112 | else | ||
| 4113 | msg = "不太幸运" | ||
| 4114 | end | ||
| 4115 | do | ||
| 4116 | local _exp_0 = math.random(1, 5) | ||
| 4117 | if 1 == _exp_0 then | ||
| 4118 | print("你很幸运") | ||
| 4119 | else | ||
| 4120 | print("不太幸运") | ||
| 4121 | end | ||
| 4122 | end | ||
| 4123 | local _exp_0 = math.random(1, 5) | ||
| 4124 | if 1 == _exp_0 then | ||
| 4125 | print("你很幸运") | ||
| 4126 | else | ||
| 4127 | print("不太幸运") | ||
| 4128 | end | ||
| 4129 | local items = { | ||
| 4130 | { | ||
| 4131 | x = 100, | ||
| 4132 | y = 200 | ||
| 4133 | }, | ||
| 4134 | { | ||
| 4135 | width = 300, | ||
| 4136 | height = 400 | ||
| 4137 | } | ||
| 4138 | } | ||
| 4139 | for _index_0 = 1, #items do | ||
| 4140 | local item = items[_index_0] | ||
| 4141 | local _type_0 = type(item) | ||
| 4142 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 4143 | local _match_0 = false | ||
| 4144 | if _tab_0 then | ||
| 4145 | local x = item.x | ||
| 4146 | local y = item.y | ||
| 4147 | if x ~= nil and y ~= nil then | ||
| 4148 | _match_0 = true | ||
| 4149 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) | ||
| 4150 | end | ||
| 4151 | end | ||
| 4152 | if not _match_0 then | ||
| 4153 | if _tab_0 then | ||
| 4154 | local width = item.width | ||
| 4155 | local height = item.height | ||
| 4156 | if width ~= nil and height ~= nil then | ||
| 4157 | print("尺寸 " .. tostring(width) .. ", " .. tostring(height)) | ||
| 4158 | end | ||
| 4159 | end | ||
| 4160 | end | ||
| 4161 | end | ||
| 4162 | local item = { } | ||
| 4163 | local x, y = item.pos.x, item.pos.y | ||
| 4164 | if x == nil then | ||
| 4165 | x = 50 | ||
| 4166 | end | ||
| 4167 | if y == nil then | ||
| 4168 | y = 200 | ||
| 4169 | end | ||
| 4170 | local _type_0 = type(item) | ||
| 4171 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 4172 | if _tab_0 then | ||
| 4173 | do | ||
| 4174 | local _obj_0 = item.pos | ||
| 4175 | local _type_1 = type(_obj_0) | ||
| 4176 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 4177 | x = _obj_0.x | ||
| 4178 | end | ||
| 4179 | end | ||
| 4180 | do | ||
| 4181 | local _obj_0 = item.pos | ||
| 4182 | local _type_1 = type(_obj_0) | ||
| 4183 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 4184 | y = _obj_0.y | ||
| 4185 | end | ||
| 4186 | end | ||
| 4187 | if x == nil then | ||
| 4188 | x = 50 | ||
| 4189 | end | ||
| 4190 | if y == nil then | ||
| 4191 | y = 200 | ||
| 4192 | end | ||
| 4193 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) | ||
| 4194 | end | ||
| 4195 | local _exp_0 = tb | ||
| 4196 | local _type_0 = type(_exp_0) | ||
| 4197 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 4198 | local _match_0 = false | ||
| 4199 | if _tab_0 then | ||
| 4200 | if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then | ||
| 4201 | _match_0 = true | ||
| 4202 | print("1, 2, 3") | ||
| 4203 | end | ||
| 4204 | end | ||
| 4205 | if not _match_0 then | ||
| 4206 | local _match_1 = false | ||
| 4207 | if _tab_0 then | ||
| 4208 | local b = _exp_0[2] | ||
| 4209 | if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then | ||
| 4210 | _match_1 = true | ||
| 4211 | print("1, " .. tostring(b) .. ", 3") | ||
| 4212 | end | ||
| 4213 | end | ||
| 4214 | if not _match_1 then | ||
| 4215 | if _tab_0 then | ||
| 4216 | local b = _exp_0[3] | ||
| 4217 | if b == nil then | ||
| 4218 | b = 3 | ||
| 4219 | end | ||
| 4220 | if 1 == _exp_0[1] and 2 == _exp_0[2] then | ||
| 4221 | print("1, 2, " .. tostring(b)) | ||
| 4222 | end | ||
| 4223 | end | ||
| 4224 | end | ||
| 4225 | end | ||
| 4226 | local _exp_0 = tb | ||
| 4227 | local _type_0 = type(_exp_0) | ||
| 4228 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 4229 | local _match_0 = false | ||
| 4230 | if _tab_0 then | ||
| 4231 | local result = _exp_0.result | ||
| 4232 | if true == _exp_0.success and result ~= nil then | ||
| 4233 | _match_0 = true | ||
| 4234 | print("成功", result) | ||
| 4235 | end | ||
| 4236 | end | ||
| 4237 | if not _match_0 then | ||
| 4238 | local _match_1 = false | ||
| 4239 | if _tab_0 then | ||
| 4240 | if false == _exp_0.success then | ||
| 4241 | _match_1 = true | ||
| 4242 | print("失败", result) | ||
| 4243 | end | ||
| 4244 | end | ||
| 4245 | if not _match_1 then | ||
| 4246 | print("无效值") | ||
| 4247 | end | ||
| 4248 | end | ||
| 4249 | local _exp_0 = tb | ||
| 4250 | local _type_0 = type(_exp_0) | ||
| 4251 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 4252 | local _match_0 = false | ||
| 4253 | if _tab_0 then | ||
| 4254 | local content | ||
| 4255 | do | ||
| 4256 | local _obj_0 = _exp_0.data | ||
| 4257 | local _type_1 = type(_obj_0) | ||
| 4258 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 4259 | content = _obj_0.content | ||
| 4260 | end | ||
| 4261 | end | ||
| 4262 | local _val_0 | ||
| 4263 | do | ||
| 4264 | local _obj_0 = _exp_0.data | ||
| 4265 | if _obj_0 ~= nil then | ||
| 4266 | _val_0 = _obj_0.type | ||
| 4267 | end | ||
| 4268 | end | ||
| 4269 | if "success" == _val_0 and content ~= nil then | ||
| 4270 | _match_0 = true | ||
| 4271 | print("成功", content) | ||
| 4272 | end | ||
| 4273 | end | ||
| 4274 | if not _match_0 then | ||
| 4275 | local _match_1 = false | ||
| 4276 | if _tab_0 then | ||
| 4277 | local content | ||
| 4278 | do | ||
| 4279 | local _obj_0 = _exp_0.data | ||
| 4280 | local _type_1 = type(_obj_0) | ||
| 4281 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 4282 | content = _obj_0.content | ||
| 4283 | end | ||
| 4284 | end | ||
| 4285 | local _val_0 | ||
| 4286 | do | ||
| 4287 | local _obj_0 = _exp_0.data | ||
| 4288 | if _obj_0 ~= nil then | ||
| 4289 | _val_0 = _obj_0.type | ||
| 4290 | end | ||
| 4291 | end | ||
| 4292 | if "error" == _val_0 and content ~= nil then | ||
| 4293 | _match_1 = true | ||
| 4294 | print("失败", content) | ||
| 4295 | end | ||
| 4296 | end | ||
| 4297 | if not _match_1 then | ||
| 4298 | print("无效值") | ||
| 4299 | end | ||
| 4300 | end | ||
| 4301 | local _exp_0 = tb | ||
| 4302 | local _type_0 = type(_exp_0) | ||
| 4303 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 4304 | if _tab_0 then | ||
| 4305 | local fourth = _exp_0[4] | ||
| 4306 | local _val_0 | ||
| 4307 | do | ||
| 4308 | local _obj_0 = _exp_0[1] | ||
| 4309 | if _obj_0 ~= nil then | ||
| 4310 | _val_0 = _obj_0.a | ||
| 4311 | end | ||
| 4312 | end | ||
| 4313 | local _val_1 | ||
| 4314 | do | ||
| 4315 | local _obj_0 = _exp_0[1] | ||
| 4316 | if _obj_0 ~= nil then | ||
| 4317 | _val_1 = _obj_0.b | ||
| 4318 | end | ||
| 4319 | end | ||
| 4320 | local _val_2 | ||
| 4321 | do | ||
| 4322 | local _obj_0 = _exp_0[2] | ||
| 4323 | if _obj_0 ~= nil then | ||
| 4324 | _val_2 = _obj_0.a | ||
| 4325 | end | ||
| 4326 | end | ||
| 4327 | local _val_3 | ||
| 4328 | do | ||
| 4329 | local _obj_0 = _exp_0[2] | ||
| 4330 | if _obj_0 ~= nil then | ||
| 4331 | _val_3 = _obj_0.b | ||
| 4332 | end | ||
| 4333 | end | ||
| 4334 | local _val_4 | ||
| 4335 | do | ||
| 4336 | local _obj_0 = _exp_0[3] | ||
| 4337 | if _obj_0 ~= nil then | ||
| 4338 | _val_4 = _obj_0.a | ||
| 4339 | end | ||
| 4340 | end | ||
| 4341 | local _val_5 | ||
| 4342 | do | ||
| 4343 | local _obj_0 = _exp_0[3] | ||
| 4344 | if _obj_0 ~= nil then | ||
| 4345 | _val_5 = _obj_0.b | ||
| 4346 | end | ||
| 4347 | end | ||
| 4348 | 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 | ||
| 4349 | print("匹配成功", fourth) | ||
| 4350 | end | ||
| 4351 | end | ||
| 4352 | local segments = { | ||
| 4353 | "admin", | ||
| 4354 | "users", | ||
| 4355 | "logs", | ||
| 4356 | "view" | ||
| 4357 | } | ||
| 4358 | local _type_0 = type(segments) | ||
| 4359 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 4360 | if _tab_0 then | ||
| 4361 | local groups | ||
| 4362 | do | ||
| 4363 | local _accum_0 = { } | ||
| 4364 | local _len_0 = 1 | ||
| 4365 | local _max_0 = #segments + -3 + 1 | ||
| 4366 | for _index_0 = 1, _max_0 do | ||
| 4367 | local _item_0 = segments[_index_0] | ||
| 4368 | _accum_0[_len_0] = _item_0 | ||
| 4369 | _len_0 = _len_0 + 1 | ||
| 4370 | end | ||
| 4371 | groups = _accum_0 | ||
| 4372 | end | ||
| 4373 | local resource = segments[#segments - 1] | ||
| 4374 | local action = segments[#segments] | ||
| 4375 | if resource ~= nil and action ~= nil then | ||
| 4376 | print("Group:", groups) | ||
| 4377 | print("Resource:", resource) | ||
| 4378 | print("Action:", action) | ||
| 4379 | end | ||
| 4380 | end | ||
| 4381 | local Inventory | 4313 | local Inventory |
| 4382 | local _class_0 | 4314 | local _class_0 |
| 4383 | local _base_0 = { | 4315 | local _base_0 = { |
| @@ -5038,6 +4970,46 @@ local _with_0 = obj | |||
| 5038 | if _with_0 ~= nil then | 4970 | if _with_0 ~= nil then |
| 5039 | print(obj.name) | 4971 | print(obj.name) |
| 5040 | 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 = "你好" | ||
| 4998 | print("原始:", str) | ||
| 4999 | print("大写:", 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 | ||
| 5041 | do | 5013 | do |
| 5042 | local var = "hello" | 5014 | local var = "hello" |
| 5043 | print(var) | 5015 | print(var) |
| @@ -5059,6 +5031,46 @@ local tbl = { | |||
| 5059 | return 1234 | 5031 | return 1234 |
| 5060 | end)() | 5032 | end)() |
| 5061 | } | 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("分配键值!") | ||
| 5052 | return 1234 | ||
| 5053 | end)() | ||
| 5054 | } | ||
| 5055 | local my_object = { | ||
| 5056 | value = 1000, | ||
| 5057 | write = function(self) | ||
| 5058 | return print("值为:", self.value) | ||
| 5059 | end | ||
| 5060 | } | ||
| 5061 | local run_callback | ||
| 5062 | run_callback = function(func) | ||
| 5063 | print("运行回调...") | ||
| 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)()) | ||
| 5062 | local my_object = { | 5074 | local my_object = { |
| 5063 | value = 1000, | 5075 | value = 1000, |
| 5064 | write = function(self) | 5076 | write = function(self) |
| @@ -5106,3 +5118,31 @@ my_func = function(add) | |||
| 5106 | end | 5118 | end |
| 5107 | my_func(22) | 5119 | my_func(22) |
| 5108 | 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) | ||
diff --git a/spec/outputs/compile_doc.lua b/spec/outputs/compile_doc.lua index e7d307d..cb359a1 100644 --- a/spec/outputs/compile_doc.lua +++ b/spec/outputs/compile_doc.lua | |||
| @@ -2,52 +2,113 @@ local outputFolder = ... | |||
| 2 | local _list_0 = { | 2 | local _list_0 = { |
| 3 | { | 3 | { |
| 4 | "codes_from_doc.lua", | 4 | "codes_from_doc.lua", |
| 5 | "doc/docs/doc/index.md" | 5 | { |
| 6 | "doc/docs/doc/introduction.md", | ||
| 7 | "doc/docs/doc/macro.md", | ||
| 8 | "doc/docs/doc/operator.md", | ||
| 9 | "doc/docs/doc/module.md", | ||
| 10 | "doc/docs/doc/assignment.md", | ||
| 11 | "doc/docs/doc/destructuring-assignment.md", | ||
| 12 | "doc/docs/doc/if-assignment.md", | ||
| 13 | "doc/docs/doc/varargs-assignment.md", | ||
| 14 | "doc/docs/doc/whitespace.md", | ||
| 15 | "doc/docs/doc/comment.md", | ||
| 16 | "doc/docs/doc/try.md", | ||
| 17 | "doc/docs/doc/attributes.md", | ||
| 18 | "doc/docs/doc/literals.md", | ||
| 19 | "doc/docs/doc/function-literals.md", | ||
| 20 | "doc/docs/doc/backcalls.md", | ||
| 21 | "doc/docs/doc/table-literals.md", | ||
| 22 | "doc/docs/doc/comprehensions.md", | ||
| 23 | "doc/docs/doc/for-loop.md", | ||
| 24 | "doc/docs/doc/while-loop.md", | ||
| 25 | "doc/docs/doc/continue.md", | ||
| 26 | "doc/docs/doc/conditionals.md", | ||
| 27 | "doc/docs/doc/line-decorators.md", | ||
| 28 | "doc/docs/doc/switch.md", | ||
| 29 | "doc/docs/doc/object-oriented-programming.md", | ||
| 30 | "doc/docs/doc/with-statement.md", | ||
| 31 | "doc/docs/doc/do.md", | ||
| 32 | "doc/docs/doc/function-stubs.md", | ||
| 33 | "doc/docs/doc/the-using-clause-controlling-destructive-assignment.md" | ||
| 34 | } | ||
| 6 | }, | 35 | }, |
| 7 | { | 36 | { |
| 8 | "codes_from_doc_zh.lua", | 37 | "codes_from_doc_zh.lua", |
| 9 | "doc/docs/zh/doc/index.md" | 38 | { |
| 39 | "doc/docs/zh/doc/introduction.md", | ||
| 40 | "doc/docs/zh/doc/macro.md", | ||
| 41 | "doc/docs/zh/doc/operator.md", | ||
| 42 | "doc/docs/zh/doc/module.md", | ||
| 43 | "doc/docs/zh/doc/assignment.md", | ||
| 44 | "doc/docs/zh/doc/destructuring-assignment.md", | ||
| 45 | "doc/docs/zh/doc/if-assignment.md", | ||
| 46 | "doc/docs/zh/doc/varargs-assignment.md", | ||
| 47 | "doc/docs/zh/doc/whitespace.md", | ||
| 48 | "doc/docs/zh/doc/comment.md", | ||
| 49 | "doc/docs/zh/doc/try.md", | ||
| 50 | "doc/docs/zh/doc/attributes.md", | ||
| 51 | "doc/docs/zh/doc/literals.md", | ||
| 52 | "doc/docs/zh/doc/function-literals.md", | ||
| 53 | "doc/docs/zh/doc/backcalls.md", | ||
| 54 | "doc/docs/zh/doc/table-literals.md", | ||
| 55 | "doc/docs/zh/doc/comprehensions.md", | ||
| 56 | "doc/docs/zh/doc/for-loop.md", | ||
| 57 | "doc/docs/zh/doc/while-loop.md", | ||
| 58 | "doc/docs/zh/doc/continue.md", | ||
| 59 | "doc/docs/zh/doc/conditionals.md", | ||
| 60 | "doc/docs/zh/doc/line-decorators.md", | ||
| 61 | "doc/docs/zh/doc/switch.md", | ||
| 62 | "doc/docs/zh/doc/object-oriented-programming.md", | ||
| 63 | "doc/docs/zh/doc/with-statement.md", | ||
| 64 | "doc/docs/zh/doc/do.md", | ||
| 65 | "doc/docs/zh/doc/function-stubs.md", | ||
| 66 | "doc/docs/zh/doc/the-using-clause-controlling-destructive-assignment.md" | ||
| 67 | } | ||
| 10 | } | 68 | } |
| 11 | } | 69 | } |
| 12 | for _index_0 = 1, #_list_0 do | 70 | for _index_0 = 1, #_list_0 do |
| 13 | local _des_0 = _list_0[_index_0] | 71 | local _des_0 = _list_0[_index_0] |
| 14 | local compiledFile, docFile = _des_0[1], _des_0[2] | 72 | local compiledFile, docFiles = _des_0[1], _des_0[2] |
| 15 | local input | 73 | local codes = { } |
| 16 | local _with_0 = io.open(docFile) | 74 | for _index_1 = 1, #docFiles do |
| 17 | if _with_0 ~= nil then | 75 | local docFile = docFiles[_index_1] |
| 18 | local to_lua = require("yue").to_lua | 76 | local input |
| 19 | local text = _with_0:read("*a") | 77 | local _with_0 = io.open(docFile) |
| 20 | local codes = { } | 78 | if _with_0 ~= nil then |
| 21 | for code in text:gmatch("```yuescript[\r\n]+(.-)```[^%w]") do | 79 | local to_lua = require("yue").to_lua |
| 22 | local result, err = to_lua(code, { | 80 | local text = _with_0:read("*a") |
| 23 | implicit_return_root = false, | 81 | for code in text:gmatch("```yuescript[\r\n]+(.-)```[^%w]") do |
| 24 | reserve_line_number = false | 82 | local result, err = to_lua(code, { |
| 25 | }) | 83 | implicit_return_root = false, |
| 26 | if result then | 84 | reserve_line_number = false |
| 27 | codes[#codes + 1] = result | 85 | }) |
| 28 | elseif not err:match("macro exporting module only accepts macro definition") then | 86 | if result then |
| 29 | print(err) | 87 | codes[#codes + 1] = result |
| 30 | os.exit(1) | 88 | elseif not err:match("macro exporting module only accepts macro definition") then |
| 89 | print(err) | ||
| 90 | os.exit(1) | ||
| 91 | end | ||
| 31 | end | 92 | end |
| 32 | end | 93 | for code in text:gmatch("```yue[\r\n]+(.-)```[^%w]") do |
| 33 | for code in text:gmatch("```yue[\r\n]+(.-)```[^%w]") do | 94 | local result, err = to_lua(code, { |
| 34 | local result, err = to_lua(code, { | 95 | implicit_return_root = false, |
| 35 | implicit_return_root = false, | 96 | reserve_line_number = false |
| 36 | reserve_line_number = false | 97 | }) |
| 37 | }) | 98 | if result then |
| 38 | if result then | 99 | codes[#codes + 1] = result |
| 39 | codes[#codes + 1] = result | 100 | else |
| 40 | else | 101 | print(err) |
| 41 | print(err) | 102 | os.exit(1) |
| 42 | os.exit(1) | 103 | end |
| 43 | end | 104 | end |
| 44 | end | 105 | end |
| 45 | local output | 106 | input = _with_0 |
| 46 | local _with_1 = io.open(tostring(outputFolder) .. "/" .. tostring(compiledFile), "w+") | 107 | local _close_0 <close> = input |
| 47 | _with_1:write(table.concat(codes)) | ||
| 48 | output = _with_1 | ||
| 49 | local _close_0 <close> = output | ||
| 50 | end | 108 | end |
| 51 | input = _with_0 | 109 | local output |
| 52 | local _close_0 <close> = input | 110 | local _with_0 = io.open(tostring(outputFolder) .. "/" .. tostring(compiledFile), "w+") |
| 111 | _with_0:write(table.concat(codes)) | ||
| 112 | output = _with_0 | ||
| 113 | local _close_0 <close> = output | ||
| 53 | end | 114 | end |
