diff options
| author | Li Jin <dragon-fly@qq.com> | 2024-03-21 09:14:34 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2024-03-21 09:14:34 +0800 |
| commit | 4a3cc26c6dfd74e61c8b6480038d6a292ea86e47 (patch) | |
| tree | 9554b94cfc15e4acee0c2e60b63af16f1b828207 /spec/outputs/codes_from_doc_zh.lua | |
| parent | 80b65520da432843f0c63431a1867bd2620bc4ac (diff) | |
| download | yuescript-4a3cc26c6dfd74e61c8b6480038d6a292ea86e47.tar.gz yuescript-4a3cc26c6dfd74e61c8b6480038d6a292ea86e47.tar.bz2 yuescript-4a3cc26c6dfd74e61c8b6480038d6a292ea86e47.zip | |
remove redundant 'do' blocks in code generation.
Diffstat (limited to 'spec/outputs/codes_from_doc_zh.lua')
| -rw-r--r-- | spec/outputs/codes_from_doc_zh.lua | 2250 |
1 files changed, 1048 insertions, 1202 deletions
diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua index 15647b2..fff0bdd 100644 --- a/spec/outputs/codes_from_doc_zh.lua +++ b/spec/outputs/codes_from_doc_zh.lua | |||
| @@ -46,13 +46,18 @@ _module_0["🌛"] = _ud83c_udf1b | |||
| 46 | return _module_0 | 46 | return _module_0 |
| 47 | local area = 6.2831853071796 * 5 | 47 | local area = 6.2831853071796 * 5 |
| 48 | print('你好 世界') | 48 | print('你好 世界') |
| 49 | assert(item ~= nil) | 49 | do |
| 50 | assert(item ~= nil) | ||
| 51 | end | ||
| 50 | local value = item | 52 | local value = item |
| 51 | if (f1() and f2() and f3()) then | 53 | if (f1() and f2() and f3()) then |
| 52 | print("OK") | 54 | print("OK") |
| 53 | end | 55 | end |
| 56 | do | ||
| 57 | local funcA | ||
| 58 | funcA = function() end | ||
| 59 | end | ||
| 54 | local funcA | 60 | local funcA |
| 55 | funcA = function() end | ||
| 56 | funcA = function() | 61 | funcA = function() |
| 57 | return "访问月之脚本定义的变量" | 62 | return "访问月之脚本定义的变量" |
| 58 | end | 63 | end |
| @@ -146,28 +151,26 @@ local b = { | |||
| 146 | y = 1 | 151 | y = 1 |
| 147 | } | 152 | } |
| 148 | local merge | 153 | local merge |
| 149 | do | 154 | local _tab_0 = { } |
| 150 | local _tab_0 = { } | 155 | local _idx_0 = 1 |
| 151 | local _idx_0 = 1 | 156 | for _key_0, _value_0 in pairs(a) do |
| 152 | for _key_0, _value_0 in pairs(a) do | 157 | if _idx_0 == _key_0 then |
| 153 | if _idx_0 == _key_0 then | 158 | _tab_0[#_tab_0 + 1] = _value_0 |
| 154 | _tab_0[#_tab_0 + 1] = _value_0 | 159 | _idx_0 = _idx_0 + 1 |
| 155 | _idx_0 = _idx_0 + 1 | 160 | else |
| 156 | else | 161 | _tab_0[_key_0] = _value_0 |
| 157 | _tab_0[_key_0] = _value_0 | ||
| 158 | end | ||
| 159 | end | 162 | end |
| 160 | local _idx_1 = 1 | 163 | end |
| 161 | for _key_0, _value_0 in pairs(b) do | 164 | local _idx_1 = 1 |
| 162 | if _idx_1 == _key_0 then | 165 | for _key_0, _value_0 in pairs(b) do |
| 163 | _tab_0[#_tab_0 + 1] = _value_0 | 166 | if _idx_1 == _key_0 then |
| 164 | _idx_1 = _idx_1 + 1 | 167 | _tab_0[#_tab_0 + 1] = _value_0 |
| 165 | else | 168 | _idx_1 = _idx_1 + 1 |
| 166 | _tab_0[_key_0] = _value_0 | 169 | else |
| 167 | end | 170 | _tab_0[_key_0] = _value_0 |
| 168 | end | 171 | end |
| 169 | merge = _tab_0 | ||
| 170 | end | 172 | end |
| 173 | merge = _tab_0 | ||
| 171 | local mt = { } | 174 | local mt = { } |
| 172 | local add | 175 | local add |
| 173 | add = function(self, right) | 176 | add = function(self, right) |
| @@ -259,12 +262,10 @@ end | |||
| 259 | if print and (x ~= nil) then | 262 | if print and (x ~= nil) then |
| 260 | print(x) | 263 | print(x) |
| 261 | end | 264 | end |
| 262 | do | 265 | local _with_0 = io.open("test.txt", "w") |
| 263 | local _with_0 = io.open("test.txt", "w") | 266 | if _with_0 ~= nil then |
| 264 | if _with_0 ~= nil then | 267 | _with_0:write("你好") |
| 265 | _with_0:write("你好") | 268 | _with_0:close() |
| 266 | _with_0:close() | ||
| 267 | end | ||
| 268 | end | 269 | end |
| 269 | print("你好") | 270 | print("你好") |
| 270 | print(1, 2) | 271 | print(1, 2) |
| @@ -341,10 +342,8 @@ do | |||
| 341 | x, y, z = _obj_0.x, _obj_0.y, _obj_0.z | 342 | x, y, z = _obj_0.x, _obj_0.y, _obj_0.z |
| 342 | end | 343 | end |
| 343 | local a, b, c | 344 | local a, b, c |
| 344 | do | 345 | local _obj_0 = require('module') |
| 345 | local _obj_0 = require('module') | 346 | a, b, c = _obj_0.a, _obj_0.b, _obj_0.c |
| 346 | a, b, c = _obj_0.a, _obj_0.b, _obj_0.c | ||
| 347 | end | ||
| 348 | end | 347 | end |
| 349 | do | 348 | do |
| 350 | local module = require('module') | 349 | local module = require('module') |
| @@ -383,29 +382,27 @@ y = function() | |||
| 383 | end | 382 | end |
| 384 | _module_0["y"] = y | 383 | _module_0["y"] = y |
| 385 | local Something | 384 | local Something |
| 386 | do | 385 | local _class_0 |
| 387 | local _class_0 | 386 | local _base_0 = { |
| 388 | local _base_0 = { | 387 | umm = "cool" |
| 389 | umm = "cool" | 388 | } |
| 390 | } | 389 | if _base_0.__index == nil then |
| 391 | if _base_0.__index == nil then | 390 | _base_0.__index = _base_0 |
| 392 | _base_0.__index = _base_0 | ||
| 393 | end | ||
| 394 | _class_0 = setmetatable({ | ||
| 395 | __init = function() end, | ||
| 396 | __base = _base_0, | ||
| 397 | __name = "Something" | ||
| 398 | }, { | ||
| 399 | __index = _base_0, | ||
| 400 | __call = function(cls, ...) | ||
| 401 | local _self_0 = setmetatable({ }, _base_0) | ||
| 402 | cls.__init(_self_0, ...) | ||
| 403 | return _self_0 | ||
| 404 | end | ||
| 405 | }) | ||
| 406 | _base_0.__class = _class_0 | ||
| 407 | Something = _class_0 | ||
| 408 | end | 391 | end |
| 392 | _class_0 = setmetatable({ | ||
| 393 | __init = function() end, | ||
| 394 | __base = _base_0, | ||
| 395 | __name = "Something" | ||
| 396 | }, { | ||
| 397 | __index = _base_0, | ||
| 398 | __call = function(cls, ...) | ||
| 399 | local _self_0 = setmetatable({ }, _base_0) | ||
| 400 | cls.__init(_self_0, ...) | ||
| 401 | return _self_0 | ||
| 402 | end | ||
| 403 | }) | ||
| 404 | _base_0.__class = _class_0 | ||
| 405 | Something = _class_0 | ||
| 409 | _module_0["Something"] = Something | 406 | _module_0["Something"] = Something |
| 410 | return _module_0 | 407 | return _module_0 |
| 411 | local _module_0 = { } | 408 | local _module_0 = { } |
| @@ -436,11 +433,9 @@ if this then | |||
| 436 | else | 433 | else |
| 437 | _module_0[#_module_0 + 1] = 456 | 434 | _module_0[#_module_0 + 1] = 456 |
| 438 | end | 435 | end |
| 439 | do | 436 | local _with_0 = tmp |
| 440 | local _with_0 = tmp | 437 | local j = 2000 |
| 441 | local j = 2000 | 438 | _module_0[#_module_0 + 1] = _with_0 |
| 442 | _module_0[#_module_0 + 1] = _with_0 | ||
| 443 | end | ||
| 444 | return _module_0 | 439 | return _module_0 |
| 445 | local _module_0 = nil | 440 | local _module_0 = nil |
| 446 | _module_0 = function() | 441 | _module_0 = function() |
| @@ -577,25 +572,19 @@ for _index_0 = 1, #tuples do | |||
| 577 | local left, right = _des_0[1], _des_0[2] | 572 | local left, right = _des_0[1], _des_0[2] |
| 578 | print(left, right) | 573 | print(left, right) |
| 579 | end | 574 | end |
| 580 | do | 575 | local user = database.find_user("moon") |
| 581 | local user = database.find_user("moon") | 576 | if user then |
| 582 | if user then | 577 | print(user.name) |
| 583 | print(user.name) | ||
| 584 | end | ||
| 585 | end | 578 | end |
| 586 | do | 579 | local hello = os.getenv("hello") |
| 587 | local hello = os.getenv("hello") | 580 | if hello then |
| 588 | if hello then | 581 | print("你有 hello", hello) |
| 589 | print("你有 hello", hello) | 582 | else |
| 583 | local world = os.getenv("world") | ||
| 584 | if world then | ||
| 585 | print("你有 world", world) | ||
| 590 | else | 586 | else |
| 591 | do | 587 | print("什么都没有 :(") |
| 592 | local world = os.getenv("world") | ||
| 593 | if world then | ||
| 594 | print("你有 world", world) | ||
| 595 | else | ||
| 596 | print("什么都没有 :(") | ||
| 597 | end | ||
| 598 | end | ||
| 599 | end | 588 | end |
| 600 | end | 589 | end |
| 601 | do | 590 | do |
| @@ -852,40 +841,34 @@ local items = { | |||
| 852 | 4 | 841 | 4 |
| 853 | } | 842 | } |
| 854 | local doubled | 843 | local doubled |
| 855 | do | 844 | local _accum_0 = { } |
| 856 | local _accum_0 = { } | 845 | local _len_0 = 1 |
| 857 | local _len_0 = 1 | 846 | for i, item in ipairs(items) do |
| 858 | for i, item in ipairs(items) do | 847 | _accum_0[_len_0] = item * 2 |
| 859 | _accum_0[_len_0] = item * 2 | 848 | _len_0 = _len_0 + 1 |
| 860 | _len_0 = _len_0 + 1 | ||
| 861 | end | ||
| 862 | doubled = _accum_0 | ||
| 863 | end | 849 | end |
| 850 | doubled = _accum_0 | ||
| 864 | local iter = ipairs(items) | 851 | local iter = ipairs(items) |
| 865 | local slice | 852 | local slice |
| 866 | do | 853 | local _accum_0 = { } |
| 867 | local _accum_0 = { } | 854 | local _len_0 = 1 |
| 868 | local _len_0 = 1 | 855 | for i, item in iter do |
| 869 | for i, item in iter do | 856 | if i > 1 and i < 3 then |
| 870 | if i > 1 and i < 3 then | 857 | _accum_0[_len_0] = item |
| 871 | _accum_0[_len_0] = item | 858 | _len_0 = _len_0 + 1 |
| 872 | _len_0 = _len_0 + 1 | ||
| 873 | end | ||
| 874 | end | 859 | end |
| 875 | slice = _accum_0 | ||
| 876 | end | 860 | end |
| 861 | slice = _accum_0 | ||
| 877 | local doubled | 862 | local doubled |
| 878 | do | 863 | local _accum_0 = { } |
| 879 | local _accum_0 = { } | 864 | local _len_0 = 1 |
| 880 | local _len_0 = 1 | 865 | local _list_0 = items |
| 881 | local _list_0 = items | 866 | for _index_0 = 1, #_list_0 do |
| 882 | for _index_0 = 1, #_list_0 do | 867 | local item = _list_0[_index_0] |
| 883 | local item = _list_0[_index_0] | 868 | _accum_0[_len_0] = item * 2 |
| 884 | _accum_0[_len_0] = item * 2 | 869 | _len_0 = _len_0 + 1 |
| 885 | _len_0 = _len_0 + 1 | ||
| 886 | end | ||
| 887 | doubled = _accum_0 | ||
| 888 | end | 870 | end |
| 871 | doubled = _accum_0 | ||
| 889 | local x_coords = { | 872 | local x_coords = { |
| 890 | 4, | 873 | 4, |
| 891 | 5, | 874 | 5, |
| @@ -898,57 +881,49 @@ local y_coords = { | |||
| 898 | 3 | 881 | 3 |
| 899 | } | 882 | } |
| 900 | local points | 883 | local points |
| 901 | do | 884 | local _accum_0 = { } |
| 902 | local _accum_0 = { } | 885 | local _len_0 = 1 |
| 903 | local _len_0 = 1 | 886 | for _index_0 = 1, #x_coords do |
| 904 | for _index_0 = 1, #x_coords do | 887 | local x = x_coords[_index_0] |
| 905 | local x = x_coords[_index_0] | 888 | for _index_1 = 1, #y_coords do |
| 906 | for _index_1 = 1, #y_coords do | 889 | local y = y_coords[_index_1] |
| 907 | local y = y_coords[_index_1] | 890 | _accum_0[_len_0] = { |
| 908 | _accum_0[_len_0] = { | 891 | x, |
| 909 | x, | 892 | y |
| 910 | y | 893 | } |
| 911 | } | 894 | _len_0 = _len_0 + 1 |
| 912 | _len_0 = _len_0 + 1 | ||
| 913 | end | ||
| 914 | end | 895 | end |
| 915 | points = _accum_0 | ||
| 916 | end | 896 | end |
| 897 | points = _accum_0 | ||
| 917 | local evens | 898 | local evens |
| 918 | do | 899 | local _accum_0 = { } |
| 919 | local _accum_0 = { } | 900 | local _len_0 = 1 |
| 920 | local _len_0 = 1 | 901 | for i = 1, 100 do |
| 921 | for i = 1, 100 do | 902 | if i % 2 == 0 then |
| 922 | if i % 2 == 0 then | 903 | _accum_0[_len_0] = i |
| 923 | _accum_0[_len_0] = i | 904 | _len_0 = _len_0 + 1 |
| 924 | _len_0 = _len_0 + 1 | ||
| 925 | end | ||
| 926 | end | 905 | end |
| 927 | evens = _accum_0 | ||
| 928 | end | 906 | end |
| 907 | evens = _accum_0 | ||
| 929 | local thing = { | 908 | local thing = { |
| 930 | color = "red", | 909 | color = "red", |
| 931 | name = "fast", | 910 | name = "fast", |
| 932 | width = 123 | 911 | width = 123 |
| 933 | } | 912 | } |
| 934 | local thing_copy | 913 | local thing_copy |
| 935 | do | 914 | local _tbl_0 = { } |
| 936 | local _tbl_0 = { } | 915 | for k, v in pairs(thing) do |
| 937 | for k, v in pairs(thing) do | 916 | _tbl_0[k] = v |
| 938 | _tbl_0[k] = v | ||
| 939 | end | ||
| 940 | thing_copy = _tbl_0 | ||
| 941 | end | 917 | end |
| 918 | thing_copy = _tbl_0 | ||
| 942 | local no_color | 919 | local no_color |
| 943 | do | 920 | local _tbl_0 = { } |
| 944 | local _tbl_0 = { } | 921 | for k, v in pairs(thing) do |
| 945 | for k, v in pairs(thing) do | 922 | if k ~= "color" then |
| 946 | if k ~= "color" then | 923 | _tbl_0[k] = v |
| 947 | _tbl_0[k] = v | ||
| 948 | end | ||
| 949 | end | 924 | end |
| 950 | no_color = _tbl_0 | ||
| 951 | end | 925 | end |
| 926 | no_color = _tbl_0 | ||
| 952 | local numbers = { | 927 | local numbers = { |
| 953 | 1, | 928 | 1, |
| 954 | 2, | 929 | 2, |
| @@ -956,14 +931,12 @@ local numbers = { | |||
| 956 | 4 | 931 | 4 |
| 957 | } | 932 | } |
| 958 | local sqrts | 933 | local sqrts |
| 959 | do | 934 | local _tbl_0 = { } |
| 960 | local _tbl_0 = { } | 935 | for _index_0 = 1, #numbers do |
| 961 | for _index_0 = 1, #numbers do | 936 | local i = numbers[_index_0] |
| 962 | local i = numbers[_index_0] | 937 | _tbl_0[i] = math.sqrt(i) |
| 963 | _tbl_0[i] = math.sqrt(i) | ||
| 964 | end | ||
| 965 | sqrts = _tbl_0 | ||
| 966 | end | 938 | end |
| 939 | sqrts = _tbl_0 | ||
| 967 | local tuples = { | 940 | local tuples = { |
| 968 | { | 941 | { |
| 969 | "hello", | 942 | "hello", |
| @@ -975,52 +948,44 @@ local tuples = { | |||
| 975 | } | 948 | } |
| 976 | } | 949 | } |
| 977 | local tbl | 950 | local tbl |
| 978 | do | 951 | local _tbl_0 = { } |
| 979 | local _tbl_0 = { } | 952 | for _index_0 = 1, #tuples do |
| 980 | for _index_0 = 1, #tuples do | 953 | local tuple = tuples[_index_0] |
| 981 | local tuple = tuples[_index_0] | 954 | local _key_0, _val_0 = unpack(tuple) |
| 982 | local _key_0, _val_0 = unpack(tuple) | 955 | _tbl_0[_key_0] = _val_0 |
| 983 | _tbl_0[_key_0] = _val_0 | ||
| 984 | end | ||
| 985 | tbl = _tbl_0 | ||
| 986 | end | 956 | end |
| 957 | tbl = _tbl_0 | ||
| 987 | local slice | 958 | local slice |
| 988 | do | 959 | local _accum_0 = { } |
| 989 | local _accum_0 = { } | 960 | local _len_0 = 1 |
| 990 | local _len_0 = 1 | 961 | local _list_0 = items |
| 991 | local _list_0 = items | 962 | local _max_0 = 5 |
| 992 | local _max_0 = 5 | 963 | for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do |
| 993 | for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do | 964 | local item = _list_0[_index_0] |
| 994 | local item = _list_0[_index_0] | 965 | _accum_0[_len_0] = item |
| 995 | _accum_0[_len_0] = item | 966 | _len_0 = _len_0 + 1 |
| 996 | _len_0 = _len_0 + 1 | ||
| 997 | end | ||
| 998 | slice = _accum_0 | ||
| 999 | end | 967 | end |
| 968 | slice = _accum_0 | ||
| 1000 | local slice | 969 | local slice |
| 1001 | do | 970 | local _accum_0 = { } |
| 1002 | local _accum_0 = { } | 971 | local _len_0 = 1 |
| 1003 | local _len_0 = 1 | 972 | local _list_0 = items |
| 1004 | local _list_0 = items | 973 | for _index_0 = 2, #_list_0 do |
| 1005 | for _index_0 = 2, #_list_0 do | 974 | local item = _list_0[_index_0] |
| 1006 | local item = _list_0[_index_0] | 975 | _accum_0[_len_0] = item |
| 1007 | _accum_0[_len_0] = item | 976 | _len_0 = _len_0 + 1 |
| 1008 | _len_0 = _len_0 + 1 | ||
| 1009 | end | ||
| 1010 | slice = _accum_0 | ||
| 1011 | end | 977 | end |
| 978 | slice = _accum_0 | ||
| 1012 | local slice | 979 | local slice |
| 1013 | do | 980 | local _accum_0 = { } |
| 1014 | local _accum_0 = { } | 981 | local _len_0 = 1 |
| 1015 | local _len_0 = 1 | 982 | local _list_0 = items |
| 1016 | local _list_0 = items | 983 | for _index_0 = 1, #_list_0, 2 do |
| 1017 | for _index_0 = 1, #_list_0, 2 do | 984 | local item = _list_0[_index_0] |
| 1018 | local item = _list_0[_index_0] | 985 | _accum_0[_len_0] = item |
| 1019 | _accum_0[_len_0] = item | 986 | _len_0 = _len_0 + 1 |
| 1020 | _len_0 = _len_0 + 1 | ||
| 1021 | end | ||
| 1022 | slice = _accum_0 | ||
| 1023 | end | 987 | end |
| 988 | slice = _accum_0 | ||
| 1024 | for i = 10, 20 do | 989 | for i = 10, 20 do |
| 1025 | print(i) | 990 | print(i) |
| 1026 | end | 991 | end |
| @@ -1030,13 +995,11 @@ end | |||
| 1030 | for key, value in pairs(object) do | 995 | for key, value in pairs(object) do |
| 1031 | print(key, value) | 996 | print(key, value) |
| 1032 | end | 997 | end |
| 1033 | do | 998 | local _list_0 = items |
| 1034 | local _list_0 = items | 999 | local _max_0 = 4 |
| 1035 | local _max_0 = 4 | 1000 | for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do |
| 1036 | for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do | 1001 | local item = _list_0[_index_0] |
| 1037 | local item = _list_0[_index_0] | 1002 | print(item) |
| 1038 | print(item) | ||
| 1039 | end | ||
| 1040 | end | 1003 | end |
| 1041 | local _list_0 = items | 1004 | local _list_0 = items |
| 1042 | for _index_0 = 1, #_list_0 do | 1005 | for _index_0 = 1, #_list_0 do |
| @@ -1047,19 +1010,17 @@ for j = 1, 10, 3 do | |||
| 1047 | print(j) | 1010 | print(j) |
| 1048 | end | 1011 | end |
| 1049 | local doubled_evens | 1012 | local doubled_evens |
| 1050 | do | 1013 | local _accum_0 = { } |
| 1051 | local _accum_0 = { } | 1014 | local _len_0 = 1 |
| 1052 | local _len_0 = 1 | 1015 | for i = 1, 20 do |
| 1053 | for i = 1, 20 do | 1016 | if i % 2 == 0 then |
| 1054 | if i % 2 == 0 then | 1017 | _accum_0[_len_0] = i * 2 |
| 1055 | _accum_0[_len_0] = i * 2 | 1018 | else |
| 1056 | else | 1019 | _accum_0[_len_0] = i |
| 1057 | _accum_0[_len_0] = i | ||
| 1058 | end | ||
| 1059 | _len_0 = _len_0 + 1 | ||
| 1060 | end | 1020 | end |
| 1061 | doubled_evens = _accum_0 | 1021 | _len_0 = _len_0 + 1 |
| 1062 | end | 1022 | end |
| 1023 | doubled_evens = _accum_0 | ||
| 1063 | local func_a | 1024 | local func_a |
| 1064 | func_a = function() | 1025 | func_a = function() |
| 1065 | for i = 1, 10 do | 1026 | for i = 1, 10 do |
| @@ -1117,20 +1078,18 @@ local my_numbers = { | |||
| 1117 | 6 | 1078 | 6 |
| 1118 | } | 1079 | } |
| 1119 | local odds | 1080 | local odds |
| 1120 | do | 1081 | local _accum_0 = { } |
| 1121 | local _accum_0 = { } | 1082 | local _len_0 = 1 |
| 1122 | local _len_0 = 1 | 1083 | for _index_0 = 1, #my_numbers do |
| 1123 | for _index_0 = 1, #my_numbers do | 1084 | local x = my_numbers[_index_0] |
| 1124 | local x = my_numbers[_index_0] | 1085 | if x % 2 == 1 then |
| 1125 | if x % 2 == 1 then | 1086 | goto _continue_0 |
| 1126 | goto _continue_0 | ||
| 1127 | end | ||
| 1128 | _accum_0[_len_0] = x | ||
| 1129 | _len_0 = _len_0 + 1 | ||
| 1130 | ::_continue_0:: | ||
| 1131 | end | 1087 | end |
| 1132 | odds = _accum_0 | 1088 | _accum_0[_len_0] = x |
| 1089 | _len_0 = _len_0 + 1 | ||
| 1090 | ::_continue_0:: | ||
| 1133 | end | 1091 | end |
| 1092 | odds = _accum_0 | ||
| 1134 | local have_coins = false | 1093 | local have_coins = false |
| 1135 | if have_coins then | 1094 | if have_coins then |
| 1136 | print("有硬币") | 1095 | print("有硬币") |
| @@ -1222,15 +1181,13 @@ else | |||
| 1222 | next_number = error("数字数得太大了!") | 1181 | next_number = error("数字数得太大了!") |
| 1223 | end | 1182 | end |
| 1224 | local msg | 1183 | local msg |
| 1225 | do | 1184 | local _exp_0 = math.random(1, 5) |
| 1226 | local _exp_0 = math.random(1, 5) | 1185 | if 1 == _exp_0 then |
| 1227 | if 1 == _exp_0 then | 1186 | msg = "你很幸运" |
| 1228 | msg = "你很幸运" | 1187 | elseif 2 == _exp_0 then |
| 1229 | elseif 2 == _exp_0 then | 1188 | msg = "你差点很幸运" |
| 1230 | msg = "你差点很幸运" | 1189 | else |
| 1231 | else | 1190 | msg = "不太幸运" |
| 1232 | msg = "不太幸运" | ||
| 1233 | end | ||
| 1234 | end | 1191 | end |
| 1235 | do | 1192 | do |
| 1236 | local _exp_0 = math.random(1, 5) | 1193 | local _exp_0 = math.random(1, 5) |
| @@ -1240,13 +1197,11 @@ do | |||
| 1240 | print("不太幸运") | 1197 | print("不太幸运") |
| 1241 | end | 1198 | end |
| 1242 | end | 1199 | end |
| 1243 | do | 1200 | local _exp_0 = math.random(1, 5) |
| 1244 | local _exp_0 = math.random(1, 5) | 1201 | if 1 == _exp_0 then |
| 1245 | if 1 == _exp_0 then | 1202 | print("你很幸运") |
| 1246 | print("你很幸运") | 1203 | else |
| 1247 | else | 1204 | print("不太幸运") |
| 1248 | print("不太幸运") | ||
| 1249 | end | ||
| 1250 | end | 1205 | end |
| 1251 | local items = { | 1206 | local items = { |
| 1252 | { | 1207 | { |
| @@ -1260,25 +1215,23 @@ local items = { | |||
| 1260 | } | 1215 | } |
| 1261 | for _index_0 = 1, #items do | 1216 | for _index_0 = 1, #items do |
| 1262 | local item = items[_index_0] | 1217 | local item = items[_index_0] |
| 1263 | do | 1218 | local _type_0 = type(item) |
| 1264 | local _type_0 = type(item) | 1219 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 |
| 1265 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | 1220 | local _match_0 = false |
| 1266 | local _match_0 = false | 1221 | if _tab_0 then |
| 1267 | if _tab_0 then | 1222 | local x = item.x |
| 1268 | local x = item.x | 1223 | local y = item.y |
| 1269 | local y = item.y | 1224 | if x ~= nil and y ~= nil then |
| 1270 | if x ~= nil and y ~= nil then | 1225 | _match_0 = true |
| 1271 | _match_0 = true | 1226 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) |
| 1272 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) | ||
| 1273 | end | ||
| 1274 | end | 1227 | end |
| 1275 | if not _match_0 then | 1228 | end |
| 1276 | if _tab_0 then | 1229 | if not _match_0 then |
| 1277 | local width = item.width | 1230 | if _tab_0 then |
| 1278 | local height = item.height | 1231 | local width = item.width |
| 1279 | if width ~= nil and height ~= nil then | 1232 | local height = item.height |
| 1280 | print("尺寸 " .. tostring(width) .. ", " .. tostring(height)) | 1233 | if width ~= nil and height ~= nil then |
| 1281 | end | 1234 | print("尺寸 " .. tostring(width) .. ", " .. tostring(height)) |
| 1282 | end | 1235 | end |
| 1283 | end | 1236 | end |
| 1284 | end | 1237 | end |
| @@ -1291,66 +1244,62 @@ end | |||
| 1291 | if y == nil then | 1244 | if y == nil then |
| 1292 | y = 200 | 1245 | y = 200 |
| 1293 | end | 1246 | end |
| 1294 | do | 1247 | local _type_0 = type(item) |
| 1295 | local _type_0 = type(item) | 1248 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 |
| 1296 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | 1249 | if _tab_0 then |
| 1297 | if _tab_0 then | 1250 | do |
| 1298 | do | 1251 | local _obj_0 = item.pos |
| 1299 | local _obj_0 = item.pos | 1252 | local _type_1 = type(_obj_0) |
| 1300 | local _type_1 = type(_obj_0) | 1253 | if "table" == _type_1 or "userdata" == _type_1 then |
| 1301 | if "table" == _type_1 or "userdata" == _type_1 then | 1254 | x = _obj_0.x |
| 1302 | x = _obj_0.x | ||
| 1303 | end | ||
| 1304 | end | ||
| 1305 | do | ||
| 1306 | local _obj_0 = item.pos | ||
| 1307 | local _type_1 = type(_obj_0) | ||
| 1308 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 1309 | y = _obj_0.y | ||
| 1310 | end | ||
| 1311 | end | ||
| 1312 | if x == nil then | ||
| 1313 | x = 50 | ||
| 1314 | end | 1255 | end |
| 1315 | if y == nil then | 1256 | end |
| 1316 | y = 200 | 1257 | do |
| 1258 | local _obj_0 = item.pos | ||
| 1259 | local _type_1 = type(_obj_0) | ||
| 1260 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 1261 | y = _obj_0.y | ||
| 1317 | end | 1262 | end |
| 1318 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) | ||
| 1319 | end | 1263 | end |
| 1264 | if x == nil then | ||
| 1265 | x = 50 | ||
| 1266 | end | ||
| 1267 | if y == nil then | ||
| 1268 | y = 200 | ||
| 1269 | end | ||
| 1270 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) | ||
| 1320 | end | 1271 | end |
| 1321 | local Inventory | 1272 | local Inventory |
| 1322 | do | 1273 | local _class_0 |
| 1323 | local _class_0 | 1274 | local _base_0 = { |
| 1324 | local _base_0 = { | 1275 | add_item = function(self, name) |
| 1325 | add_item = function(self, name) | 1276 | if self.items[name] then |
| 1326 | if self.items[name] then | 1277 | local _obj_0 = self.items |
| 1327 | local _obj_0 = self.items | 1278 | _obj_0[name] = _obj_0[name] + 1 |
| 1328 | _obj_0[name] = _obj_0[name] + 1 | 1279 | else |
| 1329 | else | 1280 | self.items[name] = 1 |
| 1330 | self.items[name] = 1 | ||
| 1331 | end | ||
| 1332 | end | 1281 | end |
| 1333 | } | ||
| 1334 | if _base_0.__index == nil then | ||
| 1335 | _base_0.__index = _base_0 | ||
| 1336 | end | 1282 | end |
| 1337 | _class_0 = setmetatable({ | 1283 | } |
| 1338 | __init = function(self) | 1284 | if _base_0.__index == nil then |
| 1339 | self.items = { } | 1285 | _base_0.__index = _base_0 |
| 1340 | end, | ||
| 1341 | __base = _base_0, | ||
| 1342 | __name = "Inventory" | ||
| 1343 | }, { | ||
| 1344 | __index = _base_0, | ||
| 1345 | __call = function(cls, ...) | ||
| 1346 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1347 | cls.__init(_self_0, ...) | ||
| 1348 | return _self_0 | ||
| 1349 | end | ||
| 1350 | }) | ||
| 1351 | _base_0.__class = _class_0 | ||
| 1352 | Inventory = _class_0 | ||
| 1353 | end | 1286 | end |
| 1287 | _class_0 = setmetatable({ | ||
| 1288 | __init = function(self) | ||
| 1289 | self.items = { } | ||
| 1290 | end, | ||
| 1291 | __base = _base_0, | ||
| 1292 | __name = "Inventory" | ||
| 1293 | }, { | ||
| 1294 | __index = _base_0, | ||
| 1295 | __call = function(cls, ...) | ||
| 1296 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1297 | cls.__init(_self_0, ...) | ||
| 1298 | return _self_0 | ||
| 1299 | end | ||
| 1300 | }) | ||
| 1301 | _base_0.__class = _class_0 | ||
| 1302 | Inventory = _class_0 | ||
| 1354 | local inv = Inventory() | 1303 | local inv = Inventory() |
| 1355 | inv:add_item("t-shirt") | 1304 | inv:add_item("t-shirt") |
| 1356 | inv:add_item("pants") | 1305 | inv:add_item("pants") |
| @@ -1391,82 +1340,78 @@ for _index_0 = 1, #_list_0 do | |||
| 1391 | print(item) | 1340 | print(item) |
| 1392 | end | 1341 | end |
| 1393 | local Person | 1342 | local Person |
| 1394 | do | 1343 | local _class_0 |
| 1395 | local _class_0 | 1344 | local _base_0 = { } |
| 1396 | local _base_0 = { } | 1345 | if _base_0.__index == nil then |
| 1397 | if _base_0.__index == nil then | 1346 | _base_0.__index = _base_0 |
| 1398 | _base_0.__index = _base_0 | 1347 | end |
| 1348 | _class_0 = setmetatable({ | ||
| 1349 | __init = function(self) | ||
| 1350 | self.clothes = { } | ||
| 1351 | end, | ||
| 1352 | __base = _base_0, | ||
| 1353 | __name = "Person" | ||
| 1354 | }, { | ||
| 1355 | __index = _base_0, | ||
| 1356 | __call = function(cls, ...) | ||
| 1357 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1358 | cls.__init(_self_0, ...) | ||
| 1359 | return _self_0 | ||
| 1399 | end | 1360 | end |
| 1400 | _class_0 = setmetatable({ | 1361 | }) |
| 1401 | __init = function(self) | 1362 | _base_0.__class = _class_0 |
| 1402 | self.clothes = { } | 1363 | Person = _class_0 |
| 1403 | end, | ||
| 1404 | __base = _base_0, | ||
| 1405 | __name = "Person" | ||
| 1406 | }, { | ||
| 1407 | __index = _base_0, | ||
| 1408 | __call = function(cls, ...) | ||
| 1409 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1410 | cls.__init(_self_0, ...) | ||
| 1411 | return _self_0 | ||
| 1412 | end | ||
| 1413 | }) | ||
| 1414 | _base_0.__class = _class_0 | ||
| 1415 | Person = _class_0 | ||
| 1416 | end | ||
| 1417 | local BackPack | 1364 | local BackPack |
| 1418 | do | 1365 | local _class_0 |
| 1419 | local _class_0 | 1366 | local _parent_0 = Inventory |
| 1420 | local _parent_0 = Inventory | 1367 | local _base_0 = { |
| 1421 | local _base_0 = { | 1368 | size = 10, |
| 1422 | size = 10, | 1369 | add_item = function(self, name) |
| 1423 | add_item = function(self, name) | 1370 | if #self.items > size then |
| 1424 | if #self.items > size then | 1371 | error("背包已满") |
| 1425 | error("背包已满") | ||
| 1426 | end | ||
| 1427 | return _class_0.__parent.__base.add_item(self, name) | ||
| 1428 | end | ||
| 1429 | } | ||
| 1430 | for _key_0, _val_0 in pairs(_parent_0.__base) do | ||
| 1431 | if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then | ||
| 1432 | _base_0[_key_0] = _val_0 | ||
| 1433 | end | 1372 | end |
| 1373 | return _class_0.__parent.__base.add_item(self, name) | ||
| 1434 | end | 1374 | end |
| 1435 | if _base_0.__index == nil then | 1375 | } |
| 1436 | _base_0.__index = _base_0 | 1376 | for _key_0, _val_0 in pairs(_parent_0.__base) do |
| 1377 | if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then | ||
| 1378 | _base_0[_key_0] = _val_0 | ||
| 1437 | end | 1379 | end |
| 1438 | setmetatable(_base_0, _parent_0.__base) | 1380 | end |
| 1439 | _class_0 = setmetatable({ | 1381 | if _base_0.__index == nil then |
| 1440 | __init = function(self, ...) | 1382 | _base_0.__index = _base_0 |
| 1441 | return _class_0.__parent.__init(self, ...) | 1383 | end |
| 1442 | end, | 1384 | setmetatable(_base_0, _parent_0.__base) |
| 1443 | __base = _base_0, | 1385 | _class_0 = setmetatable({ |
| 1444 | __name = "BackPack", | 1386 | __init = function(self, ...) |
| 1445 | __parent = _parent_0 | 1387 | return _class_0.__parent.__init(self, ...) |
| 1446 | }, { | 1388 | end, |
| 1447 | __index = function(cls, name) | 1389 | __base = _base_0, |
| 1448 | local val = rawget(_base_0, name) | 1390 | __name = "BackPack", |
| 1449 | if val == nil then | 1391 | __parent = _parent_0 |
| 1450 | local parent = rawget(cls, "__parent") | 1392 | }, { |
| 1451 | if parent then | 1393 | __index = function(cls, name) |
| 1452 | return parent[name] | 1394 | local val = rawget(_base_0, name) |
| 1453 | end | 1395 | if val == nil then |
| 1454 | else | 1396 | local parent = rawget(cls, "__parent") |
| 1455 | return val | 1397 | if parent then |
| 1398 | return parent[name] | ||
| 1456 | end | 1399 | end |
| 1457 | end, | 1400 | else |
| 1458 | __call = function(cls, ...) | 1401 | return val |
| 1459 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1460 | cls.__init(_self_0, ...) | ||
| 1461 | return _self_0 | ||
| 1462 | end | 1402 | end |
| 1463 | }) | 1403 | end, |
| 1464 | _base_0.__class = _class_0 | 1404 | __call = function(cls, ...) |
| 1465 | if _parent_0.__inherited then | 1405 | local _self_0 = setmetatable({ }, _base_0) |
| 1466 | _parent_0.__inherited(_parent_0, _class_0) | 1406 | cls.__init(_self_0, ...) |
| 1407 | return _self_0 | ||
| 1467 | end | 1408 | end |
| 1468 | BackPack = _class_0 | 1409 | }) |
| 1410 | _base_0.__class = _class_0 | ||
| 1411 | if _parent_0.__inherited then | ||
| 1412 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 1469 | end | 1413 | end |
| 1414 | BackPack = _class_0 | ||
| 1470 | local Shelf | 1415 | local Shelf |
| 1471 | do | 1416 | do |
| 1472 | local _class_0 | 1417 | local _class_0 |
| @@ -1494,102 +1439,98 @@ do | |||
| 1494 | Shelf = _class_0 | 1439 | Shelf = _class_0 |
| 1495 | end | 1440 | end |
| 1496 | local Cupboard | 1441 | local Cupboard |
| 1497 | do | 1442 | local _class_0 |
| 1498 | local _class_0 | 1443 | local _parent_0 = Shelf |
| 1499 | local _parent_0 = Shelf | 1444 | local _base_0 = { } |
| 1500 | local _base_0 = { } | 1445 | for _key_0, _val_0 in pairs(_parent_0.__base) do |
| 1501 | for _key_0, _val_0 in pairs(_parent_0.__base) do | 1446 | if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then |
| 1502 | if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then | 1447 | _base_0[_key_0] = _val_0 |
| 1503 | _base_0[_key_0] = _val_0 | 1448 | end |
| 1504 | end | 1449 | end |
| 1505 | end | 1450 | if _base_0.__index == nil then |
| 1506 | if _base_0.__index == nil then | 1451 | _base_0.__index = _base_0 |
| 1507 | _base_0.__index = _base_0 | 1452 | end |
| 1508 | end | 1453 | setmetatable(_base_0, _parent_0.__base) |
| 1509 | setmetatable(_base_0, _parent_0.__base) | 1454 | _class_0 = setmetatable({ |
| 1510 | _class_0 = setmetatable({ | 1455 | __init = function(self, ...) |
| 1511 | __init = function(self, ...) | 1456 | return _class_0.__parent.__init(self, ...) |
| 1512 | return _class_0.__parent.__init(self, ...) | 1457 | end, |
| 1513 | end, | 1458 | __base = _base_0, |
| 1514 | __base = _base_0, | 1459 | __name = "Cupboard", |
| 1515 | __name = "Cupboard", | 1460 | __parent = _parent_0 |
| 1516 | __parent = _parent_0 | 1461 | }, { |
| 1517 | }, { | 1462 | __index = function(cls, name) |
| 1518 | __index = function(cls, name) | 1463 | local val = rawget(_base_0, name) |
| 1519 | local val = rawget(_base_0, name) | 1464 | if val == nil then |
| 1520 | if val == nil then | 1465 | local parent = rawget(cls, "__parent") |
| 1521 | local parent = rawget(cls, "__parent") | 1466 | if parent then |
| 1522 | if parent then | 1467 | return parent[name] |
| 1523 | return parent[name] | ||
| 1524 | end | ||
| 1525 | else | ||
| 1526 | return val | ||
| 1527 | end | 1468 | end |
| 1528 | end, | 1469 | else |
| 1529 | __call = function(cls, ...) | 1470 | return val |
| 1530 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1531 | cls.__init(_self_0, ...) | ||
| 1532 | return _self_0 | ||
| 1533 | end | 1471 | end |
| 1534 | }) | 1472 | end, |
| 1535 | _base_0.__class = _class_0 | 1473 | __call = function(cls, ...) |
| 1536 | if _parent_0.__inherited then | 1474 | local _self_0 = setmetatable({ }, _base_0) |
| 1537 | _parent_0.__inherited(_parent_0, _class_0) | 1475 | cls.__init(_self_0, ...) |
| 1476 | return _self_0 | ||
| 1538 | end | 1477 | end |
| 1539 | Cupboard = _class_0 | 1478 | }) |
| 1479 | _base_0.__class = _class_0 | ||
| 1480 | if _parent_0.__inherited then | ||
| 1481 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 1540 | end | 1482 | end |
| 1483 | Cupboard = _class_0 | ||
| 1541 | local MyClass | 1484 | local MyClass |
| 1542 | do | 1485 | local _class_0 |
| 1543 | local _class_0 | 1486 | local _parent_0 = ParentClass |
| 1544 | local _parent_0 = ParentClass | 1487 | local _base_0 = { |
| 1545 | local _base_0 = { | 1488 | a_method = function(self) |
| 1546 | a_method = function(self) | 1489 | _class_0.__parent.__base.a_method(self, "你好", "世界") |
| 1547 | _class_0.__parent.__base.a_method(self, "你好", "世界") | 1490 | _class_0.__parent.a_method(self, "你好", "世界") |
| 1548 | _class_0.__parent.a_method(self, "你好", "世界") | 1491 | _class_0.__parent.a_method(self, "你好", "世界") |
| 1549 | _class_0.__parent.a_method(self, "你好", "世界") | 1492 | return assert(_class_0.__parent == ParentClass) |
| 1550 | return assert(_class_0.__parent == ParentClass) | 1493 | end |
| 1551 | end | 1494 | } |
| 1552 | } | 1495 | for _key_0, _val_0 in pairs(_parent_0.__base) do |
| 1553 | for _key_0, _val_0 in pairs(_parent_0.__base) do | 1496 | if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then |
| 1554 | if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then | 1497 | _base_0[_key_0] = _val_0 |
| 1555 | _base_0[_key_0] = _val_0 | 1498 | end |
| 1556 | end | 1499 | end |
| 1557 | end | 1500 | if _base_0.__index == nil then |
| 1558 | if _base_0.__index == nil then | 1501 | _base_0.__index = _base_0 |
| 1559 | _base_0.__index = _base_0 | 1502 | end |
| 1560 | end | 1503 | setmetatable(_base_0, _parent_0.__base) |
| 1561 | setmetatable(_base_0, _parent_0.__base) | 1504 | _class_0 = setmetatable({ |
| 1562 | _class_0 = setmetatable({ | 1505 | __init = function(self, ...) |
| 1563 | __init = function(self, ...) | 1506 | return _class_0.__parent.__init(self, ...) |
| 1564 | return _class_0.__parent.__init(self, ...) | 1507 | end, |
| 1565 | end, | 1508 | __base = _base_0, |
| 1566 | __base = _base_0, | 1509 | __name = "MyClass", |
| 1567 | __name = "MyClass", | 1510 | __parent = _parent_0 |
| 1568 | __parent = _parent_0 | 1511 | }, { |
| 1569 | }, { | 1512 | __index = function(cls, name) |
| 1570 | __index = function(cls, name) | 1513 | local val = rawget(_base_0, name) |
| 1571 | local val = rawget(_base_0, name) | 1514 | if val == nil then |
| 1572 | if val == nil then | 1515 | local parent = rawget(cls, "__parent") |
| 1573 | local parent = rawget(cls, "__parent") | 1516 | if parent then |
| 1574 | if parent then | 1517 | return parent[name] |
| 1575 | return parent[name] | ||
| 1576 | end | ||
| 1577 | else | ||
| 1578 | return val | ||
| 1579 | end | 1518 | end |
| 1580 | end, | 1519 | else |
| 1581 | __call = function(cls, ...) | 1520 | return val |
| 1582 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1583 | cls.__init(_self_0, ...) | ||
| 1584 | return _self_0 | ||
| 1585 | end | 1521 | end |
| 1586 | }) | 1522 | end, |
| 1587 | _base_0.__class = _class_0 | 1523 | __call = function(cls, ...) |
| 1588 | if _parent_0.__inherited then | 1524 | local _self_0 = setmetatable({ }, _base_0) |
| 1589 | _parent_0.__inherited(_parent_0, _class_0) | 1525 | cls.__init(_self_0, ...) |
| 1526 | return _self_0 | ||
| 1590 | end | 1527 | end |
| 1591 | MyClass = _class_0 | 1528 | }) |
| 1529 | _base_0.__class = _class_0 | ||
| 1530 | if _parent_0.__inherited then | ||
| 1531 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 1592 | end | 1532 | end |
| 1533 | MyClass = _class_0 | ||
| 1593 | local b = BackPack() | 1534 | local b = BackPack() |
| 1594 | assert(b.__class == BackPack) | 1535 | assert(b.__class == BackPack) |
| 1595 | print(BackPack.size) | 1536 | print(BackPack.size) |
| @@ -1653,61 +1594,57 @@ Counter() | |||
| 1653 | print(Counter.count) | 1594 | print(Counter.count) |
| 1654 | self.__class:hello(1, 2, 3, 4) | 1595 | self.__class:hello(1, 2, 3, 4) |
| 1655 | local Things | 1596 | local Things |
| 1656 | do | 1597 | local _class_0 |
| 1657 | local _class_0 | 1598 | local _base_0 = { } |
| 1658 | local _base_0 = { } | 1599 | if _base_0.__index == nil then |
| 1659 | if _base_0.__index == nil then | 1600 | _base_0.__index = _base_0 |
| 1660 | _base_0.__index = _base_0 | 1601 | end |
| 1602 | _class_0 = setmetatable({ | ||
| 1603 | __init = function() end, | ||
| 1604 | __base = _base_0, | ||
| 1605 | __name = "Things" | ||
| 1606 | }, { | ||
| 1607 | __index = _base_0, | ||
| 1608 | __call = function(cls, ...) | ||
| 1609 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1610 | cls.__init(_self_0, ...) | ||
| 1611 | return _self_0 | ||
| 1661 | end | 1612 | end |
| 1662 | _class_0 = setmetatable({ | 1613 | }) |
| 1663 | __init = function() end, | 1614 | _base_0.__class = _class_0 |
| 1664 | __base = _base_0, | 1615 | local self = _class_0; |
| 1665 | __name = "Things" | 1616 | self.class_var = "hello world" |
| 1666 | }, { | 1617 | Things = _class_0 |
| 1667 | __index = _base_0, | ||
| 1668 | __call = function(cls, ...) | ||
| 1669 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1670 | cls.__init(_self_0, ...) | ||
| 1671 | return _self_0 | ||
| 1672 | end | ||
| 1673 | }) | ||
| 1674 | _base_0.__class = _class_0 | ||
| 1675 | local self = _class_0; | ||
| 1676 | self.class_var = "hello world" | ||
| 1677 | Things = _class_0 | ||
| 1678 | end | ||
| 1679 | local MoreThings | 1618 | local MoreThings |
| 1680 | do | 1619 | local _class_0 |
| 1681 | local _class_0 | 1620 | local secret, log |
| 1682 | local secret, log | 1621 | local _base_0 = { |
| 1683 | local _base_0 = { | 1622 | some_method = function(self) |
| 1684 | some_method = function(self) | 1623 | return log("hello world: " .. secret) |
| 1685 | return log("hello world: " .. secret) | ||
| 1686 | end | ||
| 1687 | } | ||
| 1688 | if _base_0.__index == nil then | ||
| 1689 | _base_0.__index = _base_0 | ||
| 1690 | end | 1624 | end |
| 1691 | _class_0 = setmetatable({ | 1625 | } |
| 1692 | __init = function() end, | 1626 | if _base_0.__index == nil then |
| 1693 | __base = _base_0, | 1627 | _base_0.__index = _base_0 |
| 1694 | __name = "MoreThings" | 1628 | end |
| 1695 | }, { | 1629 | _class_0 = setmetatable({ |
| 1696 | __index = _base_0, | 1630 | __init = function() end, |
| 1697 | __call = function(cls, ...) | 1631 | __base = _base_0, |
| 1698 | local _self_0 = setmetatable({ }, _base_0) | 1632 | __name = "MoreThings" |
| 1699 | cls.__init(_self_0, ...) | 1633 | }, { |
| 1700 | return _self_0 | 1634 | __index = _base_0, |
| 1701 | end | 1635 | __call = function(cls, ...) |
| 1702 | }) | 1636 | local _self_0 = setmetatable({ }, _base_0) |
| 1703 | _base_0.__class = _class_0 | 1637 | cls.__init(_self_0, ...) |
| 1704 | local self = _class_0; | 1638 | return _self_0 |
| 1705 | secret = 123 | ||
| 1706 | log = function(msg) | ||
| 1707 | return print("LOG:", msg) | ||
| 1708 | end | 1639 | end |
| 1709 | MoreThings = _class_0 | 1640 | }) |
| 1641 | _base_0.__class = _class_0 | ||
| 1642 | local self = _class_0; | ||
| 1643 | secret = 123 | ||
| 1644 | log = function(msg) | ||
| 1645 | return print("LOG:", msg) | ||
| 1710 | end | 1646 | end |
| 1647 | MoreThings = _class_0 | ||
| 1711 | assert(self == self) | 1648 | assert(self == self) |
| 1712 | assert(self.__class == self.__class) | 1649 | assert(self.__class == self.__class) |
| 1713 | local some_instance_method | 1650 | local some_instance_method |
| @@ -1741,32 +1678,30 @@ do | |||
| 1741 | _base_0.__class = _class_0 | 1678 | _base_0.__class = _class_0 |
| 1742 | Something = _class_0 | 1679 | Something = _class_0 |
| 1743 | end | 1680 | end |
| 1744 | do | 1681 | local _class_0 |
| 1745 | local _class_0 | 1682 | local _base_0 = { } |
| 1746 | local _base_0 = { } | 1683 | if _base_0.__index == nil then |
| 1747 | if _base_0.__index == nil then | 1684 | _base_0.__index = _base_0 |
| 1748 | _base_0.__index = _base_0 | 1685 | end |
| 1686 | _class_0 = setmetatable({ | ||
| 1687 | __init = function(self, foo, bar, biz, baz) | ||
| 1688 | self.foo = foo | ||
| 1689 | self.bar = bar | ||
| 1690 | self.__class.biz = biz | ||
| 1691 | self.__class.baz = baz | ||
| 1692 | end, | ||
| 1693 | __base = _base_0, | ||
| 1694 | __name = "Something" | ||
| 1695 | }, { | ||
| 1696 | __index = _base_0, | ||
| 1697 | __call = function(cls, ...) | ||
| 1698 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1699 | cls.__init(_self_0, ...) | ||
| 1700 | return _self_0 | ||
| 1749 | end | 1701 | end |
| 1750 | _class_0 = setmetatable({ | 1702 | }) |
| 1751 | __init = function(self, foo, bar, biz, baz) | 1703 | _base_0.__class = _class_0 |
| 1752 | self.foo = foo | 1704 | Something = _class_0 |
| 1753 | self.bar = bar | ||
| 1754 | self.__class.biz = biz | ||
| 1755 | self.__class.baz = baz | ||
| 1756 | end, | ||
| 1757 | __base = _base_0, | ||
| 1758 | __name = "Something" | ||
| 1759 | }, { | ||
| 1760 | __index = _base_0, | ||
| 1761 | __call = function(cls, ...) | ||
| 1762 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1763 | cls.__init(_self_0, ...) | ||
| 1764 | return _self_0 | ||
| 1765 | end | ||
| 1766 | }) | ||
| 1767 | _base_0.__class = _class_0 | ||
| 1768 | Something = _class_0 | ||
| 1769 | end | ||
| 1770 | local new | 1705 | local new |
| 1771 | new = function(self, fieldA, fieldB) | 1706 | new = function(self, fieldA, fieldB) |
| 1772 | self.fieldA = fieldA | 1707 | self.fieldA = fieldA |
| @@ -1777,33 +1712,31 @@ local obj = new({ }, 123, "abc") | |||
| 1777 | print(obj) | 1712 | print(obj) |
| 1778 | local x | 1713 | local x |
| 1779 | local Bucket | 1714 | local Bucket |
| 1780 | do | 1715 | local _class_0 |
| 1781 | local _class_0 | 1716 | local _base_0 = { |
| 1782 | local _base_0 = { | 1717 | drops = 0, |
| 1783 | drops = 0, | 1718 | add_drop = function(self) |
| 1784 | add_drop = function(self) | 1719 | self.drops = self.drops + 1 |
| 1785 | self.drops = self.drops + 1 | ||
| 1786 | end | ||
| 1787 | } | ||
| 1788 | if _base_0.__index == nil then | ||
| 1789 | _base_0.__index = _base_0 | ||
| 1790 | end | 1720 | end |
| 1791 | _class_0 = setmetatable({ | 1721 | } |
| 1792 | __init = function() end, | 1722 | if _base_0.__index == nil then |
| 1793 | __base = _base_0, | 1723 | _base_0.__index = _base_0 |
| 1794 | __name = "Bucket" | ||
| 1795 | }, { | ||
| 1796 | __index = _base_0, | ||
| 1797 | __call = function(cls, ...) | ||
| 1798 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1799 | cls.__init(_self_0, ...) | ||
| 1800 | return _self_0 | ||
| 1801 | end | ||
| 1802 | }) | ||
| 1803 | _base_0.__class = _class_0 | ||
| 1804 | Bucket = _class_0 | ||
| 1805 | x = _class_0 | ||
| 1806 | end | 1724 | end |
| 1725 | _class_0 = setmetatable({ | ||
| 1726 | __init = function() end, | ||
| 1727 | __base = _base_0, | ||
| 1728 | __name = "Bucket" | ||
| 1729 | }, { | ||
| 1730 | __index = _base_0, | ||
| 1731 | __call = function(cls, ...) | ||
| 1732 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1733 | cls.__init(_self_0, ...) | ||
| 1734 | return _self_0 | ||
| 1735 | end | ||
| 1736 | }) | ||
| 1737 | _base_0.__class = _class_0 | ||
| 1738 | Bucket = _class_0 | ||
| 1739 | x = _class_0 | ||
| 1807 | local BigBucket | 1740 | local BigBucket |
| 1808 | do | 1741 | do |
| 1809 | local _class_0 | 1742 | local _class_0 |
| @@ -1855,27 +1788,25 @@ do | |||
| 1855 | end | 1788 | end |
| 1856 | assert(Bucket.__name == "BigBucket") | 1789 | assert(Bucket.__name == "BigBucket") |
| 1857 | local x | 1790 | local x |
| 1858 | do | 1791 | local _class_0 |
| 1859 | local _class_0 | 1792 | local _base_0 = { } |
| 1860 | local _base_0 = { } | 1793 | if _base_0.__index == nil then |
| 1861 | if _base_0.__index == nil then | 1794 | _base_0.__index = _base_0 |
| 1862 | _base_0.__index = _base_0 | 1795 | end |
| 1796 | _class_0 = setmetatable({ | ||
| 1797 | __init = function() end, | ||
| 1798 | __base = _base_0, | ||
| 1799 | __name = "x" | ||
| 1800 | }, { | ||
| 1801 | __index = _base_0, | ||
| 1802 | __call = function(cls, ...) | ||
| 1803 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1804 | cls.__init(_self_0, ...) | ||
| 1805 | return _self_0 | ||
| 1863 | end | 1806 | end |
| 1864 | _class_0 = setmetatable({ | 1807 | }) |
| 1865 | __init = function() end, | 1808 | _base_0.__class = _class_0 |
| 1866 | __base = _base_0, | 1809 | x = _class_0 |
| 1867 | __name = "x" | ||
| 1868 | }, { | ||
| 1869 | __index = _base_0, | ||
| 1870 | __call = function(cls, ...) | ||
| 1871 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1872 | cls.__init(_self_0, ...) | ||
| 1873 | return _self_0 | ||
| 1874 | end | ||
| 1875 | }) | ||
| 1876 | _base_0.__class = _class_0 | ||
| 1877 | x = _class_0 | ||
| 1878 | end | ||
| 1879 | local MyIndex = { | 1810 | local MyIndex = { |
| 1880 | __index = { | 1811 | __index = { |
| 1881 | var = 1 | 1812 | var = 1 |
| @@ -1958,19 +1889,15 @@ end | |||
| 1958 | local y = Y() | 1889 | local y = Y() |
| 1959 | y:func() | 1890 | y:func() |
| 1960 | assert(y.__class.__parent ~= X) | 1891 | assert(y.__class.__parent ~= X) |
| 1961 | do | 1892 | local _with_0 = Person() |
| 1962 | local _with_0 = Person() | 1893 | _with_0.name = "Oswald" |
| 1963 | _with_0.name = "Oswald" | 1894 | _with_0:add_relative(my_dad) |
| 1964 | _with_0:add_relative(my_dad) | 1895 | _with_0:save() |
| 1965 | _with_0:save() | 1896 | print(_with_0.name) |
| 1966 | print(_with_0.name) | ||
| 1967 | end | ||
| 1968 | local file | 1897 | local file |
| 1969 | do | 1898 | local _with_0 = File("favorite_foods.txt") |
| 1970 | local _with_0 = File("favorite_foods.txt") | 1899 | _with_0:set_encoding("utf8") |
| 1971 | _with_0:set_encoding("utf8") | 1900 | file = _with_0 |
| 1972 | file = _with_0 | ||
| 1973 | end | ||
| 1974 | local create_person | 1901 | local create_person |
| 1975 | create_person = function(name, relatives) | 1902 | create_person = function(name, relatives) |
| 1976 | local _with_0 = Person() | 1903 | local _with_0 = Person() |
| @@ -1986,22 +1913,18 @@ local me = create_person("Leaf", { | |||
| 1986 | mother, | 1913 | mother, |
| 1987 | sister | 1914 | sister |
| 1988 | }) | 1915 | }) |
| 1916 | local str = "你好" | ||
| 1917 | print("原始:", str) | ||
| 1918 | print("大写:", str:upper()) | ||
| 1919 | local _with_0 = tb | ||
| 1920 | _with_0[1] = 1 | ||
| 1921 | print(_with_0[2]) | ||
| 1989 | do | 1922 | do |
| 1990 | local str = "你好" | 1923 | local _with_1 = _with_0[abc] |
| 1991 | print("原始:", str) | 1924 | _with_1[3] = _with_1[2]:func() |
| 1992 | print("大写:", str:upper()) | 1925 | _with_1["key-name"] = value |
| 1993 | end | ||
| 1994 | do | ||
| 1995 | local _with_0 = tb | ||
| 1996 | _with_0[1] = 1 | ||
| 1997 | print(_with_0[2]) | ||
| 1998 | do | ||
| 1999 | local _with_1 = _with_0[abc] | ||
| 2000 | _with_1[3] = _with_1[2]:func() | ||
| 2001 | _with_1["key-name"] = value | ||
| 2002 | end | ||
| 2003 | _with_0[#_with_0 + 1] = "abc" | ||
| 2004 | end | 1926 | end |
| 1927 | _with_0[#_with_0 + 1] = "abc" | ||
| 2005 | do | 1928 | do |
| 2006 | local var = "hello" | 1929 | local var = "hello" |
| 2007 | print(var) | 1930 | print(var) |
| @@ -2118,13 +2041,18 @@ _module_0["🌛"] = _ud83c_udf1b | |||
| 2118 | return _module_0 | 2041 | return _module_0 |
| 2119 | local area = 6.2831853071796 * 5 | 2042 | local area = 6.2831853071796 * 5 |
| 2120 | print('你好 世界') | 2043 | print('你好 世界') |
| 2121 | assert(item ~= nil) | 2044 | do |
| 2045 | assert(item ~= nil) | ||
| 2046 | end | ||
| 2122 | local value = item | 2047 | local value = item |
| 2123 | if (f1() and f2() and f3()) then | 2048 | if (f1() and f2() and f3()) then |
| 2124 | print("OK") | 2049 | print("OK") |
| 2125 | end | 2050 | end |
| 2051 | do | ||
| 2052 | local funcA | ||
| 2053 | funcA = function() end | ||
| 2054 | end | ||
| 2126 | local funcA | 2055 | local funcA |
| 2127 | funcA = function() end | ||
| 2128 | funcA = function() | 2056 | funcA = function() |
| 2129 | return "访问月之脚本定义的变量" | 2057 | return "访问月之脚本定义的变量" |
| 2130 | end | 2058 | end |
| @@ -2218,28 +2146,26 @@ local b = { | |||
| 2218 | y = 1 | 2146 | y = 1 |
| 2219 | } | 2147 | } |
| 2220 | local merge | 2148 | local merge |
| 2221 | do | 2149 | local _tab_0 = { } |
| 2222 | local _tab_0 = { } | 2150 | local _idx_0 = 1 |
| 2223 | local _idx_0 = 1 | 2151 | for _key_0, _value_0 in pairs(a) do |
| 2224 | for _key_0, _value_0 in pairs(a) do | 2152 | if _idx_0 == _key_0 then |
| 2225 | if _idx_0 == _key_0 then | 2153 | _tab_0[#_tab_0 + 1] = _value_0 |
| 2226 | _tab_0[#_tab_0 + 1] = _value_0 | 2154 | _idx_0 = _idx_0 + 1 |
| 2227 | _idx_0 = _idx_0 + 1 | 2155 | else |
| 2228 | else | 2156 | _tab_0[_key_0] = _value_0 |
| 2229 | _tab_0[_key_0] = _value_0 | ||
| 2230 | end | ||
| 2231 | end | 2157 | end |
| 2232 | local _idx_1 = 1 | 2158 | end |
| 2233 | for _key_0, _value_0 in pairs(b) do | 2159 | local _idx_1 = 1 |
| 2234 | if _idx_1 == _key_0 then | 2160 | for _key_0, _value_0 in pairs(b) do |
| 2235 | _tab_0[#_tab_0 + 1] = _value_0 | 2161 | if _idx_1 == _key_0 then |
| 2236 | _idx_1 = _idx_1 + 1 | 2162 | _tab_0[#_tab_0 + 1] = _value_0 |
| 2237 | else | 2163 | _idx_1 = _idx_1 + 1 |
| 2238 | _tab_0[_key_0] = _value_0 | 2164 | else |
| 2239 | end | 2165 | _tab_0[_key_0] = _value_0 |
| 2240 | end | 2166 | end |
| 2241 | merge = _tab_0 | ||
| 2242 | end | 2167 | end |
| 2168 | merge = _tab_0 | ||
| 2243 | local mt = { } | 2169 | local mt = { } |
| 2244 | local add | 2170 | local add |
| 2245 | add = function(self, right) | 2171 | add = function(self, right) |
| @@ -2331,12 +2257,10 @@ end | |||
| 2331 | if print and (x ~= nil) then | 2257 | if print and (x ~= nil) then |
| 2332 | print(x) | 2258 | print(x) |
| 2333 | end | 2259 | end |
| 2334 | do | 2260 | local _with_0 = io.open("test.txt", "w") |
| 2335 | local _with_0 = io.open("test.txt", "w") | 2261 | if _with_0 ~= nil then |
| 2336 | if _with_0 ~= nil then | 2262 | _with_0:write("你好") |
| 2337 | _with_0:write("你好") | 2263 | _with_0:close() |
| 2338 | _with_0:close() | ||
| 2339 | end | ||
| 2340 | end | 2264 | end |
| 2341 | print("你好") | 2265 | print("你好") |
| 2342 | print(1, 2) | 2266 | print(1, 2) |
| @@ -2413,10 +2337,8 @@ do | |||
| 2413 | x, y, z = _obj_0.x, _obj_0.y, _obj_0.z | 2337 | x, y, z = _obj_0.x, _obj_0.y, _obj_0.z |
| 2414 | end | 2338 | end |
| 2415 | local a, b, c | 2339 | local a, b, c |
| 2416 | do | 2340 | local _obj_0 = require('module') |
| 2417 | local _obj_0 = require('module') | 2341 | a, b, c = _obj_0.a, _obj_0.b, _obj_0.c |
| 2418 | a, b, c = _obj_0.a, _obj_0.b, _obj_0.c | ||
| 2419 | end | ||
| 2420 | end | 2342 | end |
| 2421 | do | 2343 | do |
| 2422 | local module = require('module') | 2344 | local module = require('module') |
| @@ -2455,29 +2377,27 @@ y = function() | |||
| 2455 | end | 2377 | end |
| 2456 | _module_0["y"] = y | 2378 | _module_0["y"] = y |
| 2457 | local Something | 2379 | local Something |
| 2458 | do | 2380 | local _class_0 |
| 2459 | local _class_0 | 2381 | local _base_0 = { |
| 2460 | local _base_0 = { | 2382 | umm = "cool" |
| 2461 | umm = "cool" | 2383 | } |
| 2462 | } | 2384 | if _base_0.__index == nil then |
| 2463 | if _base_0.__index == nil then | 2385 | _base_0.__index = _base_0 |
| 2464 | _base_0.__index = _base_0 | ||
| 2465 | end | ||
| 2466 | _class_0 = setmetatable({ | ||
| 2467 | __init = function() end, | ||
| 2468 | __base = _base_0, | ||
| 2469 | __name = "Something" | ||
| 2470 | }, { | ||
| 2471 | __index = _base_0, | ||
| 2472 | __call = function(cls, ...) | ||
| 2473 | local _self_0 = setmetatable({ }, _base_0) | ||
| 2474 | cls.__init(_self_0, ...) | ||
| 2475 | return _self_0 | ||
| 2476 | end | ||
| 2477 | }) | ||
| 2478 | _base_0.__class = _class_0 | ||
| 2479 | Something = _class_0 | ||
| 2480 | end | 2386 | end |
| 2387 | _class_0 = setmetatable({ | ||
| 2388 | __init = function() end, | ||
| 2389 | __base = _base_0, | ||
| 2390 | __name = "Something" | ||
| 2391 | }, { | ||
| 2392 | __index = _base_0, | ||
| 2393 | __call = function(cls, ...) | ||
| 2394 | local _self_0 = setmetatable({ }, _base_0) | ||
| 2395 | cls.__init(_self_0, ...) | ||
| 2396 | return _self_0 | ||
| 2397 | end | ||
| 2398 | }) | ||
| 2399 | _base_0.__class = _class_0 | ||
| 2400 | Something = _class_0 | ||
| 2481 | _module_0["Something"] = Something | 2401 | _module_0["Something"] = Something |
| 2482 | return _module_0 | 2402 | return _module_0 |
| 2483 | local _module_0 = { } | 2403 | local _module_0 = { } |
| @@ -2508,11 +2428,9 @@ if this then | |||
| 2508 | else | 2428 | else |
| 2509 | _module_0[#_module_0 + 1] = 456 | 2429 | _module_0[#_module_0 + 1] = 456 |
| 2510 | end | 2430 | end |
| 2511 | do | 2431 | local _with_0 = tmp |
| 2512 | local _with_0 = tmp | 2432 | local j = 2000 |
| 2513 | local j = 2000 | 2433 | _module_0[#_module_0 + 1] = _with_0 |
| 2514 | _module_0[#_module_0 + 1] = _with_0 | ||
| 2515 | end | ||
| 2516 | return _module_0 | 2434 | return _module_0 |
| 2517 | local _module_0 = nil | 2435 | local _module_0 = nil |
| 2518 | _module_0 = function() | 2436 | _module_0 = function() |
| @@ -2649,25 +2567,19 @@ for _index_0 = 1, #tuples do | |||
| 2649 | local left, right = _des_0[1], _des_0[2] | 2567 | local left, right = _des_0[1], _des_0[2] |
| 2650 | print(left, right) | 2568 | print(left, right) |
| 2651 | end | 2569 | end |
| 2652 | do | 2570 | local user = database.find_user("moon") |
| 2653 | local user = database.find_user("moon") | 2571 | if user then |
| 2654 | if user then | 2572 | print(user.name) |
| 2655 | print(user.name) | ||
| 2656 | end | ||
| 2657 | end | 2573 | end |
| 2658 | do | 2574 | local hello = os.getenv("hello") |
| 2659 | local hello = os.getenv("hello") | 2575 | if hello then |
| 2660 | if hello then | 2576 | print("你有 hello", hello) |
| 2661 | print("你有 hello", hello) | 2577 | else |
| 2578 | local world = os.getenv("world") | ||
| 2579 | if world then | ||
| 2580 | print("你有 world", world) | ||
| 2662 | else | 2581 | else |
| 2663 | do | 2582 | print("什么都没有 :(") |
| 2664 | local world = os.getenv("world") | ||
| 2665 | if world then | ||
| 2666 | print("你有 world", world) | ||
| 2667 | else | ||
| 2668 | print("什么都没有 :(") | ||
| 2669 | end | ||
| 2670 | end | ||
| 2671 | end | 2583 | end |
| 2672 | end | 2584 | end |
| 2673 | do | 2585 | do |
| @@ -2924,40 +2836,34 @@ local items = { | |||
| 2924 | 4 | 2836 | 4 |
| 2925 | } | 2837 | } |
| 2926 | local doubled | 2838 | local doubled |
| 2927 | do | 2839 | local _accum_0 = { } |
| 2928 | local _accum_0 = { } | 2840 | local _len_0 = 1 |
| 2929 | local _len_0 = 1 | 2841 | for i, item in ipairs(items) do |
| 2930 | for i, item in ipairs(items) do | 2842 | _accum_0[_len_0] = item * 2 |
| 2931 | _accum_0[_len_0] = item * 2 | 2843 | _len_0 = _len_0 + 1 |
| 2932 | _len_0 = _len_0 + 1 | ||
| 2933 | end | ||
| 2934 | doubled = _accum_0 | ||
| 2935 | end | 2844 | end |
| 2845 | doubled = _accum_0 | ||
| 2936 | local iter = ipairs(items) | 2846 | local iter = ipairs(items) |
| 2937 | local slice | 2847 | local slice |
| 2938 | do | 2848 | local _accum_0 = { } |
| 2939 | local _accum_0 = { } | 2849 | local _len_0 = 1 |
| 2940 | local _len_0 = 1 | 2850 | for i, item in iter do |
| 2941 | for i, item in iter do | 2851 | if i > 1 and i < 3 then |
| 2942 | if i > 1 and i < 3 then | 2852 | _accum_0[_len_0] = item |
| 2943 | _accum_0[_len_0] = item | 2853 | _len_0 = _len_0 + 1 |
| 2944 | _len_0 = _len_0 + 1 | ||
| 2945 | end | ||
| 2946 | end | 2854 | end |
| 2947 | slice = _accum_0 | ||
| 2948 | end | 2855 | end |
| 2856 | slice = _accum_0 | ||
| 2949 | local doubled | 2857 | local doubled |
| 2950 | do | 2858 | local _accum_0 = { } |
| 2951 | local _accum_0 = { } | 2859 | local _len_0 = 1 |
| 2952 | local _len_0 = 1 | 2860 | local _list_0 = items |
| 2953 | local _list_0 = items | 2861 | for _index_0 = 1, #_list_0 do |
| 2954 | for _index_0 = 1, #_list_0 do | 2862 | local item = _list_0[_index_0] |
| 2955 | local item = _list_0[_index_0] | 2863 | _accum_0[_len_0] = item * 2 |
| 2956 | _accum_0[_len_0] = item * 2 | 2864 | _len_0 = _len_0 + 1 |
| 2957 | _len_0 = _len_0 + 1 | ||
| 2958 | end | ||
| 2959 | doubled = _accum_0 | ||
| 2960 | end | 2865 | end |
| 2866 | doubled = _accum_0 | ||
| 2961 | local x_coords = { | 2867 | local x_coords = { |
| 2962 | 4, | 2868 | 4, |
| 2963 | 5, | 2869 | 5, |
| @@ -2970,57 +2876,49 @@ local y_coords = { | |||
| 2970 | 3 | 2876 | 3 |
| 2971 | } | 2877 | } |
| 2972 | local points | 2878 | local points |
| 2973 | do | 2879 | local _accum_0 = { } |
| 2974 | local _accum_0 = { } | 2880 | local _len_0 = 1 |
| 2975 | local _len_0 = 1 | 2881 | for _index_0 = 1, #x_coords do |
| 2976 | for _index_0 = 1, #x_coords do | 2882 | local x = x_coords[_index_0] |
| 2977 | local x = x_coords[_index_0] | 2883 | for _index_1 = 1, #y_coords do |
| 2978 | for _index_1 = 1, #y_coords do | 2884 | local y = y_coords[_index_1] |
| 2979 | local y = y_coords[_index_1] | 2885 | _accum_0[_len_0] = { |
| 2980 | _accum_0[_len_0] = { | 2886 | x, |
| 2981 | x, | 2887 | y |
| 2982 | y | 2888 | } |
| 2983 | } | 2889 | _len_0 = _len_0 + 1 |
| 2984 | _len_0 = _len_0 + 1 | ||
| 2985 | end | ||
| 2986 | end | 2890 | end |
| 2987 | points = _accum_0 | ||
| 2988 | end | 2891 | end |
| 2892 | points = _accum_0 | ||
| 2989 | local evens | 2893 | local evens |
| 2990 | do | 2894 | local _accum_0 = { } |
| 2991 | local _accum_0 = { } | 2895 | local _len_0 = 1 |
| 2992 | local _len_0 = 1 | 2896 | for i = 1, 100 do |
| 2993 | for i = 1, 100 do | 2897 | if i % 2 == 0 then |
| 2994 | if i % 2 == 0 then | 2898 | _accum_0[_len_0] = i |
| 2995 | _accum_0[_len_0] = i | 2899 | _len_0 = _len_0 + 1 |
| 2996 | _len_0 = _len_0 + 1 | ||
| 2997 | end | ||
| 2998 | end | 2900 | end |
| 2999 | evens = _accum_0 | ||
| 3000 | end | 2901 | end |
| 2902 | evens = _accum_0 | ||
| 3001 | local thing = { | 2903 | local thing = { |
| 3002 | color = "red", | 2904 | color = "red", |
| 3003 | name = "fast", | 2905 | name = "fast", |
| 3004 | width = 123 | 2906 | width = 123 |
| 3005 | } | 2907 | } |
| 3006 | local thing_copy | 2908 | local thing_copy |
| 3007 | do | 2909 | local _tbl_0 = { } |
| 3008 | local _tbl_0 = { } | 2910 | for k, v in pairs(thing) do |
| 3009 | for k, v in pairs(thing) do | 2911 | _tbl_0[k] = v |
| 3010 | _tbl_0[k] = v | ||
| 3011 | end | ||
| 3012 | thing_copy = _tbl_0 | ||
| 3013 | end | 2912 | end |
| 2913 | thing_copy = _tbl_0 | ||
| 3014 | local no_color | 2914 | local no_color |
| 3015 | do | 2915 | local _tbl_0 = { } |
| 3016 | local _tbl_0 = { } | 2916 | for k, v in pairs(thing) do |
| 3017 | for k, v in pairs(thing) do | 2917 | if k ~= "color" then |
| 3018 | if k ~= "color" then | 2918 | _tbl_0[k] = v |
| 3019 | _tbl_0[k] = v | ||
| 3020 | end | ||
| 3021 | end | 2919 | end |
| 3022 | no_color = _tbl_0 | ||
| 3023 | end | 2920 | end |
| 2921 | no_color = _tbl_0 | ||
| 3024 | local numbers = { | 2922 | local numbers = { |
| 3025 | 1, | 2923 | 1, |
| 3026 | 2, | 2924 | 2, |
| @@ -3028,14 +2926,12 @@ local numbers = { | |||
| 3028 | 4 | 2926 | 4 |
| 3029 | } | 2927 | } |
| 3030 | local sqrts | 2928 | local sqrts |
| 3031 | do | 2929 | local _tbl_0 = { } |
| 3032 | local _tbl_0 = { } | 2930 | for _index_0 = 1, #numbers do |
| 3033 | for _index_0 = 1, #numbers do | 2931 | local i = numbers[_index_0] |
| 3034 | local i = numbers[_index_0] | 2932 | _tbl_0[i] = math.sqrt(i) |
| 3035 | _tbl_0[i] = math.sqrt(i) | ||
| 3036 | end | ||
| 3037 | sqrts = _tbl_0 | ||
| 3038 | end | 2933 | end |
| 2934 | sqrts = _tbl_0 | ||
| 3039 | local tuples = { | 2935 | local tuples = { |
| 3040 | { | 2936 | { |
| 3041 | "hello", | 2937 | "hello", |
| @@ -3047,52 +2943,44 @@ local tuples = { | |||
| 3047 | } | 2943 | } |
| 3048 | } | 2944 | } |
| 3049 | local tbl | 2945 | local tbl |
| 3050 | do | 2946 | local _tbl_0 = { } |
| 3051 | local _tbl_0 = { } | 2947 | for _index_0 = 1, #tuples do |
| 3052 | for _index_0 = 1, #tuples do | 2948 | local tuple = tuples[_index_0] |
| 3053 | local tuple = tuples[_index_0] | 2949 | local _key_0, _val_0 = unpack(tuple) |
| 3054 | local _key_0, _val_0 = unpack(tuple) | 2950 | _tbl_0[_key_0] = _val_0 |
| 3055 | _tbl_0[_key_0] = _val_0 | ||
| 3056 | end | ||
| 3057 | tbl = _tbl_0 | ||
| 3058 | end | 2951 | end |
| 2952 | tbl = _tbl_0 | ||
| 3059 | local slice | 2953 | local slice |
| 3060 | do | 2954 | local _accum_0 = { } |
| 3061 | local _accum_0 = { } | 2955 | local _len_0 = 1 |
| 3062 | local _len_0 = 1 | 2956 | local _list_0 = items |
| 3063 | local _list_0 = items | 2957 | local _max_0 = 5 |
| 3064 | local _max_0 = 5 | 2958 | for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do |
| 3065 | for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do | 2959 | local item = _list_0[_index_0] |
| 3066 | local item = _list_0[_index_0] | 2960 | _accum_0[_len_0] = item |
| 3067 | _accum_0[_len_0] = item | 2961 | _len_0 = _len_0 + 1 |
| 3068 | _len_0 = _len_0 + 1 | ||
| 3069 | end | ||
| 3070 | slice = _accum_0 | ||
| 3071 | end | 2962 | end |
| 2963 | slice = _accum_0 | ||
| 3072 | local slice | 2964 | local slice |
| 3073 | do | 2965 | local _accum_0 = { } |
| 3074 | local _accum_0 = { } | 2966 | local _len_0 = 1 |
| 3075 | local _len_0 = 1 | 2967 | local _list_0 = items |
| 3076 | local _list_0 = items | 2968 | for _index_0 = 2, #_list_0 do |
| 3077 | for _index_0 = 2, #_list_0 do | 2969 | local item = _list_0[_index_0] |
| 3078 | local item = _list_0[_index_0] | 2970 | _accum_0[_len_0] = item |
| 3079 | _accum_0[_len_0] = item | 2971 | _len_0 = _len_0 + 1 |
| 3080 | _len_0 = _len_0 + 1 | ||
| 3081 | end | ||
| 3082 | slice = _accum_0 | ||
| 3083 | end | 2972 | end |
| 2973 | slice = _accum_0 | ||
| 3084 | local slice | 2974 | local slice |
| 3085 | do | 2975 | local _accum_0 = { } |
| 3086 | local _accum_0 = { } | 2976 | local _len_0 = 1 |
| 3087 | local _len_0 = 1 | 2977 | local _list_0 = items |
| 3088 | local _list_0 = items | 2978 | for _index_0 = 1, #_list_0, 2 do |
| 3089 | for _index_0 = 1, #_list_0, 2 do | 2979 | local item = _list_0[_index_0] |
| 3090 | local item = _list_0[_index_0] | 2980 | _accum_0[_len_0] = item |
| 3091 | _accum_0[_len_0] = item | 2981 | _len_0 = _len_0 + 1 |
| 3092 | _len_0 = _len_0 + 1 | ||
| 3093 | end | ||
| 3094 | slice = _accum_0 | ||
| 3095 | end | 2982 | end |
| 2983 | slice = _accum_0 | ||
| 3096 | for i = 10, 20 do | 2984 | for i = 10, 20 do |
| 3097 | print(i) | 2985 | print(i) |
| 3098 | end | 2986 | end |
| @@ -3102,13 +2990,11 @@ end | |||
| 3102 | for key, value in pairs(object) do | 2990 | for key, value in pairs(object) do |
| 3103 | print(key, value) | 2991 | print(key, value) |
| 3104 | end | 2992 | end |
| 3105 | do | 2993 | local _list_0 = items |
| 3106 | local _list_0 = items | 2994 | local _max_0 = 4 |
| 3107 | local _max_0 = 4 | 2995 | for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do |
| 3108 | for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do | 2996 | local item = _list_0[_index_0] |
| 3109 | local item = _list_0[_index_0] | 2997 | print(item) |
| 3110 | print(item) | ||
| 3111 | end | ||
| 3112 | end | 2998 | end |
| 3113 | local _list_0 = items | 2999 | local _list_0 = items |
| 3114 | for _index_0 = 1, #_list_0 do | 3000 | for _index_0 = 1, #_list_0 do |
| @@ -3119,19 +3005,17 @@ for j = 1, 10, 3 do | |||
| 3119 | print(j) | 3005 | print(j) |
| 3120 | end | 3006 | end |
| 3121 | local doubled_evens | 3007 | local doubled_evens |
| 3122 | do | 3008 | local _accum_0 = { } |
| 3123 | local _accum_0 = { } | 3009 | local _len_0 = 1 |
| 3124 | local _len_0 = 1 | 3010 | for i = 1, 20 do |
| 3125 | for i = 1, 20 do | 3011 | if i % 2 == 0 then |
| 3126 | if i % 2 == 0 then | 3012 | _accum_0[_len_0] = i * 2 |
| 3127 | _accum_0[_len_0] = i * 2 | 3013 | else |
| 3128 | else | 3014 | _accum_0[_len_0] = i |
| 3129 | _accum_0[_len_0] = i | ||
| 3130 | end | ||
| 3131 | _len_0 = _len_0 + 1 | ||
| 3132 | end | 3015 | end |
| 3133 | doubled_evens = _accum_0 | 3016 | _len_0 = _len_0 + 1 |
| 3134 | end | 3017 | end |
| 3018 | doubled_evens = _accum_0 | ||
| 3135 | local func_a | 3019 | local func_a |
| 3136 | func_a = function() | 3020 | func_a = function() |
| 3137 | for i = 1, 10 do | 3021 | for i = 1, 10 do |
| @@ -3189,20 +3073,18 @@ local my_numbers = { | |||
| 3189 | 6 | 3073 | 6 |
| 3190 | } | 3074 | } |
| 3191 | local odds | 3075 | local odds |
| 3192 | do | 3076 | local _accum_0 = { } |
| 3193 | local _accum_0 = { } | 3077 | local _len_0 = 1 |
| 3194 | local _len_0 = 1 | 3078 | for _index_0 = 1, #my_numbers do |
| 3195 | for _index_0 = 1, #my_numbers do | 3079 | local x = my_numbers[_index_0] |
| 3196 | local x = my_numbers[_index_0] | 3080 | if x % 2 == 1 then |
| 3197 | if x % 2 == 1 then | 3081 | goto _continue_0 |
| 3198 | goto _continue_0 | ||
| 3199 | end | ||
| 3200 | _accum_0[_len_0] = x | ||
| 3201 | _len_0 = _len_0 + 1 | ||
| 3202 | ::_continue_0:: | ||
| 3203 | end | 3082 | end |
| 3204 | odds = _accum_0 | 3083 | _accum_0[_len_0] = x |
| 3084 | _len_0 = _len_0 + 1 | ||
| 3085 | ::_continue_0:: | ||
| 3205 | end | 3086 | end |
| 3087 | odds = _accum_0 | ||
| 3206 | local have_coins = false | 3088 | local have_coins = false |
| 3207 | if have_coins then | 3089 | if have_coins then |
| 3208 | print("有硬币") | 3090 | print("有硬币") |
| @@ -3294,15 +3176,13 @@ else | |||
| 3294 | next_number = error("数字数得太大了!") | 3176 | next_number = error("数字数得太大了!") |
| 3295 | end | 3177 | end |
| 3296 | local msg | 3178 | local msg |
| 3297 | do | 3179 | local _exp_0 = math.random(1, 5) |
| 3298 | local _exp_0 = math.random(1, 5) | 3180 | if 1 == _exp_0 then |
| 3299 | if 1 == _exp_0 then | 3181 | msg = "你很幸运" |
| 3300 | msg = "你很幸运" | 3182 | elseif 2 == _exp_0 then |
| 3301 | elseif 2 == _exp_0 then | 3183 | msg = "你差点很幸运" |
| 3302 | msg = "你差点很幸运" | 3184 | else |
| 3303 | else | 3185 | msg = "不太幸运" |
| 3304 | msg = "不太幸运" | ||
| 3305 | end | ||
| 3306 | end | 3186 | end |
| 3307 | do | 3187 | do |
| 3308 | local _exp_0 = math.random(1, 5) | 3188 | local _exp_0 = math.random(1, 5) |
| @@ -3312,13 +3192,11 @@ do | |||
| 3312 | print("不太幸运") | 3192 | print("不太幸运") |
| 3313 | end | 3193 | end |
| 3314 | end | 3194 | end |
| 3315 | do | 3195 | local _exp_0 = math.random(1, 5) |
| 3316 | local _exp_0 = math.random(1, 5) | 3196 | if 1 == _exp_0 then |
| 3317 | if 1 == _exp_0 then | 3197 | print("你很幸运") |
| 3318 | print("你很幸运") | 3198 | else |
| 3319 | else | 3199 | print("不太幸运") |
| 3320 | print("不太幸运") | ||
| 3321 | end | ||
| 3322 | end | 3200 | end |
| 3323 | local items = { | 3201 | local items = { |
| 3324 | { | 3202 | { |
| @@ -3332,25 +3210,23 @@ local items = { | |||
| 3332 | } | 3210 | } |
| 3333 | for _index_0 = 1, #items do | 3211 | for _index_0 = 1, #items do |
| 3334 | local item = items[_index_0] | 3212 | local item = items[_index_0] |
| 3335 | do | 3213 | local _type_0 = type(item) |
| 3336 | local _type_0 = type(item) | 3214 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 |
| 3337 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | 3215 | local _match_0 = false |
| 3338 | local _match_0 = false | 3216 | if _tab_0 then |
| 3339 | if _tab_0 then | 3217 | local x = item.x |
| 3340 | local x = item.x | 3218 | local y = item.y |
| 3341 | local y = item.y | 3219 | if x ~= nil and y ~= nil then |
| 3342 | if x ~= nil and y ~= nil then | 3220 | _match_0 = true |
| 3343 | _match_0 = true | 3221 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) |
| 3344 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) | ||
| 3345 | end | ||
| 3346 | end | 3222 | end |
| 3347 | if not _match_0 then | 3223 | end |
| 3348 | if _tab_0 then | 3224 | if not _match_0 then |
| 3349 | local width = item.width | 3225 | if _tab_0 then |
| 3350 | local height = item.height | 3226 | local width = item.width |
| 3351 | if width ~= nil and height ~= nil then | 3227 | local height = item.height |
| 3352 | print("尺寸 " .. tostring(width) .. ", " .. tostring(height)) | 3228 | if width ~= nil and height ~= nil then |
| 3353 | end | 3229 | print("尺寸 " .. tostring(width) .. ", " .. tostring(height)) |
| 3354 | end | 3230 | end |
| 3355 | end | 3231 | end |
| 3356 | end | 3232 | end |
| @@ -3363,66 +3239,62 @@ end | |||
| 3363 | if y == nil then | 3239 | if y == nil then |
| 3364 | y = 200 | 3240 | y = 200 |
| 3365 | end | 3241 | end |
| 3366 | do | 3242 | local _type_0 = type(item) |
| 3367 | local _type_0 = type(item) | 3243 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 |
| 3368 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | 3244 | if _tab_0 then |
| 3369 | if _tab_0 then | 3245 | do |
| 3370 | do | 3246 | local _obj_0 = item.pos |
| 3371 | local _obj_0 = item.pos | 3247 | local _type_1 = type(_obj_0) |
| 3372 | local _type_1 = type(_obj_0) | 3248 | if "table" == _type_1 or "userdata" == _type_1 then |
| 3373 | if "table" == _type_1 or "userdata" == _type_1 then | 3249 | x = _obj_0.x |
| 3374 | x = _obj_0.x | ||
| 3375 | end | ||
| 3376 | end | ||
| 3377 | do | ||
| 3378 | local _obj_0 = item.pos | ||
| 3379 | local _type_1 = type(_obj_0) | ||
| 3380 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 3381 | y = _obj_0.y | ||
| 3382 | end | ||
| 3383 | end | ||
| 3384 | if x == nil then | ||
| 3385 | x = 50 | ||
| 3386 | end | 3250 | end |
| 3387 | if y == nil then | 3251 | end |
| 3388 | y = 200 | 3252 | do |
| 3253 | local _obj_0 = item.pos | ||
| 3254 | local _type_1 = type(_obj_0) | ||
| 3255 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 3256 | y = _obj_0.y | ||
| 3389 | end | 3257 | end |
| 3390 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) | ||
| 3391 | end | 3258 | end |
| 3259 | if x == nil then | ||
| 3260 | x = 50 | ||
| 3261 | end | ||
| 3262 | if y == nil then | ||
| 3263 | y = 200 | ||
| 3264 | end | ||
| 3265 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) | ||
| 3392 | end | 3266 | end |
| 3393 | local Inventory | 3267 | local Inventory |
| 3394 | do | 3268 | local _class_0 |
| 3395 | local _class_0 | 3269 | local _base_0 = { |
| 3396 | local _base_0 = { | 3270 | add_item = function(self, name) |
| 3397 | add_item = function(self, name) | 3271 | if self.items[name] then |
| 3398 | if self.items[name] then | 3272 | local _obj_0 = self.items |
| 3399 | local _obj_0 = self.items | 3273 | _obj_0[name] = _obj_0[name] + 1 |
| 3400 | _obj_0[name] = _obj_0[name] + 1 | 3274 | else |
| 3401 | else | 3275 | self.items[name] = 1 |
| 3402 | self.items[name] = 1 | ||
| 3403 | end | ||
| 3404 | end | 3276 | end |
| 3405 | } | ||
| 3406 | if _base_0.__index == nil then | ||
| 3407 | _base_0.__index = _base_0 | ||
| 3408 | end | 3277 | end |
| 3409 | _class_0 = setmetatable({ | 3278 | } |
| 3410 | __init = function(self) | 3279 | if _base_0.__index == nil then |
| 3411 | self.items = { } | 3280 | _base_0.__index = _base_0 |
| 3412 | end, | ||
| 3413 | __base = _base_0, | ||
| 3414 | __name = "Inventory" | ||
| 3415 | }, { | ||
| 3416 | __index = _base_0, | ||
| 3417 | __call = function(cls, ...) | ||
| 3418 | local _self_0 = setmetatable({ }, _base_0) | ||
| 3419 | cls.__init(_self_0, ...) | ||
| 3420 | return _self_0 | ||
| 3421 | end | ||
| 3422 | }) | ||
| 3423 | _base_0.__class = _class_0 | ||
| 3424 | Inventory = _class_0 | ||
| 3425 | end | 3281 | end |
| 3282 | _class_0 = setmetatable({ | ||
| 3283 | __init = function(self) | ||
| 3284 | self.items = { } | ||
| 3285 | end, | ||
| 3286 | __base = _base_0, | ||
| 3287 | __name = "Inventory" | ||
| 3288 | }, { | ||
| 3289 | __index = _base_0, | ||
| 3290 | __call = function(cls, ...) | ||
| 3291 | local _self_0 = setmetatable({ }, _base_0) | ||
| 3292 | cls.__init(_self_0, ...) | ||
| 3293 | return _self_0 | ||
| 3294 | end | ||
| 3295 | }) | ||
| 3296 | _base_0.__class = _class_0 | ||
| 3297 | Inventory = _class_0 | ||
| 3426 | local inv = Inventory() | 3298 | local inv = Inventory() |
| 3427 | inv:add_item("t-shirt") | 3299 | inv:add_item("t-shirt") |
| 3428 | inv:add_item("pants") | 3300 | inv:add_item("pants") |
| @@ -3463,82 +3335,78 @@ for _index_0 = 1, #_list_0 do | |||
| 3463 | print(item) | 3335 | print(item) |
| 3464 | end | 3336 | end |
| 3465 | local Person | 3337 | local Person |
| 3466 | do | 3338 | local _class_0 |
| 3467 | local _class_0 | 3339 | local _base_0 = { } |
| 3468 | local _base_0 = { } | 3340 | if _base_0.__index == nil then |
| 3469 | if _base_0.__index == nil then | 3341 | _base_0.__index = _base_0 |
| 3470 | _base_0.__index = _base_0 | 3342 | end |
| 3343 | _class_0 = setmetatable({ | ||
| 3344 | __init = function(self) | ||
| 3345 | self.clothes = { } | ||
| 3346 | end, | ||
| 3347 | __base = _base_0, | ||
| 3348 | __name = "Person" | ||
| 3349 | }, { | ||
| 3350 | __index = _base_0, | ||
| 3351 | __call = function(cls, ...) | ||
| 3352 | local _self_0 = setmetatable({ }, _base_0) | ||
| 3353 | cls.__init(_self_0, ...) | ||
| 3354 | return _self_0 | ||
| 3471 | end | 3355 | end |
| 3472 | _class_0 = setmetatable({ | 3356 | }) |
| 3473 | __init = function(self) | 3357 | _base_0.__class = _class_0 |
| 3474 | self.clothes = { } | 3358 | Person = _class_0 |
| 3475 | end, | ||
| 3476 | __base = _base_0, | ||
| 3477 | __name = "Person" | ||
| 3478 | }, { | ||
| 3479 | __index = _base_0, | ||
| 3480 | __call = function(cls, ...) | ||
| 3481 | local _self_0 = setmetatable({ }, _base_0) | ||
| 3482 | cls.__init(_self_0, ...) | ||
| 3483 | return _self_0 | ||
| 3484 | end | ||
| 3485 | }) | ||
| 3486 | _base_0.__class = _class_0 | ||
| 3487 | Person = _class_0 | ||
| 3488 | end | ||
| 3489 | local BackPack | 3359 | local BackPack |
| 3490 | do | 3360 | local _class_0 |
| 3491 | local _class_0 | 3361 | local _parent_0 = Inventory |
| 3492 | local _parent_0 = Inventory | 3362 | local _base_0 = { |
| 3493 | local _base_0 = { | 3363 | size = 10, |
| 3494 | size = 10, | 3364 | add_item = function(self, name) |
| 3495 | add_item = function(self, name) | 3365 | if #self.items > size then |
| 3496 | if #self.items > size then | 3366 | error("背包已满") |
| 3497 | error("背包已满") | ||
| 3498 | end | ||
| 3499 | return _class_0.__parent.__base.add_item(self, name) | ||
| 3500 | end | ||
| 3501 | } | ||
| 3502 | for _key_0, _val_0 in pairs(_parent_0.__base) do | ||
| 3503 | if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then | ||
| 3504 | _base_0[_key_0] = _val_0 | ||
| 3505 | end | 3367 | end |
| 3368 | return _class_0.__parent.__base.add_item(self, name) | ||
| 3506 | end | 3369 | end |
| 3507 | if _base_0.__index == nil then | 3370 | } |
| 3508 | _base_0.__index = _base_0 | 3371 | for _key_0, _val_0 in pairs(_parent_0.__base) do |
| 3372 | if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then | ||
| 3373 | _base_0[_key_0] = _val_0 | ||
| 3509 | end | 3374 | end |
| 3510 | setmetatable(_base_0, _parent_0.__base) | 3375 | end |
| 3511 | _class_0 = setmetatable({ | 3376 | if _base_0.__index == nil then |
| 3512 | __init = function(self, ...) | 3377 | _base_0.__index = _base_0 |
| 3513 | return _class_0.__parent.__init(self, ...) | 3378 | end |
| 3514 | end, | 3379 | setmetatable(_base_0, _parent_0.__base) |
| 3515 | __base = _base_0, | 3380 | _class_0 = setmetatable({ |
| 3516 | __name = "BackPack", | 3381 | __init = function(self, ...) |
| 3517 | __parent = _parent_0 | 3382 | return _class_0.__parent.__init(self, ...) |
| 3518 | }, { | 3383 | end, |
| 3519 | __index = function(cls, name) | 3384 | __base = _base_0, |
| 3520 | local val = rawget(_base_0, name) | 3385 | __name = "BackPack", |
| 3521 | if val == nil then | 3386 | __parent = _parent_0 |
| 3522 | local parent = rawget(cls, "__parent") | 3387 | }, { |
| 3523 | if parent then | 3388 | __index = function(cls, name) |
| 3524 | return parent[name] | 3389 | local val = rawget(_base_0, name) |
| 3525 | end | 3390 | if val == nil then |
| 3526 | else | 3391 | local parent = rawget(cls, "__parent") |
| 3527 | return val | 3392 | if parent then |
| 3393 | return parent[name] | ||
| 3528 | end | 3394 | end |
| 3529 | end, | 3395 | else |
| 3530 | __call = function(cls, ...) | 3396 | return val |
| 3531 | local _self_0 = setmetatable({ }, _base_0) | ||
| 3532 | cls.__init(_self_0, ...) | ||
| 3533 | return _self_0 | ||
| 3534 | end | 3397 | end |
| 3535 | }) | 3398 | end, |
| 3536 | _base_0.__class = _class_0 | 3399 | __call = function(cls, ...) |
| 3537 | if _parent_0.__inherited then | 3400 | local _self_0 = setmetatable({ }, _base_0) |
| 3538 | _parent_0.__inherited(_parent_0, _class_0) | 3401 | cls.__init(_self_0, ...) |
| 3402 | return _self_0 | ||
| 3539 | end | 3403 | end |
| 3540 | BackPack = _class_0 | 3404 | }) |
| 3405 | _base_0.__class = _class_0 | ||
| 3406 | if _parent_0.__inherited then | ||
| 3407 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 3541 | end | 3408 | end |
| 3409 | BackPack = _class_0 | ||
| 3542 | local Shelf | 3410 | local Shelf |
| 3543 | do | 3411 | do |
| 3544 | local _class_0 | 3412 | local _class_0 |
| @@ -3566,102 +3434,98 @@ do | |||
| 3566 | Shelf = _class_0 | 3434 | Shelf = _class_0 |
| 3567 | end | 3435 | end |
| 3568 | local Cupboard | 3436 | local Cupboard |
| 3569 | do | 3437 | local _class_0 |
| 3570 | local _class_0 | 3438 | local _parent_0 = Shelf |
| 3571 | local _parent_0 = Shelf | 3439 | local _base_0 = { } |
| 3572 | local _base_0 = { } | 3440 | for _key_0, _val_0 in pairs(_parent_0.__base) do |
| 3573 | for _key_0, _val_0 in pairs(_parent_0.__base) do | 3441 | if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then |
| 3574 | if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then | 3442 | _base_0[_key_0] = _val_0 |
| 3575 | _base_0[_key_0] = _val_0 | 3443 | end |
| 3576 | end | 3444 | end |
| 3577 | end | 3445 | if _base_0.__index == nil then |
| 3578 | if _base_0.__index == nil then | 3446 | _base_0.__index = _base_0 |
| 3579 | _base_0.__index = _base_0 | 3447 | end |
| 3580 | end | 3448 | setmetatable(_base_0, _parent_0.__base) |
| 3581 | setmetatable(_base_0, _parent_0.__base) | 3449 | _class_0 = setmetatable({ |
| 3582 | _class_0 = setmetatable({ | 3450 | __init = function(self, ...) |
| 3583 | __init = function(self, ...) | 3451 | return _class_0.__parent.__init(self, ...) |
| 3584 | return _class_0.__parent.__init(self, ...) | 3452 | end, |
| 3585 | end, | 3453 | __base = _base_0, |
| 3586 | __base = _base_0, | 3454 | __name = "Cupboard", |
| 3587 | __name = "Cupboard", | 3455 | __parent = _parent_0 |
| 3588 | __parent = _parent_0 | 3456 | }, { |
| 3589 | }, { | 3457 | __index = function(cls, name) |
| 3590 | __index = function(cls, name) | 3458 | local val = rawget(_base_0, name) |
| 3591 | local val = rawget(_base_0, name) | 3459 | if val == nil then |
| 3592 | if val == nil then | 3460 | local parent = rawget(cls, "__parent") |
| 3593 | local parent = rawget(cls, "__parent") | 3461 | if parent then |
| 3594 | if parent then | 3462 | return parent[name] |
| 3595 | return parent[name] | ||
| 3596 | end | ||
| 3597 | else | ||
| 3598 | return val | ||
| 3599 | end | 3463 | end |
| 3600 | end, | 3464 | else |
| 3601 | __call = function(cls, ...) | 3465 | return val |
| 3602 | local _self_0 = setmetatable({ }, _base_0) | ||
| 3603 | cls.__init(_self_0, ...) | ||
| 3604 | return _self_0 | ||
| 3605 | end | 3466 | end |
| 3606 | }) | 3467 | end, |
| 3607 | _base_0.__class = _class_0 | 3468 | __call = function(cls, ...) |
| 3608 | if _parent_0.__inherited then | 3469 | local _self_0 = setmetatable({ }, _base_0) |
| 3609 | _parent_0.__inherited(_parent_0, _class_0) | 3470 | cls.__init(_self_0, ...) |
| 3471 | return _self_0 | ||
| 3610 | end | 3472 | end |
| 3611 | Cupboard = _class_0 | 3473 | }) |
| 3474 | _base_0.__class = _class_0 | ||
| 3475 | if _parent_0.__inherited then | ||
| 3476 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 3612 | end | 3477 | end |
| 3478 | Cupboard = _class_0 | ||
| 3613 | local MyClass | 3479 | local MyClass |
| 3614 | do | 3480 | local _class_0 |
| 3615 | local _class_0 | 3481 | local _parent_0 = ParentClass |
| 3616 | local _parent_0 = ParentClass | 3482 | local _base_0 = { |
| 3617 | local _base_0 = { | 3483 | a_method = function(self) |
| 3618 | a_method = function(self) | 3484 | _class_0.__parent.__base.a_method(self, "你好", "世界") |
| 3619 | _class_0.__parent.__base.a_method(self, "你好", "世界") | 3485 | _class_0.__parent.a_method(self, "你好", "世界") |
| 3620 | _class_0.__parent.a_method(self, "你好", "世界") | 3486 | _class_0.__parent.a_method(self, "你好", "世界") |
| 3621 | _class_0.__parent.a_method(self, "你好", "世界") | 3487 | return assert(_class_0.__parent == ParentClass) |
| 3622 | return assert(_class_0.__parent == ParentClass) | 3488 | end |
| 3623 | end | 3489 | } |
| 3624 | } | 3490 | for _key_0, _val_0 in pairs(_parent_0.__base) do |
| 3625 | for _key_0, _val_0 in pairs(_parent_0.__base) do | 3491 | if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then |
| 3626 | if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then | 3492 | _base_0[_key_0] = _val_0 |
| 3627 | _base_0[_key_0] = _val_0 | 3493 | end |
| 3628 | end | 3494 | end |
| 3629 | end | 3495 | if _base_0.__index == nil then |
| 3630 | if _base_0.__index == nil then | 3496 | _base_0.__index = _base_0 |
| 3631 | _base_0.__index = _base_0 | 3497 | end |
| 3632 | end | 3498 | setmetatable(_base_0, _parent_0.__base) |
| 3633 | setmetatable(_base_0, _parent_0.__base) | 3499 | _class_0 = setmetatable({ |
| 3634 | _class_0 = setmetatable({ | 3500 | __init = function(self, ...) |
| 3635 | __init = function(self, ...) | 3501 | return _class_0.__parent.__init(self, ...) |
| 3636 | return _class_0.__parent.__init(self, ...) | 3502 | end, |
| 3637 | end, | 3503 | __base = _base_0, |
| 3638 | __base = _base_0, | 3504 | __name = "MyClass", |
| 3639 | __name = "MyClass", | 3505 | __parent = _parent_0 |
| 3640 | __parent = _parent_0 | 3506 | }, { |
| 3641 | }, { | 3507 | __index = function(cls, name) |
| 3642 | __index = function(cls, name) | 3508 | local val = rawget(_base_0, name) |
| 3643 | local val = rawget(_base_0, name) | 3509 | if val == nil then |
| 3644 | if val == nil then | 3510 | local parent = rawget(cls, "__parent") |
| 3645 | local parent = rawget(cls, "__parent") | 3511 | if parent then |
| 3646 | if parent then | 3512 | return parent[name] |
| 3647 | return parent[name] | ||
| 3648 | end | ||
| 3649 | else | ||
| 3650 | return val | ||
| 3651 | end | 3513 | end |
| 3652 | end, | 3514 | else |
| 3653 | __call = function(cls, ...) | 3515 | return val |
| 3654 | local _self_0 = setmetatable({ }, _base_0) | ||
| 3655 | cls.__init(_self_0, ...) | ||
| 3656 | return _self_0 | ||
| 3657 | end | 3516 | end |
| 3658 | }) | 3517 | end, |
| 3659 | _base_0.__class = _class_0 | 3518 | __call = function(cls, ...) |
| 3660 | if _parent_0.__inherited then | 3519 | local _self_0 = setmetatable({ }, _base_0) |
| 3661 | _parent_0.__inherited(_parent_0, _class_0) | 3520 | cls.__init(_self_0, ...) |
| 3521 | return _self_0 | ||
| 3662 | end | 3522 | end |
| 3663 | MyClass = _class_0 | 3523 | }) |
| 3524 | _base_0.__class = _class_0 | ||
| 3525 | if _parent_0.__inherited then | ||
| 3526 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 3664 | end | 3527 | end |
| 3528 | MyClass = _class_0 | ||
| 3665 | local b = BackPack() | 3529 | local b = BackPack() |
| 3666 | assert(b.__class == BackPack) | 3530 | assert(b.__class == BackPack) |
| 3667 | print(BackPack.size) | 3531 | print(BackPack.size) |
| @@ -3725,61 +3589,57 @@ Counter() | |||
| 3725 | print(Counter.count) | 3589 | print(Counter.count) |
| 3726 | self.__class:hello(1, 2, 3, 4) | 3590 | self.__class:hello(1, 2, 3, 4) |
| 3727 | local Things | 3591 | local Things |
| 3728 | do | 3592 | local _class_0 |
| 3729 | local _class_0 | 3593 | local _base_0 = { } |
| 3730 | local _base_0 = { } | 3594 | if _base_0.__index == nil then |
| 3731 | if _base_0.__index == nil then | 3595 | _base_0.__index = _base_0 |
| 3732 | _base_0.__index = _base_0 | 3596 | end |
| 3597 | _class_0 = setmetatable({ | ||
| 3598 | __init = function() end, | ||
| 3599 | __base = _base_0, | ||
| 3600 | __name = "Things" | ||
| 3601 | }, { | ||
| 3602 | __index = _base_0, | ||
| 3603 | __call = function(cls, ...) | ||
| 3604 | local _self_0 = setmetatable({ }, _base_0) | ||
| 3605 | cls.__init(_self_0, ...) | ||
| 3606 | return _self_0 | ||
| 3733 | end | 3607 | end |
| 3734 | _class_0 = setmetatable({ | 3608 | }) |
| 3735 | __init = function() end, | 3609 | _base_0.__class = _class_0 |
| 3736 | __base = _base_0, | 3610 | local self = _class_0; |
| 3737 | __name = "Things" | 3611 | self.class_var = "hello world" |
| 3738 | }, { | 3612 | Things = _class_0 |
| 3739 | __index = _base_0, | ||
| 3740 | __call = function(cls, ...) | ||
| 3741 | local _self_0 = setmetatable({ }, _base_0) | ||
| 3742 | cls.__init(_self_0, ...) | ||
| 3743 | return _self_0 | ||
| 3744 | end | ||
| 3745 | }) | ||
| 3746 | _base_0.__class = _class_0 | ||
| 3747 | local self = _class_0; | ||
| 3748 | self.class_var = "hello world" | ||
| 3749 | Things = _class_0 | ||
| 3750 | end | ||
| 3751 | local MoreThings | 3613 | local MoreThings |
| 3752 | do | 3614 | local _class_0 |
| 3753 | local _class_0 | 3615 | local secret, log |
| 3754 | local secret, log | 3616 | local _base_0 = { |
| 3755 | local _base_0 = { | 3617 | some_method = function(self) |
| 3756 | some_method = function(self) | 3618 | return log("hello world: " .. secret) |
| 3757 | return log("hello world: " .. secret) | ||
| 3758 | end | ||
| 3759 | } | ||
| 3760 | if _base_0.__index == nil then | ||
| 3761 | _base_0.__index = _base_0 | ||
| 3762 | end | 3619 | end |
| 3763 | _class_0 = setmetatable({ | 3620 | } |
| 3764 | __init = function() end, | 3621 | if _base_0.__index == nil then |
| 3765 | __base = _base_0, | 3622 | _base_0.__index = _base_0 |
| 3766 | __name = "MoreThings" | 3623 | end |
| 3767 | }, { | 3624 | _class_0 = setmetatable({ |
| 3768 | __index = _base_0, | 3625 | __init = function() end, |
| 3769 | __call = function(cls, ...) | 3626 | __base = _base_0, |
| 3770 | local _self_0 = setmetatable({ }, _base_0) | 3627 | __name = "MoreThings" |
| 3771 | cls.__init(_self_0, ...) | 3628 | }, { |
| 3772 | return _self_0 | 3629 | __index = _base_0, |
| 3773 | end | 3630 | __call = function(cls, ...) |
| 3774 | }) | 3631 | local _self_0 = setmetatable({ }, _base_0) |
| 3775 | _base_0.__class = _class_0 | 3632 | cls.__init(_self_0, ...) |
| 3776 | local self = _class_0; | 3633 | return _self_0 |
| 3777 | secret = 123 | ||
| 3778 | log = function(msg) | ||
| 3779 | return print("LOG:", msg) | ||
| 3780 | end | 3634 | end |
| 3781 | MoreThings = _class_0 | 3635 | }) |
| 3636 | _base_0.__class = _class_0 | ||
| 3637 | local self = _class_0; | ||
| 3638 | secret = 123 | ||
| 3639 | log = function(msg) | ||
| 3640 | return print("LOG:", msg) | ||
| 3782 | end | 3641 | end |
| 3642 | MoreThings = _class_0 | ||
| 3783 | assert(self == self) | 3643 | assert(self == self) |
| 3784 | assert(self.__class == self.__class) | 3644 | assert(self.__class == self.__class) |
| 3785 | local some_instance_method | 3645 | local some_instance_method |
| @@ -3813,32 +3673,30 @@ do | |||
| 3813 | _base_0.__class = _class_0 | 3673 | _base_0.__class = _class_0 |
| 3814 | Something = _class_0 | 3674 | Something = _class_0 |
| 3815 | end | 3675 | end |
| 3816 | do | 3676 | local _class_0 |
| 3817 | local _class_0 | 3677 | local _base_0 = { } |
| 3818 | local _base_0 = { } | 3678 | if _base_0.__index == nil then |
| 3819 | if _base_0.__index == nil then | 3679 | _base_0.__index = _base_0 |
| 3820 | _base_0.__index = _base_0 | 3680 | end |
| 3681 | _class_0 = setmetatable({ | ||
| 3682 | __init = function(self, foo, bar, biz, baz) | ||
| 3683 | self.foo = foo | ||
| 3684 | self.bar = bar | ||
| 3685 | self.__class.biz = biz | ||
| 3686 | self.__class.baz = baz | ||
| 3687 | end, | ||
| 3688 | __base = _base_0, | ||
| 3689 | __name = "Something" | ||
| 3690 | }, { | ||
| 3691 | __index = _base_0, | ||
| 3692 | __call = function(cls, ...) | ||
| 3693 | local _self_0 = setmetatable({ }, _base_0) | ||
| 3694 | cls.__init(_self_0, ...) | ||
| 3695 | return _self_0 | ||
| 3821 | end | 3696 | end |
| 3822 | _class_0 = setmetatable({ | 3697 | }) |
| 3823 | __init = function(self, foo, bar, biz, baz) | 3698 | _base_0.__class = _class_0 |
| 3824 | self.foo = foo | 3699 | Something = _class_0 |
| 3825 | self.bar = bar | ||
| 3826 | self.__class.biz = biz | ||
| 3827 | self.__class.baz = baz | ||
| 3828 | end, | ||
| 3829 | __base = _base_0, | ||
| 3830 | __name = "Something" | ||
| 3831 | }, { | ||
| 3832 | __index = _base_0, | ||
| 3833 | __call = function(cls, ...) | ||
| 3834 | local _self_0 = setmetatable({ }, _base_0) | ||
| 3835 | cls.__init(_self_0, ...) | ||
| 3836 | return _self_0 | ||
| 3837 | end | ||
| 3838 | }) | ||
| 3839 | _base_0.__class = _class_0 | ||
| 3840 | Something = _class_0 | ||
| 3841 | end | ||
| 3842 | local new | 3700 | local new |
| 3843 | new = function(self, fieldA, fieldB) | 3701 | new = function(self, fieldA, fieldB) |
| 3844 | self.fieldA = fieldA | 3702 | self.fieldA = fieldA |
| @@ -3849,33 +3707,31 @@ local obj = new({ }, 123, "abc") | |||
| 3849 | print(obj) | 3707 | print(obj) |
| 3850 | local x | 3708 | local x |
| 3851 | local Bucket | 3709 | local Bucket |
| 3852 | do | 3710 | local _class_0 |
| 3853 | local _class_0 | 3711 | local _base_0 = { |
| 3854 | local _base_0 = { | 3712 | drops = 0, |
| 3855 | drops = 0, | 3713 | add_drop = function(self) |
| 3856 | add_drop = function(self) | 3714 | self.drops = self.drops + 1 |
| 3857 | self.drops = self.drops + 1 | ||
| 3858 | end | ||
| 3859 | } | ||
| 3860 | if _base_0.__index == nil then | ||
| 3861 | _base_0.__index = _base_0 | ||
| 3862 | end | 3715 | end |
| 3863 | _class_0 = setmetatable({ | 3716 | } |
| 3864 | __init = function() end, | 3717 | if _base_0.__index == nil then |
| 3865 | __base = _base_0, | 3718 | _base_0.__index = _base_0 |
| 3866 | __name = "Bucket" | ||
| 3867 | }, { | ||
| 3868 | __index = _base_0, | ||
| 3869 | __call = function(cls, ...) | ||
| 3870 | local _self_0 = setmetatable({ }, _base_0) | ||
| 3871 | cls.__init(_self_0, ...) | ||
| 3872 | return _self_0 | ||
| 3873 | end | ||
| 3874 | }) | ||
| 3875 | _base_0.__class = _class_0 | ||
| 3876 | Bucket = _class_0 | ||
| 3877 | x = _class_0 | ||
| 3878 | end | 3719 | end |
| 3720 | _class_0 = setmetatable({ | ||
| 3721 | __init = function() end, | ||
| 3722 | __base = _base_0, | ||
| 3723 | __name = "Bucket" | ||
| 3724 | }, { | ||
| 3725 | __index = _base_0, | ||
| 3726 | __call = function(cls, ...) | ||
| 3727 | local _self_0 = setmetatable({ }, _base_0) | ||
| 3728 | cls.__init(_self_0, ...) | ||
| 3729 | return _self_0 | ||
| 3730 | end | ||
| 3731 | }) | ||
| 3732 | _base_0.__class = _class_0 | ||
| 3733 | Bucket = _class_0 | ||
| 3734 | x = _class_0 | ||
| 3879 | local BigBucket | 3735 | local BigBucket |
| 3880 | do | 3736 | do |
| 3881 | local _class_0 | 3737 | local _class_0 |
| @@ -3927,27 +3783,25 @@ do | |||
| 3927 | end | 3783 | end |
| 3928 | assert(Bucket.__name == "BigBucket") | 3784 | assert(Bucket.__name == "BigBucket") |
| 3929 | local x | 3785 | local x |
| 3930 | do | 3786 | local _class_0 |
| 3931 | local _class_0 | 3787 | local _base_0 = { } |
| 3932 | local _base_0 = { } | 3788 | if _base_0.__index == nil then |
| 3933 | if _base_0.__index == nil then | 3789 | _base_0.__index = _base_0 |
| 3934 | _base_0.__index = _base_0 | 3790 | end |
| 3791 | _class_0 = setmetatable({ | ||
| 3792 | __init = function() end, | ||
| 3793 | __base = _base_0, | ||
| 3794 | __name = "x" | ||
| 3795 | }, { | ||
| 3796 | __index = _base_0, | ||
| 3797 | __call = function(cls, ...) | ||
| 3798 | local _self_0 = setmetatable({ }, _base_0) | ||
| 3799 | cls.__init(_self_0, ...) | ||
| 3800 | return _self_0 | ||
| 3935 | end | 3801 | end |
| 3936 | _class_0 = setmetatable({ | 3802 | }) |
| 3937 | __init = function() end, | 3803 | _base_0.__class = _class_0 |
| 3938 | __base = _base_0, | 3804 | x = _class_0 |
| 3939 | __name = "x" | ||
| 3940 | }, { | ||
| 3941 | __index = _base_0, | ||
| 3942 | __call = function(cls, ...) | ||
| 3943 | local _self_0 = setmetatable({ }, _base_0) | ||
| 3944 | cls.__init(_self_0, ...) | ||
| 3945 | return _self_0 | ||
| 3946 | end | ||
| 3947 | }) | ||
| 3948 | _base_0.__class = _class_0 | ||
| 3949 | x = _class_0 | ||
| 3950 | end | ||
| 3951 | local MyIndex = { | 3805 | local MyIndex = { |
| 3952 | __index = { | 3806 | __index = { |
| 3953 | var = 1 | 3807 | var = 1 |
| @@ -4030,19 +3884,15 @@ end | |||
| 4030 | local y = Y() | 3884 | local y = Y() |
| 4031 | y:func() | 3885 | y:func() |
| 4032 | assert(y.__class.__parent ~= X) | 3886 | assert(y.__class.__parent ~= X) |
| 4033 | do | 3887 | local _with_0 = Person() |
| 4034 | local _with_0 = Person() | 3888 | _with_0.name = "Oswald" |
| 4035 | _with_0.name = "Oswald" | 3889 | _with_0:add_relative(my_dad) |
| 4036 | _with_0:add_relative(my_dad) | 3890 | _with_0:save() |
| 4037 | _with_0:save() | 3891 | print(_with_0.name) |
| 4038 | print(_with_0.name) | ||
| 4039 | end | ||
| 4040 | local file | 3892 | local file |
| 4041 | do | 3893 | local _with_0 = File("favorite_foods.txt") |
| 4042 | local _with_0 = File("favorite_foods.txt") | 3894 | _with_0:set_encoding("utf8") |
| 4043 | _with_0:set_encoding("utf8") | 3895 | file = _with_0 |
| 4044 | file = _with_0 | ||
| 4045 | end | ||
| 4046 | local create_person | 3896 | local create_person |
| 4047 | create_person = function(name, relatives) | 3897 | create_person = function(name, relatives) |
| 4048 | local _with_0 = Person() | 3898 | local _with_0 = Person() |
| @@ -4058,22 +3908,18 @@ local me = create_person("Leaf", { | |||
| 4058 | mother, | 3908 | mother, |
| 4059 | sister | 3909 | sister |
| 4060 | }) | 3910 | }) |
| 4061 | do | 3911 | local str = "你好" |
| 4062 | local str = "你好" | 3912 | print("原始:", str) |
| 4063 | print("原始:", str) | 3913 | print("大写:", str:upper()) |
| 4064 | print("大写:", str:upper()) | 3914 | local _with_0 = tb |
| 4065 | end | 3915 | _with_0[1] = 1 |
| 4066 | do | 3916 | print(_with_0[2]) |
| 4067 | local _with_0 = tb | 3917 | do |
| 4068 | _with_0[1] = 1 | 3918 | local _with_1 = _with_0[abc] |
| 4069 | print(_with_0[2]) | 3919 | _with_1[3] = _with_1[2]:func() |
| 4070 | do | 3920 | _with_1["key-name"] = value |
| 4071 | local _with_1 = _with_0[abc] | 3921 | end |
| 4072 | _with_1[3] = _with_1[2]:func() | 3922 | _with_0[#_with_0 + 1] = "abc" |
| 4073 | _with_1["key-name"] = value | ||
| 4074 | end | ||
| 4075 | _with_0[#_with_0 + 1] = "abc" | ||
| 4076 | end | ||
| 4077 | do | 3923 | do |
| 4078 | local var = "hello" | 3924 | local var = "hello" |
| 4079 | print(var) | 3925 | print(var) |
