aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs/codes_from_doc.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.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.lua')
-rw-r--r--spec/outputs/codes_from_doc.lua2250
1 files changed, 1048 insertions, 1202 deletions
diff --git a/spec/outputs/codes_from_doc.lua b/spec/outputs/codes_from_doc.lua
index 1bcc587..1f593db 100644
--- a/spec/outputs/codes_from_doc.lua
+++ b/spec/outputs/codes_from_doc.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('hello world') 48print('hello world')
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 "assign the Yue defined variable" 62 return "assign the Yue defined variable"
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("hello")
265 _with_0:write("hello") 268 _with_0:close()
266 _with_0:close()
267 end
268end 269end
269print("hello") 270print("hello")
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("You have hello", hello)
589 print("You have hello", hello) 582else
583 local world = os.getenv("world")
584 if world then
585 print("you have world", world)
590 else 586 else
591 do 587 print("nothing :(")
592 local world = os.getenv("world")
593 if world then
594 print("you have world", world)
595 else
596 print("nothing :(")
597 end
598 end
599 end 588 end
600end 589end
601do 590do
@@ -858,40 +847,34 @@ local items = {
858 4 847 4
859} 848}
860local doubled 849local doubled
861do 850local _accum_0 = { }
862 local _accum_0 = { } 851local _len_0 = 1
863 local _len_0 = 1 852for i, item in ipairs(items) do
864 for i, item in ipairs(items) do 853 _accum_0[_len_0] = item * 2
865 _accum_0[_len_0] = item * 2 854 _len_0 = _len_0 + 1
866 _len_0 = _len_0 + 1
867 end
868 doubled = _accum_0
869end 855end
856doubled = _accum_0
870local iter = ipairs(items) 857local iter = ipairs(items)
871local slice 858local slice
872do 859local _accum_0 = { }
873 local _accum_0 = { } 860local _len_0 = 1
874 local _len_0 = 1 861for i, item in iter do
875 for i, item in iter do 862 if i > 1 and i < 3 then
876 if i > 1 and i < 3 then 863 _accum_0[_len_0] = item
877 _accum_0[_len_0] = item 864 _len_0 = _len_0 + 1
878 _len_0 = _len_0 + 1
879 end
880 end 865 end
881 slice = _accum_0
882end 866end
867slice = _accum_0
883local doubled 868local doubled
884do 869local _accum_0 = { }
885 local _accum_0 = { } 870local _len_0 = 1
886 local _len_0 = 1 871local _list_0 = items
887 local _list_0 = items 872for _index_0 = 1, #_list_0 do
888 for _index_0 = 1, #_list_0 do 873 local item = _list_0[_index_0]
889 local item = _list_0[_index_0] 874 _accum_0[_len_0] = item * 2
890 _accum_0[_len_0] = item * 2 875 _len_0 = _len_0 + 1
891 _len_0 = _len_0 + 1
892 end
893 doubled = _accum_0
894end 876end
877doubled = _accum_0
895local x_coords = { 878local x_coords = {
896 4, 879 4,
897 5, 880 5,
@@ -904,57 +887,49 @@ local y_coords = {
904 3 887 3
905} 888}
906local points 889local points
907do 890local _accum_0 = { }
908 local _accum_0 = { } 891local _len_0 = 1
909 local _len_0 = 1 892for _index_0 = 1, #x_coords do
910 for _index_0 = 1, #x_coords do 893 local x = x_coords[_index_0]
911 local x = x_coords[_index_0] 894 for _index_1 = 1, #y_coords do
912 for _index_1 = 1, #y_coords do 895 local y = y_coords[_index_1]
913 local y = y_coords[_index_1] 896 _accum_0[_len_0] = {
914 _accum_0[_len_0] = { 897 x,
915 x, 898 y
916 y 899 }
917 } 900 _len_0 = _len_0 + 1
918 _len_0 = _len_0 + 1
919 end
920 end 901 end
921 points = _accum_0
922end 902end
903points = _accum_0
923local evens 904local evens
924do 905local _accum_0 = { }
925 local _accum_0 = { } 906local _len_0 = 1
926 local _len_0 = 1 907for i = 1, 100 do
927 for i = 1, 100 do 908 if i % 2 == 0 then
928 if i % 2 == 0 then 909 _accum_0[_len_0] = i
929 _accum_0[_len_0] = i 910 _len_0 = _len_0 + 1
930 _len_0 = _len_0 + 1
931 end
932 end 911 end
933 evens = _accum_0
934end 912end
913evens = _accum_0
935local thing = { 914local thing = {
936 color = "red", 915 color = "red",
937 name = "fast", 916 name = "fast",
938 width = 123 917 width = 123
939} 918}
940local thing_copy 919local thing_copy
941do 920local _tbl_0 = { }
942 local _tbl_0 = { } 921for k, v in pairs(thing) do
943 for k, v in pairs(thing) do 922 _tbl_0[k] = v
944 _tbl_0[k] = v
945 end
946 thing_copy = _tbl_0
947end 923end
924thing_copy = _tbl_0
948local no_color 925local no_color
949do 926local _tbl_0 = { }
950 local _tbl_0 = { } 927for k, v in pairs(thing) do
951 for k, v in pairs(thing) do 928 if k ~= "color" then
952 if k ~= "color" then 929 _tbl_0[k] = v
953 _tbl_0[k] = v
954 end
955 end 930 end
956 no_color = _tbl_0
957end 931end
932no_color = _tbl_0
958local numbers = { 933local numbers = {
959 1, 934 1,
960 2, 935 2,
@@ -962,14 +937,12 @@ local numbers = {
962 4 937 4
963} 938}
964local sqrts 939local sqrts
965do 940local _tbl_0 = { }
966 local _tbl_0 = { } 941for _index_0 = 1, #numbers do
967 for _index_0 = 1, #numbers do 942 local i = numbers[_index_0]
968 local i = numbers[_index_0] 943 _tbl_0[i] = math.sqrt(i)
969 _tbl_0[i] = math.sqrt(i)
970 end
971 sqrts = _tbl_0
972end 944end
945sqrts = _tbl_0
973local tuples = { 946local tuples = {
974 { 947 {
975 "hello", 948 "hello",
@@ -981,52 +954,44 @@ local tuples = {
981 } 954 }
982} 955}
983local tbl 956local tbl
984do 957local _tbl_0 = { }
985 local _tbl_0 = { } 958for _index_0 = 1, #tuples do
986 for _index_0 = 1, #tuples do 959 local tuple = tuples[_index_0]
987 local tuple = tuples[_index_0] 960 local _key_0, _val_0 = unpack(tuple)
988 local _key_0, _val_0 = unpack(tuple) 961 _tbl_0[_key_0] = _val_0
989 _tbl_0[_key_0] = _val_0
990 end
991 tbl = _tbl_0
992end 962end
963tbl = _tbl_0
993local slice 964local slice
994do 965local _accum_0 = { }
995 local _accum_0 = { } 966local _len_0 = 1
996 local _len_0 = 1 967local _list_0 = items
997 local _list_0 = items 968local _max_0 = 5
998 local _max_0 = 5 969for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
999 for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do 970 local item = _list_0[_index_0]
1000 local item = _list_0[_index_0] 971 _accum_0[_len_0] = item
1001 _accum_0[_len_0] = item 972 _len_0 = _len_0 + 1
1002 _len_0 = _len_0 + 1
1003 end
1004 slice = _accum_0
1005end 973end
974slice = _accum_0
1006local slice 975local slice
1007do 976local _accum_0 = { }
1008 local _accum_0 = { } 977local _len_0 = 1
1009 local _len_0 = 1 978local _list_0 = items
1010 local _list_0 = items 979for _index_0 = 2, #_list_0 do
1011 for _index_0 = 2, #_list_0 do 980 local item = _list_0[_index_0]
1012 local item = _list_0[_index_0] 981 _accum_0[_len_0] = item
1013 _accum_0[_len_0] = item 982 _len_0 = _len_0 + 1
1014 _len_0 = _len_0 + 1
1015 end
1016 slice = _accum_0
1017end 983end
984slice = _accum_0
1018local slice 985local slice
1019do 986local _accum_0 = { }
1020 local _accum_0 = { } 987local _len_0 = 1
1021 local _len_0 = 1 988local _list_0 = items
1022 local _list_0 = items 989for _index_0 = 1, #_list_0, 2 do
1023 for _index_0 = 1, #_list_0, 2 do 990 local item = _list_0[_index_0]
1024 local item = _list_0[_index_0] 991 _accum_0[_len_0] = item
1025 _accum_0[_len_0] = item 992 _len_0 = _len_0 + 1
1026 _len_0 = _len_0 + 1
1027 end
1028 slice = _accum_0
1029end 993end
994slice = _accum_0
1030for i = 10, 20 do 995for i = 10, 20 do
1031 print(i) 996 print(i)
1032end 997end
@@ -1036,13 +1001,11 @@ end
1036for key, value in pairs(object) do 1001for key, value in pairs(object) do
1037 print(key, value) 1002 print(key, value)
1038end 1003end
1039do 1004local _list_0 = items
1040 local _list_0 = items 1005local _max_0 = 4
1041 local _max_0 = 4 1006for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
1042 for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do 1007 local item = _list_0[_index_0]
1043 local item = _list_0[_index_0] 1008 print(item)
1044 print(item)
1045 end
1046end 1009end
1047local _list_0 = items 1010local _list_0 = items
1048for _index_0 = 1, #_list_0 do 1011for _index_0 = 1, #_list_0 do
@@ -1053,19 +1016,17 @@ for j = 1, 10, 3 do
1053 print(j) 1016 print(j)
1054end 1017end
1055local doubled_evens 1018local doubled_evens
1056do 1019local _accum_0 = { }
1057 local _accum_0 = { } 1020local _len_0 = 1
1058 local _len_0 = 1 1021for i = 1, 20 do
1059 for i = 1, 20 do 1022 if i % 2 == 0 then
1060 if i % 2 == 0 then 1023 _accum_0[_len_0] = i * 2
1061 _accum_0[_len_0] = i * 2 1024 else
1062 else 1025 _accum_0[_len_0] = i
1063 _accum_0[_len_0] = i
1064 end
1065 _len_0 = _len_0 + 1
1066 end 1026 end
1067 doubled_evens = _accum_0 1027 _len_0 = _len_0 + 1
1068end 1028end
1029doubled_evens = _accum_0
1069local func_a 1030local func_a
1070func_a = function() 1031func_a = function()
1071 for i = 1, 10 do 1032 for i = 1, 10 do
@@ -1123,20 +1084,18 @@ local my_numbers = {
1123 6 1084 6
1124} 1085}
1125local odds 1086local odds
1126do 1087local _accum_0 = { }
1127 local _accum_0 = { } 1088local _len_0 = 1
1128 local _len_0 = 1 1089for _index_0 = 1, #my_numbers do
1129 for _index_0 = 1, #my_numbers do 1090 local x = my_numbers[_index_0]
1130 local x = my_numbers[_index_0] 1091 if x % 2 == 1 then
1131 if x % 2 == 1 then 1092 goto _continue_0
1132 goto _continue_0
1133 end
1134 _accum_0[_len_0] = x
1135 _len_0 = _len_0 + 1
1136 ::_continue_0::
1137 end 1093 end
1138 odds = _accum_0 1094 _accum_0[_len_0] = x
1095 _len_0 = _len_0 + 1
1096 ::_continue_0::
1139end 1097end
1098odds = _accum_0
1140local have_coins = false 1099local have_coins = false
1141if have_coins then 1100if have_coins then
1142 print("Got coins") 1101 print("Got coins")
@@ -1228,15 +1187,13 @@ else
1228 next_number = error("can't count that high!") 1187 next_number = error("can't count that high!")
1229end 1188end
1230local msg 1189local msg
1231do 1190local _exp_0 = math.random(1, 5)
1232 local _exp_0 = math.random(1, 5) 1191if 1 == _exp_0 then
1233 if 1 == _exp_0 then 1192 msg = "you are lucky"
1234 msg = "you are lucky" 1193elseif 2 == _exp_0 then
1235 elseif 2 == _exp_0 then 1194 msg = "you are almost lucky"
1236 msg = "you are almost lucky" 1195else
1237 else 1196 msg = "not so lucky"
1238 msg = "not so lucky"
1239 end
1240end 1197end
1241do 1198do
1242 local _exp_0 = math.random(1, 5) 1199 local _exp_0 = math.random(1, 5)
@@ -1246,13 +1203,11 @@ do
1246 print("not so lucky") 1203 print("not so lucky")
1247 end 1204 end
1248end 1205end
1249do 1206local _exp_0 = math.random(1, 5)
1250 local _exp_0 = math.random(1, 5) 1207if 1 == _exp_0 then
1251 if 1 == _exp_0 then 1208 print("you are lucky")
1252 print("you are lucky") 1209else
1253 else 1210 print("not so lucky")
1254 print("not so lucky")
1255 end
1256end 1211end
1257local items = { 1212local items = {
1258 { 1213 {
@@ -1266,25 +1221,23 @@ local items = {
1266} 1221}
1267for _index_0 = 1, #items do 1222for _index_0 = 1, #items do
1268 local item = items[_index_0] 1223 local item = items[_index_0]
1269 do 1224 local _type_0 = type(item)
1270 local _type_0 = type(item) 1225 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1271 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 1226 local _match_0 = false
1272 local _match_0 = false 1227 if _tab_0 then
1273 if _tab_0 then 1228 local x = item.x
1274 local x = item.x 1229 local y = item.y
1275 local y = item.y 1230 if x ~= nil and y ~= nil then
1276 if x ~= nil and y ~= nil then 1231 _match_0 = true
1277 _match_0 = true 1232 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
1278 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
1279 end
1280 end 1233 end
1281 if not _match_0 then 1234 end
1282 if _tab_0 then 1235 if not _match_0 then
1283 local width = item.width 1236 if _tab_0 then
1284 local height = item.height 1237 local width = item.width
1285 if width ~= nil and height ~= nil then 1238 local height = item.height
1286 print("size " .. tostring(width) .. ", " .. tostring(height)) 1239 if width ~= nil and height ~= nil then
1287 end 1240 print("size " .. tostring(width) .. ", " .. tostring(height))
1288 end 1241 end
1289 end 1242 end
1290 end 1243 end
@@ -1297,66 +1250,62 @@ end
1297if y == nil then 1250if y == nil then
1298 y = 200 1251 y = 200
1299end 1252end
1300do 1253local _type_0 = type(item)
1301 local _type_0 = type(item) 1254local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1302 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 1255if _tab_0 then
1303 if _tab_0 then 1256 do
1304 do 1257 local _obj_0 = item.pos
1305 local _obj_0 = item.pos 1258 local _type_1 = type(_obj_0)
1306 local _type_1 = type(_obj_0) 1259 if "table" == _type_1 or "userdata" == _type_1 then
1307 if "table" == _type_1 or "userdata" == _type_1 then 1260 x = _obj_0.x
1308 x = _obj_0.x
1309 end
1310 end
1311 do
1312 local _obj_0 = item.pos
1313 local _type_1 = type(_obj_0)
1314 if "table" == _type_1 or "userdata" == _type_1 then
1315 y = _obj_0.y
1316 end
1317 end
1318 if x == nil then
1319 x = 50
1320 end 1261 end
1321 if y == nil then 1262 end
1322 y = 200 1263 do
1264 local _obj_0 = item.pos
1265 local _type_1 = type(_obj_0)
1266 if "table" == _type_1 or "userdata" == _type_1 then
1267 y = _obj_0.y
1323 end 1268 end
1324 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
1325 end 1269 end
1270 if x == nil then
1271 x = 50
1272 end
1273 if y == nil then
1274 y = 200
1275 end
1276 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
1326end 1277end
1327local Inventory 1278local Inventory
1328do 1279local _class_0
1329 local _class_0 1280local _base_0 = {
1330 local _base_0 = { 1281 add_item = function(self, name)
1331 add_item = function(self, name) 1282 if self.items[name] then
1332 if self.items[name] then 1283 local _obj_0 = self.items
1333 local _obj_0 = self.items 1284 _obj_0[name] = _obj_0[name] + 1
1334 _obj_0[name] = _obj_0[name] + 1 1285 else
1335 else 1286 self.items[name] = 1
1336 self.items[name] = 1
1337 end
1338 end 1287 end
1339 }
1340 if _base_0.__index == nil then
1341 _base_0.__index = _base_0
1342 end 1288 end
1343 _class_0 = setmetatable({ 1289}
1344 __init = function(self) 1290if _base_0.__index == nil then
1345 self.items = { } 1291 _base_0.__index = _base_0
1346 end,
1347 __base = _base_0,
1348 __name = "Inventory"
1349 }, {
1350 __index = _base_0,
1351 __call = function(cls, ...)
1352 local _self_0 = setmetatable({ }, _base_0)
1353 cls.__init(_self_0, ...)
1354 return _self_0
1355 end
1356 })
1357 _base_0.__class = _class_0
1358 Inventory = _class_0
1359end 1292end
1293_class_0 = setmetatable({
1294 __init = function(self)
1295 self.items = { }
1296 end,
1297 __base = _base_0,
1298 __name = "Inventory"
1299}, {
1300 __index = _base_0,
1301 __call = function(cls, ...)
1302 local _self_0 = setmetatable({ }, _base_0)
1303 cls.__init(_self_0, ...)
1304 return _self_0
1305 end
1306})
1307_base_0.__class = _class_0
1308Inventory = _class_0
1360local inv = Inventory() 1309local inv = Inventory()
1361inv:add_item("t-shirt") 1310inv:add_item("t-shirt")
1362inv:add_item("pants") 1311inv:add_item("pants")
@@ -1397,82 +1346,78 @@ for _index_0 = 1, #_list_0 do
1397 print(item) 1346 print(item)
1398end 1347end
1399local Person 1348local Person
1400do 1349local _class_0
1401 local _class_0 1350local _base_0 = { }
1402 local _base_0 = { } 1351if _base_0.__index == nil then
1403 if _base_0.__index == nil then 1352 _base_0.__index = _base_0
1404 _base_0.__index = _base_0 1353end
1354_class_0 = setmetatable({
1355 __init = function(self)
1356 self.clothes = { }
1357 end,
1358 __base = _base_0,
1359 __name = "Person"
1360}, {
1361 __index = _base_0,
1362 __call = function(cls, ...)
1363 local _self_0 = setmetatable({ }, _base_0)
1364 cls.__init(_self_0, ...)
1365 return _self_0
1405 end 1366 end
1406 _class_0 = setmetatable({ 1367})
1407 __init = function(self) 1368_base_0.__class = _class_0
1408 self.clothes = { } 1369Person = _class_0
1409 end,
1410 __base = _base_0,
1411 __name = "Person"
1412 }, {
1413 __index = _base_0,
1414 __call = function(cls, ...)
1415 local _self_0 = setmetatable({ }, _base_0)
1416 cls.__init(_self_0, ...)
1417 return _self_0
1418 end
1419 })
1420 _base_0.__class = _class_0
1421 Person = _class_0
1422end
1423local BackPack 1370local BackPack
1424do 1371local _class_0
1425 local _class_0 1372local _parent_0 = Inventory
1426 local _parent_0 = Inventory 1373local _base_0 = {
1427 local _base_0 = { 1374 size = 10,
1428 size = 10, 1375 add_item = function(self, name)
1429 add_item = function(self, name) 1376 if #self.items > size then
1430 if #self.items > size then 1377 error("backpack is full")
1431 error("backpack is full")
1432 end
1433 return _class_0.__parent.__base.add_item(self, name)
1434 end
1435 }
1436 for _key_0, _val_0 in pairs(_parent_0.__base) do
1437 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1438 _base_0[_key_0] = _val_0
1439 end 1378 end
1379 return _class_0.__parent.__base.add_item(self, name)
1440 end 1380 end
1441 if _base_0.__index == nil then 1381}
1442 _base_0.__index = _base_0 1382for _key_0, _val_0 in pairs(_parent_0.__base) do
1383 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1384 _base_0[_key_0] = _val_0
1443 end 1385 end
1444 setmetatable(_base_0, _parent_0.__base) 1386end
1445 _class_0 = setmetatable({ 1387if _base_0.__index == nil then
1446 __init = function(self, ...) 1388 _base_0.__index = _base_0
1447 return _class_0.__parent.__init(self, ...) 1389end
1448 end, 1390setmetatable(_base_0, _parent_0.__base)
1449 __base = _base_0, 1391_class_0 = setmetatable({
1450 __name = "BackPack", 1392 __init = function(self, ...)
1451 __parent = _parent_0 1393 return _class_0.__parent.__init(self, ...)
1452 }, { 1394 end,
1453 __index = function(cls, name) 1395 __base = _base_0,
1454 local val = rawget(_base_0, name) 1396 __name = "BackPack",
1455 if val == nil then 1397 __parent = _parent_0
1456 local parent = rawget(cls, "__parent") 1398}, {
1457 if parent then 1399 __index = function(cls, name)
1458 return parent[name] 1400 local val = rawget(_base_0, name)
1459 end 1401 if val == nil then
1460 else 1402 local parent = rawget(cls, "__parent")
1461 return val 1403 if parent then
1404 return parent[name]
1462 end 1405 end
1463 end, 1406 else
1464 __call = function(cls, ...) 1407 return val
1465 local _self_0 = setmetatable({ }, _base_0)
1466 cls.__init(_self_0, ...)
1467 return _self_0
1468 end 1408 end
1469 }) 1409 end,
1470 _base_0.__class = _class_0 1410 __call = function(cls, ...)
1471 if _parent_0.__inherited then 1411 local _self_0 = setmetatable({ }, _base_0)
1472 _parent_0.__inherited(_parent_0, _class_0) 1412 cls.__init(_self_0, ...)
1413 return _self_0
1473 end 1414 end
1474 BackPack = _class_0 1415})
1416_base_0.__class = _class_0
1417if _parent_0.__inherited then
1418 _parent_0.__inherited(_parent_0, _class_0)
1475end 1419end
1420BackPack = _class_0
1476local Shelf 1421local Shelf
1477do 1422do
1478 local _class_0 1423 local _class_0
@@ -1500,102 +1445,98 @@ do
1500 Shelf = _class_0 1445 Shelf = _class_0
1501end 1446end
1502local Cupboard 1447local Cupboard
1503do 1448local _class_0
1504 local _class_0 1449local _parent_0 = Shelf
1505 local _parent_0 = Shelf 1450local _base_0 = { }
1506 local _base_0 = { } 1451for _key_0, _val_0 in pairs(_parent_0.__base) do
1507 for _key_0, _val_0 in pairs(_parent_0.__base) do 1452 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1508 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then 1453 _base_0[_key_0] = _val_0
1509 _base_0[_key_0] = _val_0 1454 end
1510 end 1455end
1511 end 1456if _base_0.__index == nil then
1512 if _base_0.__index == nil then 1457 _base_0.__index = _base_0
1513 _base_0.__index = _base_0 1458end
1514 end 1459setmetatable(_base_0, _parent_0.__base)
1515 setmetatable(_base_0, _parent_0.__base) 1460_class_0 = setmetatable({
1516 _class_0 = setmetatable({ 1461 __init = function(self, ...)
1517 __init = function(self, ...) 1462 return _class_0.__parent.__init(self, ...)
1518 return _class_0.__parent.__init(self, ...) 1463 end,
1519 end, 1464 __base = _base_0,
1520 __base = _base_0, 1465 __name = "Cupboard",
1521 __name = "Cupboard", 1466 __parent = _parent_0
1522 __parent = _parent_0 1467}, {
1523 }, { 1468 __index = function(cls, name)
1524 __index = function(cls, name) 1469 local val = rawget(_base_0, name)
1525 local val = rawget(_base_0, name) 1470 if val == nil then
1526 if val == nil then 1471 local parent = rawget(cls, "__parent")
1527 local parent = rawget(cls, "__parent") 1472 if parent then
1528 if parent then 1473 return parent[name]
1529 return parent[name]
1530 end
1531 else
1532 return val
1533 end 1474 end
1534 end, 1475 else
1535 __call = function(cls, ...) 1476 return val
1536 local _self_0 = setmetatable({ }, _base_0)
1537 cls.__init(_self_0, ...)
1538 return _self_0
1539 end 1477 end
1540 }) 1478 end,
1541 _base_0.__class = _class_0 1479 __call = function(cls, ...)
1542 if _parent_0.__inherited then 1480 local _self_0 = setmetatable({ }, _base_0)
1543 _parent_0.__inherited(_parent_0, _class_0) 1481 cls.__init(_self_0, ...)
1482 return _self_0
1544 end 1483 end
1545 Cupboard = _class_0 1484})
1485_base_0.__class = _class_0
1486if _parent_0.__inherited then
1487 _parent_0.__inherited(_parent_0, _class_0)
1546end 1488end
1489Cupboard = _class_0
1547local MyClass 1490local MyClass
1548do 1491local _class_0
1549 local _class_0 1492local _parent_0 = ParentClass
1550 local _parent_0 = ParentClass 1493local _base_0 = {
1551 local _base_0 = { 1494 a_method = function(self)
1552 a_method = function(self) 1495 _class_0.__parent.__base.a_method(self, "hello", "world")
1553 _class_0.__parent.__base.a_method(self, "hello", "world") 1496 _class_0.__parent.a_method(self, "hello", "world")
1554 _class_0.__parent.a_method(self, "hello", "world") 1497 _class_0.__parent.a_method(self, "hello", "world")
1555 _class_0.__parent.a_method(self, "hello", "world") 1498 return assert(_class_0.__parent == ParentClass)
1556 return assert(_class_0.__parent == ParentClass) 1499 end
1557 end 1500}
1558 } 1501for _key_0, _val_0 in pairs(_parent_0.__base) do
1559 for _key_0, _val_0 in pairs(_parent_0.__base) do 1502 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
1560 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then 1503 _base_0[_key_0] = _val_0
1561 _base_0[_key_0] = _val_0 1504 end
1562 end 1505end
1563 end 1506if _base_0.__index == nil then
1564 if _base_0.__index == nil then 1507 _base_0.__index = _base_0
1565 _base_0.__index = _base_0 1508end
1566 end 1509setmetatable(_base_0, _parent_0.__base)
1567 setmetatable(_base_0, _parent_0.__base) 1510_class_0 = setmetatable({
1568 _class_0 = setmetatable({ 1511 __init = function(self, ...)
1569 __init = function(self, ...) 1512 return _class_0.__parent.__init(self, ...)
1570 return _class_0.__parent.__init(self, ...) 1513 end,
1571 end, 1514 __base = _base_0,
1572 __base = _base_0, 1515 __name = "MyClass",
1573 __name = "MyClass", 1516 __parent = _parent_0
1574 __parent = _parent_0 1517}, {
1575 }, { 1518 __index = function(cls, name)
1576 __index = function(cls, name) 1519 local val = rawget(_base_0, name)
1577 local val = rawget(_base_0, name) 1520 if val == nil then
1578 if val == nil then 1521 local parent = rawget(cls, "__parent")
1579 local parent = rawget(cls, "__parent") 1522 if parent then
1580 if parent then 1523 return parent[name]
1581 return parent[name]
1582 end
1583 else
1584 return val
1585 end 1524 end
1586 end, 1525 else
1587 __call = function(cls, ...) 1526 return val
1588 local _self_0 = setmetatable({ }, _base_0)
1589 cls.__init(_self_0, ...)
1590 return _self_0
1591 end 1527 end
1592 }) 1528 end,
1593 _base_0.__class = _class_0 1529 __call = function(cls, ...)
1594 if _parent_0.__inherited then 1530 local _self_0 = setmetatable({ }, _base_0)
1595 _parent_0.__inherited(_parent_0, _class_0) 1531 cls.__init(_self_0, ...)
1532 return _self_0
1596 end 1533 end
1597 MyClass = _class_0 1534})
1535_base_0.__class = _class_0
1536if _parent_0.__inherited then
1537 _parent_0.__inherited(_parent_0, _class_0)
1598end 1538end
1539MyClass = _class_0
1599local b = BackPack() 1540local b = BackPack()
1600assert(b.__class == BackPack) 1541assert(b.__class == BackPack)
1601print(BackPack.size) 1542print(BackPack.size)
@@ -1659,61 +1600,57 @@ Counter()
1659print(Counter.count) 1600print(Counter.count)
1660self.__class:hello(1, 2, 3, 4) 1601self.__class:hello(1, 2, 3, 4)
1661local Things 1602local Things
1662do 1603local _class_0
1663 local _class_0 1604local _base_0 = { }
1664 local _base_0 = { } 1605if _base_0.__index == nil then
1665 if _base_0.__index == nil then 1606 _base_0.__index = _base_0
1666 _base_0.__index = _base_0 1607end
1608_class_0 = setmetatable({
1609 __init = function() end,
1610 __base = _base_0,
1611 __name = "Things"
1612}, {
1613 __index = _base_0,
1614 __call = function(cls, ...)
1615 local _self_0 = setmetatable({ }, _base_0)
1616 cls.__init(_self_0, ...)
1617 return _self_0
1667 end 1618 end
1668 _class_0 = setmetatable({ 1619})
1669 __init = function() end, 1620_base_0.__class = _class_0
1670 __base = _base_0, 1621local self = _class_0;
1671 __name = "Things" 1622self.class_var = "hello world"
1672 }, { 1623Things = _class_0
1673 __index = _base_0,
1674 __call = function(cls, ...)
1675 local _self_0 = setmetatable({ }, _base_0)
1676 cls.__init(_self_0, ...)
1677 return _self_0
1678 end
1679 })
1680 _base_0.__class = _class_0
1681 local self = _class_0;
1682 self.class_var = "hello world"
1683 Things = _class_0
1684end
1685local MoreThings 1624local MoreThings
1686do 1625local _class_0
1687 local _class_0 1626local secret, log
1688 local secret, log 1627local _base_0 = {
1689 local _base_0 = { 1628 some_method = function(self)
1690 some_method = function(self) 1629 return log("hello world: " .. secret)
1691 return log("hello world: " .. secret)
1692 end
1693 }
1694 if _base_0.__index == nil then
1695 _base_0.__index = _base_0
1696 end 1630 end
1697 _class_0 = setmetatable({ 1631}
1698 __init = function() end, 1632if _base_0.__index == nil then
1699 __base = _base_0, 1633 _base_0.__index = _base_0
1700 __name = "MoreThings" 1634end
1701 }, { 1635_class_0 = setmetatable({
1702 __index = _base_0, 1636 __init = function() end,
1703 __call = function(cls, ...) 1637 __base = _base_0,
1704 local _self_0 = setmetatable({ }, _base_0) 1638 __name = "MoreThings"
1705 cls.__init(_self_0, ...) 1639}, {
1706 return _self_0 1640 __index = _base_0,
1707 end 1641 __call = function(cls, ...)
1708 }) 1642 local _self_0 = setmetatable({ }, _base_0)
1709 _base_0.__class = _class_0 1643 cls.__init(_self_0, ...)
1710 local self = _class_0; 1644 return _self_0
1711 secret = 123
1712 log = function(msg)
1713 return print("LOG:", msg)
1714 end 1645 end
1715 MoreThings = _class_0 1646})
1647_base_0.__class = _class_0
1648local self = _class_0;
1649secret = 123
1650log = function(msg)
1651 return print("LOG:", msg)
1716end 1652end
1653MoreThings = _class_0
1717assert(self == self) 1654assert(self == self)
1718assert(self.__class == self.__class) 1655assert(self.__class == self.__class)
1719local some_instance_method 1656local some_instance_method
@@ -1747,32 +1684,30 @@ do
1747 _base_0.__class = _class_0 1684 _base_0.__class = _class_0
1748 Something = _class_0 1685 Something = _class_0
1749end 1686end
1750do 1687local _class_0
1751 local _class_0 1688local _base_0 = { }
1752 local _base_0 = { } 1689if _base_0.__index == nil then
1753 if _base_0.__index == nil then 1690 _base_0.__index = _base_0
1754 _base_0.__index = _base_0 1691end
1692_class_0 = setmetatable({
1693 __init = function(self, foo, bar, biz, baz)
1694 self.foo = foo
1695 self.bar = bar
1696 self.__class.biz = biz
1697 self.__class.baz = baz
1698 end,
1699 __base = _base_0,
1700 __name = "Something"
1701}, {
1702 __index = _base_0,
1703 __call = function(cls, ...)
1704 local _self_0 = setmetatable({ }, _base_0)
1705 cls.__init(_self_0, ...)
1706 return _self_0
1755 end 1707 end
1756 _class_0 = setmetatable({ 1708})
1757 __init = function(self, foo, bar, biz, baz) 1709_base_0.__class = _class_0
1758 self.foo = foo 1710Something = _class_0
1759 self.bar = bar
1760 self.__class.biz = biz
1761 self.__class.baz = baz
1762 end,
1763 __base = _base_0,
1764 __name = "Something"
1765 }, {
1766 __index = _base_0,
1767 __call = function(cls, ...)
1768 local _self_0 = setmetatable({ }, _base_0)
1769 cls.__init(_self_0, ...)
1770 return _self_0
1771 end
1772 })
1773 _base_0.__class = _class_0
1774 Something = _class_0
1775end
1776local new 1711local new
1777new = function(self, fieldA, fieldB) 1712new = function(self, fieldA, fieldB)
1778 self.fieldA = fieldA 1713 self.fieldA = fieldA
@@ -1783,33 +1718,31 @@ local obj = new({ }, 123, "abc")
1783print(obj) 1718print(obj)
1784local x 1719local x
1785local Bucket 1720local Bucket
1786do 1721local _class_0
1787 local _class_0 1722local _base_0 = {
1788 local _base_0 = { 1723 drops = 0,
1789 drops = 0, 1724 add_drop = function(self)
1790 add_drop = function(self) 1725 self.drops = self.drops + 1
1791 self.drops = self.drops + 1
1792 end
1793 }
1794 if _base_0.__index == nil then
1795 _base_0.__index = _base_0
1796 end 1726 end
1797 _class_0 = setmetatable({ 1727}
1798 __init = function() end, 1728if _base_0.__index == nil then
1799 __base = _base_0, 1729 _base_0.__index = _base_0
1800 __name = "Bucket"
1801 }, {
1802 __index = _base_0,
1803 __call = function(cls, ...)
1804 local _self_0 = setmetatable({ }, _base_0)
1805 cls.__init(_self_0, ...)
1806 return _self_0
1807 end
1808 })
1809 _base_0.__class = _class_0
1810 Bucket = _class_0
1811 x = _class_0
1812end 1730end
1731_class_0 = setmetatable({
1732 __init = function() end,
1733 __base = _base_0,
1734 __name = "Bucket"
1735}, {
1736 __index = _base_0,
1737 __call = function(cls, ...)
1738 local _self_0 = setmetatable({ }, _base_0)
1739 cls.__init(_self_0, ...)
1740 return _self_0
1741 end
1742})
1743_base_0.__class = _class_0
1744Bucket = _class_0
1745x = _class_0
1813local BigBucket 1746local BigBucket
1814do 1747do
1815 local _class_0 1748 local _class_0
@@ -1861,27 +1794,25 @@ do
1861end 1794end
1862assert(Bucket.__name == "BigBucket") 1795assert(Bucket.__name == "BigBucket")
1863local x 1796local x
1864do 1797local _class_0
1865 local _class_0 1798local _base_0 = { }
1866 local _base_0 = { } 1799if _base_0.__index == nil then
1867 if _base_0.__index == nil then 1800 _base_0.__index = _base_0
1868 _base_0.__index = _base_0 1801end
1802_class_0 = setmetatable({
1803 __init = function() end,
1804 __base = _base_0,
1805 __name = "x"
1806}, {
1807 __index = _base_0,
1808 __call = function(cls, ...)
1809 local _self_0 = setmetatable({ }, _base_0)
1810 cls.__init(_self_0, ...)
1811 return _self_0
1869 end 1812 end
1870 _class_0 = setmetatable({ 1813})
1871 __init = function() end, 1814_base_0.__class = _class_0
1872 __base = _base_0, 1815x = _class_0
1873 __name = "x"
1874 }, {
1875 __index = _base_0,
1876 __call = function(cls, ...)
1877 local _self_0 = setmetatable({ }, _base_0)
1878 cls.__init(_self_0, ...)
1879 return _self_0
1880 end
1881 })
1882 _base_0.__class = _class_0
1883 x = _class_0
1884end
1885local MyIndex = { 1816local MyIndex = {
1886 __index = { 1817 __index = {
1887 var = 1 1818 var = 1
@@ -1964,19 +1895,15 @@ end
1964local y = Y() 1895local y = Y()
1965y:func() 1896y:func()
1966assert(y.__class.__parent ~= X) 1897assert(y.__class.__parent ~= X)
1967do 1898local _with_0 = Person()
1968 local _with_0 = Person() 1899_with_0.name = "Oswald"
1969 _with_0.name = "Oswald" 1900_with_0:add_relative(my_dad)
1970 _with_0:add_relative(my_dad) 1901_with_0:save()
1971 _with_0:save() 1902print(_with_0.name)
1972 print(_with_0.name)
1973end
1974local file 1903local file
1975do 1904local _with_0 = File("favorite_foods.txt")
1976 local _with_0 = File("favorite_foods.txt") 1905_with_0:set_encoding("utf8")
1977 _with_0:set_encoding("utf8") 1906file = _with_0
1978 file = _with_0
1979end
1980local create_person 1907local create_person
1981create_person = function(name, relatives) 1908create_person = function(name, relatives)
1982 local _with_0 = Person() 1909 local _with_0 = Person()
@@ -1992,22 +1919,18 @@ local me = create_person("Leaf", {
1992 mother, 1919 mother,
1993 sister 1920 sister
1994}) 1921})
1922local str = "Hello"
1923print("original:", str)
1924print("upper:", str:upper())
1925local _with_0 = tb
1926_with_0[1] = 1
1927print(_with_0[2])
1995do 1928do
1996 local str = "Hello" 1929 local _with_1 = _with_0[abc]
1997 print("original:", str) 1930 _with_1[3] = _with_1[2]:func()
1998 print("upper:", str:upper()) 1931 _with_1["key-name"] = value
1999end
2000do
2001 local _with_0 = tb
2002 _with_0[1] = 1
2003 print(_with_0[2])
2004 do
2005 local _with_1 = _with_0[abc]
2006 _with_1[3] = _with_1[2]:func()
2007 _with_1["key-name"] = value
2008 end
2009 _with_0[#_with_0 + 1] = "abc"
2010end 1932end
1933_with_0[#_with_0 + 1] = "abc"
2011do 1934do
2012 local var = "hello" 1935 local var = "hello"
2013 print(var) 1936 print(var)
@@ -2124,13 +2047,18 @@ _module_0["🌛"] = _ud83c_udf1b
2124return _module_0 2047return _module_0
2125local area = 6.2831853071796 * 5 2048local area = 6.2831853071796 * 5
2126print('hello world') 2049print('hello world')
2127assert(item ~= nil) 2050do
2051 assert(item ~= nil)
2052end
2128local value = item 2053local value = item
2129if (f1() and f2() and f3()) then 2054if (f1() and f2() and f3()) then
2130 print("OK") 2055 print("OK")
2131end 2056end
2057do
2058 local funcA
2059 funcA = function() end
2060end
2132local funcA 2061local funcA
2133funcA = function() end
2134funcA = function() 2062funcA = function()
2135 return "assign the Yue defined variable" 2063 return "assign the Yue defined variable"
2136end 2064end
@@ -2224,28 +2152,26 @@ local b = {
2224 y = 1 2152 y = 1
2225} 2153}
2226local merge 2154local merge
2227do 2155local _tab_0 = { }
2228 local _tab_0 = { } 2156local _idx_0 = 1
2229 local _idx_0 = 1 2157for _key_0, _value_0 in pairs(a) do
2230 for _key_0, _value_0 in pairs(a) do 2158 if _idx_0 == _key_0 then
2231 if _idx_0 == _key_0 then 2159 _tab_0[#_tab_0 + 1] = _value_0
2232 _tab_0[#_tab_0 + 1] = _value_0 2160 _idx_0 = _idx_0 + 1
2233 _idx_0 = _idx_0 + 1 2161 else
2234 else 2162 _tab_0[_key_0] = _value_0
2235 _tab_0[_key_0] = _value_0
2236 end
2237 end 2163 end
2238 local _idx_1 = 1 2164end
2239 for _key_0, _value_0 in pairs(b) do 2165local _idx_1 = 1
2240 if _idx_1 == _key_0 then 2166for _key_0, _value_0 in pairs(b) do
2241 _tab_0[#_tab_0 + 1] = _value_0 2167 if _idx_1 == _key_0 then
2242 _idx_1 = _idx_1 + 1 2168 _tab_0[#_tab_0 + 1] = _value_0
2243 else 2169 _idx_1 = _idx_1 + 1
2244 _tab_0[_key_0] = _value_0 2170 else
2245 end 2171 _tab_0[_key_0] = _value_0
2246 end 2172 end
2247 merge = _tab_0
2248end 2173end
2174merge = _tab_0
2249local mt = { } 2175local mt = { }
2250local add 2176local add
2251add = function(self, right) 2177add = function(self, right)
@@ -2337,12 +2263,10 @@ end
2337if print and (x ~= nil) then 2263if print and (x ~= nil) then
2338 print(x) 2264 print(x)
2339end 2265end
2340do 2266local _with_0 = io.open("test.txt", "w")
2341 local _with_0 = io.open("test.txt", "w") 2267if _with_0 ~= nil then
2342 if _with_0 ~= nil then 2268 _with_0:write("hello")
2343 _with_0:write("hello") 2269 _with_0:close()
2344 _with_0:close()
2345 end
2346end 2270end
2347print("hello") 2271print("hello")
2348print(1, 2) 2272print(1, 2)
@@ -2419,10 +2343,8 @@ do
2419 x, y, z = _obj_0.x, _obj_0.y, _obj_0.z 2343 x, y, z = _obj_0.x, _obj_0.y, _obj_0.z
2420 end 2344 end
2421 local a, b, c 2345 local a, b, c
2422 do 2346 local _obj_0 = require('module')
2423 local _obj_0 = require('module') 2347 a, b, c = _obj_0.a, _obj_0.b, _obj_0.c
2424 a, b, c = _obj_0.a, _obj_0.b, _obj_0.c
2425 end
2426end 2348end
2427do 2349do
2428 local module = require('module') 2350 local module = require('module')
@@ -2461,29 +2383,27 @@ y = function()
2461end 2383end
2462_module_0["y"] = y 2384_module_0["y"] = y
2463local Something 2385local Something
2464do 2386local _class_0
2465 local _class_0 2387local _base_0 = {
2466 local _base_0 = { 2388 umm = "cool"
2467 umm = "cool" 2389}
2468 } 2390if _base_0.__index == nil then
2469 if _base_0.__index == nil then 2391 _base_0.__index = _base_0
2470 _base_0.__index = _base_0
2471 end
2472 _class_0 = setmetatable({
2473 __init = function() end,
2474 __base = _base_0,
2475 __name = "Something"
2476 }, {
2477 __index = _base_0,
2478 __call = function(cls, ...)
2479 local _self_0 = setmetatable({ }, _base_0)
2480 cls.__init(_self_0, ...)
2481 return _self_0
2482 end
2483 })
2484 _base_0.__class = _class_0
2485 Something = _class_0
2486end 2392end
2393_class_0 = setmetatable({
2394 __init = function() end,
2395 __base = _base_0,
2396 __name = "Something"
2397}, {
2398 __index = _base_0,
2399 __call = function(cls, ...)
2400 local _self_0 = setmetatable({ }, _base_0)
2401 cls.__init(_self_0, ...)
2402 return _self_0
2403 end
2404})
2405_base_0.__class = _class_0
2406Something = _class_0
2487_module_0["Something"] = Something 2407_module_0["Something"] = Something
2488return _module_0 2408return _module_0
2489local _module_0 = { } 2409local _module_0 = { }
@@ -2514,11 +2434,9 @@ if this then
2514else 2434else
2515 _module_0[#_module_0 + 1] = 456 2435 _module_0[#_module_0 + 1] = 456
2516end 2436end
2517do 2437local _with_0 = tmp
2518 local _with_0 = tmp 2438local j = 2000
2519 local j = 2000 2439_module_0[#_module_0 + 1] = _with_0
2520 _module_0[#_module_0 + 1] = _with_0
2521end
2522return _module_0 2440return _module_0
2523local _module_0 = nil 2441local _module_0 = nil
2524_module_0 = function() 2442_module_0 = function()
@@ -2655,25 +2573,19 @@ for _index_0 = 1, #tuples do
2655 local left, right = _des_0[1], _des_0[2] 2573 local left, right = _des_0[1], _des_0[2]
2656 print(left, right) 2574 print(left, right)
2657end 2575end
2658do 2576local user = database.find_user("moon")
2659 local user = database.find_user("moon") 2577if user then
2660 if user then 2578 print(user.name)
2661 print(user.name)
2662 end
2663end 2579end
2664do 2580local hello = os.getenv("hello")
2665 local hello = os.getenv("hello") 2581if hello then
2666 if hello then 2582 print("You have hello", hello)
2667 print("You have hello", hello) 2583else
2584 local world = os.getenv("world")
2585 if world then
2586 print("you have world", world)
2668 else 2587 else
2669 do 2588 print("nothing :(")
2670 local world = os.getenv("world")
2671 if world then
2672 print("you have world", world)
2673 else
2674 print("nothing :(")
2675 end
2676 end
2677 end 2589 end
2678end 2590end
2679do 2591do
@@ -2936,40 +2848,34 @@ local items = {
2936 4 2848 4
2937} 2849}
2938local doubled 2850local doubled
2939do 2851local _accum_0 = { }
2940 local _accum_0 = { } 2852local _len_0 = 1
2941 local _len_0 = 1 2853for i, item in ipairs(items) do
2942 for i, item in ipairs(items) do 2854 _accum_0[_len_0] = item * 2
2943 _accum_0[_len_0] = item * 2 2855 _len_0 = _len_0 + 1
2944 _len_0 = _len_0 + 1
2945 end
2946 doubled = _accum_0
2947end 2856end
2857doubled = _accum_0
2948local iter = ipairs(items) 2858local iter = ipairs(items)
2949local slice 2859local slice
2950do 2860local _accum_0 = { }
2951 local _accum_0 = { } 2861local _len_0 = 1
2952 local _len_0 = 1 2862for i, item in iter do
2953 for i, item in iter do 2863 if i > 1 and i < 3 then
2954 if i > 1 and i < 3 then 2864 _accum_0[_len_0] = item
2955 _accum_0[_len_0] = item 2865 _len_0 = _len_0 + 1
2956 _len_0 = _len_0 + 1
2957 end
2958 end 2866 end
2959 slice = _accum_0
2960end 2867end
2868slice = _accum_0
2961local doubled 2869local doubled
2962do 2870local _accum_0 = { }
2963 local _accum_0 = { } 2871local _len_0 = 1
2964 local _len_0 = 1 2872local _list_0 = items
2965 local _list_0 = items 2873for _index_0 = 1, #_list_0 do
2966 for _index_0 = 1, #_list_0 do 2874 local item = _list_0[_index_0]
2967 local item = _list_0[_index_0] 2875 _accum_0[_len_0] = item * 2
2968 _accum_0[_len_0] = item * 2 2876 _len_0 = _len_0 + 1
2969 _len_0 = _len_0 + 1
2970 end
2971 doubled = _accum_0
2972end 2877end
2878doubled = _accum_0
2973local x_coords = { 2879local x_coords = {
2974 4, 2880 4,
2975 5, 2881 5,
@@ -2982,57 +2888,49 @@ local y_coords = {
2982 3 2888 3
2983} 2889}
2984local points 2890local points
2985do 2891local _accum_0 = { }
2986 local _accum_0 = { } 2892local _len_0 = 1
2987 local _len_0 = 1 2893for _index_0 = 1, #x_coords do
2988 for _index_0 = 1, #x_coords do 2894 local x = x_coords[_index_0]
2989 local x = x_coords[_index_0] 2895 for _index_1 = 1, #y_coords do
2990 for _index_1 = 1, #y_coords do 2896 local y = y_coords[_index_1]
2991 local y = y_coords[_index_1] 2897 _accum_0[_len_0] = {
2992 _accum_0[_len_0] = { 2898 x,
2993 x, 2899 y
2994 y 2900 }
2995 } 2901 _len_0 = _len_0 + 1
2996 _len_0 = _len_0 + 1
2997 end
2998 end 2902 end
2999 points = _accum_0
3000end 2903end
2904points = _accum_0
3001local evens 2905local evens
3002do 2906local _accum_0 = { }
3003 local _accum_0 = { } 2907local _len_0 = 1
3004 local _len_0 = 1 2908for i = 1, 100 do
3005 for i = 1, 100 do 2909 if i % 2 == 0 then
3006 if i % 2 == 0 then 2910 _accum_0[_len_0] = i
3007 _accum_0[_len_0] = i 2911 _len_0 = _len_0 + 1
3008 _len_0 = _len_0 + 1
3009 end
3010 end 2912 end
3011 evens = _accum_0
3012end 2913end
2914evens = _accum_0
3013local thing = { 2915local thing = {
3014 color = "red", 2916 color = "red",
3015 name = "fast", 2917 name = "fast",
3016 width = 123 2918 width = 123
3017} 2919}
3018local thing_copy 2920local thing_copy
3019do 2921local _tbl_0 = { }
3020 local _tbl_0 = { } 2922for k, v in pairs(thing) do
3021 for k, v in pairs(thing) do 2923 _tbl_0[k] = v
3022 _tbl_0[k] = v
3023 end
3024 thing_copy = _tbl_0
3025end 2924end
2925thing_copy = _tbl_0
3026local no_color 2926local no_color
3027do 2927local _tbl_0 = { }
3028 local _tbl_0 = { } 2928for k, v in pairs(thing) do
3029 for k, v in pairs(thing) do 2929 if k ~= "color" then
3030 if k ~= "color" then 2930 _tbl_0[k] = v
3031 _tbl_0[k] = v
3032 end
3033 end 2931 end
3034 no_color = _tbl_0
3035end 2932end
2933no_color = _tbl_0
3036local numbers = { 2934local numbers = {
3037 1, 2935 1,
3038 2, 2936 2,
@@ -3040,14 +2938,12 @@ local numbers = {
3040 4 2938 4
3041} 2939}
3042local sqrts 2940local sqrts
3043do 2941local _tbl_0 = { }
3044 local _tbl_0 = { } 2942for _index_0 = 1, #numbers do
3045 for _index_0 = 1, #numbers do 2943 local i = numbers[_index_0]
3046 local i = numbers[_index_0] 2944 _tbl_0[i] = math.sqrt(i)
3047 _tbl_0[i] = math.sqrt(i)
3048 end
3049 sqrts = _tbl_0
3050end 2945end
2946sqrts = _tbl_0
3051local tuples = { 2947local tuples = {
3052 { 2948 {
3053 "hello", 2949 "hello",
@@ -3059,52 +2955,44 @@ local tuples = {
3059 } 2955 }
3060} 2956}
3061local tbl 2957local tbl
3062do 2958local _tbl_0 = { }
3063 local _tbl_0 = { } 2959for _index_0 = 1, #tuples do
3064 for _index_0 = 1, #tuples do 2960 local tuple = tuples[_index_0]
3065 local tuple = tuples[_index_0] 2961 local _key_0, _val_0 = unpack(tuple)
3066 local _key_0, _val_0 = unpack(tuple) 2962 _tbl_0[_key_0] = _val_0
3067 _tbl_0[_key_0] = _val_0
3068 end
3069 tbl = _tbl_0
3070end 2963end
2964tbl = _tbl_0
3071local slice 2965local slice
3072do 2966local _accum_0 = { }
3073 local _accum_0 = { } 2967local _len_0 = 1
3074 local _len_0 = 1 2968local _list_0 = items
3075 local _list_0 = items 2969local _max_0 = 5
3076 local _max_0 = 5 2970for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
3077 for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do 2971 local item = _list_0[_index_0]
3078 local item = _list_0[_index_0] 2972 _accum_0[_len_0] = item
3079 _accum_0[_len_0] = item 2973 _len_0 = _len_0 + 1
3080 _len_0 = _len_0 + 1
3081 end
3082 slice = _accum_0
3083end 2974end
2975slice = _accum_0
3084local slice 2976local slice
3085do 2977local _accum_0 = { }
3086 local _accum_0 = { } 2978local _len_0 = 1
3087 local _len_0 = 1 2979local _list_0 = items
3088 local _list_0 = items 2980for _index_0 = 2, #_list_0 do
3089 for _index_0 = 2, #_list_0 do 2981 local item = _list_0[_index_0]
3090 local item = _list_0[_index_0] 2982 _accum_0[_len_0] = item
3091 _accum_0[_len_0] = item 2983 _len_0 = _len_0 + 1
3092 _len_0 = _len_0 + 1
3093 end
3094 slice = _accum_0
3095end 2984end
2985slice = _accum_0
3096local slice 2986local slice
3097do 2987local _accum_0 = { }
3098 local _accum_0 = { } 2988local _len_0 = 1
3099 local _len_0 = 1 2989local _list_0 = items
3100 local _list_0 = items 2990for _index_0 = 1, #_list_0, 2 do
3101 for _index_0 = 1, #_list_0, 2 do 2991 local item = _list_0[_index_0]
3102 local item = _list_0[_index_0] 2992 _accum_0[_len_0] = item
3103 _accum_0[_len_0] = item 2993 _len_0 = _len_0 + 1
3104 _len_0 = _len_0 + 1
3105 end
3106 slice = _accum_0
3107end 2994end
2995slice = _accum_0
3108for i = 10, 20 do 2996for i = 10, 20 do
3109 print(i) 2997 print(i)
3110end 2998end
@@ -3114,13 +3002,11 @@ end
3114for key, value in pairs(object) do 3002for key, value in pairs(object) do
3115 print(key, value) 3003 print(key, value)
3116end 3004end
3117do 3005local _list_0 = items
3118 local _list_0 = items 3006local _max_0 = 4
3119 local _max_0 = 4 3007for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
3120 for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do 3008 local item = _list_0[_index_0]
3121 local item = _list_0[_index_0] 3009 print(item)
3122 print(item)
3123 end
3124end 3010end
3125local _list_0 = items 3011local _list_0 = items
3126for _index_0 = 1, #_list_0 do 3012for _index_0 = 1, #_list_0 do
@@ -3131,19 +3017,17 @@ for j = 1, 10, 3 do
3131 print(j) 3017 print(j)
3132end 3018end
3133local doubled_evens 3019local doubled_evens
3134do 3020local _accum_0 = { }
3135 local _accum_0 = { } 3021local _len_0 = 1
3136 local _len_0 = 1 3022for i = 1, 20 do
3137 for i = 1, 20 do 3023 if i % 2 == 0 then
3138 if i % 2 == 0 then 3024 _accum_0[_len_0] = i * 2
3139 _accum_0[_len_0] = i * 2 3025 else
3140 else 3026 _accum_0[_len_0] = i
3141 _accum_0[_len_0] = i
3142 end
3143 _len_0 = _len_0 + 1
3144 end 3027 end
3145 doubled_evens = _accum_0 3028 _len_0 = _len_0 + 1
3146end 3029end
3030doubled_evens = _accum_0
3147local func_a 3031local func_a
3148func_a = function() 3032func_a = function()
3149 for i = 1, 10 do 3033 for i = 1, 10 do
@@ -3201,20 +3085,18 @@ local my_numbers = {
3201 6 3085 6
3202} 3086}
3203local odds 3087local odds
3204do 3088local _accum_0 = { }
3205 local _accum_0 = { } 3089local _len_0 = 1
3206 local _len_0 = 1 3090for _index_0 = 1, #my_numbers do
3207 for _index_0 = 1, #my_numbers do 3091 local x = my_numbers[_index_0]
3208 local x = my_numbers[_index_0] 3092 if x % 2 == 1 then
3209 if x % 2 == 1 then 3093 goto _continue_0
3210 goto _continue_0
3211 end
3212 _accum_0[_len_0] = x
3213 _len_0 = _len_0 + 1
3214 ::_continue_0::
3215 end 3094 end
3216 odds = _accum_0 3095 _accum_0[_len_0] = x
3096 _len_0 = _len_0 + 1
3097 ::_continue_0::
3217end 3098end
3099odds = _accum_0
3218local have_coins = false 3100local have_coins = false
3219if have_coins then 3101if have_coins then
3220 print("Got coins") 3102 print("Got coins")
@@ -3306,15 +3188,13 @@ else
3306 next_number = error("can't count that high!") 3188 next_number = error("can't count that high!")
3307end 3189end
3308local msg 3190local msg
3309do 3191local _exp_0 = math.random(1, 5)
3310 local _exp_0 = math.random(1, 5) 3192if 1 == _exp_0 then
3311 if 1 == _exp_0 then 3193 msg = "you are lucky"
3312 msg = "you are lucky" 3194elseif 2 == _exp_0 then
3313 elseif 2 == _exp_0 then 3195 msg = "you are almost lucky"
3314 msg = "you are almost lucky" 3196else
3315 else 3197 msg = "not so lucky"
3316 msg = "not so lucky"
3317 end
3318end 3198end
3319do 3199do
3320 local _exp_0 = math.random(1, 5) 3200 local _exp_0 = math.random(1, 5)
@@ -3324,13 +3204,11 @@ do
3324 print("not so lucky") 3204 print("not so lucky")
3325 end 3205 end
3326end 3206end
3327do 3207local _exp_0 = math.random(1, 5)
3328 local _exp_0 = math.random(1, 5) 3208if 1 == _exp_0 then
3329 if 1 == _exp_0 then 3209 print("you are lucky")
3330 print("you are lucky") 3210else
3331 else 3211 print("not so lucky")
3332 print("not so lucky")
3333 end
3334end 3212end
3335local items = { 3213local items = {
3336 { 3214 {
@@ -3344,25 +3222,23 @@ local items = {
3344} 3222}
3345for _index_0 = 1, #items do 3223for _index_0 = 1, #items do
3346 local item = items[_index_0] 3224 local item = items[_index_0]
3347 do 3225 local _type_0 = type(item)
3348 local _type_0 = type(item) 3226 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3349 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 3227 local _match_0 = false
3350 local _match_0 = false 3228 if _tab_0 then
3351 if _tab_0 then 3229 local x = item.x
3352 local x = item.x 3230 local y = item.y
3353 local y = item.y 3231 if x ~= nil and y ~= nil then
3354 if x ~= nil and y ~= nil then 3232 _match_0 = true
3355 _match_0 = true 3233 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3356 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3357 end
3358 end 3234 end
3359 if not _match_0 then 3235 end
3360 if _tab_0 then 3236 if not _match_0 then
3361 local width = item.width 3237 if _tab_0 then
3362 local height = item.height 3238 local width = item.width
3363 if width ~= nil and height ~= nil then 3239 local height = item.height
3364 print("size " .. tostring(width) .. ", " .. tostring(height)) 3240 if width ~= nil and height ~= nil then
3365 end 3241 print("size " .. tostring(width) .. ", " .. tostring(height))
3366 end 3242 end
3367 end 3243 end
3368 end 3244 end
@@ -3375,66 +3251,62 @@ end
3375if y == nil then 3251if y == nil then
3376 y = 200 3252 y = 200
3377end 3253end
3378do 3254local _type_0 = type(item)
3379 local _type_0 = type(item) 3255local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3380 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 3256if _tab_0 then
3381 if _tab_0 then 3257 do
3382 do 3258 local _obj_0 = item.pos
3383 local _obj_0 = item.pos 3259 local _type_1 = type(_obj_0)
3384 local _type_1 = type(_obj_0) 3260 if "table" == _type_1 or "userdata" == _type_1 then
3385 if "table" == _type_1 or "userdata" == _type_1 then 3261 x = _obj_0.x
3386 x = _obj_0.x
3387 end
3388 end
3389 do
3390 local _obj_0 = item.pos
3391 local _type_1 = type(_obj_0)
3392 if "table" == _type_1 or "userdata" == _type_1 then
3393 y = _obj_0.y
3394 end
3395 end
3396 if x == nil then
3397 x = 50
3398 end 3262 end
3399 if y == nil then 3263 end
3400 y = 200 3264 do
3265 local _obj_0 = item.pos
3266 local _type_1 = type(_obj_0)
3267 if "table" == _type_1 or "userdata" == _type_1 then
3268 y = _obj_0.y
3401 end 3269 end
3402 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3403 end 3270 end
3271 if x == nil then
3272 x = 50
3273 end
3274 if y == nil then
3275 y = 200
3276 end
3277 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3404end 3278end
3405local Inventory 3279local Inventory
3406do 3280local _class_0
3407 local _class_0 3281local _base_0 = {
3408 local _base_0 = { 3282 add_item = function(self, name)
3409 add_item = function(self, name) 3283 if self.items[name] then
3410 if self.items[name] then 3284 local _obj_0 = self.items
3411 local _obj_0 = self.items 3285 _obj_0[name] = _obj_0[name] + 1
3412 _obj_0[name] = _obj_0[name] + 1 3286 else
3413 else 3287 self.items[name] = 1
3414 self.items[name] = 1
3415 end
3416 end 3288 end
3417 }
3418 if _base_0.__index == nil then
3419 _base_0.__index = _base_0
3420 end 3289 end
3421 _class_0 = setmetatable({ 3290}
3422 __init = function(self) 3291if _base_0.__index == nil then
3423 self.items = { } 3292 _base_0.__index = _base_0
3424 end,
3425 __base = _base_0,
3426 __name = "Inventory"
3427 }, {
3428 __index = _base_0,
3429 __call = function(cls, ...)
3430 local _self_0 = setmetatable({ }, _base_0)
3431 cls.__init(_self_0, ...)
3432 return _self_0
3433 end
3434 })
3435 _base_0.__class = _class_0
3436 Inventory = _class_0
3437end 3293end
3294_class_0 = setmetatable({
3295 __init = function(self)
3296 self.items = { }
3297 end,
3298 __base = _base_0,
3299 __name = "Inventory"
3300}, {
3301 __index = _base_0,
3302 __call = function(cls, ...)
3303 local _self_0 = setmetatable({ }, _base_0)
3304 cls.__init(_self_0, ...)
3305 return _self_0
3306 end
3307})
3308_base_0.__class = _class_0
3309Inventory = _class_0
3438local inv = Inventory() 3310local inv = Inventory()
3439inv:add_item("t-shirt") 3311inv:add_item("t-shirt")
3440inv:add_item("pants") 3312inv:add_item("pants")
@@ -3475,82 +3347,78 @@ for _index_0 = 1, #_list_0 do
3475 print(item) 3347 print(item)
3476end 3348end
3477local Person 3349local Person
3478do 3350local _class_0
3479 local _class_0 3351local _base_0 = { }
3480 local _base_0 = { } 3352if _base_0.__index == nil then
3481 if _base_0.__index == nil then 3353 _base_0.__index = _base_0
3482 _base_0.__index = _base_0 3354end
3355_class_0 = setmetatable({
3356 __init = function(self)
3357 self.clothes = { }
3358 end,
3359 __base = _base_0,
3360 __name = "Person"
3361}, {
3362 __index = _base_0,
3363 __call = function(cls, ...)
3364 local _self_0 = setmetatable({ }, _base_0)
3365 cls.__init(_self_0, ...)
3366 return _self_0
3483 end 3367 end
3484 _class_0 = setmetatable({ 3368})
3485 __init = function(self) 3369_base_0.__class = _class_0
3486 self.clothes = { } 3370Person = _class_0
3487 end,
3488 __base = _base_0,
3489 __name = "Person"
3490 }, {
3491 __index = _base_0,
3492 __call = function(cls, ...)
3493 local _self_0 = setmetatable({ }, _base_0)
3494 cls.__init(_self_0, ...)
3495 return _self_0
3496 end
3497 })
3498 _base_0.__class = _class_0
3499 Person = _class_0
3500end
3501local BackPack 3371local BackPack
3502do 3372local _class_0
3503 local _class_0 3373local _parent_0 = Inventory
3504 local _parent_0 = Inventory 3374local _base_0 = {
3505 local _base_0 = { 3375 size = 10,
3506 size = 10, 3376 add_item = function(self, name)
3507 add_item = function(self, name) 3377 if #self.items > size then
3508 if #self.items > size then 3378 error("backpack is full")
3509 error("backpack is full")
3510 end
3511 return _class_0.__parent.__base.add_item(self, name)
3512 end
3513 }
3514 for _key_0, _val_0 in pairs(_parent_0.__base) do
3515 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
3516 _base_0[_key_0] = _val_0
3517 end 3379 end
3380 return _class_0.__parent.__base.add_item(self, name)
3518 end 3381 end
3519 if _base_0.__index == nil then 3382}
3520 _base_0.__index = _base_0 3383for _key_0, _val_0 in pairs(_parent_0.__base) do
3384 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
3385 _base_0[_key_0] = _val_0
3521 end 3386 end
3522 setmetatable(_base_0, _parent_0.__base) 3387end
3523 _class_0 = setmetatable({ 3388if _base_0.__index == nil then
3524 __init = function(self, ...) 3389 _base_0.__index = _base_0
3525 return _class_0.__parent.__init(self, ...) 3390end
3526 end, 3391setmetatable(_base_0, _parent_0.__base)
3527 __base = _base_0, 3392_class_0 = setmetatable({
3528 __name = "BackPack", 3393 __init = function(self, ...)
3529 __parent = _parent_0 3394 return _class_0.__parent.__init(self, ...)
3530 }, { 3395 end,
3531 __index = function(cls, name) 3396 __base = _base_0,
3532 local val = rawget(_base_0, name) 3397 __name = "BackPack",
3533 if val == nil then 3398 __parent = _parent_0
3534 local parent = rawget(cls, "__parent") 3399}, {
3535 if parent then 3400 __index = function(cls, name)
3536 return parent[name] 3401 local val = rawget(_base_0, name)
3537 end 3402 if val == nil then
3538 else 3403 local parent = rawget(cls, "__parent")
3539 return val 3404 if parent then
3405 return parent[name]
3540 end 3406 end
3541 end, 3407 else
3542 __call = function(cls, ...) 3408 return val
3543 local _self_0 = setmetatable({ }, _base_0)
3544 cls.__init(_self_0, ...)
3545 return _self_0
3546 end 3409 end
3547 }) 3410 end,
3548 _base_0.__class = _class_0 3411 __call = function(cls, ...)
3549 if _parent_0.__inherited then 3412 local _self_0 = setmetatable({ }, _base_0)
3550 _parent_0.__inherited(_parent_0, _class_0) 3413 cls.__init(_self_0, ...)
3414 return _self_0
3551 end 3415 end
3552 BackPack = _class_0 3416})
3417_base_0.__class = _class_0
3418if _parent_0.__inherited then
3419 _parent_0.__inherited(_parent_0, _class_0)
3553end 3420end
3421BackPack = _class_0
3554local Shelf 3422local Shelf
3555do 3423do
3556 local _class_0 3424 local _class_0
@@ -3578,102 +3446,98 @@ do
3578 Shelf = _class_0 3446 Shelf = _class_0
3579end 3447end
3580local Cupboard 3448local Cupboard
3581do 3449local _class_0
3582 local _class_0 3450local _parent_0 = Shelf
3583 local _parent_0 = Shelf 3451local _base_0 = { }
3584 local _base_0 = { } 3452for _key_0, _val_0 in pairs(_parent_0.__base) do
3585 for _key_0, _val_0 in pairs(_parent_0.__base) do 3453 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
3586 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then 3454 _base_0[_key_0] = _val_0
3587 _base_0[_key_0] = _val_0 3455 end
3588 end 3456end
3589 end 3457if _base_0.__index == nil then
3590 if _base_0.__index == nil then 3458 _base_0.__index = _base_0
3591 _base_0.__index = _base_0 3459end
3592 end 3460setmetatable(_base_0, _parent_0.__base)
3593 setmetatable(_base_0, _parent_0.__base) 3461_class_0 = setmetatable({
3594 _class_0 = setmetatable({ 3462 __init = function(self, ...)
3595 __init = function(self, ...) 3463 return _class_0.__parent.__init(self, ...)
3596 return _class_0.__parent.__init(self, ...) 3464 end,
3597 end, 3465 __base = _base_0,
3598 __base = _base_0, 3466 __name = "Cupboard",
3599 __name = "Cupboard", 3467 __parent = _parent_0
3600 __parent = _parent_0 3468}, {
3601 }, { 3469 __index = function(cls, name)
3602 __index = function(cls, name) 3470 local val = rawget(_base_0, name)
3603 local val = rawget(_base_0, name) 3471 if val == nil then
3604 if val == nil then 3472 local parent = rawget(cls, "__parent")
3605 local parent = rawget(cls, "__parent") 3473 if parent then
3606 if parent then 3474 return parent[name]
3607 return parent[name]
3608 end
3609 else
3610 return val
3611 end 3475 end
3612 end, 3476 else
3613 __call = function(cls, ...) 3477 return val
3614 local _self_0 = setmetatable({ }, _base_0)
3615 cls.__init(_self_0, ...)
3616 return _self_0
3617 end 3478 end
3618 }) 3479 end,
3619 _base_0.__class = _class_0 3480 __call = function(cls, ...)
3620 if _parent_0.__inherited then 3481 local _self_0 = setmetatable({ }, _base_0)
3621 _parent_0.__inherited(_parent_0, _class_0) 3482 cls.__init(_self_0, ...)
3483 return _self_0
3622 end 3484 end
3623 Cupboard = _class_0 3485})
3486_base_0.__class = _class_0
3487if _parent_0.__inherited then
3488 _parent_0.__inherited(_parent_0, _class_0)
3624end 3489end
3490Cupboard = _class_0
3625local MyClass 3491local MyClass
3626do 3492local _class_0
3627 local _class_0 3493local _parent_0 = ParentClass
3628 local _parent_0 = ParentClass 3494local _base_0 = {
3629 local _base_0 = { 3495 a_method = function(self)
3630 a_method = function(self) 3496 _class_0.__parent.__base.a_method(self, "hello", "world")
3631 _class_0.__parent.__base.a_method(self, "hello", "world") 3497 _class_0.__parent.a_method(self, "hello", "world")
3632 _class_0.__parent.a_method(self, "hello", "world") 3498 _class_0.__parent.a_method(self, "hello", "world")
3633 _class_0.__parent.a_method(self, "hello", "world") 3499 return assert(_class_0.__parent == ParentClass)
3634 return assert(_class_0.__parent == ParentClass) 3500 end
3635 end 3501}
3636 } 3502for _key_0, _val_0 in pairs(_parent_0.__base) do
3637 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
3638 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
3639 _base_0[_key_0] = _val_0 3505 end
3640 end 3506end
3641 end 3507if _base_0.__index == nil then
3642 if _base_0.__index == nil then 3508 _base_0.__index = _base_0
3643 _base_0.__index = _base_0 3509end
3644 end 3510setmetatable(_base_0, _parent_0.__base)
3645 setmetatable(_base_0, _parent_0.__base) 3511_class_0 = setmetatable({
3646 _class_0 = setmetatable({ 3512 __init = function(self, ...)
3647 __init = function(self, ...) 3513 return _class_0.__parent.__init(self, ...)
3648 return _class_0.__parent.__init(self, ...) 3514 end,
3649 end, 3515 __base = _base_0,
3650 __base = _base_0, 3516 __name = "MyClass",
3651 __name = "MyClass", 3517 __parent = _parent_0
3652 __parent = _parent_0 3518}, {
3653 }, { 3519 __index = function(cls, name)
3654 __index = function(cls, name) 3520 local val = rawget(_base_0, name)
3655 local val = rawget(_base_0, name) 3521 if val == nil then
3656 if val == nil then 3522 local parent = rawget(cls, "__parent")
3657 local parent = rawget(cls, "__parent") 3523 if parent then
3658 if parent then 3524 return parent[name]
3659 return parent[name]
3660 end
3661 else
3662 return val
3663 end 3525 end
3664 end, 3526 else
3665 __call = function(cls, ...) 3527 return val
3666 local _self_0 = setmetatable({ }, _base_0)
3667 cls.__init(_self_0, ...)
3668 return _self_0
3669 end 3528 end
3670 }) 3529 end,
3671 _base_0.__class = _class_0 3530 __call = function(cls, ...)
3672 if _parent_0.__inherited then 3531 local _self_0 = setmetatable({ }, _base_0)
3673 _parent_0.__inherited(_parent_0, _class_0) 3532 cls.__init(_self_0, ...)
3533 return _self_0
3674 end 3534 end
3675 MyClass = _class_0 3535})
3536_base_0.__class = _class_0
3537if _parent_0.__inherited then
3538 _parent_0.__inherited(_parent_0, _class_0)
3676end 3539end
3540MyClass = _class_0
3677local b = BackPack() 3541local b = BackPack()
3678assert(b.__class == BackPack) 3542assert(b.__class == BackPack)
3679print(BackPack.size) 3543print(BackPack.size)
@@ -3737,61 +3601,57 @@ Counter()
3737print(Counter.count) 3601print(Counter.count)
3738self.__class:hello(1, 2, 3, 4) 3602self.__class:hello(1, 2, 3, 4)
3739local Things 3603local Things
3740do 3604local _class_0
3741 local _class_0 3605local _base_0 = { }
3742 local _base_0 = { } 3606if _base_0.__index == nil then
3743 if _base_0.__index == nil then 3607 _base_0.__index = _base_0
3744 _base_0.__index = _base_0 3608end
3609_class_0 = setmetatable({
3610 __init = function() end,
3611 __base = _base_0,
3612 __name = "Things"
3613}, {
3614 __index = _base_0,
3615 __call = function(cls, ...)
3616 local _self_0 = setmetatable({ }, _base_0)
3617 cls.__init(_self_0, ...)
3618 return _self_0
3745 end 3619 end
3746 _class_0 = setmetatable({ 3620})
3747 __init = function() end, 3621_base_0.__class = _class_0
3748 __base = _base_0, 3622local self = _class_0;
3749 __name = "Things" 3623self.class_var = "hello world"
3750 }, { 3624Things = _class_0
3751 __index = _base_0,
3752 __call = function(cls, ...)
3753 local _self_0 = setmetatable({ }, _base_0)
3754 cls.__init(_self_0, ...)
3755 return _self_0
3756 end
3757 })
3758 _base_0.__class = _class_0
3759 local self = _class_0;
3760 self.class_var = "hello world"
3761 Things = _class_0
3762end
3763local MoreThings 3625local MoreThings
3764do 3626local _class_0
3765 local _class_0 3627local secret, log
3766 local secret, log 3628local _base_0 = {
3767 local _base_0 = { 3629 some_method = function(self)
3768 some_method = function(self) 3630 return log("hello world: " .. secret)
3769 return log("hello world: " .. secret)
3770 end
3771 }
3772 if _base_0.__index == nil then
3773 _base_0.__index = _base_0
3774 end 3631 end
3775 _class_0 = setmetatable({ 3632}
3776 __init = function() end, 3633if _base_0.__index == nil then
3777 __base = _base_0, 3634 _base_0.__index = _base_0
3778 __name = "MoreThings" 3635end
3779 }, { 3636_class_0 = setmetatable({
3780 __index = _base_0, 3637 __init = function() end,
3781 __call = function(cls, ...) 3638 __base = _base_0,
3782 local _self_0 = setmetatable({ }, _base_0) 3639 __name = "MoreThings"
3783 cls.__init(_self_0, ...) 3640}, {
3784 return _self_0 3641 __index = _base_0,
3785 end 3642 __call = function(cls, ...)
3786 }) 3643 local _self_0 = setmetatable({ }, _base_0)
3787 _base_0.__class = _class_0 3644 cls.__init(_self_0, ...)
3788 local self = _class_0; 3645 return _self_0
3789 secret = 123
3790 log = function(msg)
3791 return print("LOG:", msg)
3792 end 3646 end
3793 MoreThings = _class_0 3647})
3648_base_0.__class = _class_0
3649local self = _class_0;
3650secret = 123
3651log = function(msg)
3652 return print("LOG:", msg)
3794end 3653end
3654MoreThings = _class_0
3795assert(self == self) 3655assert(self == self)
3796assert(self.__class == self.__class) 3656assert(self.__class == self.__class)
3797local some_instance_method 3657local some_instance_method
@@ -3825,32 +3685,30 @@ do
3825 _base_0.__class = _class_0 3685 _base_0.__class = _class_0
3826 Something = _class_0 3686 Something = _class_0
3827end 3687end
3828do 3688local _class_0
3829 local _class_0 3689local _base_0 = { }
3830 local _base_0 = { } 3690if _base_0.__index == nil then
3831 if _base_0.__index == nil then 3691 _base_0.__index = _base_0
3832 _base_0.__index = _base_0 3692end
3693_class_0 = setmetatable({
3694 __init = function(self, foo, bar, biz, baz)
3695 self.foo = foo
3696 self.bar = bar
3697 self.__class.biz = biz
3698 self.__class.baz = baz
3699 end,
3700 __base = _base_0,
3701 __name = "Something"
3702}, {
3703 __index = _base_0,
3704 __call = function(cls, ...)
3705 local _self_0 = setmetatable({ }, _base_0)
3706 cls.__init(_self_0, ...)
3707 return _self_0
3833 end 3708 end
3834 _class_0 = setmetatable({ 3709})
3835 __init = function(self, foo, bar, biz, baz) 3710_base_0.__class = _class_0
3836 self.foo = foo 3711Something = _class_0
3837 self.bar = bar
3838 self.__class.biz = biz
3839 self.__class.baz = baz
3840 end,
3841 __base = _base_0,
3842 __name = "Something"
3843 }, {
3844 __index = _base_0,
3845 __call = function(cls, ...)
3846 local _self_0 = setmetatable({ }, _base_0)
3847 cls.__init(_self_0, ...)
3848 return _self_0
3849 end
3850 })
3851 _base_0.__class = _class_0
3852 Something = _class_0
3853end
3854local new 3712local new
3855new = function(self, fieldA, fieldB) 3713new = function(self, fieldA, fieldB)
3856 self.fieldA = fieldA 3714 self.fieldA = fieldA
@@ -3861,33 +3719,31 @@ local obj = new({ }, 123, "abc")
3861print(obj) 3719print(obj)
3862local x 3720local x
3863local Bucket 3721local Bucket
3864do 3722local _class_0
3865 local _class_0 3723local _base_0 = {
3866 local _base_0 = { 3724 drops = 0,
3867 drops = 0, 3725 add_drop = function(self)
3868 add_drop = function(self) 3726 self.drops = self.drops + 1
3869 self.drops = self.drops + 1
3870 end
3871 }
3872 if _base_0.__index == nil then
3873 _base_0.__index = _base_0
3874 end 3727 end
3875 _class_0 = setmetatable({ 3728}
3876 __init = function() end, 3729if _base_0.__index == nil then
3877 __base = _base_0, 3730 _base_0.__index = _base_0
3878 __name = "Bucket"
3879 }, {
3880 __index = _base_0,
3881 __call = function(cls, ...)
3882 local _self_0 = setmetatable({ }, _base_0)
3883 cls.__init(_self_0, ...)
3884 return _self_0
3885 end
3886 })
3887 _base_0.__class = _class_0
3888 Bucket = _class_0
3889 x = _class_0
3890end 3731end
3732_class_0 = setmetatable({
3733 __init = function() end,
3734 __base = _base_0,
3735 __name = "Bucket"
3736}, {
3737 __index = _base_0,
3738 __call = function(cls, ...)
3739 local _self_0 = setmetatable({ }, _base_0)
3740 cls.__init(_self_0, ...)
3741 return _self_0
3742 end
3743})
3744_base_0.__class = _class_0
3745Bucket = _class_0
3746x = _class_0
3891local BigBucket 3747local BigBucket
3892do 3748do
3893 local _class_0 3749 local _class_0
@@ -3939,27 +3795,25 @@ do
3939end 3795end
3940assert(Bucket.__name == "BigBucket") 3796assert(Bucket.__name == "BigBucket")
3941local x 3797local x
3942do 3798local _class_0
3943 local _class_0 3799local _base_0 = { }
3944 local _base_0 = { } 3800if _base_0.__index == nil then
3945 if _base_0.__index == nil then 3801 _base_0.__index = _base_0
3946 _base_0.__index = _base_0 3802end
3803_class_0 = setmetatable({
3804 __init = function() end,
3805 __base = _base_0,
3806 __name = "x"
3807}, {
3808 __index = _base_0,
3809 __call = function(cls, ...)
3810 local _self_0 = setmetatable({ }, _base_0)
3811 cls.__init(_self_0, ...)
3812 return _self_0
3947 end 3813 end
3948 _class_0 = setmetatable({ 3814})
3949 __init = function() end, 3815_base_0.__class = _class_0
3950 __base = _base_0, 3816x = _class_0
3951 __name = "x"
3952 }, {
3953 __index = _base_0,
3954 __call = function(cls, ...)
3955 local _self_0 = setmetatable({ }, _base_0)
3956 cls.__init(_self_0, ...)
3957 return _self_0
3958 end
3959 })
3960 _base_0.__class = _class_0
3961 x = _class_0
3962end
3963local MyIndex = { 3817local MyIndex = {
3964 __index = { 3818 __index = {
3965 var = 1 3819 var = 1
@@ -4042,19 +3896,15 @@ end
4042local y = Y() 3896local y = Y()
4043y:func() 3897y:func()
4044assert(y.__class.__parent ~= X) 3898assert(y.__class.__parent ~= X)
4045do 3899local _with_0 = Person()
4046 local _with_0 = Person() 3900_with_0.name = "Oswald"
4047 _with_0.name = "Oswald" 3901_with_0:add_relative(my_dad)
4048 _with_0:add_relative(my_dad) 3902_with_0:save()
4049 _with_0:save() 3903print(_with_0.name)
4050 print(_with_0.name)
4051end
4052local file 3904local file
4053do 3905local _with_0 = File("favorite_foods.txt")
4054 local _with_0 = File("favorite_foods.txt") 3906_with_0:set_encoding("utf8")
4055 _with_0:set_encoding("utf8") 3907file = _with_0
4056 file = _with_0
4057end
4058local create_person 3908local create_person
4059create_person = function(name, relatives) 3909create_person = function(name, relatives)
4060 local _with_0 = Person() 3910 local _with_0 = Person()
@@ -4070,22 +3920,18 @@ local me = create_person("Leaf", {
4070 mother, 3920 mother,
4071 sister 3921 sister
4072}) 3922})
4073do 3923local str = "Hello"
4074 local str = "Hello" 3924print("original:", str)
4075 print("original:", str) 3925print("upper:", str:upper())
4076 print("upper:", str:upper()) 3926local _with_0 = tb
4077end 3927_with_0[1] = 1
4078do 3928print(_with_0[2])
4079 local _with_0 = tb 3929do
4080 _with_0[1] = 1 3930 local _with_1 = _with_0[abc]
4081 print(_with_0[2]) 3931 _with_1[3] = _with_1[2]:func()
4082 do 3932 _with_1["key-name"] = value
4083 local _with_1 = _with_0[abc] 3933end
4084 _with_1[3] = _with_1[2]:func() 3934_with_0[#_with_0 + 1] = "abc"
4085 _with_1["key-name"] = value
4086 end
4087 _with_0[#_with_0 + 1] = "abc"
4088end
4089do 3935do
4090 local var = "hello" 3936 local var = "hello"
4091 print(var) 3937 print(var)