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.lua872
1 files changed, 834 insertions, 38 deletions
diff --git a/spec/outputs/codes_from_doc.lua b/spec/outputs/codes_from_doc.lua
index 74db469..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 = {
@@ -467,8 +523,7 @@ local x = f()
467local y = x 523local y = x
468local z = x 524local z = x
469do 525do
470 local a 526 local a = 1
471 a = 1
472 local x, y, z 527 local x, y, z
473 print("forward declare all variables as locals") 528 print("forward declare all variables as locals")
474 x = function() 529 x = function()
@@ -478,8 +533,7 @@ do
478 instance = Item:new() 533 instance = Item:new()
479end 534end
480do 535do
481 local X 536 local X = 1
482 X = 1
483 local B 537 local B
484 print("only forward declare upper case variables") 538 print("only forward declare upper case variables")
485 local a = 1 539 local a = 1
@@ -488,19 +542,17 @@ end
488do 542do
489 a = 1 543 a = 1
490 print("declare all variables as globals") 544 print("declare all variables as globals")
491 local x
492 x = function() 545 x = function()
493 return 1 + y + z 546 return 1 + y + z
494 end 547 end
495 local y, z = 2, 3 548 y, z = 2, 3
496end 549end
497do 550do
498 X = 1 551 X = 1
499 print("only declare upper case variables as globals") 552 print("only declare upper case variables as globals")
500 local a = 1 553 local a = 1
501 local B = 2 554 B = 2
502 local Temp 555 local Temp = "a local value"
503 Temp = "a local value"
504end 556end
505local thing = { 557local thing = {
506 1, 558 1,
@@ -551,6 +603,59 @@ end
551local two, four 603local two, four
552local _obj_0 = items 604local _obj_0 = items
553two, 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]
554local tuples = { 659local tuples = {
555 { 660 {
556 "hello", 661 "hello",
@@ -652,6 +757,56 @@ end)
652if success then 757if success then
653 print(result) 758 print(result)
654end 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)())
655local a <const> = 123 810local a <const> = 123
656local _ <close> = setmetatable({ }, { 811local _ <close> = setmetatable({ }, {
657 __close = function() 812 __close = function()
@@ -661,10 +816,19 @@ local _ <close> = setmetatable({ }, {
661local a, b, c, d 816local a, b, c, d
662local _obj_0 = tb 817local _obj_0 = tb
663a, 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
664local 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."
665print("I am " .. tostring(math.random() * 100) .. "% sure.") 821print("I am " .. tostring(math.random() * 100) .. "% sure.")
666local integer = 1000000 822local integer = 1000000
667local 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) .. "!\"'"
668local my_function 832local my_function
669my_function = function() end 833my_function = function() end
670my_function() 834my_function()
@@ -864,11 +1028,10 @@ for i, item in ipairs(items) do
864 _len_0 = _len_0 + 1 1028 _len_0 = _len_0 + 1
865end 1029end
866doubled = _accum_0 1030doubled = _accum_0
867local iter = ipairs(items)
868local slice 1031local slice
869local _accum_0 = { } 1032local _accum_0 = { }
870local _len_0 = 1 1033local _len_0 = 1
871for i, item in iter do 1034for i, item in ipairs(items) do
872 if i > 1 and i < 3 then 1035 if i > 1 and i < 3 then
873 _accum_0[_len_0] = item 1036 _accum_0[_len_0] = item
874 _len_0 = _len_0 + 1 1037 _len_0 = _len_0 + 1
@@ -975,8 +1138,7 @@ local slice
975local _accum_0 = { } 1138local _accum_0 = { }
976local _len_0 = 1 1139local _len_0 = 1
977local _list_0 = items 1140local _list_0 = items
978local _max_0 = 5 1141for _index_0 = 1, 5 do
979for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
980 local item = _list_0[_index_0] 1142 local item = _list_0[_index_0]
981 _accum_0[_len_0] = item 1143 _accum_0[_len_0] = item
982 _len_0 = _len_0 + 1 1144 _len_0 = _len_0 + 1
@@ -986,7 +1148,8 @@ local slice
986local _accum_0 = { } 1148local _accum_0 = { }
987local _len_0 = 1 1149local _len_0 = 1
988local _list_0 = items 1150local _list_0 = items
989for _index_0 = 2, #_list_0 do 1151local _max_0 = #_list_0
1152for _index_0 = 2, _max_0 do
990 local item = _list_0[_index_0] 1153 local item = _list_0[_index_0]
991 _accum_0[_len_0] = item 1154 _accum_0[_len_0] = item
992 _len_0 = _len_0 + 1 1155 _len_0 = _len_0 + 1
@@ -996,12 +1159,46 @@ local slice
996local _accum_0 = { } 1159local _accum_0 = { }
997local _len_0 = 1 1160local _len_0 = 1
998local _list_0 = items 1161local _list_0 = items
999for _index_0 = 1, #_list_0, 2 do 1162local _max_0 = #_list_0
1163for _index_0 = 1, _max_0, 2 do
1000 local item = _list_0[_index_0] 1164 local item = _list_0[_index_0]
1001 _accum_0[_len_0] = item 1165 _accum_0[_len_0] = item
1002 _len_0 = _len_0 + 1 1166 _len_0 = _len_0 + 1
1003end 1167end
1004slice = _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
1005for i = 10, 20 do 1202for i = 10, 20 do
1006 print(i) 1203 print(i)
1007end 1204end
@@ -1012,8 +1209,7 @@ for key, value in pairs(object) do
1012 print(key, value) 1209 print(key, value)
1013end 1210end
1014local _list_0 = items 1211local _list_0 = items
1015local _max_0 = 4 1212for _index_0 = 2, 4 do
1016for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
1017 local item = _list_0[_index_0] 1213 local item = _list_0[_index_0]
1018 print(item) 1214 print(item)
1019end 1215end
@@ -1031,12 +1227,24 @@ local _len_0 = 1
1031for i = 1, 20 do 1227for i = 1, 20 do
1032 if i % 2 == 0 then 1228 if i % 2 == 0 then
1033 _accum_0[_len_0] = i * 2 1229 _accum_0[_len_0] = i * 2
1230 _len_0 = _len_0 + 1
1034 else 1231 else
1035 _accum_0[_len_0] = i 1232 _accum_0[_len_0] = i
1233 _len_0 = _len_0 + 1
1036 end 1234 end
1037 _len_0 = _len_0 + 1
1038end 1235end
1039doubled_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
1040local func_a 1248local func_a
1041func_a = function() 1249func_a = function()
1042 for i = 1, 10 do 1250 for i = 1, 10 do
@@ -1185,7 +1393,7 @@ if "Robert" == name then
1185elseif "Dan" == name or "Daniel" == name then 1393elseif "Dan" == name or "Daniel" == name then
1186 print("Your name, it's Dan") 1394 print("Your name, it's Dan")
1187else 1395else
1188 print("I don't know about your name") 1396 print("I don't know about you with name " .. tostring(name))
1189end 1397end
1190local b = 1 1398local b = 1
1191local next_number 1399local next_number
@@ -1285,6 +1493,192 @@ if _tab_0 then
1285 end 1493 end
1286 print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) 1494 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
1287end 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
1288local Inventory 1682local Inventory
1289local _class_0 1683local _class_0
1290local _base_0 = { 1684local _base_0 = {
@@ -1941,6 +2335,10 @@ do
1941 _with_1["key-name"] = value 2335 _with_1["key-name"] = value
1942end 2336end
1943_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
1944do 2342do
1945 local var = "hello" 2343 local var = "hello"
1946 print(var) 2344 print(var)
@@ -2031,6 +2429,38 @@ local inventory = {
2031 } 2429 }
2032 } 2430 }
2033} 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
2034print(reduce(filter(map({ 2464print(reduce(filter(map({
2035 1, 2465 1,
2036 2, 2466 2,
@@ -2088,6 +2518,12 @@ end
2088print("yuescript") 2518print("yuescript")
2089print(3) 2519print(3)
2090print("Valid enum type:", "Static") 2520print("Valid enum type:", "Static")
2521do
2522 print(123, "hello")
2523end
2524do
2525 print(123, "hello")
2526end
2091if tb ~= nil then 2527if tb ~= nil then
2092 tb:func() 2528 tb:func()
2093end 2529end
@@ -2188,6 +2624,16 @@ for _key_0, _value_0 in pairs(b) do
2188 end 2624 end
2189end 2625end
2190merge = _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
2191local mt = { } 2637local mt = { }
2192local add 2638local add
2193add = function(self, right) 2639add = function(self, right)
@@ -2318,6 +2764,14 @@ func({
2318 2, 2764 2,
2319 3 2765 3
2320}) 2766})
2767local f
2768f = function()
2769 return {
2770 1,
2771 2,
2772 3
2773 }
2774end
2321local tb = { 2775local tb = {
2322 name = "abc", 2776 name = "abc",
2323 values = { 2777 values = {
@@ -2478,8 +2932,7 @@ local x = f()
2478local y = x 2932local y = x
2479local z = x 2933local z = x
2480do 2934do
2481 local a 2935 local a = 1
2482 a = 1
2483 local x, y, z 2936 local x, y, z
2484 print("forward declare all variables as locals") 2937 print("forward declare all variables as locals")
2485 x = function() 2938 x = function()
@@ -2489,8 +2942,7 @@ do
2489 instance = Item:new() 2942 instance = Item:new()
2490end 2943end
2491do 2944do
2492 local X 2945 local X = 1
2493 X = 1
2494 local B 2946 local B
2495 print("only forward declare upper case variables") 2947 print("only forward declare upper case variables")
2496 local a = 1 2948 local a = 1
@@ -2499,19 +2951,17 @@ end
2499do 2951do
2500 a = 1 2952 a = 1
2501 print("declare all variables as globals") 2953 print("declare all variables as globals")
2502 local x
2503 x = function() 2954 x = function()
2504 return 1 + y + z 2955 return 1 + y + z
2505 end 2956 end
2506 local y, z = 2, 3 2957 y, z = 2, 3
2507end 2958end
2508do 2959do
2509 X = 1 2960 X = 1
2510 print("only declare upper case variables as globals") 2961 print("only declare upper case variables as globals")
2511 local a = 1 2962 local a = 1
2512 local B = 2 2963 B = 2
2513 local Temp 2964 local Temp = "a local value"
2514 Temp = "a local value"
2515end 2965end
2516local thing = { 2966local thing = {
2517 1, 2967 1,
@@ -2562,6 +3012,59 @@ end
2562local two, four 3012local two, four
2563local _obj_0 = items 3013local _obj_0 = items
2564two, 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]
2565local tuples = { 3068local tuples = {
2566 { 3069 {
2567 "hello", 3070 "hello",
@@ -2663,6 +3166,56 @@ end)
2663if success then 3166if success then
2664 print(result) 3167 print(result)
2665end 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)())
2666local a <const> = 123 3219local a <const> = 123
2667local _ <close> = setmetatable({ }, { 3220local _ <close> = setmetatable({ }, {
2668 __close = function() 3221 __close = function()
@@ -2672,10 +3225,19 @@ local _ <close> = setmetatable({ }, {
2672local a, b, c, d 3225local a, b, c, d
2673local _obj_0 = tb 3226local _obj_0 = tb
2674a, 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
2675local 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."
2676print("I am " .. tostring(math.random() * 100) .. "% sure.") 3230print("I am " .. tostring(math.random() * 100) .. "% sure.")
2677local integer = 1000000 3231local integer = 1000000
2678local 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) .. "!\"'"
2679local my_function 3241local my_function
2680my_function = function() end 3242my_function = function() end
2681my_function() 3243my_function()
@@ -2875,11 +3437,10 @@ for i, item in ipairs(items) do
2875 _len_0 = _len_0 + 1 3437 _len_0 = _len_0 + 1
2876end 3438end
2877doubled = _accum_0 3439doubled = _accum_0
2878local iter = ipairs(items)
2879local slice 3440local slice
2880local _accum_0 = { } 3441local _accum_0 = { }
2881local _len_0 = 1 3442local _len_0 = 1
2882for i, item in iter do 3443for i, item in ipairs(items) do
2883 if i > 1 and i < 3 then 3444 if i > 1 and i < 3 then
2884 _accum_0[_len_0] = item 3445 _accum_0[_len_0] = item
2885 _len_0 = _len_0 + 1 3446 _len_0 = _len_0 + 1
@@ -2986,8 +3547,7 @@ local slice
2986local _accum_0 = { } 3547local _accum_0 = { }
2987local _len_0 = 1 3548local _len_0 = 1
2988local _list_0 = items 3549local _list_0 = items
2989local _max_0 = 5 3550for _index_0 = 1, 5 do
2990for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
2991 local item = _list_0[_index_0] 3551 local item = _list_0[_index_0]
2992 _accum_0[_len_0] = item 3552 _accum_0[_len_0] = item
2993 _len_0 = _len_0 + 1 3553 _len_0 = _len_0 + 1
@@ -2997,7 +3557,8 @@ local slice
2997local _accum_0 = { } 3557local _accum_0 = { }
2998local _len_0 = 1 3558local _len_0 = 1
2999local _list_0 = items 3559local _list_0 = items
3000for _index_0 = 2, #_list_0 do 3560local _max_0 = #_list_0
3561for _index_0 = 2, _max_0 do
3001 local item = _list_0[_index_0] 3562 local item = _list_0[_index_0]
3002 _accum_0[_len_0] = item 3563 _accum_0[_len_0] = item
3003 _len_0 = _len_0 + 1 3564 _len_0 = _len_0 + 1
@@ -3007,12 +3568,46 @@ local slice
3007local _accum_0 = { } 3568local _accum_0 = { }
3008local _len_0 = 1 3569local _len_0 = 1
3009local _list_0 = items 3570local _list_0 = items
3010for _index_0 = 1, #_list_0, 2 do 3571local _max_0 = #_list_0
3572for _index_0 = 1, _max_0, 2 do
3011 local item = _list_0[_index_0] 3573 local item = _list_0[_index_0]
3012 _accum_0[_len_0] = item 3574 _accum_0[_len_0] = item
3013 _len_0 = _len_0 + 1 3575 _len_0 = _len_0 + 1
3014end 3576end
3015slice = _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
3016for i = 10, 20 do 3611for i = 10, 20 do
3017 print(i) 3612 print(i)
3018end 3613end
@@ -3023,8 +3618,7 @@ for key, value in pairs(object) do
3023 print(key, value) 3618 print(key, value)
3024end 3619end
3025local _list_0 = items 3620local _list_0 = items
3026local _max_0 = 4 3621for _index_0 = 2, 4 do
3027for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
3028 local item = _list_0[_index_0] 3622 local item = _list_0[_index_0]
3029 print(item) 3623 print(item)
3030end 3624end
@@ -3042,12 +3636,24 @@ local _len_0 = 1
3042for i = 1, 20 do 3636for i = 1, 20 do
3043 if i % 2 == 0 then 3637 if i % 2 == 0 then
3044 _accum_0[_len_0] = i * 2 3638 _accum_0[_len_0] = i * 2
3639 _len_0 = _len_0 + 1
3045 else 3640 else
3046 _accum_0[_len_0] = i 3641 _accum_0[_len_0] = i
3642 _len_0 = _len_0 + 1
3047 end 3643 end
3048 _len_0 = _len_0 + 1
3049end 3644end
3050doubled_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
3051local func_a 3657local func_a
3052func_a = function() 3658func_a = function()
3053 for i = 1, 10 do 3659 for i = 1, 10 do
@@ -3196,7 +3802,7 @@ if "Robert" == name then
3196elseif "Dan" == name or "Daniel" == name then 3802elseif "Dan" == name or "Daniel" == name then
3197 print("Your name, it's Dan") 3803 print("Your name, it's Dan")
3198else 3804else
3199 print("I don't know about your name") 3805 print("I don't know about you with name " .. tostring(name))
3200end 3806end
3201local b = 1 3807local b = 1
3202local next_number 3808local next_number
@@ -3296,6 +3902,192 @@ if _tab_0 then
3296 end 3902 end
3297 print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) 3903 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3298end 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
3299local Inventory 4091local Inventory
3300local _class_0 4092local _class_0
3301local _base_0 = { 4093local _base_0 = {
@@ -3952,6 +4744,10 @@ do
3952 _with_1["key-name"] = value 4744 _with_1["key-name"] = value
3953end 4745end
3954_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
3955do 4751do
3956 local var = "hello" 4752 local var = "hello"
3957 print(var) 4753 print(var)