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.lua872
1 files changed, 834 insertions, 38 deletions
diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua
index 1a10555..b54d6d7 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 = {
@@ -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("预先声明后续所有变量为局部变量") 528 print("预先声明后续所有变量为局部变量")
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("只预先声明后续大写的变量为局部变量") 538 print("只预先声明后续大写的变量为局部变量")
485 local a = 1 539 local a = 1
@@ -488,19 +542,17 @@ end
488do 542do
489 a = 1 543 a = 1
490 print("预先声明所有变量为全局变量") 544 print("预先声明所有变量为全局变量")
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("只预先声明大写的变量为全局变量") 552 print("只预先声明大写的变量为全局变量")
500 local a = 1 553 local a = 1
501 local B = 2 554 B = 2
502 local Temp 555 local Temp = "一个局部值"
503 Temp = "一个局部值"
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 = "这是一个字符串\n 并包括一个换行。" 820local some_string = "这是一个字符串\n 并包括一个换行。"
665print("我有" .. tostring(math.random() * 100) .. "%的把握。") 821print("我有" .. tostring(math.random() * 100) .. "%的把握。")
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()
@@ -858,11 +1022,10 @@ for i, item in ipairs(items) do
858 _len_0 = _len_0 + 1 1022 _len_0 = _len_0 + 1
859end 1023end
860doubled = _accum_0 1024doubled = _accum_0
861local iter = ipairs(items)
862local slice 1025local slice
863local _accum_0 = { } 1026local _accum_0 = { }
864local _len_0 = 1 1027local _len_0 = 1
865for i, item in iter do 1028for i, item in ipairs(items) do
866 if i > 1 and i < 3 then 1029 if i > 1 and i < 3 then
867 _accum_0[_len_0] = item 1030 _accum_0[_len_0] = item
868 _len_0 = _len_0 + 1 1031 _len_0 = _len_0 + 1
@@ -969,8 +1132,18 @@ local slice
969local _accum_0 = { } 1132local _accum_0 = { }
970local _len_0 = 1 1133local _len_0 = 1
971local _list_0 = items 1134local _list_0 = items
972local _max_0 = 5 1135for _index_0 = 1, 5 do
973for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do 1136 local item = _list_0[_index_0]
1137 _accum_0[_len_0] = item
1138 _len_0 = _len_0 + 1
1139end
1140slice = _accum_0
1141local slice
1142local _accum_0 = { }
1143local _len_0 = 1
1144local _list_0 = items
1145local _max_0 = #_list_0
1146for _index_0 = 2, _max_0 do
974 local item = _list_0[_index_0] 1147 local item = _list_0[_index_0]
975 _accum_0[_len_0] = item 1148 _accum_0[_len_0] = item
976 _len_0 = _len_0 + 1 1149 _len_0 = _len_0 + 1
@@ -980,7 +1153,8 @@ local slice
980local _accum_0 = { } 1153local _accum_0 = { }
981local _len_0 = 1 1154local _len_0 = 1
982local _list_0 = items 1155local _list_0 = items
983for _index_0 = 2, #_list_0 do 1156local _max_0 = #_list_0
1157for _index_0 = 1, _max_0, 2 do
984 local item = _list_0[_index_0] 1158 local item = _list_0[_index_0]
985 _accum_0[_len_0] = item 1159 _accum_0[_len_0] = item
986 _len_0 = _len_0 + 1 1160 _len_0 = _len_0 + 1
@@ -990,12 +1164,35 @@ local slice
990local _accum_0 = { } 1164local _accum_0 = { }
991local _len_0 = 1 1165local _len_0 = 1
992local _list_0 = items 1166local _list_0 = items
993for _index_0 = 1, #_list_0, 2 do 1167local _min_0 = #_list_0 + -4 + 1
1168local _max_0 = #_list_0 + -1 + 1
1169for _index_0 = _min_0, _max_0 do
994 local item = _list_0[_index_0] 1170 local item = _list_0[_index_0]
995 _accum_0[_len_0] = item 1171 _accum_0[_len_0] = item
996 _len_0 = _len_0 + 1 1172 _len_0 = _len_0 + 1
997end 1173end
998slice = _accum_0 1174slice = _accum_0
1175local reverse_slice
1176local _accum_0 = { }
1177local _len_0 = 1
1178local _list_0 = items
1179local _min_0 = #_list_0 + -1 + 1
1180for _index_0 = _min_0, 1, -1 do
1181 local item = _list_0[_index_0]
1182 _accum_0[_len_0] = item
1183 _len_0 = _len_0 + 1
1184end
1185reverse_slice = _accum_0
1186local sub_list
1187local _accum_0 = { }
1188local _len_0 = 1
1189local _list_0 = items
1190for _index_0 = 2, 4 do
1191 local _item_0 = _list_0[_index_0]
1192 _accum_0[_len_0] = _item_0
1193 _len_0 = _len_0 + 1
1194end
1195sub_list = _accum_0
999for i = 10, 20 do 1196for i = 10, 20 do
1000 print(i) 1197 print(i)
1001end 1198end
@@ -1006,8 +1203,7 @@ for key, value in pairs(object) do
1006 print(key, value) 1203 print(key, value)
1007end 1204end
1008local _list_0 = items 1205local _list_0 = items
1009local _max_0 = 4 1206for _index_0 = 2, 4 do
1010for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
1011 local item = _list_0[_index_0] 1207 local item = _list_0[_index_0]
1012 print(item) 1208 print(item)
1013end 1209end
@@ -1025,12 +1221,24 @@ local _len_0 = 1
1025for i = 1, 20 do 1221for i = 1, 20 do
1026 if i % 2 == 0 then 1222 if i % 2 == 0 then
1027 _accum_0[_len_0] = i * 2 1223 _accum_0[_len_0] = i * 2
1224 _len_0 = _len_0 + 1
1028 else 1225 else
1029 _accum_0[_len_0] = i 1226 _accum_0[_len_0] = i
1227 _len_0 = _len_0 + 1
1030 end 1228 end
1031 _len_0 = _len_0 + 1
1032end 1229end
1033doubled_evens = _accum_0 1230doubled_evens = _accum_0
1231local first_large
1232local _accum_0
1233local _list_0 = numbers
1234for _index_0 = 1, #_list_0 do
1235 local n = _list_0[_index_0]
1236 if n > 10 then
1237 _accum_0 = n
1238 break
1239 end
1240end
1241first_large = _accum_0
1034local func_a 1242local func_a
1035func_a = function() 1243func_a = function()
1036 for i = 1, 10 do 1244 for i = 1, 10 do
@@ -1179,7 +1387,7 @@ if "Robert" == name then
1179elseif "Dan" == name or "Daniel" == name then 1387elseif "Dan" == name or "Daniel" == name then
1180 print("你的名字是Dan") 1388 print("你的名字是Dan")
1181else 1389else
1182 print("我不知道你的名字") 1390 print("我不认识,你的名字" .. tostring(name))
1183end 1391end
1184local b = 1 1392local b = 1
1185local next_number 1393local next_number
@@ -1279,6 +1487,192 @@ if _tab_0 then
1279 end 1487 end
1280 print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) 1488 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
1281end 1489end
1490local _exp_0 = tb
1491local _type_0 = type(_exp_0)
1492local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1493local _match_0 = false
1494if _tab_0 then
1495 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
1496 _match_0 = true
1497 print("1, 2, 3")
1498 end
1499end
1500if not _match_0 then
1501 local _match_1 = false
1502 if _tab_0 then
1503 local b = _exp_0[2]
1504 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
1505 _match_1 = true
1506 print("1, " .. tostring(b) .. ", 3")
1507 end
1508 end
1509 if not _match_1 then
1510 if _tab_0 then
1511 local b = _exp_0[3]
1512 if b == nil then
1513 b = 3
1514 end
1515 if 1 == _exp_0[1] and 2 == _exp_0[2] then
1516 print("1, 2, " .. tostring(b))
1517 end
1518 end
1519 end
1520end
1521local _exp_0 = tb
1522local _type_0 = type(_exp_0)
1523local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1524local _match_0 = false
1525if _tab_0 then
1526 local result = _exp_0.result
1527 if true == _exp_0.success and result ~= nil then
1528 _match_0 = true
1529 print("成功", result)
1530 end
1531end
1532if not _match_0 then
1533 local _match_1 = false
1534 if _tab_0 then
1535 if false == _exp_0.success then
1536 _match_1 = true
1537 print("失败", result)
1538 end
1539 end
1540 if not _match_1 then
1541 print("无效值")
1542 end
1543end
1544local _exp_0 = tb
1545local _type_0 = type(_exp_0)
1546local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1547local _match_0 = false
1548if _tab_0 then
1549 local content
1550 do
1551 local _obj_0 = _exp_0.data
1552 local _type_1 = type(_obj_0)
1553 if "table" == _type_1 or "userdata" == _type_1 then
1554 content = _obj_0.content
1555 end
1556 end
1557 local _val_0
1558 do
1559 local _obj_0 = _exp_0.data
1560 if _obj_0 ~= nil then
1561 _val_0 = _obj_0.type
1562 end
1563 end
1564 if "success" == _val_0 and content ~= nil then
1565 _match_0 = true
1566 print("成功", content)
1567 end
1568end
1569if not _match_0 then
1570 local _match_1 = false
1571 if _tab_0 then
1572 local content
1573 do
1574 local _obj_0 = _exp_0.data
1575 local _type_1 = type(_obj_0)
1576 if "table" == _type_1 or "userdata" == _type_1 then
1577 content = _obj_0.content
1578 end
1579 end
1580 local _val_0
1581 do
1582 local _obj_0 = _exp_0.data
1583 if _obj_0 ~= nil then
1584 _val_0 = _obj_0.type
1585 end
1586 end
1587 if "error" == _val_0 and content ~= nil then
1588 _match_1 = true
1589 print("失败", content)
1590 end
1591 end
1592 if not _match_1 then
1593 print("无效值")
1594 end
1595end
1596local _exp_0 = tb
1597local _type_0 = type(_exp_0)
1598local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1599if _tab_0 then
1600 local fourth = _exp_0[4]
1601 local _val_0
1602 do
1603 local _obj_0 = _exp_0[1]
1604 if _obj_0 ~= nil then
1605 _val_0 = _obj_0.a
1606 end
1607 end
1608 local _val_1
1609 do
1610 local _obj_0 = _exp_0[1]
1611 if _obj_0 ~= nil then
1612 _val_1 = _obj_0.b
1613 end
1614 end
1615 local _val_2
1616 do
1617 local _obj_0 = _exp_0[2]
1618 if _obj_0 ~= nil then
1619 _val_2 = _obj_0.a
1620 end
1621 end
1622 local _val_3
1623 do
1624 local _obj_0 = _exp_0[2]
1625 if _obj_0 ~= nil then
1626 _val_3 = _obj_0.b
1627 end
1628 end
1629 local _val_4
1630 do
1631 local _obj_0 = _exp_0[3]
1632 if _obj_0 ~= nil then
1633 _val_4 = _obj_0.a
1634 end
1635 end
1636 local _val_5
1637 do
1638 local _obj_0 = _exp_0[3]
1639 if _obj_0 ~= nil then
1640 _val_5 = _obj_0.b
1641 end
1642 end
1643 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
1644 print("匹配成功", fourth)
1645 end
1646end
1647local segments = {
1648 "admin",
1649 "users",
1650 "logs",
1651 "view"
1652}
1653local _type_0 = type(segments)
1654local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1655if _tab_0 then
1656 local groups
1657 do
1658 local _accum_0 = { }
1659 local _len_0 = 1
1660 local _max_0 = #segments + -3 + 1
1661 for _index_0 = 1, _max_0 do
1662 local _item_0 = segments[_index_0]
1663 _accum_0[_len_0] = _item_0
1664 _len_0 = _len_0 + 1
1665 end
1666 groups = _accum_0
1667 end
1668 local resource = segments[#segments - 1]
1669 local action = segments[#segments]
1670 if resource ~= nil and action ~= nil then
1671 print("Group:", groups)
1672 print("Resource:", resource)
1673 print("Action:", action)
1674 end
1675end
1282local Inventory 1676local Inventory
1283local _class_0 1677local _class_0
1284local _base_0 = { 1678local _base_0 = {
@@ -1935,6 +2329,10 @@ do
1935 _with_1["key-name"] = value 2329 _with_1["key-name"] = value
1936end 2330end
1937_with_0[#_with_0 + 1] = "abc" 2331_with_0[#_with_0 + 1] = "abc"
2332local _with_0 = obj
2333if _with_0 ~= nil then
2334 print(obj.name)
2335end
1938do 2336do
1939 local var = "hello" 2337 local var = "hello"
1940 print(var) 2338 print(var)
@@ -2025,6 +2423,38 @@ local inventory = {
2025 } 2423 }
2026 } 2424 }
2027} 2425}
2426local map
2427map = function(arr, action)
2428 local _accum_0 = { }
2429 local _len_0 = 1
2430 for _index_0 = 1, #arr do
2431 local item = arr[_index_0]
2432 _accum_0[_len_0] = action(item)
2433 _len_0 = _len_0 + 1
2434 end
2435 return _accum_0
2436end
2437local filter
2438filter = function(arr, cond)
2439 local _accum_0 = { }
2440 local _len_0 = 1
2441 for _index_0 = 1, #arr do
2442 local item = arr[_index_0]
2443 if cond(item) then
2444 _accum_0[_len_0] = item
2445 _len_0 = _len_0 + 1
2446 end
2447 end
2448 return _accum_0
2449end
2450local reduce
2451reduce = function(arr, init, action)
2452 for _index_0 = 1, #arr do
2453 local item = arr[_index_0]
2454 init = action(init, item)
2455 end
2456 return init
2457end
2028print(reduce(filter(map({ 2458print(reduce(filter(map({
2029 1, 2459 1,
2030 2, 2460 2,
@@ -2082,6 +2512,12 @@ end
2082print("yuescript") 2512print("yuescript")
2083print(3) 2513print(3)
2084print("有效的枚举类型:", "Static") 2514print("有效的枚举类型:", "Static")
2515do
2516 print(123, "hello")
2517end
2518do
2519 print(123, "hello")
2520end
2085if tb ~= nil then 2521if tb ~= nil then
2086 tb:func() 2522 tb:func()
2087end 2523end
@@ -2182,6 +2618,16 @@ for _key_0, _value_0 in pairs(b) do
2182 end 2618 end
2183end 2619end
2184merge = _tab_0 2620merge = _tab_0
2621local last
2622do
2623 local _item_0 = data.items
2624 last = _item_0[#_item_0]
2625end
2626local second_last
2627do
2628 local _item_0 = data.items
2629 second_last = _item_0[#_item_0 - 1]
2630end
2185local mt = { } 2631local mt = { }
2186local add 2632local add
2187add = function(self, right) 2633add = function(self, right)
@@ -2312,6 +2758,14 @@ func({
2312 2, 2758 2,
2313 3 2759 3
2314}) 2760})
2761local f
2762f = function()
2763 return {
2764 1,
2765 2,
2766 3
2767 }
2768end
2315local tb = { 2769local tb = {
2316 name = "abc", 2770 name = "abc",
2317 values = { 2771 values = {
@@ -2472,8 +2926,7 @@ local x = f()
2472local y = x 2926local y = x
2473local z = x 2927local z = x
2474do 2928do
2475 local a 2929 local a = 1
2476 a = 1
2477 local x, y, z 2930 local x, y, z
2478 print("预先声明后续所有变量为局部变量") 2931 print("预先声明后续所有变量为局部变量")
2479 x = function() 2932 x = function()
@@ -2483,8 +2936,7 @@ do
2483 instance = Item:new() 2936 instance = Item:new()
2484end 2937end
2485do 2938do
2486 local X 2939 local X = 1
2487 X = 1
2488 local B 2940 local B
2489 print("只预先声明后续大写的变量为局部变量") 2941 print("只预先声明后续大写的变量为局部变量")
2490 local a = 1 2942 local a = 1
@@ -2493,19 +2945,17 @@ end
2493do 2945do
2494 a = 1 2946 a = 1
2495 print("预先声明所有变量为全局变量") 2947 print("预先声明所有变量为全局变量")
2496 local x
2497 x = function() 2948 x = function()
2498 return 1 + y + z 2949 return 1 + y + z
2499 end 2950 end
2500 local y, z = 2, 3 2951 y, z = 2, 3
2501end 2952end
2502do 2953do
2503 x = 1 2954 x = 1
2504 print("只预先声明大写的变量为全局变量") 2955 print("只预先声明大写的变量为全局变量")
2505 local a = 1 2956 local a = 1
2506 local B = 2 2957 B = 2
2507 local Temp 2958 local Temp = "一个局部值"
2508 Temp = "一个局部值"
2509end 2959end
2510local thing = { 2960local thing = {
2511 1, 2961 1,
@@ -2556,6 +3006,59 @@ end
2556local two, four 3006local two, four
2557local _obj_0 = items 3007local _obj_0 = items
2558two, four = _obj_0[2], _obj_0[4] 3008two, four = _obj_0[2], _obj_0[4]
3009local orders = {
3010 "first",
3011 "second",
3012 "third",
3013 "fourth",
3014 "last"
3015}
3016local first, bulk, last = orders[1], (function()
3017 local _accum_0 = { }
3018 local _len_0 = 1
3019 local _max_0 = #orders + -2 + 1
3020 for _index_0 = 2, _max_0 do
3021 local _item_0 = orders[_index_0]
3022 _accum_0[_len_0] = _item_0
3023 _len_0 = _len_0 + 1
3024 end
3025 return _accum_0
3026end)(), orders[#orders]
3027print(first)
3028print(bulk)
3029print(last)
3030local first, rest
3031do
3032 local _obj_0 = orders
3033 first, rest = _obj_0[1], (function()
3034 local _accum_0 = { }
3035 local _len_0 = 1
3036 local _max_0 = #_obj_0
3037 for _index_0 = 2, _max_0 do
3038 local _item_0 = _obj_0[_index_0]
3039 _accum_0[_len_0] = _item_0
3040 _len_0 = _len_0 + 1
3041 end
3042 return _accum_0
3043 end)()
3044end
3045local start, last
3046do
3047 local _obj_0 = orders
3048 start, last = (function()
3049 local _accum_0 = { }
3050 local _len_0 = 1
3051 local _max_0 = #_obj_0 + -2 + 1
3052 for _index_0 = 1, _max_0 do
3053 local _item_0 = _obj_0[_index_0]
3054 _accum_0[_len_0] = _item_0
3055 _len_0 = _len_0 + 1
3056 end
3057 return _accum_0
3058 end)(), _obj_0[#_obj_0]
3059end
3060local _obj_0 = orders
3061first, last = _obj_0[1], _obj_0[#_obj_0]
2559local tuples = { 3062local tuples = {
2560 { 3063 {
2561 "hello", 3064 "hello",
@@ -2657,6 +3160,56 @@ end)
2657if success then 3160if success then
2658 print(result) 3161 print(result)
2659end 3162end
3163local a, b, c
3164do
3165 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
3166 return func()
3167 end)
3168 if _ok_0 then
3169 a, b, c = _ret_0, _ret_1, _ret_2
3170 end
3171end
3172do
3173 local _exp_0 = ((function()
3174 return (function(_arg_0, ...)
3175 local _ok_0 = _arg_0
3176 if _ok_0 then
3177 return ...
3178 end
3179 end)(pcall(function()
3180 return func()
3181 end))
3182 end)())
3183 if _exp_0 ~= nil then
3184 a = _exp_0
3185 else
3186 a = "default"
3187 end
3188end
3189f((function()
3190 return (function(_arg_0, ...)
3191 local _ok_0 = _arg_0
3192 if _ok_0 then
3193 return ...
3194 end
3195 end)(pcall(function()
3196 return func()
3197 end))
3198end)())
3199f((function()
3200 return (function(_arg_0, ...)
3201 local _ok_0 = _arg_0
3202 if _ok_0 then
3203 return ...
3204 end
3205 end)(xpcall(function()
3206 print(123)
3207 return func()
3208 end, function(e)
3209 print(e)
3210 return e
3211 end))
3212end)())
2660local a <const> = 123 3213local a <const> = 123
2661local _ <close> = setmetatable({ }, { 3214local _ <close> = setmetatable({ }, {
2662 __close = function() 3215 __close = function()
@@ -2666,10 +3219,19 @@ local _ <close> = setmetatable({ }, {
2666local a, b, c, d 3219local a, b, c, d
2667local _obj_0 = tb 3220local _obj_0 = tb
2668a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] 3221a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
3222Constant = 123
2669local some_string = "这是一个字符串\n 并包括一个换行。" 3223local some_string = "这是一个字符串\n 并包括一个换行。"
2670print("我有" .. tostring(math.random() * 100) .. "%的把握。") 3224print("我有" .. tostring(math.random() * 100) .. "%的把握。")
2671local integer = 1000000 3225local integer = 1000000
2672local hex = 0xEFBBBF 3226local hex = 0xEFBBBF
3227local binary = 19
3228local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
3229local fn
3230fn = function()
3231 local str = "foo:\n bar: baz"
3232 return str
3233end
3234local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
2673local my_function 3235local my_function
2674my_function = function() end 3236my_function = function() end
2675my_function() 3237my_function()
@@ -2863,11 +3425,10 @@ for i, item in ipairs(items) do
2863 _len_0 = _len_0 + 1 3425 _len_0 = _len_0 + 1
2864end 3426end
2865doubled = _accum_0 3427doubled = _accum_0
2866local iter = ipairs(items)
2867local slice 3428local slice
2868local _accum_0 = { } 3429local _accum_0 = { }
2869local _len_0 = 1 3430local _len_0 = 1
2870for i, item in iter do 3431for i, item in ipairs(items) do
2871 if i > 1 and i < 3 then 3432 if i > 1 and i < 3 then
2872 _accum_0[_len_0] = item 3433 _accum_0[_len_0] = item
2873 _len_0 = _len_0 + 1 3434 _len_0 = _len_0 + 1
@@ -2974,8 +3535,18 @@ local slice
2974local _accum_0 = { } 3535local _accum_0 = { }
2975local _len_0 = 1 3536local _len_0 = 1
2976local _list_0 = items 3537local _list_0 = items
2977local _max_0 = 5 3538for _index_0 = 1, 5 do
2978for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do 3539 local item = _list_0[_index_0]
3540 _accum_0[_len_0] = item
3541 _len_0 = _len_0 + 1
3542end
3543slice = _accum_0
3544local slice
3545local _accum_0 = { }
3546local _len_0 = 1
3547local _list_0 = items
3548local _max_0 = #_list_0
3549for _index_0 = 2, _max_0 do
2979 local item = _list_0[_index_0] 3550 local item = _list_0[_index_0]
2980 _accum_0[_len_0] = item 3551 _accum_0[_len_0] = item
2981 _len_0 = _len_0 + 1 3552 _len_0 = _len_0 + 1
@@ -2985,7 +3556,8 @@ local slice
2985local _accum_0 = { } 3556local _accum_0 = { }
2986local _len_0 = 1 3557local _len_0 = 1
2987local _list_0 = items 3558local _list_0 = items
2988for _index_0 = 2, #_list_0 do 3559local _max_0 = #_list_0
3560for _index_0 = 1, _max_0, 2 do
2989 local item = _list_0[_index_0] 3561 local item = _list_0[_index_0]
2990 _accum_0[_len_0] = item 3562 _accum_0[_len_0] = item
2991 _len_0 = _len_0 + 1 3563 _len_0 = _len_0 + 1
@@ -2995,12 +3567,35 @@ local slice
2995local _accum_0 = { } 3567local _accum_0 = { }
2996local _len_0 = 1 3568local _len_0 = 1
2997local _list_0 = items 3569local _list_0 = items
2998for _index_0 = 1, #_list_0, 2 do 3570local _min_0 = #_list_0 + -4 + 1
3571local _max_0 = #_list_0 + -1 + 1
3572for _index_0 = _min_0, _max_0 do
2999 local item = _list_0[_index_0] 3573 local item = _list_0[_index_0]
3000 _accum_0[_len_0] = item 3574 _accum_0[_len_0] = item
3001 _len_0 = _len_0 + 1 3575 _len_0 = _len_0 + 1
3002end 3576end
3003slice = _accum_0 3577slice = _accum_0
3578local reverse_slice
3579local _accum_0 = { }
3580local _len_0 = 1
3581local _list_0 = items
3582local _min_0 = #_list_0 + -1 + 1
3583for _index_0 = _min_0, 1, -1 do
3584 local item = _list_0[_index_0]
3585 _accum_0[_len_0] = item
3586 _len_0 = _len_0 + 1
3587end
3588reverse_slice = _accum_0
3589local sub_list
3590local _accum_0 = { }
3591local _len_0 = 1
3592local _list_0 = items
3593for _index_0 = 2, 4 do
3594 local _item_0 = _list_0[_index_0]
3595 _accum_0[_len_0] = _item_0
3596 _len_0 = _len_0 + 1
3597end
3598sub_list = _accum_0
3004for i = 10, 20 do 3599for i = 10, 20 do
3005 print(i) 3600 print(i)
3006end 3601end
@@ -3011,8 +3606,7 @@ for key, value in pairs(object) do
3011 print(key, value) 3606 print(key, value)
3012end 3607end
3013local _list_0 = items 3608local _list_0 = items
3014local _max_0 = 4 3609for _index_0 = 2, 4 do
3015for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
3016 local item = _list_0[_index_0] 3610 local item = _list_0[_index_0]
3017 print(item) 3611 print(item)
3018end 3612end
@@ -3030,12 +3624,24 @@ local _len_0 = 1
3030for i = 1, 20 do 3624for i = 1, 20 do
3031 if i % 2 == 0 then 3625 if i % 2 == 0 then
3032 _accum_0[_len_0] = i * 2 3626 _accum_0[_len_0] = i * 2
3627 _len_0 = _len_0 + 1
3033 else 3628 else
3034 _accum_0[_len_0] = i 3629 _accum_0[_len_0] = i
3630 _len_0 = _len_0 + 1
3035 end 3631 end
3036 _len_0 = _len_0 + 1
3037end 3632end
3038doubled_evens = _accum_0 3633doubled_evens = _accum_0
3634local first_large
3635local _accum_0
3636local _list_0 = numbers
3637for _index_0 = 1, #_list_0 do
3638 local n = _list_0[_index_0]
3639 if n > 10 then
3640 _accum_0 = n
3641 break
3642 end
3643end
3644first_large = _accum_0
3039local func_a 3645local func_a
3040func_a = function() 3646func_a = function()
3041 for i = 1, 10 do 3647 for i = 1, 10 do
@@ -3184,7 +3790,7 @@ if "Robert" == name then
3184elseif "Dan" == name or "Daniel" == name then 3790elseif "Dan" == name or "Daniel" == name then
3185 print("你的名字是Dan") 3791 print("你的名字是Dan")
3186else 3792else
3187 print("我不知道你的名字") 3793 print("我不认识,你的名字" .. tostring(name))
3188end 3794end
3189local b = 1 3795local b = 1
3190local next_number 3796local next_number
@@ -3284,6 +3890,192 @@ if _tab_0 then
3284 end 3890 end
3285 print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) 3891 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3286end 3892end
3893local _exp_0 = tb
3894local _type_0 = type(_exp_0)
3895local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3896local _match_0 = false
3897if _tab_0 then
3898 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
3899 _match_0 = true
3900 print("1, 2, 3")
3901 end
3902end
3903if not _match_0 then
3904 local _match_1 = false
3905 if _tab_0 then
3906 local b = _exp_0[2]
3907 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
3908 _match_1 = true
3909 print("1, " .. tostring(b) .. ", 3")
3910 end
3911 end
3912 if not _match_1 then
3913 if _tab_0 then
3914 local b = _exp_0[3]
3915 if b == nil then
3916 b = 3
3917 end
3918 if 1 == _exp_0[1] and 2 == _exp_0[2] then
3919 print("1, 2, " .. tostring(b))
3920 end
3921 end
3922 end
3923end
3924local _exp_0 = tb
3925local _type_0 = type(_exp_0)
3926local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3927local _match_0 = false
3928if _tab_0 then
3929 local result = _exp_0.result
3930 if true == _exp_0.success and result ~= nil then
3931 _match_0 = true
3932 print("成功", result)
3933 end
3934end
3935if not _match_0 then
3936 local _match_1 = false
3937 if _tab_0 then
3938 if false == _exp_0.success then
3939 _match_1 = true
3940 print("失败", result)
3941 end
3942 end
3943 if not _match_1 then
3944 print("无效值")
3945 end
3946end
3947local _exp_0 = tb
3948local _type_0 = type(_exp_0)
3949local _tab_0 = "table" == _type_0 or "userdata" == _type_0
3950local _match_0 = false
3951if _tab_0 then
3952 local content
3953 do
3954 local _obj_0 = _exp_0.data
3955 local _type_1 = type(_obj_0)
3956 if "table" == _type_1 or "userdata" == _type_1 then
3957 content = _obj_0.content
3958 end
3959 end
3960 local _val_0
3961 do
3962 local _obj_0 = _exp_0.data
3963 if _obj_0 ~= nil then
3964 _val_0 = _obj_0.type
3965 end
3966 end
3967 if "success" == _val_0 and content ~= nil then
3968 _match_0 = true
3969 print("成功", content)
3970 end
3971end
3972if not _match_0 then
3973 local _match_1 = false
3974 if _tab_0 then
3975 local content
3976 do
3977 local _obj_0 = _exp_0.data
3978 local _type_1 = type(_obj_0)
3979 if "table" == _type_1 or "userdata" == _type_1 then
3980 content = _obj_0.content
3981 end
3982 end
3983 local _val_0
3984 do
3985 local _obj_0 = _exp_0.data
3986 if _obj_0 ~= nil then
3987 _val_0 = _obj_0.type
3988 end
3989 end
3990 if "error" == _val_0 and content ~= nil then
3991 _match_1 = true
3992 print("失败", content)
3993 end
3994 end
3995 if not _match_1 then
3996 print("无效值")
3997 end
3998end
3999local _exp_0 = tb
4000local _type_0 = type(_exp_0)
4001local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4002if _tab_0 then
4003 local fourth = _exp_0[4]
4004 local _val_0
4005 do
4006 local _obj_0 = _exp_0[1]
4007 if _obj_0 ~= nil then
4008 _val_0 = _obj_0.a
4009 end
4010 end
4011 local _val_1
4012 do
4013 local _obj_0 = _exp_0[1]
4014 if _obj_0 ~= nil then
4015 _val_1 = _obj_0.b
4016 end
4017 end
4018 local _val_2
4019 do
4020 local _obj_0 = _exp_0[2]
4021 if _obj_0 ~= nil then
4022 _val_2 = _obj_0.a
4023 end
4024 end
4025 local _val_3
4026 do
4027 local _obj_0 = _exp_0[2]
4028 if _obj_0 ~= nil then
4029 _val_3 = _obj_0.b
4030 end
4031 end
4032 local _val_4
4033 do
4034 local _obj_0 = _exp_0[3]
4035 if _obj_0 ~= nil then
4036 _val_4 = _obj_0.a
4037 end
4038 end
4039 local _val_5
4040 do
4041 local _obj_0 = _exp_0[3]
4042 if _obj_0 ~= nil then
4043 _val_5 = _obj_0.b
4044 end
4045 end
4046 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
4047 print("匹配成功", fourth)
4048 end
4049end
4050local segments = {
4051 "admin",
4052 "users",
4053 "logs",
4054 "view"
4055}
4056local _type_0 = type(segments)
4057local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4058if _tab_0 then
4059 local groups
4060 do
4061 local _accum_0 = { }
4062 local _len_0 = 1
4063 local _max_0 = #segments + -3 + 1
4064 for _index_0 = 1, _max_0 do
4065 local _item_0 = segments[_index_0]
4066 _accum_0[_len_0] = _item_0
4067 _len_0 = _len_0 + 1
4068 end
4069 groups = _accum_0
4070 end
4071 local resource = segments[#segments - 1]
4072 local action = segments[#segments]
4073 if resource ~= nil and action ~= nil then
4074 print("Group:", groups)
4075 print("Resource:", resource)
4076 print("Action:", action)
4077 end
4078end
3287local Inventory 4079local Inventory
3288local _class_0 4080local _class_0
3289local _base_0 = { 4081local _base_0 = {
@@ -3940,6 +4732,10 @@ do
3940 _with_1["key-name"] = value 4732 _with_1["key-name"] = value
3941end 4733end
3942_with_0[#_with_0 + 1] = "abc" 4734_with_0[#_with_0 + 1] = "abc"
4735local _with_0 = obj
4736if _with_0 ~= nil then
4737 print(obj.name)
4738end
3943do 4739do
3944 local var = "hello" 4740 local var = "hello"
3945 print(var) 4741 print(var)