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.lua934
1 files changed, 914 insertions, 20 deletions
diff --git a/spec/outputs/codes_from_doc.lua b/spec/outputs/codes_from_doc.lua
index 27f8de5..055e79b 100644
--- a/spec/outputs/codes_from_doc.lua
+++ b/spec/outputs/codes_from_doc.lua
@@ -20,6 +20,38 @@ local inventory = {
20 } 20 }
21 } 21 }
22} 22}
23local map
24map = function(arr, action)
25 local _accum_0 = { }
26 local _len_0 = 1
27 for _index_0 = 1, #arr do
28 local item = arr[_index_0]
29 _accum_0[_len_0] = action(item)
30 _len_0 = _len_0 + 1
31 end
32 return _accum_0
33end
34local filter
35filter = function(arr, cond)
36 local _accum_0 = { }
37 local _len_0 = 1
38 for _index_0 = 1, #arr do
39 local item = arr[_index_0]
40 if cond(item) then
41 _accum_0[_len_0] = item
42 _len_0 = _len_0 + 1
43 end
44 end
45 return _accum_0
46end
47local reduce
48reduce = function(arr, init, action)
49 for _index_0 = 1, #arr do
50 local item = arr[_index_0]
51 init = action(init, item)
52 end
53 return init
54end
23print(reduce(filter(map({ 55print(reduce(filter(map({
24 1, 56 1,
25 2, 57 2,
@@ -77,6 +109,12 @@ end
77print("yuescript") 109print("yuescript")
78print(3) 110print(3)
79print("Valid enum type:", "Static") 111print("Valid enum type:", "Static")
112do
113 print(123, "hello")
114end
115do
116 print(123, "hello")
117end
80if tb ~= nil then 118if tb ~= nil then
81 tb:func() 119 tb:func()
82end 120end
@@ -177,6 +215,16 @@ for _key_0, _value_0 in pairs(b) do
177 end 215 end
178end 216end
179merge = _tab_0 217merge = _tab_0
218local last
219do
220 local _item_0 = data.items
221 last = _item_0[#_item_0]
222end
223local second_last
224do
225 local _item_0 = data.items
226 second_last = _item_0[#_item_0 - 1]
227end
180local mt = { } 228local mt = { }
181local add 229local add
182add = function(self, right) 230add = function(self, right)
@@ -307,6 +355,14 @@ func({
307 2, 355 2,
308 3 356 3
309}) 357})
358local f
359f = function()
360 return {
361 1,
362 2,
363 3
364 }
365end
310local tb = { 366local tb = {
311 name = "abc", 367 name = "abc",
312 values = { 368 values = {
@@ -547,6 +603,59 @@ end
547local two, four 603local two, four
548local _obj_0 = items 604local _obj_0 = items
549two, four = _obj_0[2], _obj_0[4] 605two, four = _obj_0[2], _obj_0[4]
606local orders = {
607 "first",
608 "second",
609 "third",
610 "fourth",
611 "last"
612}
613local first, bulk, last = orders[1], (function()
614 local _accum_0 = { }
615 local _len_0 = 1
616 local _max_0 = #orders + -2 + 1
617 for _index_0 = 2, _max_0 do
618 local _item_0 = orders[_index_0]
619 _accum_0[_len_0] = _item_0
620 _len_0 = _len_0 + 1
621 end
622 return _accum_0
623end)(), orders[#orders]
624print(first)
625print(bulk)
626print(last)
627local first, rest
628do
629 local _obj_0 = orders
630 first, rest = _obj_0[1], (function()
631 local _accum_0 = { }
632 local _len_0 = 1
633 local _max_0 = #_obj_0
634 for _index_0 = 2, _max_0 do
635 local _item_0 = _obj_0[_index_0]
636 _accum_0[_len_0] = _item_0
637 _len_0 = _len_0 + 1
638 end
639 return _accum_0
640 end)()
641end
642local start, last
643do
644 local _obj_0 = orders
645 start, last = (function()
646 local _accum_0 = { }
647 local _len_0 = 1
648 local _max_0 = #_obj_0 + -2 + 1
649 for _index_0 = 1, _max_0 do
650 local _item_0 = _obj_0[_index_0]
651 _accum_0[_len_0] = _item_0
652 _len_0 = _len_0 + 1
653 end
654 return _accum_0
655 end)(), _obj_0[#_obj_0]
656end
657local _obj_0 = orders
658first, last = _obj_0[1], _obj_0[#_obj_0]
550local tuples = { 659local tuples = {
551 { 660 {
552 "hello", 661 "hello",
@@ -648,6 +757,56 @@ end)
648if success then 757if success then
649 print(result) 758 print(result)
650end 759end
760local a, b, c
761do
762 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
763 return func()
764 end)
765 if _ok_0 then
766 a, b, c = _ret_0, _ret_1, _ret_2
767 end
768end
769do
770 local _exp_0 = ((function()
771 return (function(_arg_0, ...)
772 local _ok_0 = _arg_0
773 if _ok_0 then
774 return ...
775 end
776 end)(pcall(function()
777 return func()
778 end))
779 end)())
780 if _exp_0 ~= nil then
781 a = _exp_0
782 else
783 a = "default"
784 end
785end
786f((function()
787 return (function(_arg_0, ...)
788 local _ok_0 = _arg_0
789 if _ok_0 then
790 return ...
791 end
792 end)(pcall(function()
793 return func()
794 end))
795end)())
796f((function()
797 return (function(_arg_0, ...)
798 local _ok_0 = _arg_0
799 if _ok_0 then
800 return ...
801 end
802 end)(xpcall(function()
803 print(123)
804 return func()
805 end, function(e)
806 print(e)
807 return e
808 end))
809end)())
651local a <const> = 123 810local a <const> = 123
652local _ <close> = setmetatable({ }, { 811local _ <close> = setmetatable({ }, {
653 __close = function() 812 __close = function()
@@ -657,10 +816,19 @@ local _ <close> = setmetatable({ }, {
657local a, b, c, d 816local a, b, c, d
658local _obj_0 = tb 817local _obj_0 = tb
659a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] 818a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
819Constant = 123
660local some_string = "Here is a string\n that has a line break in it." 820local some_string = "Here is a string\n that has a line break in it."
661print("I am " .. tostring(math.random() * 100) .. "% sure.") 821print("I am " .. tostring(math.random() * 100) .. "% sure.")
662local integer = 1000000 822local integer = 1000000
663local hex = 0xEFBBBF 823local hex = 0xEFBBBF
824local binary = 19
825local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
826local fn
827fn = function()
828 local str = "foo:\n bar: baz"
829 return str
830end
831local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
664local my_function 832local my_function
665my_function = function() end 833my_function = function() end
666my_function() 834my_function()
@@ -755,6 +923,36 @@ if func(1, 2, 3, "hello", "world") then
755 print("hello") 923 print("hello")
756 print("I am inside if") 924 print("I am inside if")
757end 925end
926local f1
927f1 = function(_arg_0)
928 local a, b, c
929 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
930 return print(a, b, c)
931end
932f1({
933 a = 1,
934 b = "2",
935 c = { }
936})
937local f2
938f2 = function(_arg_0, c)
939 local a1, b
940 a1, b = _arg_0.a, _arg_0.b
941 if a1 == nil then
942 a1 = 123
943 end
944 if b == nil then
945 b = 'abc'
946 end
947 if c == nil then
948 c = { }
949 end
950 return print(a1, b, c)
951end
952local arg1 = {
953 a = 0
954}
955f2(arg1, arg2)
758f(function() 956f(function()
759 return print("hello") 957 return print("hello")
760end) 958end)
@@ -860,11 +1058,10 @@ for i, item in ipairs(items) do
860 _len_0 = _len_0 + 1 1058 _len_0 = _len_0 + 1
861end 1059end
862doubled = _accum_0 1060doubled = _accum_0
863local iter = ipairs(items)
864local slice 1061local slice
865local _accum_0 = { } 1062local _accum_0 = { }
866local _len_0 = 1 1063local _len_0 = 1
867for i, item in iter do 1064for i, item in ipairs(items) do
868 if i > 1 and i < 3 then 1065 if i > 1 and i < 3 then
869 _accum_0[_len_0] = item 1066 _accum_0[_len_0] = item
870 _len_0 = _len_0 + 1 1067 _len_0 = _len_0 + 1
@@ -971,8 +1168,7 @@ local slice
971local _accum_0 = { } 1168local _accum_0 = { }
972local _len_0 = 1 1169local _len_0 = 1
973local _list_0 = items 1170local _list_0 = items
974local _max_0 = 5 1171for _index_0 = 1, 5 do
975for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
976 local item = _list_0[_index_0] 1172 local item = _list_0[_index_0]
977 _accum_0[_len_0] = item 1173 _accum_0[_len_0] = item
978 _len_0 = _len_0 + 1 1174 _len_0 = _len_0 + 1
@@ -982,7 +1178,8 @@ local slice
982local _accum_0 = { } 1178local _accum_0 = { }
983local _len_0 = 1 1179local _len_0 = 1
984local _list_0 = items 1180local _list_0 = items
985for _index_0 = 2, #_list_0 do 1181local _max_0 = #_list_0
1182for _index_0 = 2, _max_0 do
986 local item = _list_0[_index_0] 1183 local item = _list_0[_index_0]
987 _accum_0[_len_0] = item 1184 _accum_0[_len_0] = item
988 _len_0 = _len_0 + 1 1185 _len_0 = _len_0 + 1
@@ -992,12 +1189,46 @@ local slice
992local _accum_0 = { } 1189local _accum_0 = { }
993local _len_0 = 1 1190local _len_0 = 1
994local _list_0 = items 1191local _list_0 = items
995for _index_0 = 1, #_list_0, 2 do 1192local _max_0 = #_list_0
1193for _index_0 = 1, _max_0, 2 do
996 local item = _list_0[_index_0] 1194 local item = _list_0[_index_0]
997 _accum_0[_len_0] = item 1195 _accum_0[_len_0] = item
998 _len_0 = _len_0 + 1 1196 _len_0 = _len_0 + 1
999end 1197end
1000slice = _accum_0 1198slice = _accum_0
1199local slice
1200local _accum_0 = { }
1201local _len_0 = 1
1202local _list_0 = items
1203local _min_0 = #_list_0 + -4 + 1
1204local _max_0 = #_list_0 + -1 + 1
1205for _index_0 = _min_0, _max_0 do
1206 local item = _list_0[_index_0]
1207 _accum_0[_len_0] = item
1208 _len_0 = _len_0 + 1
1209end
1210slice = _accum_0
1211local reverse_slice
1212local _accum_0 = { }
1213local _len_0 = 1
1214local _list_0 = items
1215local _min_0 = #_list_0 + -1 + 1
1216for _index_0 = _min_0, 1, -1 do
1217 local item = _list_0[_index_0]
1218 _accum_0[_len_0] = item
1219 _len_0 = _len_0 + 1
1220end
1221reverse_slice = _accum_0
1222local sub_list
1223local _accum_0 = { }
1224local _len_0 = 1
1225local _list_0 = items
1226for _index_0 = 2, 4 do
1227 local _item_0 = _list_0[_index_0]
1228 _accum_0[_len_0] = _item_0
1229 _len_0 = _len_0 + 1
1230end
1231sub_list = _accum_0
1001for i = 10, 20 do 1232for i = 10, 20 do
1002 print(i) 1233 print(i)
1003end 1234end
@@ -1008,8 +1239,7 @@ for key, value in pairs(object) do
1008 print(key, value) 1239 print(key, value)
1009end 1240end
1010local _list_0 = items 1241local _list_0 = items
1011local _max_0 = 4 1242for _index_0 = 2, 4 do
1012for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
1013 local item = _list_0[_index_0] 1243 local item = _list_0[_index_0]
1014 print(item) 1244 print(item)
1015end 1245end
@@ -1027,12 +1257,24 @@ local _len_0 = 1
1027for i = 1, 20 do 1257for i = 1, 20 do
1028 if i % 2 == 0 then 1258 if i % 2 == 0 then
1029 _accum_0[_len_0] = i * 2 1259 _accum_0[_len_0] = i * 2
1260 _len_0 = _len_0 + 1
1030 else 1261 else
1031 _accum_0[_len_0] = i 1262 _accum_0[_len_0] = i
1263 _len_0 = _len_0 + 1
1032 end 1264 end
1033 _len_0 = _len_0 + 1
1034end 1265end
1035doubled_evens = _accum_0 1266doubled_evens = _accum_0
1267local first_large
1268local _accum_0
1269local _list_0 = numbers
1270for _index_0 = 1, #_list_0 do
1271 local n = _list_0[_index_0]
1272 if n > 10 then
1273 _accum_0 = n
1274 break
1275 end
1276end
1277first_large = _accum_0
1036local func_a 1278local func_a
1037func_a = function() 1279func_a = function()
1038 for i = 1, 10 do 1280 for i = 1, 10 do
@@ -1181,7 +1423,7 @@ if "Robert" == name then
1181elseif "Dan" == name or "Daniel" == name then 1423elseif "Dan" == name or "Daniel" == name then
1182 print("Your name, it's Dan") 1424 print("Your name, it's Dan")
1183else 1425else
1184 print("I don't know about your name") 1426 print("I don't know about you with name " .. tostring(name))
1185end 1427end
1186local b = 1 1428local b = 1
1187local next_number 1429local next_number
@@ -1281,6 +1523,192 @@ if _tab_0 then
1281 end 1523 end
1282 print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) 1524 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
1283end 1525end
1526local _exp_0 = tb
1527local _type_0 = type(_exp_0)
1528local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1529local _match_0 = false
1530if _tab_0 then
1531 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
1532 _match_0 = true
1533 print("1, 2, 3")
1534 end
1535end
1536if not _match_0 then
1537 local _match_1 = false
1538 if _tab_0 then
1539 local b = _exp_0[2]
1540 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
1541 _match_1 = true
1542 print("1, " .. tostring(b) .. ", 3")
1543 end
1544 end
1545 if not _match_1 then
1546 if _tab_0 then
1547 local b = _exp_0[3]
1548 if b == nil then
1549 b = 3
1550 end
1551 if 1 == _exp_0[1] and 2 == _exp_0[2] then
1552 print("1, 2, " .. tostring(b))
1553 end
1554 end
1555 end
1556end
1557local _exp_0 = tb
1558local _type_0 = type(_exp_0)
1559local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1560local _match_0 = false
1561if _tab_0 then
1562 local result = _exp_0.result
1563 if true == _exp_0.success and result ~= nil then
1564 _match_0 = true
1565 print("success", result)
1566 end
1567end
1568if not _match_0 then
1569 local _match_1 = false
1570 if _tab_0 then
1571 if false == _exp_0.success then
1572 _match_1 = true
1573 print("failed", result)
1574 end
1575 end
1576 if not _match_1 then
1577 print("invalid")
1578 end
1579end
1580local _exp_0 = tb
1581local _type_0 = type(_exp_0)
1582local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1583local _match_0 = false
1584if _tab_0 then
1585 local content
1586 do
1587 local _obj_0 = _exp_0.data
1588 local _type_1 = type(_obj_0)
1589 if "table" == _type_1 or "userdata" == _type_1 then
1590 content = _obj_0.content
1591 end
1592 end
1593 local _val_0
1594 do
1595 local _obj_0 = _exp_0.data
1596 if _obj_0 ~= nil then
1597 _val_0 = _obj_0.type
1598 end
1599 end
1600 if "success" == _val_0 and content ~= nil then
1601 _match_0 = true
1602 print("success", content)
1603 end
1604end
1605if not _match_0 then
1606 local _match_1 = false
1607 if _tab_0 then
1608 local content
1609 do
1610 local _obj_0 = _exp_0.data
1611 local _type_1 = type(_obj_0)
1612 if "table" == _type_1 or "userdata" == _type_1 then
1613 content = _obj_0.content
1614 end
1615 end
1616 local _val_0
1617 do
1618 local _obj_0 = _exp_0.data
1619 if _obj_0 ~= nil then
1620 _val_0 = _obj_0.type
1621 end
1622 end
1623 if "error" == _val_0 and content ~= nil then
1624 _match_1 = true
1625 print("failed", content)
1626 end
1627 end
1628 if not _match_1 then
1629 print("invalid")
1630 end
1631end
1632local _exp_0 = tb
1633local _type_0 = type(_exp_0)
1634local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1635if _tab_0 then
1636 local fourth = _exp_0[4]
1637 local _val_0
1638 do
1639 local _obj_0 = _exp_0[1]
1640 if _obj_0 ~= nil then
1641 _val_0 = _obj_0.a
1642 end
1643 end
1644 local _val_1
1645 do
1646 local _obj_0 = _exp_0[1]
1647 if _obj_0 ~= nil then
1648 _val_1 = _obj_0.b
1649 end
1650 end
1651 local _val_2
1652 do
1653 local _obj_0 = _exp_0[2]
1654 if _obj_0 ~= nil then
1655 _val_2 = _obj_0.a
1656 end
1657 end
1658 local _val_3
1659 do
1660 local _obj_0 = _exp_0[2]
1661 if _obj_0 ~= nil then
1662 _val_3 = _obj_0.b
1663 end
1664 end
1665 local _val_4
1666 do
1667 local _obj_0 = _exp_0[3]
1668 if _obj_0 ~= nil then
1669 _val_4 = _obj_0.a
1670 end
1671 end
1672 local _val_5
1673 do
1674 local _obj_0 = _exp_0[3]
1675 if _obj_0 ~= nil then
1676 _val_5 = _obj_0.b
1677 end
1678 end
1679 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
1680 print("matched", fourth)
1681 end
1682end
1683local segments = {
1684 "admin",
1685 "users",
1686 "logs",
1687 "view"
1688}
1689local _type_0 = type(segments)
1690local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1691if _tab_0 then
1692 local groups
1693 do
1694 local _accum_0 = { }
1695 local _len_0 = 1
1696 local _max_0 = #segments + -3 + 1
1697 for _index_0 = 1, _max_0 do
1698 local _item_0 = segments[_index_0]
1699 _accum_0[_len_0] = _item_0
1700 _len_0 = _len_0 + 1
1701 end
1702 groups = _accum_0
1703 end
1704 local resource = segments[#segments - 1]
1705 local action = segments[#segments]
1706 if resource ~= nil and action ~= nil then
1707 print("Group:", groups)
1708 print("Resource:", resource)
1709 print("Action:", action)
1710 end
1711end
1284local Inventory 1712local Inventory
1285local _class_0 1713local _class_0
1286local _base_0 = { 1714local _base_0 = {
@@ -1937,6 +2365,10 @@ do
1937 _with_1["key-name"] = value 2365 _with_1["key-name"] = value
1938end 2366end
1939_with_0[#_with_0 + 1] = "abc" 2367_with_0[#_with_0 + 1] = "abc"
2368local _with_0 = obj
2369if _with_0 ~= nil then
2370 print(obj.name)
2371end
1940do 2372do
1941 local var = "hello" 2373 local var = "hello"
1942 print(var) 2374 print(var)
@@ -2027,6 +2459,38 @@ local inventory = {
2027 } 2459 }
2028 } 2460 }
2029} 2461}
2462local map
2463map = function(arr, action)
2464 local _accum_0 = { }
2465 local _len_0 = 1
2466 for _index_0 = 1, #arr do
2467 local item = arr[_index_0]
2468 _accum_0[_len_0] = action(item)
2469 _len_0 = _len_0 + 1
2470 end
2471 return _accum_0
2472end
2473local filter
2474filter = function(arr, cond)
2475 local _accum_0 = { }
2476 local _len_0 = 1
2477 for _index_0 = 1, #arr do
2478 local item = arr[_index_0]
2479 if cond(item) then
2480 _accum_0[_len_0] = item
2481 _len_0 = _len_0 + 1
2482 end
2483 end
2484 return _accum_0
2485end
2486local reduce
2487reduce = function(arr, init, action)
2488 for _index_0 = 1, #arr do
2489 local item = arr[_index_0]
2490 init = action(init, item)
2491 end
2492 return init
2493end
2030print(reduce(filter(map({ 2494print(reduce(filter(map({
2031 1, 2495 1,
2032 2, 2496 2,
@@ -2084,6 +2548,12 @@ end
2084print("yuescript") 2548print("yuescript")
2085print(3) 2549print(3)
2086print("Valid enum type:", "Static") 2550print("Valid enum type:", "Static")
2551do
2552 print(123, "hello")
2553end
2554do
2555 print(123, "hello")
2556end
2087if tb ~= nil then 2557if tb ~= nil then
2088 tb:func() 2558 tb:func()
2089end 2559end
@@ -2184,6 +2654,16 @@ for _key_0, _value_0 in pairs(b) do
2184 end 2654 end
2185end 2655end
2186merge = _tab_0 2656merge = _tab_0
2657local last
2658do
2659 local _item_0 = data.items
2660 last = _item_0[#_item_0]
2661end
2662local second_last
2663do
2664 local _item_0 = data.items
2665 second_last = _item_0[#_item_0 - 1]
2666end
2187local mt = { } 2667local mt = { }
2188local add 2668local add
2189add = function(self, right) 2669add = function(self, right)
@@ -2314,6 +2794,14 @@ func({
2314 2, 2794 2,
2315 3 2795 3
2316}) 2796})
2797local f
2798f = function()
2799 return {
2800 1,
2801 2,
2802 3
2803 }
2804end
2317local tb = { 2805local tb = {
2318 name = "abc", 2806 name = "abc",
2319 values = { 2807 values = {
@@ -2554,6 +3042,59 @@ end
2554local two, four 3042local two, four
2555local _obj_0 = items 3043local _obj_0 = items
2556two, four = _obj_0[2], _obj_0[4] 3044two, four = _obj_0[2], _obj_0[4]
3045local orders = {
3046 "first",
3047 "second",
3048 "third",
3049 "fourth",
3050 "last"
3051}
3052local first, bulk, last = orders[1], (function()
3053 local _accum_0 = { }
3054 local _len_0 = 1
3055 local _max_0 = #orders + -2 + 1
3056 for _index_0 = 2, _max_0 do
3057 local _item_0 = orders[_index_0]
3058 _accum_0[_len_0] = _item_0
3059 _len_0 = _len_0 + 1
3060 end
3061 return _accum_0
3062end)(), orders[#orders]
3063print(first)
3064print(bulk)
3065print(last)
3066local first, rest
3067do
3068 local _obj_0 = orders
3069 first, rest = _obj_0[1], (function()
3070 local _accum_0 = { }
3071 local _len_0 = 1
3072 local _max_0 = #_obj_0
3073 for _index_0 = 2, _max_0 do
3074 local _item_0 = _obj_0[_index_0]
3075 _accum_0[_len_0] = _item_0
3076 _len_0 = _len_0 + 1
3077 end
3078 return _accum_0
3079 end)()
3080end
3081local start, last
3082do
3083 local _obj_0 = orders
3084 start, last = (function()
3085 local _accum_0 = { }
3086 local _len_0 = 1
3087 local _max_0 = #_obj_0 + -2 + 1
3088 for _index_0 = 1, _max_0 do
3089 local _item_0 = _obj_0[_index_0]
3090 _accum_0[_len_0] = _item_0
3091 _len_0 = _len_0 + 1
3092 end
3093 return _accum_0
3094 end)(), _obj_0[#_obj_0]
3095end
3096local _obj_0 = orders
3097first, last = _obj_0[1], _obj_0[#_obj_0]
2557local tuples = { 3098local tuples = {
2558 { 3099 {
2559 "hello", 3100 "hello",
@@ -2655,6 +3196,56 @@ end)
2655if success then 3196if success then
2656 print(result) 3197 print(result)
2657end 3198end
3199local a, b, c
3200do
3201 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
3202 return func()
3203 end)
3204 if _ok_0 then
3205 a, b, c = _ret_0, _ret_1, _ret_2
3206 end
3207end
3208do
3209 local _exp_0 = ((function()
3210 return (function(_arg_0, ...)
3211 local _ok_0 = _arg_0
3212 if _ok_0 then
3213 return ...
3214 end
3215 end)(pcall(function()
3216 return func()
3217 end))
3218 end)())
3219 if _exp_0 ~= nil then
3220 a = _exp_0
3221 else
3222 a = "default"
3223 end
3224end
3225f((function()
3226 return (function(_arg_0, ...)
3227 local _ok_0 = _arg_0
3228 if _ok_0 then
3229 return ...
3230 end
3231 end)(pcall(function()
3232 return func()
3233 end))
3234end)())
3235f((function()
3236 return (function(_arg_0, ...)
3237 local _ok_0 = _arg_0
3238 if _ok_0 then
3239 return ...
3240 end
3241 end)(xpcall(function()
3242 print(123)
3243 return func()
3244 end, function(e)
3245 print(e)
3246 return e
3247 end))
3248end)())
2658local a <const> = 123 3249local a <const> = 123
2659local _ <close> = setmetatable({ }, { 3250local _ <close> = setmetatable({ }, {
2660 __close = function() 3251 __close = function()
@@ -2664,10 +3255,19 @@ local _ <close> = setmetatable({ }, {
2664local a, b, c, d 3255local a, b, c, d
2665local _obj_0 = tb 3256local _obj_0 = tb
2666a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] 3257a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
3258Constant = 123
2667local some_string = "Here is a string\n that has a line break in it." 3259local some_string = "Here is a string\n that has a line break in it."
2668print("I am " .. tostring(math.random() * 100) .. "% sure.") 3260print("I am " .. tostring(math.random() * 100) .. "% sure.")
2669local integer = 1000000 3261local integer = 1000000
2670local hex = 0xEFBBBF 3262local hex = 0xEFBBBF
3263local binary = 19
3264local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
3265local fn
3266fn = function()
3267 local str = "foo:\n bar: baz"
3268 return str
3269end
3270local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
2671local my_function 3271local my_function
2672my_function = function() end 3272my_function = function() end
2673my_function() 3273my_function()
@@ -2762,6 +3362,66 @@ if func(1, 2, 3, "hello", "world") then
2762 print("hello") 3362 print("hello")
2763 print("I am inside if") 3363 print("I am inside if")
2764end 3364end
3365local f1
3366f1 = function(_arg_0)
3367 local a, b, c
3368 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
3369 return print(a, b, c)
3370end
3371f1({
3372 a = 1,
3373 b = "2",
3374 c = { }
3375})
3376local f2
3377f2 = function(_arg_0, c)
3378 local a1, b
3379 a1, b = _arg_0.a, _arg_0.b
3380 if a1 == nil then
3381 a1 = 123
3382 end
3383 if b == nil then
3384 b = 'abc'
3385 end
3386 if c == nil then
3387 c = { }
3388 end
3389end
3390print(a1, b, c)
3391local arg1 = {
3392 a = 0
3393}
3394f2(arg1, arg2)
3395local findFirstEven
3396findFirstEven = function(list)
3397 for _index_0 = 1, #list do
3398 local item = list[_index_0]
3399 if type(item) == "table" then
3400 for _index_1 = 1, #item do
3401 local sub = item[_index_1]
3402 if sub % 2 == 0 then
3403 return sub
3404 end
3405 end
3406 end
3407 end
3408 return nil
3409end
3410local findFirstEven
3411findFirstEven = function(list)
3412 for _index_0 = 1, #list do
3413 local item = list[_index_0]
3414 if type(item) == "table" then
3415 for _index_1 = 1, #item do
3416 local sub = item[_index_1]
3417 if sub % 2 == 0 then
3418 return sub
3419 end
3420 end
3421 end
3422 end
3423 return nil
3424end
2765f(function() 3425f(function()
2766 return print("hello") 3426 return print("hello")
2767end) 3427end)
@@ -2867,11 +3527,10 @@ for i, item in ipairs(items) do
2867 _len_0 = _len_0 + 1 3527 _len_0 = _len_0 + 1
2868end 3528end
2869doubled = _accum_0 3529doubled = _accum_0
2870local iter = ipairs(items)
2871local slice 3530local slice
2872local _accum_0 = { } 3531local _accum_0 = { }
2873local _len_0 = 1 3532local _len_0 = 1
2874for i, item in iter do 3533for i, item in ipairs(items) do
2875 if i > 1 and i < 3 then 3534 if i > 1 and i < 3 then
2876 _accum_0[_len_0] = item 3535 _accum_0[_len_0] = item
2877 _len_0 = _len_0 + 1 3536 _len_0 = _len_0 + 1
@@ -2978,8 +3637,7 @@ local slice
2978local _accum_0 = { } 3637local _accum_0 = { }
2979local _len_0 = 1 3638local _len_0 = 1
2980local _list_0 = items 3639local _list_0 = items
2981local _max_0 = 5 3640for _index_0 = 1, 5 do
2982for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
2983 local item = _list_0[_index_0] 3641 local item = _list_0[_index_0]
2984 _accum_0[_len_0] = item 3642 _accum_0[_len_0] = item
2985 _len_0 = _len_0 + 1 3643 _len_0 = _len_0 + 1
@@ -2989,7 +3647,8 @@ local slice
2989local _accum_0 = { } 3647local _accum_0 = { }
2990local _len_0 = 1 3648local _len_0 = 1
2991local _list_0 = items 3649local _list_0 = items
2992for _index_0 = 2, #_list_0 do 3650local _max_0 = #_list_0
3651for _index_0 = 2, _max_0 do
2993 local item = _list_0[_index_0] 3652 local item = _list_0[_index_0]
2994 _accum_0[_len_0] = item 3653 _accum_0[_len_0] = item
2995 _len_0 = _len_0 + 1 3654 _len_0 = _len_0 + 1
@@ -2999,12 +3658,46 @@ local slice
2999local _accum_0 = { } 3658local _accum_0 = { }
3000local _len_0 = 1 3659local _len_0 = 1
3001local _list_0 = items 3660local _list_0 = items
3002for _index_0 = 1, #_list_0, 2 do 3661local _max_0 = #_list_0
3662for _index_0 = 1, _max_0, 2 do
3003 local item = _list_0[_index_0] 3663 local item = _list_0[_index_0]
3004 _accum_0[_len_0] = item 3664 _accum_0[_len_0] = item
3005 _len_0 = _len_0 + 1 3665 _len_0 = _len_0 + 1
3006end 3666end
3007slice = _accum_0 3667slice = _accum_0
3668local slice
3669local _accum_0 = { }
3670local _len_0 = 1
3671local _list_0 = items
3672local _min_0 = #_list_0 + -4 + 1
3673local _max_0 = #_list_0 + -1 + 1
3674for _index_0 = _min_0, _max_0 do
3675 local item = _list_0[_index_0]
3676 _accum_0[_len_0] = item
3677 _len_0 = _len_0 + 1
3678end
3679slice = _accum_0
3680local reverse_slice
3681local _accum_0 = { }
3682local _len_0 = 1
3683local _list_0 = items
3684local _min_0 = #_list_0 + -1 + 1
3685for _index_0 = _min_0, 1, -1 do
3686 local item = _list_0[_index_0]
3687 _accum_0[_len_0] = item
3688 _len_0 = _len_0 + 1
3689end
3690reverse_slice = _accum_0
3691local sub_list
3692local _accum_0 = { }
3693local _len_0 = 1
3694local _list_0 = items
3695for _index_0 = 2, 4 do
3696 local _item_0 = _list_0[_index_0]
3697 _accum_0[_len_0] = _item_0
3698 _len_0 = _len_0 + 1
3699end
3700sub_list = _accum_0
3008for i = 10, 20 do 3701for i = 10, 20 do
3009 print(i) 3702 print(i)
3010end 3703end
@@ -3015,8 +3708,7 @@ for key, value in pairs(object) do
3015 print(key, value) 3708 print(key, value)
3016end 3709end
3017local _list_0 = items 3710local _list_0 = items
3018local _max_0 = 4 3711for _index_0 = 2, 4 do
3019for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
3020 local item = _list_0[_index_0] 3712 local item = _list_0[_index_0]
3021 print(item) 3713 print(item)
3022end 3714end
@@ -3034,12 +3726,24 @@ local _len_0 = 1
3034for i = 1, 20 do 3726for i = 1, 20 do
3035 if i % 2 == 0 then 3727 if i % 2 == 0 then
3036 _accum_0[_len_0] = i * 2 3728 _accum_0[_len_0] = i * 2
3729 _len_0 = _len_0 + 1
3037 else 3730 else
3038 _accum_0[_len_0] = i 3731 _accum_0[_len_0] = i
3732 _len_0 = _len_0 + 1
3039 end 3733 end
3040 _len_0 = _len_0 + 1
3041end 3734end
3042doubled_evens = _accum_0 3735doubled_evens = _accum_0
3736local first_large
3737local _accum_0
3738local _list_0 = numbers
3739for _index_0 = 1, #_list_0 do
3740 local n = _list_0[_index_0]
3741 if n > 10 then
3742 _accum_0 = n
3743 break
3744 end
3745end
3746first_large = _accum_0
3043local func_a 3747local func_a
3044func_a = function() 3748func_a = function()
3045 for i = 1, 10 do 3749 for i = 1, 10 do
@@ -3188,7 +3892,7 @@ if "Robert" == name then
3188elseif "Dan" == name or "Daniel" == name then 3892elseif "Dan" == name or "Daniel" == name then
3189 print("Your name, it's Dan") 3893 print("Your name, it's Dan")
3190else 3894else
3191 print("I don't know about your name") 3895 print("I don't know about you with name " .. tostring(name))
3192end 3896end
3193local b = 1 3897local b = 1
3194local next_number 3898local next_number
@@ -3288,6 +3992,192 @@ if _tab_0 then
3288 end 3992 end
3289 print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) 3993 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3290end 3994end
3995local _exp_0 = tb
3996local _type_0 = type(_exp_0)
3997local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3998local _match_0 = false
3999if _tab_0 then
4000 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
4001 _match_0 = true
4002 print("1, 2, 3")
4003 end
4004end
4005if not _match_0 then
4006 local _match_1 = false
4007 if _tab_0 then
4008 local b = _exp_0[2]
4009 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
4010 _match_1 = true
4011 print("1, " .. tostring(b) .. ", 3")
4012 end
4013 end
4014 if not _match_1 then
4015 if _tab_0 then
4016 local b = _exp_0[3]
4017 if b == nil then
4018 b = 3
4019 end
4020 if 1 == _exp_0[1] and 2 == _exp_0[2] then
4021 print("1, 2, " .. tostring(b))
4022 end
4023 end
4024 end
4025end
4026local _exp_0 = tb
4027local _type_0 = type(_exp_0)
4028local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4029local _match_0 = false
4030if _tab_0 then
4031 local result = _exp_0.result
4032 if true == _exp_0.success and result ~= nil then
4033 _match_0 = true
4034 print("success", result)
4035 end
4036end
4037if not _match_0 then
4038 local _match_1 = false
4039 if _tab_0 then
4040 if false == _exp_0.success then
4041 _match_1 = true
4042 print("failed", result)
4043 end
4044 end
4045 if not _match_1 then
4046 print("invalid")
4047 end
4048end
4049local _exp_0 = tb
4050local _type_0 = type(_exp_0)
4051local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4052local _match_0 = false
4053if _tab_0 then
4054 local content
4055 do
4056 local _obj_0 = _exp_0.data
4057 local _type_1 = type(_obj_0)
4058 if "table" == _type_1 or "userdata" == _type_1 then
4059 content = _obj_0.content
4060 end
4061 end
4062 local _val_0
4063 do
4064 local _obj_0 = _exp_0.data
4065 if _obj_0 ~= nil then
4066 _val_0 = _obj_0.type
4067 end
4068 end
4069 if "success" == _val_0 and content ~= nil then
4070 _match_0 = true
4071 print("success", content)
4072 end
4073end
4074if not _match_0 then
4075 local _match_1 = false
4076 if _tab_0 then
4077 local content
4078 do
4079 local _obj_0 = _exp_0.data
4080 local _type_1 = type(_obj_0)
4081 if "table" == _type_1 or "userdata" == _type_1 then
4082 content = _obj_0.content
4083 end
4084 end
4085 local _val_0
4086 do
4087 local _obj_0 = _exp_0.data
4088 if _obj_0 ~= nil then
4089 _val_0 = _obj_0.type
4090 end
4091 end
4092 if "error" == _val_0 and content ~= nil then
4093 _match_1 = true
4094 print("failed", content)
4095 end
4096 end
4097 if not _match_1 then
4098 print("invalid")
4099 end
4100end
4101local _exp_0 = tb
4102local _type_0 = type(_exp_0)
4103local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4104if _tab_0 then
4105 local fourth = _exp_0[4]
4106 local _val_0
4107 do
4108 local _obj_0 = _exp_0[1]
4109 if _obj_0 ~= nil then
4110 _val_0 = _obj_0.a
4111 end
4112 end
4113 local _val_1
4114 do
4115 local _obj_0 = _exp_0[1]
4116 if _obj_0 ~= nil then
4117 _val_1 = _obj_0.b
4118 end
4119 end
4120 local _val_2
4121 do
4122 local _obj_0 = _exp_0[2]
4123 if _obj_0 ~= nil then
4124 _val_2 = _obj_0.a
4125 end
4126 end
4127 local _val_3
4128 do
4129 local _obj_0 = _exp_0[2]
4130 if _obj_0 ~= nil then
4131 _val_3 = _obj_0.b
4132 end
4133 end
4134 local _val_4
4135 do
4136 local _obj_0 = _exp_0[3]
4137 if _obj_0 ~= nil then
4138 _val_4 = _obj_0.a
4139 end
4140 end
4141 local _val_5
4142 do
4143 local _obj_0 = _exp_0[3]
4144 if _obj_0 ~= nil then
4145 _val_5 = _obj_0.b
4146 end
4147 end
4148 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
4149 print("matched", fourth)
4150 end
4151end
4152local segments = {
4153 "admin",
4154 "users",
4155 "logs",
4156 "view"
4157}
4158local _type_0 = type(segments)
4159local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4160if _tab_0 then
4161 local groups
4162 do
4163 local _accum_0 = { }
4164 local _len_0 = 1
4165 local _max_0 = #segments + -3 + 1
4166 for _index_0 = 1, _max_0 do
4167 local _item_0 = segments[_index_0]
4168 _accum_0[_len_0] = _item_0
4169 _len_0 = _len_0 + 1
4170 end
4171 groups = _accum_0
4172 end
4173 local resource = segments[#segments - 1]
4174 local action = segments[#segments]
4175 if resource ~= nil and action ~= nil then
4176 print("Group:", groups)
4177 print("Resource:", resource)
4178 print("Action:", action)
4179 end
4180end
3291local Inventory 4181local Inventory
3292local _class_0 4182local _class_0
3293local _base_0 = { 4183local _base_0 = {
@@ -3944,6 +4834,10 @@ do
3944 _with_1["key-name"] = value 4834 _with_1["key-name"] = value
3945end 4835end
3946_with_0[#_with_0 + 1] = "abc" 4836_with_0[#_with_0 + 1] = "abc"
4837local _with_0 = obj
4838if _with_0 ~= nil then
4839 print(obj.name)
4840end
3947do 4841do
3948 local var = "hello" 4842 local var = "hello"
3949 print(var) 4843 print(var)