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.lua844
1 files changed, 824 insertions, 20 deletions
diff --git a/spec/outputs/codes_from_doc.lua b/spec/outputs/codes_from_doc.lua
index 27f8de5..b7d1236 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()
@@ -860,11 +1028,10 @@ for i, item in ipairs(items) do
860 _len_0 = _len_0 + 1 1028 _len_0 = _len_0 + 1
861end 1029end
862doubled = _accum_0 1030doubled = _accum_0
863local iter = ipairs(items)
864local slice 1031local slice
865local _accum_0 = { } 1032local _accum_0 = { }
866local _len_0 = 1 1033local _len_0 = 1
867for i, item in iter do 1034for i, item in ipairs(items) do
868 if i > 1 and i < 3 then 1035 if i > 1 and i < 3 then
869 _accum_0[_len_0] = item 1036 _accum_0[_len_0] = item
870 _len_0 = _len_0 + 1 1037 _len_0 = _len_0 + 1
@@ -971,8 +1138,7 @@ local slice
971local _accum_0 = { } 1138local _accum_0 = { }
972local _len_0 = 1 1139local _len_0 = 1
973local _list_0 = items 1140local _list_0 = items
974local _max_0 = 5 1141for _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] 1142 local item = _list_0[_index_0]
977 _accum_0[_len_0] = item 1143 _accum_0[_len_0] = item
978 _len_0 = _len_0 + 1 1144 _len_0 = _len_0 + 1
@@ -982,7 +1148,8 @@ local slice
982local _accum_0 = { } 1148local _accum_0 = { }
983local _len_0 = 1 1149local _len_0 = 1
984local _list_0 = items 1150local _list_0 = items
985for _index_0 = 2, #_list_0 do 1151local _max_0 = #_list_0
1152for _index_0 = 2, _max_0 do
986 local item = _list_0[_index_0] 1153 local item = _list_0[_index_0]
987 _accum_0[_len_0] = item 1154 _accum_0[_len_0] = item
988 _len_0 = _len_0 + 1 1155 _len_0 = _len_0 + 1
@@ -992,12 +1159,46 @@ local slice
992local _accum_0 = { } 1159local _accum_0 = { }
993local _len_0 = 1 1160local _len_0 = 1
994local _list_0 = items 1161local _list_0 = items
995for _index_0 = 1, #_list_0, 2 do 1162local _max_0 = #_list_0
1163for _index_0 = 1, _max_0, 2 do
996 local item = _list_0[_index_0] 1164 local item = _list_0[_index_0]
997 _accum_0[_len_0] = item 1165 _accum_0[_len_0] = item
998 _len_0 = _len_0 + 1 1166 _len_0 = _len_0 + 1
999end 1167end
1000slice = _accum_0 1168slice = _accum_0
1169local slice
1170local _accum_0 = { }
1171local _len_0 = 1
1172local _list_0 = items
1173local _min_0 = #_list_0 + -4 + 1
1174local _max_0 = #_list_0 + -1 + 1
1175for _index_0 = _min_0, _max_0 do
1176 local item = _list_0[_index_0]
1177 _accum_0[_len_0] = item
1178 _len_0 = _len_0 + 1
1179end
1180slice = _accum_0
1181local reverse_slice
1182local _accum_0 = { }
1183local _len_0 = 1
1184local _list_0 = items
1185local _min_0 = #_list_0 + -1 + 1
1186for _index_0 = _min_0, 1, -1 do
1187 local item = _list_0[_index_0]
1188 _accum_0[_len_0] = item
1189 _len_0 = _len_0 + 1
1190end
1191reverse_slice = _accum_0
1192local sub_list
1193local _accum_0 = { }
1194local _len_0 = 1
1195local _list_0 = items
1196for _index_0 = 2, 4 do
1197 local _item_0 = _list_0[_index_0]
1198 _accum_0[_len_0] = _item_0
1199 _len_0 = _len_0 + 1
1200end
1201sub_list = _accum_0
1001for i = 10, 20 do 1202for i = 10, 20 do
1002 print(i) 1203 print(i)
1003end 1204end
@@ -1008,8 +1209,7 @@ for key, value in pairs(object) do
1008 print(key, value) 1209 print(key, value)
1009end 1210end
1010local _list_0 = items 1211local _list_0 = items
1011local _max_0 = 4 1212for _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] 1213 local item = _list_0[_index_0]
1014 print(item) 1214 print(item)
1015end 1215end
@@ -1027,12 +1227,24 @@ local _len_0 = 1
1027for i = 1, 20 do 1227for i = 1, 20 do
1028 if i % 2 == 0 then 1228 if i % 2 == 0 then
1029 _accum_0[_len_0] = i * 2 1229 _accum_0[_len_0] = i * 2
1230 _len_0 = _len_0 + 1
1030 else 1231 else
1031 _accum_0[_len_0] = i 1232 _accum_0[_len_0] = i
1233 _len_0 = _len_0 + 1
1032 end 1234 end
1033 _len_0 = _len_0 + 1
1034end 1235end
1035doubled_evens = _accum_0 1236doubled_evens = _accum_0
1237local first_large
1238local _accum_0
1239local _list_0 = numbers
1240for _index_0 = 1, #_list_0 do
1241 local n = _list_0[_index_0]
1242 if n > 10 then
1243 _accum_0 = n
1244 break
1245 end
1246end
1247first_large = _accum_0
1036local func_a 1248local func_a
1037func_a = function() 1249func_a = function()
1038 for i = 1, 10 do 1250 for i = 1, 10 do
@@ -1181,7 +1393,7 @@ if "Robert" == name then
1181elseif "Dan" == name or "Daniel" == name then 1393elseif "Dan" == name or "Daniel" == name then
1182 print("Your name, it's Dan") 1394 print("Your name, it's Dan")
1183else 1395else
1184 print("I don't know about your name") 1396 print("I don't know about you with name " .. tostring(name))
1185end 1397end
1186local b = 1 1398local b = 1
1187local next_number 1399local next_number
@@ -1281,6 +1493,192 @@ if _tab_0 then
1281 end 1493 end
1282 print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) 1494 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
1283end 1495end
1496local _exp_0 = tb
1497local _type_0 = type(_exp_0)
1498local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1499local _match_0 = false
1500if _tab_0 then
1501 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
1502 _match_0 = true
1503 print("1, 2, 3")
1504 end
1505end
1506if not _match_0 then
1507 local _match_1 = false
1508 if _tab_0 then
1509 local b = _exp_0[2]
1510 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
1511 _match_1 = true
1512 print("1, " .. tostring(b) .. ", 3")
1513 end
1514 end
1515 if not _match_1 then
1516 if _tab_0 then
1517 local b = _exp_0[3]
1518 if b == nil then
1519 b = 3
1520 end
1521 if 1 == _exp_0[1] and 2 == _exp_0[2] then
1522 print("1, 2, " .. tostring(b))
1523 end
1524 end
1525 end
1526end
1527local _exp_0 = tb
1528local _type_0 = type(_exp_0)
1529local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1530local _match_0 = false
1531if _tab_0 then
1532 local result = _exp_0.result
1533 if true == _exp_0.success and result ~= nil then
1534 _match_0 = true
1535 print("success", result)
1536 end
1537end
1538if not _match_0 then
1539 local _match_1 = false
1540 if _tab_0 then
1541 if false == _exp_0.success then
1542 _match_1 = true
1543 print("failed", result)
1544 end
1545 end
1546 if not _match_1 then
1547 print("invalid")
1548 end
1549end
1550local _exp_0 = tb
1551local _type_0 = type(_exp_0)
1552local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1553local _match_0 = false
1554if _tab_0 then
1555 local content
1556 do
1557 local _obj_0 = _exp_0.data
1558 local _type_1 = type(_obj_0)
1559 if "table" == _type_1 or "userdata" == _type_1 then
1560 content = _obj_0.content
1561 end
1562 end
1563 local _val_0
1564 do
1565 local _obj_0 = _exp_0.data
1566 if _obj_0 ~= nil then
1567 _val_0 = _obj_0.type
1568 end
1569 end
1570 if "success" == _val_0 and content ~= nil then
1571 _match_0 = true
1572 print("success", content)
1573 end
1574end
1575if not _match_0 then
1576 local _match_1 = false
1577 if _tab_0 then
1578 local content
1579 do
1580 local _obj_0 = _exp_0.data
1581 local _type_1 = type(_obj_0)
1582 if "table" == _type_1 or "userdata" == _type_1 then
1583 content = _obj_0.content
1584 end
1585 end
1586 local _val_0
1587 do
1588 local _obj_0 = _exp_0.data
1589 if _obj_0 ~= nil then
1590 _val_0 = _obj_0.type
1591 end
1592 end
1593 if "error" == _val_0 and content ~= nil then
1594 _match_1 = true
1595 print("failed", content)
1596 end
1597 end
1598 if not _match_1 then
1599 print("invalid")
1600 end
1601end
1602local _exp_0 = tb
1603local _type_0 = type(_exp_0)
1604local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1605if _tab_0 then
1606 local fourth = _exp_0[4]
1607 local _val_0
1608 do
1609 local _obj_0 = _exp_0[1]
1610 if _obj_0 ~= nil then
1611 _val_0 = _obj_0.a
1612 end
1613 end
1614 local _val_1
1615 do
1616 local _obj_0 = _exp_0[1]
1617 if _obj_0 ~= nil then
1618 _val_1 = _obj_0.b
1619 end
1620 end
1621 local _val_2
1622 do
1623 local _obj_0 = _exp_0[2]
1624 if _obj_0 ~= nil then
1625 _val_2 = _obj_0.a
1626 end
1627 end
1628 local _val_3
1629 do
1630 local _obj_0 = _exp_0[2]
1631 if _obj_0 ~= nil then
1632 _val_3 = _obj_0.b
1633 end
1634 end
1635 local _val_4
1636 do
1637 local _obj_0 = _exp_0[3]
1638 if _obj_0 ~= nil then
1639 _val_4 = _obj_0.a
1640 end
1641 end
1642 local _val_5
1643 do
1644 local _obj_0 = _exp_0[3]
1645 if _obj_0 ~= nil then
1646 _val_5 = _obj_0.b
1647 end
1648 end
1649 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
1650 print("matched", fourth)
1651 end
1652end
1653local segments = {
1654 "admin",
1655 "users",
1656 "logs",
1657 "view"
1658}
1659local _type_0 = type(segments)
1660local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1661if _tab_0 then
1662 local groups
1663 do
1664 local _accum_0 = { }
1665 local _len_0 = 1
1666 local _max_0 = #segments + -3 + 1
1667 for _index_0 = 1, _max_0 do
1668 local _item_0 = segments[_index_0]
1669 _accum_0[_len_0] = _item_0
1670 _len_0 = _len_0 + 1
1671 end
1672 groups = _accum_0
1673 end
1674 local resource = segments[#segments - 1]
1675 local action = segments[#segments]
1676 if resource ~= nil and action ~= nil then
1677 print("Group:", groups)
1678 print("Resource:", resource)
1679 print("Action:", action)
1680 end
1681end
1284local Inventory 1682local Inventory
1285local _class_0 1683local _class_0
1286local _base_0 = { 1684local _base_0 = {
@@ -1937,6 +2335,10 @@ do
1937 _with_1["key-name"] = value 2335 _with_1["key-name"] = value
1938end 2336end
1939_with_0[#_with_0 + 1] = "abc" 2337_with_0[#_with_0 + 1] = "abc"
2338local _with_0 = obj
2339if _with_0 ~= nil then
2340 print(obj.name)
2341end
1940do 2342do
1941 local var = "hello" 2343 local var = "hello"
1942 print(var) 2344 print(var)
@@ -2027,6 +2429,38 @@ local inventory = {
2027 } 2429 }
2028 } 2430 }
2029} 2431}
2432local map
2433map = function(arr, action)
2434 local _accum_0 = { }
2435 local _len_0 = 1
2436 for _index_0 = 1, #arr do
2437 local item = arr[_index_0]
2438 _accum_0[_len_0] = action(item)
2439 _len_0 = _len_0 + 1
2440 end
2441 return _accum_0
2442end
2443local filter
2444filter = function(arr, cond)
2445 local _accum_0 = { }
2446 local _len_0 = 1
2447 for _index_0 = 1, #arr do
2448 local item = arr[_index_0]
2449 if cond(item) then
2450 _accum_0[_len_0] = item
2451 _len_0 = _len_0 + 1
2452 end
2453 end
2454 return _accum_0
2455end
2456local reduce
2457reduce = function(arr, init, action)
2458 for _index_0 = 1, #arr do
2459 local item = arr[_index_0]
2460 init = action(init, item)
2461 end
2462 return init
2463end
2030print(reduce(filter(map({ 2464print(reduce(filter(map({
2031 1, 2465 1,
2032 2, 2466 2,
@@ -2084,6 +2518,12 @@ end
2084print("yuescript") 2518print("yuescript")
2085print(3) 2519print(3)
2086print("Valid enum type:", "Static") 2520print("Valid enum type:", "Static")
2521do
2522 print(123, "hello")
2523end
2524do
2525 print(123, "hello")
2526end
2087if tb ~= nil then 2527if tb ~= nil then
2088 tb:func() 2528 tb:func()
2089end 2529end
@@ -2184,6 +2624,16 @@ for _key_0, _value_0 in pairs(b) do
2184 end 2624 end
2185end 2625end
2186merge = _tab_0 2626merge = _tab_0
2627local last
2628do
2629 local _item_0 = data.items
2630 last = _item_0[#_item_0]
2631end
2632local second_last
2633do
2634 local _item_0 = data.items
2635 second_last = _item_0[#_item_0 - 1]
2636end
2187local mt = { } 2637local mt = { }
2188local add 2638local add
2189add = function(self, right) 2639add = function(self, right)
@@ -2314,6 +2764,14 @@ func({
2314 2, 2764 2,
2315 3 2765 3
2316}) 2766})
2767local f
2768f = function()
2769 return {
2770 1,
2771 2,
2772 3
2773 }
2774end
2317local tb = { 2775local tb = {
2318 name = "abc", 2776 name = "abc",
2319 values = { 2777 values = {
@@ -2554,6 +3012,59 @@ end
2554local two, four 3012local two, four
2555local _obj_0 = items 3013local _obj_0 = items
2556two, four = _obj_0[2], _obj_0[4] 3014two, four = _obj_0[2], _obj_0[4]
3015local orders = {
3016 "first",
3017 "second",
3018 "third",
3019 "fourth",
3020 "last"
3021}
3022local first, bulk, last = orders[1], (function()
3023 local _accum_0 = { }
3024 local _len_0 = 1
3025 local _max_0 = #orders + -2 + 1
3026 for _index_0 = 2, _max_0 do
3027 local _item_0 = orders[_index_0]
3028 _accum_0[_len_0] = _item_0
3029 _len_0 = _len_0 + 1
3030 end
3031 return _accum_0
3032end)(), orders[#orders]
3033print(first)
3034print(bulk)
3035print(last)
3036local first, rest
3037do
3038 local _obj_0 = orders
3039 first, rest = _obj_0[1], (function()
3040 local _accum_0 = { }
3041 local _len_0 = 1
3042 local _max_0 = #_obj_0
3043 for _index_0 = 2, _max_0 do
3044 local _item_0 = _obj_0[_index_0]
3045 _accum_0[_len_0] = _item_0
3046 _len_0 = _len_0 + 1
3047 end
3048 return _accum_0
3049 end)()
3050end
3051local start, last
3052do
3053 local _obj_0 = orders
3054 start, last = (function()
3055 local _accum_0 = { }
3056 local _len_0 = 1
3057 local _max_0 = #_obj_0 + -2 + 1
3058 for _index_0 = 1, _max_0 do
3059 local _item_0 = _obj_0[_index_0]
3060 _accum_0[_len_0] = _item_0
3061 _len_0 = _len_0 + 1
3062 end
3063 return _accum_0
3064 end)(), _obj_0[#_obj_0]
3065end
3066local _obj_0 = orders
3067first, last = _obj_0[1], _obj_0[#_obj_0]
2557local tuples = { 3068local tuples = {
2558 { 3069 {
2559 "hello", 3070 "hello",
@@ -2655,6 +3166,56 @@ end)
2655if success then 3166if success then
2656 print(result) 3167 print(result)
2657end 3168end
3169local a, b, c
3170do
3171 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
3172 return func()
3173 end)
3174 if _ok_0 then
3175 a, b, c = _ret_0, _ret_1, _ret_2
3176 end
3177end
3178do
3179 local _exp_0 = ((function()
3180 return (function(_arg_0, ...)
3181 local _ok_0 = _arg_0
3182 if _ok_0 then
3183 return ...
3184 end
3185 end)(pcall(function()
3186 return func()
3187 end))
3188 end)())
3189 if _exp_0 ~= nil then
3190 a = _exp_0
3191 else
3192 a = "default"
3193 end
3194end
3195f((function()
3196 return (function(_arg_0, ...)
3197 local _ok_0 = _arg_0
3198 if _ok_0 then
3199 return ...
3200 end
3201 end)(pcall(function()
3202 return func()
3203 end))
3204end)())
3205f((function()
3206 return (function(_arg_0, ...)
3207 local _ok_0 = _arg_0
3208 if _ok_0 then
3209 return ...
3210 end
3211 end)(xpcall(function()
3212 print(123)
3213 return func()
3214 end, function(e)
3215 print(e)
3216 return e
3217 end))
3218end)())
2658local a <const> = 123 3219local a <const> = 123
2659local _ <close> = setmetatable({ }, { 3220local _ <close> = setmetatable({ }, {
2660 __close = function() 3221 __close = function()
@@ -2664,10 +3225,19 @@ local _ <close> = setmetatable({ }, {
2664local a, b, c, d 3225local a, b, c, d
2665local _obj_0 = tb 3226local _obj_0 = tb
2666a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] 3227a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
3228Constant = 123
2667local some_string = "Here is a string\n that has a line break in it." 3229local some_string = "Here is a string\n that has a line break in it."
2668print("I am " .. tostring(math.random() * 100) .. "% sure.") 3230print("I am " .. tostring(math.random() * 100) .. "% sure.")
2669local integer = 1000000 3231local integer = 1000000
2670local hex = 0xEFBBBF 3232local hex = 0xEFBBBF
3233local binary = 19
3234local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
3235local fn
3236fn = function()
3237 local str = "foo:\n bar: baz"
3238 return str
3239end
3240local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
2671local my_function 3241local my_function
2672my_function = function() end 3242my_function = function() end
2673my_function() 3243my_function()
@@ -2867,11 +3437,10 @@ for i, item in ipairs(items) do
2867 _len_0 = _len_0 + 1 3437 _len_0 = _len_0 + 1
2868end 3438end
2869doubled = _accum_0 3439doubled = _accum_0
2870local iter = ipairs(items)
2871local slice 3440local slice
2872local _accum_0 = { } 3441local _accum_0 = { }
2873local _len_0 = 1 3442local _len_0 = 1
2874for i, item in iter do 3443for i, item in ipairs(items) do
2875 if i > 1 and i < 3 then 3444 if i > 1 and i < 3 then
2876 _accum_0[_len_0] = item 3445 _accum_0[_len_0] = item
2877 _len_0 = _len_0 + 1 3446 _len_0 = _len_0 + 1
@@ -2978,8 +3547,7 @@ local slice
2978local _accum_0 = { } 3547local _accum_0 = { }
2979local _len_0 = 1 3548local _len_0 = 1
2980local _list_0 = items 3549local _list_0 = items
2981local _max_0 = 5 3550for _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] 3551 local item = _list_0[_index_0]
2984 _accum_0[_len_0] = item 3552 _accum_0[_len_0] = item
2985 _len_0 = _len_0 + 1 3553 _len_0 = _len_0 + 1
@@ -2989,7 +3557,8 @@ local slice
2989local _accum_0 = { } 3557local _accum_0 = { }
2990local _len_0 = 1 3558local _len_0 = 1
2991local _list_0 = items 3559local _list_0 = items
2992for _index_0 = 2, #_list_0 do 3560local _max_0 = #_list_0
3561for _index_0 = 2, _max_0 do
2993 local item = _list_0[_index_0] 3562 local item = _list_0[_index_0]
2994 _accum_0[_len_0] = item 3563 _accum_0[_len_0] = item
2995 _len_0 = _len_0 + 1 3564 _len_0 = _len_0 + 1
@@ -2999,12 +3568,46 @@ local slice
2999local _accum_0 = { } 3568local _accum_0 = { }
3000local _len_0 = 1 3569local _len_0 = 1
3001local _list_0 = items 3570local _list_0 = items
3002for _index_0 = 1, #_list_0, 2 do 3571local _max_0 = #_list_0
3572for _index_0 = 1, _max_0, 2 do
3003 local item = _list_0[_index_0] 3573 local item = _list_0[_index_0]
3004 _accum_0[_len_0] = item 3574 _accum_0[_len_0] = item
3005 _len_0 = _len_0 + 1 3575 _len_0 = _len_0 + 1
3006end 3576end
3007slice = _accum_0 3577slice = _accum_0
3578local slice
3579local _accum_0 = { }
3580local _len_0 = 1
3581local _list_0 = items
3582local _min_0 = #_list_0 + -4 + 1
3583local _max_0 = #_list_0 + -1 + 1
3584for _index_0 = _min_0, _max_0 do
3585 local item = _list_0[_index_0]
3586 _accum_0[_len_0] = item
3587 _len_0 = _len_0 + 1
3588end
3589slice = _accum_0
3590local reverse_slice
3591local _accum_0 = { }
3592local _len_0 = 1
3593local _list_0 = items
3594local _min_0 = #_list_0 + -1 + 1
3595for _index_0 = _min_0, 1, -1 do
3596 local item = _list_0[_index_0]
3597 _accum_0[_len_0] = item
3598 _len_0 = _len_0 + 1
3599end
3600reverse_slice = _accum_0
3601local sub_list
3602local _accum_0 = { }
3603local _len_0 = 1
3604local _list_0 = items
3605for _index_0 = 2, 4 do
3606 local _item_0 = _list_0[_index_0]
3607 _accum_0[_len_0] = _item_0
3608 _len_0 = _len_0 + 1
3609end
3610sub_list = _accum_0
3008for i = 10, 20 do 3611for i = 10, 20 do
3009 print(i) 3612 print(i)
3010end 3613end
@@ -3015,8 +3618,7 @@ for key, value in pairs(object) do
3015 print(key, value) 3618 print(key, value)
3016end 3619end
3017local _list_0 = items 3620local _list_0 = items
3018local _max_0 = 4 3621for _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] 3622 local item = _list_0[_index_0]
3021 print(item) 3623 print(item)
3022end 3624end
@@ -3034,12 +3636,24 @@ local _len_0 = 1
3034for i = 1, 20 do 3636for i = 1, 20 do
3035 if i % 2 == 0 then 3637 if i % 2 == 0 then
3036 _accum_0[_len_0] = i * 2 3638 _accum_0[_len_0] = i * 2
3639 _len_0 = _len_0 + 1
3037 else 3640 else
3038 _accum_0[_len_0] = i 3641 _accum_0[_len_0] = i
3642 _len_0 = _len_0 + 1
3039 end 3643 end
3040 _len_0 = _len_0 + 1
3041end 3644end
3042doubled_evens = _accum_0 3645doubled_evens = _accum_0
3646local first_large
3647local _accum_0
3648local _list_0 = numbers
3649for _index_0 = 1, #_list_0 do
3650 local n = _list_0[_index_0]
3651 if n > 10 then
3652 _accum_0 = n
3653 break
3654 end
3655end
3656first_large = _accum_0
3043local func_a 3657local func_a
3044func_a = function() 3658func_a = function()
3045 for i = 1, 10 do 3659 for i = 1, 10 do
@@ -3188,7 +3802,7 @@ if "Robert" == name then
3188elseif "Dan" == name or "Daniel" == name then 3802elseif "Dan" == name or "Daniel" == name then
3189 print("Your name, it's Dan") 3803 print("Your name, it's Dan")
3190else 3804else
3191 print("I don't know about your name") 3805 print("I don't know about you with name " .. tostring(name))
3192end 3806end
3193local b = 1 3807local b = 1
3194local next_number 3808local next_number
@@ -3288,6 +3902,192 @@ if _tab_0 then
3288 end 3902 end
3289 print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) 3903 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3290end 3904end
3905local _exp_0 = tb
3906local _type_0 = type(_exp_0)
3907local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3908local _match_0 = false
3909if _tab_0 then
3910 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
3911 _match_0 = true
3912 print("1, 2, 3")
3913 end
3914end
3915if not _match_0 then
3916 local _match_1 = false
3917 if _tab_0 then
3918 local b = _exp_0[2]
3919 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
3920 _match_1 = true
3921 print("1, " .. tostring(b) .. ", 3")
3922 end
3923 end
3924 if not _match_1 then
3925 if _tab_0 then
3926 local b = _exp_0[3]
3927 if b == nil then
3928 b = 3
3929 end
3930 if 1 == _exp_0[1] and 2 == _exp_0[2] then
3931 print("1, 2, " .. tostring(b))
3932 end
3933 end
3934 end
3935end
3936local _exp_0 = tb
3937local _type_0 = type(_exp_0)
3938local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3939local _match_0 = false
3940if _tab_0 then
3941 local result = _exp_0.result
3942 if true == _exp_0.success and result ~= nil then
3943 _match_0 = true
3944 print("success", result)
3945 end
3946end
3947if not _match_0 then
3948 local _match_1 = false
3949 if _tab_0 then
3950 if false == _exp_0.success then
3951 _match_1 = true
3952 print("failed", result)
3953 end
3954 end
3955 if not _match_1 then
3956 print("invalid")
3957 end
3958end
3959local _exp_0 = tb
3960local _type_0 = type(_exp_0)
3961local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3962local _match_0 = false
3963if _tab_0 then
3964 local content
3965 do
3966 local _obj_0 = _exp_0.data
3967 local _type_1 = type(_obj_0)
3968 if "table" == _type_1 or "userdata" == _type_1 then
3969 content = _obj_0.content
3970 end
3971 end
3972 local _val_0
3973 do
3974 local _obj_0 = _exp_0.data
3975 if _obj_0 ~= nil then
3976 _val_0 = _obj_0.type
3977 end
3978 end
3979 if "success" == _val_0 and content ~= nil then
3980 _match_0 = true
3981 print("success", content)
3982 end
3983end
3984if not _match_0 then
3985 local _match_1 = false
3986 if _tab_0 then
3987 local content
3988 do
3989 local _obj_0 = _exp_0.data
3990 local _type_1 = type(_obj_0)
3991 if "table" == _type_1 or "userdata" == _type_1 then
3992 content = _obj_0.content
3993 end
3994 end
3995 local _val_0
3996 do
3997 local _obj_0 = _exp_0.data
3998 if _obj_0 ~= nil then
3999 _val_0 = _obj_0.type
4000 end
4001 end
4002 if "error" == _val_0 and content ~= nil then
4003 _match_1 = true
4004 print("failed", content)
4005 end
4006 end
4007 if not _match_1 then
4008 print("invalid")
4009 end
4010end
4011local _exp_0 = tb
4012local _type_0 = type(_exp_0)
4013local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4014if _tab_0 then
4015 local fourth = _exp_0[4]
4016 local _val_0
4017 do
4018 local _obj_0 = _exp_0[1]
4019 if _obj_0 ~= nil then
4020 _val_0 = _obj_0.a
4021 end
4022 end
4023 local _val_1
4024 do
4025 local _obj_0 = _exp_0[1]
4026 if _obj_0 ~= nil then
4027 _val_1 = _obj_0.b
4028 end
4029 end
4030 local _val_2
4031 do
4032 local _obj_0 = _exp_0[2]
4033 if _obj_0 ~= nil then
4034 _val_2 = _obj_0.a
4035 end
4036 end
4037 local _val_3
4038 do
4039 local _obj_0 = _exp_0[2]
4040 if _obj_0 ~= nil then
4041 _val_3 = _obj_0.b
4042 end
4043 end
4044 local _val_4
4045 do
4046 local _obj_0 = _exp_0[3]
4047 if _obj_0 ~= nil then
4048 _val_4 = _obj_0.a
4049 end
4050 end
4051 local _val_5
4052 do
4053 local _obj_0 = _exp_0[3]
4054 if _obj_0 ~= nil then
4055 _val_5 = _obj_0.b
4056 end
4057 end
4058 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
4059 print("matched", fourth)
4060 end
4061end
4062local segments = {
4063 "admin",
4064 "users",
4065 "logs",
4066 "view"
4067}
4068local _type_0 = type(segments)
4069local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4070if _tab_0 then
4071 local groups
4072 do
4073 local _accum_0 = { }
4074 local _len_0 = 1
4075 local _max_0 = #segments + -3 + 1
4076 for _index_0 = 1, _max_0 do
4077 local _item_0 = segments[_index_0]
4078 _accum_0[_len_0] = _item_0
4079 _len_0 = _len_0 + 1
4080 end
4081 groups = _accum_0
4082 end
4083 local resource = segments[#segments - 1]
4084 local action = segments[#segments]
4085 if resource ~= nil and action ~= nil then
4086 print("Group:", groups)
4087 print("Resource:", resource)
4088 print("Action:", action)
4089 end
4090end
3291local Inventory 4091local Inventory
3292local _class_0 4092local _class_0
3293local _base_0 = { 4093local _base_0 = {
@@ -3944,6 +4744,10 @@ do
3944 _with_1["key-name"] = value 4744 _with_1["key-name"] = value
3945end 4745end
3946_with_0[#_with_0 + 1] = "abc" 4746_with_0[#_with_0 + 1] = "abc"
4747local _with_0 = obj
4748if _with_0 ~= nil then
4749 print(obj.name)
4750end
3947do 4751do
3948 local var = "hello" 4752 local var = "hello"
3949 print(var) 4753 print(var)