aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs/codes_from_doc_zh.lua
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2024-03-21 09:14:34 +0800
committerLi Jin <dragon-fly@qq.com>2024-03-21 09:14:34 +0800
commit4a3cc26c6dfd74e61c8b6480038d6a292ea86e47 (patch)
tree9554b94cfc15e4acee0c2e60b63af16f1b828207 /spec/outputs/codes_from_doc_zh.lua
parent80b65520da432843f0c63431a1867bd2620bc4ac (diff)
downloadyuescript-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.lua2250
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
46return _module_0 46return _module_0
47local area = 6.2831853071796 * 5 47local area = 6.2831853071796 * 5
48print('你好 世界') 48print('你好 世界')
49assert(item ~= nil) 49do
50 assert(item ~= nil)
51end
50local value = item 52local value = item
51if (f1() and f2() and f3()) then 53if (f1() and f2() and f3()) then
52 print("OK") 54 print("OK")
53end 55end
56do
57 local funcA
58 funcA = function() end
59end
54local funcA 60local funcA
55funcA = function() end
56funcA = function() 61funcA = function()
57 return "访问月之脚本定义的变量" 62 return "访问月之脚本定义的变量"
58end 63end
@@ -146,28 +151,26 @@ local b = {
146 y = 1 151 y = 1
147} 152}
148local merge 153local merge
149do 154local _tab_0 = { }
150 local _tab_0 = { } 155local _idx_0 = 1
151 local _idx_0 = 1 156for _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 163end
161 for _key_0, _value_0 in pairs(b) do 164local _idx_1 = 1
162 if _idx_1 == _key_0 then 165for _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
170end 172end
173merge = _tab_0
171local mt = { } 174local mt = { }
172local add 175local add
173add = function(self, right) 176add = function(self, right)
@@ -259,12 +262,10 @@ end
259if print and (x ~= nil) then 262if print and (x ~= nil) then
260 print(x) 263 print(x)
261end 264end
262do 265local _with_0 = io.open("test.txt", "w")
263 local _with_0 = io.open("test.txt", "w") 266if _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
268end 269end
269print("你好") 270print("你好")
270print(1, 2) 271print(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
348end 347end
349do 348do
350 local module = require('module') 349 local module = require('module')
@@ -383,29 +382,27 @@ y = function()
383end 382end
384_module_0["y"] = y 383_module_0["y"] = y
385local Something 384local Something
386do 385local _class_0
387 local _class_0 386local _base_0 = {
388 local _base_0 = { 387 umm = "cool"
389 umm = "cool" 388}
390 } 389if _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
408end 391end
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
405Something = _class_0
409_module_0["Something"] = Something 406_module_0["Something"] = Something
410return _module_0 407return _module_0
411local _module_0 = { } 408local _module_0 = { }
@@ -436,11 +433,9 @@ if this then
436else 433else
437 _module_0[#_module_0 + 1] = 456 434 _module_0[#_module_0 + 1] = 456
438end 435end
439do 436local _with_0 = tmp
440 local _with_0 = tmp 437local j = 2000
441 local j = 2000 438_module_0[#_module_0 + 1] = _with_0
442 _module_0[#_module_0 + 1] = _with_0
443end
444return _module_0 439return _module_0
445local _module_0 = nil 440local _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)
579end 574end
580do 575local user = database.find_user("moon")
581 local user = database.find_user("moon") 576if user then
582 if user then 577 print(user.name)
583 print(user.name)
584 end
585end 578end
586do 579local hello = os.getenv("hello")
587 local hello = os.getenv("hello") 580if hello then
588 if hello then 581 print("你有 hello", hello)
589 print("你有 hello", hello) 582else
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
600end 589end
601do 590do
@@ -852,40 +841,34 @@ local items = {
852 4 841 4
853} 842}
854local doubled 843local doubled
855do 844local _accum_0 = { }
856 local _accum_0 = { } 845local _len_0 = 1
857 local _len_0 = 1 846for 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
863end 849end
850doubled = _accum_0
864local iter = ipairs(items) 851local iter = ipairs(items)
865local slice 852local slice
866do 853local _accum_0 = { }
867 local _accum_0 = { } 854local _len_0 = 1
868 local _len_0 = 1 855for 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
876end 860end
861slice = _accum_0
877local doubled 862local doubled
878do 863local _accum_0 = { }
879 local _accum_0 = { } 864local _len_0 = 1
880 local _len_0 = 1 865local _list_0 = items
881 local _list_0 = items 866for _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
888end 870end
871doubled = _accum_0
889local x_coords = { 872local x_coords = {
890 4, 873 4,
891 5, 874 5,
@@ -898,57 +881,49 @@ local y_coords = {
898 3 881 3
899} 882}
900local points 883local points
901do 884local _accum_0 = { }
902 local _accum_0 = { } 885local _len_0 = 1
903 local _len_0 = 1 886for _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
916end 896end
897points = _accum_0
917local evens 898local evens
918do 899local _accum_0 = { }
919 local _accum_0 = { } 900local _len_0 = 1
920 local _len_0 = 1 901for 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
928end 906end
907evens = _accum_0
929local thing = { 908local thing = {
930 color = "red", 909 color = "red",
931 name = "fast", 910 name = "fast",
932 width = 123 911 width = 123
933} 912}
934local thing_copy 913local thing_copy
935do 914local _tbl_0 = { }
936 local _tbl_0 = { } 915for 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
941end 917end
918thing_copy = _tbl_0
942local no_color 919local no_color
943do 920local _tbl_0 = { }
944 local _tbl_0 = { } 921for 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
951end 925end
926no_color = _tbl_0
952local numbers = { 927local numbers = {
953 1, 928 1,
954 2, 929 2,
@@ -956,14 +931,12 @@ local numbers = {
956 4 931 4
957} 932}
958local sqrts 933local sqrts
959do 934local _tbl_0 = { }
960 local _tbl_0 = { } 935for _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
966end 938end
939sqrts = _tbl_0
967local tuples = { 940local tuples = {
968 { 941 {
969 "hello", 942 "hello",
@@ -975,52 +948,44 @@ local tuples = {
975 } 948 }
976} 949}
977local tbl 950local tbl
978do 951local _tbl_0 = { }
979 local _tbl_0 = { } 952for _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
986end 956end
957tbl = _tbl_0
987local slice 958local slice
988do 959local _accum_0 = { }
989 local _accum_0 = { } 960local _len_0 = 1
990 local _len_0 = 1 961local _list_0 = items
991 local _list_0 = items 962local _max_0 = 5
992 local _max_0 = 5 963for _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
999end 967end
968slice = _accum_0
1000local slice 969local slice
1001do 970local _accum_0 = { }
1002 local _accum_0 = { } 971local _len_0 = 1
1003 local _len_0 = 1 972local _list_0 = items
1004 local _list_0 = items 973for _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
1011end 977end
978slice = _accum_0
1012local slice 979local slice
1013do 980local _accum_0 = { }
1014 local _accum_0 = { } 981local _len_0 = 1
1015 local _len_0 = 1 982local _list_0 = items
1016 local _list_0 = items 983for _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
1023end 987end
988slice = _accum_0
1024for i = 10, 20 do 989for i = 10, 20 do
1025 print(i) 990 print(i)
1026end 991end
@@ -1030,13 +995,11 @@ end
1030for key, value in pairs(object) do 995for key, value in pairs(object) do
1031 print(key, value) 996 print(key, value)
1032end 997end
1033do 998local _list_0 = items
1034 local _list_0 = items 999local _max_0 = 4
1035 local _max_0 = 4 1000for _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
1040end 1003end
1041local _list_0 = items 1004local _list_0 = items
1042for _index_0 = 1, #_list_0 do 1005for _index_0 = 1, #_list_0 do
@@ -1047,19 +1010,17 @@ for j = 1, 10, 3 do
1047 print(j) 1010 print(j)
1048end 1011end
1049local doubled_evens 1012local doubled_evens
1050do 1013local _accum_0 = { }
1051 local _accum_0 = { } 1014local _len_0 = 1
1052 local _len_0 = 1 1015for 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
1062end 1022end
1023doubled_evens = _accum_0
1063local func_a 1024local func_a
1064func_a = function() 1025func_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}
1119local odds 1080local odds
1120do 1081local _accum_0 = { }
1121 local _accum_0 = { } 1082local _len_0 = 1
1122 local _len_0 = 1 1083for _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::
1133end 1091end
1092odds = _accum_0
1134local have_coins = false 1093local have_coins = false
1135if have_coins then 1094if have_coins then
1136 print("有硬币") 1095 print("有硬币")
@@ -1222,15 +1181,13 @@ else
1222 next_number = error("数字数得太大了!") 1181 next_number = error("数字数得太大了!")
1223end 1182end
1224local msg 1183local msg
1225do 1184local _exp_0 = math.random(1, 5)
1226 local _exp_0 = math.random(1, 5) 1185if 1 == _exp_0 then
1227 if 1 == _exp_0 then 1186 msg = "你很幸运"
1228 msg = "你很幸运" 1187elseif 2 == _exp_0 then
1229 elseif 2 == _exp_0 then 1188 msg = "你差点很幸运"
1230 msg = "你差点很幸运" 1189else
1231 else 1190 msg = "不太幸运"
1232 msg = "不太幸运"
1233 end
1234end 1191end
1235do 1192do
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
1242end 1199end
1243do 1200local _exp_0 = math.random(1, 5)
1244 local _exp_0 = math.random(1, 5) 1201if 1 == _exp_0 then
1245 if 1 == _exp_0 then 1202 print("你很幸运")
1246 print("你很幸运") 1203else
1247 else 1204 print("不太幸运")
1248 print("不太幸运")
1249 end
1250end 1205end
1251local items = { 1206local items = {
1252 { 1207 {
@@ -1260,25 +1215,23 @@ local items = {
1260} 1215}
1261for _index_0 = 1, #items do 1216for _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
1291if y == nil then 1244if y == nil then
1292 y = 200 1245 y = 200
1293end 1246end
1294do 1247local _type_0 = type(item)
1295 local _type_0 = type(item) 1248local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1296 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 1249if _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))
1320end 1271end
1321local Inventory 1272local Inventory
1322do 1273local _class_0
1323 local _class_0 1274local _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) 1284if _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
1353end 1286end
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
1302Inventory = _class_0
1354local inv = Inventory() 1303local inv = Inventory()
1355inv:add_item("t-shirt") 1304inv:add_item("t-shirt")
1356inv:add_item("pants") 1305inv:add_item("pants")
@@ -1391,82 +1340,78 @@ for _index_0 = 1, #_list_0 do
1391 print(item) 1340 print(item)
1392end 1341end
1393local Person 1342local Person
1394do 1343local _class_0
1395 local _class_0 1344local _base_0 = { }
1396 local _base_0 = { } 1345if _base_0.__index == nil then
1397 if _base_0.__index == nil then 1346 _base_0.__index = _base_0
1398 _base_0.__index = _base_0 1347end
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 = { } 1363Person = _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
1416end
1417local BackPack 1364local BackPack
1418do 1365local _class_0
1419 local _class_0 1366local _parent_0 = Inventory
1420 local _parent_0 = Inventory 1367local _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 1376for _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) 1380end
1439 _class_0 = setmetatable({ 1381if _base_0.__index == nil then
1440 __init = function(self, ...) 1382 _base_0.__index = _base_0
1441 return _class_0.__parent.__init(self, ...) 1383end
1442 end, 1384setmetatable(_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
1411if _parent_0.__inherited then
1412 _parent_0.__inherited(_parent_0, _class_0)
1469end 1413end
1414BackPack = _class_0
1470local Shelf 1415local Shelf
1471do 1416do
1472 local _class_0 1417 local _class_0
@@ -1494,102 +1439,98 @@ do
1494 Shelf = _class_0 1439 Shelf = _class_0
1495end 1440end
1496local Cupboard 1441local Cupboard
1497do 1442local _class_0
1498 local _class_0 1443local _parent_0 = Shelf
1499 local _parent_0 = Shelf 1444local _base_0 = { }
1500 local _base_0 = { } 1445for _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 1449end
1505 end 1450if _base_0.__index == nil then
1506 if _base_0.__index == nil then 1451 _base_0.__index = _base_0
1507 _base_0.__index = _base_0 1452end
1508 end 1453setmetatable(_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
1480if _parent_0.__inherited then
1481 _parent_0.__inherited(_parent_0, _class_0)
1540end 1482end
1483Cupboard = _class_0
1541local MyClass 1484local MyClass
1542do 1485local _class_0
1543 local _class_0 1486local _parent_0 = ParentClass
1544 local _parent_0 = ParentClass 1487local _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 } 1495for _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 1499end
1557 end 1500if _base_0.__index == nil then
1558 if _base_0.__index == nil then 1501 _base_0.__index = _base_0
1559 _base_0.__index = _base_0 1502end
1560 end 1503setmetatable(_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
1530if _parent_0.__inherited then
1531 _parent_0.__inherited(_parent_0, _class_0)
1592end 1532end
1533MyClass = _class_0
1593local b = BackPack() 1534local b = BackPack()
1594assert(b.__class == BackPack) 1535assert(b.__class == BackPack)
1595print(BackPack.size) 1536print(BackPack.size)
@@ -1653,61 +1594,57 @@ Counter()
1653print(Counter.count) 1594print(Counter.count)
1654self.__class:hello(1, 2, 3, 4) 1595self.__class:hello(1, 2, 3, 4)
1655local Things 1596local Things
1656do 1597local _class_0
1657 local _class_0 1598local _base_0 = { }
1658 local _base_0 = { } 1599if _base_0.__index == nil then
1659 if _base_0.__index == nil then 1600 _base_0.__index = _base_0
1660 _base_0.__index = _base_0 1601end
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, 1615local self = _class_0;
1665 __name = "Things" 1616self.class_var = "hello world"
1666 }, { 1617Things = _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
1678end
1679local MoreThings 1618local MoreThings
1680do 1619local _class_0
1681 local _class_0 1620local secret, log
1682 local secret, log 1621local _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, 1626if _base_0.__index == nil then
1693 __base = _base_0, 1627 _base_0.__index = _base_0
1694 __name = "MoreThings" 1628end
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
1642local self = _class_0;
1643secret = 123
1644log = function(msg)
1645 return print("LOG:", msg)
1710end 1646end
1647MoreThings = _class_0
1711assert(self == self) 1648assert(self == self)
1712assert(self.__class == self.__class) 1649assert(self.__class == self.__class)
1713local some_instance_method 1650local 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
1743end 1680end
1744do 1681local _class_0
1745 local _class_0 1682local _base_0 = { }
1746 local _base_0 = { } 1683if _base_0.__index == nil then
1747 if _base_0.__index == nil then 1684 _base_0.__index = _base_0
1748 _base_0.__index = _base_0 1685end
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 1704Something = _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
1769end
1770local new 1705local new
1771new = function(self, fieldA, fieldB) 1706new = function(self, fieldA, fieldB)
1772 self.fieldA = fieldA 1707 self.fieldA = fieldA
@@ -1777,33 +1712,31 @@ local obj = new({ }, 123, "abc")
1777print(obj) 1712print(obj)
1778local x 1713local x
1779local Bucket 1714local Bucket
1780do 1715local _class_0
1781 local _class_0 1716local _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, 1722if _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
1806end 1724end
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
1738Bucket = _class_0
1739x = _class_0
1807local BigBucket 1740local BigBucket
1808do 1741do
1809 local _class_0 1742 local _class_0
@@ -1855,27 +1788,25 @@ do
1855end 1788end
1856assert(Bucket.__name == "BigBucket") 1789assert(Bucket.__name == "BigBucket")
1857local x 1790local x
1858do 1791local _class_0
1859 local _class_0 1792local _base_0 = { }
1860 local _base_0 = { } 1793if _base_0.__index == nil then
1861 if _base_0.__index == nil then 1794 _base_0.__index = _base_0
1862 _base_0.__index = _base_0 1795end
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, 1809x = _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
1878end
1879local MyIndex = { 1810local MyIndex = {
1880 __index = { 1811 __index = {
1881 var = 1 1812 var = 1
@@ -1958,19 +1889,15 @@ end
1958local y = Y() 1889local y = Y()
1959y:func() 1890y:func()
1960assert(y.__class.__parent ~= X) 1891assert(y.__class.__parent ~= X)
1961do 1892local _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() 1896print(_with_0.name)
1966 print(_with_0.name)
1967end
1968local file 1897local file
1969do 1898local _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") 1900file = _with_0
1972 file = _with_0
1973end
1974local create_person 1901local create_person
1975create_person = function(name, relatives) 1902create_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})
1916local str = "你好"
1917print("原始:", str)
1918print("大写:", str:upper())
1919local _with_0 = tb
1920_with_0[1] = 1
1921print(_with_0[2])
1989do 1922do
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
1993end
1994do
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"
2004end 1926end
1927_with_0[#_with_0 + 1] = "abc"
2005do 1928do
2006 local var = "hello" 1929 local var = "hello"
2007 print(var) 1930 print(var)
@@ -2118,13 +2041,18 @@ _module_0["🌛"] = _ud83c_udf1b
2118return _module_0 2041return _module_0
2119local area = 6.2831853071796 * 5 2042local area = 6.2831853071796 * 5
2120print('你好 世界') 2043print('你好 世界')
2121assert(item ~= nil) 2044do
2045 assert(item ~= nil)
2046end
2122local value = item 2047local value = item
2123if (f1() and f2() and f3()) then 2048if (f1() and f2() and f3()) then
2124 print("OK") 2049 print("OK")
2125end 2050end
2051do
2052 local funcA
2053 funcA = function() end
2054end
2126local funcA 2055local funcA
2127funcA = function() end
2128funcA = function() 2056funcA = function()
2129 return "访问月之脚本定义的变量" 2057 return "访问月之脚本定义的变量"
2130end 2058end
@@ -2218,28 +2146,26 @@ local b = {
2218 y = 1 2146 y = 1
2219} 2147}
2220local merge 2148local merge
2221do 2149local _tab_0 = { }
2222 local _tab_0 = { } 2150local _idx_0 = 1
2223 local _idx_0 = 1 2151for _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 2158end
2233 for _key_0, _value_0 in pairs(b) do 2159local _idx_1 = 1
2234 if _idx_1 == _key_0 then 2160for _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
2242end 2167end
2168merge = _tab_0
2243local mt = { } 2169local mt = { }
2244local add 2170local add
2245add = function(self, right) 2171add = function(self, right)
@@ -2331,12 +2257,10 @@ end
2331if print and (x ~= nil) then 2257if print and (x ~= nil) then
2332 print(x) 2258 print(x)
2333end 2259end
2334do 2260local _with_0 = io.open("test.txt", "w")
2335 local _with_0 = io.open("test.txt", "w") 2261if _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
2340end 2264end
2341print("你好") 2265print("你好")
2342print(1, 2) 2266print(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
2420end 2342end
2421do 2343do
2422 local module = require('module') 2344 local module = require('module')
@@ -2455,29 +2377,27 @@ y = function()
2455end 2377end
2456_module_0["y"] = y 2378_module_0["y"] = y
2457local Something 2379local Something
2458do 2380local _class_0
2459 local _class_0 2381local _base_0 = {
2460 local _base_0 = { 2382 umm = "cool"
2461 umm = "cool" 2383}
2462 } 2384if _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
2480end 2386end
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
2400Something = _class_0
2481_module_0["Something"] = Something 2401_module_0["Something"] = Something
2482return _module_0 2402return _module_0
2483local _module_0 = { } 2403local _module_0 = { }
@@ -2508,11 +2428,9 @@ if this then
2508else 2428else
2509 _module_0[#_module_0 + 1] = 456 2429 _module_0[#_module_0 + 1] = 456
2510end 2430end
2511do 2431local _with_0 = tmp
2512 local _with_0 = tmp 2432local j = 2000
2513 local j = 2000 2433_module_0[#_module_0 + 1] = _with_0
2514 _module_0[#_module_0 + 1] = _with_0
2515end
2516return _module_0 2434return _module_0
2517local _module_0 = nil 2435local _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)
2651end 2569end
2652do 2570local user = database.find_user("moon")
2653 local user = database.find_user("moon") 2571if user then
2654 if user then 2572 print(user.name)
2655 print(user.name)
2656 end
2657end 2573end
2658do 2574local hello = os.getenv("hello")
2659 local hello = os.getenv("hello") 2575if hello then
2660 if hello then 2576 print("你有 hello", hello)
2661 print("你有 hello", hello) 2577else
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
2672end 2584end
2673do 2585do
@@ -2924,40 +2836,34 @@ local items = {
2924 4 2836 4
2925} 2837}
2926local doubled 2838local doubled
2927do 2839local _accum_0 = { }
2928 local _accum_0 = { } 2840local _len_0 = 1
2929 local _len_0 = 1 2841for 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
2935end 2844end
2845doubled = _accum_0
2936local iter = ipairs(items) 2846local iter = ipairs(items)
2937local slice 2847local slice
2938do 2848local _accum_0 = { }
2939 local _accum_0 = { } 2849local _len_0 = 1
2940 local _len_0 = 1 2850for 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
2948end 2855end
2856slice = _accum_0
2949local doubled 2857local doubled
2950do 2858local _accum_0 = { }
2951 local _accum_0 = { } 2859local _len_0 = 1
2952 local _len_0 = 1 2860local _list_0 = items
2953 local _list_0 = items 2861for _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
2960end 2865end
2866doubled = _accum_0
2961local x_coords = { 2867local x_coords = {
2962 4, 2868 4,
2963 5, 2869 5,
@@ -2970,57 +2876,49 @@ local y_coords = {
2970 3 2876 3
2971} 2877}
2972local points 2878local points
2973do 2879local _accum_0 = { }
2974 local _accum_0 = { } 2880local _len_0 = 1
2975 local _len_0 = 1 2881for _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
2988end 2891end
2892points = _accum_0
2989local evens 2893local evens
2990do 2894local _accum_0 = { }
2991 local _accum_0 = { } 2895local _len_0 = 1
2992 local _len_0 = 1 2896for 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
3000end 2901end
2902evens = _accum_0
3001local thing = { 2903local thing = {
3002 color = "red", 2904 color = "red",
3003 name = "fast", 2905 name = "fast",
3004 width = 123 2906 width = 123
3005} 2907}
3006local thing_copy 2908local thing_copy
3007do 2909local _tbl_0 = { }
3008 local _tbl_0 = { } 2910for 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
3013end 2912end
2913thing_copy = _tbl_0
3014local no_color 2914local no_color
3015do 2915local _tbl_0 = { }
3016 local _tbl_0 = { } 2916for 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
3023end 2920end
2921no_color = _tbl_0
3024local numbers = { 2922local numbers = {
3025 1, 2923 1,
3026 2, 2924 2,
@@ -3028,14 +2926,12 @@ local numbers = {
3028 4 2926 4
3029} 2927}
3030local sqrts 2928local sqrts
3031do 2929local _tbl_0 = { }
3032 local _tbl_0 = { } 2930for _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
3038end 2933end
2934sqrts = _tbl_0
3039local tuples = { 2935local tuples = {
3040 { 2936 {
3041 "hello", 2937 "hello",
@@ -3047,52 +2943,44 @@ local tuples = {
3047 } 2943 }
3048} 2944}
3049local tbl 2945local tbl
3050do 2946local _tbl_0 = { }
3051 local _tbl_0 = { } 2947for _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
3058end 2951end
2952tbl = _tbl_0
3059local slice 2953local slice
3060do 2954local _accum_0 = { }
3061 local _accum_0 = { } 2955local _len_0 = 1
3062 local _len_0 = 1 2956local _list_0 = items
3063 local _list_0 = items 2957local _max_0 = 5
3064 local _max_0 = 5 2958for _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
3071end 2962end
2963slice = _accum_0
3072local slice 2964local slice
3073do 2965local _accum_0 = { }
3074 local _accum_0 = { } 2966local _len_0 = 1
3075 local _len_0 = 1 2967local _list_0 = items
3076 local _list_0 = items 2968for _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
3083end 2972end
2973slice = _accum_0
3084local slice 2974local slice
3085do 2975local _accum_0 = { }
3086 local _accum_0 = { } 2976local _len_0 = 1
3087 local _len_0 = 1 2977local _list_0 = items
3088 local _list_0 = items 2978for _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
3095end 2982end
2983slice = _accum_0
3096for i = 10, 20 do 2984for i = 10, 20 do
3097 print(i) 2985 print(i)
3098end 2986end
@@ -3102,13 +2990,11 @@ end
3102for key, value in pairs(object) do 2990for key, value in pairs(object) do
3103 print(key, value) 2991 print(key, value)
3104end 2992end
3105do 2993local _list_0 = items
3106 local _list_0 = items 2994local _max_0 = 4
3107 local _max_0 = 4 2995for _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
3112end 2998end
3113local _list_0 = items 2999local _list_0 = items
3114for _index_0 = 1, #_list_0 do 3000for _index_0 = 1, #_list_0 do
@@ -3119,19 +3005,17 @@ for j = 1, 10, 3 do
3119 print(j) 3005 print(j)
3120end 3006end
3121local doubled_evens 3007local doubled_evens
3122do 3008local _accum_0 = { }
3123 local _accum_0 = { } 3009local _len_0 = 1
3124 local _len_0 = 1 3010for 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
3134end 3017end
3018doubled_evens = _accum_0
3135local func_a 3019local func_a
3136func_a = function() 3020func_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}
3191local odds 3075local odds
3192do 3076local _accum_0 = { }
3193 local _accum_0 = { } 3077local _len_0 = 1
3194 local _len_0 = 1 3078for _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::
3205end 3086end
3087odds = _accum_0
3206local have_coins = false 3088local have_coins = false
3207if have_coins then 3089if have_coins then
3208 print("有硬币") 3090 print("有硬币")
@@ -3294,15 +3176,13 @@ else
3294 next_number = error("数字数得太大了!") 3176 next_number = error("数字数得太大了!")
3295end 3177end
3296local msg 3178local msg
3297do 3179local _exp_0 = math.random(1, 5)
3298 local _exp_0 = math.random(1, 5) 3180if 1 == _exp_0 then
3299 if 1 == _exp_0 then 3181 msg = "你很幸运"
3300 msg = "你很幸运" 3182elseif 2 == _exp_0 then
3301 elseif 2 == _exp_0 then 3183 msg = "你差点很幸运"
3302 msg = "你差点很幸运" 3184else
3303 else 3185 msg = "不太幸运"
3304 msg = "不太幸运"
3305 end
3306end 3186end
3307do 3187do
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
3314end 3194end
3315do 3195local _exp_0 = math.random(1, 5)
3316 local _exp_0 = math.random(1, 5) 3196if 1 == _exp_0 then
3317 if 1 == _exp_0 then 3197 print("你很幸运")
3318 print("你很幸运") 3198else
3319 else 3199 print("不太幸运")
3320 print("不太幸运")
3321 end
3322end 3200end
3323local items = { 3201local items = {
3324 { 3202 {
@@ -3332,25 +3210,23 @@ local items = {
3332} 3210}
3333for _index_0 = 1, #items do 3211for _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
3363if y == nil then 3239if y == nil then
3364 y = 200 3240 y = 200
3365end 3241end
3366do 3242local _type_0 = type(item)
3367 local _type_0 = type(item) 3243local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3368 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 3244if _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))
3392end 3266end
3393local Inventory 3267local Inventory
3394do 3268local _class_0
3395 local _class_0 3269local _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) 3279if _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
3425end 3281end
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
3297Inventory = _class_0
3426local inv = Inventory() 3298local inv = Inventory()
3427inv:add_item("t-shirt") 3299inv:add_item("t-shirt")
3428inv:add_item("pants") 3300inv:add_item("pants")
@@ -3463,82 +3335,78 @@ for _index_0 = 1, #_list_0 do
3463 print(item) 3335 print(item)
3464end 3336end
3465local Person 3337local Person
3466do 3338local _class_0
3467 local _class_0 3339local _base_0 = { }
3468 local _base_0 = { } 3340if _base_0.__index == nil then
3469 if _base_0.__index == nil then 3341 _base_0.__index = _base_0
3470 _base_0.__index = _base_0 3342end
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 = { } 3358Person = _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
3488end
3489local BackPack 3359local BackPack
3490do 3360local _class_0
3491 local _class_0 3361local _parent_0 = Inventory
3492 local _parent_0 = Inventory 3362local _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 3371for _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) 3375end
3511 _class_0 = setmetatable({ 3376if _base_0.__index == nil then
3512 __init = function(self, ...) 3377 _base_0.__index = _base_0
3513 return _class_0.__parent.__init(self, ...) 3378end
3514 end, 3379setmetatable(_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
3406if _parent_0.__inherited then
3407 _parent_0.__inherited(_parent_0, _class_0)
3541end 3408end
3409BackPack = _class_0
3542local Shelf 3410local Shelf
3543do 3411do
3544 local _class_0 3412 local _class_0
@@ -3566,102 +3434,98 @@ do
3566 Shelf = _class_0 3434 Shelf = _class_0
3567end 3435end
3568local Cupboard 3436local Cupboard
3569do 3437local _class_0
3570 local _class_0 3438local _parent_0 = Shelf
3571 local _parent_0 = Shelf 3439local _base_0 = { }
3572 local _base_0 = { } 3440for _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 3444end
3577 end 3445if _base_0.__index == nil then
3578 if _base_0.__index == nil then 3446 _base_0.__index = _base_0
3579 _base_0.__index = _base_0 3447end
3580 end 3448setmetatable(_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
3475if _parent_0.__inherited then
3476 _parent_0.__inherited(_parent_0, _class_0)
3612end 3477end
3478Cupboard = _class_0
3613local MyClass 3479local MyClass
3614do 3480local _class_0
3615 local _class_0 3481local _parent_0 = ParentClass
3616 local _parent_0 = ParentClass 3482local _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 } 3490for _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 3494end
3629 end 3495if _base_0.__index == nil then
3630 if _base_0.__index == nil then 3496 _base_0.__index = _base_0
3631 _base_0.__index = _base_0 3497end
3632 end 3498setmetatable(_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
3525if _parent_0.__inherited then
3526 _parent_0.__inherited(_parent_0, _class_0)
3664end 3527end
3528MyClass = _class_0
3665local b = BackPack() 3529local b = BackPack()
3666assert(b.__class == BackPack) 3530assert(b.__class == BackPack)
3667print(BackPack.size) 3531print(BackPack.size)
@@ -3725,61 +3589,57 @@ Counter()
3725print(Counter.count) 3589print(Counter.count)
3726self.__class:hello(1, 2, 3, 4) 3590self.__class:hello(1, 2, 3, 4)
3727local Things 3591local Things
3728do 3592local _class_0
3729 local _class_0 3593local _base_0 = { }
3730 local _base_0 = { } 3594if _base_0.__index == nil then
3731 if _base_0.__index == nil then 3595 _base_0.__index = _base_0
3732 _base_0.__index = _base_0 3596end
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, 3610local self = _class_0;
3737 __name = "Things" 3611self.class_var = "hello world"
3738 }, { 3612Things = _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
3750end
3751local MoreThings 3613local MoreThings
3752do 3614local _class_0
3753 local _class_0 3615local secret, log
3754 local secret, log 3616local _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, 3621if _base_0.__index == nil then
3765 __base = _base_0, 3622 _base_0.__index = _base_0
3766 __name = "MoreThings" 3623end
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
3637local self = _class_0;
3638secret = 123
3639log = function(msg)
3640 return print("LOG:", msg)
3782end 3641end
3642MoreThings = _class_0
3783assert(self == self) 3643assert(self == self)
3784assert(self.__class == self.__class) 3644assert(self.__class == self.__class)
3785local some_instance_method 3645local 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
3815end 3675end
3816do 3676local _class_0
3817 local _class_0 3677local _base_0 = { }
3818 local _base_0 = { } 3678if _base_0.__index == nil then
3819 if _base_0.__index == nil then 3679 _base_0.__index = _base_0
3820 _base_0.__index = _base_0 3680end
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 3699Something = _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
3841end
3842local new 3700local new
3843new = function(self, fieldA, fieldB) 3701new = function(self, fieldA, fieldB)
3844 self.fieldA = fieldA 3702 self.fieldA = fieldA
@@ -3849,33 +3707,31 @@ local obj = new({ }, 123, "abc")
3849print(obj) 3707print(obj)
3850local x 3708local x
3851local Bucket 3709local Bucket
3852do 3710local _class_0
3853 local _class_0 3711local _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, 3717if _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
3878end 3719end
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
3733Bucket = _class_0
3734x = _class_0
3879local BigBucket 3735local BigBucket
3880do 3736do
3881 local _class_0 3737 local _class_0
@@ -3927,27 +3783,25 @@ do
3927end 3783end
3928assert(Bucket.__name == "BigBucket") 3784assert(Bucket.__name == "BigBucket")
3929local x 3785local x
3930do 3786local _class_0
3931 local _class_0 3787local _base_0 = { }
3932 local _base_0 = { } 3788if _base_0.__index == nil then
3933 if _base_0.__index == nil then 3789 _base_0.__index = _base_0
3934 _base_0.__index = _base_0 3790end
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, 3804x = _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
3950end
3951local MyIndex = { 3805local MyIndex = {
3952 __index = { 3806 __index = {
3953 var = 1 3807 var = 1
@@ -4030,19 +3884,15 @@ end
4030local y = Y() 3884local y = Y()
4031y:func() 3885y:func()
4032assert(y.__class.__parent ~= X) 3886assert(y.__class.__parent ~= X)
4033do 3887local _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() 3891print(_with_0.name)
4038 print(_with_0.name)
4039end
4040local file 3892local file
4041do 3893local _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") 3895file = _with_0
4044 file = _with_0
4045end
4046local create_person 3896local create_person
4047create_person = function(name, relatives) 3897create_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})
4061do 3911local str = "你好"
4062 local str = "你好" 3912print("原始:", str)
4063 print("原始:", str) 3913print("大写:", str:upper())
4064 print("大写:", str:upper()) 3914local _with_0 = tb
4065end 3915_with_0[1] = 1
4066do 3916print(_with_0[2])
4067 local _with_0 = tb 3917do
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] 3921end
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"
4076end
4077do 3923do
4078 local var = "hello" 3924 local var = "hello"
4079 print(var) 3925 print(var)