aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs/codes_from_doc_zh.lua
diff options
context:
space:
mode:
Diffstat (limited to 'spec/outputs/codes_from_doc_zh.lua')
-rw-r--r--spec/outputs/codes_from_doc_zh.lua928
1 files changed, 912 insertions, 16 deletions
diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua
index acd41a0..de76829 100644
--- a/spec/outputs/codes_from_doc_zh.lua
+++ b/spec/outputs/codes_from_doc_zh.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("有效的枚举类型:", "Static") 111print("有效的枚举类型:", "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 = "这是一个字符串\n 并包括一个换行。" 820local some_string = "这是一个字符串\n 并包括一个换行。"
661print("我有" .. tostring(math.random() * 100) .. "%的把握。") 821print("我有" .. tostring(math.random() * 100) .. "%的把握。")
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()
@@ -749,6 +917,36 @@ if func(1, 2, 3, "你好", "世界") then
749 print("hello") 917 print("hello")
750 print("我在if内部") 918 print("我在if内部")
751end 919end
920local f1
921f1 = function(_arg_0)
922 local a, b, c
923 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
924 return print(a, b, c)
925end
926f1({
927 a = 1,
928 b = "2",
929 c = { }
930})
931local f2
932f2 = function(_arg_0, c)
933 local a1, b
934 a1, b = _arg_0.a, _arg_0.b
935 if a1 == nil then
936 a1 = 123
937 end
938 if b == nil then
939 b = 'abc'
940 end
941 if c == nil then
942 c = { }
943 end
944 return print(a1, b, c)
945end
946local arg1 = {
947 a = 0
948}
949f2(arg1, arg2)
752f(function() 950f(function()
753 return print("hello") 951 return print("hello")
754end) 952end)
@@ -964,8 +1162,7 @@ local slice
964local _accum_0 = { } 1162local _accum_0 = { }
965local _len_0 = 1 1163local _len_0 = 1
966local _list_0 = items 1164local _list_0 = items
967local _max_0 = 5 1165for _index_0 = 1, 5 do
968for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
969 local item = _list_0[_index_0] 1166 local item = _list_0[_index_0]
970 _accum_0[_len_0] = item 1167 _accum_0[_len_0] = item
971 _len_0 = _len_0 + 1 1168 _len_0 = _len_0 + 1
@@ -975,7 +1172,8 @@ local slice
975local _accum_0 = { } 1172local _accum_0 = { }
976local _len_0 = 1 1173local _len_0 = 1
977local _list_0 = items 1174local _list_0 = items
978for _index_0 = 2, #_list_0 do 1175local _max_0 = #_list_0
1176for _index_0 = 2, _max_0 do
979 local item = _list_0[_index_0] 1177 local item = _list_0[_index_0]
980 _accum_0[_len_0] = item 1178 _accum_0[_len_0] = item
981 _len_0 = _len_0 + 1 1179 _len_0 = _len_0 + 1
@@ -985,12 +1183,46 @@ local slice
985local _accum_0 = { } 1183local _accum_0 = { }
986local _len_0 = 1 1184local _len_0 = 1
987local _list_0 = items 1185local _list_0 = items
988for _index_0 = 1, #_list_0, 2 do 1186local _max_0 = #_list_0
1187for _index_0 = 1, _max_0, 2 do
989 local item = _list_0[_index_0] 1188 local item = _list_0[_index_0]
990 _accum_0[_len_0] = item 1189 _accum_0[_len_0] = item
991 _len_0 = _len_0 + 1 1190 _len_0 = _len_0 + 1
992end 1191end
993slice = _accum_0 1192slice = _accum_0
1193local slice
1194local _accum_0 = { }
1195local _len_0 = 1
1196local _list_0 = items
1197local _min_0 = #_list_0 + -4 + 1
1198local _max_0 = #_list_0 + -1 + 1
1199for _index_0 = _min_0, _max_0 do
1200 local item = _list_0[_index_0]
1201 _accum_0[_len_0] = item
1202 _len_0 = _len_0 + 1
1203end
1204slice = _accum_0
1205local reverse_slice
1206local _accum_0 = { }
1207local _len_0 = 1
1208local _list_0 = items
1209local _min_0 = #_list_0 + -1 + 1
1210for _index_0 = _min_0, 1, -1 do
1211 local item = _list_0[_index_0]
1212 _accum_0[_len_0] = item
1213 _len_0 = _len_0 + 1
1214end
1215reverse_slice = _accum_0
1216local sub_list
1217local _accum_0 = { }
1218local _len_0 = 1
1219local _list_0 = items
1220for _index_0 = 2, 4 do
1221 local _item_0 = _list_0[_index_0]
1222 _accum_0[_len_0] = _item_0
1223 _len_0 = _len_0 + 1
1224end
1225sub_list = _accum_0
994for i = 10, 20 do 1226for i = 10, 20 do
995 print(i) 1227 print(i)
996end 1228end
@@ -1001,8 +1233,7 @@ for key, value in pairs(object) do
1001 print(key, value) 1233 print(key, value)
1002end 1234end
1003local _list_0 = items 1235local _list_0 = items
1004local _max_0 = 4 1236for _index_0 = 2, 4 do
1005for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
1006 local item = _list_0[_index_0] 1237 local item = _list_0[_index_0]
1007 print(item) 1238 print(item)
1008end 1239end
@@ -1020,12 +1251,24 @@ local _len_0 = 1
1020for i = 1, 20 do 1251for i = 1, 20 do
1021 if i % 2 == 0 then 1252 if i % 2 == 0 then
1022 _accum_0[_len_0] = i * 2 1253 _accum_0[_len_0] = i * 2
1254 _len_0 = _len_0 + 1
1023 else 1255 else
1024 _accum_0[_len_0] = i 1256 _accum_0[_len_0] = i
1257 _len_0 = _len_0 + 1
1025 end 1258 end
1026 _len_0 = _len_0 + 1
1027end 1259end
1028doubled_evens = _accum_0 1260doubled_evens = _accum_0
1261local first_large
1262local _accum_0
1263local _list_0 = numbers
1264for _index_0 = 1, #_list_0 do
1265 local n = _list_0[_index_0]
1266 if n > 10 then
1267 _accum_0 = n
1268 break
1269 end
1270end
1271first_large = _accum_0
1029local func_a 1272local func_a
1030func_a = function() 1273func_a = function()
1031 for i = 1, 10 do 1274 for i = 1, 10 do
@@ -1174,7 +1417,7 @@ if "Robert" == name then
1174elseif "Dan" == name or "Daniel" == name then 1417elseif "Dan" == name or "Daniel" == name then
1175 print("你的名字是Dan") 1418 print("你的名字是Dan")
1176else 1419else
1177 print("我不知道你的名字") 1420 print("我不认识,你的名字" .. tostring(name))
1178end 1421end
1179local b = 1 1422local b = 1
1180local next_number 1423local next_number
@@ -1274,6 +1517,192 @@ if _tab_0 then
1274 end 1517 end
1275 print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) 1518 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
1276end 1519end
1520local _exp_0 = tb
1521local _type_0 = type(_exp_0)
1522local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1523local _match_0 = false
1524if _tab_0 then
1525 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
1526 _match_0 = true
1527 print("1, 2, 3")
1528 end
1529end
1530if not _match_0 then
1531 local _match_1 = false
1532 if _tab_0 then
1533 local b = _exp_0[2]
1534 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
1535 _match_1 = true
1536 print("1, " .. tostring(b) .. ", 3")
1537 end
1538 end
1539 if not _match_1 then
1540 if _tab_0 then
1541 local b = _exp_0[3]
1542 if b == nil then
1543 b = 3
1544 end
1545 if 1 == _exp_0[1] and 2 == _exp_0[2] then
1546 print("1, 2, " .. tostring(b))
1547 end
1548 end
1549 end
1550end
1551local _exp_0 = tb
1552local _type_0 = type(_exp_0)
1553local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1554local _match_0 = false
1555if _tab_0 then
1556 local result = _exp_0.result
1557 if true == _exp_0.success and result ~= nil then
1558 _match_0 = true
1559 print("成功", result)
1560 end
1561end
1562if not _match_0 then
1563 local _match_1 = false
1564 if _tab_0 then
1565 if false == _exp_0.success then
1566 _match_1 = true
1567 print("失败", result)
1568 end
1569 end
1570 if not _match_1 then
1571 print("无效值")
1572 end
1573end
1574local _exp_0 = tb
1575local _type_0 = type(_exp_0)
1576local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1577local _match_0 = false
1578if _tab_0 then
1579 local content
1580 do
1581 local _obj_0 = _exp_0.data
1582 local _type_1 = type(_obj_0)
1583 if "table" == _type_1 or "userdata" == _type_1 then
1584 content = _obj_0.content
1585 end
1586 end
1587 local _val_0
1588 do
1589 local _obj_0 = _exp_0.data
1590 if _obj_0 ~= nil then
1591 _val_0 = _obj_0.type
1592 end
1593 end
1594 if "success" == _val_0 and content ~= nil then
1595 _match_0 = true
1596 print("成功", content)
1597 end
1598end
1599if not _match_0 then
1600 local _match_1 = false
1601 if _tab_0 then
1602 local content
1603 do
1604 local _obj_0 = _exp_0.data
1605 local _type_1 = type(_obj_0)
1606 if "table" == _type_1 or "userdata" == _type_1 then
1607 content = _obj_0.content
1608 end
1609 end
1610 local _val_0
1611 do
1612 local _obj_0 = _exp_0.data
1613 if _obj_0 ~= nil then
1614 _val_0 = _obj_0.type
1615 end
1616 end
1617 if "error" == _val_0 and content ~= nil then
1618 _match_1 = true
1619 print("失败", content)
1620 end
1621 end
1622 if not _match_1 then
1623 print("无效值")
1624 end
1625end
1626local _exp_0 = tb
1627local _type_0 = type(_exp_0)
1628local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1629if _tab_0 then
1630 local fourth = _exp_0[4]
1631 local _val_0
1632 do
1633 local _obj_0 = _exp_0[1]
1634 if _obj_0 ~= nil then
1635 _val_0 = _obj_0.a
1636 end
1637 end
1638 local _val_1
1639 do
1640 local _obj_0 = _exp_0[1]
1641 if _obj_0 ~= nil then
1642 _val_1 = _obj_0.b
1643 end
1644 end
1645 local _val_2
1646 do
1647 local _obj_0 = _exp_0[2]
1648 if _obj_0 ~= nil then
1649 _val_2 = _obj_0.a
1650 end
1651 end
1652 local _val_3
1653 do
1654 local _obj_0 = _exp_0[2]
1655 if _obj_0 ~= nil then
1656 _val_3 = _obj_0.b
1657 end
1658 end
1659 local _val_4
1660 do
1661 local _obj_0 = _exp_0[3]
1662 if _obj_0 ~= nil then
1663 _val_4 = _obj_0.a
1664 end
1665 end
1666 local _val_5
1667 do
1668 local _obj_0 = _exp_0[3]
1669 if _obj_0 ~= nil then
1670 _val_5 = _obj_0.b
1671 end
1672 end
1673 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
1674 print("匹配成功", fourth)
1675 end
1676end
1677local segments = {
1678 "admin",
1679 "users",
1680 "logs",
1681 "view"
1682}
1683local _type_0 = type(segments)
1684local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1685if _tab_0 then
1686 local groups
1687 do
1688 local _accum_0 = { }
1689 local _len_0 = 1
1690 local _max_0 = #segments + -3 + 1
1691 for _index_0 = 1, _max_0 do
1692 local _item_0 = segments[_index_0]
1693 _accum_0[_len_0] = _item_0
1694 _len_0 = _len_0 + 1
1695 end
1696 groups = _accum_0
1697 end
1698 local resource = segments[#segments - 1]
1699 local action = segments[#segments]
1700 if resource ~= nil and action ~= nil then
1701 print("Group:", groups)
1702 print("Resource:", resource)
1703 print("Action:", action)
1704 end
1705end
1277local Inventory 1706local Inventory
1278local _class_0 1707local _class_0
1279local _base_0 = { 1708local _base_0 = {
@@ -1930,6 +2359,10 @@ do
1930 _with_1["key-name"] = value 2359 _with_1["key-name"] = value
1931end 2360end
1932_with_0[#_with_0 + 1] = "abc" 2361_with_0[#_with_0 + 1] = "abc"
2362local _with_0 = obj
2363if _with_0 ~= nil then
2364 print(obj.name)
2365end
1933do 2366do
1934 local var = "hello" 2367 local var = "hello"
1935 print(var) 2368 print(var)
@@ -2020,6 +2453,38 @@ local inventory = {
2020 } 2453 }
2021 } 2454 }
2022} 2455}
2456local map
2457map = function(arr, action)
2458 local _accum_0 = { }
2459 local _len_0 = 1
2460 for _index_0 = 1, #arr do
2461 local item = arr[_index_0]
2462 _accum_0[_len_0] = action(item)
2463 _len_0 = _len_0 + 1
2464 end
2465 return _accum_0
2466end
2467local filter
2468filter = function(arr, cond)
2469 local _accum_0 = { }
2470 local _len_0 = 1
2471 for _index_0 = 1, #arr do
2472 local item = arr[_index_0]
2473 if cond(item) then
2474 _accum_0[_len_0] = item
2475 _len_0 = _len_0 + 1
2476 end
2477 end
2478 return _accum_0
2479end
2480local reduce
2481reduce = function(arr, init, action)
2482 for _index_0 = 1, #arr do
2483 local item = arr[_index_0]
2484 init = action(init, item)
2485 end
2486 return init
2487end
2023print(reduce(filter(map({ 2488print(reduce(filter(map({
2024 1, 2489 1,
2025 2, 2490 2,
@@ -2077,6 +2542,12 @@ end
2077print("yuescript") 2542print("yuescript")
2078print(3) 2543print(3)
2079print("有效的枚举类型:", "Static") 2544print("有效的枚举类型:", "Static")
2545do
2546 print(123, "hello")
2547end
2548do
2549 print(123, "hello")
2550end
2080if tb ~= nil then 2551if tb ~= nil then
2081 tb:func() 2552 tb:func()
2082end 2553end
@@ -2177,6 +2648,16 @@ for _key_0, _value_0 in pairs(b) do
2177 end 2648 end
2178end 2649end
2179merge = _tab_0 2650merge = _tab_0
2651local last
2652do
2653 local _item_0 = data.items
2654 last = _item_0[#_item_0]
2655end
2656local second_last
2657do
2658 local _item_0 = data.items
2659 second_last = _item_0[#_item_0 - 1]
2660end
2180local mt = { } 2661local mt = { }
2181local add 2662local add
2182add = function(self, right) 2663add = function(self, right)
@@ -2307,6 +2788,14 @@ func({
2307 2, 2788 2,
2308 3 2789 3
2309}) 2790})
2791local f
2792f = function()
2793 return {
2794 1,
2795 2,
2796 3
2797 }
2798end
2310local tb = { 2799local tb = {
2311 name = "abc", 2800 name = "abc",
2312 values = { 2801 values = {
@@ -2547,6 +3036,59 @@ end
2547local two, four 3036local two, four
2548local _obj_0 = items 3037local _obj_0 = items
2549two, four = _obj_0[2], _obj_0[4] 3038two, four = _obj_0[2], _obj_0[4]
3039local orders = {
3040 "first",
3041 "second",
3042 "third",
3043 "fourth",
3044 "last"
3045}
3046local first, bulk, last = orders[1], (function()
3047 local _accum_0 = { }
3048 local _len_0 = 1
3049 local _max_0 = #orders + -2 + 1
3050 for _index_0 = 2, _max_0 do
3051 local _item_0 = orders[_index_0]
3052 _accum_0[_len_0] = _item_0
3053 _len_0 = _len_0 + 1
3054 end
3055 return _accum_0
3056end)(), orders[#orders]
3057print(first)
3058print(bulk)
3059print(last)
3060local first, rest
3061do
3062 local _obj_0 = orders
3063 first, rest = _obj_0[1], (function()
3064 local _accum_0 = { }
3065 local _len_0 = 1
3066 local _max_0 = #_obj_0
3067 for _index_0 = 2, _max_0 do
3068 local _item_0 = _obj_0[_index_0]
3069 _accum_0[_len_0] = _item_0
3070 _len_0 = _len_0 + 1
3071 end
3072 return _accum_0
3073 end)()
3074end
3075local start, last
3076do
3077 local _obj_0 = orders
3078 start, last = (function()
3079 local _accum_0 = { }
3080 local _len_0 = 1
3081 local _max_0 = #_obj_0 + -2 + 1
3082 for _index_0 = 1, _max_0 do
3083 local _item_0 = _obj_0[_index_0]
3084 _accum_0[_len_0] = _item_0
3085 _len_0 = _len_0 + 1
3086 end
3087 return _accum_0
3088 end)(), _obj_0[#_obj_0]
3089end
3090local _obj_0 = orders
3091first, last = _obj_0[1], _obj_0[#_obj_0]
2550local tuples = { 3092local tuples = {
2551 { 3093 {
2552 "hello", 3094 "hello",
@@ -2648,6 +3190,56 @@ end)
2648if success then 3190if success then
2649 print(result) 3191 print(result)
2650end 3192end
3193local a, b, c
3194do
3195 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
3196 return func()
3197 end)
3198 if _ok_0 then
3199 a, b, c = _ret_0, _ret_1, _ret_2
3200 end
3201end
3202do
3203 local _exp_0 = ((function()
3204 return (function(_arg_0, ...)
3205 local _ok_0 = _arg_0
3206 if _ok_0 then
3207 return ...
3208 end
3209 end)(pcall(function()
3210 return func()
3211 end))
3212 end)())
3213 if _exp_0 ~= nil then
3214 a = _exp_0
3215 else
3216 a = "default"
3217 end
3218end
3219f((function()
3220 return (function(_arg_0, ...)
3221 local _ok_0 = _arg_0
3222 if _ok_0 then
3223 return ...
3224 end
3225 end)(pcall(function()
3226 return func()
3227 end))
3228end)())
3229f((function()
3230 return (function(_arg_0, ...)
3231 local _ok_0 = _arg_0
3232 if _ok_0 then
3233 return ...
3234 end
3235 end)(xpcall(function()
3236 print(123)
3237 return func()
3238 end, function(e)
3239 print(e)
3240 return e
3241 end))
3242end)())
2651local a <const> = 123 3243local a <const> = 123
2652local _ <close> = setmetatable({ }, { 3244local _ <close> = setmetatable({ }, {
2653 __close = function() 3245 __close = function()
@@ -2657,10 +3249,19 @@ local _ <close> = setmetatable({ }, {
2657local a, b, c, d 3249local a, b, c, d
2658local _obj_0 = tb 3250local _obj_0 = tb
2659a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] 3251a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
3252Constant = 123
2660local some_string = "这是一个字符串\n 并包括一个换行。" 3253local some_string = "这是一个字符串\n 并包括一个换行。"
2661print("我有" .. tostring(math.random() * 100) .. "%的把握。") 3254print("我有" .. tostring(math.random() * 100) .. "%的把握。")
2662local integer = 1000000 3255local integer = 1000000
2663local hex = 0xEFBBBF 3256local hex = 0xEFBBBF
3257local binary = 19
3258local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
3259local fn
3260fn = function()
3261 local str = "foo:\n bar: baz"
3262 return str
3263end
3264local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
2664local my_function 3265local my_function
2665my_function = function() end 3266my_function = function() end
2666my_function() 3267my_function()
@@ -2749,6 +3350,66 @@ if func(1, 2, 3, "你好", "世界") then
2749 print("你好") 3350 print("你好")
2750 print("我在if内部") 3351 print("我在if内部")
2751end 3352end
3353local f1
3354f1 = function(_arg_0)
3355 local a, b, c
3356 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
3357 return print(a, b, c)
3358end
3359f1({
3360 a = 1,
3361 b = "2",
3362 c = { }
3363})
3364local f2
3365f2 = function(_arg_0, c)
3366 local a1, b
3367 a1, b = _arg_0.a, _arg_0.b
3368 if a1 == nil then
3369 a1 = 123
3370 end
3371 if b == nil then
3372 b = 'abc'
3373 end
3374 if c == nil then
3375 c = { }
3376 end
3377 return print(a1, b, c)
3378end
3379local arg1 = {
3380 a = 0
3381}
3382f2(arg1, arg2)
3383local findFirstEven
3384findFirstEven = function(list)
3385 for _index_0 = 1, #list do
3386 local item = list[_index_0]
3387 if type(item) == "table" then
3388 for _index_1 = 1, #item do
3389 local sub = item[_index_1]
3390 if sub % 2 == 0 then
3391 return sub
3392 end
3393 end
3394 end
3395 end
3396 return nil
3397end
3398local findFirstEven
3399findFirstEven = function(list)
3400 for _index_0 = 1, #list do
3401 local item = list[_index_0]
3402 if type(item) == "table" then
3403 for _index_1 = 1, #item do
3404 local sub = item[_index_1]
3405 if sub % 2 == 0 then
3406 return sub
3407 end
3408 end
3409 end
3410 end
3411 return nil
3412end
2752f(function() 3413f(function()
2753 return print("hello") 3414 return print("hello")
2754end) 3415end)
@@ -2964,8 +3625,7 @@ local slice
2964local _accum_0 = { } 3625local _accum_0 = { }
2965local _len_0 = 1 3626local _len_0 = 1
2966local _list_0 = items 3627local _list_0 = items
2967local _max_0 = 5 3628for _index_0 = 1, 5 do
2968for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
2969 local item = _list_0[_index_0] 3629 local item = _list_0[_index_0]
2970 _accum_0[_len_0] = item 3630 _accum_0[_len_0] = item
2971 _len_0 = _len_0 + 1 3631 _len_0 = _len_0 + 1
@@ -2975,7 +3635,8 @@ local slice
2975local _accum_0 = { } 3635local _accum_0 = { }
2976local _len_0 = 1 3636local _len_0 = 1
2977local _list_0 = items 3637local _list_0 = items
2978for _index_0 = 2, #_list_0 do 3638local _max_0 = #_list_0
3639for _index_0 = 2, _max_0 do
2979 local item = _list_0[_index_0] 3640 local item = _list_0[_index_0]
2980 _accum_0[_len_0] = item 3641 _accum_0[_len_0] = item
2981 _len_0 = _len_0 + 1 3642 _len_0 = _len_0 + 1
@@ -2985,12 +3646,46 @@ local slice
2985local _accum_0 = { } 3646local _accum_0 = { }
2986local _len_0 = 1 3647local _len_0 = 1
2987local _list_0 = items 3648local _list_0 = items
2988for _index_0 = 1, #_list_0, 2 do 3649local _max_0 = #_list_0
3650for _index_0 = 1, _max_0, 2 do
2989 local item = _list_0[_index_0] 3651 local item = _list_0[_index_0]
2990 _accum_0[_len_0] = item 3652 _accum_0[_len_0] = item
2991 _len_0 = _len_0 + 1 3653 _len_0 = _len_0 + 1
2992end 3654end
2993slice = _accum_0 3655slice = _accum_0
3656local slice
3657local _accum_0 = { }
3658local _len_0 = 1
3659local _list_0 = items
3660local _min_0 = #_list_0 + -4 + 1
3661local _max_0 = #_list_0 + -1 + 1
3662for _index_0 = _min_0, _max_0 do
3663 local item = _list_0[_index_0]
3664 _accum_0[_len_0] = item
3665 _len_0 = _len_0 + 1
3666end
3667slice = _accum_0
3668local reverse_slice
3669local _accum_0 = { }
3670local _len_0 = 1
3671local _list_0 = items
3672local _min_0 = #_list_0 + -1 + 1
3673for _index_0 = _min_0, 1, -1 do
3674 local item = _list_0[_index_0]
3675 _accum_0[_len_0] = item
3676 _len_0 = _len_0 + 1
3677end
3678reverse_slice = _accum_0
3679local sub_list
3680local _accum_0 = { }
3681local _len_0 = 1
3682local _list_0 = items
3683for _index_0 = 2, 4 do
3684 local _item_0 = _list_0[_index_0]
3685 _accum_0[_len_0] = _item_0
3686 _len_0 = _len_0 + 1
3687end
3688sub_list = _accum_0
2994for i = 10, 20 do 3689for i = 10, 20 do
2995 print(i) 3690 print(i)
2996end 3691end
@@ -3001,8 +3696,7 @@ for key, value in pairs(object) do
3001 print(key, value) 3696 print(key, value)
3002end 3697end
3003local _list_0 = items 3698local _list_0 = items
3004local _max_0 = 4 3699for _index_0 = 2, 4 do
3005for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
3006 local item = _list_0[_index_0] 3700 local item = _list_0[_index_0]
3007 print(item) 3701 print(item)
3008end 3702end
@@ -3020,12 +3714,24 @@ local _len_0 = 1
3020for i = 1, 20 do 3714for i = 1, 20 do
3021 if i % 2 == 0 then 3715 if i % 2 == 0 then
3022 _accum_0[_len_0] = i * 2 3716 _accum_0[_len_0] = i * 2
3717 _len_0 = _len_0 + 1
3023 else 3718 else
3024 _accum_0[_len_0] = i 3719 _accum_0[_len_0] = i
3720 _len_0 = _len_0 + 1
3025 end 3721 end
3026 _len_0 = _len_0 + 1
3027end 3722end
3028doubled_evens = _accum_0 3723doubled_evens = _accum_0
3724local first_large
3725local _accum_0
3726local _list_0 = numbers
3727for _index_0 = 1, #_list_0 do
3728 local n = _list_0[_index_0]
3729 if n > 10 then
3730 _accum_0 = n
3731 break
3732 end
3733end
3734first_large = _accum_0
3029local func_a 3735local func_a
3030func_a = function() 3736func_a = function()
3031 for i = 1, 10 do 3737 for i = 1, 10 do
@@ -3174,7 +3880,7 @@ if "Robert" == name then
3174elseif "Dan" == name or "Daniel" == name then 3880elseif "Dan" == name or "Daniel" == name then
3175 print("你的名字是Dan") 3881 print("你的名字是Dan")
3176else 3882else
3177 print("我不知道你的名字") 3883 print("我不认识,你的名字" .. tostring(name))
3178end 3884end
3179local b = 1 3885local b = 1
3180local next_number 3886local next_number
@@ -3274,6 +3980,192 @@ if _tab_0 then
3274 end 3980 end
3275 print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) 3981 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3276end 3982end
3983local _exp_0 = tb
3984local _type_0 = type(_exp_0)
3985local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3986local _match_0 = false
3987if _tab_0 then
3988 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
3989 _match_0 = true
3990 print("1, 2, 3")
3991 end
3992end
3993if not _match_0 then
3994 local _match_1 = false
3995 if _tab_0 then
3996 local b = _exp_0[2]
3997 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
3998 _match_1 = true
3999 print("1, " .. tostring(b) .. ", 3")
4000 end
4001 end
4002 if not _match_1 then
4003 if _tab_0 then
4004 local b = _exp_0[3]
4005 if b == nil then
4006 b = 3
4007 end
4008 if 1 == _exp_0[1] and 2 == _exp_0[2] then
4009 print("1, 2, " .. tostring(b))
4010 end
4011 end
4012 end
4013end
4014local _exp_0 = tb
4015local _type_0 = type(_exp_0)
4016local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4017local _match_0 = false
4018if _tab_0 then
4019 local result = _exp_0.result
4020 if true == _exp_0.success and result ~= nil then
4021 _match_0 = true
4022 print("成功", result)
4023 end
4024end
4025if not _match_0 then
4026 local _match_1 = false
4027 if _tab_0 then
4028 if false == _exp_0.success then
4029 _match_1 = true
4030 print("失败", result)
4031 end
4032 end
4033 if not _match_1 then
4034 print("无效值")
4035 end
4036end
4037local _exp_0 = tb
4038local _type_0 = type(_exp_0)
4039local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4040local _match_0 = false
4041if _tab_0 then
4042 local content
4043 do
4044 local _obj_0 = _exp_0.data
4045 local _type_1 = type(_obj_0)
4046 if "table" == _type_1 or "userdata" == _type_1 then
4047 content = _obj_0.content
4048 end
4049 end
4050 local _val_0
4051 do
4052 local _obj_0 = _exp_0.data
4053 if _obj_0 ~= nil then
4054 _val_0 = _obj_0.type
4055 end
4056 end
4057 if "success" == _val_0 and content ~= nil then
4058 _match_0 = true
4059 print("成功", content)
4060 end
4061end
4062if not _match_0 then
4063 local _match_1 = false
4064 if _tab_0 then
4065 local content
4066 do
4067 local _obj_0 = _exp_0.data
4068 local _type_1 = type(_obj_0)
4069 if "table" == _type_1 or "userdata" == _type_1 then
4070 content = _obj_0.content
4071 end
4072 end
4073 local _val_0
4074 do
4075 local _obj_0 = _exp_0.data
4076 if _obj_0 ~= nil then
4077 _val_0 = _obj_0.type
4078 end
4079 end
4080 if "error" == _val_0 and content ~= nil then
4081 _match_1 = true
4082 print("失败", content)
4083 end
4084 end
4085 if not _match_1 then
4086 print("无效值")
4087 end
4088end
4089local _exp_0 = tb
4090local _type_0 = type(_exp_0)
4091local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4092if _tab_0 then
4093 local fourth = _exp_0[4]
4094 local _val_0
4095 do
4096 local _obj_0 = _exp_0[1]
4097 if _obj_0 ~= nil then
4098 _val_0 = _obj_0.a
4099 end
4100 end
4101 local _val_1
4102 do
4103 local _obj_0 = _exp_0[1]
4104 if _obj_0 ~= nil then
4105 _val_1 = _obj_0.b
4106 end
4107 end
4108 local _val_2
4109 do
4110 local _obj_0 = _exp_0[2]
4111 if _obj_0 ~= nil then
4112 _val_2 = _obj_0.a
4113 end
4114 end
4115 local _val_3
4116 do
4117 local _obj_0 = _exp_0[2]
4118 if _obj_0 ~= nil then
4119 _val_3 = _obj_0.b
4120 end
4121 end
4122 local _val_4
4123 do
4124 local _obj_0 = _exp_0[3]
4125 if _obj_0 ~= nil then
4126 _val_4 = _obj_0.a
4127 end
4128 end
4129 local _val_5
4130 do
4131 local _obj_0 = _exp_0[3]
4132 if _obj_0 ~= nil then
4133 _val_5 = _obj_0.b
4134 end
4135 end
4136 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
4137 print("匹配成功", fourth)
4138 end
4139end
4140local segments = {
4141 "admin",
4142 "users",
4143 "logs",
4144 "view"
4145}
4146local _type_0 = type(segments)
4147local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4148if _tab_0 then
4149 local groups
4150 do
4151 local _accum_0 = { }
4152 local _len_0 = 1
4153 local _max_0 = #segments + -3 + 1
4154 for _index_0 = 1, _max_0 do
4155 local _item_0 = segments[_index_0]
4156 _accum_0[_len_0] = _item_0
4157 _len_0 = _len_0 + 1
4158 end
4159 groups = _accum_0
4160 end
4161 local resource = segments[#segments - 1]
4162 local action = segments[#segments]
4163 if resource ~= nil and action ~= nil then
4164 print("Group:", groups)
4165 print("Resource:", resource)
4166 print("Action:", action)
4167 end
4168end
3277local Inventory 4169local Inventory
3278local _class_0 4170local _class_0
3279local _base_0 = { 4171local _base_0 = {
@@ -3930,6 +4822,10 @@ do
3930 _with_1["key-name"] = value 4822 _with_1["key-name"] = value
3931end 4823end
3932_with_0[#_with_0 + 1] = "abc" 4824_with_0[#_with_0 + 1] = "abc"
4825local _with_0 = obj
4826if _with_0 ~= nil then
4827 print(obj.name)
4828end
3933do 4829do
3934 local var = "hello" 4830 local var = "hello"
3935 print(var) 4831 print(var)