diff options
Diffstat (limited to 'spec/outputs/codes_from_doc_zh.lua')
-rw-r--r-- | spec/outputs/codes_from_doc_zh.lua | 928 |
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 | } |
23 | local map | ||
24 | map = 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 | ||
33 | end | ||
34 | local filter | ||
35 | filter = 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 | ||
46 | end | ||
47 | local reduce | ||
48 | reduce = 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 | ||
54 | end | ||
23 | print(reduce(filter(map({ | 55 | print(reduce(filter(map({ |
24 | 1, | 56 | 1, |
25 | 2, | 57 | 2, |
@@ -77,6 +109,12 @@ end | |||
77 | print("yuescript") | 109 | print("yuescript") |
78 | print(3) | 110 | print(3) |
79 | print("有效的枚举类型:", "Static") | 111 | print("有效的枚举类型:", "Static") |
112 | do | ||
113 | print(123, "hello") | ||
114 | end | ||
115 | do | ||
116 | print(123, "hello") | ||
117 | end | ||
80 | if tb ~= nil then | 118 | if tb ~= nil then |
81 | tb:func() | 119 | tb:func() |
82 | end | 120 | end |
@@ -177,6 +215,16 @@ for _key_0, _value_0 in pairs(b) do | |||
177 | end | 215 | end |
178 | end | 216 | end |
179 | merge = _tab_0 | 217 | merge = _tab_0 |
218 | local last | ||
219 | do | ||
220 | local _item_0 = data.items | ||
221 | last = _item_0[#_item_0] | ||
222 | end | ||
223 | local second_last | ||
224 | do | ||
225 | local _item_0 = data.items | ||
226 | second_last = _item_0[#_item_0 - 1] | ||
227 | end | ||
180 | local mt = { } | 228 | local mt = { } |
181 | local add | 229 | local add |
182 | add = function(self, right) | 230 | add = function(self, right) |
@@ -307,6 +355,14 @@ func({ | |||
307 | 2, | 355 | 2, |
308 | 3 | 356 | 3 |
309 | }) | 357 | }) |
358 | local f | ||
359 | f = function() | ||
360 | return { | ||
361 | 1, | ||
362 | 2, | ||
363 | 3 | ||
364 | } | ||
365 | end | ||
310 | local tb = { | 366 | local tb = { |
311 | name = "abc", | 367 | name = "abc", |
312 | values = { | 368 | values = { |
@@ -547,6 +603,59 @@ end | |||
547 | local two, four | 603 | local two, four |
548 | local _obj_0 = items | 604 | local _obj_0 = items |
549 | two, four = _obj_0[2], _obj_0[4] | 605 | two, four = _obj_0[2], _obj_0[4] |
606 | local orders = { | ||
607 | "first", | ||
608 | "second", | ||
609 | "third", | ||
610 | "fourth", | ||
611 | "last" | ||
612 | } | ||
613 | local 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 | ||
623 | end)(), orders[#orders] | ||
624 | print(first) | ||
625 | print(bulk) | ||
626 | print(last) | ||
627 | local first, rest | ||
628 | do | ||
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)() | ||
641 | end | ||
642 | local start, last | ||
643 | do | ||
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] | ||
656 | end | ||
657 | local _obj_0 = orders | ||
658 | first, last = _obj_0[1], _obj_0[#_obj_0] | ||
550 | local tuples = { | 659 | local tuples = { |
551 | { | 660 | { |
552 | "hello", | 661 | "hello", |
@@ -648,6 +757,56 @@ end) | |||
648 | if success then | 757 | if success then |
649 | print(result) | 758 | print(result) |
650 | end | 759 | end |
760 | local a, b, c | ||
761 | do | ||
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 | ||
768 | end | ||
769 | do | ||
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 | ||
785 | end | ||
786 | f((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)) | ||
795 | end)()) | ||
796 | f((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)) | ||
809 | end)()) | ||
651 | local a <const> = 123 | 810 | local a <const> = 123 |
652 | local _ <close> = setmetatable({ }, { | 811 | local _ <close> = setmetatable({ }, { |
653 | __close = function() | 812 | __close = function() |
@@ -657,10 +816,19 @@ local _ <close> = setmetatable({ }, { | |||
657 | local a, b, c, d | 816 | local a, b, c, d |
658 | local _obj_0 = tb | 817 | local _obj_0 = tb |
659 | a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] | 818 | a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] |
819 | Constant = 123 | ||
660 | local some_string = "这是一个字符串\n 并包括一个换行。" | 820 | local some_string = "这是一个字符串\n 并包括一个换行。" |
661 | print("我有" .. tostring(math.random() * 100) .. "%的把握。") | 821 | print("我有" .. tostring(math.random() * 100) .. "%的把握。") |
662 | local integer = 1000000 | 822 | local integer = 1000000 |
663 | local hex = 0xEFBBBF | 823 | local hex = 0xEFBBBF |
824 | local binary = 19 | ||
825 | local str = "key: value\nlist:\n - item1\n - " .. tostring(expr) | ||
826 | local fn | ||
827 | fn = function() | ||
828 | local str = "foo:\n bar: baz" | ||
829 | return str | ||
830 | end | ||
831 | local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'" | ||
664 | local my_function | 832 | local my_function |
665 | my_function = function() end | 833 | my_function = function() end |
666 | my_function() | 834 | my_function() |
@@ -749,6 +917,36 @@ if func(1, 2, 3, "你好", "世界") then | |||
749 | print("hello") | 917 | print("hello") |
750 | print("我在if内部") | 918 | print("我在if内部") |
751 | end | 919 | end |
920 | local f1 | ||
921 | f1 = 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) | ||
925 | end | ||
926 | f1({ | ||
927 | a = 1, | ||
928 | b = "2", | ||
929 | c = { } | ||
930 | }) | ||
931 | local f2 | ||
932 | f2 = 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) | ||
945 | end | ||
946 | local arg1 = { | ||
947 | a = 0 | ||
948 | } | ||
949 | f2(arg1, arg2) | ||
752 | f(function() | 950 | f(function() |
753 | return print("hello") | 951 | return print("hello") |
754 | end) | 952 | end) |
@@ -964,8 +1162,7 @@ local slice | |||
964 | local _accum_0 = { } | 1162 | local _accum_0 = { } |
965 | local _len_0 = 1 | 1163 | local _len_0 = 1 |
966 | local _list_0 = items | 1164 | local _list_0 = items |
967 | local _max_0 = 5 | 1165 | for _index_0 = 1, 5 do |
968 | for _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 | |||
975 | local _accum_0 = { } | 1172 | local _accum_0 = { } |
976 | local _len_0 = 1 | 1173 | local _len_0 = 1 |
977 | local _list_0 = items | 1174 | local _list_0 = items |
978 | for _index_0 = 2, #_list_0 do | 1175 | local _max_0 = #_list_0 |
1176 | for _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 | |||
985 | local _accum_0 = { } | 1183 | local _accum_0 = { } |
986 | local _len_0 = 1 | 1184 | local _len_0 = 1 |
987 | local _list_0 = items | 1185 | local _list_0 = items |
988 | for _index_0 = 1, #_list_0, 2 do | 1186 | local _max_0 = #_list_0 |
1187 | for _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 |
992 | end | 1191 | end |
993 | slice = _accum_0 | 1192 | slice = _accum_0 |
1193 | local slice | ||
1194 | local _accum_0 = { } | ||
1195 | local _len_0 = 1 | ||
1196 | local _list_0 = items | ||
1197 | local _min_0 = #_list_0 + -4 + 1 | ||
1198 | local _max_0 = #_list_0 + -1 + 1 | ||
1199 | for _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 | ||
1203 | end | ||
1204 | slice = _accum_0 | ||
1205 | local reverse_slice | ||
1206 | local _accum_0 = { } | ||
1207 | local _len_0 = 1 | ||
1208 | local _list_0 = items | ||
1209 | local _min_0 = #_list_0 + -1 + 1 | ||
1210 | for _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 | ||
1214 | end | ||
1215 | reverse_slice = _accum_0 | ||
1216 | local sub_list | ||
1217 | local _accum_0 = { } | ||
1218 | local _len_0 = 1 | ||
1219 | local _list_0 = items | ||
1220 | for _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 | ||
1224 | end | ||
1225 | sub_list = _accum_0 | ||
994 | for i = 10, 20 do | 1226 | for i = 10, 20 do |
995 | print(i) | 1227 | print(i) |
996 | end | 1228 | end |
@@ -1001,8 +1233,7 @@ for key, value in pairs(object) do | |||
1001 | print(key, value) | 1233 | print(key, value) |
1002 | end | 1234 | end |
1003 | local _list_0 = items | 1235 | local _list_0 = items |
1004 | local _max_0 = 4 | 1236 | for _index_0 = 2, 4 do |
1005 | for _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) |
1008 | end | 1239 | end |
@@ -1020,12 +1251,24 @@ local _len_0 = 1 | |||
1020 | for i = 1, 20 do | 1251 | for 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 | ||
1027 | end | 1259 | end |
1028 | doubled_evens = _accum_0 | 1260 | doubled_evens = _accum_0 |
1261 | local first_large | ||
1262 | local _accum_0 | ||
1263 | local _list_0 = numbers | ||
1264 | for _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 | ||
1270 | end | ||
1271 | first_large = _accum_0 | ||
1029 | local func_a | 1272 | local func_a |
1030 | func_a = function() | 1273 | func_a = function() |
1031 | for i = 1, 10 do | 1274 | for i = 1, 10 do |
@@ -1174,7 +1417,7 @@ if "Robert" == name then | |||
1174 | elseif "Dan" == name or "Daniel" == name then | 1417 | elseif "Dan" == name or "Daniel" == name then |
1175 | print("你的名字是Dan") | 1418 | print("你的名字是Dan") |
1176 | else | 1419 | else |
1177 | print("我不知道你的名字") | 1420 | print("我不认识你,你的名字是" .. tostring(name)) |
1178 | end | 1421 | end |
1179 | local b = 1 | 1422 | local b = 1 |
1180 | local next_number | 1423 | local 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)) |
1276 | end | 1519 | end |
1520 | local _exp_0 = tb | ||
1521 | local _type_0 = type(_exp_0) | ||
1522 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
1523 | local _match_0 = false | ||
1524 | if _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 | ||
1529 | end | ||
1530 | if 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 | ||
1550 | end | ||
1551 | local _exp_0 = tb | ||
1552 | local _type_0 = type(_exp_0) | ||
1553 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
1554 | local _match_0 = false | ||
1555 | if _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 | ||
1561 | end | ||
1562 | if 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 | ||
1573 | end | ||
1574 | local _exp_0 = tb | ||
1575 | local _type_0 = type(_exp_0) | ||
1576 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
1577 | local _match_0 = false | ||
1578 | if _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 | ||
1598 | end | ||
1599 | if 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 | ||
1625 | end | ||
1626 | local _exp_0 = tb | ||
1627 | local _type_0 = type(_exp_0) | ||
1628 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
1629 | if _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 | ||
1676 | end | ||
1677 | local segments = { | ||
1678 | "admin", | ||
1679 | "users", | ||
1680 | "logs", | ||
1681 | "view" | ||
1682 | } | ||
1683 | local _type_0 = type(segments) | ||
1684 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
1685 | if _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 | ||
1705 | end | ||
1277 | local Inventory | 1706 | local Inventory |
1278 | local _class_0 | 1707 | local _class_0 |
1279 | local _base_0 = { | 1708 | local _base_0 = { |
@@ -1930,6 +2359,10 @@ do | |||
1930 | _with_1["key-name"] = value | 2359 | _with_1["key-name"] = value |
1931 | end | 2360 | end |
1932 | _with_0[#_with_0 + 1] = "abc" | 2361 | _with_0[#_with_0 + 1] = "abc" |
2362 | local _with_0 = obj | ||
2363 | if _with_0 ~= nil then | ||
2364 | print(obj.name) | ||
2365 | end | ||
1933 | do | 2366 | do |
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 | } |
2456 | local map | ||
2457 | map = 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 | ||
2466 | end | ||
2467 | local filter | ||
2468 | filter = 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 | ||
2479 | end | ||
2480 | local reduce | ||
2481 | reduce = 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 | ||
2487 | end | ||
2023 | print(reduce(filter(map({ | 2488 | print(reduce(filter(map({ |
2024 | 1, | 2489 | 1, |
2025 | 2, | 2490 | 2, |
@@ -2077,6 +2542,12 @@ end | |||
2077 | print("yuescript") | 2542 | print("yuescript") |
2078 | print(3) | 2543 | print(3) |
2079 | print("有效的枚举类型:", "Static") | 2544 | print("有效的枚举类型:", "Static") |
2545 | do | ||
2546 | print(123, "hello") | ||
2547 | end | ||
2548 | do | ||
2549 | print(123, "hello") | ||
2550 | end | ||
2080 | if tb ~= nil then | 2551 | if tb ~= nil then |
2081 | tb:func() | 2552 | tb:func() |
2082 | end | 2553 | end |
@@ -2177,6 +2648,16 @@ for _key_0, _value_0 in pairs(b) do | |||
2177 | end | 2648 | end |
2178 | end | 2649 | end |
2179 | merge = _tab_0 | 2650 | merge = _tab_0 |
2651 | local last | ||
2652 | do | ||
2653 | local _item_0 = data.items | ||
2654 | last = _item_0[#_item_0] | ||
2655 | end | ||
2656 | local second_last | ||
2657 | do | ||
2658 | local _item_0 = data.items | ||
2659 | second_last = _item_0[#_item_0 - 1] | ||
2660 | end | ||
2180 | local mt = { } | 2661 | local mt = { } |
2181 | local add | 2662 | local add |
2182 | add = function(self, right) | 2663 | add = function(self, right) |
@@ -2307,6 +2788,14 @@ func({ | |||
2307 | 2, | 2788 | 2, |
2308 | 3 | 2789 | 3 |
2309 | }) | 2790 | }) |
2791 | local f | ||
2792 | f = function() | ||
2793 | return { | ||
2794 | 1, | ||
2795 | 2, | ||
2796 | 3 | ||
2797 | } | ||
2798 | end | ||
2310 | local tb = { | 2799 | local tb = { |
2311 | name = "abc", | 2800 | name = "abc", |
2312 | values = { | 2801 | values = { |
@@ -2547,6 +3036,59 @@ end | |||
2547 | local two, four | 3036 | local two, four |
2548 | local _obj_0 = items | 3037 | local _obj_0 = items |
2549 | two, four = _obj_0[2], _obj_0[4] | 3038 | two, four = _obj_0[2], _obj_0[4] |
3039 | local orders = { | ||
3040 | "first", | ||
3041 | "second", | ||
3042 | "third", | ||
3043 | "fourth", | ||
3044 | "last" | ||
3045 | } | ||
3046 | local 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 | ||
3056 | end)(), orders[#orders] | ||
3057 | print(first) | ||
3058 | print(bulk) | ||
3059 | print(last) | ||
3060 | local first, rest | ||
3061 | do | ||
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)() | ||
3074 | end | ||
3075 | local start, last | ||
3076 | do | ||
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] | ||
3089 | end | ||
3090 | local _obj_0 = orders | ||
3091 | first, last = _obj_0[1], _obj_0[#_obj_0] | ||
2550 | local tuples = { | 3092 | local tuples = { |
2551 | { | 3093 | { |
2552 | "hello", | 3094 | "hello", |
@@ -2648,6 +3190,56 @@ end) | |||
2648 | if success then | 3190 | if success then |
2649 | print(result) | 3191 | print(result) |
2650 | end | 3192 | end |
3193 | local a, b, c | ||
3194 | do | ||
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 | ||
3201 | end | ||
3202 | do | ||
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 | ||
3218 | end | ||
3219 | f((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)) | ||
3228 | end)()) | ||
3229 | f((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)) | ||
3242 | end)()) | ||
2651 | local a <const> = 123 | 3243 | local a <const> = 123 |
2652 | local _ <close> = setmetatable({ }, { | 3244 | local _ <close> = setmetatable({ }, { |
2653 | __close = function() | 3245 | __close = function() |
@@ -2657,10 +3249,19 @@ local _ <close> = setmetatable({ }, { | |||
2657 | local a, b, c, d | 3249 | local a, b, c, d |
2658 | local _obj_0 = tb | 3250 | local _obj_0 = tb |
2659 | a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] | 3251 | a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] |
3252 | Constant = 123 | ||
2660 | local some_string = "这是一个字符串\n 并包括一个换行。" | 3253 | local some_string = "这是一个字符串\n 并包括一个换行。" |
2661 | print("我有" .. tostring(math.random() * 100) .. "%的把握。") | 3254 | print("我有" .. tostring(math.random() * 100) .. "%的把握。") |
2662 | local integer = 1000000 | 3255 | local integer = 1000000 |
2663 | local hex = 0xEFBBBF | 3256 | local hex = 0xEFBBBF |
3257 | local binary = 19 | ||
3258 | local str = "key: value\nlist:\n - item1\n - " .. tostring(expr) | ||
3259 | local fn | ||
3260 | fn = function() | ||
3261 | local str = "foo:\n bar: baz" | ||
3262 | return str | ||
3263 | end | ||
3264 | local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'" | ||
2664 | local my_function | 3265 | local my_function |
2665 | my_function = function() end | 3266 | my_function = function() end |
2666 | my_function() | 3267 | my_function() |
@@ -2749,6 +3350,66 @@ if func(1, 2, 3, "你好", "世界") then | |||
2749 | print("你好") | 3350 | print("你好") |
2750 | print("我在if内部") | 3351 | print("我在if内部") |
2751 | end | 3352 | end |
3353 | local f1 | ||
3354 | f1 = 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) | ||
3358 | end | ||
3359 | f1({ | ||
3360 | a = 1, | ||
3361 | b = "2", | ||
3362 | c = { } | ||
3363 | }) | ||
3364 | local f2 | ||
3365 | f2 = 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) | ||
3378 | end | ||
3379 | local arg1 = { | ||
3380 | a = 0 | ||
3381 | } | ||
3382 | f2(arg1, arg2) | ||
3383 | local findFirstEven | ||
3384 | findFirstEven = 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 | ||
3397 | end | ||
3398 | local findFirstEven | ||
3399 | findFirstEven = 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 | ||
3412 | end | ||
2752 | f(function() | 3413 | f(function() |
2753 | return print("hello") | 3414 | return print("hello") |
2754 | end) | 3415 | end) |
@@ -2964,8 +3625,7 @@ local slice | |||
2964 | local _accum_0 = { } | 3625 | local _accum_0 = { } |
2965 | local _len_0 = 1 | 3626 | local _len_0 = 1 |
2966 | local _list_0 = items | 3627 | local _list_0 = items |
2967 | local _max_0 = 5 | 3628 | for _index_0 = 1, 5 do |
2968 | for _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 | |||
2975 | local _accum_0 = { } | 3635 | local _accum_0 = { } |
2976 | local _len_0 = 1 | 3636 | local _len_0 = 1 |
2977 | local _list_0 = items | 3637 | local _list_0 = items |
2978 | for _index_0 = 2, #_list_0 do | 3638 | local _max_0 = #_list_0 |
3639 | for _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 | |||
2985 | local _accum_0 = { } | 3646 | local _accum_0 = { } |
2986 | local _len_0 = 1 | 3647 | local _len_0 = 1 |
2987 | local _list_0 = items | 3648 | local _list_0 = items |
2988 | for _index_0 = 1, #_list_0, 2 do | 3649 | local _max_0 = #_list_0 |
3650 | for _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 |
2992 | end | 3654 | end |
2993 | slice = _accum_0 | 3655 | slice = _accum_0 |
3656 | local slice | ||
3657 | local _accum_0 = { } | ||
3658 | local _len_0 = 1 | ||
3659 | local _list_0 = items | ||
3660 | local _min_0 = #_list_0 + -4 + 1 | ||
3661 | local _max_0 = #_list_0 + -1 + 1 | ||
3662 | for _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 | ||
3666 | end | ||
3667 | slice = _accum_0 | ||
3668 | local reverse_slice | ||
3669 | local _accum_0 = { } | ||
3670 | local _len_0 = 1 | ||
3671 | local _list_0 = items | ||
3672 | local _min_0 = #_list_0 + -1 + 1 | ||
3673 | for _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 | ||
3677 | end | ||
3678 | reverse_slice = _accum_0 | ||
3679 | local sub_list | ||
3680 | local _accum_0 = { } | ||
3681 | local _len_0 = 1 | ||
3682 | local _list_0 = items | ||
3683 | for _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 | ||
3687 | end | ||
3688 | sub_list = _accum_0 | ||
2994 | for i = 10, 20 do | 3689 | for i = 10, 20 do |
2995 | print(i) | 3690 | print(i) |
2996 | end | 3691 | end |
@@ -3001,8 +3696,7 @@ for key, value in pairs(object) do | |||
3001 | print(key, value) | 3696 | print(key, value) |
3002 | end | 3697 | end |
3003 | local _list_0 = items | 3698 | local _list_0 = items |
3004 | local _max_0 = 4 | 3699 | for _index_0 = 2, 4 do |
3005 | for _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) |
3008 | end | 3702 | end |
@@ -3020,12 +3714,24 @@ local _len_0 = 1 | |||
3020 | for i = 1, 20 do | 3714 | for 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 | ||
3027 | end | 3722 | end |
3028 | doubled_evens = _accum_0 | 3723 | doubled_evens = _accum_0 |
3724 | local first_large | ||
3725 | local _accum_0 | ||
3726 | local _list_0 = numbers | ||
3727 | for _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 | ||
3733 | end | ||
3734 | first_large = _accum_0 | ||
3029 | local func_a | 3735 | local func_a |
3030 | func_a = function() | 3736 | func_a = function() |
3031 | for i = 1, 10 do | 3737 | for i = 1, 10 do |
@@ -3174,7 +3880,7 @@ if "Robert" == name then | |||
3174 | elseif "Dan" == name or "Daniel" == name then | 3880 | elseif "Dan" == name or "Daniel" == name then |
3175 | print("你的名字是Dan") | 3881 | print("你的名字是Dan") |
3176 | else | 3882 | else |
3177 | print("我不知道你的名字") | 3883 | print("我不认识你,你的名字是" .. tostring(name)) |
3178 | end | 3884 | end |
3179 | local b = 1 | 3885 | local b = 1 |
3180 | local next_number | 3886 | local 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)) |
3276 | end | 3982 | end |
3983 | local _exp_0 = tb | ||
3984 | local _type_0 = type(_exp_0) | ||
3985 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
3986 | local _match_0 = false | ||
3987 | if _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 | ||
3992 | end | ||
3993 | if 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 | ||
4013 | end | ||
4014 | local _exp_0 = tb | ||
4015 | local _type_0 = type(_exp_0) | ||
4016 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
4017 | local _match_0 = false | ||
4018 | if _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 | ||
4024 | end | ||
4025 | if 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 | ||
4036 | end | ||
4037 | local _exp_0 = tb | ||
4038 | local _type_0 = type(_exp_0) | ||
4039 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
4040 | local _match_0 = false | ||
4041 | if _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 | ||
4061 | end | ||
4062 | if 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 | ||
4088 | end | ||
4089 | local _exp_0 = tb | ||
4090 | local _type_0 = type(_exp_0) | ||
4091 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
4092 | if _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 | ||
4139 | end | ||
4140 | local segments = { | ||
4141 | "admin", | ||
4142 | "users", | ||
4143 | "logs", | ||
4144 | "view" | ||
4145 | } | ||
4146 | local _type_0 = type(segments) | ||
4147 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
4148 | if _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 | ||
4168 | end | ||
3277 | local Inventory | 4169 | local Inventory |
3278 | local _class_0 | 4170 | local _class_0 |
3279 | local _base_0 = { | 4171 | local _base_0 = { |
@@ -3930,6 +4822,10 @@ do | |||
3930 | _with_1["key-name"] = value | 4822 | _with_1["key-name"] = value |
3931 | end | 4823 | end |
3932 | _with_0[#_with_0 + 1] = "abc" | 4824 | _with_0[#_with_0 + 1] = "abc" |
4825 | local _with_0 = obj | ||
4826 | if _with_0 ~= nil then | ||
4827 | print(obj.name) | ||
4828 | end | ||
3933 | do | 4829 | do |
3934 | local var = "hello" | 4830 | local var = "hello" |
3935 | print(var) | 4831 | print(var) |