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