diff options
Diffstat (limited to 'spec/outputs')
42 files changed, 3994 insertions, 394 deletions
diff --git a/spec/outputs/5.1/attrib.lua b/spec/outputs/5.1/attrib.lua index dc1285c..bda24bc 100644 --- a/spec/outputs/5.1/attrib.lua +++ b/spec/outputs/5.1/attrib.lua | |||
@@ -5,12 +5,36 @@ do | |||
5 | return print("closed") | 5 | return print("closed") |
6 | end | 6 | end |
7 | }) | 7 | }) |
8 | local _close_0 = assert(getmetatable(a).__close) | 8 | local _close_0 |
9 | local _close_1 = assert(getmetatable(b).__close); | 9 | if (function() |
10 | local _val_0 = type(a) | ||
11 | return 'table' == _val_0 or 'userdata' == _val_0 | ||
12 | end)() then | ||
13 | _close_0 = assert(getmetatable(a) and getmetatable(a).__close, "variable 'a' got a non-closable value") | ||
14 | elseif a == nil then | ||
15 | _close_0 = nil | ||
16 | else | ||
17 | _close_0 = error("variable 'a' got a non-closable value") | ||
18 | end | ||
19 | local _close_1 | ||
20 | if (function() | ||
21 | local _val_0 = type(b) | ||
22 | return 'table' == _val_0 or 'userdata' == _val_0 | ||
23 | end)() then | ||
24 | _close_1 = assert(getmetatable(b) and getmetatable(b).__close, "variable 'b' got a non-closable value") | ||
25 | elseif b == nil then | ||
26 | _close_1 = nil | ||
27 | else | ||
28 | _close_1 = error("variable 'b' got a non-closable value") | ||
29 | end | ||
10 | (function(_arg_0, ...) | 30 | (function(_arg_0, ...) |
11 | local _ok_0 = _arg_0 | 31 | local _ok_0 = _arg_0 |
12 | _close_1(b) | 32 | if _close_1 ~= nil then |
13 | _close_0(a) | 33 | _close_1(b) |
34 | end | ||
35 | if _close_0 ~= nil then | ||
36 | _close_0(a) | ||
37 | end | ||
14 | if _ok_0 then | 38 | if _ok_0 then |
15 | return ... | 39 | return ... |
16 | else | 40 | else |
@@ -53,10 +77,22 @@ do | |||
53 | __close = function(self) end | 77 | __close = function(self) end |
54 | }) | 78 | }) |
55 | end | 79 | end |
56 | local _close_0 = assert(getmetatable(v).__close); | 80 | local _close_0 |
81 | if (function() | ||
82 | local _val_0 = type(v) | ||
83 | return 'table' == _val_0 or 'userdata' == _val_0 | ||
84 | end)() then | ||
85 | _close_0 = assert(getmetatable(v) and getmetatable(v).__close, "variable 'v' got a non-closable value") | ||
86 | elseif v == nil then | ||
87 | _close_0 = nil | ||
88 | else | ||
89 | _close_0 = error("variable 'v' got a non-closable value") | ||
90 | end | ||
57 | (function(_arg_0, ...) | 91 | (function(_arg_0, ...) |
58 | local _ok_0 = _arg_0 | 92 | local _ok_0 = _arg_0 |
59 | _close_0(v) | 93 | if _close_0 ~= nil then |
94 | _close_0(v) | ||
95 | end | ||
60 | if _ok_0 then | 96 | if _ok_0 then |
61 | return ... | 97 | return ... |
62 | else | 98 | else |
@@ -69,10 +105,22 @@ do | |||
69 | _with_0:write("Hello") | 105 | _with_0:write("Hello") |
70 | f = _with_0 | 106 | f = _with_0 |
71 | end | 107 | end |
72 | local _close_1 = assert(getmetatable(f).__close) | 108 | local _close_1 |
109 | if (function() | ||
110 | local _val_0 = type(f) | ||
111 | return 'table' == _val_0 or 'userdata' == _val_0 | ||
112 | end)() then | ||
113 | _close_1 = assert(getmetatable(f) and getmetatable(f).__close, "variable 'f' got a non-closable value") | ||
114 | elseif f == nil then | ||
115 | _close_1 = nil | ||
116 | else | ||
117 | _close_1 = error("variable 'f' got a non-closable value") | ||
118 | end | ||
73 | return (function(_arg_0, ...) | 119 | return (function(_arg_0, ...) |
74 | local _ok_0 = _arg_0 | 120 | local _ok_0 = _arg_0 |
75 | _close_1(f) | 121 | if _close_1 ~= nil then |
122 | _close_1(f) | ||
123 | end | ||
76 | if _ok_0 then | 124 | if _ok_0 then |
77 | return ... | 125 | return ... |
78 | else | 126 | else |
@@ -88,14 +136,28 @@ do | |||
88 | end | 136 | end |
89 | local b | 137 | local b |
90 | if not false then | 138 | if not false then |
91 | if x then | 139 | b = ((function() |
92 | b = 1 | 140 | if x then |
93 | end | 141 | return 1 |
142 | end | ||
143 | end)()) | ||
144 | end | ||
145 | local _close_0 | ||
146 | if (function() | ||
147 | local _val_0 = type(b) | ||
148 | return 'table' == _val_0 or 'userdata' == _val_0 | ||
149 | end)() then | ||
150 | _close_0 = assert(getmetatable(b) and getmetatable(b).__close, "variable 'b' got a non-closable value") | ||
151 | elseif b == nil then | ||
152 | _close_0 = nil | ||
153 | else | ||
154 | _close_0 = error("variable 'b' got a non-closable value") | ||
94 | end | 155 | end |
95 | local _close_0 = assert(getmetatable(b).__close); | ||
96 | (function(_arg_0, ...) | 156 | (function(_arg_0, ...) |
97 | local _ok_0 = _arg_0 | 157 | local _ok_0 = _arg_0 |
98 | _close_0(b) | 158 | if _close_0 ~= nil then |
159 | _close_0(b) | ||
160 | end | ||
99 | if _ok_0 then | 161 | if _ok_0 then |
100 | return ... | 162 | return ... |
101 | else | 163 | else |
@@ -104,10 +166,12 @@ do | |||
104 | end)(pcall(function() | 166 | end)(pcall(function() |
105 | local c | 167 | local c |
106 | if true then | 168 | if true then |
107 | local _exp_0 = x | 169 | c = ((function() |
108 | if "abc" == _exp_0 then | 170 | local _exp_0 = x |
109 | c = 998 | 171 | if "abc" == _exp_0 then |
110 | end | 172 | return 998 |
173 | end | ||
174 | end)()) | ||
111 | end | 175 | end |
112 | local d | 176 | local d |
113 | if (function() | 177 | if (function() |
@@ -121,10 +185,22 @@ do | |||
121 | value = value | 185 | value = value |
122 | } | 186 | } |
123 | end | 187 | end |
124 | local _close_1 = assert(getmetatable(d).__close) | 188 | local _close_1 |
189 | if (function() | ||
190 | local _val_0 = type(d) | ||
191 | return 'table' == _val_0 or 'userdata' == _val_0 | ||
192 | end)() then | ||
193 | _close_1 = assert(getmetatable(d) and getmetatable(d).__close, "variable 'd' got a non-closable value") | ||
194 | elseif d == nil then | ||
195 | _close_1 = nil | ||
196 | else | ||
197 | _close_1 = error("variable 'd' got a non-closable value") | ||
198 | end | ||
125 | return (function(_arg_0, ...) | 199 | return (function(_arg_0, ...) |
126 | local _ok_0 = _arg_0 | 200 | local _ok_0 = _arg_0 |
127 | _close_1(d) | 201 | if _close_1 ~= nil then |
202 | _close_1(d) | ||
203 | end | ||
128 | if _ok_0 then | 204 | if _ok_0 then |
129 | return ... | 205 | return ... |
130 | else | 206 | else |
@@ -140,10 +216,22 @@ do | |||
140 | _with_0:write("Hello") | 216 | _with_0:write("Hello") |
141 | _ = _with_0 | 217 | _ = _with_0 |
142 | end | 218 | end |
143 | local _close_0 = assert(getmetatable(_).__close); | 219 | local _close_0 |
220 | if (function() | ||
221 | local _val_0 = type(_) | ||
222 | return 'table' == _val_0 or 'userdata' == _val_0 | ||
223 | end)() then | ||
224 | _close_0 = assert(getmetatable(_) and getmetatable(_).__close, "variable '_' got a non-closable value") | ||
225 | elseif _ == nil then | ||
226 | _close_0 = nil | ||
227 | else | ||
228 | _close_0 = error("variable '_' got a non-closable value") | ||
229 | end | ||
144 | (function(_arg_0, ...) | 230 | (function(_arg_0, ...) |
145 | local _ok_0 = _arg_0 | 231 | local _ok_0 = _arg_0 |
146 | _close_0(_) | 232 | if _close_0 ~= nil then |
233 | _close_0(_) | ||
234 | end | ||
147 | if _ok_0 then | 235 | if _ok_0 then |
148 | return ... | 236 | return ... |
149 | else | 237 | else |
@@ -155,10 +243,22 @@ do | |||
155 | return print("second") | 243 | return print("second") |
156 | end | 244 | end |
157 | }) | 245 | }) |
158 | local _close_1 = assert(getmetatable(_).__close) | 246 | local _close_1 |
247 | if (function() | ||
248 | local _val_0 = type(_) | ||
249 | return 'table' == _val_0 or 'userdata' == _val_0 | ||
250 | end)() then | ||
251 | _close_1 = assert(getmetatable(_) and getmetatable(_).__close, "variable '_' got a non-closable value") | ||
252 | elseif _ == nil then | ||
253 | _close_1 = nil | ||
254 | else | ||
255 | _close_1 = error("variable '_' got a non-closable value") | ||
256 | end | ||
159 | return (function(_arg_0, ...) | 257 | return (function(_arg_0, ...) |
160 | local _ok_0 = _arg_0 | 258 | local _ok_0 = _arg_0 |
161 | _close_1(_) | 259 | if _close_1 ~= nil then |
260 | _close_1(_) | ||
261 | end | ||
162 | if _ok_0 then | 262 | if _ok_0 then |
163 | return ... | 263 | return ... |
164 | else | 264 | else |
@@ -170,10 +270,22 @@ do | |||
170 | return print("first") | 270 | return print("first") |
171 | end | 271 | end |
172 | }) | 272 | }) |
173 | local _close_2 = assert(getmetatable(_).__close) | 273 | local _close_2 |
274 | if (function() | ||
275 | local _val_0 = type(_) | ||
276 | return 'table' == _val_0 or 'userdata' == _val_0 | ||
277 | end)() then | ||
278 | _close_2 = assert(getmetatable(_) and getmetatable(_).__close, "variable '_' got a non-closable value") | ||
279 | elseif _ == nil then | ||
280 | _close_2 = nil | ||
281 | else | ||
282 | _close_2 = error("variable '_' got a non-closable value") | ||
283 | end | ||
174 | return (function(_arg_0, ...) | 284 | return (function(_arg_0, ...) |
175 | local _ok_0 = _arg_0 | 285 | local _ok_0 = _arg_0 |
176 | _close_2(_) | 286 | if _close_2 ~= nil then |
287 | _close_2(_) | ||
288 | end | ||
177 | if _ok_0 then | 289 | if _ok_0 then |
178 | return ... | 290 | return ... |
179 | else | 291 | else |
@@ -200,10 +312,22 @@ do | |||
200 | local _ = def(function() | 312 | local _ = def(function() |
201 | return print(3) | 313 | return print(3) |
202 | end) | 314 | end) |
203 | local _close_0 = assert(getmetatable(_).__close) | 315 | local _close_0 |
316 | if (function() | ||
317 | local _val_0 = type(_) | ||
318 | return 'table' == _val_0 or 'userdata' == _val_0 | ||
319 | end)() then | ||
320 | _close_0 = assert(getmetatable(_) and getmetatable(_).__close, "variable '_' got a non-closable value") | ||
321 | elseif _ == nil then | ||
322 | _close_0 = nil | ||
323 | else | ||
324 | _close_0 = error("variable '_' got a non-closable value") | ||
325 | end | ||
204 | return (function(_arg_0, ...) | 326 | return (function(_arg_0, ...) |
205 | local _ok_0 = _arg_0 | 327 | local _ok_0 = _arg_0 |
206 | _close_0(_) | 328 | if _close_0 ~= nil then |
329 | _close_0(_) | ||
330 | end | ||
207 | if _ok_0 then | 331 | if _ok_0 then |
208 | return ... | 332 | return ... |
209 | else | 333 | else |
@@ -213,10 +337,22 @@ do | |||
213 | local _ = def(function() | 337 | local _ = def(function() |
214 | return print(2) | 338 | return print(2) |
215 | end) | 339 | end) |
216 | local _close_1 = assert(getmetatable(_).__close) | 340 | local _close_1 |
341 | if (function() | ||
342 | local _val_0 = type(_) | ||
343 | return 'table' == _val_0 or 'userdata' == _val_0 | ||
344 | end)() then | ||
345 | _close_1 = assert(getmetatable(_) and getmetatable(_).__close, "variable '_' got a non-closable value") | ||
346 | elseif _ == nil then | ||
347 | _close_1 = nil | ||
348 | else | ||
349 | _close_1 = error("variable '_' got a non-closable value") | ||
350 | end | ||
217 | return (function(_arg_0, ...) | 351 | return (function(_arg_0, ...) |
218 | local _ok_0 = _arg_0 | 352 | local _ok_0 = _arg_0 |
219 | _close_1(_) | 353 | if _close_1 ~= nil then |
354 | _close_1(_) | ||
355 | end | ||
220 | if _ok_0 then | 356 | if _ok_0 then |
221 | return ... | 357 | return ... |
222 | else | 358 | else |
@@ -226,10 +362,22 @@ do | |||
226 | local _ = def(function() | 362 | local _ = def(function() |
227 | return print(1) | 363 | return print(1) |
228 | end) | 364 | end) |
229 | local _close_2 = assert(getmetatable(_).__close) | 365 | local _close_2 |
366 | if (function() | ||
367 | local _val_0 = type(_) | ||
368 | return 'table' == _val_0 or 'userdata' == _val_0 | ||
369 | end)() then | ||
370 | _close_2 = assert(getmetatable(_) and getmetatable(_).__close, "variable '_' got a non-closable value") | ||
371 | elseif _ == nil then | ||
372 | _close_2 = nil | ||
373 | else | ||
374 | _close_2 = error("variable '_' got a non-closable value") | ||
375 | end | ||
230 | return (function(_arg_0, ...) | 376 | return (function(_arg_0, ...) |
231 | local _ok_0 = _arg_0 | 377 | local _ok_0 = _arg_0 |
232 | _close_2(_) | 378 | if _close_2 ~= nil then |
379 | _close_2(_) | ||
380 | end | ||
233 | if _ok_0 then | 381 | if _ok_0 then |
234 | return ... | 382 | return ... |
235 | else | 383 | else |
diff --git a/spec/outputs/5.1/loops.lua b/spec/outputs/5.1/loops.lua index 57b19be..e4f2871 100644 --- a/spec/outputs/5.1/loops.lua +++ b/spec/outputs/5.1/loops.lua | |||
@@ -60,8 +60,8 @@ do | |||
60 | local y = hello[_index_0] | 60 | local y = hello[_index_0] |
61 | if y % 2 == 0 then | 61 | if y % 2 == 0 then |
62 | _accum_0[_len_0] = y | 62 | _accum_0[_len_0] = y |
63 | _len_0 = _len_0 + 1 | ||
63 | end | 64 | end |
64 | _len_0 = _len_0 + 1 | ||
65 | end | 65 | end |
66 | x = _accum_0 | 66 | x = _accum_0 |
67 | end | 67 | end |
@@ -132,13 +132,11 @@ do | |||
132 | end | 132 | end |
133 | do | 133 | do |
134 | local _accum_0 = { } | 134 | local _accum_0 = { } |
135 | local _len_0 = 1 | ||
136 | local _list_2 = 3 | 135 | local _list_2 = 3 |
137 | for _index_0 = 1, #_list_2 do | 136 | for _index_0 = 1, #_list_2 do |
138 | local thing = _list_2[_index_0] | 137 | local thing = _list_2[_index_0] |
139 | y = "hello" | 138 | y = "hello" |
140 | break | 139 | break |
141 | _len_0 = _len_0 + 1 | ||
142 | end | 140 | end |
143 | x = _accum_0 | 141 | x = _accum_0 |
144 | end | 142 | end |
@@ -489,3 +487,131 @@ do | |||
489 | end | 487 | end |
490 | until false | 488 | until false |
491 | end | 489 | end |
490 | local _anon_func_0 = function(i, tb) | ||
491 | local _accum_0 = { } | ||
492 | local _len_0 = 1 | ||
493 | while tb[i] do | ||
494 | i = i + 1 | ||
495 | _accum_0[_len_0] = i - 1 | ||
496 | _len_0 = _len_0 + 1 | ||
497 | end | ||
498 | return _accum_0 | ||
499 | end | ||
500 | do | ||
501 | local index | ||
502 | do | ||
503 | local _accum_0 | ||
504 | for i = 1, #tb do | ||
505 | if tb[i] then | ||
506 | _accum_0 = i | ||
507 | break | ||
508 | end | ||
509 | end | ||
510 | index = _accum_0 | ||
511 | end | ||
512 | f((function() | ||
513 | local _accum_0 | ||
514 | for i = 1, #tb do | ||
515 | if tb[i] then | ||
516 | _accum_0 = i | ||
517 | break | ||
518 | end | ||
519 | end | ||
520 | return _accum_0 | ||
521 | end)()) | ||
522 | f((function() | ||
523 | local _accum_0 = { } | ||
524 | local _len_0 = 1 | ||
525 | for i = 1, #tb do | ||
526 | if tb[i] then | ||
527 | _accum_0[_len_0] = i | ||
528 | _len_0 = _len_0 + 1 | ||
529 | end | ||
530 | end | ||
531 | return _accum_0 | ||
532 | end)()) | ||
533 | i = 1 | ||
534 | local ids | ||
535 | do | ||
536 | local _accum_0 = { } | ||
537 | local _len_0 = 1 | ||
538 | while tb[i] do | ||
539 | i = i + 1 | ||
540 | _accum_0[_len_0] = i - 1 | ||
541 | _len_0 = _len_0 + 1 | ||
542 | end | ||
543 | ids = _accum_0 | ||
544 | end | ||
545 | i = 1 | ||
546 | local idx | ||
547 | do | ||
548 | local _accum_0 | ||
549 | while tb[i] do | ||
550 | i = i + 1 | ||
551 | _accum_0 = i - 1 | ||
552 | break | ||
553 | end | ||
554 | idx = _accum_0 | ||
555 | end | ||
556 | local f1 | ||
557 | f1 = function() | ||
558 | i = 1 | ||
559 | return f(_anon_func_0(i, tb)) | ||
560 | end | ||
561 | i = 1 | ||
562 | f((function() | ||
563 | local _accum_0 | ||
564 | while tb[i] do | ||
565 | i = i + 1 | ||
566 | _accum_0 = i - 1 | ||
567 | break | ||
568 | end | ||
569 | return _accum_0 | ||
570 | end)()) | ||
571 | local _accum_0 = { } | ||
572 | local _len_0 = 1 | ||
573 | local _list_3 = items | ||
574 | for _index_0 = 1, #_list_3 do | ||
575 | local item = _list_3[_index_0] | ||
576 | local _type_0 = type(item) | ||
577 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
578 | if _tab_0 then | ||
579 | local value = item.value | ||
580 | if "A" == item.type and value ~= nil then | ||
581 | if value > 5 then | ||
582 | _accum_0[_len_0] = item | ||
583 | _len_0 = _len_0 + 1 | ||
584 | end | ||
585 | end | ||
586 | end | ||
587 | end | ||
588 | list = _accum_0 | ||
589 | end | ||
590 | do | ||
591 | repeat | ||
592 | print(1) | ||
593 | until true | ||
594 | do | ||
595 | local _accum_0 | ||
596 | repeat | ||
597 | a = func() | ||
598 | _accum_0 = a.x | ||
599 | break | ||
600 | until a.v | ||
601 | x = _accum_0 | ||
602 | end | ||
603 | local items | ||
604 | local _accum_0 = { } | ||
605 | local _len_0 = 1 | ||
606 | repeat | ||
607 | local item = getItem() | ||
608 | if not item then | ||
609 | break | ||
610 | end | ||
611 | if item.value > 0 then | ||
612 | _accum_0[_len_0] = item | ||
613 | _len_0 = _len_0 + 1 | ||
614 | end | ||
615 | until false | ||
616 | items = _accum_0 | ||
617 | end | ||
diff --git a/spec/outputs/5.1/try_catch.lua b/spec/outputs/5.1/try_catch.lua index d4c80c1..d2b58bc 100644 --- a/spec/outputs/5.1/try_catch.lua +++ b/spec/outputs/5.1/try_catch.lua | |||
@@ -8,10 +8,10 @@ local _anon_func_2 = function(tb) | |||
8 | return tb.func() | 8 | return tb.func() |
9 | end | 9 | end |
10 | local _anon_func_3 = function(tb) | 10 | local _anon_func_3 = function(tb) |
11 | return tb.func() | 11 | return (tb.func()) |
12 | end | 12 | end |
13 | local _anon_func_4 = function(tb) | 13 | local _anon_func_4 = function(tb) |
14 | return tb:func(1, 2, 3) | 14 | return (tb:func(1, 2, 3)) |
15 | end | 15 | end |
16 | local _anon_func_5 = function(tb) | 16 | local _anon_func_5 = function(tb) |
17 | return tb.func(1) | 17 | return tb.func(1) |
@@ -22,6 +22,43 @@ end | |||
22 | local _anon_func_7 = function(a, b, c, tb) | 22 | local _anon_func_7 = function(a, b, c, tb) |
23 | return tb.f(a, b, c) | 23 | return tb.f(a, b, c) |
24 | end | 24 | end |
25 | local _anon_func_8 = function(_arg_0, ...) | ||
26 | local ok = _arg_0 | ||
27 | return ... | ||
28 | end | ||
29 | local _anon_func_10 = function(_arg_0, ...) | ||
30 | local _ok_0 = _arg_0 | ||
31 | if _ok_0 then | ||
32 | return ... | ||
33 | end | ||
34 | end | ||
35 | local _anon_func_9 = function(func, pcall) | ||
36 | return _anon_func_10(pcall(func)) | ||
37 | end | ||
38 | local _anon_func_12 = function(_arg_0, ...) | ||
39 | local _ok_0 = _arg_0 | ||
40 | if _ok_0 then | ||
41 | return ... | ||
42 | end | ||
43 | end | ||
44 | local _anon_func_11 = function(func, pcall) | ||
45 | return _anon_func_12(pcall(func)) | ||
46 | end | ||
47 | local _anon_func_14 = function(_arg_0, ...) | ||
48 | local _ok_0 = _arg_0 | ||
49 | if _ok_0 then | ||
50 | return ... | ||
51 | end | ||
52 | end | ||
53 | local _anon_func_13 = function(func, print, xpcall) | ||
54 | return _anon_func_14(xpcall(function() | ||
55 | print(123) | ||
56 | return func() | ||
57 | end, function(e) | ||
58 | print(e) | ||
59 | return e | ||
60 | end)) | ||
61 | end | ||
25 | local f | 62 | local f |
26 | f = function() | 63 | f = function() |
27 | xpcall(function() | 64 | xpcall(function() |
@@ -64,7 +101,7 @@ f = function() | |||
64 | print("OK") | 101 | print("OK") |
65 | end | 102 | end |
66 | if xpcall(function() | 103 | if xpcall(function() |
67 | return func(1) | 104 | return (func(1)) |
68 | end, function(err) | 105 | end, function(err) |
69 | return print(err) | 106 | return print(err) |
70 | end) then | 107 | end) then |
@@ -104,10 +141,236 @@ f = function() | |||
104 | do | 141 | do |
105 | x(function() | 142 | x(function() |
106 | local tb, a, b, c | 143 | local tb, a, b, c |
107 | f = function() | 144 | local f1 |
145 | f1 = function() | ||
108 | return pcall(_anon_func_7, a, b, c, tb) | 146 | return pcall(_anon_func_7, a, b, c, tb) |
109 | end | 147 | end |
110 | end) | 148 | end) |
111 | end | 149 | end |
150 | do | ||
151 | local f1 | ||
152 | f1 = function() | ||
153 | do | ||
154 | return _anon_func_8(pcall(function() | ||
155 | return func() | ||
156 | end)) | ||
157 | end | ||
158 | end | ||
159 | end | ||
160 | do | ||
161 | local func | ||
162 | local a, b, c | ||
163 | local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(func) | ||
164 | if _ok_0 then | ||
165 | a, b, c = _ret_0, _ret_1, _ret_2 | ||
166 | end | ||
167 | end | ||
168 | do | ||
169 | local a, b, c | ||
170 | local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function() | ||
171 | return func() | ||
172 | end) | ||
173 | if _ok_0 then | ||
174 | a, b, c = _ret_0, _ret_1, _ret_2 | ||
175 | end | ||
176 | end | ||
177 | do | ||
178 | local a | ||
179 | local _exp_0 = (_anon_func_9(func, pcall)) | ||
180 | if _exp_0 ~= nil then | ||
181 | a = _exp_0 | ||
182 | else | ||
183 | a = "default" | ||
184 | end | ||
185 | end | ||
186 | do | ||
187 | f(_anon_func_11(func, pcall)) | ||
188 | end | ||
189 | do | ||
190 | f(_anon_func_13(func, print, xpcall)) | ||
191 | end | ||
112 | return nil | 192 | return nil |
113 | end | 193 | end |
194 | local _anon_func_15 = function(a, b, c, tb) | ||
195 | return tb.f(a, b, c) | ||
196 | end | ||
197 | local _anon_func_16 = function(_arg_0, ...) | ||
198 | local ok = _arg_0 | ||
199 | return ... | ||
200 | end | ||
201 | do | ||
202 | xpcall(function() | ||
203 | return func(1, 2, 3) | ||
204 | end, function(err) | ||
205 | return print(err) | ||
206 | end) | ||
207 | xpcall(function() | ||
208 | return func(1, 2, 3) | ||
209 | end, function(err) | ||
210 | return print(err) | ||
211 | end) | ||
212 | pcall(function() | ||
213 | print("trying") | ||
214 | return func(1, 2, 3) | ||
215 | end) | ||
216 | do | ||
217 | local success, result = xpcall(function() | ||
218 | return func(1, 2, 3) | ||
219 | end, function(err) | ||
220 | return print(err) | ||
221 | end) | ||
222 | success, result = pcall(function() | ||
223 | return func(1, 2, 3) | ||
224 | end) | ||
225 | end | ||
226 | local tb = { } | ||
227 | pcall(function() | ||
228 | return tb.func | ||
229 | end) | ||
230 | pcall(function() | ||
231 | return tb.func() | ||
232 | end) | ||
233 | pcall(function() | ||
234 | return tb.func() | ||
235 | end) | ||
236 | pcall(function() | ||
237 | return (tb.func()) | ||
238 | end) | ||
239 | pcall(function() | ||
240 | return (tb:func(1, 2, 3)) | ||
241 | end) | ||
242 | pcall(function() | ||
243 | return tb.func(1) | ||
244 | end) | ||
245 | pcall(function() | ||
246 | return tb.func(1) | ||
247 | end) | ||
248 | if (xpcall(function() | ||
249 | return func(1) | ||
250 | end, function(err) | ||
251 | return print(err) | ||
252 | end)) then | ||
253 | print("OK") | ||
254 | end | ||
255 | if xpcall(function() | ||
256 | return (func(1)) | ||
257 | end, function(err) | ||
258 | return print(err) | ||
259 | end) then | ||
260 | print("OK") | ||
261 | end | ||
262 | do | ||
263 | do | ||
264 | local success, result = pcall(function() | ||
265 | return func("abc", 123) | ||
266 | end) | ||
267 | if success then | ||
268 | print(result) | ||
269 | end | ||
270 | end | ||
271 | local success, result = xpcall(function() | ||
272 | return func("abc", 123) | ||
273 | end, function(err) | ||
274 | return print(err) | ||
275 | end) | ||
276 | success, result = xpcall(function() | ||
277 | return func("abc", 123) | ||
278 | end, function(err) | ||
279 | return print(err) | ||
280 | end) | ||
281 | if success then | ||
282 | print(result) | ||
283 | end | ||
284 | end | ||
285 | do | ||
286 | pcall(function() | ||
287 | return func(1, 2, 3) | ||
288 | end) | ||
289 | pcall(function() | ||
290 | return func(1, 2, 3) | ||
291 | end) | ||
292 | end | ||
293 | do | ||
294 | x(function() | ||
295 | local tb, a, b, c | ||
296 | local f1 | ||
297 | f1 = function() | ||
298 | return pcall(_anon_func_15, a, b, c, tb) | ||
299 | end | ||
300 | end) | ||
301 | end | ||
302 | do | ||
303 | local f1 | ||
304 | f1 = function() | ||
305 | do | ||
306 | return _anon_func_16(pcall(function() | ||
307 | return func() | ||
308 | end)) | ||
309 | end | ||
310 | end | ||
311 | end | ||
312 | do | ||
313 | local func | ||
314 | local a, b, c | ||
315 | local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(func) | ||
316 | if _ok_0 then | ||
317 | a, b, c = _ret_0, _ret_1, _ret_2 | ||
318 | end | ||
319 | end | ||
320 | do | ||
321 | local a, b, c | ||
322 | local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function() | ||
323 | return func() | ||
324 | end) | ||
325 | if _ok_0 then | ||
326 | a, b, c = _ret_0, _ret_1, _ret_2 | ||
327 | end | ||
328 | end | ||
329 | do | ||
330 | local a | ||
331 | local _exp_0 = ((function() | ||
332 | return (function(_arg_0, ...) | ||
333 | local _ok_0 = _arg_0 | ||
334 | if _ok_0 then | ||
335 | return ... | ||
336 | end | ||
337 | end)(pcall(function() | ||
338 | return func() | ||
339 | end)) | ||
340 | end)()) | ||
341 | if _exp_0 ~= nil then | ||
342 | a = _exp_0 | ||
343 | else | ||
344 | a = "default" | ||
345 | end | ||
346 | end | ||
347 | do | ||
348 | f((function() | ||
349 | return (function(_arg_0, ...) | ||
350 | local _ok_0 = _arg_0 | ||
351 | if _ok_0 then | ||
352 | return ... | ||
353 | end | ||
354 | end)(pcall(function() | ||
355 | return func() | ||
356 | end)) | ||
357 | end)()) | ||
358 | end | ||
359 | do | ||
360 | f((function() | ||
361 | return (function(_arg_0, ...) | ||
362 | local _ok_0 = _arg_0 | ||
363 | if _ok_0 then | ||
364 | return ... | ||
365 | end | ||
366 | end)(xpcall(function() | ||
367 | print(123) | ||
368 | return func() | ||
369 | end, function(e) | ||
370 | print(e) | ||
371 | return e | ||
372 | end)) | ||
373 | end)()) | ||
374 | end | ||
375 | end | ||
376 | return nil | ||
diff --git a/spec/outputs/assign.lua b/spec/outputs/assign.lua index 162a563..89c5f8a 100644 --- a/spec/outputs/assign.lua +++ b/spec/outputs/assign.lua | |||
@@ -36,17 +36,15 @@ local x | |||
36 | do | 36 | do |
37 | local f = getHandler() | 37 | local f = getHandler() |
38 | if f then | 38 | if f then |
39 | do | 39 | x = ((function() |
40 | f() | 40 | f() |
41 | x = 123 | 41 | return 123 |
42 | end | 42 | end)()) |
43 | end | 43 | end |
44 | end | 44 | end |
45 | local _anon_func_0 = function(print) | 45 | local _anon_func_0 = function(print) |
46 | do | 46 | print(123) |
47 | print(123) | 47 | return { } |
48 | return { } | ||
49 | end | ||
50 | end | 48 | end |
51 | return _(function() | 49 | return _(function() |
52 | setmetatable(a, _anon_func_0(print)) | 50 | setmetatable(a, _anon_func_0(print)) |
@@ -181,5 +179,30 @@ return _(function() | |||
181 | local b = val | 179 | local b = val |
182 | local c = val | 180 | local c = val |
183 | end | 181 | end |
182 | do | ||
183 | local a = a .. "abc" | ||
184 | a = a // 2 | ||
185 | a = a or def | ||
186 | a = a and false | ||
187 | a = a >> 10 | ||
188 | a = a << 10 | ||
189 | local _obj_0 = a.b | ||
190 | if _obj_0.c == nil then | ||
191 | _obj_0.c = 123 | ||
192 | end | ||
193 | local _obj_1 = a.b | ||
194 | _obj_1.c = _obj_1.c + 1 | ||
195 | local _obj_2 = a.b | ||
196 | _obj_2.c = _obj_2.c - 2 | ||
197 | local _obj_3 = a.b | ||
198 | _obj_3.c = _obj_3.c * 3 | ||
199 | local _obj_4 = a.b | ||
200 | _obj_4.c = _obj_4.c / 4 | ||
201 | local _obj_5 = a.b | ||
202 | _obj_5.c = _obj_5.c % 5 | ||
203 | a = a & 6 | ||
204 | a = a | 7 | ||
205 | a = a ^ 8 | ||
206 | end | ||
184 | return nil | 207 | return nil |
185 | end) | 208 | end) |
diff --git a/spec/outputs/attrib.lua b/spec/outputs/attrib.lua index e48963c..bb9916c 100644 --- a/spec/outputs/attrib.lua +++ b/spec/outputs/attrib.lua | |||
@@ -56,17 +56,21 @@ do | |||
56 | end | 56 | end |
57 | local b | 57 | local b |
58 | if not false then | 58 | if not false then |
59 | if x then | 59 | b = ((function() |
60 | b = 1 | 60 | if x then |
61 | end | 61 | return 1 |
62 | end | ||
63 | end)()) | ||
62 | end | 64 | end |
63 | local _close_0 <close> = b | 65 | local _close_0 <close> = b |
64 | local c | 66 | local c |
65 | if true then | 67 | if true then |
66 | local _exp_0 = x | 68 | c = ((function() |
67 | if "abc" == _exp_0 then | 69 | local _exp_0 = x |
68 | c = 998 | 70 | if "abc" == _exp_0 then |
69 | end | 71 | return 998 |
72 | end | ||
73 | end)()) | ||
70 | end | 74 | end |
71 | local d | 75 | local d |
72 | if (function() | 76 | if (function() |
diff --git a/spec/outputs/class.lua b/spec/outputs/class.lua index aaea33c..07efde4 100644 --- a/spec/outputs/class.lua +++ b/spec/outputs/class.lua | |||
@@ -1231,30 +1231,28 @@ do | |||
1231 | end | 1231 | end |
1232 | do | 1232 | do |
1233 | local CX | 1233 | local CX |
1234 | do | 1234 | local _class_0 |
1235 | local _class_0 | 1235 | local _base_0 = { } |
1236 | local _base_0 = { } | 1236 | if _base_0.__index == nil then |
1237 | if _base_0.__index == nil then | 1237 | _base_0.__index = _base_0 |
1238 | _base_0.__index = _base_0 | ||
1239 | end | ||
1240 | _class_0 = setmetatable({ | ||
1241 | __init = function(self) end, | ||
1242 | __base = _base_0, | ||
1243 | __name = "CX" | ||
1244 | }, { | ||
1245 | __index = _base_0, | ||
1246 | __call = function(cls, ...) | ||
1247 | local _self_0 = setmetatable({ }, _base_0) | ||
1248 | cls.__init(_self_0, ...) | ||
1249 | return _self_0 | ||
1250 | end | ||
1251 | }) | ||
1252 | _base_0.__class = _class_0 | ||
1253 | local self = _class_0; | ||
1254 | xa = 1 | ||
1255 | xb = 1 | ||
1256 | CX = _class_0 | ||
1257 | end | 1238 | end |
1239 | _class_0 = setmetatable({ | ||
1240 | __init = function(self) end, | ||
1241 | __base = _base_0, | ||
1242 | __name = "CX" | ||
1243 | }, { | ||
1244 | __index = _base_0, | ||
1245 | __call = function(cls, ...) | ||
1246 | local _self_0 = setmetatable({ }, _base_0) | ||
1247 | cls.__init(_self_0, ...) | ||
1248 | return _self_0 | ||
1249 | end | ||
1250 | }) | ||
1251 | _base_0.__class = _class_0 | ||
1252 | local self = _class_0; | ||
1253 | xa = 1 | ||
1254 | xb = 1 | ||
1255 | CX = _class_0 | ||
1258 | end | 1256 | end |
1259 | do | 1257 | do |
1260 | local CY | 1258 | local CY |
diff --git a/spec/outputs/codes_from_doc.lua b/spec/outputs/codes_from_doc.lua index 74db469..b7d1236 100644 --- a/spec/outputs/codes_from_doc.lua +++ b/spec/outputs/codes_from_doc.lua | |||
@@ -20,6 +20,38 @@ local inventory = { | |||
20 | } | 20 | } |
21 | } | 21 | } |
22 | } | 22 | } |
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("Valid enum type:", "Static") | 111 | print("Valid enum type:", "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 = { |
@@ -467,8 +523,7 @@ local x = f() | |||
467 | local y = x | 523 | local y = x |
468 | local z = x | 524 | local z = x |
469 | do | 525 | do |
470 | local a | 526 | local a = 1 |
471 | a = 1 | ||
472 | local x, y, z | 527 | local x, y, z |
473 | print("forward declare all variables as locals") | 528 | print("forward declare all variables as locals") |
474 | x = function() | 529 | x = function() |
@@ -478,8 +533,7 @@ do | |||
478 | instance = Item:new() | 533 | instance = Item:new() |
479 | end | 534 | end |
480 | do | 535 | do |
481 | local X | 536 | local X = 1 |
482 | X = 1 | ||
483 | local B | 537 | local B |
484 | print("only forward declare upper case variables") | 538 | print("only forward declare upper case variables") |
485 | local a = 1 | 539 | local a = 1 |
@@ -488,19 +542,17 @@ end | |||
488 | do | 542 | do |
489 | a = 1 | 543 | a = 1 |
490 | print("declare all variables as globals") | 544 | print("declare all variables as globals") |
491 | local x | ||
492 | x = function() | 545 | x = function() |
493 | return 1 + y + z | 546 | return 1 + y + z |
494 | end | 547 | end |
495 | local y, z = 2, 3 | 548 | y, z = 2, 3 |
496 | end | 549 | end |
497 | do | 550 | do |
498 | X = 1 | 551 | X = 1 |
499 | print("only declare upper case variables as globals") | 552 | print("only declare upper case variables as globals") |
500 | local a = 1 | 553 | local a = 1 |
501 | local B = 2 | 554 | B = 2 |
502 | local Temp | 555 | local Temp = "a local value" |
503 | Temp = "a local value" | ||
504 | end | 556 | end |
505 | local thing = { | 557 | local thing = { |
506 | 1, | 558 | 1, |
@@ -551,6 +603,59 @@ end | |||
551 | local two, four | 603 | local two, four |
552 | local _obj_0 = items | 604 | local _obj_0 = items |
553 | 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] | ||
554 | local tuples = { | 659 | local tuples = { |
555 | { | 660 | { |
556 | "hello", | 661 | "hello", |
@@ -652,6 +757,56 @@ end) | |||
652 | if success then | 757 | if success then |
653 | print(result) | 758 | print(result) |
654 | 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)()) | ||
655 | local a <const> = 123 | 810 | local a <const> = 123 |
656 | local _ <close> = setmetatable({ }, { | 811 | local _ <close> = setmetatable({ }, { |
657 | __close = function() | 812 | __close = function() |
@@ -661,10 +816,19 @@ local _ <close> = setmetatable({ }, { | |||
661 | local a, b, c, d | 816 | local a, b, c, d |
662 | local _obj_0 = tb | 817 | local _obj_0 = tb |
663 | 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 | ||
664 | local some_string = "Here is a string\n that has a line break in it." | 820 | local some_string = "Here is a string\n that has a line break in it." |
665 | print("I am " .. tostring(math.random() * 100) .. "% sure.") | 821 | print("I am " .. tostring(math.random() * 100) .. "% sure.") |
666 | local integer = 1000000 | 822 | local integer = 1000000 |
667 | 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) .. "!\"'" | ||
668 | local my_function | 832 | local my_function |
669 | my_function = function() end | 833 | my_function = function() end |
670 | my_function() | 834 | my_function() |
@@ -864,11 +1028,10 @@ for i, item in ipairs(items) do | |||
864 | _len_0 = _len_0 + 1 | 1028 | _len_0 = _len_0 + 1 |
865 | end | 1029 | end |
866 | doubled = _accum_0 | 1030 | doubled = _accum_0 |
867 | local iter = ipairs(items) | ||
868 | local slice | 1031 | local slice |
869 | local _accum_0 = { } | 1032 | local _accum_0 = { } |
870 | local _len_0 = 1 | 1033 | local _len_0 = 1 |
871 | for i, item in iter do | 1034 | for i, item in ipairs(items) do |
872 | if i > 1 and i < 3 then | 1035 | if i > 1 and i < 3 then |
873 | _accum_0[_len_0] = item | 1036 | _accum_0[_len_0] = item |
874 | _len_0 = _len_0 + 1 | 1037 | _len_0 = _len_0 + 1 |
@@ -975,8 +1138,7 @@ local slice | |||
975 | local _accum_0 = { } | 1138 | local _accum_0 = { } |
976 | local _len_0 = 1 | 1139 | local _len_0 = 1 |
977 | local _list_0 = items | 1140 | local _list_0 = items |
978 | local _max_0 = 5 | 1141 | for _index_0 = 1, 5 do |
979 | for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do | ||
980 | local item = _list_0[_index_0] | 1142 | local item = _list_0[_index_0] |
981 | _accum_0[_len_0] = item | 1143 | _accum_0[_len_0] = item |
982 | _len_0 = _len_0 + 1 | 1144 | _len_0 = _len_0 + 1 |
@@ -986,7 +1148,8 @@ local slice | |||
986 | local _accum_0 = { } | 1148 | local _accum_0 = { } |
987 | local _len_0 = 1 | 1149 | local _len_0 = 1 |
988 | local _list_0 = items | 1150 | local _list_0 = items |
989 | for _index_0 = 2, #_list_0 do | 1151 | local _max_0 = #_list_0 |
1152 | for _index_0 = 2, _max_0 do | ||
990 | local item = _list_0[_index_0] | 1153 | local item = _list_0[_index_0] |
991 | _accum_0[_len_0] = item | 1154 | _accum_0[_len_0] = item |
992 | _len_0 = _len_0 + 1 | 1155 | _len_0 = _len_0 + 1 |
@@ -996,12 +1159,46 @@ local slice | |||
996 | local _accum_0 = { } | 1159 | local _accum_0 = { } |
997 | local _len_0 = 1 | 1160 | local _len_0 = 1 |
998 | local _list_0 = items | 1161 | local _list_0 = items |
999 | for _index_0 = 1, #_list_0, 2 do | 1162 | local _max_0 = #_list_0 |
1163 | for _index_0 = 1, _max_0, 2 do | ||
1000 | local item = _list_0[_index_0] | 1164 | local item = _list_0[_index_0] |
1001 | _accum_0[_len_0] = item | 1165 | _accum_0[_len_0] = item |
1002 | _len_0 = _len_0 + 1 | 1166 | _len_0 = _len_0 + 1 |
1003 | end | 1167 | end |
1004 | slice = _accum_0 | 1168 | slice = _accum_0 |
1169 | local slice | ||
1170 | local _accum_0 = { } | ||
1171 | local _len_0 = 1 | ||
1172 | local _list_0 = items | ||
1173 | local _min_0 = #_list_0 + -4 + 1 | ||
1174 | local _max_0 = #_list_0 + -1 + 1 | ||
1175 | for _index_0 = _min_0, _max_0 do | ||
1176 | local item = _list_0[_index_0] | ||
1177 | _accum_0[_len_0] = item | ||
1178 | _len_0 = _len_0 + 1 | ||
1179 | end | ||
1180 | slice = _accum_0 | ||
1181 | local reverse_slice | ||
1182 | local _accum_0 = { } | ||
1183 | local _len_0 = 1 | ||
1184 | local _list_0 = items | ||
1185 | local _min_0 = #_list_0 + -1 + 1 | ||
1186 | for _index_0 = _min_0, 1, -1 do | ||
1187 | local item = _list_0[_index_0] | ||
1188 | _accum_0[_len_0] = item | ||
1189 | _len_0 = _len_0 + 1 | ||
1190 | end | ||
1191 | reverse_slice = _accum_0 | ||
1192 | local sub_list | ||
1193 | local _accum_0 = { } | ||
1194 | local _len_0 = 1 | ||
1195 | local _list_0 = items | ||
1196 | for _index_0 = 2, 4 do | ||
1197 | local _item_0 = _list_0[_index_0] | ||
1198 | _accum_0[_len_0] = _item_0 | ||
1199 | _len_0 = _len_0 + 1 | ||
1200 | end | ||
1201 | sub_list = _accum_0 | ||
1005 | for i = 10, 20 do | 1202 | for i = 10, 20 do |
1006 | print(i) | 1203 | print(i) |
1007 | end | 1204 | end |
@@ -1012,8 +1209,7 @@ for key, value in pairs(object) do | |||
1012 | print(key, value) | 1209 | print(key, value) |
1013 | end | 1210 | end |
1014 | local _list_0 = items | 1211 | local _list_0 = items |
1015 | local _max_0 = 4 | 1212 | for _index_0 = 2, 4 do |
1016 | for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do | ||
1017 | local item = _list_0[_index_0] | 1213 | local item = _list_0[_index_0] |
1018 | print(item) | 1214 | print(item) |
1019 | end | 1215 | end |
@@ -1031,12 +1227,24 @@ local _len_0 = 1 | |||
1031 | for i = 1, 20 do | 1227 | for i = 1, 20 do |
1032 | if i % 2 == 0 then | 1228 | if i % 2 == 0 then |
1033 | _accum_0[_len_0] = i * 2 | 1229 | _accum_0[_len_0] = i * 2 |
1230 | _len_0 = _len_0 + 1 | ||
1034 | else | 1231 | else |
1035 | _accum_0[_len_0] = i | 1232 | _accum_0[_len_0] = i |
1233 | _len_0 = _len_0 + 1 | ||
1036 | end | 1234 | end |
1037 | _len_0 = _len_0 + 1 | ||
1038 | end | 1235 | end |
1039 | doubled_evens = _accum_0 | 1236 | doubled_evens = _accum_0 |
1237 | local first_large | ||
1238 | local _accum_0 | ||
1239 | local _list_0 = numbers | ||
1240 | for _index_0 = 1, #_list_0 do | ||
1241 | local n = _list_0[_index_0] | ||
1242 | if n > 10 then | ||
1243 | _accum_0 = n | ||
1244 | break | ||
1245 | end | ||
1246 | end | ||
1247 | first_large = _accum_0 | ||
1040 | local func_a | 1248 | local func_a |
1041 | func_a = function() | 1249 | func_a = function() |
1042 | for i = 1, 10 do | 1250 | for i = 1, 10 do |
@@ -1185,7 +1393,7 @@ if "Robert" == name then | |||
1185 | elseif "Dan" == name or "Daniel" == name then | 1393 | elseif "Dan" == name or "Daniel" == name then |
1186 | print("Your name, it's Dan") | 1394 | print("Your name, it's Dan") |
1187 | else | 1395 | else |
1188 | print("I don't know about your name") | 1396 | print("I don't know about you with name " .. tostring(name)) |
1189 | end | 1397 | end |
1190 | local b = 1 | 1398 | local b = 1 |
1191 | local next_number | 1399 | local next_number |
@@ -1285,6 +1493,192 @@ if _tab_0 then | |||
1285 | end | 1493 | end |
1286 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) | 1494 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) |
1287 | end | 1495 | end |
1496 | local _exp_0 = tb | ||
1497 | local _type_0 = type(_exp_0) | ||
1498 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
1499 | local _match_0 = false | ||
1500 | if _tab_0 then | ||
1501 | if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then | ||
1502 | _match_0 = true | ||
1503 | print("1, 2, 3") | ||
1504 | end | ||
1505 | end | ||
1506 | if not _match_0 then | ||
1507 | local _match_1 = false | ||
1508 | if _tab_0 then | ||
1509 | local b = _exp_0[2] | ||
1510 | if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then | ||
1511 | _match_1 = true | ||
1512 | print("1, " .. tostring(b) .. ", 3") | ||
1513 | end | ||
1514 | end | ||
1515 | if not _match_1 then | ||
1516 | if _tab_0 then | ||
1517 | local b = _exp_0[3] | ||
1518 | if b == nil then | ||
1519 | b = 3 | ||
1520 | end | ||
1521 | if 1 == _exp_0[1] and 2 == _exp_0[2] then | ||
1522 | print("1, 2, " .. tostring(b)) | ||
1523 | end | ||
1524 | end | ||
1525 | end | ||
1526 | end | ||
1527 | local _exp_0 = tb | ||
1528 | local _type_0 = type(_exp_0) | ||
1529 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
1530 | local _match_0 = false | ||
1531 | if _tab_0 then | ||
1532 | local result = _exp_0.result | ||
1533 | if true == _exp_0.success and result ~= nil then | ||
1534 | _match_0 = true | ||
1535 | print("success", result) | ||
1536 | end | ||
1537 | end | ||
1538 | if not _match_0 then | ||
1539 | local _match_1 = false | ||
1540 | if _tab_0 then | ||
1541 | if false == _exp_0.success then | ||
1542 | _match_1 = true | ||
1543 | print("failed", result) | ||
1544 | end | ||
1545 | end | ||
1546 | if not _match_1 then | ||
1547 | print("invalid") | ||
1548 | end | ||
1549 | end | ||
1550 | local _exp_0 = tb | ||
1551 | local _type_0 = type(_exp_0) | ||
1552 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
1553 | local _match_0 = false | ||
1554 | if _tab_0 then | ||
1555 | local content | ||
1556 | do | ||
1557 | local _obj_0 = _exp_0.data | ||
1558 | local _type_1 = type(_obj_0) | ||
1559 | if "table" == _type_1 or "userdata" == _type_1 then | ||
1560 | content = _obj_0.content | ||
1561 | end | ||
1562 | end | ||
1563 | local _val_0 | ||
1564 | do | ||
1565 | local _obj_0 = _exp_0.data | ||
1566 | if _obj_0 ~= nil then | ||
1567 | _val_0 = _obj_0.type | ||
1568 | end | ||
1569 | end | ||
1570 | if "success" == _val_0 and content ~= nil then | ||
1571 | _match_0 = true | ||
1572 | print("success", content) | ||
1573 | end | ||
1574 | end | ||
1575 | if not _match_0 then | ||
1576 | local _match_1 = false | ||
1577 | if _tab_0 then | ||
1578 | local content | ||
1579 | do | ||
1580 | local _obj_0 = _exp_0.data | ||
1581 | local _type_1 = type(_obj_0) | ||
1582 | if "table" == _type_1 or "userdata" == _type_1 then | ||
1583 | content = _obj_0.content | ||
1584 | end | ||
1585 | end | ||
1586 | local _val_0 | ||
1587 | do | ||
1588 | local _obj_0 = _exp_0.data | ||
1589 | if _obj_0 ~= nil then | ||
1590 | _val_0 = _obj_0.type | ||
1591 | end | ||
1592 | end | ||
1593 | if "error" == _val_0 and content ~= nil then | ||
1594 | _match_1 = true | ||
1595 | print("failed", content) | ||
1596 | end | ||
1597 | end | ||
1598 | if not _match_1 then | ||
1599 | print("invalid") | ||
1600 | end | ||
1601 | end | ||
1602 | local _exp_0 = tb | ||
1603 | local _type_0 = type(_exp_0) | ||
1604 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
1605 | if _tab_0 then | ||
1606 | local fourth = _exp_0[4] | ||
1607 | local _val_0 | ||
1608 | do | ||
1609 | local _obj_0 = _exp_0[1] | ||
1610 | if _obj_0 ~= nil then | ||
1611 | _val_0 = _obj_0.a | ||
1612 | end | ||
1613 | end | ||
1614 | local _val_1 | ||
1615 | do | ||
1616 | local _obj_0 = _exp_0[1] | ||
1617 | if _obj_0 ~= nil then | ||
1618 | _val_1 = _obj_0.b | ||
1619 | end | ||
1620 | end | ||
1621 | local _val_2 | ||
1622 | do | ||
1623 | local _obj_0 = _exp_0[2] | ||
1624 | if _obj_0 ~= nil then | ||
1625 | _val_2 = _obj_0.a | ||
1626 | end | ||
1627 | end | ||
1628 | local _val_3 | ||
1629 | do | ||
1630 | local _obj_0 = _exp_0[2] | ||
1631 | if _obj_0 ~= nil then | ||
1632 | _val_3 = _obj_0.b | ||
1633 | end | ||
1634 | end | ||
1635 | local _val_4 | ||
1636 | do | ||
1637 | local _obj_0 = _exp_0[3] | ||
1638 | if _obj_0 ~= nil then | ||
1639 | _val_4 = _obj_0.a | ||
1640 | end | ||
1641 | end | ||
1642 | local _val_5 | ||
1643 | do | ||
1644 | local _obj_0 = _exp_0[3] | ||
1645 | if _obj_0 ~= nil then | ||
1646 | _val_5 = _obj_0.b | ||
1647 | end | ||
1648 | end | ||
1649 | if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then | ||
1650 | print("matched", fourth) | ||
1651 | end | ||
1652 | end | ||
1653 | local segments = { | ||
1654 | "admin", | ||
1655 | "users", | ||
1656 | "logs", | ||
1657 | "view" | ||
1658 | } | ||
1659 | local _type_0 = type(segments) | ||
1660 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
1661 | if _tab_0 then | ||
1662 | local groups | ||
1663 | do | ||
1664 | local _accum_0 = { } | ||
1665 | local _len_0 = 1 | ||
1666 | local _max_0 = #segments + -3 + 1 | ||
1667 | for _index_0 = 1, _max_0 do | ||
1668 | local _item_0 = segments[_index_0] | ||
1669 | _accum_0[_len_0] = _item_0 | ||
1670 | _len_0 = _len_0 + 1 | ||
1671 | end | ||
1672 | groups = _accum_0 | ||
1673 | end | ||
1674 | local resource = segments[#segments - 1] | ||
1675 | local action = segments[#segments] | ||
1676 | if resource ~= nil and action ~= nil then | ||
1677 | print("Group:", groups) | ||
1678 | print("Resource:", resource) | ||
1679 | print("Action:", action) | ||
1680 | end | ||
1681 | end | ||
1288 | local Inventory | 1682 | local Inventory |
1289 | local _class_0 | 1683 | local _class_0 |
1290 | local _base_0 = { | 1684 | local _base_0 = { |
@@ -1941,6 +2335,10 @@ do | |||
1941 | _with_1["key-name"] = value | 2335 | _with_1["key-name"] = value |
1942 | end | 2336 | end |
1943 | _with_0[#_with_0 + 1] = "abc" | 2337 | _with_0[#_with_0 + 1] = "abc" |
2338 | local _with_0 = obj | ||
2339 | if _with_0 ~= nil then | ||
2340 | print(obj.name) | ||
2341 | end | ||
1944 | do | 2342 | do |
1945 | local var = "hello" | 2343 | local var = "hello" |
1946 | print(var) | 2344 | print(var) |
@@ -2031,6 +2429,38 @@ local inventory = { | |||
2031 | } | 2429 | } |
2032 | } | 2430 | } |
2033 | } | 2431 | } |
2432 | local map | ||
2433 | map = function(arr, action) | ||
2434 | local _accum_0 = { } | ||
2435 | local _len_0 = 1 | ||
2436 | for _index_0 = 1, #arr do | ||
2437 | local item = arr[_index_0] | ||
2438 | _accum_0[_len_0] = action(item) | ||
2439 | _len_0 = _len_0 + 1 | ||
2440 | end | ||
2441 | return _accum_0 | ||
2442 | end | ||
2443 | local filter | ||
2444 | filter = function(arr, cond) | ||
2445 | local _accum_0 = { } | ||
2446 | local _len_0 = 1 | ||
2447 | for _index_0 = 1, #arr do | ||
2448 | local item = arr[_index_0] | ||
2449 | if cond(item) then | ||
2450 | _accum_0[_len_0] = item | ||
2451 | _len_0 = _len_0 + 1 | ||
2452 | end | ||
2453 | end | ||
2454 | return _accum_0 | ||
2455 | end | ||
2456 | local reduce | ||
2457 | reduce = function(arr, init, action) | ||
2458 | for _index_0 = 1, #arr do | ||
2459 | local item = arr[_index_0] | ||
2460 | init = action(init, item) | ||
2461 | end | ||
2462 | return init | ||
2463 | end | ||
2034 | print(reduce(filter(map({ | 2464 | print(reduce(filter(map({ |
2035 | 1, | 2465 | 1, |
2036 | 2, | 2466 | 2, |
@@ -2088,6 +2518,12 @@ end | |||
2088 | print("yuescript") | 2518 | print("yuescript") |
2089 | print(3) | 2519 | print(3) |
2090 | print("Valid enum type:", "Static") | 2520 | print("Valid enum type:", "Static") |
2521 | do | ||
2522 | print(123, "hello") | ||
2523 | end | ||
2524 | do | ||
2525 | print(123, "hello") | ||
2526 | end | ||
2091 | if tb ~= nil then | 2527 | if tb ~= nil then |
2092 | tb:func() | 2528 | tb:func() |
2093 | end | 2529 | end |
@@ -2188,6 +2624,16 @@ for _key_0, _value_0 in pairs(b) do | |||
2188 | end | 2624 | end |
2189 | end | 2625 | end |
2190 | merge = _tab_0 | 2626 | merge = _tab_0 |
2627 | local last | ||
2628 | do | ||
2629 | local _item_0 = data.items | ||
2630 | last = _item_0[#_item_0] | ||
2631 | end | ||
2632 | local second_last | ||
2633 | do | ||
2634 | local _item_0 = data.items | ||
2635 | second_last = _item_0[#_item_0 - 1] | ||
2636 | end | ||
2191 | local mt = { } | 2637 | local mt = { } |
2192 | local add | 2638 | local add |
2193 | add = function(self, right) | 2639 | add = function(self, right) |
@@ -2318,6 +2764,14 @@ func({ | |||
2318 | 2, | 2764 | 2, |
2319 | 3 | 2765 | 3 |
2320 | }) | 2766 | }) |
2767 | local f | ||
2768 | f = function() | ||
2769 | return { | ||
2770 | 1, | ||
2771 | 2, | ||
2772 | 3 | ||
2773 | } | ||
2774 | end | ||
2321 | local tb = { | 2775 | local tb = { |
2322 | name = "abc", | 2776 | name = "abc", |
2323 | values = { | 2777 | values = { |
@@ -2478,8 +2932,7 @@ local x = f() | |||
2478 | local y = x | 2932 | local y = x |
2479 | local z = x | 2933 | local z = x |
2480 | do | 2934 | do |
2481 | local a | 2935 | local a = 1 |
2482 | a = 1 | ||
2483 | local x, y, z | 2936 | local x, y, z |
2484 | print("forward declare all variables as locals") | 2937 | print("forward declare all variables as locals") |
2485 | x = function() | 2938 | x = function() |
@@ -2489,8 +2942,7 @@ do | |||
2489 | instance = Item:new() | 2942 | instance = Item:new() |
2490 | end | 2943 | end |
2491 | do | 2944 | do |
2492 | local X | 2945 | local X = 1 |
2493 | X = 1 | ||
2494 | local B | 2946 | local B |
2495 | print("only forward declare upper case variables") | 2947 | print("only forward declare upper case variables") |
2496 | local a = 1 | 2948 | local a = 1 |
@@ -2499,19 +2951,17 @@ end | |||
2499 | do | 2951 | do |
2500 | a = 1 | 2952 | a = 1 |
2501 | print("declare all variables as globals") | 2953 | print("declare all variables as globals") |
2502 | local x | ||
2503 | x = function() | 2954 | x = function() |
2504 | return 1 + y + z | 2955 | return 1 + y + z |
2505 | end | 2956 | end |
2506 | local y, z = 2, 3 | 2957 | y, z = 2, 3 |
2507 | end | 2958 | end |
2508 | do | 2959 | do |
2509 | X = 1 | 2960 | X = 1 |
2510 | print("only declare upper case variables as globals") | 2961 | print("only declare upper case variables as globals") |
2511 | local a = 1 | 2962 | local a = 1 |
2512 | local B = 2 | 2963 | B = 2 |
2513 | local Temp | 2964 | local Temp = "a local value" |
2514 | Temp = "a local value" | ||
2515 | end | 2965 | end |
2516 | local thing = { | 2966 | local thing = { |
2517 | 1, | 2967 | 1, |
@@ -2562,6 +3012,59 @@ end | |||
2562 | local two, four | 3012 | local two, four |
2563 | local _obj_0 = items | 3013 | local _obj_0 = items |
2564 | two, four = _obj_0[2], _obj_0[4] | 3014 | two, four = _obj_0[2], _obj_0[4] |
3015 | local orders = { | ||
3016 | "first", | ||
3017 | "second", | ||
3018 | "third", | ||
3019 | "fourth", | ||
3020 | "last" | ||
3021 | } | ||
3022 | local first, bulk, last = orders[1], (function() | ||
3023 | local _accum_0 = { } | ||
3024 | local _len_0 = 1 | ||
3025 | local _max_0 = #orders + -2 + 1 | ||
3026 | for _index_0 = 2, _max_0 do | ||
3027 | local _item_0 = orders[_index_0] | ||
3028 | _accum_0[_len_0] = _item_0 | ||
3029 | _len_0 = _len_0 + 1 | ||
3030 | end | ||
3031 | return _accum_0 | ||
3032 | end)(), orders[#orders] | ||
3033 | print(first) | ||
3034 | print(bulk) | ||
3035 | print(last) | ||
3036 | local first, rest | ||
3037 | do | ||
3038 | local _obj_0 = orders | ||
3039 | first, rest = _obj_0[1], (function() | ||
3040 | local _accum_0 = { } | ||
3041 | local _len_0 = 1 | ||
3042 | local _max_0 = #_obj_0 | ||
3043 | for _index_0 = 2, _max_0 do | ||
3044 | local _item_0 = _obj_0[_index_0] | ||
3045 | _accum_0[_len_0] = _item_0 | ||
3046 | _len_0 = _len_0 + 1 | ||
3047 | end | ||
3048 | return _accum_0 | ||
3049 | end)() | ||
3050 | end | ||
3051 | local start, last | ||
3052 | do | ||
3053 | local _obj_0 = orders | ||
3054 | start, last = (function() | ||
3055 | local _accum_0 = { } | ||
3056 | local _len_0 = 1 | ||
3057 | local _max_0 = #_obj_0 + -2 + 1 | ||
3058 | for _index_0 = 1, _max_0 do | ||
3059 | local _item_0 = _obj_0[_index_0] | ||
3060 | _accum_0[_len_0] = _item_0 | ||
3061 | _len_0 = _len_0 + 1 | ||
3062 | end | ||
3063 | return _accum_0 | ||
3064 | end)(), _obj_0[#_obj_0] | ||
3065 | end | ||
3066 | local _obj_0 = orders | ||
3067 | first, last = _obj_0[1], _obj_0[#_obj_0] | ||
2565 | local tuples = { | 3068 | local tuples = { |
2566 | { | 3069 | { |
2567 | "hello", | 3070 | "hello", |
@@ -2663,6 +3166,56 @@ end) | |||
2663 | if success then | 3166 | if success then |
2664 | print(result) | 3167 | print(result) |
2665 | end | 3168 | end |
3169 | local a, b, c | ||
3170 | do | ||
3171 | local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function() | ||
3172 | return func() | ||
3173 | end) | ||
3174 | if _ok_0 then | ||
3175 | a, b, c = _ret_0, _ret_1, _ret_2 | ||
3176 | end | ||
3177 | end | ||
3178 | do | ||
3179 | local _exp_0 = ((function() | ||
3180 | return (function(_arg_0, ...) | ||
3181 | local _ok_0 = _arg_0 | ||
3182 | if _ok_0 then | ||
3183 | return ... | ||
3184 | end | ||
3185 | end)(pcall(function() | ||
3186 | return func() | ||
3187 | end)) | ||
3188 | end)()) | ||
3189 | if _exp_0 ~= nil then | ||
3190 | a = _exp_0 | ||
3191 | else | ||
3192 | a = "default" | ||
3193 | end | ||
3194 | end | ||
3195 | f((function() | ||
3196 | return (function(_arg_0, ...) | ||
3197 | local _ok_0 = _arg_0 | ||
3198 | if _ok_0 then | ||
3199 | return ... | ||
3200 | end | ||
3201 | end)(pcall(function() | ||
3202 | return func() | ||
3203 | end)) | ||
3204 | end)()) | ||
3205 | f((function() | ||
3206 | return (function(_arg_0, ...) | ||
3207 | local _ok_0 = _arg_0 | ||
3208 | if _ok_0 then | ||
3209 | return ... | ||
3210 | end | ||
3211 | end)(xpcall(function() | ||
3212 | print(123) | ||
3213 | return func() | ||
3214 | end, function(e) | ||
3215 | print(e) | ||
3216 | return e | ||
3217 | end)) | ||
3218 | end)()) | ||
2666 | local a <const> = 123 | 3219 | local a <const> = 123 |
2667 | local _ <close> = setmetatable({ }, { | 3220 | local _ <close> = setmetatable({ }, { |
2668 | __close = function() | 3221 | __close = function() |
@@ -2672,10 +3225,19 @@ local _ <close> = setmetatable({ }, { | |||
2672 | local a, b, c, d | 3225 | local a, b, c, d |
2673 | local _obj_0 = tb | 3226 | local _obj_0 = tb |
2674 | a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] | 3227 | a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] |
3228 | Constant = 123 | ||
2675 | local some_string = "Here is a string\n that has a line break in it." | 3229 | local some_string = "Here is a string\n that has a line break in it." |
2676 | print("I am " .. tostring(math.random() * 100) .. "% sure.") | 3230 | print("I am " .. tostring(math.random() * 100) .. "% sure.") |
2677 | local integer = 1000000 | 3231 | local integer = 1000000 |
2678 | local hex = 0xEFBBBF | 3232 | local hex = 0xEFBBBF |
3233 | local binary = 19 | ||
3234 | local str = "key: value\nlist:\n - item1\n - " .. tostring(expr) | ||
3235 | local fn | ||
3236 | fn = function() | ||
3237 | local str = "foo:\n bar: baz" | ||
3238 | return str | ||
3239 | end | ||
3240 | local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'" | ||
2679 | local my_function | 3241 | local my_function |
2680 | my_function = function() end | 3242 | my_function = function() end |
2681 | my_function() | 3243 | my_function() |
@@ -2875,11 +3437,10 @@ for i, item in ipairs(items) do | |||
2875 | _len_0 = _len_0 + 1 | 3437 | _len_0 = _len_0 + 1 |
2876 | end | 3438 | end |
2877 | doubled = _accum_0 | 3439 | doubled = _accum_0 |
2878 | local iter = ipairs(items) | ||
2879 | local slice | 3440 | local slice |
2880 | local _accum_0 = { } | 3441 | local _accum_0 = { } |
2881 | local _len_0 = 1 | 3442 | local _len_0 = 1 |
2882 | for i, item in iter do | 3443 | for i, item in ipairs(items) do |
2883 | if i > 1 and i < 3 then | 3444 | if i > 1 and i < 3 then |
2884 | _accum_0[_len_0] = item | 3445 | _accum_0[_len_0] = item |
2885 | _len_0 = _len_0 + 1 | 3446 | _len_0 = _len_0 + 1 |
@@ -2986,8 +3547,7 @@ local slice | |||
2986 | local _accum_0 = { } | 3547 | local _accum_0 = { } |
2987 | local _len_0 = 1 | 3548 | local _len_0 = 1 |
2988 | local _list_0 = items | 3549 | local _list_0 = items |
2989 | local _max_0 = 5 | 3550 | for _index_0 = 1, 5 do |
2990 | for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do | ||
2991 | local item = _list_0[_index_0] | 3551 | local item = _list_0[_index_0] |
2992 | _accum_0[_len_0] = item | 3552 | _accum_0[_len_0] = item |
2993 | _len_0 = _len_0 + 1 | 3553 | _len_0 = _len_0 + 1 |
@@ -2997,7 +3557,8 @@ local slice | |||
2997 | local _accum_0 = { } | 3557 | local _accum_0 = { } |
2998 | local _len_0 = 1 | 3558 | local _len_0 = 1 |
2999 | local _list_0 = items | 3559 | local _list_0 = items |
3000 | for _index_0 = 2, #_list_0 do | 3560 | local _max_0 = #_list_0 |
3561 | for _index_0 = 2, _max_0 do | ||
3001 | local item = _list_0[_index_0] | 3562 | local item = _list_0[_index_0] |
3002 | _accum_0[_len_0] = item | 3563 | _accum_0[_len_0] = item |
3003 | _len_0 = _len_0 + 1 | 3564 | _len_0 = _len_0 + 1 |
@@ -3007,12 +3568,46 @@ local slice | |||
3007 | local _accum_0 = { } | 3568 | local _accum_0 = { } |
3008 | local _len_0 = 1 | 3569 | local _len_0 = 1 |
3009 | local _list_0 = items | 3570 | local _list_0 = items |
3010 | for _index_0 = 1, #_list_0, 2 do | 3571 | local _max_0 = #_list_0 |
3572 | for _index_0 = 1, _max_0, 2 do | ||
3011 | local item = _list_0[_index_0] | 3573 | local item = _list_0[_index_0] |
3012 | _accum_0[_len_0] = item | 3574 | _accum_0[_len_0] = item |
3013 | _len_0 = _len_0 + 1 | 3575 | _len_0 = _len_0 + 1 |
3014 | end | 3576 | end |
3015 | slice = _accum_0 | 3577 | slice = _accum_0 |
3578 | local slice | ||
3579 | local _accum_0 = { } | ||
3580 | local _len_0 = 1 | ||
3581 | local _list_0 = items | ||
3582 | local _min_0 = #_list_0 + -4 + 1 | ||
3583 | local _max_0 = #_list_0 + -1 + 1 | ||
3584 | for _index_0 = _min_0, _max_0 do | ||
3585 | local item = _list_0[_index_0] | ||
3586 | _accum_0[_len_0] = item | ||
3587 | _len_0 = _len_0 + 1 | ||
3588 | end | ||
3589 | slice = _accum_0 | ||
3590 | local reverse_slice | ||
3591 | local _accum_0 = { } | ||
3592 | local _len_0 = 1 | ||
3593 | local _list_0 = items | ||
3594 | local _min_0 = #_list_0 + -1 + 1 | ||
3595 | for _index_0 = _min_0, 1, -1 do | ||
3596 | local item = _list_0[_index_0] | ||
3597 | _accum_0[_len_0] = item | ||
3598 | _len_0 = _len_0 + 1 | ||
3599 | end | ||
3600 | reverse_slice = _accum_0 | ||
3601 | local sub_list | ||
3602 | local _accum_0 = { } | ||
3603 | local _len_0 = 1 | ||
3604 | local _list_0 = items | ||
3605 | for _index_0 = 2, 4 do | ||
3606 | local _item_0 = _list_0[_index_0] | ||
3607 | _accum_0[_len_0] = _item_0 | ||
3608 | _len_0 = _len_0 + 1 | ||
3609 | end | ||
3610 | sub_list = _accum_0 | ||
3016 | for i = 10, 20 do | 3611 | for i = 10, 20 do |
3017 | print(i) | 3612 | print(i) |
3018 | end | 3613 | end |
@@ -3023,8 +3618,7 @@ for key, value in pairs(object) do | |||
3023 | print(key, value) | 3618 | print(key, value) |
3024 | end | 3619 | end |
3025 | local _list_0 = items | 3620 | local _list_0 = items |
3026 | local _max_0 = 4 | 3621 | for _index_0 = 2, 4 do |
3027 | for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do | ||
3028 | local item = _list_0[_index_0] | 3622 | local item = _list_0[_index_0] |
3029 | print(item) | 3623 | print(item) |
3030 | end | 3624 | end |
@@ -3042,12 +3636,24 @@ local _len_0 = 1 | |||
3042 | for i = 1, 20 do | 3636 | for i = 1, 20 do |
3043 | if i % 2 == 0 then | 3637 | if i % 2 == 0 then |
3044 | _accum_0[_len_0] = i * 2 | 3638 | _accum_0[_len_0] = i * 2 |
3639 | _len_0 = _len_0 + 1 | ||
3045 | else | 3640 | else |
3046 | _accum_0[_len_0] = i | 3641 | _accum_0[_len_0] = i |
3642 | _len_0 = _len_0 + 1 | ||
3047 | end | 3643 | end |
3048 | _len_0 = _len_0 + 1 | ||
3049 | end | 3644 | end |
3050 | doubled_evens = _accum_0 | 3645 | doubled_evens = _accum_0 |
3646 | local first_large | ||
3647 | local _accum_0 | ||
3648 | local _list_0 = numbers | ||
3649 | for _index_0 = 1, #_list_0 do | ||
3650 | local n = _list_0[_index_0] | ||
3651 | if n > 10 then | ||
3652 | _accum_0 = n | ||
3653 | break | ||
3654 | end | ||
3655 | end | ||
3656 | first_large = _accum_0 | ||
3051 | local func_a | 3657 | local func_a |
3052 | func_a = function() | 3658 | func_a = function() |
3053 | for i = 1, 10 do | 3659 | for i = 1, 10 do |
@@ -3196,7 +3802,7 @@ if "Robert" == name then | |||
3196 | elseif "Dan" == name or "Daniel" == name then | 3802 | elseif "Dan" == name or "Daniel" == name then |
3197 | print("Your name, it's Dan") | 3803 | print("Your name, it's Dan") |
3198 | else | 3804 | else |
3199 | print("I don't know about your name") | 3805 | print("I don't know about you with name " .. tostring(name)) |
3200 | end | 3806 | end |
3201 | local b = 1 | 3807 | local b = 1 |
3202 | local next_number | 3808 | local next_number |
@@ -3296,6 +3902,192 @@ if _tab_0 then | |||
3296 | end | 3902 | end |
3297 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) | 3903 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) |
3298 | end | 3904 | end |
3905 | local _exp_0 = tb | ||
3906 | local _type_0 = type(_exp_0) | ||
3907 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
3908 | local _match_0 = false | ||
3909 | if _tab_0 then | ||
3910 | if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then | ||
3911 | _match_0 = true | ||
3912 | print("1, 2, 3") | ||
3913 | end | ||
3914 | end | ||
3915 | if not _match_0 then | ||
3916 | local _match_1 = false | ||
3917 | if _tab_0 then | ||
3918 | local b = _exp_0[2] | ||
3919 | if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then | ||
3920 | _match_1 = true | ||
3921 | print("1, " .. tostring(b) .. ", 3") | ||
3922 | end | ||
3923 | end | ||
3924 | if not _match_1 then | ||
3925 | if _tab_0 then | ||
3926 | local b = _exp_0[3] | ||
3927 | if b == nil then | ||
3928 | b = 3 | ||
3929 | end | ||
3930 | if 1 == _exp_0[1] and 2 == _exp_0[2] then | ||
3931 | print("1, 2, " .. tostring(b)) | ||
3932 | end | ||
3933 | end | ||
3934 | end | ||
3935 | end | ||
3936 | local _exp_0 = tb | ||
3937 | local _type_0 = type(_exp_0) | ||
3938 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
3939 | local _match_0 = false | ||
3940 | if _tab_0 then | ||
3941 | local result = _exp_0.result | ||
3942 | if true == _exp_0.success and result ~= nil then | ||
3943 | _match_0 = true | ||
3944 | print("success", result) | ||
3945 | end | ||
3946 | end | ||
3947 | if not _match_0 then | ||
3948 | local _match_1 = false | ||
3949 | if _tab_0 then | ||
3950 | if false == _exp_0.success then | ||
3951 | _match_1 = true | ||
3952 | print("failed", result) | ||
3953 | end | ||
3954 | end | ||
3955 | if not _match_1 then | ||
3956 | print("invalid") | ||
3957 | end | ||
3958 | end | ||
3959 | local _exp_0 = tb | ||
3960 | local _type_0 = type(_exp_0) | ||
3961 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
3962 | local _match_0 = false | ||
3963 | if _tab_0 then | ||
3964 | local content | ||
3965 | do | ||
3966 | local _obj_0 = _exp_0.data | ||
3967 | local _type_1 = type(_obj_0) | ||
3968 | if "table" == _type_1 or "userdata" == _type_1 then | ||
3969 | content = _obj_0.content | ||
3970 | end | ||
3971 | end | ||
3972 | local _val_0 | ||
3973 | do | ||
3974 | local _obj_0 = _exp_0.data | ||
3975 | if _obj_0 ~= nil then | ||
3976 | _val_0 = _obj_0.type | ||
3977 | end | ||
3978 | end | ||
3979 | if "success" == _val_0 and content ~= nil then | ||
3980 | _match_0 = true | ||
3981 | print("success", content) | ||
3982 | end | ||
3983 | end | ||
3984 | if not _match_0 then | ||
3985 | local _match_1 = false | ||
3986 | if _tab_0 then | ||
3987 | local content | ||
3988 | do | ||
3989 | local _obj_0 = _exp_0.data | ||
3990 | local _type_1 = type(_obj_0) | ||
3991 | if "table" == _type_1 or "userdata" == _type_1 then | ||
3992 | content = _obj_0.content | ||
3993 | end | ||
3994 | end | ||
3995 | local _val_0 | ||
3996 | do | ||
3997 | local _obj_0 = _exp_0.data | ||
3998 | if _obj_0 ~= nil then | ||
3999 | _val_0 = _obj_0.type | ||
4000 | end | ||
4001 | end | ||
4002 | if "error" == _val_0 and content ~= nil then | ||
4003 | _match_1 = true | ||
4004 | print("failed", content) | ||
4005 | end | ||
4006 | end | ||
4007 | if not _match_1 then | ||
4008 | print("invalid") | ||
4009 | end | ||
4010 | end | ||
4011 | local _exp_0 = tb | ||
4012 | local _type_0 = type(_exp_0) | ||
4013 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
4014 | if _tab_0 then | ||
4015 | local fourth = _exp_0[4] | ||
4016 | local _val_0 | ||
4017 | do | ||
4018 | local _obj_0 = _exp_0[1] | ||
4019 | if _obj_0 ~= nil then | ||
4020 | _val_0 = _obj_0.a | ||
4021 | end | ||
4022 | end | ||
4023 | local _val_1 | ||
4024 | do | ||
4025 | local _obj_0 = _exp_0[1] | ||
4026 | if _obj_0 ~= nil then | ||
4027 | _val_1 = _obj_0.b | ||
4028 | end | ||
4029 | end | ||
4030 | local _val_2 | ||
4031 | do | ||
4032 | local _obj_0 = _exp_0[2] | ||
4033 | if _obj_0 ~= nil then | ||
4034 | _val_2 = _obj_0.a | ||
4035 | end | ||
4036 | end | ||
4037 | local _val_3 | ||
4038 | do | ||
4039 | local _obj_0 = _exp_0[2] | ||
4040 | if _obj_0 ~= nil then | ||
4041 | _val_3 = _obj_0.b | ||
4042 | end | ||
4043 | end | ||
4044 | local _val_4 | ||
4045 | do | ||
4046 | local _obj_0 = _exp_0[3] | ||
4047 | if _obj_0 ~= nil then | ||
4048 | _val_4 = _obj_0.a | ||
4049 | end | ||
4050 | end | ||
4051 | local _val_5 | ||
4052 | do | ||
4053 | local _obj_0 = _exp_0[3] | ||
4054 | if _obj_0 ~= nil then | ||
4055 | _val_5 = _obj_0.b | ||
4056 | end | ||
4057 | end | ||
4058 | if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then | ||
4059 | print("matched", fourth) | ||
4060 | end | ||
4061 | end | ||
4062 | local segments = { | ||
4063 | "admin", | ||
4064 | "users", | ||
4065 | "logs", | ||
4066 | "view" | ||
4067 | } | ||
4068 | local _type_0 = type(segments) | ||
4069 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
4070 | if _tab_0 then | ||
4071 | local groups | ||
4072 | do | ||
4073 | local _accum_0 = { } | ||
4074 | local _len_0 = 1 | ||
4075 | local _max_0 = #segments + -3 + 1 | ||
4076 | for _index_0 = 1, _max_0 do | ||
4077 | local _item_0 = segments[_index_0] | ||
4078 | _accum_0[_len_0] = _item_0 | ||
4079 | _len_0 = _len_0 + 1 | ||
4080 | end | ||
4081 | groups = _accum_0 | ||
4082 | end | ||
4083 | local resource = segments[#segments - 1] | ||
4084 | local action = segments[#segments] | ||
4085 | if resource ~= nil and action ~= nil then | ||
4086 | print("Group:", groups) | ||
4087 | print("Resource:", resource) | ||
4088 | print("Action:", action) | ||
4089 | end | ||
4090 | end | ||
3299 | local Inventory | 4091 | local Inventory |
3300 | local _class_0 | 4092 | local _class_0 |
3301 | local _base_0 = { | 4093 | local _base_0 = { |
@@ -3952,6 +4744,10 @@ do | |||
3952 | _with_1["key-name"] = value | 4744 | _with_1["key-name"] = value |
3953 | end | 4745 | end |
3954 | _with_0[#_with_0 + 1] = "abc" | 4746 | _with_0[#_with_0 + 1] = "abc" |
4747 | local _with_0 = obj | ||
4748 | if _with_0 ~= nil then | ||
4749 | print(obj.name) | ||
4750 | end | ||
3955 | do | 4751 | do |
3956 | local var = "hello" | 4752 | local var = "hello" |
3957 | print(var) | 4753 | print(var) |
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 | } |
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 = { |
@@ -467,8 +523,7 @@ local x = f() | |||
467 | local y = x | 523 | local y = x |
468 | local z = x | 524 | local z = x |
469 | do | 525 | do |
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() |
479 | end | 534 | end |
480 | do | 535 | do |
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 | |||
488 | do | 542 | do |
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 |
496 | end | 549 | end |
497 | do | 550 | do |
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 = "一个局部值" | ||
504 | end | 556 | end |
505 | local thing = { | 557 | local thing = { |
506 | 1, | 558 | 1, |
@@ -551,6 +603,59 @@ end | |||
551 | local two, four | 603 | local two, four |
552 | local _obj_0 = items | 604 | local _obj_0 = items |
553 | 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] | ||
554 | local tuples = { | 659 | local tuples = { |
555 | { | 660 | { |
556 | "hello", | 661 | "hello", |
@@ -652,6 +757,56 @@ end) | |||
652 | if success then | 757 | if success then |
653 | print(result) | 758 | print(result) |
654 | 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)()) | ||
655 | local a <const> = 123 | 810 | local a <const> = 123 |
656 | local _ <close> = setmetatable({ }, { | 811 | local _ <close> = setmetatable({ }, { |
657 | __close = function() | 812 | __close = function() |
@@ -661,10 +816,19 @@ local _ <close> = setmetatable({ }, { | |||
661 | local a, b, c, d | 816 | local a, b, c, d |
662 | local _obj_0 = tb | 817 | local _obj_0 = tb |
663 | 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 | ||
664 | local some_string = "这是一个字符串\n 并包括一个换行。" | 820 | local some_string = "这是一个字符串\n 并包括一个换行。" |
665 | print("我有" .. tostring(math.random() * 100) .. "%的把握。") | 821 | print("我有" .. tostring(math.random() * 100) .. "%的把握。") |
666 | local integer = 1000000 | 822 | local integer = 1000000 |
667 | 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) .. "!\"'" | ||
668 | local my_function | 832 | local my_function |
669 | my_function = function() end | 833 | my_function = function() end |
670 | my_function() | 834 | my_function() |
@@ -858,11 +1022,10 @@ for i, item in ipairs(items) do | |||
858 | _len_0 = _len_0 + 1 | 1022 | _len_0 = _len_0 + 1 |
859 | end | 1023 | end |
860 | doubled = _accum_0 | 1024 | doubled = _accum_0 |
861 | local iter = ipairs(items) | ||
862 | local slice | 1025 | local slice |
863 | local _accum_0 = { } | 1026 | local _accum_0 = { } |
864 | local _len_0 = 1 | 1027 | local _len_0 = 1 |
865 | for i, item in iter do | 1028 | for 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 | |||
969 | local _accum_0 = { } | 1132 | local _accum_0 = { } |
970 | local _len_0 = 1 | 1133 | local _len_0 = 1 |
971 | local _list_0 = items | 1134 | local _list_0 = items |
972 | local _max_0 = 5 | 1135 | for _index_0 = 1, 5 do |
973 | for _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 | ||
1139 | end | ||
1140 | slice = _accum_0 | ||
1141 | local slice | ||
1142 | local _accum_0 = { } | ||
1143 | local _len_0 = 1 | ||
1144 | local _list_0 = items | ||
1145 | local _max_0 = #_list_0 | ||
1146 | for _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 | |||
980 | local _accum_0 = { } | 1153 | local _accum_0 = { } |
981 | local _len_0 = 1 | 1154 | local _len_0 = 1 |
982 | local _list_0 = items | 1155 | local _list_0 = items |
983 | for _index_0 = 2, #_list_0 do | 1156 | local _max_0 = #_list_0 |
1157 | for _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 | |||
990 | local _accum_0 = { } | 1164 | local _accum_0 = { } |
991 | local _len_0 = 1 | 1165 | local _len_0 = 1 |
992 | local _list_0 = items | 1166 | local _list_0 = items |
993 | for _index_0 = 1, #_list_0, 2 do | 1167 | local _min_0 = #_list_0 + -4 + 1 |
1168 | local _max_0 = #_list_0 + -1 + 1 | ||
1169 | for _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 |
997 | end | 1173 | end |
998 | slice = _accum_0 | 1174 | slice = _accum_0 |
1175 | local reverse_slice | ||
1176 | local _accum_0 = { } | ||
1177 | local _len_0 = 1 | ||
1178 | local _list_0 = items | ||
1179 | local _min_0 = #_list_0 + -1 + 1 | ||
1180 | for _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 | ||
1184 | end | ||
1185 | reverse_slice = _accum_0 | ||
1186 | local sub_list | ||
1187 | local _accum_0 = { } | ||
1188 | local _len_0 = 1 | ||
1189 | local _list_0 = items | ||
1190 | for _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 | ||
1194 | end | ||
1195 | sub_list = _accum_0 | ||
999 | for i = 10, 20 do | 1196 | for i = 10, 20 do |
1000 | print(i) | 1197 | print(i) |
1001 | end | 1198 | end |
@@ -1006,8 +1203,7 @@ for key, value in pairs(object) do | |||
1006 | print(key, value) | 1203 | print(key, value) |
1007 | end | 1204 | end |
1008 | local _list_0 = items | 1205 | local _list_0 = items |
1009 | local _max_0 = 4 | 1206 | for _index_0 = 2, 4 do |
1010 | for _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) |
1013 | end | 1209 | end |
@@ -1025,12 +1221,24 @@ local _len_0 = 1 | |||
1025 | for i = 1, 20 do | 1221 | for 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 | ||
1032 | end | 1229 | end |
1033 | doubled_evens = _accum_0 | 1230 | doubled_evens = _accum_0 |
1231 | local first_large | ||
1232 | local _accum_0 | ||
1233 | local _list_0 = numbers | ||
1234 | for _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 | ||
1240 | end | ||
1241 | first_large = _accum_0 | ||
1034 | local func_a | 1242 | local func_a |
1035 | func_a = function() | 1243 | func_a = function() |
1036 | for i = 1, 10 do | 1244 | for i = 1, 10 do |
@@ -1179,7 +1387,7 @@ if "Robert" == name then | |||
1179 | elseif "Dan" == name or "Daniel" == name then | 1387 | elseif "Dan" == name or "Daniel" == name then |
1180 | print("你的名字是Dan") | 1388 | print("你的名字是Dan") |
1181 | else | 1389 | else |
1182 | print("我不知道你的名字") | 1390 | print("我不认识你,你的名字是" .. tostring(name)) |
1183 | end | 1391 | end |
1184 | local b = 1 | 1392 | local b = 1 |
1185 | local next_number | 1393 | local 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)) |
1281 | end | 1489 | end |
1490 | local _exp_0 = tb | ||
1491 | local _type_0 = type(_exp_0) | ||
1492 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
1493 | local _match_0 = false | ||
1494 | if _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 | ||
1499 | end | ||
1500 | if 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 | ||
1520 | end | ||
1521 | local _exp_0 = tb | ||
1522 | local _type_0 = type(_exp_0) | ||
1523 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
1524 | local _match_0 = false | ||
1525 | if _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 | ||
1531 | end | ||
1532 | if 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 | ||
1543 | end | ||
1544 | local _exp_0 = tb | ||
1545 | local _type_0 = type(_exp_0) | ||
1546 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
1547 | local _match_0 = false | ||
1548 | if _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 | ||
1568 | end | ||
1569 | if 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 | ||
1595 | end | ||
1596 | local _exp_0 = tb | ||
1597 | local _type_0 = type(_exp_0) | ||
1598 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
1599 | if _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 | ||
1646 | end | ||
1647 | local segments = { | ||
1648 | "admin", | ||
1649 | "users", | ||
1650 | "logs", | ||
1651 | "view" | ||
1652 | } | ||
1653 | local _type_0 = type(segments) | ||
1654 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
1655 | if _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 | ||
1675 | end | ||
1282 | local Inventory | 1676 | local Inventory |
1283 | local _class_0 | 1677 | local _class_0 |
1284 | local _base_0 = { | 1678 | local _base_0 = { |
@@ -1935,6 +2329,10 @@ do | |||
1935 | _with_1["key-name"] = value | 2329 | _with_1["key-name"] = value |
1936 | end | 2330 | end |
1937 | _with_0[#_with_0 + 1] = "abc" | 2331 | _with_0[#_with_0 + 1] = "abc" |
2332 | local _with_0 = obj | ||
2333 | if _with_0 ~= nil then | ||
2334 | print(obj.name) | ||
2335 | end | ||
1938 | do | 2336 | do |
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 | } |
2426 | local map | ||
2427 | map = 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 | ||
2436 | end | ||
2437 | local filter | ||
2438 | filter = 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 | ||
2449 | end | ||
2450 | local reduce | ||
2451 | reduce = 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 | ||
2457 | end | ||
2028 | print(reduce(filter(map({ | 2458 | print(reduce(filter(map({ |
2029 | 1, | 2459 | 1, |
2030 | 2, | 2460 | 2, |
@@ -2082,6 +2512,12 @@ end | |||
2082 | print("yuescript") | 2512 | print("yuescript") |
2083 | print(3) | 2513 | print(3) |
2084 | print("有效的枚举类型:", "Static") | 2514 | print("有效的枚举类型:", "Static") |
2515 | do | ||
2516 | print(123, "hello") | ||
2517 | end | ||
2518 | do | ||
2519 | print(123, "hello") | ||
2520 | end | ||
2085 | if tb ~= nil then | 2521 | if tb ~= nil then |
2086 | tb:func() | 2522 | tb:func() |
2087 | end | 2523 | end |
@@ -2182,6 +2618,16 @@ for _key_0, _value_0 in pairs(b) do | |||
2182 | end | 2618 | end |
2183 | end | 2619 | end |
2184 | merge = _tab_0 | 2620 | merge = _tab_0 |
2621 | local last | ||
2622 | do | ||
2623 | local _item_0 = data.items | ||
2624 | last = _item_0[#_item_0] | ||
2625 | end | ||
2626 | local second_last | ||
2627 | do | ||
2628 | local _item_0 = data.items | ||
2629 | second_last = _item_0[#_item_0 - 1] | ||
2630 | end | ||
2185 | local mt = { } | 2631 | local mt = { } |
2186 | local add | 2632 | local add |
2187 | add = function(self, right) | 2633 | add = function(self, right) |
@@ -2312,6 +2758,14 @@ func({ | |||
2312 | 2, | 2758 | 2, |
2313 | 3 | 2759 | 3 |
2314 | }) | 2760 | }) |
2761 | local f | ||
2762 | f = function() | ||
2763 | return { | ||
2764 | 1, | ||
2765 | 2, | ||
2766 | 3 | ||
2767 | } | ||
2768 | end | ||
2315 | local tb = { | 2769 | local tb = { |
2316 | name = "abc", | 2770 | name = "abc", |
2317 | values = { | 2771 | values = { |
@@ -2472,8 +2926,7 @@ local x = f() | |||
2472 | local y = x | 2926 | local y = x |
2473 | local z = x | 2927 | local z = x |
2474 | do | 2928 | do |
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() |
2484 | end | 2937 | end |
2485 | do | 2938 | do |
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 | |||
2493 | do | 2945 | do |
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 |
2501 | end | 2952 | end |
2502 | do | 2953 | do |
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 = "一个局部值" | ||
2509 | end | 2959 | end |
2510 | local thing = { | 2960 | local thing = { |
2511 | 1, | 2961 | 1, |
@@ -2556,6 +3006,59 @@ end | |||
2556 | local two, four | 3006 | local two, four |
2557 | local _obj_0 = items | 3007 | local _obj_0 = items |
2558 | two, four = _obj_0[2], _obj_0[4] | 3008 | two, four = _obj_0[2], _obj_0[4] |
3009 | local orders = { | ||
3010 | "first", | ||
3011 | "second", | ||
3012 | "third", | ||
3013 | "fourth", | ||
3014 | "last" | ||
3015 | } | ||
3016 | local 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 | ||
3026 | end)(), orders[#orders] | ||
3027 | print(first) | ||
3028 | print(bulk) | ||
3029 | print(last) | ||
3030 | local first, rest | ||
3031 | do | ||
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)() | ||
3044 | end | ||
3045 | local start, last | ||
3046 | do | ||
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] | ||
3059 | end | ||
3060 | local _obj_0 = orders | ||
3061 | first, last = _obj_0[1], _obj_0[#_obj_0] | ||
2559 | local tuples = { | 3062 | local tuples = { |
2560 | { | 3063 | { |
2561 | "hello", | 3064 | "hello", |
@@ -2657,6 +3160,56 @@ end) | |||
2657 | if success then | 3160 | if success then |
2658 | print(result) | 3161 | print(result) |
2659 | end | 3162 | end |
3163 | local a, b, c | ||
3164 | do | ||
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 | ||
3171 | end | ||
3172 | do | ||
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 | ||
3188 | end | ||
3189 | f((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)) | ||
3198 | end)()) | ||
3199 | f((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)) | ||
3212 | end)()) | ||
2660 | local a <const> = 123 | 3213 | local a <const> = 123 |
2661 | local _ <close> = setmetatable({ }, { | 3214 | local _ <close> = setmetatable({ }, { |
2662 | __close = function() | 3215 | __close = function() |
@@ -2666,10 +3219,19 @@ local _ <close> = setmetatable({ }, { | |||
2666 | local a, b, c, d | 3219 | local a, b, c, d |
2667 | local _obj_0 = tb | 3220 | local _obj_0 = tb |
2668 | a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] | 3221 | a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] |
3222 | Constant = 123 | ||
2669 | local some_string = "这是一个字符串\n 并包括一个换行。" | 3223 | local some_string = "这是一个字符串\n 并包括一个换行。" |
2670 | print("我有" .. tostring(math.random() * 100) .. "%的把握。") | 3224 | print("我有" .. tostring(math.random() * 100) .. "%的把握。") |
2671 | local integer = 1000000 | 3225 | local integer = 1000000 |
2672 | local hex = 0xEFBBBF | 3226 | local hex = 0xEFBBBF |
3227 | local binary = 19 | ||
3228 | local str = "key: value\nlist:\n - item1\n - " .. tostring(expr) | ||
3229 | local fn | ||
3230 | fn = function() | ||
3231 | local str = "foo:\n bar: baz" | ||
3232 | return str | ||
3233 | end | ||
3234 | local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'" | ||
2673 | local my_function | 3235 | local my_function |
2674 | my_function = function() end | 3236 | my_function = function() end |
2675 | my_function() | 3237 | my_function() |
@@ -2863,11 +3425,10 @@ for i, item in ipairs(items) do | |||
2863 | _len_0 = _len_0 + 1 | 3425 | _len_0 = _len_0 + 1 |
2864 | end | 3426 | end |
2865 | doubled = _accum_0 | 3427 | doubled = _accum_0 |
2866 | local iter = ipairs(items) | ||
2867 | local slice | 3428 | local slice |
2868 | local _accum_0 = { } | 3429 | local _accum_0 = { } |
2869 | local _len_0 = 1 | 3430 | local _len_0 = 1 |
2870 | for i, item in iter do | 3431 | for 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 | |||
2974 | local _accum_0 = { } | 3535 | local _accum_0 = { } |
2975 | local _len_0 = 1 | 3536 | local _len_0 = 1 |
2976 | local _list_0 = items | 3537 | local _list_0 = items |
2977 | local _max_0 = 5 | 3538 | for _index_0 = 1, 5 do |
2978 | for _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 | ||
3542 | end | ||
3543 | slice = _accum_0 | ||
3544 | local slice | ||
3545 | local _accum_0 = { } | ||
3546 | local _len_0 = 1 | ||
3547 | local _list_0 = items | ||
3548 | local _max_0 = #_list_0 | ||
3549 | for _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 | |||
2985 | local _accum_0 = { } | 3556 | local _accum_0 = { } |
2986 | local _len_0 = 1 | 3557 | local _len_0 = 1 |
2987 | local _list_0 = items | 3558 | local _list_0 = items |
2988 | for _index_0 = 2, #_list_0 do | 3559 | local _max_0 = #_list_0 |
3560 | for _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 | |||
2995 | local _accum_0 = { } | 3567 | local _accum_0 = { } |
2996 | local _len_0 = 1 | 3568 | local _len_0 = 1 |
2997 | local _list_0 = items | 3569 | local _list_0 = items |
2998 | for _index_0 = 1, #_list_0, 2 do | 3570 | local _min_0 = #_list_0 + -4 + 1 |
3571 | local _max_0 = #_list_0 + -1 + 1 | ||
3572 | for _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 |
3002 | end | 3576 | end |
3003 | slice = _accum_0 | 3577 | slice = _accum_0 |
3578 | local reverse_slice | ||
3579 | local _accum_0 = { } | ||
3580 | local _len_0 = 1 | ||
3581 | local _list_0 = items | ||
3582 | local _min_0 = #_list_0 + -1 + 1 | ||
3583 | for _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 | ||
3587 | end | ||
3588 | reverse_slice = _accum_0 | ||
3589 | local sub_list | ||
3590 | local _accum_0 = { } | ||
3591 | local _len_0 = 1 | ||
3592 | local _list_0 = items | ||
3593 | for _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 | ||
3597 | end | ||
3598 | sub_list = _accum_0 | ||
3004 | for i = 10, 20 do | 3599 | for i = 10, 20 do |
3005 | print(i) | 3600 | print(i) |
3006 | end | 3601 | end |
@@ -3011,8 +3606,7 @@ for key, value in pairs(object) do | |||
3011 | print(key, value) | 3606 | print(key, value) |
3012 | end | 3607 | end |
3013 | local _list_0 = items | 3608 | local _list_0 = items |
3014 | local _max_0 = 4 | 3609 | for _index_0 = 2, 4 do |
3015 | for _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) |
3018 | end | 3612 | end |
@@ -3030,12 +3624,24 @@ local _len_0 = 1 | |||
3030 | for i = 1, 20 do | 3624 | for 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 | ||
3037 | end | 3632 | end |
3038 | doubled_evens = _accum_0 | 3633 | doubled_evens = _accum_0 |
3634 | local first_large | ||
3635 | local _accum_0 | ||
3636 | local _list_0 = numbers | ||
3637 | for _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 | ||
3643 | end | ||
3644 | first_large = _accum_0 | ||
3039 | local func_a | 3645 | local func_a |
3040 | func_a = function() | 3646 | func_a = function() |
3041 | for i = 1, 10 do | 3647 | for i = 1, 10 do |
@@ -3184,7 +3790,7 @@ if "Robert" == name then | |||
3184 | elseif "Dan" == name or "Daniel" == name then | 3790 | elseif "Dan" == name or "Daniel" == name then |
3185 | print("你的名字是Dan") | 3791 | print("你的名字是Dan") |
3186 | else | 3792 | else |
3187 | print("我不知道你的名字") | 3793 | print("我不认识你,你的名字是" .. tostring(name)) |
3188 | end | 3794 | end |
3189 | local b = 1 | 3795 | local b = 1 |
3190 | local next_number | 3796 | local 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)) |
3286 | end | 3892 | end |
3893 | local _exp_0 = tb | ||
3894 | local _type_0 = type(_exp_0) | ||
3895 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
3896 | local _match_0 = false | ||
3897 | if _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 | ||
3902 | end | ||
3903 | if 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 | ||
3923 | end | ||
3924 | local _exp_0 = tb | ||
3925 | local _type_0 = type(_exp_0) | ||
3926 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
3927 | local _match_0 = false | ||
3928 | if _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 | ||
3934 | end | ||
3935 | if 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 | ||
3946 | end | ||
3947 | local _exp_0 = tb | ||
3948 | local _type_0 = type(_exp_0) | ||
3949 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
3950 | local _match_0 = false | ||
3951 | if _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 | ||
3971 | end | ||
3972 | if 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 | ||
3998 | end | ||
3999 | local _exp_0 = tb | ||
4000 | local _type_0 = type(_exp_0) | ||
4001 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
4002 | if _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 | ||
4049 | end | ||
4050 | local segments = { | ||
4051 | "admin", | ||
4052 | "users", | ||
4053 | "logs", | ||
4054 | "view" | ||
4055 | } | ||
4056 | local _type_0 = type(segments) | ||
4057 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
4058 | if _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 | ||
4078 | end | ||
3287 | local Inventory | 4079 | local Inventory |
3288 | local _class_0 | 4080 | local _class_0 |
3289 | local _base_0 = { | 4081 | local _base_0 = { |
@@ -3940,6 +4732,10 @@ do | |||
3940 | _with_1["key-name"] = value | 4732 | _with_1["key-name"] = value |
3941 | end | 4733 | end |
3942 | _with_0[#_with_0 + 1] = "abc" | 4734 | _with_0[#_with_0 + 1] = "abc" |
4735 | local _with_0 = obj | ||
4736 | if _with_0 ~= nil then | ||
4737 | print(obj.name) | ||
4738 | end | ||
3943 | do | 4739 | do |
3944 | local var = "hello" | 4740 | local var = "hello" |
3945 | print(var) | 4741 | print(var) |
diff --git a/spec/outputs/comprehension.lua b/spec/outputs/comprehension.lua index 9a7c478..663bd44 100644 --- a/spec/outputs/comprehension.lua +++ b/spec/outputs/comprehension.lua | |||
@@ -243,8 +243,11 @@ end | |||
243 | do | 243 | do |
244 | local _accum_0 = { } | 244 | local _accum_0 = { } |
245 | local _len_0 = 1 | 245 | local _len_0 = 1 |
246 | local _min_0 = 1 + 2 | ||
246 | local _max_0 = 3 + 4 | 247 | local _max_0 = 3 + 4 |
247 | for _index_0 = 1 + 2, _max_0 < 0 and #items + _max_0 or _max_0 do | 248 | _min_0 = _min_0 < 0 and #items + _min_0 + 1 or _min_0 |
249 | _max_0 = _max_0 < 0 and #items + _max_0 + 1 or _max_0 | ||
250 | for _index_0 = _min_0, _max_0 do | ||
248 | local item = items[_index_0] | 251 | local item = items[_index_0] |
249 | _accum_0[_len_0] = item | 252 | _accum_0[_len_0] = item |
250 | _len_0 = _len_0 + 1 | 253 | _len_0 = _len_0 + 1 |
@@ -254,8 +257,11 @@ end | |||
254 | do | 257 | do |
255 | local _accum_0 = { } | 258 | local _accum_0 = { } |
256 | local _len_0 = 1 | 259 | local _len_0 = 1 |
260 | local _min_0 = hello() * 4 | ||
257 | local _max_0 = 2 - thing[4] | 261 | local _max_0 = 2 - thing[4] |
258 | for _index_0 = hello() * 4, _max_0 < 0 and #items + _max_0 or _max_0 do | 262 | _min_0 = _min_0 < 0 and #items + _min_0 + 1 or _min_0 |
263 | _max_0 = _max_0 < 0 and #items + _max_0 + 1 or _max_0 | ||
264 | for _index_0 = _min_0, _max_0 do | ||
259 | local item = items[_index_0] | 265 | local item = items[_index_0] |
260 | _accum_0[_len_0] = item | 266 | _accum_0[_len_0] = item |
261 | _len_0 = _len_0 + 1 | 267 | _len_0 = _len_0 + 1 |
diff --git a/spec/outputs/cond.lua b/spec/outputs/cond.lua index 083419a..e194909 100644 --- a/spec/outputs/cond.lua +++ b/spec/outputs/cond.lua | |||
@@ -313,14 +313,12 @@ do | |||
313 | end | 313 | end |
314 | end | 314 | end |
315 | do | 315 | do |
316 | do | 316 | local _des_0 = { } |
317 | local _des_0 = { } | 317 | if _des_0 then |
318 | if _des_0 then | 318 | _M = _des_0 |
319 | _M = _des_0 | 319 | local Thing = _M.Thing |
320 | local Thing = _M.Thing | 320 | local _obj_0 = _M |
321 | local _obj_0 = _M | 321 | a, b = _obj_0.a, _obj_0.b |
322 | a, b = _obj_0.a, _obj_0.b | ||
323 | end | ||
324 | end | 322 | end |
325 | end | 323 | end |
326 | do | 324 | do |
diff --git a/spec/outputs/destructure.lua b/spec/outputs/destructure.lua index 44da58b..ba216b5 100644 --- a/spec/outputs/destructure.lua +++ b/spec/outputs/destructure.lua | |||
@@ -621,4 +621,94 @@ do | |||
621 | print(meta_field, abc, def) | 621 | print(meta_field, abc, def) |
622 | end | 622 | end |
623 | end | 623 | end |
624 | do | ||
625 | local clients = { | ||
626 | "VIP_Alice", | ||
627 | "User_Bob", | ||
628 | "User_Clara", | ||
629 | "VIP_Eva" | ||
630 | } | ||
631 | local vipStart, regulars, vipEnd = clients[1], (function() | ||
632 | local _accum_0 = { } | ||
633 | local _len_0 = 1 | ||
634 | local _max_0 = #clients + -2 + 1 | ||
635 | for _index_0 = 2, _max_0 do | ||
636 | local _item_0 = clients[_index_0] | ||
637 | _accum_0[_len_0] = _item_0 | ||
638 | _len_0 = _len_0 + 1 | ||
639 | end | ||
640 | return _accum_0 | ||
641 | end)(), clients[#clients] | ||
642 | print(vipStart) | ||
643 | print(regulars) | ||
644 | print(vipEnd) | ||
645 | end | ||
646 | do | ||
647 | local setupMeeting | ||
648 | setupMeeting = function(participants) | ||
649 | local chair, secretary = participants[1], participants[#participants] | ||
650 | return print(chair, secretary) | ||
651 | end | ||
652 | setupMeeting({ | ||
653 | "Alice", | ||
654 | "Bob", | ||
655 | "Charlie", | ||
656 | "David" | ||
657 | }) | ||
658 | end | ||
659 | do | ||
660 | local getTransactions | ||
661 | getTransactions = function() | ||
662 | return { | ||
663 | { | ||
664 | id = "T1", | ||
665 | amount = 100 | ||
666 | }, | ||
667 | { | ||
668 | id = "T2", | ||
669 | amount = 200 | ||
670 | }, | ||
671 | { | ||
672 | id = "T3", | ||
673 | amount = 300 | ||
674 | } | ||
675 | } | ||
676 | end | ||
677 | local id, amount | ||
678 | do | ||
679 | local _item_0 = getTransactions() | ||
680 | local _obj_0 = _item_0[#_item_0] | ||
681 | id, amount = _obj_0.id, _obj_0.amount | ||
682 | end | ||
683 | assert(id == "T3") | ||
684 | assert(amount == 300) | ||
685 | end | ||
686 | do | ||
687 | local middle | ||
688 | local _accum_0 = { } | ||
689 | local _len_0 = 1 | ||
690 | local _list_0 = tb | ||
691 | local _max_0 = #_list_0 + -2 + 1 | ||
692 | for _index_0 = 2, _max_0 do | ||
693 | local _item_0 = _list_0[_index_0] | ||
694 | _accum_0[_len_0] = _item_0 | ||
695 | _len_0 = _len_0 + 1 | ||
696 | end | ||
697 | middle = _accum_0 | ||
698 | end | ||
699 | do | ||
700 | local a, abc, b, def, sub, d, e | ||
701 | local _obj_0 = tb | ||
702 | a, abc, b, def, sub, d, e = _obj_0[1], _obj_0.abc, _obj_0[2], _obj_0.def, (function() | ||
703 | local _accum_0 = { } | ||
704 | local _len_0 = 1 | ||
705 | local _max_0 = #_obj_0 + -3 + 1 | ||
706 | for _index_0 = 3, _max_0 do | ||
707 | local _item_0 = _obj_0[_index_0] | ||
708 | _accum_0[_len_0] = _item_0 | ||
709 | _len_0 = _len_0 + 1 | ||
710 | end | ||
711 | return _accum_0 | ||
712 | end)(), _obj_0[#_obj_0 - 1], _obj_0[#_obj_0] | ||
713 | end | ||
624 | return nil | 714 | return nil |
diff --git a/spec/outputs/do.lua b/spec/outputs/do.lua index 6473e03..96d1022 100644 --- a/spec/outputs/do.lua +++ b/spec/outputs/do.lua | |||
@@ -32,10 +32,10 @@ local t = { | |||
32 | } | 32 | } |
33 | return function(y, k) | 33 | return function(y, k) |
34 | if y == nil then | 34 | if y == nil then |
35 | do | 35 | y = ((function() |
36 | x = 10 + 2 | 36 | x = 10 + 2 |
37 | y = x | 37 | return x |
38 | end | 38 | end)()) |
39 | end | 39 | end |
40 | if k == nil then | 40 | if k == nil then |
41 | do | 41 | do |
diff --git a/spec/outputs/global.lua b/spec/outputs/global.lua index 7e74387..3918f85 100644 --- a/spec/outputs/global.lua +++ b/spec/outputs/global.lua | |||
@@ -87,3 +87,34 @@ do | |||
87 | end | 87 | end |
88 | local h = 100 | 88 | local h = 100 |
89 | end | 89 | end |
90 | do | ||
91 | x = y | ||
92 | local foobar = "all lowercase" | ||
93 | FooBar = "pascal case" | ||
94 | FOOBAR = "all uppercase" | ||
95 | end | ||
96 | do | ||
97 | do | ||
98 | local _class_0 | ||
99 | local _base_0 = { } | ||
100 | if _base_0.__index == nil then | ||
101 | _base_0.__index = _base_0 | ||
102 | end | ||
103 | _class_0 = setmetatable({ | ||
104 | __init = function() end, | ||
105 | __base = _base_0, | ||
106 | __name = "A" | ||
107 | }, { | ||
108 | __index = _base_0, | ||
109 | __call = function(cls, ...) | ||
110 | local _self_0 = setmetatable({ }, _base_0) | ||
111 | cls.__init(_self_0, ...) | ||
112 | return _self_0 | ||
113 | end | ||
114 | }) | ||
115 | _base_0.__class = _class_0 | ||
116 | A = _class_0 | ||
117 | end | ||
118 | Flag = 1 | ||
119 | const, x, y = "const", 1, 2 | ||
120 | end | ||
diff --git a/spec/outputs/import.lua b/spec/outputs/import.lua index 83c99e2..7aa130f 100644 --- a/spec/outputs/import.lua +++ b/spec/outputs/import.lua | |||
@@ -166,3 +166,13 @@ do | |||
166 | local _obj_1 = require("m") | 166 | local _obj_1 = require("m") |
167 | g, i = _obj_1[1], getmetatable(_obj_1[2]).__close | 167 | g, i = _obj_1[1], getmetatable(_obj_1[2]).__close |
168 | end | 168 | end |
169 | do | ||
170 | local require <const> = require | ||
171 | local stringlib <const> = string | ||
172 | local format <const> = string.format | ||
173 | local io_read <const> = io.read | ||
174 | local type | ||
175 | type = function() end | ||
176 | local tp <const> = _G.type | ||
177 | local yue <const> = _G["月"] | ||
178 | end | ||
diff --git a/spec/outputs/lists.lua b/spec/outputs/lists.lua index 48ec9c8..2ed7b95 100644 --- a/spec/outputs/lists.lua +++ b/spec/outputs/lists.lua | |||
@@ -230,31 +230,36 @@ x = { | |||
230 | 6, | 230 | 6, |
231 | 7 | 231 | 7 |
232 | } | 232 | } |
233 | local _max_0 = -5 | 233 | local _max_0 = #x + -5 + 1 |
234 | for _index_0 = 2, _max_0 < 0 and #x + _max_0 or _max_0, 2 do | 234 | for _index_0 = 2, _max_0, 2 do |
235 | local y = x[_index_0] | 235 | local y = x[_index_0] |
236 | print(y) | 236 | print(y) |
237 | end | 237 | end |
238 | local _max_1 = 3 | 238 | for _index_0 = 1, 3 do |
239 | for _index_0 = 1, _max_1 < 0 and #x + _max_1 or _max_1 do | ||
240 | local y = x[_index_0] | 239 | local y = x[_index_0] |
241 | print(y) | 240 | print(y) |
242 | end | 241 | end |
243 | for _index_0 = 2, #x do | 242 | local _max_1 = #x |
243 | for _index_0 = 2, _max_1 do | ||
244 | local y = x[_index_0] | 244 | local y = x[_index_0] |
245 | print(y) | 245 | print(y) |
246 | end | 246 | end |
247 | for _index_0 = 1, #x, 2 do | 247 | local _max_2 = #x |
248 | for _index_0 = 1, _max_2, 2 do | ||
248 | local y = x[_index_0] | 249 | local y = x[_index_0] |
249 | print(y) | 250 | print(y) |
250 | end | 251 | end |
251 | for _index_0 = 2, #x, 2 do | 252 | local _max_3 = #x |
253 | for _index_0 = 2, _max_3, 2 do | ||
252 | local y = x[_index_0] | 254 | local y = x[_index_0] |
253 | print(y) | 255 | print(y) |
254 | end | 256 | end |
255 | local a, b, c = 1, 5, 2 | 257 | local a, b, c = 1, 5, 2 |
256 | local _max_2 = b | 258 | local _min_0 = a |
257 | for _index_0 = a, _max_2 < 0 and #x + _max_2 or _max_2, c do | 259 | local _max_4 = b |
260 | _min_0 = _min_0 < 0 and #x + _min_0 + 1 or _min_0 | ||
261 | _max_4 = _max_4 < 0 and #x + _max_4 + 1 or _max_4 | ||
262 | for _index_0 = _min_0, _max_4, c do | ||
258 | local y = x[_index_0] | 263 | local y = x[_index_0] |
259 | print(y) | 264 | print(y) |
260 | end | 265 | end |
@@ -287,7 +292,10 @@ do | |||
287 | a | 292 | a |
288 | }) | 293 | }) |
289 | local _list_0 = f | 294 | local _list_0 = f |
290 | for _index_0 = a, #_list_0 do | 295 | local _min_1 = a |
296 | local _max_5 = #_list_0 | ||
297 | _min_1 = _min_1 < 0 and #_list_0 + _min_1 + 1 or _min_1 | ||
298 | for _index_0 = _min_1, _max_5 do | ||
291 | local v = _list_0[_index_0] | 299 | local v = _list_0[_index_0] |
292 | print(v) | 300 | print(v) |
293 | end | 301 | end |
@@ -327,4 +335,191 @@ do | |||
327 | job = "jobless" | 335 | job = "jobless" |
328 | end | 336 | end |
329 | end | 337 | end |
338 | do | ||
339 | local transactions = { | ||
340 | "T001", | ||
341 | "T002", | ||
342 | "T003", | ||
343 | "T004", | ||
344 | "T005" | ||
345 | } | ||
346 | local middleTransactions | ||
347 | do | ||
348 | local _accum_0 = { } | ||
349 | local _len_0 = 1 | ||
350 | local _max_5 = #transactions + -2 + 1 | ||
351 | for _index_0 = 2, _max_5 do | ||
352 | local _item_0 = transactions[_index_0] | ||
353 | _accum_0[_len_0] = _item_0 | ||
354 | _len_0 = _len_0 + 1 | ||
355 | end | ||
356 | middleTransactions = _accum_0 | ||
357 | end | ||
358 | print(middleTransactions) | ||
359 | end | ||
360 | do | ||
361 | local logs = { | ||
362 | { | ||
363 | start = 0, | ||
364 | ["end"] = 100 | ||
365 | }, | ||
366 | { | ||
367 | start = 100, | ||
368 | ["end"] = 200 | ||
369 | }, | ||
370 | { | ||
371 | start = 200, | ||
372 | ["end"] = 123 | ||
373 | } | ||
374 | } | ||
375 | print(logs[#logs]["end"]) | ||
376 | end | ||
377 | do | ||
378 | local pendingOrders = { | ||
379 | "O001", | ||
380 | "O002", | ||
381 | "O003", | ||
382 | "O004" | ||
383 | } | ||
384 | print(pendingOrders[#pendingOrders - 1]) | ||
385 | end | ||
386 | do | ||
387 | local getOrders | ||
388 | getOrders = function() | ||
389 | return { | ||
390 | { | ||
391 | id = "O1001", | ||
392 | status = "pending" | ||
393 | }, | ||
394 | { | ||
395 | id = "O1002", | ||
396 | status = "processing" | ||
397 | }, | ||
398 | { | ||
399 | id = "O1003", | ||
400 | status = "done" | ||
401 | } | ||
402 | } | ||
403 | end | ||
404 | local lastStatus | ||
405 | do | ||
406 | local _item_0 = getOrders() | ||
407 | lastStatus = _item_0[#_item_0].status | ||
408 | end | ||
409 | assert(lastStatus == "done") | ||
410 | end | ||
411 | do | ||
412 | local cloneList1 | ||
413 | cloneList1 = function(list) | ||
414 | local _accum_0 = { } | ||
415 | local _len_0 = 1 | ||
416 | local _max_5 = #list | ||
417 | for _index_0 = 1, _max_5 do | ||
418 | local _item_0 = list[_index_0] | ||
419 | _accum_0[_len_0] = _item_0 | ||
420 | _len_0 = _len_0 + 1 | ||
421 | end | ||
422 | return _accum_0 | ||
423 | end | ||
424 | local cloneList2 | ||
425 | cloneList2 = function(list) | ||
426 | local _tab_0 = { } | ||
427 | local _idx_0 = #_tab_0 + 1 | ||
428 | for _index_0 = 1, #list do | ||
429 | local _value_0 = list[_index_0] | ||
430 | _tab_0[_idx_0] = _value_0 | ||
431 | _idx_0 = _idx_0 + 1 | ||
432 | end | ||
433 | return _tab_0 | ||
434 | end | ||
435 | local cloneTable | ||
436 | cloneTable = function(tb) | ||
437 | local _tab_0 = { } | ||
438 | local _idx_0 = 1 | ||
439 | for _key_0, _value_0 in pairs(tb) do | ||
440 | if _idx_0 == _key_0 then | ||
441 | _tab_0[#_tab_0 + 1] = _value_0 | ||
442 | _idx_0 = _idx_0 + 1 | ||
443 | else | ||
444 | _tab_0[_key_0] = _value_0 | ||
445 | end | ||
446 | end | ||
447 | return _tab_0 | ||
448 | end | ||
449 | end | ||
450 | do | ||
451 | print((function() | ||
452 | local _item_0 = globalTB | ||
453 | return _item_0[#_item_0] | ||
454 | end)(), (function() | ||
455 | local _item_0 = a.b.c | ||
456 | return _item_0[#_item_0 - 2] | ||
457 | end)(), (function() | ||
458 | if x ~= nil then | ||
459 | local _obj_0 = x.y | ||
460 | if _obj_0 ~= nil then | ||
461 | local _obj_1 = _obj_0(x).z | ||
462 | if _obj_1 ~= nil then | ||
463 | return _obj_1[#_obj_1 - 3] | ||
464 | end | ||
465 | return nil | ||
466 | end | ||
467 | return nil | ||
468 | end | ||
469 | return nil | ||
470 | end)()) | ||
471 | end | ||
472 | local _anon_func_0 = function(globalTB) | ||
473 | local _item_0 = globalTB | ||
474 | local _call_0 = _item_0[#_item_0] | ||
475 | return _call_0["end"](_call_0, 123) | ||
476 | end | ||
477 | local _anon_func_1 = function(a) | ||
478 | local _item_0 | ||
479 | do | ||
480 | local _accum_0 = { } | ||
481 | local _len_0 = 1 | ||
482 | local _list_0 = a.b.c | ||
483 | local _max_5 = #_list_0 + -5 + 1 | ||
484 | for _index_0 = 5, _max_5 do | ||
485 | local _item_1 = _list_0[_index_0] | ||
486 | _accum_0[_len_0] = _item_1 | ||
487 | _len_0 = _len_0 + 1 | ||
488 | end | ||
489 | _item_0 = _accum_0 | ||
490 | end | ||
491 | return _item_0[#_item_0 - 2] | ||
492 | end | ||
493 | local _anon_func_2 = function(x) | ||
494 | if x ~= nil then | ||
495 | local _obj_0 = x.y | ||
496 | if _obj_0 ~= nil then | ||
497 | local _obj_1 = _obj_0(x).z | ||
498 | if _obj_1 ~= nil then | ||
499 | local _obj_2 = _obj_1[#_obj_1 - 3] | ||
500 | if _obj_2 ~= nil then | ||
501 | local _accum_0 = { } | ||
502 | local _len_0 = 1 | ||
503 | local _max_5 = #_obj_2 + -3 + 1 | ||
504 | for _index_0 = 1, _max_5 do | ||
505 | local _item_0 = _obj_2[_index_0] | ||
506 | _accum_0[_len_0] = _item_0 | ||
507 | _len_0 = _len_0 + 1 | ||
508 | end | ||
509 | return _accum_0 | ||
510 | end | ||
511 | return nil | ||
512 | end | ||
513 | return nil | ||
514 | end | ||
515 | return nil | ||
516 | end | ||
517 | return nil | ||
518 | end | ||
519 | do | ||
520 | local f | ||
521 | f = function() | ||
522 | return print(_anon_func_0(globalTB), _anon_func_1(a), _anon_func_2(x)) | ||
523 | end | ||
524 | end | ||
330 | return nil | 525 | return nil |
diff --git a/spec/outputs/literals.lua b/spec/outputs/literals.lua index a578d58..6de5411 100644 --- a/spec/outputs/literals.lua +++ b/spec/outputs/literals.lua | |||
@@ -8,10 +8,18 @@ local _ = { | |||
8 | 0xfF2323, | 8 | 0xfF2323, |
9 | 0xabcdef, | 9 | 0xabcdef, |
10 | 0xABCDEF, | 10 | 0xABCDEF, |
11 | 0XFBC400, | ||
11 | 0x123p-123, | 12 | 0x123p-123, |
12 | 0xABCP+321, | 13 | 0xABCP+321, |
13 | 0x.1p-111, | 14 | 0x.1p-111, |
14 | 0xABCP-321, | 15 | 0xABCP-321, |
16 | 0x0.1E, | ||
17 | 0xA23p-4, | ||
18 | 0X1.921FB54442D18P+1, | ||
19 | 1, | ||
20 | 8, | ||
21 | 15, | ||
22 | 201, | ||
15 | .2323, | 23 | .2323, |
16 | .2323e-1, | 24 | .2323e-1, |
17 | .2323e13434, | 25 | .2323e13434, |
diff --git a/spec/outputs/loops.lua b/spec/outputs/loops.lua index 8624d49..6ab4bbb 100644 --- a/spec/outputs/loops.lua +++ b/spec/outputs/loops.lua | |||
@@ -60,8 +60,8 @@ do | |||
60 | local y = hello[_index_0] | 60 | local y = hello[_index_0] |
61 | if y % 2 == 0 then | 61 | if y % 2 == 0 then |
62 | _accum_0[_len_0] = y | 62 | _accum_0[_len_0] = y |
63 | _len_0 = _len_0 + 1 | ||
63 | end | 64 | end |
64 | _len_0 = _len_0 + 1 | ||
65 | end | 65 | end |
66 | x = _accum_0 | 66 | x = _accum_0 |
67 | end | 67 | end |
@@ -132,13 +132,11 @@ do | |||
132 | end | 132 | end |
133 | do | 133 | do |
134 | local _accum_0 = { } | 134 | local _accum_0 = { } |
135 | local _len_0 = 1 | ||
136 | local _list_2 = 3 | 135 | local _list_2 = 3 |
137 | for _index_0 = 1, #_list_2 do | 136 | for _index_0 = 1, #_list_2 do |
138 | local thing = _list_2[_index_0] | 137 | local thing = _list_2[_index_0] |
139 | y = "hello" | 138 | y = "hello" |
140 | break | 139 | break |
141 | _len_0 = _len_0 + 1 | ||
142 | end | 140 | end |
143 | x = _accum_0 | 141 | x = _accum_0 |
144 | end | 142 | end |
@@ -370,3 +368,131 @@ do | |||
370 | end | 368 | end |
371 | until false | 369 | until false |
372 | end | 370 | end |
371 | local _anon_func_0 = function(i, tb) | ||
372 | local _accum_0 = { } | ||
373 | local _len_0 = 1 | ||
374 | while tb[i] do | ||
375 | i = i + 1 | ||
376 | _accum_0[_len_0] = i - 1 | ||
377 | _len_0 = _len_0 + 1 | ||
378 | end | ||
379 | return _accum_0 | ||
380 | end | ||
381 | do | ||
382 | local index | ||
383 | do | ||
384 | local _accum_0 | ||
385 | for i = 1, #tb do | ||
386 | if tb[i] then | ||
387 | _accum_0 = i | ||
388 | break | ||
389 | end | ||
390 | end | ||
391 | index = _accum_0 | ||
392 | end | ||
393 | f((function() | ||
394 | local _accum_0 | ||
395 | for i = 1, #tb do | ||
396 | if tb[i] then | ||
397 | _accum_0 = i | ||
398 | break | ||
399 | end | ||
400 | end | ||
401 | return _accum_0 | ||
402 | end)()) | ||
403 | f((function() | ||
404 | local _accum_0 = { } | ||
405 | local _len_0 = 1 | ||
406 | for i = 1, #tb do | ||
407 | if tb[i] then | ||
408 | _accum_0[_len_0] = i | ||
409 | _len_0 = _len_0 + 1 | ||
410 | end | ||
411 | end | ||
412 | return _accum_0 | ||
413 | end)()) | ||
414 | i = 1 | ||
415 | local ids | ||
416 | do | ||
417 | local _accum_0 = { } | ||
418 | local _len_0 = 1 | ||
419 | while tb[i] do | ||
420 | i = i + 1 | ||
421 | _accum_0[_len_0] = i - 1 | ||
422 | _len_0 = _len_0 + 1 | ||
423 | end | ||
424 | ids = _accum_0 | ||
425 | end | ||
426 | i = 1 | ||
427 | local idx | ||
428 | do | ||
429 | local _accum_0 | ||
430 | while tb[i] do | ||
431 | i = i + 1 | ||
432 | _accum_0 = i - 1 | ||
433 | break | ||
434 | end | ||
435 | idx = _accum_0 | ||
436 | end | ||
437 | local f1 | ||
438 | f1 = function() | ||
439 | i = 1 | ||
440 | return f(_anon_func_0(i, tb)) | ||
441 | end | ||
442 | i = 1 | ||
443 | f((function() | ||
444 | local _accum_0 | ||
445 | while tb[i] do | ||
446 | i = i + 1 | ||
447 | _accum_0 = i - 1 | ||
448 | break | ||
449 | end | ||
450 | return _accum_0 | ||
451 | end)()) | ||
452 | local _accum_0 = { } | ||
453 | local _len_0 = 1 | ||
454 | local _list_3 = items | ||
455 | for _index_0 = 1, #_list_3 do | ||
456 | local item = _list_3[_index_0] | ||
457 | local _type_0 = type(item) | ||
458 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
459 | if _tab_0 then | ||
460 | local value = item.value | ||
461 | if "A" == item.type and value ~= nil then | ||
462 | if value > 5 then | ||
463 | _accum_0[_len_0] = item | ||
464 | _len_0 = _len_0 + 1 | ||
465 | end | ||
466 | end | ||
467 | end | ||
468 | end | ||
469 | list = _accum_0 | ||
470 | end | ||
471 | do | ||
472 | repeat | ||
473 | print(1) | ||
474 | until true | ||
475 | do | ||
476 | local _accum_0 | ||
477 | repeat | ||
478 | a = func() | ||
479 | _accum_0 = a.x | ||
480 | break | ||
481 | until a.v | ||
482 | x = _accum_0 | ||
483 | end | ||
484 | local items | ||
485 | local _accum_0 = { } | ||
486 | local _len_0 = 1 | ||
487 | repeat | ||
488 | local item = getItem() | ||
489 | if not item then | ||
490 | break | ||
491 | end | ||
492 | if item.value > 0 then | ||
493 | _accum_0[_len_0] = item | ||
494 | _len_0 = _len_0 + 1 | ||
495 | end | ||
496 | until false | ||
497 | items = _accum_0 | ||
498 | end | ||
diff --git a/spec/outputs/macro.lua b/spec/outputs/macro.lua index aa74ed9..89c6e63 100644 --- a/spec/outputs/macro.lua +++ b/spec/outputs/macro.lua | |||
@@ -26,6 +26,10 @@ print({ | |||
26 | 123, | 26 | 123, |
27 | 'xyz' | 27 | 'xyz' |
28 | }) | 28 | }) |
29 | print({ | ||
30 | 456, | ||
31 | 'abc' | ||
32 | }) | ||
29 | do | 33 | do |
30 | assert(item == nil) | 34 | assert(item == nil) |
31 | end | 35 | end |
@@ -191,13 +195,11 @@ end | |||
191 | do | 195 | do |
192 | local a = 8 | 196 | local a = 8 |
193 | a = (function() | 197 | a = (function() |
194 | local a | 198 | local a = 1 |
195 | a = 1 | ||
196 | return a + 1 | 199 | return a + 1 |
197 | end)() | 200 | end)() |
198 | a = a + (function() | 201 | a = a + (function() |
199 | local a | 202 | local a = 1 |
200 | a = 1 | ||
201 | return a + 1 | 203 | return a + 1 |
202 | end)() | 204 | end)() |
203 | print(a) | 205 | print(a) |
@@ -215,6 +217,13 @@ function tb:func() | |||
215 | end | 217 | end |
216 | end | 218 | end |
217 | print(x) | 219 | print(x) |
220 | local yue = require("yue") | ||
221 | do | ||
222 | local function f2(a) | ||
223 | return a + 1 | ||
224 | end | ||
225 | x = x + f2(3) | ||
226 | end | ||
218 | local sel | 227 | local sel |
219 | sel = function(a, b, c) | 228 | sel = function(a, b, c) |
220 | if a then | 229 | if a then |
@@ -274,18 +283,12 @@ local result = ((((((origin.transform.root.gameObject:Parents()):Descendants()): | |||
274 | end)):Destroy() | 283 | end)):Destroy() |
275 | do | 284 | do |
276 | do | 285 | do |
277 | local _1 | 286 | local _1 = origin.transform.root.gameObject:Parents() |
278 | _1 = origin.transform.root.gameObject:Parents() | 287 | local _2 = _1:Descendants() |
279 | local _2 | 288 | local _3 = _2:SelectEnable() |
280 | _2 = _1:Descendants() | 289 | local _4 = _3:SelectVisible() |
281 | local _3 | 290 | local _5 = _4:TagEqual("fx") |
282 | _3 = _2:SelectEnable() | 291 | local _6 = _5:Where(function(x) |
283 | local _4 | ||
284 | _4 = _3:SelectVisible() | ||
285 | local _5 | ||
286 | _5 = _4:TagEqual("fx") | ||
287 | local _6 | ||
288 | _6 = _5:Where(function(x) | ||
289 | return x.name:EndsWith("(Clone)") | 292 | return x.name:EndsWith("(Clone)") |
290 | end) | 293 | end) |
291 | _6:Destroy() | 294 | _6:Destroy() |
@@ -325,7 +328,7 @@ print((setmetatable({ | |||
325 | return 998 | 328 | return 998 |
326 | end | 329 | end |
327 | })) | 330 | })) |
328 | print("current line: " .. tostring(323)) | 331 | print("current line: " .. tostring(349)) |
329 | do | 332 | do |
330 | do | 333 | do |
331 | -- TODO | 334 | -- TODO |
@@ -338,10 +341,8 @@ local _1 | |||
338 | _1 = function() | 341 | _1 = function() |
339 | print(1) | 342 | print(1) |
340 | local _accum_0 = { } | 343 | local _accum_0 = { } |
341 | local _len_0 = 1 | ||
342 | while false do | 344 | while false do |
343 | break | 345 | break |
344 | _len_0 = _len_0 + 1 | ||
345 | end | 346 | end |
346 | return _accum_0 | 347 | return _accum_0 |
347 | end | 348 | end |
diff --git a/spec/outputs/plus.lua b/spec/outputs/plus.lua index bd89bfe..dda0660 100644 --- a/spec/outputs/plus.lua +++ b/spec/outputs/plus.lua | |||
@@ -65,7 +65,6 @@ backpack = { | |||
65 | local start = { | 65 | local start = { |
66 | something = "cold" | 66 | something = "cold" |
67 | } | 67 | } |
68 | local bathe | 68 | local bathe = { |
69 | bathe = { | ||
70 | on = "fire" | 69 | on = "fire" |
71 | } | 70 | } |
diff --git a/spec/outputs/props.lua b/spec/outputs/props.lua new file mode 100644 index 0000000..2c282e0 --- /dev/null +++ b/spec/outputs/props.lua | |||
@@ -0,0 +1,240 @@ | |||
1 | local Props | ||
2 | do | ||
3 | local _class_0 | ||
4 | local assignReadOnly | ||
5 | local _base_0 = { | ||
6 | __index = function(self, name) | ||
7 | local cls = getmetatable(self) | ||
8 | do | ||
9 | local item | ||
10 | do | ||
11 | local _obj_0 = cls.__getter | ||
12 | if _obj_0 ~= nil then | ||
13 | item = _obj_0[name] | ||
14 | end | ||
15 | end | ||
16 | if item then | ||
17 | return item(self) | ||
18 | else | ||
19 | item = rawget(cls, name) | ||
20 | if item then | ||
21 | return item | ||
22 | else | ||
23 | local c = cls | ||
24 | repeat | ||
25 | c = getmetatable(c) | ||
26 | if c then | ||
27 | local _obj_0 = c.__getter | ||
28 | if _obj_0 ~= nil then | ||
29 | item = _obj_0[name] | ||
30 | end | ||
31 | if item then | ||
32 | if cls.__getter == nil then | ||
33 | cls.__getter = { } | ||
34 | end | ||
35 | cls.__getter[name] = item | ||
36 | return item(self) | ||
37 | else | ||
38 | item = rawget(c, name) | ||
39 | if item then | ||
40 | rawset(cls, name, item) | ||
41 | return item | ||
42 | end | ||
43 | end | ||
44 | else | ||
45 | break | ||
46 | end | ||
47 | until false | ||
48 | end | ||
49 | end | ||
50 | end | ||
51 | return nil | ||
52 | end, | ||
53 | __newindex = function(self, name, value) | ||
54 | local cls = getmetatable(self) | ||
55 | local item | ||
56 | local _obj_0 = cls.__setter | ||
57 | if _obj_0 ~= nil then | ||
58 | item = _obj_0[name] | ||
59 | end | ||
60 | if item then | ||
61 | return item(self, value) | ||
62 | else | ||
63 | local c = cls | ||
64 | repeat | ||
65 | c = getmetatable(c) | ||
66 | if c then | ||
67 | local _obj_1 = c.__setter | ||
68 | if _obj_1 ~= nil then | ||
69 | item = _obj_1[name] | ||
70 | end | ||
71 | if item then | ||
72 | if cls.__setter == nil then | ||
73 | cls.__setter = { } | ||
74 | end | ||
75 | cls.__setter[name] = item | ||
76 | item(self, value) | ||
77 | return | ||
78 | end | ||
79 | else | ||
80 | break | ||
81 | end | ||
82 | until false | ||
83 | return rawset(self, name, value) | ||
84 | end | ||
85 | end, | ||
86 | prop = function(self, name, props) | ||
87 | local get, set = props.get, props.set | ||
88 | if set == nil then | ||
89 | set = assignReadOnly | ||
90 | end | ||
91 | do | ||
92 | local getter = rawget(self.__base, "__getter") | ||
93 | if getter then | ||
94 | getter[name] = get | ||
95 | else | ||
96 | rawset(self.__base, "__getter", { | ||
97 | [name] = get | ||
98 | }) | ||
99 | end | ||
100 | end | ||
101 | local setter = rawget(self.__base, "__setter") | ||
102 | if setter then | ||
103 | setter[name] = set | ||
104 | else | ||
105 | return rawset(self.__base, "__setter", { | ||
106 | [name] = set | ||
107 | }) | ||
108 | end | ||
109 | end | ||
110 | } | ||
111 | if _base_0.__index == nil then | ||
112 | _base_0.__index = _base_0 | ||
113 | end | ||
114 | _class_0 = setmetatable({ | ||
115 | __init = function() end, | ||
116 | __base = _base_0, | ||
117 | __name = "Props" | ||
118 | }, { | ||
119 | __index = _base_0, | ||
120 | __call = function(cls, ...) | ||
121 | local _self_0 = setmetatable({ }, _base_0) | ||
122 | cls.__init(_self_0, ...) | ||
123 | return _self_0 | ||
124 | end | ||
125 | }) | ||
126 | _base_0.__class = _class_0 | ||
127 | local self = _class_0; | ||
128 | assignReadOnly = function() | ||
129 | return error("assigning a readonly property") | ||
130 | end | ||
131 | Props = _class_0 | ||
132 | end | ||
133 | local A | ||
134 | do | ||
135 | local _class_0 | ||
136 | local _parent_0 = Props | ||
137 | local _base_0 = { } | ||
138 | for _key_0, _val_0 in pairs(_parent_0.__base) do | ||
139 | if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then | ||
140 | _base_0[_key_0] = _val_0 | ||
141 | end | ||
142 | end | ||
143 | if _base_0.__index == nil then | ||
144 | _base_0.__index = _base_0 | ||
145 | end | ||
146 | setmetatable(_base_0, _parent_0.__base) | ||
147 | _class_0 = setmetatable({ | ||
148 | __init = function(self) | ||
149 | self._x = 0 | ||
150 | end, | ||
151 | __base = _base_0, | ||
152 | __name = "A", | ||
153 | __parent = _parent_0 | ||
154 | }, { | ||
155 | __index = function(cls, name) | ||
156 | local val = rawget(_base_0, name) | ||
157 | if val == nil then | ||
158 | local parent = rawget(cls, "__parent") | ||
159 | if parent then | ||
160 | return parent[name] | ||
161 | end | ||
162 | else | ||
163 | return val | ||
164 | end | ||
165 | end, | ||
166 | __call = function(cls, ...) | ||
167 | local _self_0 = setmetatable({ }, _base_0) | ||
168 | cls.__init(_self_0, ...) | ||
169 | return _self_0 | ||
170 | end | ||
171 | }) | ||
172 | _base_0.__class = _class_0 | ||
173 | local self = _class_0; | ||
174 | self:prop('x', { | ||
175 | get = function(self) | ||
176 | return self._x + 1000 | ||
177 | end, | ||
178 | set = function(self, v) | ||
179 | self._x = v | ||
180 | end | ||
181 | }) | ||
182 | if _parent_0.__inherited then | ||
183 | _parent_0.__inherited(_parent_0, _class_0) | ||
184 | end | ||
185 | A = _class_0 | ||
186 | end | ||
187 | local B | ||
188 | do | ||
189 | local _class_0 | ||
190 | local _parent_0 = A | ||
191 | local _base_0 = { } | ||
192 | for _key_0, _val_0 in pairs(_parent_0.__base) do | ||
193 | if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then | ||
194 | _base_0[_key_0] = _val_0 | ||
195 | end | ||
196 | end | ||
197 | if _base_0.__index == nil then | ||
198 | _base_0.__index = _base_0 | ||
199 | end | ||
200 | setmetatable(_base_0, _parent_0.__base) | ||
201 | _class_0 = setmetatable({ | ||
202 | __init = function(self, ...) | ||
203 | return _class_0.__parent.__init(self, ...) | ||
204 | end, | ||
205 | __base = _base_0, | ||
206 | __name = "B", | ||
207 | __parent = _parent_0 | ||
208 | }, { | ||
209 | __index = function(cls, name) | ||
210 | local val = rawget(_base_0, name) | ||
211 | if val == nil then | ||
212 | local parent = rawget(cls, "__parent") | ||
213 | if parent then | ||
214 | return parent[name] | ||
215 | end | ||
216 | else | ||
217 | return val | ||
218 | end | ||
219 | end, | ||
220 | __call = function(cls, ...) | ||
221 | local _self_0 = setmetatable({ }, _base_0) | ||
222 | cls.__init(_self_0, ...) | ||
223 | return _self_0 | ||
224 | end | ||
225 | }) | ||
226 | _base_0.__class = _class_0 | ||
227 | local self = _class_0; | ||
228 | self:prop('abc', { | ||
229 | get = function(self) | ||
230 | return "hello" | ||
231 | end | ||
232 | }) | ||
233 | if _parent_0.__inherited then | ||
234 | _parent_0.__inherited(_parent_0, _class_0) | ||
235 | end | ||
236 | B = _class_0 | ||
237 | end | ||
238 | local b = B() | ||
239 | b.x = 999 | ||
240 | return print(b.x, b.abc) | ||
diff --git a/spec/outputs/string.lua b/spec/outputs/string.lua index febea62..b536e6d 100644 --- a/spec/outputs/string.lua +++ b/spec/outputs/string.lua | |||
@@ -1,3 +1,4 @@ | |||
1 | local _module_0 = { } | ||
1 | local hi = "hello" | 2 | local hi = "hello" |
2 | local hello = "what the heckyes" | 3 | local hello = "what the heckyes" |
3 | print(hi) | 4 | print(hi) |
@@ -41,4 +42,42 @@ local _ = "hello"; | |||
41 | ("hello"):format().hello(1, 2, 3); | 42 | ("hello"):format().hello(1, 2, 3); |
42 | ("hello"):format(1, 2, 3) | 43 | ("hello"):format(1, 2, 3) |
43 | something("hello"):world() | 44 | something("hello"):world() |
44 | return something(("hello"):world()) | 45 | something(("hello"):world()) |
46 | do | ||
47 | local str = "key: value" | ||
48 | str = "config:\n\tenabled: true\n\tlevel: 5" | ||
49 | str = "header: start\nfooter: end" | ||
50 | str = "name: " .. tostring(username) | ||
51 | str = "count: " .. tostring(total) .. " items" | ||
52 | str = "user: " .. tostring(name) .. "\nid: " .. tostring(id) | ||
53 | str = "path: \"C:\\\\Program Files\\\\App\"\ndesc: 'single \"quote\" test'" | ||
54 | str = "key: value \nnext: 123 " | ||
55 | str = "list:\n - \"one\"\n - \"two\"" | ||
56 | str = "-- comment\ncontent text\n-- comment" | ||
57 | str = tostring(1 + 2) .. '\n' .. tostring(2 + 3) .. '\n' .. tostring("a" .. "b") | ||
58 | local obj = { | ||
59 | settings = "mode: " .. tostring(mode) .. "\nflags:\n\t- " .. tostring(flag1) .. "\n\t- default" | ||
60 | } | ||
61 | local fn | ||
62 | fn = function() | ||
63 | return "Hello\nname: " .. tostring(userName) | ||
64 | end | ||
65 | str = "result:\n\tstatus: " .. tostring((function() | ||
66 | if ok then | ||
67 | return "pass" | ||
68 | else | ||
69 | return "fail" | ||
70 | end | ||
71 | end)()) .. "\n\tcode: " .. tostring(code) | ||
72 | local summary = "date: " .. tostring(os.date()) .. "\nvalues:\n\t-\n\t\ta: " .. tostring(aVal) .. "\n\t\tb: " .. tostring(bVal or defaultB) | ||
73 | local msg = send("Hello, " .. tostring(user) .. "!\nToday is " .. tostring(os.date("%A")) .. ".") | ||
74 | local desc | ||
75 | do | ||
76 | local prefix = "Result" | ||
77 | desc = tostring(prefix) .. ":\nvalue: " .. tostring(compute()) | ||
78 | end | ||
79 | print(("1\n2\n3")) | ||
80 | end | ||
81 | local yaml = "version: " .. tostring(ver) .. "\nok: true" | ||
82 | _module_0["yaml"] = yaml | ||
83 | return _module_0 | ||
diff --git a/spec/outputs/switch.lua b/spec/outputs/switch.lua index e4dedc9..7c1004b 100644 --- a/spec/outputs/switch.lua +++ b/spec/outputs/switch.lua | |||
@@ -415,4 +415,366 @@ do | |||
415 | end | 415 | end |
416 | end | 416 | end |
417 | end | 417 | end |
418 | do | ||
419 | local _exp_0 = tb | ||
420 | local _type_0 = type(_exp_0) | ||
421 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
422 | local _match_0 = false | ||
423 | if _tab_0 then | ||
424 | if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then | ||
425 | _match_0 = true | ||
426 | print("1, 2, 3") | ||
427 | end | ||
428 | end | ||
429 | if not _match_0 then | ||
430 | local _match_1 = false | ||
431 | if _tab_0 then | ||
432 | local b = _exp_0[2] | ||
433 | if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then | ||
434 | _match_1 = true | ||
435 | print("1, " .. tostring(b) .. ", 3") | ||
436 | end | ||
437 | end | ||
438 | if not _match_1 then | ||
439 | if _tab_0 then | ||
440 | local b = _exp_0[3] | ||
441 | if b == nil then | ||
442 | b = 3 | ||
443 | end | ||
444 | if 1 == _exp_0[1] and 2 == _exp_0[2] then | ||
445 | print("1, 2, " .. tostring(b)) | ||
446 | end | ||
447 | end | ||
448 | end | ||
449 | end | ||
450 | end | ||
451 | do | ||
452 | local _exp_0 = tb | ||
453 | local _type_0 = type(_exp_0) | ||
454 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
455 | local _match_0 = false | ||
456 | if _tab_0 then | ||
457 | local result = _exp_0.result | ||
458 | if true == _exp_0.success and result ~= nil then | ||
459 | _match_0 = true | ||
460 | print("success", result) | ||
461 | end | ||
462 | end | ||
463 | if not _match_0 then | ||
464 | local _match_1 = false | ||
465 | if _tab_0 then | ||
466 | if false == _exp_0.success then | ||
467 | _match_1 = true | ||
468 | print("failed", result) | ||
469 | end | ||
470 | end | ||
471 | if not _match_1 then | ||
472 | print("invalid") | ||
473 | end | ||
474 | end | ||
475 | end | ||
476 | do | ||
477 | local _exp_0 = tb | ||
478 | local _type_0 = type(_exp_0) | ||
479 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
480 | local _match_0 = false | ||
481 | if _tab_0 then | ||
482 | local content = _exp_0.content | ||
483 | if "success" == _exp_0.type and content ~= nil then | ||
484 | _match_0 = true | ||
485 | print("success", content) | ||
486 | end | ||
487 | end | ||
488 | if not _match_0 then | ||
489 | local _match_1 = false | ||
490 | if _tab_0 then | ||
491 | local content = _exp_0.content | ||
492 | if "error" == _exp_0.type and content ~= nil then | ||
493 | _match_1 = true | ||
494 | print("failed", content) | ||
495 | end | ||
496 | end | ||
497 | if not _match_1 then | ||
498 | print("invalid") | ||
499 | end | ||
500 | end | ||
501 | end | ||
502 | do | ||
503 | do | ||
504 | local _exp_0 = tb | ||
505 | local _type_0 = type(_exp_0) | ||
506 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
507 | if _tab_0 then | ||
508 | local fourth = _exp_0[4] | ||
509 | local _val_0 | ||
510 | do | ||
511 | local _obj_0 = _exp_0[1] | ||
512 | if _obj_0 ~= nil then | ||
513 | _val_0 = _obj_0.a | ||
514 | end | ||
515 | end | ||
516 | local _val_1 | ||
517 | do | ||
518 | local _obj_0 = _exp_0[1] | ||
519 | if _obj_0 ~= nil then | ||
520 | _val_1 = _obj_0.b | ||
521 | end | ||
522 | end | ||
523 | local _val_2 | ||
524 | do | ||
525 | local _obj_0 = _exp_0[2] | ||
526 | if _obj_0 ~= nil then | ||
527 | _val_2 = _obj_0.a | ||
528 | end | ||
529 | end | ||
530 | local _val_3 | ||
531 | do | ||
532 | local _obj_0 = _exp_0[2] | ||
533 | if _obj_0 ~= nil then | ||
534 | _val_3 = _obj_0.b | ||
535 | end | ||
536 | end | ||
537 | local _val_4 | ||
538 | do | ||
539 | local _obj_0 = _exp_0[3] | ||
540 | if _obj_0 ~= nil then | ||
541 | _val_4 = _obj_0.a | ||
542 | end | ||
543 | end | ||
544 | local _val_5 | ||
545 | do | ||
546 | local _obj_0 = _exp_0[3] | ||
547 | if _obj_0 ~= nil then | ||
548 | _val_5 = _obj_0.b | ||
549 | end | ||
550 | end | ||
551 | 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 | ||
552 | print("matched", fourth) | ||
553 | end | ||
554 | end | ||
555 | end | ||
556 | local _exp_0 = tb | ||
557 | local _type_0 = type(_exp_0) | ||
558 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
559 | local _match_0 = false | ||
560 | if _tab_0 then | ||
561 | local _val_0 | ||
562 | do | ||
563 | local _obj_0 = _exp_0[1] | ||
564 | if _obj_0 ~= nil then | ||
565 | _val_0 = _obj_0.c | ||
566 | end | ||
567 | end | ||
568 | local _val_1 | ||
569 | do | ||
570 | local _obj_0 = _exp_0[1] | ||
571 | if _obj_0 ~= nil then | ||
572 | _val_1 = _obj_0.d | ||
573 | end | ||
574 | end | ||
575 | local _val_2 | ||
576 | do | ||
577 | local _obj_0 = _exp_0[2] | ||
578 | if _obj_0 ~= nil then | ||
579 | _val_2 = _obj_0.c | ||
580 | end | ||
581 | end | ||
582 | local _val_3 | ||
583 | do | ||
584 | local _obj_0 = _exp_0[2] | ||
585 | if _obj_0 ~= nil then | ||
586 | _val_3 = _obj_0.d | ||
587 | end | ||
588 | end | ||
589 | local _val_4 | ||
590 | do | ||
591 | local _obj_0 = _exp_0[3] | ||
592 | if _obj_0 ~= nil then | ||
593 | _val_4 = _obj_0.c | ||
594 | end | ||
595 | end | ||
596 | local _val_5 | ||
597 | do | ||
598 | local _obj_0 = _exp_0[3] | ||
599 | if _obj_0 ~= nil then | ||
600 | _val_5 = _obj_0.d | ||
601 | end | ||
602 | end | ||
603 | if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 then | ||
604 | _match_0 = true | ||
605 | print("OK") | ||
606 | end | ||
607 | end | ||
608 | if not _match_0 then | ||
609 | if _tab_0 then | ||
610 | local sixth = _exp_0[6] | ||
611 | local _val_0 | ||
612 | do | ||
613 | local _obj_0 = _exp_0[3] | ||
614 | if _obj_0 ~= nil then | ||
615 | _val_0 = _obj_0.a | ||
616 | end | ||
617 | end | ||
618 | local _val_1 | ||
619 | do | ||
620 | local _obj_0 = _exp_0[3] | ||
621 | if _obj_0 ~= nil then | ||
622 | _val_1 = _obj_0.b | ||
623 | end | ||
624 | end | ||
625 | local _val_2 | ||
626 | do | ||
627 | local _obj_0 = _exp_0[4] | ||
628 | if _obj_0 ~= nil then | ||
629 | _val_2 = _obj_0.a | ||
630 | end | ||
631 | end | ||
632 | local _val_3 | ||
633 | do | ||
634 | local _obj_0 = _exp_0[4] | ||
635 | if _obj_0 ~= nil then | ||
636 | _val_3 = _obj_0.b | ||
637 | end | ||
638 | end | ||
639 | local _val_4 | ||
640 | do | ||
641 | local _obj_0 = _exp_0[5] | ||
642 | if _obj_0 ~= nil then | ||
643 | _val_4 = _obj_0.a | ||
644 | end | ||
645 | end | ||
646 | local _val_5 | ||
647 | do | ||
648 | local _obj_0 = _exp_0[5] | ||
649 | if _obj_0 ~= nil then | ||
650 | _val_5 = _obj_0.b | ||
651 | end | ||
652 | end | ||
653 | 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 sixth ~= nil then | ||
654 | print("matched", sixth) | ||
655 | end | ||
656 | end | ||
657 | end | ||
658 | end | ||
659 | do | ||
660 | local v = "hello" | ||
661 | if "hello" == v then | ||
662 | print("matched hello") | ||
663 | else | ||
664 | print("not matched") | ||
665 | end | ||
666 | end | ||
667 | do | ||
668 | local f | ||
669 | f = function() | ||
670 | return "ok" | ||
671 | end | ||
672 | local val = f() | ||
673 | if "ok" == val then | ||
674 | print("it's ok") | ||
675 | end | ||
676 | end | ||
677 | do | ||
678 | local g | ||
679 | g = function() | ||
680 | return 42 | ||
681 | end | ||
682 | local result = g() | ||
683 | if 1 == result or 2 == result then | ||
684 | print("small") | ||
685 | elseif 42 == result then | ||
686 | print("life universe everything") | ||
687 | else | ||
688 | print("other " .. tostring(result)) | ||
689 | end | ||
690 | end | ||
691 | do | ||
692 | local check | ||
693 | check = function() | ||
694 | if true then | ||
695 | return "yes" | ||
696 | else | ||
697 | return "no" | ||
698 | end | ||
699 | end | ||
700 | local x = check() | ||
701 | if "yes" == x then | ||
702 | print("affirmative") | ||
703 | else | ||
704 | print("negative") | ||
705 | end | ||
706 | end | ||
707 | do | ||
708 | local t | ||
709 | t = function() | ||
710 | local tb = { | ||
711 | a = 1 | ||
712 | } | ||
713 | tb.a = 2 | ||
714 | return tb | ||
715 | end | ||
716 | local data = t() | ||
717 | local _type_0 = type(data) | ||
718 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
719 | local _match_0 = false | ||
720 | if _tab_0 then | ||
721 | if 2 == data.a then | ||
722 | _match_0 = true | ||
723 | print("matched") | ||
724 | end | ||
725 | end | ||
726 | if not _match_0 then | ||
727 | print("not matched") | ||
728 | end | ||
729 | end | ||
730 | do | ||
731 | local clientData = { | ||
732 | "Meta", | ||
733 | "CUST_1001", | ||
734 | "CHK123" | ||
735 | } | ||
736 | local _type_0 = type(clientData) | ||
737 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
738 | if _tab_0 then | ||
739 | local metadata | ||
740 | do | ||
741 | local _accum_0 = { } | ||
742 | local _len_0 = 1 | ||
743 | local _max_0 = #clientData + -3 + 1 | ||
744 | for _index_0 = 1, _max_0 do | ||
745 | local _item_0 = clientData[_index_0] | ||
746 | _accum_0[_len_0] = _item_0 | ||
747 | _len_0 = _len_0 + 1 | ||
748 | end | ||
749 | metadata = _accum_0 | ||
750 | end | ||
751 | local customerId = clientData[#clientData - 1] | ||
752 | local checksum = clientData[#clientData] | ||
753 | if customerId ~= nil and checksum ~= nil then | ||
754 | print(metadata) | ||
755 | print(customerId) | ||
756 | print(checksum) | ||
757 | end | ||
758 | end | ||
759 | end | ||
760 | do | ||
761 | local handlePath | ||
762 | handlePath = function(segments) | ||
763 | local _type_0 = type(segments) | ||
764 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
765 | if _tab_0 then | ||
766 | local resource = segments[#segments - 1] | ||
767 | local action = segments[#segments] | ||
768 | if resource ~= nil and action ~= nil then | ||
769 | print("Resource:", resource) | ||
770 | return print("Action:", action) | ||
771 | end | ||
772 | end | ||
773 | end | ||
774 | handlePath({ | ||
775 | "admin", | ||
776 | "logs", | ||
777 | "view" | ||
778 | }) | ||
779 | end | ||
418 | return nil | 780 | return nil |
diff --git a/spec/outputs/syntax.lua b/spec/outputs/syntax.lua index 5fd1821..040a325 100644 --- a/spec/outputs/syntax.lua +++ b/spec/outputs/syntax.lua | |||
@@ -239,9 +239,11 @@ x = 0 | |||
239 | local _list_0 = values | 239 | local _list_0 = values |
240 | for _index_0 = 1, #_list_0 do | 240 | for _index_0 = 1, #_list_0 do |
241 | local v = _list_0[_index_0] | 241 | local v = _list_0[_index_0] |
242 | if ntype(v) == "fndef" then | 242 | _ = ((function() |
243 | _ = x + 1 | 243 | if ntype(v) == "fndef" then |
244 | end | 244 | return x + 1 |
245 | end | ||
246 | end)()) | ||
245 | end | 247 | end |
246 | hello = { | 248 | hello = { |
247 | something = world, | 249 | something = world, |
diff --git a/spec/outputs/tables.lua b/spec/outputs/tables.lua index f358811..3f851de 100644 --- a/spec/outputs/tables.lua +++ b/spec/outputs/tables.lua | |||
@@ -366,6 +366,28 @@ local menus = { | |||
366 | } | 366 | } |
367 | } | 367 | } |
368 | } | 368 | } |
369 | _ = { | ||
370 | boolean = { | ||
371 | true, | ||
372 | false | ||
373 | }, | ||
374 | float = { | ||
375 | 3.14, | ||
376 | -6.8523015e+5 | ||
377 | }, | ||
378 | int = { | ||
379 | 123, | ||
380 | -685230 | ||
381 | }, | ||
382 | null = { | ||
383 | nodeName = 'node', | ||
384 | parent = nil | ||
385 | }, | ||
386 | string = { | ||
387 | 'Hello world', | ||
388 | "newline\nnewline2" | ||
389 | } | ||
390 | } | ||
369 | local tb | 391 | local tb |
370 | do | 392 | do |
371 | local _tab_0 = { } | 393 | local _tab_0 = { } |
diff --git a/spec/outputs/try_catch.lua b/spec/outputs/try_catch.lua index d4c80c1..edb2341 100644 --- a/spec/outputs/try_catch.lua +++ b/spec/outputs/try_catch.lua | |||
@@ -8,10 +8,10 @@ local _anon_func_2 = function(tb) | |||
8 | return tb.func() | 8 | return tb.func() |
9 | end | 9 | end |
10 | local _anon_func_3 = function(tb) | 10 | local _anon_func_3 = function(tb) |
11 | return tb.func() | 11 | return (tb.func()) |
12 | end | 12 | end |
13 | local _anon_func_4 = function(tb) | 13 | local _anon_func_4 = function(tb) |
14 | return tb:func(1, 2, 3) | 14 | return (tb:func(1, 2, 3)) |
15 | end | 15 | end |
16 | local _anon_func_5 = function(tb) | 16 | local _anon_func_5 = function(tb) |
17 | return tb.func(1) | 17 | return tb.func(1) |
@@ -22,6 +22,44 @@ end | |||
22 | local _anon_func_7 = function(a, b, c, tb) | 22 | local _anon_func_7 = function(a, b, c, tb) |
23 | return tb.f(a, b, c) | 23 | return tb.f(a, b, c) |
24 | end | 24 | end |
25 | local _anon_func_8 = function(_arg_0, ...) | ||
26 | local ok = _arg_0 | ||
27 | return ... | ||
28 | end | ||
29 | local _anon_func_10 = function(_arg_0, ...) | ||
30 | local _ok_0 = _arg_0 | ||
31 | if _ok_0 then | ||
32 | return ... | ||
33 | end | ||
34 | end | ||
35 | local _anon_func_9 = function(func, pcall) | ||
36 | return _anon_func_10(pcall(func)) | ||
37 | end | ||
38 | local _anon_func_12 = function(_arg_0, ...) | ||
39 | local _ok_0 = _arg_0 | ||
40 | if _ok_0 then | ||
41 | return ... | ||
42 | end | ||
43 | end | ||
44 | local _anon_func_11 = function(func, pcall) | ||
45 | return _anon_func_12(pcall(func)) | ||
46 | end | ||
47 | local _anon_func_14 = function(_arg_0, ...) | ||
48 | local _ok_0 = _arg_0 | ||
49 | if _ok_0 then | ||
50 | return ... | ||
51 | end | ||
52 | end | ||
53 | local _anon_func_15 = function(func, print) | ||
54 | print(123) | ||
55 | return func() | ||
56 | end | ||
57 | local _anon_func_13 = function(func, print, xpcall) | ||
58 | return _anon_func_14(xpcall(_anon_func_15, function(e) | ||
59 | print(e) | ||
60 | return e | ||
61 | end, func, print)) | ||
62 | end | ||
25 | local f | 63 | local f |
26 | f = function() | 64 | f = function() |
27 | xpcall(function() | 65 | xpcall(function() |
@@ -64,7 +102,7 @@ f = function() | |||
64 | print("OK") | 102 | print("OK") |
65 | end | 103 | end |
66 | if xpcall(function() | 104 | if xpcall(function() |
67 | return func(1) | 105 | return (func(1)) |
68 | end, function(err) | 106 | end, function(err) |
69 | return print(err) | 107 | return print(err) |
70 | end) then | 108 | end) then |
@@ -104,10 +142,236 @@ f = function() | |||
104 | do | 142 | do |
105 | x(function() | 143 | x(function() |
106 | local tb, a, b, c | 144 | local tb, a, b, c |
107 | f = function() | 145 | local f1 |
146 | f1 = function() | ||
108 | return pcall(_anon_func_7, a, b, c, tb) | 147 | return pcall(_anon_func_7, a, b, c, tb) |
109 | end | 148 | end |
110 | end) | 149 | end) |
111 | end | 150 | end |
151 | do | ||
152 | local f1 | ||
153 | f1 = function() | ||
154 | do | ||
155 | return _anon_func_8(pcall(function() | ||
156 | return func() | ||
157 | end)) | ||
158 | end | ||
159 | end | ||
160 | end | ||
161 | do | ||
162 | local func | ||
163 | local a, b, c | ||
164 | local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(func) | ||
165 | if _ok_0 then | ||
166 | a, b, c = _ret_0, _ret_1, _ret_2 | ||
167 | end | ||
168 | end | ||
169 | do | ||
170 | local a, b, c | ||
171 | local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function() | ||
172 | return func() | ||
173 | end) | ||
174 | if _ok_0 then | ||
175 | a, b, c = _ret_0, _ret_1, _ret_2 | ||
176 | end | ||
177 | end | ||
178 | do | ||
179 | local a | ||
180 | local _exp_0 = (_anon_func_9(func, pcall)) | ||
181 | if _exp_0 ~= nil then | ||
182 | a = _exp_0 | ||
183 | else | ||
184 | a = "default" | ||
185 | end | ||
186 | end | ||
187 | do | ||
188 | f(_anon_func_11(func, pcall)) | ||
189 | end | ||
190 | do | ||
191 | f(_anon_func_13(func, print, xpcall)) | ||
192 | end | ||
112 | return nil | 193 | return nil |
113 | end | 194 | end |
195 | local _anon_func_16 = function(a, b, c, tb) | ||
196 | return tb.f(a, b, c) | ||
197 | end | ||
198 | local _anon_func_17 = function(_arg_0, ...) | ||
199 | local ok = _arg_0 | ||
200 | return ... | ||
201 | end | ||
202 | do | ||
203 | xpcall(function() | ||
204 | return func(1, 2, 3) | ||
205 | end, function(err) | ||
206 | return print(err) | ||
207 | end) | ||
208 | xpcall(function() | ||
209 | return func(1, 2, 3) | ||
210 | end, function(err) | ||
211 | return print(err) | ||
212 | end) | ||
213 | pcall(function() | ||
214 | print("trying") | ||
215 | return func(1, 2, 3) | ||
216 | end) | ||
217 | do | ||
218 | local success, result = xpcall(function() | ||
219 | return func(1, 2, 3) | ||
220 | end, function(err) | ||
221 | return print(err) | ||
222 | end) | ||
223 | success, result = pcall(function() | ||
224 | return func(1, 2, 3) | ||
225 | end) | ||
226 | end | ||
227 | local tb = { } | ||
228 | pcall(function() | ||
229 | return tb.func | ||
230 | end) | ||
231 | pcall(function() | ||
232 | return tb.func() | ||
233 | end) | ||
234 | pcall(function() | ||
235 | return tb.func() | ||
236 | end) | ||
237 | pcall(function() | ||
238 | return (tb.func()) | ||
239 | end) | ||
240 | pcall(function() | ||
241 | return (tb:func(1, 2, 3)) | ||
242 | end) | ||
243 | pcall(function() | ||
244 | return tb.func(1) | ||
245 | end) | ||
246 | pcall(function() | ||
247 | return tb.func(1) | ||
248 | end) | ||
249 | if (xpcall(function() | ||
250 | return func(1) | ||
251 | end, function(err) | ||
252 | return print(err) | ||
253 | end)) then | ||
254 | print("OK") | ||
255 | end | ||
256 | if xpcall(function() | ||
257 | return (func(1)) | ||
258 | end, function(err) | ||
259 | return print(err) | ||
260 | end) then | ||
261 | print("OK") | ||
262 | end | ||
263 | do | ||
264 | do | ||
265 | local success, result = pcall(function() | ||
266 | return func("abc", 123) | ||
267 | end) | ||
268 | if success then | ||
269 | print(result) | ||
270 | end | ||
271 | end | ||
272 | local success, result = xpcall(function() | ||
273 | return func("abc", 123) | ||
274 | end, function(err) | ||
275 | return print(err) | ||
276 | end) | ||
277 | success, result = xpcall(function() | ||
278 | return func("abc", 123) | ||
279 | end, function(err) | ||
280 | return print(err) | ||
281 | end) | ||
282 | if success then | ||
283 | print(result) | ||
284 | end | ||
285 | end | ||
286 | do | ||
287 | pcall(function() | ||
288 | return func(1, 2, 3) | ||
289 | end) | ||
290 | pcall(function() | ||
291 | return func(1, 2, 3) | ||
292 | end) | ||
293 | end | ||
294 | do | ||
295 | x(function() | ||
296 | local tb, a, b, c | ||
297 | local f1 | ||
298 | f1 = function() | ||
299 | return pcall(_anon_func_16, a, b, c, tb) | ||
300 | end | ||
301 | end) | ||
302 | end | ||
303 | do | ||
304 | local f1 | ||
305 | f1 = function() | ||
306 | do | ||
307 | return _anon_func_17(pcall(function() | ||
308 | return func() | ||
309 | end)) | ||
310 | end | ||
311 | end | ||
312 | end | ||
313 | do | ||
314 | local func | ||
315 | local a, b, c | ||
316 | local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(func) | ||
317 | if _ok_0 then | ||
318 | a, b, c = _ret_0, _ret_1, _ret_2 | ||
319 | end | ||
320 | end | ||
321 | do | ||
322 | local a, b, c | ||
323 | local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function() | ||
324 | return func() | ||
325 | end) | ||
326 | if _ok_0 then | ||
327 | a, b, c = _ret_0, _ret_1, _ret_2 | ||
328 | end | ||
329 | end | ||
330 | do | ||
331 | local a | ||
332 | local _exp_0 = ((function() | ||
333 | return (function(_arg_0, ...) | ||
334 | local _ok_0 = _arg_0 | ||
335 | if _ok_0 then | ||
336 | return ... | ||
337 | end | ||
338 | end)(pcall(function() | ||
339 | return func() | ||
340 | end)) | ||
341 | end)()) | ||
342 | if _exp_0 ~= nil then | ||
343 | a = _exp_0 | ||
344 | else | ||
345 | a = "default" | ||
346 | end | ||
347 | end | ||
348 | do | ||
349 | f((function() | ||
350 | return (function(_arg_0, ...) | ||
351 | local _ok_0 = _arg_0 | ||
352 | if _ok_0 then | ||
353 | return ... | ||
354 | end | ||
355 | end)(pcall(function() | ||
356 | return func() | ||
357 | end)) | ||
358 | end)()) | ||
359 | end | ||
360 | do | ||
361 | f((function() | ||
362 | return (function(_arg_0, ...) | ||
363 | local _ok_0 = _arg_0 | ||
364 | if _ok_0 then | ||
365 | return ... | ||
366 | end | ||
367 | end)(xpcall(function() | ||
368 | print(123) | ||
369 | return func() | ||
370 | end, function(e) | ||
371 | print(e) | ||
372 | return e | ||
373 | end)) | ||
374 | end)()) | ||
375 | end | ||
376 | end | ||
377 | return nil | ||
diff --git a/spec/outputs/unicode/assign.lua b/spec/outputs/unicode/assign.lua index bf43953..e00d016 100644 --- a/spec/outputs/unicode/assign.lua +++ b/spec/outputs/unicode/assign.lua | |||
@@ -36,17 +36,15 @@ local _u53d8_u91cfx | |||
36 | do | 36 | do |
37 | local _u51fd_u6570 = _u83b7_u53d6_u5904_u7406_u51fd_u6570() | 37 | local _u51fd_u6570 = _u83b7_u53d6_u5904_u7406_u51fd_u6570() |
38 | if _u51fd_u6570 then | 38 | if _u51fd_u6570 then |
39 | do | 39 | _u53d8_u91cfx = ((function() |
40 | _u51fd_u6570() | 40 | _u51fd_u6570() |
41 | _u53d8_u91cfx = 123 | 41 | return 123 |
42 | end | 42 | end)()) |
43 | end | 43 | end |
44 | end | 44 | end |
45 | local _anon_func_0 = function(_u6253_u5370) | 45 | local _anon_func_0 = function(_u6253_u5370) |
46 | do | 46 | _u6253_u5370(123) |
47 | _u6253_u5370(123) | 47 | return { } |
48 | return { } | ||
49 | end | ||
50 | end | 48 | end |
51 | return __u65e0_u6548_u53d8_u91cf(function() | 49 | return __u65e0_u6548_u53d8_u91cf(function() |
52 | setmetatable(a_u53d8_u91cf, _anon_func_0(_u6253_u5370)) | 50 | setmetatable(a_u53d8_u91cf, _anon_func_0(_u6253_u5370)) |
diff --git a/spec/outputs/unicode/attrib.lua b/spec/outputs/unicode/attrib.lua index 1c48de4..5e5bb99 100644 --- a/spec/outputs/unicode/attrib.lua +++ b/spec/outputs/unicode/attrib.lua | |||
@@ -48,17 +48,21 @@ do | |||
48 | end | 48 | end |
49 | local _u5173_u95ed_u53d8_u91cfb | 49 | local _u5173_u95ed_u53d8_u91cfb |
50 | if not false then | 50 | if not false then |
51 | if _u6761_u4ef6x then | 51 | _u5173_u95ed_u53d8_u91cfb = ((function() |
52 | _u5173_u95ed_u53d8_u91cfb = 1 | 52 | if _u6761_u4ef6x then |
53 | end | 53 | return 1 |
54 | end | ||
55 | end)()) | ||
54 | end | 56 | end |
55 | local _close_0 <close> = _u5173_u95ed_u53d8_u91cfb | 57 | local _close_0 <close> = _u5173_u95ed_u53d8_u91cfb |
56 | local _u5e38_u91cfc | 58 | local _u5e38_u91cfc |
57 | if true then | 59 | if true then |
58 | local _exp_0 = _u6761_u4ef6x | 60 | _u5e38_u91cfc = ((function() |
59 | if "abc" == _exp_0 then | 61 | local _exp_0 = _u6761_u4ef6x |
60 | _u5e38_u91cfc = 998 | 62 | if "abc" == _exp_0 then |
61 | end | 63 | return 998 |
64 | end | ||
65 | end)()) | ||
62 | end | 66 | end |
63 | local _u5173_u95ed_u53d8_u91cfd | 67 | local _u5173_u95ed_u53d8_u91cfd |
64 | if (function() | 68 | if (function() |
diff --git a/spec/outputs/unicode/comprehension.lua b/spec/outputs/unicode/comprehension.lua index 60e490f..92bce69 100644 --- a/spec/outputs/unicode/comprehension.lua +++ b/spec/outputs/unicode/comprehension.lua | |||
@@ -243,8 +243,11 @@ end | |||
243 | do | 243 | do |
244 | local _accum_0 = { } | 244 | local _accum_0 = { } |
245 | local _len_0 = 1 | 245 | local _len_0 = 1 |
246 | local _min_0 = 1 + 2 | ||
246 | local _max_0 = 3 + 4 | 247 | local _max_0 = 3 + 4 |
247 | for _index_0 = 1 + 2, _max_0 < 0 and #_u5217_u8868 + _max_0 or _max_0 do | 248 | _min_0 = _min_0 < 0 and #_u5217_u8868 + _min_0 + 1 or _min_0 |
249 | _max_0 = _max_0 < 0 and #_u5217_u8868 + _max_0 + 1 or _max_0 | ||
250 | for _index_0 = _min_0, _max_0 do | ||
248 | local _u9879_u76ee = _u5217_u8868[_index_0] | 251 | local _u9879_u76ee = _u5217_u8868[_index_0] |
249 | _accum_0[_len_0] = _u9879_u76ee | 252 | _accum_0[_len_0] = _u9879_u76ee |
250 | _len_0 = _len_0 + 1 | 253 | _len_0 = _len_0 + 1 |
@@ -254,8 +257,11 @@ end | |||
254 | do | 257 | do |
255 | local _accum_0 = { } | 258 | local _accum_0 = { } |
256 | local _len_0 = 1 | 259 | local _len_0 = 1 |
260 | local _min_0 = _u4f60_u597d() * 4 | ||
257 | local _max_0 = 2 - _u4e1c_u897f[4] | 261 | local _max_0 = 2 - _u4e1c_u897f[4] |
258 | for _index_0 = _u4f60_u597d() * 4, _max_0 < 0 and #_u5217_u8868 + _max_0 or _max_0 do | 262 | _min_0 = _min_0 < 0 and #_u5217_u8868 + _min_0 + 1 or _min_0 |
263 | _max_0 = _max_0 < 0 and #_u5217_u8868 + _max_0 + 1 or _max_0 | ||
264 | for _index_0 = _min_0, _max_0 do | ||
259 | local _u9879_u76ee = _u5217_u8868[_index_0] | 265 | local _u9879_u76ee = _u5217_u8868[_index_0] |
260 | _accum_0[_len_0] = _u9879_u76ee | 266 | _accum_0[_len_0] = _u9879_u76ee |
261 | _len_0 = _len_0 + 1 | 267 | _len_0 = _len_0 + 1 |
diff --git a/spec/outputs/unicode/cond.lua b/spec/outputs/unicode/cond.lua index 7229001..5e86228 100644 --- a/spec/outputs/unicode/cond.lua +++ b/spec/outputs/unicode/cond.lua | |||
@@ -314,15 +314,13 @@ do | |||
314 | end | 314 | end |
315 | end | 315 | end |
316 | do | 316 | do |
317 | do | 317 | local _des_0 = { } |
318 | local _des_0 = { } | 318 | if _des_0 then |
319 | if _des_0 then | 319 | __u6a21_u5757 = _des_0 |
320 | __u6a21_u5757 = _des_0 | 320 | local _u4e1c_u897f = __u6a21_u5757["东西"] |
321 | local _u4e1c_u897f = __u6a21_u5757["东西"] | 321 | local a_u529f_u80fd, b_u529f_u80fd |
322 | local a_u529f_u80fd, b_u529f_u80fd | 322 | local _obj_0 = __u6a21_u5757 |
323 | local _obj_0 = __u6a21_u5757 | 323 | a_u529f_u80fd, b_u529f_u80fd = _obj_0["a功能"], _obj_0["b功能"] |
324 | a_u529f_u80fd, b_u529f_u80fd = _obj_0["a功能"], _obj_0["b功能"] | ||
325 | end | ||
326 | end | 324 | end |
327 | end | 325 | end |
328 | do | 326 | do |
diff --git a/spec/outputs/unicode/do.lua b/spec/outputs/unicode/do.lua index f9c3079..7bf1da3 100644 --- a/spec/outputs/unicode/do.lua +++ b/spec/outputs/unicode/do.lua | |||
@@ -32,10 +32,10 @@ local _u53d8_u91cft = { | |||
32 | } | 32 | } |
33 | return function(_u53c2_u6570y, _u53c2_u6570k) | 33 | return function(_u53c2_u6570y, _u53c2_u6570k) |
34 | if _u53c2_u6570y == nil then | 34 | if _u53c2_u6570y == nil then |
35 | do | 35 | _u53c2_u6570y = ((function() |
36 | _u53d8_u91cfx = 10 + 2 | 36 | _u53d8_u91cfx = 10 + 2 |
37 | _u53c2_u6570y = _u53d8_u91cfx | 37 | return _u53d8_u91cfx |
38 | end | 38 | end)()) |
39 | end | 39 | end |
40 | if _u53c2_u6570k == nil then | 40 | if _u53c2_u6570k == nil then |
41 | do | 41 | do |
diff --git a/spec/outputs/unicode/lists.lua b/spec/outputs/unicode/lists.lua index aafd516..3bf6f50 100644 --- a/spec/outputs/unicode/lists.lua +++ b/spec/outputs/unicode/lists.lua | |||
@@ -229,31 +229,36 @@ _u53d8_u91cfx = { | |||
229 | 6, | 229 | 6, |
230 | 7 | 230 | 7 |
231 | } | 231 | } |
232 | local _max_0 = -5 | 232 | local _max_0 = #_u53d8_u91cfx + -5 + 1 |
233 | for _index_0 = 2, _max_0 < 0 and #_u53d8_u91cfx + _max_0 or _max_0, 2 do | 233 | for _index_0 = 2, _max_0, 2 do |
234 | local _u53d8_u91cfy = _u53d8_u91cfx[_index_0] | 234 | local _u53d8_u91cfy = _u53d8_u91cfx[_index_0] |
235 | _u6253_u5370(_u53d8_u91cfy) | 235 | _u6253_u5370(_u53d8_u91cfy) |
236 | end | 236 | end |
237 | local _max_1 = 3 | 237 | for _index_0 = 1, 3 do |
238 | for _index_0 = 1, _max_1 < 0 and #_u53d8_u91cfx + _max_1 or _max_1 do | ||
239 | local _u53d8_u91cfy = _u53d8_u91cfx[_index_0] | 238 | local _u53d8_u91cfy = _u53d8_u91cfx[_index_0] |
240 | _u6253_u5370(_u53d8_u91cfy) | 239 | _u6253_u5370(_u53d8_u91cfy) |
241 | end | 240 | end |
242 | for _index_0 = 2, #_u53d8_u91cfx do | 241 | local _max_1 = #_u53d8_u91cfx |
242 | for _index_0 = 2, _max_1 do | ||
243 | local _u53d8_u91cfy = _u53d8_u91cfx[_index_0] | 243 | local _u53d8_u91cfy = _u53d8_u91cfx[_index_0] |
244 | _u6253_u5370(_u53d8_u91cfy) | 244 | _u6253_u5370(_u53d8_u91cfy) |
245 | end | 245 | end |
246 | for _index_0 = 1, #_u53d8_u91cfx, 2 do | 246 | local _max_2 = #_u53d8_u91cfx |
247 | for _index_0 = 1, _max_2, 2 do | ||
247 | local _u53d8_u91cfy = _u53d8_u91cfx[_index_0] | 248 | local _u53d8_u91cfy = _u53d8_u91cfx[_index_0] |
248 | _u6253_u5370(_u53d8_u91cfy) | 249 | _u6253_u5370(_u53d8_u91cfy) |
249 | end | 250 | end |
250 | for _index_0 = 2, #_u53d8_u91cfx, 2 do | 251 | local _max_3 = #_u53d8_u91cfx |
252 | for _index_0 = 2, _max_3, 2 do | ||
251 | local _u53d8_u91cfy = _u53d8_u91cfx[_index_0] | 253 | local _u53d8_u91cfy = _u53d8_u91cfx[_index_0] |
252 | _u6253_u5370(_u53d8_u91cfy) | 254 | _u6253_u5370(_u53d8_u91cfy) |
253 | end | 255 | end |
254 | local _u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc = 1, 5, 2 | 256 | local _u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc = 1, 5, 2 |
255 | local _max_2 = _u53d8_u91cfb | 257 | local _min_0 = _u53d8_u91cfa |
256 | for _index_0 = _u53d8_u91cfa, _max_2 < 0 and #_u53d8_u91cfx + _max_2 or _max_2, _u53d8_u91cfc do | 258 | local _max_4 = _u53d8_u91cfb |
259 | _min_0 = _min_0 < 0 and #_u53d8_u91cfx + _min_0 + 1 or _min_0 | ||
260 | _max_4 = _max_4 < 0 and #_u53d8_u91cfx + _max_4 + 1 or _max_4 | ||
261 | for _index_0 = _min_0, _max_4, _u53d8_u91cfc do | ||
257 | local _u53d8_u91cfy = _u53d8_u91cfx[_index_0] | 262 | local _u53d8_u91cfy = _u53d8_u91cfx[_index_0] |
258 | _u6253_u5370(_u53d8_u91cfy) | 263 | _u6253_u5370(_u53d8_u91cfy) |
259 | end | 264 | end |
diff --git a/spec/outputs/unicode/loops.lua b/spec/outputs/unicode/loops.lua index 8379993..27bbe2e 100644 --- a/spec/outputs/unicode/loops.lua +++ b/spec/outputs/unicode/loops.lua | |||
@@ -60,8 +60,8 @@ do | |||
60 | local _u53d8_u91cfy = _u4f60_u597d[_index_0] | 60 | local _u53d8_u91cfy = _u4f60_u597d[_index_0] |
61 | if _u53d8_u91cfy % 2 == 0 then | 61 | if _u53d8_u91cfy % 2 == 0 then |
62 | _accum_0[_len_0] = _u53d8_u91cfy | 62 | _accum_0[_len_0] = _u53d8_u91cfy |
63 | _len_0 = _len_0 + 1 | ||
63 | end | 64 | end |
64 | _len_0 = _len_0 + 1 | ||
65 | end | 65 | end |
66 | _u53d8_u91cfx = _accum_0 | 66 | _u53d8_u91cfx = _accum_0 |
67 | end | 67 | end |
@@ -132,13 +132,11 @@ do | |||
132 | end | 132 | end |
133 | do | 133 | do |
134 | local _accum_0 = { } | 134 | local _accum_0 = { } |
135 | local _len_0 = 1 | ||
136 | local _list_2 = 3 | 135 | local _list_2 = 3 |
137 | for _index_0 = 1, #_list_2 do | 136 | for _index_0 = 1, #_list_2 do |
138 | local _u4e1c_u897f = _list_2[_index_0] | 137 | local _u4e1c_u897f = _list_2[_index_0] |
139 | _u53d8_u91cfy = "你好" | 138 | _u53d8_u91cfy = "你好" |
140 | break | 139 | break |
141 | _len_0 = _len_0 + 1 | ||
142 | end | 140 | end |
143 | _u53d8_u91cfx = _accum_0 | 141 | _u53d8_u91cfx = _accum_0 |
144 | end | 142 | end |
diff --git a/spec/outputs/unicode/macro.lua b/spec/outputs/unicode/macro.lua index e2195e4..b4e78cd 100644 --- a/spec/outputs/unicode/macro.lua +++ b/spec/outputs/unicode/macro.lua | |||
@@ -167,13 +167,11 @@ end | |||
167 | do | 167 | do |
168 | local _u53d8_u91cfa = 8 | 168 | local _u53d8_u91cfa = 8 |
169 | _u53d8_u91cfa = (function() | 169 | _u53d8_u91cfa = (function() |
170 | local _u53d8_u91cfa | 170 | local _u53d8_u91cfa = 1 |
171 | _u53d8_u91cfa = 1 | ||
172 | return _u53d8_u91cfa + 1 | 171 | return _u53d8_u91cfa + 1 |
173 | end)() | 172 | end)() |
174 | _u53d8_u91cfa = _u53d8_u91cfa + (function() | 173 | _u53d8_u91cfa = _u53d8_u91cfa + (function() |
175 | local _u53d8_u91cfa | 174 | local _u53d8_u91cfa = 1 |
176 | _u53d8_u91cfa = 1 | ||
177 | return _u53d8_u91cfa + 1 | 175 | return _u53d8_u91cfa + 1 |
178 | end)() | 176 | end)() |
179 | _u6253_u5370(_u53d8_u91cfa) | 177 | _u6253_u5370(_u53d8_u91cfa) |
@@ -217,24 +215,8 @@ do | |||
217 | -- 这有个注释 | 215 | -- 这有个注释 |
218 | end | 216 | end |
219 | local _ = require('下划线') | 217 | local _ = require('下划线') |
220 | local _call_0 = (_({ | 218 | local _anon_func_0 = function(_) |
221 | 1, | 219 | local _call_0 = (_({ |
222 | 2, | ||
223 | 3, | ||
224 | 4, | ||
225 | -2, | ||
226 | 3 | ||
227 | })) | ||
228 | _call_0 = _call_0["链"](_call_0) | ||
229 | _call_0 = _call_0["映射"](_call_0, function(self) | ||
230 | return self * 2 | ||
231 | end) | ||
232 | _call_0 = _call_0["过滤"](_call_0, function(self) | ||
233 | return self > 3 | ||
234 | end) | ||
235 | local _u7ed3_u679ca = _call_0["取值"](_call_0) | ||
236 | do | ||
237 | local _call_1 = (_({ | ||
238 | 1, | 220 | 1, |
239 | 2, | 221 | 2, |
240 | 3, | 222 | 3, |
@@ -242,27 +224,70 @@ do | |||
242 | -2, | 224 | -2, |
243 | 3 | 225 | 3 |
244 | })) | 226 | })) |
245 | _call_1 = _call_1["链"](_call_1) | 227 | return _call_0["链"](_call_0) |
246 | _call_1 = _call_1["映射"](_call_1, function(self) | 228 | end |
247 | return self * 2 | 229 | local _call_0 = ((function() |
248 | end) | 230 | local _call_0 = ((function() |
249 | _call_1 = _call_1["过滤"](_call_1, function(self) | 231 | local _call_0 = (_anon_func_0(_)) |
232 | return _call_0["映射"](_call_0, function(self) | ||
233 | return self * 2 | ||
234 | end) | ||
235 | end)()) | ||
236 | return _call_0["过滤"](_call_0, function(self) | ||
250 | return self > 3 | 237 | return self > 3 |
251 | end) | 238 | end) |
239 | end)()) | ||
240 | local _u7ed3_u679ca = _call_0["取值"](_call_0) | ||
241 | local _anon_func_1 = function(_) | ||
242 | local _call_1 = (_({ | ||
243 | 1, | ||
244 | 2, | ||
245 | 3, | ||
246 | 4, | ||
247 | -2, | ||
248 | 3 | ||
249 | })) | ||
250 | return _call_1["链"](_call_1) | ||
251 | end | ||
252 | do | ||
253 | local _call_1 = ((function() | ||
254 | local _call_1 = ((function() | ||
255 | local _call_1 = (_anon_func_1(_)) | ||
256 | return _call_1["映射"](_call_1, function(self) | ||
257 | return self * 2 | ||
258 | end) | ||
259 | end)()) | ||
260 | return _call_1["过滤"](_call_1, function(self) | ||
261 | return self > 3 | ||
262 | end) | ||
263 | end)()) | ||
252 | _call_1["每一个"](_call_1, function(self) | 264 | _call_1["每一个"](_call_1, function(self) |
253 | return _u6253_u5370(self) | 265 | return _u6253_u5370(self) |
254 | end) | 266 | end) |
255 | end | 267 | end |
256 | local _call_1 = _u539f_u70b9["变换"]["根节点"]["游戏对象"] | 268 | local _anon_func_2 = function(_u539f_u70b9) |
257 | _call_1 = _call_1["父节点"](_call_1) | 269 | local _call_1 = _u539f_u70b9["变换"]["根节点"]["游戏对象"] |
258 | _call_1 = _call_1["后代"](_call_1) | 270 | return _call_1["父节点"](_call_1) |
259 | _call_1 = _call_1["选择启用"](_call_1) | 271 | end |
260 | _call_1 = _call_1["选择可见"](_call_1) | 272 | local _call_1 = ((function() |
261 | _call_1 = _call_1["标签等于"](_call_1, "fx") | 273 | local _call_1 = ((function() |
262 | _call_1 = _call_1["其中"](_call_1, function(x) | 274 | local _call_1 = ((function() |
263 | local _call_2 = x["名称"] | 275 | local _call_1 = ((function() |
264 | return _call_2["结尾为"](_call_2, "(克隆)") | 276 | local _call_1 = ((function() |
265 | end) | 277 | local _call_1 = (_anon_func_2(_u539f_u70b9)) |
278 | return _call_1["后代"](_call_1) | ||
279 | end)()) | ||
280 | return _call_1["选择启用"](_call_1) | ||
281 | end)()) | ||
282 | return _call_1["选择可见"](_call_1) | ||
283 | end)()) | ||
284 | return _call_1["标签等于"](_call_1, "fx") | ||
285 | end)()) | ||
286 | return _call_1["其中"](_call_1, function(x) | ||
287 | local _call_2 = x["名称"] | ||
288 | return _call_2["结尾为"](_call_2, "(克隆)") | ||
289 | end) | ||
290 | end)()) | ||
266 | _u7ed3_u679c = _call_1["摧毁"](_call_1) | 291 | _u7ed3_u679c = _call_1["摧毁"](_call_1) |
267 | do | 292 | do |
268 | do | 293 | do |
@@ -334,10 +359,8 @@ local _1 | |||
334 | _1 = function() | 359 | _1 = function() |
335 | _u6253_u5370(1) | 360 | _u6253_u5370(1) |
336 | local _accum_0 = { } | 361 | local _accum_0 = { } |
337 | local _len_0 = 1 | ||
338 | while false do | 362 | while false do |
339 | break | 363 | break |
340 | _len_0 = _len_0 + 1 | ||
341 | end | 364 | end |
342 | return _accum_0 | 365 | return _accum_0 |
343 | end | 366 | end |
diff --git a/spec/outputs/unicode/multiline_chain.lua b/spec/outputs/unicode/multiline_chain.lua index c1da13f..61e7057 100644 --- a/spec/outputs/unicode/multiline_chain.lua +++ b/spec/outputs/unicode/multiline_chain.lua | |||
@@ -59,10 +59,8 @@ _u51fd_u6570 = function() | |||
59 | return _accum_0 | 59 | return _accum_0 |
60 | end | 60 | end |
61 | local _anon_func_0 = function(_u53d8_u91cfa) | 61 | local _anon_func_0 = function(_u53d8_u91cfa) |
62 | do | 62 | local _call_1 = _u53d8_u91cfa |
63 | local _call_1 = _u53d8_u91cfa | 63 | return (_call_1["变量b"](_call_1, 123))["变量c"]("abc") |
64 | return (_call_1["变量b"](_call_1, 123))["变量c"]("abc") | ||
65 | end | ||
66 | end | 64 | end |
67 | local _u51fd_u65701 | 65 | local _u51fd_u65701 |
68 | _u51fd_u65701 = function() | 66 | _u51fd_u65701 = function() |
diff --git a/spec/outputs/unicode/plus.lua b/spec/outputs/unicode/plus.lua index 75e4aac..adce62e 100644 --- a/spec/outputs/unicode/plus.lua +++ b/spec/outputs/unicode/plus.lua | |||
@@ -67,7 +67,6 @@ _u80cc_u5305 = { | |||
67 | local _u5f00_u59cb = { | 67 | local _u5f00_u59cb = { |
68 | ["东西"] = "冷" | 68 | ["东西"] = "冷" |
69 | } | 69 | } |
70 | local _u6d17_u6fa1 | 70 | local _u6d17_u6fa1 = { |
71 | _u6d17_u6fa1 = { | ||
72 | ["在"] = "火" | 71 | ["在"] = "火" |
73 | } | 72 | } |
diff --git a/spec/outputs/unicode/syntax.lua b/spec/outputs/unicode/syntax.lua index ea97bb9..a13302b 100644 --- a/spec/outputs/unicode/syntax.lua +++ b/spec/outputs/unicode/syntax.lua | |||
@@ -258,9 +258,11 @@ _u53d8_u91cfx = 0 | |||
258 | local _list_0 = _u503c | 258 | local _list_0 = _u503c |
259 | for _index_0 = 1, #_list_0 do | 259 | for _index_0 = 1, #_list_0 do |
260 | local _u53d8_u91cfv = _list_0[_index_0] | 260 | local _u53d8_u91cfv = _list_0[_index_0] |
261 | if ntype(_u53d8_u91cfv) == "函数定义" then | 261 | _ = ((function() |
262 | _ = _u53d8_u91cfx + 1 | 262 | if ntype(_u53d8_u91cfv) == "函数定义" then |
263 | end | 263 | return _u53d8_u91cfx + 1 |
264 | end | ||
265 | end)()) | ||
264 | end | 266 | end |
265 | _u4f60_u597d = { | 267 | _u4f60_u597d = { |
266 | ["某物"] = _u4e16_u754c, | 268 | ["某物"] = _u4e16_u754c, |
@@ -284,10 +286,8 @@ _ = 5 - _u4ec0_u4e48(_u65e0_u804a) | |||
284 | _u4ec0_u4e48(_u65e0_u804a - 5) | 286 | _u4ec0_u4e48(_u65e0_u804a - 5) |
285 | _u53d8_u91cfx = _u4f60_u597d - _u4e16_u754c - _u67d0_u7269 | 287 | _u53d8_u91cfx = _u4f60_u597d - _u4e16_u754c - _u67d0_u7269 |
286 | local _anon_func_0 = function(_u4ec0_u4e48) | 288 | local _anon_func_0 = function(_u4ec0_u4e48) |
287 | do | 289 | local _call_8 = _u4ec0_u4e48 |
288 | local _call_8 = _u4ec0_u4e48 | 290 | return _call_8["酷"](_call_8, 100) |
289 | return _call_8["酷"](_call_8, 100) | ||
290 | end | ||
291 | end | 291 | end |
292 | (function(_u67d0_u7269) | 292 | (function(_u67d0_u7269) |
293 | if _u67d0_u7269 == nil then | 293 | if _u67d0_u7269 == nil then |
diff --git a/spec/outputs/unicode/try_catch.lua b/spec/outputs/unicode/try_catch.lua index 22f29f9..f8c7849 100644 --- a/spec/outputs/unicode/try_catch.lua +++ b/spec/outputs/unicode/try_catch.lua | |||
@@ -32,11 +32,13 @@ pcall(function() | |||
32 | return _u8868["函数"]() | 32 | return _u8868["函数"]() |
33 | end) | 33 | end) |
34 | pcall(function() | 34 | pcall(function() |
35 | return _u8868["函数"]() | 35 | return (_u8868["函数"]()) |
36 | end) | 36 | end) |
37 | pcall(function() | 37 | pcall(function() |
38 | local _call_0 = _u8868 | 38 | return ((function() |
39 | return _call_0["函数"](_call_0, 1, 2, 3) | 39 | local _call_0 = _u8868 |
40 | return _call_0["函数"](_call_0, 1, 2, 3) | ||
41 | end)()) | ||
40 | end) | 42 | end) |
41 | pcall(function() | 43 | pcall(function() |
42 | return _u8868["函数"](1) | 44 | return _u8868["函数"](1) |
@@ -52,7 +54,7 @@ end)) then | |||
52 | _u6253_u5370("好的") | 54 | _u6253_u5370("好的") |
53 | end | 55 | end |
54 | if xpcall(function() | 56 | if xpcall(function() |
55 | return _u51fd_u6570(1) | 57 | return (_u51fd_u6570(1)) |
56 | end, function(_u9519_u8bef) | 58 | end, function(_u9519_u8bef) |
57 | return _u6253_u5370(_u9519_u8bef) | 59 | return _u6253_u5370(_u9519_u8bef) |
58 | end) then | 60 | end) then |
diff --git a/spec/outputs/unicode/vararg.lua b/spec/outputs/unicode/vararg.lua index b837006..fc894ff 100644 --- a/spec/outputs/unicode/vararg.lua +++ b/spec/outputs/unicode/vararg.lua | |||
@@ -125,14 +125,10 @@ local _anon_func_11 = function(_u9879_u76ee, ...) | |||
125 | return _tbl_0 | 125 | return _tbl_0 |
126 | end | 126 | end |
127 | local _anon_func_12 = function(_u51fd_u6570) | 127 | local _anon_func_12 = function(_u51fd_u6570) |
128 | do | 128 | return _u51fd_u6570() |
129 | return _u51fd_u6570() | ||
130 | end | ||
131 | end | 129 | end |
132 | local _anon_func_13 = function(_u51fd_u6570, ...) | 130 | local _anon_func_13 = function(_u51fd_u6570, ...) |
133 | do | 131 | return _u51fd_u6570(...) |
134 | return _u51fd_u6570(...) | ||
135 | end | ||
136 | end | 132 | end |
137 | local _anon_func_14 = function(_u51fd_u6570) | 133 | local _anon_func_14 = function(_u51fd_u6570) |
138 | local _accum_0 = { } | 134 | local _accum_0 = { } |
@@ -195,15 +191,11 @@ local _anon_func_23 = function(_u51fd_u6570, ...) | |||
195 | return nil | 191 | return nil |
196 | end | 192 | end |
197 | local _anon_func_24 = function(_u6253_u5370, select, ...) | 193 | local _anon_func_24 = function(_u6253_u5370, select, ...) |
198 | do | 194 | _u6253_u5370(select("#", ...)) |
199 | _u6253_u5370(select("#", ...)) | 195 | return _u6253_u5370(...) |
200 | return _u6253_u5370(...) | ||
201 | end | ||
202 | end | 196 | end |
203 | local _anon_func_25 = function(_u6253_u5370, ...) | 197 | local _anon_func_25 = function(_u6253_u5370, ...) |
204 | do | 198 | return _u6253_u5370(...) |
205 | return _u6253_u5370(...) | ||
206 | end | ||
207 | end | 199 | end |
208 | local _anon_func_26 = function(_u53d8_u91cfx, _u8868, _u88682) | 200 | local _anon_func_26 = function(_u53d8_u91cfx, _u8868, _u88682) |
209 | if 1 == _u53d8_u91cfx then | 201 | if 1 == _u53d8_u91cfx then |
@@ -214,9 +206,7 @@ local _anon_func_26 = function(_u53d8_u91cfx, _u8868, _u88682) | |||
214 | end | 206 | end |
215 | end | 207 | end |
216 | local _anon_func_27 = function(_u6253_u5370, ...) | 208 | local _anon_func_27 = function(_u6253_u5370, ...) |
217 | do | 209 | return _u6253_u5370(...) |
218 | return _u6253_u5370(...) | ||
219 | end | ||
220 | end | 210 | end |
221 | local _anon_func_28 = function(_u6761_u4ef6) | 211 | local _anon_func_28 = function(_u6761_u4ef6) |
222 | if _u6761_u4ef6 then | 212 | if _u6761_u4ef6 then |
@@ -224,10 +214,8 @@ local _anon_func_28 = function(_u6761_u4ef6) | |||
224 | end | 214 | end |
225 | end | 215 | end |
226 | local _anon_func_29 = function(_u6253_u5370, _arg_0, ...) | 216 | local _anon_func_29 = function(_u6253_u5370, _arg_0, ...) |
227 | do | 217 | local _u8868 = _arg_0 |
228 | local _u8868 = _arg_0 | 218 | return _u6253_u5370(...) |
229 | return _u6253_u5370(...) | ||
230 | end | ||
231 | end | 219 | end |
232 | local _u8fde_u63a5 | 220 | local _u8fde_u63a5 |
233 | _u8fde_u63a5 = function(...) | 221 | _u8fde_u63a5 = function(...) |
diff --git a/spec/outputs/unicode/with.lua b/spec/outputs/unicode/with.lua index 7a5ba00..3a32a27 100644 --- a/spec/outputs/unicode/with.lua +++ b/spec/outputs/unicode/with.lua | |||
@@ -161,17 +161,15 @@ do | |||
161 | } | 161 | } |
162 | end | 162 | end |
163 | do | 163 | do |
164 | do | 164 | local _with_0 = _u5b9e_u5fc3_u77e9_u5f62({ |
165 | local _with_0 = _u5b9e_u5fc3_u77e9_u5f62({ | 165 | ["宽"] = w, |
166 | ["宽"] = w, | 166 | ["高"] = h, |
167 | ["高"] = h, | 167 | ["颜色"] = 0x66000000 |
168 | ["颜色"] = 0x66000000 | 168 | }) |
169 | }) | 169 | _u63a9_u7801 = _with_0 |
170 | _u63a9_u7801 = _with_0 | 170 | if _with_0 ~= nil then |
171 | if _with_0 ~= nil then | 171 | _with_0["触摸启用"] = true |
172 | _with_0["触摸启用"] = true | 172 | _with_0["吞噬触摸"] = true |
173 | _with_0["吞噬触摸"] = true | ||
174 | end | ||
175 | end | 173 | end |
176 | end | 174 | end |
177 | do | 175 | do |
diff --git a/spec/outputs/upvalue_func.lua b/spec/outputs/upvalue_func.lua index 3181adf..3e088be 100644 --- a/spec/outputs/upvalue_func.lua +++ b/spec/outputs/upvalue_func.lua | |||
@@ -214,10 +214,8 @@ local _anon_func_1 = function(valueB) | |||
214 | end | 214 | end |
215 | end | 215 | end |
216 | local _anon_func_2 = function(print, select, _arg_0, ...) | 216 | local _anon_func_2 = function(print, select, _arg_0, ...) |
217 | do | 217 | local ok = _arg_0 |
218 | local ok = _arg_0 | 218 | return print(select(3, ...)) |
219 | return print(select(3, ...)) | ||
220 | end | ||
221 | end | 219 | end |
222 | local _anon_func_3 = function(tb) | 220 | local _anon_func_3 = function(tb) |
223 | if tb ~= nil then | 221 | if tb ~= nil then |
@@ -242,11 +240,9 @@ local _anon_func_5 = function(getmetatable, tb) | |||
242 | return _obj_0[1 + 1](_obj_0, "abc") | 240 | return _obj_0[1 + 1](_obj_0, "abc") |
243 | end | 241 | end |
244 | local _anon_func_6 = function(tb) | 242 | local _anon_func_6 = function(tb) |
245 | do | 243 | local _call_0 = tb |
246 | local _call_0 = tb | 244 | local _call_1 = _call_0["end"](_call_0) |
247 | local _call_1 = _call_0["end"](_call_0) | 245 | return _call_1["🤣"](_call_1, 123) |
248 | return _call_1["🤣"](_call_1, 123) | ||
249 | end | ||
250 | end | 246 | end |
251 | local _anon_func_7 = function(itemA, listA) | 247 | local _anon_func_7 = function(itemA, listA) |
252 | for _index_0 = 1, #listA do | 248 | for _index_0 = 1, #listA do |
@@ -354,17 +350,13 @@ local _anon_func_16 = function(pairs, tb, tostring) | |||
354 | return _tbl_0 | 350 | return _tbl_0 |
355 | end | 351 | end |
356 | local _anon_func_17 = function(print) | 352 | local _anon_func_17 = function(print) |
357 | do | 353 | print(123) |
358 | print(123) | 354 | return "abc" |
359 | return "abc" | ||
360 | end | ||
361 | end | 355 | end |
362 | local _anon_func_18 = function(print, select, _arg_0, ...) | 356 | local _anon_func_18 = function(print, select, _arg_0, ...) |
363 | do | 357 | local success = _arg_0 |
364 | local success = _arg_0 | 358 | if success then |
365 | if success then | 359 | return print(select('#', ...)) |
366 | return print(select('#', ...)) | ||
367 | end | ||
368 | end | 360 | end |
369 | end | 361 | end |
370 | local _anon_func_19 = function(cond, i) | 362 | local _anon_func_19 = function(cond, i) |
@@ -459,11 +451,9 @@ local _anon_func_25 = function(itemA, listA) | |||
459 | return false | 451 | return false |
460 | end | 452 | end |
461 | local _anon_func_24 = function(itemA, listA, tb) | 453 | local _anon_func_24 = function(itemA, listA, tb) |
462 | do | 454 | local _call_0 = tb |
463 | local _call_0 = tb | 455 | local _call_1 = _call_0["end"](_call_0) |
464 | local _call_1 = _call_0["end"](_call_0) | 456 | return _call_1["🤣"](_call_1, 123 and (#listA > 0 and _anon_func_25(itemA, listA))) |
465 | return _call_1["🤣"](_call_1, 123 and (#listA > 0 and _anon_func_25(itemA, listA))) | ||
466 | end | ||
467 | end | 457 | end |
468 | GameEngine:onEvent("SomeEvent", function() | 458 | GameEngine:onEvent("SomeEvent", function() |
469 | return func(value + (_anon_func_21(cond)) + (_anon_func_22(valueB)) > _anon_func_23(tb) + _anon_func_24(itemA, listA, tb)) | 459 | return func(value + (_anon_func_21(cond)) + (_anon_func_22(valueB)) > _anon_func_23(tb) + _anon_func_24(itemA, listA, tb)) |
@@ -503,13 +493,11 @@ local _anon_func_27 = function(char) | |||
503 | return nil | 493 | return nil |
504 | end | 494 | end |
505 | local _anon_func_28 = function(os, _arg_0, ...) | 495 | local _anon_func_28 = function(os, _arg_0, ...) |
506 | do | 496 | local ok = _arg_0 |
507 | local ok = _arg_0 | 497 | if ok then |
508 | if ok then | 498 | return ... |
509 | return ... | 499 | else |
510 | else | 500 | return os.exit(1) |
511 | return os.exit(1) | ||
512 | end | ||
513 | end | 501 | end |
514 | end | 502 | end |
515 | local _anon_func_29 = function(debug_env_after, debug_env_before, env, func) | 503 | local _anon_func_29 = function(debug_env_after, debug_env_before, env, func) |
diff --git a/spec/outputs/vararg.lua b/spec/outputs/vararg.lua index dabba44..254aa6a 100644 --- a/spec/outputs/vararg.lua +++ b/spec/outputs/vararg.lua | |||
@@ -125,14 +125,10 @@ local _anon_func_11 = function(items, ...) | |||
125 | return _tbl_0 | 125 | return _tbl_0 |
126 | end | 126 | end |
127 | local _anon_func_12 = function(func) | 127 | local _anon_func_12 = function(func) |
128 | do | 128 | return func() |
129 | return func() | ||
130 | end | ||
131 | end | 129 | end |
132 | local _anon_func_13 = function(func, ...) | 130 | local _anon_func_13 = function(func, ...) |
133 | do | 131 | return func(...) |
134 | return func(...) | ||
135 | end | ||
136 | end | 132 | end |
137 | local _anon_func_14 = function(func) | 133 | local _anon_func_14 = function(func) |
138 | local _accum_0 = { } | 134 | local _accum_0 = { } |
@@ -195,15 +191,11 @@ local _anon_func_23 = function(func, ...) | |||
195 | return nil | 191 | return nil |
196 | end | 192 | end |
197 | local _anon_func_24 = function(print, select, ...) | 193 | local _anon_func_24 = function(print, select, ...) |
198 | do | 194 | print(select("#", ...)) |
199 | print(select("#", ...)) | 195 | return print(...) |
200 | return print(...) | ||
201 | end | ||
202 | end | 196 | end |
203 | local _anon_func_25 = function(print, ...) | 197 | local _anon_func_25 = function(print, ...) |
204 | do | 198 | return print(...) |
205 | return print(...) | ||
206 | end | ||
207 | end | 199 | end |
208 | local _anon_func_26 = function(tb, tb2, x) | 200 | local _anon_func_26 = function(tb, tb2, x) |
209 | if 1 == x then | 201 | if 1 == x then |
@@ -214,9 +206,7 @@ local _anon_func_26 = function(tb, tb2, x) | |||
214 | end | 206 | end |
215 | end | 207 | end |
216 | local _anon_func_27 = function(print, ...) | 208 | local _anon_func_27 = function(print, ...) |
217 | do | 209 | return print(...) |
218 | return print(...) | ||
219 | end | ||
220 | end | 210 | end |
221 | local _anon_func_28 = function(cond) | 211 | local _anon_func_28 = function(cond) |
222 | if cond then | 212 | if cond then |
@@ -224,10 +214,8 @@ local _anon_func_28 = function(cond) | |||
224 | end | 214 | end |
225 | end | 215 | end |
226 | local _anon_func_29 = function(print, _arg_0, ...) | 216 | local _anon_func_29 = function(print, _arg_0, ...) |
227 | do | 217 | local tb = _arg_0 |
228 | local tb = _arg_0 | 218 | return print(...) |
229 | return print(...) | ||
230 | end | ||
231 | end | 219 | end |
232 | local join | 220 | local join |
233 | join = function(...) | 221 | join = function(...) |
diff --git a/spec/outputs/with.lua b/spec/outputs/with.lua index 5d33bdb..530915e 100644 --- a/spec/outputs/with.lua +++ b/spec/outputs/with.lua | |||
@@ -158,17 +158,15 @@ do | |||
158 | } | 158 | } |
159 | end | 159 | end |
160 | do | 160 | do |
161 | do | 161 | local _with_0 = SolidRect({ |
162 | local _with_0 = SolidRect({ | 162 | width = w, |
163 | width = w, | 163 | height = h, |
164 | height = h, | 164 | color = 0x66000000 |
165 | color = 0x66000000 | 165 | }) |
166 | }) | 166 | mask = _with_0 |
167 | mask = _with_0 | 167 | if _with_0 ~= nil then |
168 | if _with_0 ~= nil then | 168 | _with_0.touchEnabled = true |
169 | _with_0.touchEnabled = true | 169 | _with_0.swallowTouches = true |
170 | _with_0.swallowTouches = true | ||
171 | end | ||
172 | end | 170 | end |
173 | end | 171 | end |
174 | do | 172 | do |
@@ -189,4 +187,66 @@ do | |||
189 | return _with_0[123] | 187 | return _with_0[123] |
190 | end | 188 | end |
191 | end | 189 | end |
190 | do | ||
191 | f((function() | ||
192 | local _with_0 = item | ||
193 | do | ||
194 | local _accum_0 | ||
195 | repeat | ||
196 | if _with_0.id > 0 then | ||
197 | _accum_0 = _with_0.content | ||
198 | break | ||
199 | end | ||
200 | until true | ||
201 | _with_0 = _accum_0 | ||
202 | end | ||
203 | return _with_0 | ||
204 | end)()) | ||
205 | local a | ||
206 | do | ||
207 | local _with_0 = tb | ||
208 | do | ||
209 | local _accum_0 | ||
210 | repeat | ||
211 | if _with_0.v then | ||
212 | _accum_0 = _with_0.a | ||
213 | break | ||
214 | end | ||
215 | until true | ||
216 | _with_0 = _accum_0 | ||
217 | end | ||
218 | a = _with_0 | ||
219 | end | ||
220 | local _accum_0 | ||
221 | while true do | ||
222 | local _with_0 = tb | ||
223 | local _accum_1 | ||
224 | repeat | ||
225 | if _with_0 ~= nil then | ||
226 | _accum_1 = 1 | ||
227 | break | ||
228 | end | ||
229 | until true | ||
230 | _with_0 = _accum_1 | ||
231 | _accum_0 = _with_0 | ||
232 | break | ||
233 | end | ||
234 | a = _accum_0 | ||
235 | end | ||
236 | do | ||
237 | local a | ||
238 | local _accum_0 | ||
239 | for i = 1, 100 do | ||
240 | local x = tb[i] | ||
241 | if x ~= nil then | ||
242 | local _des_0 = 1 | ||
243 | if _des_0 then | ||
244 | x.id = _des_0 | ||
245 | _accum_0 = x | ||
246 | break | ||
247 | end | ||
248 | end | ||
249 | end | ||
250 | a = _accum_0 | ||
251 | end | ||
192 | return nil | 252 | return nil |