diff options
Diffstat (limited to 'spec/outputs')
38 files changed, 5136 insertions, 252 deletions
diff --git a/spec/outputs/5.1/import_global.lua b/spec/outputs/5.1/import_global.lua new file mode 100644 index 0000000..3b8334a --- /dev/null +++ b/spec/outputs/5.1/import_global.lua | |||
| @@ -0,0 +1,131 @@ | |||
| 1 | do | ||
| 2 | local print = print | ||
| 3 | local math = math | ||
| 4 | print("hello") | ||
| 5 | math.random(10) | ||
| 6 | end | ||
| 7 | do | ||
| 8 | local print = print | ||
| 9 | local value = 1 | ||
| 10 | value = value + 2 | ||
| 11 | print(value) | ||
| 12 | end | ||
| 13 | do | ||
| 14 | local print | ||
| 15 | print = function(msg) | ||
| 16 | return msg | ||
| 17 | end | ||
| 18 | do | ||
| 19 | local math = math | ||
| 20 | print("local") | ||
| 21 | math.random(1) | ||
| 22 | end | ||
| 23 | end | ||
| 24 | do | ||
| 25 | local print = print | ||
| 26 | local tostring | ||
| 27 | tostring = function(v) | ||
| 28 | return "local" | ||
| 29 | end | ||
| 30 | tostring("value") | ||
| 31 | print(tostring(123)) | ||
| 32 | end | ||
| 33 | do | ||
| 34 | local func | ||
| 35 | func = function(x, y) | ||
| 36 | local type = type | ||
| 37 | local tostring = tostring | ||
| 38 | local print = print | ||
| 39 | return type(x, tostring(y, print)) | ||
| 40 | end | ||
| 41 | func(1, 2) | ||
| 42 | end | ||
| 43 | do | ||
| 44 | local xpcall = xpcall | ||
| 45 | local func = func | ||
| 46 | local world = world | ||
| 47 | local tostring = tostring | ||
| 48 | local print = print | ||
| 49 | xpcall(function() | ||
| 50 | return func("hello " .. tostring(world)) | ||
| 51 | end, function(err) | ||
| 52 | return print(err) | ||
| 53 | end) | ||
| 54 | end | ||
| 55 | do | ||
| 56 | local print = print | ||
| 57 | print(FLAG) | ||
| 58 | FLAG = 123 | ||
| 59 | end | ||
| 60 | do | ||
| 61 | local print = print | ||
| 62 | Foo = 10 | ||
| 63 | print(Foo) | ||
| 64 | Foo = Foo + 2 | ||
| 65 | end | ||
| 66 | do | ||
| 67 | local print = print | ||
| 68 | Bar = 1 | ||
| 69 | Baz = 2 | ||
| 70 | print(Bar, Baz) | ||
| 71 | end | ||
| 72 | do | ||
| 73 | local y = y | ||
| 74 | x = 3434 | ||
| 75 | if y then | ||
| 76 | x = 10 | ||
| 77 | end | ||
| 78 | end | ||
| 79 | do | ||
| 80 | local lowercase = lowercase | ||
| 81 | local tostring = tostring | ||
| 82 | local Uppercase = Uppercase | ||
| 83 | local foobar = "all " .. tostring(lowercase) | ||
| 84 | FooBar = "pascal case" | ||
| 85 | FOOBAR = "all " .. tostring(Uppercase) | ||
| 86 | end | ||
| 87 | do | ||
| 88 | local setmetatable = setmetatable | ||
| 89 | local print = print | ||
| 90 | do | ||
| 91 | local _class_0 | ||
| 92 | local _base_0 = { } | ||
| 93 | if _base_0.__index == nil then | ||
| 94 | _base_0.__index = _base_0 | ||
| 95 | end | ||
| 96 | _class_0 = setmetatable({ | ||
| 97 | __init = function() end, | ||
| 98 | __base = _base_0, | ||
| 99 | __name = "A" | ||
| 100 | }, { | ||
| 101 | __index = _base_0, | ||
| 102 | __call = function(cls, ...) | ||
| 103 | local _self_0 = setmetatable({ }, _base_0) | ||
| 104 | cls.__init(_self_0, ...) | ||
| 105 | return _self_0 | ||
| 106 | end | ||
| 107 | }) | ||
| 108 | _base_0.__class = _class_0 | ||
| 109 | A = _class_0 | ||
| 110 | end | ||
| 111 | Flag = 1 | ||
| 112 | const, x, y = "const", 1, 2 | ||
| 113 | print(math, table) | ||
| 114 | end | ||
| 115 | do | ||
| 116 | local X = X | ||
| 117 | X:func(1, 2, 3) | ||
| 118 | X.tag = "abc" | ||
| 119 | end | ||
| 120 | local _anon_func_0 = function(func) | ||
| 121 | return func | ||
| 122 | end | ||
| 123 | do | ||
| 124 | local func = func | ||
| 125 | local pcall = pcall | ||
| 126 | local f | ||
| 127 | f = function() | ||
| 128 | func() | ||
| 129 | return pcall(_anon_func_0, func) | ||
| 130 | end | ||
| 131 | end | ||
diff --git a/spec/outputs/5.1/literals.lua b/spec/outputs/5.1/literals.lua deleted file mode 100644 index 36c705a..0000000 --- a/spec/outputs/5.1/literals.lua +++ /dev/null | |||
| @@ -1,44 +0,0 @@ | |||
| 1 | local _ = { | ||
| 2 | 121, | ||
| 3 | 121.2323, | ||
| 4 | 121.2323e-1, | ||
| 5 | 121.2323e13434, | ||
| 6 | 2323E34, | ||
| 7 | 0x12323, | ||
| 8 | 0xfF2323, | ||
| 9 | 0xabcdef, | ||
| 10 | 0xABCDEF, | ||
| 11 | 0XFBC400, | ||
| 12 | 2.7365508487142853e-35, | ||
| 13 | 0xABCP321, | ||
| 14 | 2.4074124304840448e-35, | ||
| 15 | 6.4326233113470805e-94, | ||
| 16 | 0.1171875, | ||
| 17 | 162.1875, | ||
| 18 | 3.1415926535897931, | ||
| 19 | 1, | ||
| 20 | 8, | ||
| 21 | 15, | ||
| 22 | 201, | ||
| 23 | .2323, | ||
| 24 | .2323e-1, | ||
| 25 | .2323e13434, | ||
| 26 | 1LL, | ||
| 27 | 1ULL, | ||
| 28 | 9332LL, | ||
| 29 | 9332, | ||
| 30 | 0x2aLL, | ||
| 31 | 0x2aULL, | ||
| 32 | 1000000.0000001, | ||
| 33 | 1234e5678, | ||
| 34 | 1234E-5678, | ||
| 35 | 0xDEADBEEF, | ||
| 36 | [[ hello world ]], | ||
| 37 | [=[ hello world ]=], | ||
| 38 | [====[ hello world ]====], | ||
| 39 | "another world", | ||
| 40 | 'what world', | ||
| 41 | "\n hello world\n ", | ||
| 42 | 'yeah\n what is going on\n here is something cool' | ||
| 43 | } | ||
| 44 | return nil | ||
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 efd92c6..d2b58bc 100644 --- a/spec/outputs/5.1/try_catch.lua +++ b/spec/outputs/5.1/try_catch.lua | |||
| @@ -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() |
| @@ -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 162c5a8..89c5f8a 100644 --- a/spec/outputs/assign.lua +++ b/spec/outputs/assign.lua | |||
| @@ -43,10 +43,8 @@ do | |||
| 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)) |
diff --git a/spec/outputs/codes_from_doc.lua b/spec/outputs/codes_from_doc.lua index f6d5d61..3b0724a 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, |
| @@ -41,8 +73,8 @@ local apple = setmetatable({ | |||
| 41 | if (getmetatable(apple) ~= nil) then | 73 | if (getmetatable(apple) ~= nil) then |
| 42 | p(apple.size, apple.color, getmetatable(apple).__index) | 74 | p(apple.size, apple.color, getmetatable(apple).__index) |
| 43 | end | 75 | end |
| 44 | local _ud83c_udf1b = "月之脚本" | 76 | local _u1f31b = "月之脚本" |
| 45 | _module_0["🌛"] = _ud83c_udf1b | 77 | _module_0["🌛"] = _u1f31b |
| 46 | return _module_0 | 78 | return _module_0 |
| 47 | local area = 6.2831853071796 * 5 | 79 | local area = 6.2831853071796 * 5 |
| 48 | print('hello world') | 80 | print('hello world') |
| @@ -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 |
| @@ -109,6 +147,21 @@ print((function() | |||
| 109 | end)()) | 147 | end)()) |
| 110 | local tab = { } | 148 | local tab = { } |
| 111 | tab[#tab + 1] = "Value" | 149 | tab[#tab + 1] = "Value" |
| 150 | local tbA = { | ||
| 151 | 1, | ||
| 152 | 2, | ||
| 153 | 3 | ||
| 154 | } | ||
| 155 | local tbB = { | ||
| 156 | 4, | ||
| 157 | 5, | ||
| 158 | 6 | ||
| 159 | } | ||
| 160 | local _len_0 = #tbA + 1 | ||
| 161 | for _index_0 = 1, #tbB do | ||
| 162 | local _elm_0 = tbB[_index_0] | ||
| 163 | tbA[_len_0], _len_0 = _elm_0, _len_0 + 1 | ||
| 164 | end | ||
| 112 | local parts = { | 165 | local parts = { |
| 113 | "shoulders", | 166 | "shoulders", |
| 114 | "knees" | 167 | "knees" |
| @@ -177,6 +230,18 @@ for _key_0, _value_0 in pairs(b) do | |||
| 177 | end | 230 | end |
| 178 | end | 231 | end |
| 179 | merge = _tab_0 | 232 | merge = _tab_0 |
| 233 | local last | ||
| 234 | do | ||
| 235 | local _item_0 = data.items | ||
| 236 | last = _item_0[#_item_0] | ||
| 237 | end | ||
| 238 | local second_last | ||
| 239 | do | ||
| 240 | local _item_0 = data.items | ||
| 241 | second_last = _item_0[#_item_0 - 1] | ||
| 242 | end | ||
| 243 | local _obj_0 = data.items | ||
| 244 | _obj_0[#_obj_0] = 1 | ||
| 180 | local mt = { } | 245 | local mt = { } |
| 181 | local add | 246 | local add |
| 182 | add = function(self, right) | 247 | add = function(self, right) |
| @@ -307,6 +372,14 @@ func({ | |||
| 307 | 2, | 372 | 2, |
| 308 | 3 | 373 | 3 |
| 309 | }) | 374 | }) |
| 375 | local f | ||
| 376 | f = function() | ||
| 377 | return { | ||
| 378 | 1, | ||
| 379 | 2, | ||
| 380 | 3 | ||
| 381 | } | ||
| 382 | end | ||
| 310 | local tb = { | 383 | local tb = { |
| 311 | name = "abc", | 384 | name = "abc", |
| 312 | values = { | 385 | values = { |
| @@ -368,6 +441,25 @@ do | |||
| 368 | local _obj_0 = require("export") | 441 | local _obj_0 = require("export") |
| 369 | one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] | 442 | one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] |
| 370 | end | 443 | end |
| 444 | do | ||
| 445 | local tostring <const> = tostring | ||
| 446 | local concat <const> = table.concat | ||
| 447 | print(concat({ | ||
| 448 | "a", | ||
| 449 | tostring(1) | ||
| 450 | })) | ||
| 451 | end | ||
| 452 | do | ||
| 453 | local print <const> = print | ||
| 454 | local math <const> = math | ||
| 455 | print("hello") | ||
| 456 | math.random(3) | ||
| 457 | end | ||
| 458 | do | ||
| 459 | local print <const> = print | ||
| 460 | print(FLAG) | ||
| 461 | FLAG = 123 | ||
| 462 | end | ||
| 371 | local _module_0 = { } | 463 | local _module_0 = { } |
| 372 | local a, b, c = 1, 2, 3 | 464 | local a, b, c = 1, 2, 3 |
| 373 | _module_0["a"], _module_0["b"], _module_0["c"] = a, b, c | 465 | _module_0["a"], _module_0["b"], _module_0["c"] = a, b, c |
| @@ -547,6 +639,59 @@ end | |||
| 547 | local two, four | 639 | local two, four |
| 548 | local _obj_0 = items | 640 | local _obj_0 = items |
| 549 | two, four = _obj_0[2], _obj_0[4] | 641 | two, four = _obj_0[2], _obj_0[4] |
| 642 | local orders = { | ||
| 643 | "first", | ||
| 644 | "second", | ||
| 645 | "third", | ||
| 646 | "fourth", | ||
| 647 | "last" | ||
| 648 | } | ||
| 649 | local first, bulk, last = orders[1], (function() | ||
| 650 | local _accum_0 = { } | ||
| 651 | local _len_0 = 1 | ||
| 652 | local _max_0 = #orders + -2 + 1 | ||
| 653 | for _index_0 = 2, _max_0 do | ||
| 654 | local _item_0 = orders[_index_0] | ||
| 655 | _accum_0[_len_0] = _item_0 | ||
| 656 | _len_0 = _len_0 + 1 | ||
| 657 | end | ||
| 658 | return _accum_0 | ||
| 659 | end)(), orders[#orders] | ||
| 660 | print(first) | ||
| 661 | print(bulk) | ||
| 662 | print(last) | ||
| 663 | local first, rest | ||
| 664 | do | ||
| 665 | local _obj_0 = orders | ||
| 666 | first, rest = _obj_0[1], (function() | ||
| 667 | local _accum_0 = { } | ||
| 668 | local _len_0 = 1 | ||
| 669 | local _max_0 = #_obj_0 | ||
| 670 | for _index_0 = 2, _max_0 do | ||
| 671 | local _item_0 = _obj_0[_index_0] | ||
| 672 | _accum_0[_len_0] = _item_0 | ||
| 673 | _len_0 = _len_0 + 1 | ||
| 674 | end | ||
| 675 | return _accum_0 | ||
| 676 | end)() | ||
| 677 | end | ||
| 678 | local start, last | ||
| 679 | do | ||
| 680 | local _obj_0 = orders | ||
| 681 | start, last = (function() | ||
| 682 | local _accum_0 = { } | ||
| 683 | local _len_0 = 1 | ||
| 684 | local _max_0 = #_obj_0 + -2 + 1 | ||
| 685 | for _index_0 = 1, _max_0 do | ||
| 686 | local _item_0 = _obj_0[_index_0] | ||
| 687 | _accum_0[_len_0] = _item_0 | ||
| 688 | _len_0 = _len_0 + 1 | ||
| 689 | end | ||
| 690 | return _accum_0 | ||
| 691 | end)(), _obj_0[#_obj_0] | ||
| 692 | end | ||
| 693 | local _obj_0 = orders | ||
| 694 | first, last = _obj_0[1], _obj_0[#_obj_0] | ||
| 550 | local tuples = { | 695 | local tuples = { |
| 551 | { | 696 | { |
| 552 | "hello", | 697 | "hello", |
| @@ -611,6 +756,9 @@ end | |||
| 611 | local first = select(1, ...) | 756 | local first = select(1, ...) |
| 612 | return print(ok, count, first) | 757 | return print(ok, count, first) |
| 613 | end)(fn(true)) | 758 | end)(fn(true)) |
| 759 | local a = 1 | ||
| 760 | local b = 2 | ||
| 761 | print(a + b) | ||
| 614 | Rx.Observable.fromRange(1, 8):filter(function(x) | 762 | Rx.Observable.fromRange(1, 8):filter(function(x) |
| 615 | return x % 2 == 0 | 763 | return x % 2 == 0 |
| 616 | end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) | 764 | end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) |
| @@ -648,6 +796,56 @@ end) | |||
| 648 | if success then | 796 | if success then |
| 649 | print(result) | 797 | print(result) |
| 650 | end | 798 | end |
| 799 | local a, b, c | ||
| 800 | do | ||
| 801 | local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function() | ||
| 802 | return func() | ||
| 803 | end) | ||
| 804 | if _ok_0 then | ||
| 805 | a, b, c = _ret_0, _ret_1, _ret_2 | ||
| 806 | end | ||
| 807 | end | ||
| 808 | do | ||
| 809 | local _exp_0 = ((function() | ||
| 810 | return (function(_arg_0, ...) | ||
| 811 | local _ok_0 = _arg_0 | ||
| 812 | if _ok_0 then | ||
| 813 | return ... | ||
| 814 | end | ||
| 815 | end)(pcall(function() | ||
| 816 | return func() | ||
| 817 | end)) | ||
| 818 | end)()) | ||
| 819 | if _exp_0 ~= nil then | ||
| 820 | a = _exp_0 | ||
| 821 | else | ||
| 822 | a = "default" | ||
| 823 | end | ||
| 824 | end | ||
| 825 | f((function() | ||
| 826 | return (function(_arg_0, ...) | ||
| 827 | local _ok_0 = _arg_0 | ||
| 828 | if _ok_0 then | ||
| 829 | return ... | ||
| 830 | end | ||
| 831 | end)(pcall(function() | ||
| 832 | return func() | ||
| 833 | end)) | ||
| 834 | end)()) | ||
| 835 | f((function() | ||
| 836 | return (function(_arg_0, ...) | ||
| 837 | local _ok_0 = _arg_0 | ||
| 838 | if _ok_0 then | ||
| 839 | return ... | ||
| 840 | end | ||
| 841 | end)(xpcall(function() | ||
| 842 | print(123) | ||
| 843 | return func() | ||
| 844 | end, function(e) | ||
| 845 | print(e) | ||
| 846 | return e | ||
| 847 | end)) | ||
| 848 | end)()) | ||
| 651 | local a <const> = 123 | 849 | local a <const> = 123 |
| 652 | local _ <close> = setmetatable({ }, { | 850 | local _ <close> = setmetatable({ }, { |
| 653 | __close = function() | 851 | __close = function() |
| @@ -657,10 +855,19 @@ local _ <close> = setmetatable({ }, { | |||
| 657 | local a, b, c, d | 855 | local a, b, c, d |
| 658 | local _obj_0 = tb | 856 | local _obj_0 = tb |
| 659 | a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] | 857 | a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] |
| 858 | Constant = 123 | ||
| 660 | local some_string = "Here is a string\n that has a line break in it." | 859 | local some_string = "Here is a string\n that has a line break in it." |
| 661 | print("I am " .. tostring(math.random() * 100) .. "% sure.") | 860 | print("I am " .. tostring(math.random() * 100) .. "% sure.") |
| 662 | local integer = 1000000 | 861 | local integer = 1000000 |
| 663 | local hex = 0xEFBBBF | 862 | local hex = 0xEFBBBF |
| 863 | local binary = 19 | ||
| 864 | local str = "key: value\nlist:\n - item1\n - " .. tostring(expr) | ||
| 865 | local fn | ||
| 866 | fn = function() | ||
| 867 | local str = "foo:\n bar: baz" | ||
| 868 | return str | ||
| 869 | end | ||
| 870 | local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'" | ||
| 664 | local my_function | 871 | local my_function |
| 665 | my_function = function() end | 872 | my_function = function() end |
| 666 | my_function() | 873 | my_function() |
| @@ -755,6 +962,66 @@ if func(1, 2, 3, "hello", "world") then | |||
| 755 | print("hello") | 962 | print("hello") |
| 756 | print("I am inside if") | 963 | print("I am inside if") |
| 757 | end | 964 | end |
| 965 | local f1 | ||
| 966 | f1 = function(_arg_0) | ||
| 967 | local a, b, c | ||
| 968 | a, b, c = _arg_0.a, _arg_0.b, _arg_0.c | ||
| 969 | return print(a, b, c) | ||
| 970 | end | ||
| 971 | f1({ | ||
| 972 | a = 1, | ||
| 973 | b = "2", | ||
| 974 | c = { } | ||
| 975 | }) | ||
| 976 | local f2 | ||
| 977 | f2 = function(_arg_0, c) | ||
| 978 | local a1, b | ||
| 979 | a1, b = _arg_0.a, _arg_0.b | ||
| 980 | if a1 == nil then | ||
| 981 | a1 = 123 | ||
| 982 | end | ||
| 983 | if b == nil then | ||
| 984 | b = 'abc' | ||
| 985 | end | ||
| 986 | if c == nil then | ||
| 987 | c = { } | ||
| 988 | end | ||
| 989 | return print(a1, b, c) | ||
| 990 | end | ||
| 991 | local arg1 = { | ||
| 992 | a = 0 | ||
| 993 | } | ||
| 994 | f2(arg1, arg2) | ||
| 995 | local f | ||
| 996 | f = function(...) | ||
| 997 | local t = { | ||
| 998 | n = select("#", ...), | ||
| 999 | ... | ||
| 1000 | } | ||
| 1001 | print("argument count:", t.n) | ||
| 1002 | print("table length:", #t) | ||
| 1003 | for i = 1, t.n do | ||
| 1004 | print(t[i]) | ||
| 1005 | end | ||
| 1006 | end | ||
| 1007 | f(1, 2, 3) | ||
| 1008 | f("a", "b", "c", "d") | ||
| 1009 | f() | ||
| 1010 | local process | ||
| 1011 | process = function(...) | ||
| 1012 | local args = { | ||
| 1013 | n = select("#", ...), | ||
| 1014 | ... | ||
| 1015 | } | ||
| 1016 | local sum = 0 | ||
| 1017 | for i = 1, args.n do | ||
| 1018 | if args[i] ~= nil and type(args[i]) == "number" then | ||
| 1019 | sum = sum + args[i] | ||
| 1020 | end | ||
| 1021 | end | ||
| 1022 | return sum | ||
| 1023 | end | ||
| 1024 | process(1, nil, 3, nil, 5) | ||
| 758 | f(function() | 1025 | f(function() |
| 759 | return print("hello") | 1026 | return print("hello") |
| 760 | end) | 1027 | end) |
| @@ -880,6 +1147,28 @@ for _index_0 = 1, #_list_0 do | |||
| 880 | _len_0 = _len_0 + 1 | 1147 | _len_0 = _len_0 + 1 |
| 881 | end | 1148 | end |
| 882 | doubled = _accum_0 | 1149 | doubled = _accum_0 |
| 1150 | local data = { | ||
| 1151 | a = { | ||
| 1152 | 1, | ||
| 1153 | 2, | ||
| 1154 | 3 | ||
| 1155 | }, | ||
| 1156 | b = { | ||
| 1157 | 4, | ||
| 1158 | 5, | ||
| 1159 | 6 | ||
| 1160 | } | ||
| 1161 | } | ||
| 1162 | local flat | ||
| 1163 | local _accum_0 = { } | ||
| 1164 | for k, v in pairs(data) do | ||
| 1165 | local _len_0 = #_accum_0 + 1 | ||
| 1166 | for _index_0 = 1, #v do | ||
| 1167 | local _elm_0 = v[_index_0] | ||
| 1168 | _accum_0[_len_0], _len_0 = _elm_0, _len_0 + 1 | ||
| 1169 | end | ||
| 1170 | end | ||
| 1171 | flat = _accum_0 | ||
| 883 | local x_coords = { | 1172 | local x_coords = { |
| 884 | 4, | 1173 | 4, |
| 885 | 5, | 1174 | 5, |
| @@ -970,8 +1259,18 @@ local slice | |||
| 970 | local _accum_0 = { } | 1259 | local _accum_0 = { } |
| 971 | local _len_0 = 1 | 1260 | local _len_0 = 1 |
| 972 | local _list_0 = items | 1261 | local _list_0 = items |
| 973 | local _max_0 = 5 | 1262 | for _index_0 = 1, 5 do |
| 974 | for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do | 1263 | local item = _list_0[_index_0] |
| 1264 | _accum_0[_len_0] = item | ||
| 1265 | _len_0 = _len_0 + 1 | ||
| 1266 | end | ||
| 1267 | slice = _accum_0 | ||
| 1268 | local slice | ||
| 1269 | local _accum_0 = { } | ||
| 1270 | local _len_0 = 1 | ||
| 1271 | local _list_0 = items | ||
| 1272 | local _max_0 = #_list_0 | ||
| 1273 | for _index_0 = 2, _max_0 do | ||
| 975 | local item = _list_0[_index_0] | 1274 | local item = _list_0[_index_0] |
| 976 | _accum_0[_len_0] = item | 1275 | _accum_0[_len_0] = item |
| 977 | _len_0 = _len_0 + 1 | 1276 | _len_0 = _len_0 + 1 |
| @@ -981,7 +1280,8 @@ local slice | |||
| 981 | local _accum_0 = { } | 1280 | local _accum_0 = { } |
| 982 | local _len_0 = 1 | 1281 | local _len_0 = 1 |
| 983 | local _list_0 = items | 1282 | local _list_0 = items |
| 984 | for _index_0 = 2, #_list_0 do | 1283 | local _max_0 = #_list_0 |
| 1284 | for _index_0 = 1, _max_0, 2 do | ||
| 985 | local item = _list_0[_index_0] | 1285 | local item = _list_0[_index_0] |
| 986 | _accum_0[_len_0] = item | 1286 | _accum_0[_len_0] = item |
| 987 | _len_0 = _len_0 + 1 | 1287 | _len_0 = _len_0 + 1 |
| @@ -991,12 +1291,35 @@ local slice | |||
| 991 | local _accum_0 = { } | 1291 | local _accum_0 = { } |
| 992 | local _len_0 = 1 | 1292 | local _len_0 = 1 |
| 993 | local _list_0 = items | 1293 | local _list_0 = items |
| 994 | for _index_0 = 1, #_list_0, 2 do | 1294 | local _min_0 = #_list_0 + -4 + 1 |
| 1295 | local _max_0 = #_list_0 + -1 + 1 | ||
| 1296 | for _index_0 = _min_0, _max_0 do | ||
| 995 | local item = _list_0[_index_0] | 1297 | local item = _list_0[_index_0] |
| 996 | _accum_0[_len_0] = item | 1298 | _accum_0[_len_0] = item |
| 997 | _len_0 = _len_0 + 1 | 1299 | _len_0 = _len_0 + 1 |
| 998 | end | 1300 | end |
| 999 | slice = _accum_0 | 1301 | slice = _accum_0 |
| 1302 | local reverse_slice | ||
| 1303 | local _accum_0 = { } | ||
| 1304 | local _len_0 = 1 | ||
| 1305 | local _list_0 = items | ||
| 1306 | local _min_0 = #_list_0 + -1 + 1 | ||
| 1307 | for _index_0 = _min_0, 1, -1 do | ||
| 1308 | local item = _list_0[_index_0] | ||
| 1309 | _accum_0[_len_0] = item | ||
| 1310 | _len_0 = _len_0 + 1 | ||
| 1311 | end | ||
| 1312 | reverse_slice = _accum_0 | ||
| 1313 | local sub_list | ||
| 1314 | local _accum_0 = { } | ||
| 1315 | local _len_0 = 1 | ||
| 1316 | local _list_0 = items | ||
| 1317 | for _index_0 = 2, 4 do | ||
| 1318 | local _item_0 = _list_0[_index_0] | ||
| 1319 | _accum_0[_len_0] = _item_0 | ||
| 1320 | _len_0 = _len_0 + 1 | ||
| 1321 | end | ||
| 1322 | sub_list = _accum_0 | ||
| 1000 | for i = 10, 20 do | 1323 | for i = 10, 20 do |
| 1001 | print(i) | 1324 | print(i) |
| 1002 | end | 1325 | end |
| @@ -1007,8 +1330,7 @@ for key, value in pairs(object) do | |||
| 1007 | print(key, value) | 1330 | print(key, value) |
| 1008 | end | 1331 | end |
| 1009 | local _list_0 = items | 1332 | local _list_0 = items |
| 1010 | local _max_0 = 4 | 1333 | for _index_0 = 2, 4 do |
| 1011 | for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do | ||
| 1012 | local item = _list_0[_index_0] | 1334 | local item = _list_0[_index_0] |
| 1013 | print(item) | 1335 | print(item) |
| 1014 | end | 1336 | end |
| @@ -1026,12 +1348,24 @@ local _len_0 = 1 | |||
| 1026 | for i = 1, 20 do | 1348 | for i = 1, 20 do |
| 1027 | if i % 2 == 0 then | 1349 | if i % 2 == 0 then |
| 1028 | _accum_0[_len_0] = i * 2 | 1350 | _accum_0[_len_0] = i * 2 |
| 1351 | _len_0 = _len_0 + 1 | ||
| 1029 | else | 1352 | else |
| 1030 | _accum_0[_len_0] = i | 1353 | _accum_0[_len_0] = i |
| 1354 | _len_0 = _len_0 + 1 | ||
| 1031 | end | 1355 | end |
| 1032 | _len_0 = _len_0 + 1 | ||
| 1033 | end | 1356 | end |
| 1034 | doubled_evens = _accum_0 | 1357 | doubled_evens = _accum_0 |
| 1358 | local first_large | ||
| 1359 | local _accum_0 | ||
| 1360 | local _list_0 = numbers | ||
| 1361 | for _index_0 = 1, #_list_0 do | ||
| 1362 | local n = _list_0[_index_0] | ||
| 1363 | if n > 10 then | ||
| 1364 | _accum_0 = n | ||
| 1365 | break | ||
| 1366 | end | ||
| 1367 | end | ||
| 1368 | first_large = _accum_0 | ||
| 1035 | local func_a | 1369 | local func_a |
| 1036 | func_a = function() | 1370 | func_a = function() |
| 1037 | for i = 1, 10 do | 1371 | for i = 1, 10 do |
| @@ -1180,7 +1514,7 @@ if "Robert" == name then | |||
| 1180 | elseif "Dan" == name or "Daniel" == name then | 1514 | elseif "Dan" == name or "Daniel" == name then |
| 1181 | print("Your name, it's Dan") | 1515 | print("Your name, it's Dan") |
| 1182 | else | 1516 | else |
| 1183 | print("I don't know about your name") | 1517 | print("I don't know about you with name " .. tostring(name)) |
| 1184 | end | 1518 | end |
| 1185 | local b = 1 | 1519 | local b = 1 |
| 1186 | local next_number | 1520 | local next_number |
| @@ -1280,6 +1614,192 @@ if _tab_0 then | |||
| 1280 | end | 1614 | end |
| 1281 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) | 1615 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) |
| 1282 | end | 1616 | end |
| 1617 | local _exp_0 = tb | ||
| 1618 | local _type_0 = type(_exp_0) | ||
| 1619 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 1620 | local _match_0 = false | ||
| 1621 | if _tab_0 then | ||
| 1622 | if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then | ||
| 1623 | _match_0 = true | ||
| 1624 | print("1, 2, 3") | ||
| 1625 | end | ||
| 1626 | end | ||
| 1627 | if not _match_0 then | ||
| 1628 | local _match_1 = false | ||
| 1629 | if _tab_0 then | ||
| 1630 | local b = _exp_0[2] | ||
| 1631 | if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then | ||
| 1632 | _match_1 = true | ||
| 1633 | print("1, " .. tostring(b) .. ", 3") | ||
| 1634 | end | ||
| 1635 | end | ||
| 1636 | if not _match_1 then | ||
| 1637 | if _tab_0 then | ||
| 1638 | local b = _exp_0[3] | ||
| 1639 | if b == nil then | ||
| 1640 | b = 3 | ||
| 1641 | end | ||
| 1642 | if 1 == _exp_0[1] and 2 == _exp_0[2] then | ||
| 1643 | print("1, 2, " .. tostring(b)) | ||
| 1644 | end | ||
| 1645 | end | ||
| 1646 | end | ||
| 1647 | end | ||
| 1648 | local _exp_0 = tb | ||
| 1649 | local _type_0 = type(_exp_0) | ||
| 1650 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 1651 | local _match_0 = false | ||
| 1652 | if _tab_0 then | ||
| 1653 | local result = _exp_0.result | ||
| 1654 | if true == _exp_0.success and result ~= nil then | ||
| 1655 | _match_0 = true | ||
| 1656 | print("success", result) | ||
| 1657 | end | ||
| 1658 | end | ||
| 1659 | if not _match_0 then | ||
| 1660 | local _match_1 = false | ||
| 1661 | if _tab_0 then | ||
| 1662 | if false == _exp_0.success then | ||
| 1663 | _match_1 = true | ||
| 1664 | print("failed", result) | ||
| 1665 | end | ||
| 1666 | end | ||
| 1667 | if not _match_1 then | ||
| 1668 | print("invalid") | ||
| 1669 | end | ||
| 1670 | end | ||
| 1671 | local _exp_0 = tb | ||
| 1672 | local _type_0 = type(_exp_0) | ||
| 1673 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 1674 | local _match_0 = false | ||
| 1675 | if _tab_0 then | ||
| 1676 | local content | ||
| 1677 | do | ||
| 1678 | local _obj_0 = _exp_0.data | ||
| 1679 | local _type_1 = type(_obj_0) | ||
| 1680 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 1681 | content = _obj_0.content | ||
| 1682 | end | ||
| 1683 | end | ||
| 1684 | local _val_0 | ||
| 1685 | do | ||
| 1686 | local _obj_0 = _exp_0.data | ||
| 1687 | if _obj_0 ~= nil then | ||
| 1688 | _val_0 = _obj_0.type | ||
| 1689 | end | ||
| 1690 | end | ||
| 1691 | if "success" == _val_0 and content ~= nil then | ||
| 1692 | _match_0 = true | ||
| 1693 | print("success", content) | ||
| 1694 | end | ||
| 1695 | end | ||
| 1696 | if not _match_0 then | ||
| 1697 | local _match_1 = false | ||
| 1698 | if _tab_0 then | ||
| 1699 | local content | ||
| 1700 | do | ||
| 1701 | local _obj_0 = _exp_0.data | ||
| 1702 | local _type_1 = type(_obj_0) | ||
| 1703 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 1704 | content = _obj_0.content | ||
| 1705 | end | ||
| 1706 | end | ||
| 1707 | local _val_0 | ||
| 1708 | do | ||
| 1709 | local _obj_0 = _exp_0.data | ||
| 1710 | if _obj_0 ~= nil then | ||
| 1711 | _val_0 = _obj_0.type | ||
| 1712 | end | ||
| 1713 | end | ||
| 1714 | if "error" == _val_0 and content ~= nil then | ||
| 1715 | _match_1 = true | ||
| 1716 | print("failed", content) | ||
| 1717 | end | ||
| 1718 | end | ||
| 1719 | if not _match_1 then | ||
| 1720 | print("invalid") | ||
| 1721 | end | ||
| 1722 | end | ||
| 1723 | local _exp_0 = tb | ||
| 1724 | local _type_0 = type(_exp_0) | ||
| 1725 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 1726 | if _tab_0 then | ||
| 1727 | local fourth = _exp_0[4] | ||
| 1728 | local _val_0 | ||
| 1729 | do | ||
| 1730 | local _obj_0 = _exp_0[1] | ||
| 1731 | if _obj_0 ~= nil then | ||
| 1732 | _val_0 = _obj_0.a | ||
| 1733 | end | ||
| 1734 | end | ||
| 1735 | local _val_1 | ||
| 1736 | do | ||
| 1737 | local _obj_0 = _exp_0[1] | ||
| 1738 | if _obj_0 ~= nil then | ||
| 1739 | _val_1 = _obj_0.b | ||
| 1740 | end | ||
| 1741 | end | ||
| 1742 | local _val_2 | ||
| 1743 | do | ||
| 1744 | local _obj_0 = _exp_0[2] | ||
| 1745 | if _obj_0 ~= nil then | ||
| 1746 | _val_2 = _obj_0.a | ||
| 1747 | end | ||
| 1748 | end | ||
| 1749 | local _val_3 | ||
| 1750 | do | ||
| 1751 | local _obj_0 = _exp_0[2] | ||
| 1752 | if _obj_0 ~= nil then | ||
| 1753 | _val_3 = _obj_0.b | ||
| 1754 | end | ||
| 1755 | end | ||
| 1756 | local _val_4 | ||
| 1757 | do | ||
| 1758 | local _obj_0 = _exp_0[3] | ||
| 1759 | if _obj_0 ~= nil then | ||
| 1760 | _val_4 = _obj_0.a | ||
| 1761 | end | ||
| 1762 | end | ||
| 1763 | local _val_5 | ||
| 1764 | do | ||
| 1765 | local _obj_0 = _exp_0[3] | ||
| 1766 | if _obj_0 ~= nil then | ||
| 1767 | _val_5 = _obj_0.b | ||
| 1768 | end | ||
| 1769 | end | ||
| 1770 | 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 | ||
| 1771 | print("matched", fourth) | ||
| 1772 | end | ||
| 1773 | end | ||
| 1774 | local segments = { | ||
| 1775 | "admin", | ||
| 1776 | "users", | ||
| 1777 | "logs", | ||
| 1778 | "view" | ||
| 1779 | } | ||
| 1780 | local _type_0 = type(segments) | ||
| 1781 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 1782 | if _tab_0 then | ||
| 1783 | local groups | ||
| 1784 | do | ||
| 1785 | local _accum_0 = { } | ||
| 1786 | local _len_0 = 1 | ||
| 1787 | local _max_0 = #segments + -3 + 1 | ||
| 1788 | for _index_0 = 1, _max_0 do | ||
| 1789 | local _item_0 = segments[_index_0] | ||
| 1790 | _accum_0[_len_0] = _item_0 | ||
| 1791 | _len_0 = _len_0 + 1 | ||
| 1792 | end | ||
| 1793 | groups = _accum_0 | ||
| 1794 | end | ||
| 1795 | local resource = segments[#segments - 1] | ||
| 1796 | local action = segments[#segments] | ||
| 1797 | if resource ~= nil and action ~= nil then | ||
| 1798 | print("Group:", groups) | ||
| 1799 | print("Resource:", resource) | ||
| 1800 | print("Action:", action) | ||
| 1801 | end | ||
| 1802 | end | ||
| 1283 | local Inventory | 1803 | local Inventory |
| 1284 | local _class_0 | 1804 | local _class_0 |
| 1285 | local _base_0 = { | 1805 | local _base_0 = { |
| @@ -1936,6 +2456,10 @@ do | |||
| 1936 | _with_1["key-name"] = value | 2456 | _with_1["key-name"] = value |
| 1937 | end | 2457 | end |
| 1938 | _with_0[#_with_0 + 1] = "abc" | 2458 | _with_0[#_with_0 + 1] = "abc" |
| 2459 | local _with_0 = obj | ||
| 2460 | if _with_0 ~= nil then | ||
| 2461 | print(obj.name) | ||
| 2462 | end | ||
| 1939 | do | 2463 | do |
| 1940 | local var = "hello" | 2464 | local var = "hello" |
| 1941 | print(var) | 2465 | print(var) |
| @@ -2026,6 +2550,38 @@ local inventory = { | |||
| 2026 | } | 2550 | } |
| 2027 | } | 2551 | } |
| 2028 | } | 2552 | } |
| 2553 | local map | ||
| 2554 | map = function(arr, action) | ||
| 2555 | local _accum_0 = { } | ||
| 2556 | local _len_0 = 1 | ||
| 2557 | for _index_0 = 1, #arr do | ||
| 2558 | local item = arr[_index_0] | ||
| 2559 | _accum_0[_len_0] = action(item) | ||
| 2560 | _len_0 = _len_0 + 1 | ||
| 2561 | end | ||
| 2562 | return _accum_0 | ||
| 2563 | end | ||
| 2564 | local filter | ||
| 2565 | filter = function(arr, cond) | ||
| 2566 | local _accum_0 = { } | ||
| 2567 | local _len_0 = 1 | ||
| 2568 | for _index_0 = 1, #arr do | ||
| 2569 | local item = arr[_index_0] | ||
| 2570 | if cond(item) then | ||
| 2571 | _accum_0[_len_0] = item | ||
| 2572 | _len_0 = _len_0 + 1 | ||
| 2573 | end | ||
| 2574 | end | ||
| 2575 | return _accum_0 | ||
| 2576 | end | ||
| 2577 | local reduce | ||
| 2578 | reduce = function(arr, init, action) | ||
| 2579 | for _index_0 = 1, #arr do | ||
| 2580 | local item = arr[_index_0] | ||
| 2581 | init = action(init, item) | ||
| 2582 | end | ||
| 2583 | return init | ||
| 2584 | end | ||
| 2029 | print(reduce(filter(map({ | 2585 | print(reduce(filter(map({ |
| 2030 | 1, | 2586 | 1, |
| 2031 | 2, | 2587 | 2, |
| @@ -2047,8 +2603,8 @@ local apple = setmetatable({ | |||
| 2047 | if (getmetatable(apple) ~= nil) then | 2603 | if (getmetatable(apple) ~= nil) then |
| 2048 | p(apple.size, apple.color, getmetatable(apple).__index) | 2604 | p(apple.size, apple.color, getmetatable(apple).__index) |
| 2049 | end | 2605 | end |
| 2050 | local _ud83c_udf1b = "月之脚本" | 2606 | local _u1f31b = "月之脚本" |
| 2051 | _module_0["🌛"] = _ud83c_udf1b | 2607 | _module_0["🌛"] = _u1f31b |
| 2052 | return _module_0 | 2608 | return _module_0 |
| 2053 | local area = 6.2831853071796 * 5 | 2609 | local area = 6.2831853071796 * 5 |
| 2054 | print('hello world') | 2610 | print('hello world') |
| @@ -2083,6 +2639,12 @@ end | |||
| 2083 | print("yuescript") | 2639 | print("yuescript") |
| 2084 | print(3) | 2640 | print(3) |
| 2085 | print("Valid enum type:", "Static") | 2641 | print("Valid enum type:", "Static") |
| 2642 | do | ||
| 2643 | print(123, "hello") | ||
| 2644 | end | ||
| 2645 | do | ||
| 2646 | print(123, "hello") | ||
| 2647 | end | ||
| 2086 | if tb ~= nil then | 2648 | if tb ~= nil then |
| 2087 | tb:func() | 2649 | tb:func() |
| 2088 | end | 2650 | end |
| @@ -2115,6 +2677,21 @@ print((function() | |||
| 2115 | end)()) | 2677 | end)()) |
| 2116 | local tab = { } | 2678 | local tab = { } |
| 2117 | tab[#tab + 1] = "Value" | 2679 | tab[#tab + 1] = "Value" |
| 2680 | local tbA = { | ||
| 2681 | 1, | ||
| 2682 | 2, | ||
| 2683 | 3 | ||
| 2684 | } | ||
| 2685 | local tbB = { | ||
| 2686 | 4, | ||
| 2687 | 5, | ||
| 2688 | 6 | ||
| 2689 | } | ||
| 2690 | local _len_0 = #tbA + 1 | ||
| 2691 | for _index_0 = 1, #tbB do | ||
| 2692 | local _elm_0 = tbB[_index_0] | ||
| 2693 | tbA[_len_0], _len_0 = _elm_0, _len_0 + 1 | ||
| 2694 | end | ||
| 2118 | local parts = { | 2695 | local parts = { |
| 2119 | "shoulders", | 2696 | "shoulders", |
| 2120 | "knees" | 2697 | "knees" |
| @@ -2183,6 +2760,18 @@ for _key_0, _value_0 in pairs(b) do | |||
| 2183 | end | 2760 | end |
| 2184 | end | 2761 | end |
| 2185 | merge = _tab_0 | 2762 | merge = _tab_0 |
| 2763 | local last | ||
| 2764 | do | ||
| 2765 | local _item_0 = data.items | ||
| 2766 | last = _item_0[#_item_0] | ||
| 2767 | end | ||
| 2768 | local second_last | ||
| 2769 | do | ||
| 2770 | local _item_0 = data.items | ||
| 2771 | second_last = _item_0[#_item_0 - 1] | ||
| 2772 | end | ||
| 2773 | local _obj_0 = data.items | ||
| 2774 | _obj_0[#_obj_0] = 1 | ||
| 2186 | local mt = { } | 2775 | local mt = { } |
| 2187 | local add | 2776 | local add |
| 2188 | add = function(self, right) | 2777 | add = function(self, right) |
| @@ -2313,6 +2902,14 @@ func({ | |||
| 2313 | 2, | 2902 | 2, |
| 2314 | 3 | 2903 | 3 |
| 2315 | }) | 2904 | }) |
| 2905 | local f | ||
| 2906 | f = function() | ||
| 2907 | return { | ||
| 2908 | 1, | ||
| 2909 | 2, | ||
| 2910 | 3 | ||
| 2911 | } | ||
| 2912 | end | ||
| 2316 | local tb = { | 2913 | local tb = { |
| 2317 | name = "abc", | 2914 | name = "abc", |
| 2318 | values = { | 2915 | values = { |
| @@ -2374,6 +2971,25 @@ do | |||
| 2374 | local _obj_0 = require("export") | 2971 | local _obj_0 = require("export") |
| 2375 | one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] | 2972 | one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] |
| 2376 | end | 2973 | end |
| 2974 | do | ||
| 2975 | local tostring <const> = tostring | ||
| 2976 | local concat <const> = table.concat | ||
| 2977 | print(concat({ | ||
| 2978 | "a", | ||
| 2979 | tostring(1) | ||
| 2980 | })) | ||
| 2981 | end | ||
| 2982 | do | ||
| 2983 | local print <const> = print | ||
| 2984 | local math <const> = math | ||
| 2985 | print("hello") | ||
| 2986 | math.random(3) | ||
| 2987 | end | ||
| 2988 | do | ||
| 2989 | local print <const> = print | ||
| 2990 | print(FLAG) | ||
| 2991 | FLAG = 123 | ||
| 2992 | end | ||
| 2377 | local _module_0 = { } | 2993 | local _module_0 = { } |
| 2378 | local a, b, c = 1, 2, 3 | 2994 | local a, b, c = 1, 2, 3 |
| 2379 | _module_0["a"], _module_0["b"], _module_0["c"] = a, b, c | 2995 | _module_0["a"], _module_0["b"], _module_0["c"] = a, b, c |
| @@ -2553,6 +3169,59 @@ end | |||
| 2553 | local two, four | 3169 | local two, four |
| 2554 | local _obj_0 = items | 3170 | local _obj_0 = items |
| 2555 | two, four = _obj_0[2], _obj_0[4] | 3171 | two, four = _obj_0[2], _obj_0[4] |
| 3172 | local orders = { | ||
| 3173 | "first", | ||
| 3174 | "second", | ||
| 3175 | "third", | ||
| 3176 | "fourth", | ||
| 3177 | "last" | ||
| 3178 | } | ||
| 3179 | local first, bulk, last = orders[1], (function() | ||
| 3180 | local _accum_0 = { } | ||
| 3181 | local _len_0 = 1 | ||
| 3182 | local _max_0 = #orders + -2 + 1 | ||
| 3183 | for _index_0 = 2, _max_0 do | ||
| 3184 | local _item_0 = orders[_index_0] | ||
| 3185 | _accum_0[_len_0] = _item_0 | ||
| 3186 | _len_0 = _len_0 + 1 | ||
| 3187 | end | ||
| 3188 | return _accum_0 | ||
| 3189 | end)(), orders[#orders] | ||
| 3190 | print(first) | ||
| 3191 | print(bulk) | ||
| 3192 | print(last) | ||
| 3193 | local first, rest | ||
| 3194 | do | ||
| 3195 | local _obj_0 = orders | ||
| 3196 | first, rest = _obj_0[1], (function() | ||
| 3197 | local _accum_0 = { } | ||
| 3198 | local _len_0 = 1 | ||
| 3199 | local _max_0 = #_obj_0 | ||
| 3200 | for _index_0 = 2, _max_0 do | ||
| 3201 | local _item_0 = _obj_0[_index_0] | ||
| 3202 | _accum_0[_len_0] = _item_0 | ||
| 3203 | _len_0 = _len_0 + 1 | ||
| 3204 | end | ||
| 3205 | return _accum_0 | ||
| 3206 | end)() | ||
| 3207 | end | ||
| 3208 | local start, last | ||
| 3209 | do | ||
| 3210 | local _obj_0 = orders | ||
| 3211 | start, last = (function() | ||
| 3212 | local _accum_0 = { } | ||
| 3213 | local _len_0 = 1 | ||
| 3214 | local _max_0 = #_obj_0 + -2 + 1 | ||
| 3215 | for _index_0 = 1, _max_0 do | ||
| 3216 | local _item_0 = _obj_0[_index_0] | ||
| 3217 | _accum_0[_len_0] = _item_0 | ||
| 3218 | _len_0 = _len_0 + 1 | ||
| 3219 | end | ||
| 3220 | return _accum_0 | ||
| 3221 | end)(), _obj_0[#_obj_0] | ||
| 3222 | end | ||
| 3223 | local _obj_0 = orders | ||
| 3224 | first, last = _obj_0[1], _obj_0[#_obj_0] | ||
| 2556 | local tuples = { | 3225 | local tuples = { |
| 2557 | { | 3226 | { |
| 2558 | "hello", | 3227 | "hello", |
| @@ -2617,6 +3286,9 @@ end | |||
| 2617 | local first = select(1, ...) | 3286 | local first = select(1, ...) |
| 2618 | return print(ok, count, first) | 3287 | return print(ok, count, first) |
| 2619 | end)(fn(true)) | 3288 | end)(fn(true)) |
| 3289 | local a = 1 | ||
| 3290 | local b = 2 | ||
| 3291 | print(a + b) | ||
| 2620 | Rx.Observable.fromRange(1, 8):filter(function(x) | 3292 | Rx.Observable.fromRange(1, 8):filter(function(x) |
| 2621 | return x % 2 == 0 | 3293 | return x % 2 == 0 |
| 2622 | end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) | 3294 | end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) |
| @@ -2654,6 +3326,56 @@ end) | |||
| 2654 | if success then | 3326 | if success then |
| 2655 | print(result) | 3327 | print(result) |
| 2656 | end | 3328 | end |
| 3329 | local a, b, c | ||
| 3330 | do | ||
| 3331 | local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function() | ||
| 3332 | return func() | ||
| 3333 | end) | ||
| 3334 | if _ok_0 then | ||
| 3335 | a, b, c = _ret_0, _ret_1, _ret_2 | ||
| 3336 | end | ||
| 3337 | end | ||
| 3338 | do | ||
| 3339 | local _exp_0 = ((function() | ||
| 3340 | return (function(_arg_0, ...) | ||
| 3341 | local _ok_0 = _arg_0 | ||
| 3342 | if _ok_0 then | ||
| 3343 | return ... | ||
| 3344 | end | ||
| 3345 | end)(pcall(function() | ||
| 3346 | return func() | ||
| 3347 | end)) | ||
| 3348 | end)()) | ||
| 3349 | if _exp_0 ~= nil then | ||
| 3350 | a = _exp_0 | ||
| 3351 | else | ||
| 3352 | a = "default" | ||
| 3353 | end | ||
| 3354 | end | ||
| 3355 | f((function() | ||
| 3356 | return (function(_arg_0, ...) | ||
| 3357 | local _ok_0 = _arg_0 | ||
| 3358 | if _ok_0 then | ||
| 3359 | return ... | ||
| 3360 | end | ||
| 3361 | end)(pcall(function() | ||
| 3362 | return func() | ||
| 3363 | end)) | ||
| 3364 | end)()) | ||
| 3365 | f((function() | ||
| 3366 | return (function(_arg_0, ...) | ||
| 3367 | local _ok_0 = _arg_0 | ||
| 3368 | if _ok_0 then | ||
| 3369 | return ... | ||
| 3370 | end | ||
| 3371 | end)(xpcall(function() | ||
| 3372 | print(123) | ||
| 3373 | return func() | ||
| 3374 | end, function(e) | ||
| 3375 | print(e) | ||
| 3376 | return e | ||
| 3377 | end)) | ||
| 3378 | end)()) | ||
| 2657 | local a <const> = 123 | 3379 | local a <const> = 123 |
| 2658 | local _ <close> = setmetatable({ }, { | 3380 | local _ <close> = setmetatable({ }, { |
| 2659 | __close = function() | 3381 | __close = function() |
| @@ -2663,10 +3385,19 @@ local _ <close> = setmetatable({ }, { | |||
| 2663 | local a, b, c, d | 3385 | local a, b, c, d |
| 2664 | local _obj_0 = tb | 3386 | local _obj_0 = tb |
| 2665 | a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] | 3387 | a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] |
| 3388 | Constant = 123 | ||
| 2666 | local some_string = "Here is a string\n that has a line break in it." | 3389 | local some_string = "Here is a string\n that has a line break in it." |
| 2667 | print("I am " .. tostring(math.random() * 100) .. "% sure.") | 3390 | print("I am " .. tostring(math.random() * 100) .. "% sure.") |
| 2668 | local integer = 1000000 | 3391 | local integer = 1000000 |
| 2669 | local hex = 0xEFBBBF | 3392 | local hex = 0xEFBBBF |
| 3393 | local binary = 19 | ||
| 3394 | local str = "key: value\nlist:\n - item1\n - " .. tostring(expr) | ||
| 3395 | local fn | ||
| 3396 | fn = function() | ||
| 3397 | local str = "foo:\n bar: baz" | ||
| 3398 | return str | ||
| 3399 | end | ||
| 3400 | local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'" | ||
| 2670 | local my_function | 3401 | local my_function |
| 2671 | my_function = function() end | 3402 | my_function = function() end |
| 2672 | my_function() | 3403 | my_function() |
| @@ -2761,6 +3492,96 @@ if func(1, 2, 3, "hello", "world") then | |||
| 2761 | print("hello") | 3492 | print("hello") |
| 2762 | print("I am inside if") | 3493 | print("I am inside if") |
| 2763 | end | 3494 | end |
| 3495 | local f1 | ||
| 3496 | f1 = function(_arg_0) | ||
| 3497 | local a, b, c | ||
| 3498 | a, b, c = _arg_0.a, _arg_0.b, _arg_0.c | ||
| 3499 | return print(a, b, c) | ||
| 3500 | end | ||
| 3501 | f1({ | ||
| 3502 | a = 1, | ||
| 3503 | b = "2", | ||
| 3504 | c = { } | ||
| 3505 | }) | ||
| 3506 | local f2 | ||
| 3507 | f2 = function(_arg_0, c) | ||
| 3508 | local a1, b | ||
| 3509 | a1, b = _arg_0.a, _arg_0.b | ||
| 3510 | if a1 == nil then | ||
| 3511 | a1 = 123 | ||
| 3512 | end | ||
| 3513 | if b == nil then | ||
| 3514 | b = 'abc' | ||
| 3515 | end | ||
| 3516 | if c == nil then | ||
| 3517 | c = { } | ||
| 3518 | end | ||
| 3519 | end | ||
| 3520 | print(a1, b, c) | ||
| 3521 | local arg1 = { | ||
| 3522 | a = 0 | ||
| 3523 | } | ||
| 3524 | f2(arg1, arg2) | ||
| 3525 | local findFirstEven | ||
| 3526 | findFirstEven = function(list) | ||
| 3527 | for _index_0 = 1, #list do | ||
| 3528 | local item = list[_index_0] | ||
| 3529 | if type(item) == "table" then | ||
| 3530 | for _index_1 = 1, #item do | ||
| 3531 | local sub = item[_index_1] | ||
| 3532 | if sub % 2 == 0 then | ||
| 3533 | return sub | ||
| 3534 | end | ||
| 3535 | end | ||
| 3536 | end | ||
| 3537 | end | ||
| 3538 | return nil | ||
| 3539 | end | ||
| 3540 | local findFirstEven | ||
| 3541 | findFirstEven = function(list) | ||
| 3542 | for _index_0 = 1, #list do | ||
| 3543 | local item = list[_index_0] | ||
| 3544 | if type(item) == "table" then | ||
| 3545 | for _index_1 = 1, #item do | ||
| 3546 | local sub = item[_index_1] | ||
| 3547 | if sub % 2 == 0 then | ||
| 3548 | return sub | ||
| 3549 | end | ||
| 3550 | end | ||
| 3551 | end | ||
| 3552 | end | ||
| 3553 | return nil | ||
| 3554 | end | ||
| 3555 | local f | ||
| 3556 | f = function(...) | ||
| 3557 | local t = { | ||
| 3558 | n = select("#", ...), | ||
| 3559 | ... | ||
| 3560 | } | ||
| 3561 | print("argument count:", t.n) | ||
| 3562 | print("table length:", #t) | ||
| 3563 | for i = 1, t.n do | ||
| 3564 | print(t[i]) | ||
| 3565 | end | ||
| 3566 | end | ||
| 3567 | f(1, 2, 3) | ||
| 3568 | f("a", "b", "c", "d") | ||
| 3569 | f() | ||
| 3570 | local process | ||
| 3571 | process = function(...) | ||
| 3572 | local args = { | ||
| 3573 | n = select("#", ...), | ||
| 3574 | ... | ||
| 3575 | } | ||
| 3576 | local sum = 0 | ||
| 3577 | for i = 1, args.n do | ||
| 3578 | if args[i] ~= nil and type(args[i]) == "number" then | ||
| 3579 | sum = sum + args[i] | ||
| 3580 | end | ||
| 3581 | end | ||
| 3582 | return sum | ||
| 3583 | end | ||
| 3584 | process(1, nil, 3, nil, 5) | ||
| 2764 | f(function() | 3585 | f(function() |
| 2765 | return print("hello") | 3586 | return print("hello") |
| 2766 | end) | 3587 | end) |
| @@ -2886,6 +3707,28 @@ for _index_0 = 1, #_list_0 do | |||
| 2886 | _len_0 = _len_0 + 1 | 3707 | _len_0 = _len_0 + 1 |
| 2887 | end | 3708 | end |
| 2888 | doubled = _accum_0 | 3709 | doubled = _accum_0 |
| 3710 | local data = { | ||
| 3711 | a = { | ||
| 3712 | 1, | ||
| 3713 | 2, | ||
| 3714 | 3 | ||
| 3715 | }, | ||
| 3716 | b = { | ||
| 3717 | 4, | ||
| 3718 | 5, | ||
| 3719 | 6 | ||
| 3720 | } | ||
| 3721 | } | ||
| 3722 | local flat | ||
| 3723 | local _accum_0 = { } | ||
| 3724 | for k, v in pairs(data) do | ||
| 3725 | local _len_0 = #_accum_0 + 1 | ||
| 3726 | for _index_0 = 1, #v do | ||
| 3727 | local _elm_0 = v[_index_0] | ||
| 3728 | _accum_0[_len_0], _len_0 = _elm_0, _len_0 + 1 | ||
| 3729 | end | ||
| 3730 | end | ||
| 3731 | flat = _accum_0 | ||
| 2889 | local x_coords = { | 3732 | local x_coords = { |
| 2890 | 4, | 3733 | 4, |
| 2891 | 5, | 3734 | 5, |
| @@ -2976,8 +3819,7 @@ local slice | |||
| 2976 | local _accum_0 = { } | 3819 | local _accum_0 = { } |
| 2977 | local _len_0 = 1 | 3820 | local _len_0 = 1 |
| 2978 | local _list_0 = items | 3821 | local _list_0 = items |
| 2979 | local _max_0 = 5 | 3822 | for _index_0 = 1, 5 do |
| 2980 | for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do | ||
| 2981 | local item = _list_0[_index_0] | 3823 | local item = _list_0[_index_0] |
| 2982 | _accum_0[_len_0] = item | 3824 | _accum_0[_len_0] = item |
| 2983 | _len_0 = _len_0 + 1 | 3825 | _len_0 = _len_0 + 1 |
| @@ -2987,7 +3829,8 @@ local slice | |||
| 2987 | local _accum_0 = { } | 3829 | local _accum_0 = { } |
| 2988 | local _len_0 = 1 | 3830 | local _len_0 = 1 |
| 2989 | local _list_0 = items | 3831 | local _list_0 = items |
| 2990 | for _index_0 = 2, #_list_0 do | 3832 | local _max_0 = #_list_0 |
| 3833 | for _index_0 = 2, _max_0 do | ||
| 2991 | local item = _list_0[_index_0] | 3834 | local item = _list_0[_index_0] |
| 2992 | _accum_0[_len_0] = item | 3835 | _accum_0[_len_0] = item |
| 2993 | _len_0 = _len_0 + 1 | 3836 | _len_0 = _len_0 + 1 |
| @@ -2997,12 +3840,46 @@ local slice | |||
| 2997 | local _accum_0 = { } | 3840 | local _accum_0 = { } |
| 2998 | local _len_0 = 1 | 3841 | local _len_0 = 1 |
| 2999 | local _list_0 = items | 3842 | local _list_0 = items |
| 3000 | for _index_0 = 1, #_list_0, 2 do | 3843 | local _max_0 = #_list_0 |
| 3844 | for _index_0 = 1, _max_0, 2 do | ||
| 3001 | local item = _list_0[_index_0] | 3845 | local item = _list_0[_index_0] |
| 3002 | _accum_0[_len_0] = item | 3846 | _accum_0[_len_0] = item |
| 3003 | _len_0 = _len_0 + 1 | 3847 | _len_0 = _len_0 + 1 |
| 3004 | end | 3848 | end |
| 3005 | slice = _accum_0 | 3849 | slice = _accum_0 |
| 3850 | local slice | ||
| 3851 | local _accum_0 = { } | ||
| 3852 | local _len_0 = 1 | ||
| 3853 | local _list_0 = items | ||
| 3854 | local _min_0 = #_list_0 + -4 + 1 | ||
| 3855 | local _max_0 = #_list_0 + -1 + 1 | ||
| 3856 | for _index_0 = _min_0, _max_0 do | ||
| 3857 | local item = _list_0[_index_0] | ||
| 3858 | _accum_0[_len_0] = item | ||
| 3859 | _len_0 = _len_0 + 1 | ||
| 3860 | end | ||
| 3861 | slice = _accum_0 | ||
| 3862 | local reverse_slice | ||
| 3863 | local _accum_0 = { } | ||
| 3864 | local _len_0 = 1 | ||
| 3865 | local _list_0 = items | ||
| 3866 | local _min_0 = #_list_0 + -1 + 1 | ||
| 3867 | for _index_0 = _min_0, 1, -1 do | ||
| 3868 | local item = _list_0[_index_0] | ||
| 3869 | _accum_0[_len_0] = item | ||
| 3870 | _len_0 = _len_0 + 1 | ||
| 3871 | end | ||
| 3872 | reverse_slice = _accum_0 | ||
| 3873 | local sub_list | ||
| 3874 | local _accum_0 = { } | ||
| 3875 | local _len_0 = 1 | ||
| 3876 | local _list_0 = items | ||
| 3877 | for _index_0 = 2, 4 do | ||
| 3878 | local _item_0 = _list_0[_index_0] | ||
| 3879 | _accum_0[_len_0] = _item_0 | ||
| 3880 | _len_0 = _len_0 + 1 | ||
| 3881 | end | ||
| 3882 | sub_list = _accum_0 | ||
| 3006 | for i = 10, 20 do | 3883 | for i = 10, 20 do |
| 3007 | print(i) | 3884 | print(i) |
| 3008 | end | 3885 | end |
| @@ -3013,8 +3890,7 @@ for key, value in pairs(object) do | |||
| 3013 | print(key, value) | 3890 | print(key, value) |
| 3014 | end | 3891 | end |
| 3015 | local _list_0 = items | 3892 | local _list_0 = items |
| 3016 | local _max_0 = 4 | 3893 | for _index_0 = 2, 4 do |
| 3017 | for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do | ||
| 3018 | local item = _list_0[_index_0] | 3894 | local item = _list_0[_index_0] |
| 3019 | print(item) | 3895 | print(item) |
| 3020 | end | 3896 | end |
| @@ -3032,12 +3908,24 @@ local _len_0 = 1 | |||
| 3032 | for i = 1, 20 do | 3908 | for i = 1, 20 do |
| 3033 | if i % 2 == 0 then | 3909 | if i % 2 == 0 then |
| 3034 | _accum_0[_len_0] = i * 2 | 3910 | _accum_0[_len_0] = i * 2 |
| 3911 | _len_0 = _len_0 + 1 | ||
| 3035 | else | 3912 | else |
| 3036 | _accum_0[_len_0] = i | 3913 | _accum_0[_len_0] = i |
| 3914 | _len_0 = _len_0 + 1 | ||
| 3037 | end | 3915 | end |
| 3038 | _len_0 = _len_0 + 1 | ||
| 3039 | end | 3916 | end |
| 3040 | doubled_evens = _accum_0 | 3917 | doubled_evens = _accum_0 |
| 3918 | local first_large | ||
| 3919 | local _accum_0 | ||
| 3920 | local _list_0 = numbers | ||
| 3921 | for _index_0 = 1, #_list_0 do | ||
| 3922 | local n = _list_0[_index_0] | ||
| 3923 | if n > 10 then | ||
| 3924 | _accum_0 = n | ||
| 3925 | break | ||
| 3926 | end | ||
| 3927 | end | ||
| 3928 | first_large = _accum_0 | ||
| 3041 | local func_a | 3929 | local func_a |
| 3042 | func_a = function() | 3930 | func_a = function() |
| 3043 | for i = 1, 10 do | 3931 | for i = 1, 10 do |
| @@ -3186,7 +4074,7 @@ if "Robert" == name then | |||
| 3186 | elseif "Dan" == name or "Daniel" == name then | 4074 | elseif "Dan" == name or "Daniel" == name then |
| 3187 | print("Your name, it's Dan") | 4075 | print("Your name, it's Dan") |
| 3188 | else | 4076 | else |
| 3189 | print("I don't know about your name") | 4077 | print("I don't know about you with name " .. tostring(name)) |
| 3190 | end | 4078 | end |
| 3191 | local b = 1 | 4079 | local b = 1 |
| 3192 | local next_number | 4080 | local next_number |
| @@ -3286,6 +4174,192 @@ if _tab_0 then | |||
| 3286 | end | 4174 | end |
| 3287 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) | 4175 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) |
| 3288 | end | 4176 | end |
| 4177 | local _exp_0 = tb | ||
| 4178 | local _type_0 = type(_exp_0) | ||
| 4179 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 4180 | local _match_0 = false | ||
| 4181 | if _tab_0 then | ||
| 4182 | if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then | ||
| 4183 | _match_0 = true | ||
| 4184 | print("1, 2, 3") | ||
| 4185 | end | ||
| 4186 | end | ||
| 4187 | if not _match_0 then | ||
| 4188 | local _match_1 = false | ||
| 4189 | if _tab_0 then | ||
| 4190 | local b = _exp_0[2] | ||
| 4191 | if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then | ||
| 4192 | _match_1 = true | ||
| 4193 | print("1, " .. tostring(b) .. ", 3") | ||
| 4194 | end | ||
| 4195 | end | ||
| 4196 | if not _match_1 then | ||
| 4197 | if _tab_0 then | ||
| 4198 | local b = _exp_0[3] | ||
| 4199 | if b == nil then | ||
| 4200 | b = 3 | ||
| 4201 | end | ||
| 4202 | if 1 == _exp_0[1] and 2 == _exp_0[2] then | ||
| 4203 | print("1, 2, " .. tostring(b)) | ||
| 4204 | end | ||
| 4205 | end | ||
| 4206 | end | ||
| 4207 | end | ||
| 4208 | local _exp_0 = tb | ||
| 4209 | local _type_0 = type(_exp_0) | ||
| 4210 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 4211 | local _match_0 = false | ||
| 4212 | if _tab_0 then | ||
| 4213 | local result = _exp_0.result | ||
| 4214 | if true == _exp_0.success and result ~= nil then | ||
| 4215 | _match_0 = true | ||
| 4216 | print("success", result) | ||
| 4217 | end | ||
| 4218 | end | ||
| 4219 | if not _match_0 then | ||
| 4220 | local _match_1 = false | ||
| 4221 | if _tab_0 then | ||
| 4222 | if false == _exp_0.success then | ||
| 4223 | _match_1 = true | ||
| 4224 | print("failed", result) | ||
| 4225 | end | ||
| 4226 | end | ||
| 4227 | if not _match_1 then | ||
| 4228 | print("invalid") | ||
| 4229 | end | ||
| 4230 | end | ||
| 4231 | local _exp_0 = tb | ||
| 4232 | local _type_0 = type(_exp_0) | ||
| 4233 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 4234 | local _match_0 = false | ||
| 4235 | if _tab_0 then | ||
| 4236 | local content | ||
| 4237 | do | ||
| 4238 | local _obj_0 = _exp_0.data | ||
| 4239 | local _type_1 = type(_obj_0) | ||
| 4240 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 4241 | content = _obj_0.content | ||
| 4242 | end | ||
| 4243 | end | ||
| 4244 | local _val_0 | ||
| 4245 | do | ||
| 4246 | local _obj_0 = _exp_0.data | ||
| 4247 | if _obj_0 ~= nil then | ||
| 4248 | _val_0 = _obj_0.type | ||
| 4249 | end | ||
| 4250 | end | ||
| 4251 | if "success" == _val_0 and content ~= nil then | ||
| 4252 | _match_0 = true | ||
| 4253 | print("success", content) | ||
| 4254 | end | ||
| 4255 | end | ||
| 4256 | if not _match_0 then | ||
| 4257 | local _match_1 = false | ||
| 4258 | if _tab_0 then | ||
| 4259 | local content | ||
| 4260 | do | ||
| 4261 | local _obj_0 = _exp_0.data | ||
| 4262 | local _type_1 = type(_obj_0) | ||
| 4263 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 4264 | content = _obj_0.content | ||
| 4265 | end | ||
| 4266 | end | ||
| 4267 | local _val_0 | ||
| 4268 | do | ||
| 4269 | local _obj_0 = _exp_0.data | ||
| 4270 | if _obj_0 ~= nil then | ||
| 4271 | _val_0 = _obj_0.type | ||
| 4272 | end | ||
| 4273 | end | ||
| 4274 | if "error" == _val_0 and content ~= nil then | ||
| 4275 | _match_1 = true | ||
| 4276 | print("failed", content) | ||
| 4277 | end | ||
| 4278 | end | ||
| 4279 | if not _match_1 then | ||
| 4280 | print("invalid") | ||
| 4281 | end | ||
| 4282 | end | ||
| 4283 | local _exp_0 = tb | ||
| 4284 | local _type_0 = type(_exp_0) | ||
| 4285 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 4286 | if _tab_0 then | ||
| 4287 | local fourth = _exp_0[4] | ||
| 4288 | local _val_0 | ||
| 4289 | do | ||
| 4290 | local _obj_0 = _exp_0[1] | ||
| 4291 | if _obj_0 ~= nil then | ||
| 4292 | _val_0 = _obj_0.a | ||
| 4293 | end | ||
| 4294 | end | ||
| 4295 | local _val_1 | ||
| 4296 | do | ||
| 4297 | local _obj_0 = _exp_0[1] | ||
| 4298 | if _obj_0 ~= nil then | ||
| 4299 | _val_1 = _obj_0.b | ||
| 4300 | end | ||
| 4301 | end | ||
| 4302 | local _val_2 | ||
| 4303 | do | ||
| 4304 | local _obj_0 = _exp_0[2] | ||
| 4305 | if _obj_0 ~= nil then | ||
| 4306 | _val_2 = _obj_0.a | ||
| 4307 | end | ||
| 4308 | end | ||
| 4309 | local _val_3 | ||
| 4310 | do | ||
| 4311 | local _obj_0 = _exp_0[2] | ||
| 4312 | if _obj_0 ~= nil then | ||
| 4313 | _val_3 = _obj_0.b | ||
| 4314 | end | ||
| 4315 | end | ||
| 4316 | local _val_4 | ||
| 4317 | do | ||
| 4318 | local _obj_0 = _exp_0[3] | ||
| 4319 | if _obj_0 ~= nil then | ||
| 4320 | _val_4 = _obj_0.a | ||
| 4321 | end | ||
| 4322 | end | ||
| 4323 | local _val_5 | ||
| 4324 | do | ||
| 4325 | local _obj_0 = _exp_0[3] | ||
| 4326 | if _obj_0 ~= nil then | ||
| 4327 | _val_5 = _obj_0.b | ||
| 4328 | end | ||
| 4329 | end | ||
| 4330 | 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 | ||
| 4331 | print("matched", fourth) | ||
| 4332 | end | ||
| 4333 | end | ||
| 4334 | local segments = { | ||
| 4335 | "admin", | ||
| 4336 | "users", | ||
| 4337 | "logs", | ||
| 4338 | "view" | ||
| 4339 | } | ||
| 4340 | local _type_0 = type(segments) | ||
| 4341 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 4342 | if _tab_0 then | ||
| 4343 | local groups | ||
| 4344 | do | ||
| 4345 | local _accum_0 = { } | ||
| 4346 | local _len_0 = 1 | ||
| 4347 | local _max_0 = #segments + -3 + 1 | ||
| 4348 | for _index_0 = 1, _max_0 do | ||
| 4349 | local _item_0 = segments[_index_0] | ||
| 4350 | _accum_0[_len_0] = _item_0 | ||
| 4351 | _len_0 = _len_0 + 1 | ||
| 4352 | end | ||
| 4353 | groups = _accum_0 | ||
| 4354 | end | ||
| 4355 | local resource = segments[#segments - 1] | ||
| 4356 | local action = segments[#segments] | ||
| 4357 | if resource ~= nil and action ~= nil then | ||
| 4358 | print("Group:", groups) | ||
| 4359 | print("Resource:", resource) | ||
| 4360 | print("Action:", action) | ||
| 4361 | end | ||
| 4362 | end | ||
| 3289 | local Inventory | 4363 | local Inventory |
| 3290 | local _class_0 | 4364 | local _class_0 |
| 3291 | local _base_0 = { | 4365 | local _base_0 = { |
| @@ -3942,6 +5016,10 @@ do | |||
| 3942 | _with_1["key-name"] = value | 5016 | _with_1["key-name"] = value |
| 3943 | end | 5017 | end |
| 3944 | _with_0[#_with_0 + 1] = "abc" | 5018 | _with_0[#_with_0 + 1] = "abc" |
| 5019 | local _with_0 = obj | ||
| 5020 | if _with_0 ~= nil then | ||
| 5021 | print(obj.name) | ||
| 5022 | end | ||
| 3945 | do | 5023 | do |
| 3946 | local var = "hello" | 5024 | local var = "hello" |
| 3947 | print(var) | 5025 | print(var) |
diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua index acd41a0..89335c9 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, |
| @@ -41,8 +73,8 @@ local apple = setmetatable({ | |||
| 41 | if (getmetatable(apple) ~= nil) then | 73 | if (getmetatable(apple) ~= nil) then |
| 42 | p(apple.size, apple.color, getmetatable(apple).__index) | 74 | p(apple.size, apple.color, getmetatable(apple).__index) |
| 43 | end | 75 | end |
| 44 | local _ud83c_udf1b = "月之脚本" | 76 | local _u1f31b = "月之脚本" |
| 45 | _module_0["🌛"] = _ud83c_udf1b | 77 | _module_0["🌛"] = _u1f31b |
| 46 | return _module_0 | 78 | return _module_0 |
| 47 | local area = 6.2831853071796 * 5 | 79 | local area = 6.2831853071796 * 5 |
| 48 | print('你好 世界') | 80 | print('你好 世界') |
| @@ -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 |
| @@ -109,6 +147,21 @@ print((function() | |||
| 109 | end)()) | 147 | end)()) |
| 110 | local tab = { } | 148 | local tab = { } |
| 111 | tab[#tab + 1] = "Value" | 149 | tab[#tab + 1] = "Value" |
| 150 | local tbA = { | ||
| 151 | 1, | ||
| 152 | 2, | ||
| 153 | 3 | ||
| 154 | } | ||
| 155 | local tbB = { | ||
| 156 | 4, | ||
| 157 | 5, | ||
| 158 | 6 | ||
| 159 | } | ||
| 160 | local _len_0 = #tbA + 1 | ||
| 161 | for _index_0 = 1, #tbB do | ||
| 162 | local _elm_0 = tbB[_index_0] | ||
| 163 | tbA[_len_0], _len_0 = _elm_0, _len_0 + 1 | ||
| 164 | end | ||
| 112 | local parts = { | 165 | local parts = { |
| 113 | "shoulders", | 166 | "shoulders", |
| 114 | "knees" | 167 | "knees" |
| @@ -177,6 +230,18 @@ for _key_0, _value_0 in pairs(b) do | |||
| 177 | end | 230 | end |
| 178 | end | 231 | end |
| 179 | merge = _tab_0 | 232 | merge = _tab_0 |
| 233 | local last | ||
| 234 | do | ||
| 235 | local _item_0 = data.items | ||
| 236 | last = _item_0[#_item_0] | ||
| 237 | end | ||
| 238 | local second_last | ||
| 239 | do | ||
| 240 | local _item_0 = data.items | ||
| 241 | second_last = _item_0[#_item_0 - 1] | ||
| 242 | end | ||
| 243 | local _obj_0 = data.items | ||
| 244 | _obj_0[#_obj_0] = 1 | ||
| 180 | local mt = { } | 245 | local mt = { } |
| 181 | local add | 246 | local add |
| 182 | add = function(self, right) | 247 | add = function(self, right) |
| @@ -307,6 +372,14 @@ func({ | |||
| 307 | 2, | 372 | 2, |
| 308 | 3 | 373 | 3 |
| 309 | }) | 374 | }) |
| 375 | local f | ||
| 376 | f = function() | ||
| 377 | return { | ||
| 378 | 1, | ||
| 379 | 2, | ||
| 380 | 3 | ||
| 381 | } | ||
| 382 | end | ||
| 310 | local tb = { | 383 | local tb = { |
| 311 | name = "abc", | 384 | name = "abc", |
| 312 | values = { | 385 | values = { |
| @@ -368,6 +441,25 @@ do | |||
| 368 | local _obj_0 = require("export") | 441 | local _obj_0 = require("export") |
| 369 | one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] | 442 | one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] |
| 370 | end | 443 | end |
| 444 | do | ||
| 445 | local tostring <const> = tostring | ||
| 446 | local concat <const> = table.concat | ||
| 447 | print(concat({ | ||
| 448 | "a", | ||
| 449 | tostring(1) | ||
| 450 | })) | ||
| 451 | end | ||
| 452 | do | ||
| 453 | local print <const> = print | ||
| 454 | local math <const> = math | ||
| 455 | print("hello") | ||
| 456 | math.random(3) | ||
| 457 | end | ||
| 458 | do | ||
| 459 | local print <const> = print | ||
| 460 | print(FLAG) | ||
| 461 | FLAG = 123 | ||
| 462 | end | ||
| 371 | local _module_0 = { } | 463 | local _module_0 = { } |
| 372 | local a, b, c = 1, 2, 3 | 464 | local a, b, c = 1, 2, 3 |
| 373 | _module_0["a"], _module_0["b"], _module_0["c"] = a, b, c | 465 | _module_0["a"], _module_0["b"], _module_0["c"] = a, b, c |
| @@ -547,6 +639,59 @@ end | |||
| 547 | local two, four | 639 | local two, four |
| 548 | local _obj_0 = items | 640 | local _obj_0 = items |
| 549 | two, four = _obj_0[2], _obj_0[4] | 641 | two, four = _obj_0[2], _obj_0[4] |
| 642 | local orders = { | ||
| 643 | "first", | ||
| 644 | "second", | ||
| 645 | "third", | ||
| 646 | "fourth", | ||
| 647 | "last" | ||
| 648 | } | ||
| 649 | local first, bulk, last = orders[1], (function() | ||
| 650 | local _accum_0 = { } | ||
| 651 | local _len_0 = 1 | ||
| 652 | local _max_0 = #orders + -2 + 1 | ||
| 653 | for _index_0 = 2, _max_0 do | ||
| 654 | local _item_0 = orders[_index_0] | ||
| 655 | _accum_0[_len_0] = _item_0 | ||
| 656 | _len_0 = _len_0 + 1 | ||
| 657 | end | ||
| 658 | return _accum_0 | ||
| 659 | end)(), orders[#orders] | ||
| 660 | print(first) | ||
| 661 | print(bulk) | ||
| 662 | print(last) | ||
| 663 | local first, rest | ||
| 664 | do | ||
| 665 | local _obj_0 = orders | ||
| 666 | first, rest = _obj_0[1], (function() | ||
| 667 | local _accum_0 = { } | ||
| 668 | local _len_0 = 1 | ||
| 669 | local _max_0 = #_obj_0 | ||
| 670 | for _index_0 = 2, _max_0 do | ||
| 671 | local _item_0 = _obj_0[_index_0] | ||
| 672 | _accum_0[_len_0] = _item_0 | ||
| 673 | _len_0 = _len_0 + 1 | ||
| 674 | end | ||
| 675 | return _accum_0 | ||
| 676 | end)() | ||
| 677 | end | ||
| 678 | local start, last | ||
| 679 | do | ||
| 680 | local _obj_0 = orders | ||
| 681 | start, last = (function() | ||
| 682 | local _accum_0 = { } | ||
| 683 | local _len_0 = 1 | ||
| 684 | local _max_0 = #_obj_0 + -2 + 1 | ||
| 685 | for _index_0 = 1, _max_0 do | ||
| 686 | local _item_0 = _obj_0[_index_0] | ||
| 687 | _accum_0[_len_0] = _item_0 | ||
| 688 | _len_0 = _len_0 + 1 | ||
| 689 | end | ||
| 690 | return _accum_0 | ||
| 691 | end)(), _obj_0[#_obj_0] | ||
| 692 | end | ||
| 693 | local _obj_0 = orders | ||
| 694 | first, last = _obj_0[1], _obj_0[#_obj_0] | ||
| 550 | local tuples = { | 695 | local tuples = { |
| 551 | { | 696 | { |
| 552 | "hello", | 697 | "hello", |
| @@ -611,6 +756,9 @@ end | |||
| 611 | local first = select(1, ...) | 756 | local first = select(1, ...) |
| 612 | return print(ok, count, first) | 757 | return print(ok, count, first) |
| 613 | end)(fn(true)) | 758 | end)(fn(true)) |
| 759 | local a = 1 | ||
| 760 | local b = 2 | ||
| 761 | print(a + b) | ||
| 614 | Rx.Observable.fromRange(1, 8):filter(function(x) | 762 | Rx.Observable.fromRange(1, 8):filter(function(x) |
| 615 | return x % 2 == 0 | 763 | return x % 2 == 0 |
| 616 | end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) | 764 | end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) |
| @@ -648,6 +796,56 @@ end) | |||
| 648 | if success then | 796 | if success then |
| 649 | print(result) | 797 | print(result) |
| 650 | end | 798 | end |
| 799 | local a, b, c | ||
| 800 | do | ||
| 801 | local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function() | ||
| 802 | return func() | ||
| 803 | end) | ||
| 804 | if _ok_0 then | ||
| 805 | a, b, c = _ret_0, _ret_1, _ret_2 | ||
| 806 | end | ||
| 807 | end | ||
| 808 | do | ||
| 809 | local _exp_0 = ((function() | ||
| 810 | return (function(_arg_0, ...) | ||
| 811 | local _ok_0 = _arg_0 | ||
| 812 | if _ok_0 then | ||
| 813 | return ... | ||
| 814 | end | ||
| 815 | end)(pcall(function() | ||
| 816 | return func() | ||
| 817 | end)) | ||
| 818 | end)()) | ||
| 819 | if _exp_0 ~= nil then | ||
| 820 | a = _exp_0 | ||
| 821 | else | ||
| 822 | a = "default" | ||
| 823 | end | ||
| 824 | end | ||
| 825 | f((function() | ||
| 826 | return (function(_arg_0, ...) | ||
| 827 | local _ok_0 = _arg_0 | ||
| 828 | if _ok_0 then | ||
| 829 | return ... | ||
| 830 | end | ||
| 831 | end)(pcall(function() | ||
| 832 | return func() | ||
| 833 | end)) | ||
| 834 | end)()) | ||
| 835 | f((function() | ||
| 836 | return (function(_arg_0, ...) | ||
| 837 | local _ok_0 = _arg_0 | ||
| 838 | if _ok_0 then | ||
| 839 | return ... | ||
| 840 | end | ||
| 841 | end)(xpcall(function() | ||
| 842 | print(123) | ||
| 843 | return func() | ||
| 844 | end, function(e) | ||
| 845 | print(e) | ||
| 846 | return e | ||
| 847 | end)) | ||
| 848 | end)()) | ||
| 651 | local a <const> = 123 | 849 | local a <const> = 123 |
| 652 | local _ <close> = setmetatable({ }, { | 850 | local _ <close> = setmetatable({ }, { |
| 653 | __close = function() | 851 | __close = function() |
| @@ -657,10 +855,19 @@ local _ <close> = setmetatable({ }, { | |||
| 657 | local a, b, c, d | 855 | local a, b, c, d |
| 658 | local _obj_0 = tb | 856 | local _obj_0 = tb |
| 659 | a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] | 857 | a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] |
| 858 | Constant = 123 | ||
| 660 | local some_string = "这是一个字符串\n 并包括一个换行。" | 859 | local some_string = "这是一个字符串\n 并包括一个换行。" |
| 661 | print("我有" .. tostring(math.random() * 100) .. "%的把握。") | 860 | print("我有" .. tostring(math.random() * 100) .. "%的把握。") |
| 662 | local integer = 1000000 | 861 | local integer = 1000000 |
| 663 | local hex = 0xEFBBBF | 862 | local hex = 0xEFBBBF |
| 863 | local binary = 19 | ||
| 864 | local str = "key: value\nlist:\n - item1\n - " .. tostring(expr) | ||
| 865 | local fn | ||
| 866 | fn = function() | ||
| 867 | local str = "foo:\n bar: baz" | ||
| 868 | return str | ||
| 869 | end | ||
| 870 | local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'" | ||
| 664 | local my_function | 871 | local my_function |
| 665 | my_function = function() end | 872 | my_function = function() end |
| 666 | my_function() | 873 | my_function() |
| @@ -749,6 +956,66 @@ if func(1, 2, 3, "你好", "世界") then | |||
| 749 | print("hello") | 956 | print("hello") |
| 750 | print("我在if内部") | 957 | print("我在if内部") |
| 751 | end | 958 | end |
| 959 | local f1 | ||
| 960 | f1 = function(_arg_0) | ||
| 961 | local a, b, c | ||
| 962 | a, b, c = _arg_0.a, _arg_0.b, _arg_0.c | ||
| 963 | return print(a, b, c) | ||
| 964 | end | ||
| 965 | f1({ | ||
| 966 | a = 1, | ||
| 967 | b = "2", | ||
| 968 | c = { } | ||
| 969 | }) | ||
| 970 | local f2 | ||
| 971 | f2 = function(_arg_0, c) | ||
| 972 | local a1, b | ||
| 973 | a1, b = _arg_0.a, _arg_0.b | ||
| 974 | if a1 == nil then | ||
| 975 | a1 = 123 | ||
| 976 | end | ||
| 977 | if b == nil then | ||
| 978 | b = 'abc' | ||
| 979 | end | ||
| 980 | if c == nil then | ||
| 981 | c = { } | ||
| 982 | end | ||
| 983 | return print(a1, b, c) | ||
| 984 | end | ||
| 985 | local arg1 = { | ||
| 986 | a = 0 | ||
| 987 | } | ||
| 988 | f2(arg1, arg2) | ||
| 989 | local f | ||
| 990 | f = function(...) | ||
| 991 | local t = { | ||
| 992 | n = select("#", ...), | ||
| 993 | ... | ||
| 994 | } | ||
| 995 | print("参数个数:", t.n) | ||
| 996 | print("表长度:", #t) | ||
| 997 | for i = 1, t.n do | ||
| 998 | print(t[i]) | ||
| 999 | end | ||
| 1000 | end | ||
| 1001 | f(1, 2, 3) | ||
| 1002 | f("a", "b", "c", "d") | ||
| 1003 | f() | ||
| 1004 | local process | ||
| 1005 | process = function(...) | ||
| 1006 | local args = { | ||
| 1007 | n = select("#", ...), | ||
| 1008 | ... | ||
| 1009 | } | ||
| 1010 | local sum = 0 | ||
| 1011 | for i = 1, args.n do | ||
| 1012 | if args[i] ~= nil and type(args[i]) == "number" then | ||
| 1013 | sum = sum + args[i] | ||
| 1014 | end | ||
| 1015 | end | ||
| 1016 | return sum | ||
| 1017 | end | ||
| 1018 | process(1, nil, 3, nil, 5) | ||
| 752 | f(function() | 1019 | f(function() |
| 753 | return print("hello") | 1020 | return print("hello") |
| 754 | end) | 1021 | end) |
| @@ -874,6 +1141,28 @@ for _index_0 = 1, #_list_0 do | |||
| 874 | _len_0 = _len_0 + 1 | 1141 | _len_0 = _len_0 + 1 |
| 875 | end | 1142 | end |
| 876 | doubled = _accum_0 | 1143 | doubled = _accum_0 |
| 1144 | local data = { | ||
| 1145 | a = { | ||
| 1146 | 1, | ||
| 1147 | 2, | ||
| 1148 | 3 | ||
| 1149 | }, | ||
| 1150 | b = { | ||
| 1151 | 4, | ||
| 1152 | 5, | ||
| 1153 | 6 | ||
| 1154 | } | ||
| 1155 | } | ||
| 1156 | local flat | ||
| 1157 | local _accum_0 = { } | ||
| 1158 | for k, v in pairs(data) do | ||
| 1159 | local _len_0 = #_accum_0 + 1 | ||
| 1160 | for _index_0 = 1, #v do | ||
| 1161 | local _elm_0 = v[_index_0] | ||
| 1162 | _accum_0[_len_0], _len_0 = _elm_0, _len_0 + 1 | ||
| 1163 | end | ||
| 1164 | end | ||
| 1165 | flat = _accum_0 | ||
| 877 | local x_coords = { | 1166 | local x_coords = { |
| 878 | 4, | 1167 | 4, |
| 879 | 5, | 1168 | 5, |
| @@ -964,8 +1253,18 @@ local slice | |||
| 964 | local _accum_0 = { } | 1253 | local _accum_0 = { } |
| 965 | local _len_0 = 1 | 1254 | local _len_0 = 1 |
| 966 | local _list_0 = items | 1255 | local _list_0 = items |
| 967 | local _max_0 = 5 | 1256 | for _index_0 = 1, 5 do |
| 968 | for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do | 1257 | local item = _list_0[_index_0] |
| 1258 | _accum_0[_len_0] = item | ||
| 1259 | _len_0 = _len_0 + 1 | ||
| 1260 | end | ||
| 1261 | slice = _accum_0 | ||
| 1262 | local slice | ||
| 1263 | local _accum_0 = { } | ||
| 1264 | local _len_0 = 1 | ||
| 1265 | local _list_0 = items | ||
| 1266 | local _max_0 = #_list_0 | ||
| 1267 | for _index_0 = 2, _max_0 do | ||
| 969 | local item = _list_0[_index_0] | 1268 | local item = _list_0[_index_0] |
| 970 | _accum_0[_len_0] = item | 1269 | _accum_0[_len_0] = item |
| 971 | _len_0 = _len_0 + 1 | 1270 | _len_0 = _len_0 + 1 |
| @@ -975,7 +1274,8 @@ local slice | |||
| 975 | local _accum_0 = { } | 1274 | local _accum_0 = { } |
| 976 | local _len_0 = 1 | 1275 | local _len_0 = 1 |
| 977 | local _list_0 = items | 1276 | local _list_0 = items |
| 978 | for _index_0 = 2, #_list_0 do | 1277 | local _max_0 = #_list_0 |
| 1278 | for _index_0 = 1, _max_0, 2 do | ||
| 979 | local item = _list_0[_index_0] | 1279 | local item = _list_0[_index_0] |
| 980 | _accum_0[_len_0] = item | 1280 | _accum_0[_len_0] = item |
| 981 | _len_0 = _len_0 + 1 | 1281 | _len_0 = _len_0 + 1 |
| @@ -985,12 +1285,35 @@ local slice | |||
| 985 | local _accum_0 = { } | 1285 | local _accum_0 = { } |
| 986 | local _len_0 = 1 | 1286 | local _len_0 = 1 |
| 987 | local _list_0 = items | 1287 | local _list_0 = items |
| 988 | for _index_0 = 1, #_list_0, 2 do | 1288 | local _min_0 = #_list_0 + -4 + 1 |
| 1289 | local _max_0 = #_list_0 + -1 + 1 | ||
| 1290 | for _index_0 = _min_0, _max_0 do | ||
| 989 | local item = _list_0[_index_0] | 1291 | local item = _list_0[_index_0] |
| 990 | _accum_0[_len_0] = item | 1292 | _accum_0[_len_0] = item |
| 991 | _len_0 = _len_0 + 1 | 1293 | _len_0 = _len_0 + 1 |
| 992 | end | 1294 | end |
| 993 | slice = _accum_0 | 1295 | slice = _accum_0 |
| 1296 | local reverse_slice | ||
| 1297 | local _accum_0 = { } | ||
| 1298 | local _len_0 = 1 | ||
| 1299 | local _list_0 = items | ||
| 1300 | local _min_0 = #_list_0 + -1 + 1 | ||
| 1301 | for _index_0 = _min_0, 1, -1 do | ||
| 1302 | local item = _list_0[_index_0] | ||
| 1303 | _accum_0[_len_0] = item | ||
| 1304 | _len_0 = _len_0 + 1 | ||
| 1305 | end | ||
| 1306 | reverse_slice = _accum_0 | ||
| 1307 | local sub_list | ||
| 1308 | local _accum_0 = { } | ||
| 1309 | local _len_0 = 1 | ||
| 1310 | local _list_0 = items | ||
| 1311 | for _index_0 = 2, 4 do | ||
| 1312 | local _item_0 = _list_0[_index_0] | ||
| 1313 | _accum_0[_len_0] = _item_0 | ||
| 1314 | _len_0 = _len_0 + 1 | ||
| 1315 | end | ||
| 1316 | sub_list = _accum_0 | ||
| 994 | for i = 10, 20 do | 1317 | for i = 10, 20 do |
| 995 | print(i) | 1318 | print(i) |
| 996 | end | 1319 | end |
| @@ -1001,8 +1324,7 @@ for key, value in pairs(object) do | |||
| 1001 | print(key, value) | 1324 | print(key, value) |
| 1002 | end | 1325 | end |
| 1003 | local _list_0 = items | 1326 | local _list_0 = items |
| 1004 | local _max_0 = 4 | 1327 | for _index_0 = 2, 4 do |
| 1005 | for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do | ||
| 1006 | local item = _list_0[_index_0] | 1328 | local item = _list_0[_index_0] |
| 1007 | print(item) | 1329 | print(item) |
| 1008 | end | 1330 | end |
| @@ -1020,12 +1342,24 @@ local _len_0 = 1 | |||
| 1020 | for i = 1, 20 do | 1342 | for i = 1, 20 do |
| 1021 | if i % 2 == 0 then | 1343 | if i % 2 == 0 then |
| 1022 | _accum_0[_len_0] = i * 2 | 1344 | _accum_0[_len_0] = i * 2 |
| 1345 | _len_0 = _len_0 + 1 | ||
| 1023 | else | 1346 | else |
| 1024 | _accum_0[_len_0] = i | 1347 | _accum_0[_len_0] = i |
| 1348 | _len_0 = _len_0 + 1 | ||
| 1025 | end | 1349 | end |
| 1026 | _len_0 = _len_0 + 1 | ||
| 1027 | end | 1350 | end |
| 1028 | doubled_evens = _accum_0 | 1351 | doubled_evens = _accum_0 |
| 1352 | local first_large | ||
| 1353 | local _accum_0 | ||
| 1354 | local _list_0 = numbers | ||
| 1355 | for _index_0 = 1, #_list_0 do | ||
| 1356 | local n = _list_0[_index_0] | ||
| 1357 | if n > 10 then | ||
| 1358 | _accum_0 = n | ||
| 1359 | break | ||
| 1360 | end | ||
| 1361 | end | ||
| 1362 | first_large = _accum_0 | ||
| 1029 | local func_a | 1363 | local func_a |
| 1030 | func_a = function() | 1364 | func_a = function() |
| 1031 | for i = 1, 10 do | 1365 | for i = 1, 10 do |
| @@ -1174,7 +1508,7 @@ if "Robert" == name then | |||
| 1174 | elseif "Dan" == name or "Daniel" == name then | 1508 | elseif "Dan" == name or "Daniel" == name then |
| 1175 | print("你的名字是Dan") | 1509 | print("你的名字是Dan") |
| 1176 | else | 1510 | else |
| 1177 | print("我不知道你的名字") | 1511 | print("我不认识你,你的名字是" .. tostring(name)) |
| 1178 | end | 1512 | end |
| 1179 | local b = 1 | 1513 | local b = 1 |
| 1180 | local next_number | 1514 | local next_number |
| @@ -1274,6 +1608,192 @@ if _tab_0 then | |||
| 1274 | end | 1608 | end |
| 1275 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) | 1609 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) |
| 1276 | end | 1610 | end |
| 1611 | local _exp_0 = tb | ||
| 1612 | local _type_0 = type(_exp_0) | ||
| 1613 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 1614 | local _match_0 = false | ||
| 1615 | if _tab_0 then | ||
| 1616 | if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then | ||
| 1617 | _match_0 = true | ||
| 1618 | print("1, 2, 3") | ||
| 1619 | end | ||
| 1620 | end | ||
| 1621 | if not _match_0 then | ||
| 1622 | local _match_1 = false | ||
| 1623 | if _tab_0 then | ||
| 1624 | local b = _exp_0[2] | ||
| 1625 | if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then | ||
| 1626 | _match_1 = true | ||
| 1627 | print("1, " .. tostring(b) .. ", 3") | ||
| 1628 | end | ||
| 1629 | end | ||
| 1630 | if not _match_1 then | ||
| 1631 | if _tab_0 then | ||
| 1632 | local b = _exp_0[3] | ||
| 1633 | if b == nil then | ||
| 1634 | b = 3 | ||
| 1635 | end | ||
| 1636 | if 1 == _exp_0[1] and 2 == _exp_0[2] then | ||
| 1637 | print("1, 2, " .. tostring(b)) | ||
| 1638 | end | ||
| 1639 | end | ||
| 1640 | end | ||
| 1641 | end | ||
| 1642 | local _exp_0 = tb | ||
| 1643 | local _type_0 = type(_exp_0) | ||
| 1644 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 1645 | local _match_0 = false | ||
| 1646 | if _tab_0 then | ||
| 1647 | local result = _exp_0.result | ||
| 1648 | if true == _exp_0.success and result ~= nil then | ||
| 1649 | _match_0 = true | ||
| 1650 | print("成功", result) | ||
| 1651 | end | ||
| 1652 | end | ||
| 1653 | if not _match_0 then | ||
| 1654 | local _match_1 = false | ||
| 1655 | if _tab_0 then | ||
| 1656 | if false == _exp_0.success then | ||
| 1657 | _match_1 = true | ||
| 1658 | print("失败", result) | ||
| 1659 | end | ||
| 1660 | end | ||
| 1661 | if not _match_1 then | ||
| 1662 | print("无效值") | ||
| 1663 | end | ||
| 1664 | end | ||
| 1665 | local _exp_0 = tb | ||
| 1666 | local _type_0 = type(_exp_0) | ||
| 1667 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 1668 | local _match_0 = false | ||
| 1669 | if _tab_0 then | ||
| 1670 | local content | ||
| 1671 | do | ||
| 1672 | local _obj_0 = _exp_0.data | ||
| 1673 | local _type_1 = type(_obj_0) | ||
| 1674 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 1675 | content = _obj_0.content | ||
| 1676 | end | ||
| 1677 | end | ||
| 1678 | local _val_0 | ||
| 1679 | do | ||
| 1680 | local _obj_0 = _exp_0.data | ||
| 1681 | if _obj_0 ~= nil then | ||
| 1682 | _val_0 = _obj_0.type | ||
| 1683 | end | ||
| 1684 | end | ||
| 1685 | if "success" == _val_0 and content ~= nil then | ||
| 1686 | _match_0 = true | ||
| 1687 | print("成功", content) | ||
| 1688 | end | ||
| 1689 | end | ||
| 1690 | if not _match_0 then | ||
| 1691 | local _match_1 = false | ||
| 1692 | if _tab_0 then | ||
| 1693 | local content | ||
| 1694 | do | ||
| 1695 | local _obj_0 = _exp_0.data | ||
| 1696 | local _type_1 = type(_obj_0) | ||
| 1697 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 1698 | content = _obj_0.content | ||
| 1699 | end | ||
| 1700 | end | ||
| 1701 | local _val_0 | ||
| 1702 | do | ||
| 1703 | local _obj_0 = _exp_0.data | ||
| 1704 | if _obj_0 ~= nil then | ||
| 1705 | _val_0 = _obj_0.type | ||
| 1706 | end | ||
| 1707 | end | ||
| 1708 | if "error" == _val_0 and content ~= nil then | ||
| 1709 | _match_1 = true | ||
| 1710 | print("失败", content) | ||
| 1711 | end | ||
| 1712 | end | ||
| 1713 | if not _match_1 then | ||
| 1714 | print("无效值") | ||
| 1715 | end | ||
| 1716 | end | ||
| 1717 | local _exp_0 = tb | ||
| 1718 | local _type_0 = type(_exp_0) | ||
| 1719 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 1720 | if _tab_0 then | ||
| 1721 | local fourth = _exp_0[4] | ||
| 1722 | local _val_0 | ||
| 1723 | do | ||
| 1724 | local _obj_0 = _exp_0[1] | ||
| 1725 | if _obj_0 ~= nil then | ||
| 1726 | _val_0 = _obj_0.a | ||
| 1727 | end | ||
| 1728 | end | ||
| 1729 | local _val_1 | ||
| 1730 | do | ||
| 1731 | local _obj_0 = _exp_0[1] | ||
| 1732 | if _obj_0 ~= nil then | ||
| 1733 | _val_1 = _obj_0.b | ||
| 1734 | end | ||
| 1735 | end | ||
| 1736 | local _val_2 | ||
| 1737 | do | ||
| 1738 | local _obj_0 = _exp_0[2] | ||
| 1739 | if _obj_0 ~= nil then | ||
| 1740 | _val_2 = _obj_0.a | ||
| 1741 | end | ||
| 1742 | end | ||
| 1743 | local _val_3 | ||
| 1744 | do | ||
| 1745 | local _obj_0 = _exp_0[2] | ||
| 1746 | if _obj_0 ~= nil then | ||
| 1747 | _val_3 = _obj_0.b | ||
| 1748 | end | ||
| 1749 | end | ||
| 1750 | local _val_4 | ||
| 1751 | do | ||
| 1752 | local _obj_0 = _exp_0[3] | ||
| 1753 | if _obj_0 ~= nil then | ||
| 1754 | _val_4 = _obj_0.a | ||
| 1755 | end | ||
| 1756 | end | ||
| 1757 | local _val_5 | ||
| 1758 | do | ||
| 1759 | local _obj_0 = _exp_0[3] | ||
| 1760 | if _obj_0 ~= nil then | ||
| 1761 | _val_5 = _obj_0.b | ||
| 1762 | end | ||
| 1763 | end | ||
| 1764 | 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 | ||
| 1765 | print("匹配成功", fourth) | ||
| 1766 | end | ||
| 1767 | end | ||
| 1768 | local segments = { | ||
| 1769 | "admin", | ||
| 1770 | "users", | ||
| 1771 | "logs", | ||
| 1772 | "view" | ||
| 1773 | } | ||
| 1774 | local _type_0 = type(segments) | ||
| 1775 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 1776 | if _tab_0 then | ||
| 1777 | local groups | ||
| 1778 | do | ||
| 1779 | local _accum_0 = { } | ||
| 1780 | local _len_0 = 1 | ||
| 1781 | local _max_0 = #segments + -3 + 1 | ||
| 1782 | for _index_0 = 1, _max_0 do | ||
| 1783 | local _item_0 = segments[_index_0] | ||
| 1784 | _accum_0[_len_0] = _item_0 | ||
| 1785 | _len_0 = _len_0 + 1 | ||
| 1786 | end | ||
| 1787 | groups = _accum_0 | ||
| 1788 | end | ||
| 1789 | local resource = segments[#segments - 1] | ||
| 1790 | local action = segments[#segments] | ||
| 1791 | if resource ~= nil and action ~= nil then | ||
| 1792 | print("Group:", groups) | ||
| 1793 | print("Resource:", resource) | ||
| 1794 | print("Action:", action) | ||
| 1795 | end | ||
| 1796 | end | ||
| 1277 | local Inventory | 1797 | local Inventory |
| 1278 | local _class_0 | 1798 | local _class_0 |
| 1279 | local _base_0 = { | 1799 | local _base_0 = { |
| @@ -1930,6 +2450,10 @@ do | |||
| 1930 | _with_1["key-name"] = value | 2450 | _with_1["key-name"] = value |
| 1931 | end | 2451 | end |
| 1932 | _with_0[#_with_0 + 1] = "abc" | 2452 | _with_0[#_with_0 + 1] = "abc" |
| 2453 | local _with_0 = obj | ||
| 2454 | if _with_0 ~= nil then | ||
| 2455 | print(obj.name) | ||
| 2456 | end | ||
| 1933 | do | 2457 | do |
| 1934 | local var = "hello" | 2458 | local var = "hello" |
| 1935 | print(var) | 2459 | print(var) |
| @@ -2020,6 +2544,38 @@ local inventory = { | |||
| 2020 | } | 2544 | } |
| 2021 | } | 2545 | } |
| 2022 | } | 2546 | } |
| 2547 | local map | ||
| 2548 | map = function(arr, action) | ||
| 2549 | local _accum_0 = { } | ||
| 2550 | local _len_0 = 1 | ||
| 2551 | for _index_0 = 1, #arr do | ||
| 2552 | local item = arr[_index_0] | ||
| 2553 | _accum_0[_len_0] = action(item) | ||
| 2554 | _len_0 = _len_0 + 1 | ||
| 2555 | end | ||
| 2556 | return _accum_0 | ||
| 2557 | end | ||
| 2558 | local filter | ||
| 2559 | filter = function(arr, cond) | ||
| 2560 | local _accum_0 = { } | ||
| 2561 | local _len_0 = 1 | ||
| 2562 | for _index_0 = 1, #arr do | ||
| 2563 | local item = arr[_index_0] | ||
| 2564 | if cond(item) then | ||
| 2565 | _accum_0[_len_0] = item | ||
| 2566 | _len_0 = _len_0 + 1 | ||
| 2567 | end | ||
| 2568 | end | ||
| 2569 | return _accum_0 | ||
| 2570 | end | ||
| 2571 | local reduce | ||
| 2572 | reduce = function(arr, init, action) | ||
| 2573 | for _index_0 = 1, #arr do | ||
| 2574 | local item = arr[_index_0] | ||
| 2575 | init = action(init, item) | ||
| 2576 | end | ||
| 2577 | return init | ||
| 2578 | end | ||
| 2023 | print(reduce(filter(map({ | 2579 | print(reduce(filter(map({ |
| 2024 | 1, | 2580 | 1, |
| 2025 | 2, | 2581 | 2, |
| @@ -2041,8 +2597,8 @@ local apple = setmetatable({ | |||
| 2041 | if (getmetatable(apple) ~= nil) then | 2597 | if (getmetatable(apple) ~= nil) then |
| 2042 | p(apple.size, apple.color, getmetatable(apple).__index) | 2598 | p(apple.size, apple.color, getmetatable(apple).__index) |
| 2043 | end | 2599 | end |
| 2044 | local _ud83c_udf1b = "月之脚本" | 2600 | local _u1f31b = "月之脚本" |
| 2045 | _module_0["🌛"] = _ud83c_udf1b | 2601 | _module_0["🌛"] = _u1f31b |
| 2046 | return _module_0 | 2602 | return _module_0 |
| 2047 | local area = 6.2831853071796 * 5 | 2603 | local area = 6.2831853071796 * 5 |
| 2048 | print('你好 世界') | 2604 | print('你好 世界') |
| @@ -2077,6 +2633,12 @@ end | |||
| 2077 | print("yuescript") | 2633 | print("yuescript") |
| 2078 | print(3) | 2634 | print(3) |
| 2079 | print("有效的枚举类型:", "Static") | 2635 | print("有效的枚举类型:", "Static") |
| 2636 | do | ||
| 2637 | print(123, "hello") | ||
| 2638 | end | ||
| 2639 | do | ||
| 2640 | print(123, "hello") | ||
| 2641 | end | ||
| 2080 | if tb ~= nil then | 2642 | if tb ~= nil then |
| 2081 | tb:func() | 2643 | tb:func() |
| 2082 | end | 2644 | end |
| @@ -2109,6 +2671,21 @@ print((function() | |||
| 2109 | end)()) | 2671 | end)()) |
| 2110 | local tab = { } | 2672 | local tab = { } |
| 2111 | tab[#tab + 1] = "Value" | 2673 | tab[#tab + 1] = "Value" |
| 2674 | local tbA = { | ||
| 2675 | 1, | ||
| 2676 | 2, | ||
| 2677 | 3 | ||
| 2678 | } | ||
| 2679 | local tbB = { | ||
| 2680 | 4, | ||
| 2681 | 5, | ||
| 2682 | 6 | ||
| 2683 | } | ||
| 2684 | local _len_0 = #tbA + 1 | ||
| 2685 | for _index_0 = 1, #tbB do | ||
| 2686 | local _elm_0 = tbB[_index_0] | ||
| 2687 | tbA[_len_0], _len_0 = _elm_0, _len_0 + 1 | ||
| 2688 | end | ||
| 2112 | local parts = { | 2689 | local parts = { |
| 2113 | "shoulders", | 2690 | "shoulders", |
| 2114 | "knees" | 2691 | "knees" |
| @@ -2177,6 +2754,18 @@ for _key_0, _value_0 in pairs(b) do | |||
| 2177 | end | 2754 | end |
| 2178 | end | 2755 | end |
| 2179 | merge = _tab_0 | 2756 | merge = _tab_0 |
| 2757 | local last | ||
| 2758 | do | ||
| 2759 | local _item_0 = data.items | ||
| 2760 | last = _item_0[#_item_0] | ||
| 2761 | end | ||
| 2762 | local second_last | ||
| 2763 | do | ||
| 2764 | local _item_0 = data.items | ||
| 2765 | second_last = _item_0[#_item_0 - 1] | ||
| 2766 | end | ||
| 2767 | local _obj_0 = data.items | ||
| 2768 | _obj_0[#_obj_0] = 1 | ||
| 2180 | local mt = { } | 2769 | local mt = { } |
| 2181 | local add | 2770 | local add |
| 2182 | add = function(self, right) | 2771 | add = function(self, right) |
| @@ -2307,6 +2896,14 @@ func({ | |||
| 2307 | 2, | 2896 | 2, |
| 2308 | 3 | 2897 | 3 |
| 2309 | }) | 2898 | }) |
| 2899 | local f | ||
| 2900 | f = function() | ||
| 2901 | return { | ||
| 2902 | 1, | ||
| 2903 | 2, | ||
| 2904 | 3 | ||
| 2905 | } | ||
| 2906 | end | ||
| 2310 | local tb = { | 2907 | local tb = { |
| 2311 | name = "abc", | 2908 | name = "abc", |
| 2312 | values = { | 2909 | values = { |
| @@ -2368,6 +2965,25 @@ do | |||
| 2368 | local _obj_0 = require("export") | 2965 | local _obj_0 = require("export") |
| 2369 | one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] | 2966 | one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] |
| 2370 | end | 2967 | end |
| 2968 | do | ||
| 2969 | local tostring <const> = tostring | ||
| 2970 | local concat <const> = table.concat | ||
| 2971 | print(concat({ | ||
| 2972 | "a", | ||
| 2973 | tostring(1) | ||
| 2974 | })) | ||
| 2975 | end | ||
| 2976 | do | ||
| 2977 | local print <const> = print | ||
| 2978 | local math <const> = math | ||
| 2979 | print("hello") | ||
| 2980 | math.random(3) | ||
| 2981 | end | ||
| 2982 | do | ||
| 2983 | local print <const> = print | ||
| 2984 | print(FLAG) | ||
| 2985 | FLAG = 123 | ||
| 2986 | end | ||
| 2371 | local _module_0 = { } | 2987 | local _module_0 = { } |
| 2372 | local a, b, c = 1, 2, 3 | 2988 | local a, b, c = 1, 2, 3 |
| 2373 | _module_0["a"], _module_0["b"], _module_0["c"] = a, b, c | 2989 | _module_0["a"], _module_0["b"], _module_0["c"] = a, b, c |
| @@ -2547,6 +3163,59 @@ end | |||
| 2547 | local two, four | 3163 | local two, four |
| 2548 | local _obj_0 = items | 3164 | local _obj_0 = items |
| 2549 | two, four = _obj_0[2], _obj_0[4] | 3165 | two, four = _obj_0[2], _obj_0[4] |
| 3166 | local orders = { | ||
| 3167 | "first", | ||
| 3168 | "second", | ||
| 3169 | "third", | ||
| 3170 | "fourth", | ||
| 3171 | "last" | ||
| 3172 | } | ||
| 3173 | local first, bulk, last = orders[1], (function() | ||
| 3174 | local _accum_0 = { } | ||
| 3175 | local _len_0 = 1 | ||
| 3176 | local _max_0 = #orders + -2 + 1 | ||
| 3177 | for _index_0 = 2, _max_0 do | ||
| 3178 | local _item_0 = orders[_index_0] | ||
| 3179 | _accum_0[_len_0] = _item_0 | ||
| 3180 | _len_0 = _len_0 + 1 | ||
| 3181 | end | ||
| 3182 | return _accum_0 | ||
| 3183 | end)(), orders[#orders] | ||
| 3184 | print(first) | ||
| 3185 | print(bulk) | ||
| 3186 | print(last) | ||
| 3187 | local first, rest | ||
| 3188 | do | ||
| 3189 | local _obj_0 = orders | ||
| 3190 | first, rest = _obj_0[1], (function() | ||
| 3191 | local _accum_0 = { } | ||
| 3192 | local _len_0 = 1 | ||
| 3193 | local _max_0 = #_obj_0 | ||
| 3194 | for _index_0 = 2, _max_0 do | ||
| 3195 | local _item_0 = _obj_0[_index_0] | ||
| 3196 | _accum_0[_len_0] = _item_0 | ||
| 3197 | _len_0 = _len_0 + 1 | ||
| 3198 | end | ||
| 3199 | return _accum_0 | ||
| 3200 | end)() | ||
| 3201 | end | ||
| 3202 | local start, last | ||
| 3203 | do | ||
| 3204 | local _obj_0 = orders | ||
| 3205 | start, last = (function() | ||
| 3206 | local _accum_0 = { } | ||
| 3207 | local _len_0 = 1 | ||
| 3208 | local _max_0 = #_obj_0 + -2 + 1 | ||
| 3209 | for _index_0 = 1, _max_0 do | ||
| 3210 | local _item_0 = _obj_0[_index_0] | ||
| 3211 | _accum_0[_len_0] = _item_0 | ||
| 3212 | _len_0 = _len_0 + 1 | ||
| 3213 | end | ||
| 3214 | return _accum_0 | ||
| 3215 | end)(), _obj_0[#_obj_0] | ||
| 3216 | end | ||
| 3217 | local _obj_0 = orders | ||
| 3218 | first, last = _obj_0[1], _obj_0[#_obj_0] | ||
| 2550 | local tuples = { | 3219 | local tuples = { |
| 2551 | { | 3220 | { |
| 2552 | "hello", | 3221 | "hello", |
| @@ -2611,6 +3280,9 @@ end | |||
| 2611 | local first = select(1, ...) | 3280 | local first = select(1, ...) |
| 2612 | return print(ok, count, first) | 3281 | return print(ok, count, first) |
| 2613 | end)(fn(true)) | 3282 | end)(fn(true)) |
| 3283 | local a = 1 | ||
| 3284 | local b = 2 | ||
| 3285 | print(a + b) | ||
| 2614 | Rx.Observable.fromRange(1, 8):filter(function(x) | 3286 | Rx.Observable.fromRange(1, 8):filter(function(x) |
| 2615 | return x % 2 == 0 | 3287 | return x % 2 == 0 |
| 2616 | end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) | 3288 | end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) |
| @@ -2648,6 +3320,56 @@ end) | |||
| 2648 | if success then | 3320 | if success then |
| 2649 | print(result) | 3321 | print(result) |
| 2650 | end | 3322 | end |
| 3323 | local a, b, c | ||
| 3324 | do | ||
| 3325 | local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function() | ||
| 3326 | return func() | ||
| 3327 | end) | ||
| 3328 | if _ok_0 then | ||
| 3329 | a, b, c = _ret_0, _ret_1, _ret_2 | ||
| 3330 | end | ||
| 3331 | end | ||
| 3332 | do | ||
| 3333 | local _exp_0 = ((function() | ||
| 3334 | return (function(_arg_0, ...) | ||
| 3335 | local _ok_0 = _arg_0 | ||
| 3336 | if _ok_0 then | ||
| 3337 | return ... | ||
| 3338 | end | ||
| 3339 | end)(pcall(function() | ||
| 3340 | return func() | ||
| 3341 | end)) | ||
| 3342 | end)()) | ||
| 3343 | if _exp_0 ~= nil then | ||
| 3344 | a = _exp_0 | ||
| 3345 | else | ||
| 3346 | a = "default" | ||
| 3347 | end | ||
| 3348 | end | ||
| 3349 | f((function() | ||
| 3350 | return (function(_arg_0, ...) | ||
| 3351 | local _ok_0 = _arg_0 | ||
| 3352 | if _ok_0 then | ||
| 3353 | return ... | ||
| 3354 | end | ||
| 3355 | end)(pcall(function() | ||
| 3356 | return func() | ||
| 3357 | end)) | ||
| 3358 | end)()) | ||
| 3359 | f((function() | ||
| 3360 | return (function(_arg_0, ...) | ||
| 3361 | local _ok_0 = _arg_0 | ||
| 3362 | if _ok_0 then | ||
| 3363 | return ... | ||
| 3364 | end | ||
| 3365 | end)(xpcall(function() | ||
| 3366 | print(123) | ||
| 3367 | return func() | ||
| 3368 | end, function(e) | ||
| 3369 | print(e) | ||
| 3370 | return e | ||
| 3371 | end)) | ||
| 3372 | end)()) | ||
| 2651 | local a <const> = 123 | 3373 | local a <const> = 123 |
| 2652 | local _ <close> = setmetatable({ }, { | 3374 | local _ <close> = setmetatable({ }, { |
| 2653 | __close = function() | 3375 | __close = function() |
| @@ -2657,10 +3379,19 @@ local _ <close> = setmetatable({ }, { | |||
| 2657 | local a, b, c, d | 3379 | local a, b, c, d |
| 2658 | local _obj_0 = tb | 3380 | local _obj_0 = tb |
| 2659 | a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] | 3381 | a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] |
| 3382 | Constant = 123 | ||
| 2660 | local some_string = "这是一个字符串\n 并包括一个换行。" | 3383 | local some_string = "这是一个字符串\n 并包括一个换行。" |
| 2661 | print("我有" .. tostring(math.random() * 100) .. "%的把握。") | 3384 | print("我有" .. tostring(math.random() * 100) .. "%的把握。") |
| 2662 | local integer = 1000000 | 3385 | local integer = 1000000 |
| 2663 | local hex = 0xEFBBBF | 3386 | local hex = 0xEFBBBF |
| 3387 | local binary = 19 | ||
| 3388 | local str = "key: value\nlist:\n - item1\n - " .. tostring(expr) | ||
| 3389 | local fn | ||
| 3390 | fn = function() | ||
| 3391 | local str = "foo:\n bar: baz" | ||
| 3392 | return str | ||
| 3393 | end | ||
| 3394 | local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'" | ||
| 2664 | local my_function | 3395 | local my_function |
| 2665 | my_function = function() end | 3396 | my_function = function() end |
| 2666 | my_function() | 3397 | my_function() |
| @@ -2749,6 +3480,96 @@ if func(1, 2, 3, "你好", "世界") then | |||
| 2749 | print("你好") | 3480 | print("你好") |
| 2750 | print("我在if内部") | 3481 | print("我在if内部") |
| 2751 | end | 3482 | end |
| 3483 | local f1 | ||
| 3484 | f1 = function(_arg_0) | ||
| 3485 | local a, b, c | ||
| 3486 | a, b, c = _arg_0.a, _arg_0.b, _arg_0.c | ||
| 3487 | return print(a, b, c) | ||
| 3488 | end | ||
| 3489 | f1({ | ||
| 3490 | a = 1, | ||
| 3491 | b = "2", | ||
| 3492 | c = { } | ||
| 3493 | }) | ||
| 3494 | local f2 | ||
| 3495 | f2 = function(_arg_0, c) | ||
| 3496 | local a1, b | ||
| 3497 | a1, b = _arg_0.a, _arg_0.b | ||
| 3498 | if a1 == nil then | ||
| 3499 | a1 = 123 | ||
| 3500 | end | ||
| 3501 | if b == nil then | ||
| 3502 | b = 'abc' | ||
| 3503 | end | ||
| 3504 | if c == nil then | ||
| 3505 | c = { } | ||
| 3506 | end | ||
| 3507 | return print(a1, b, c) | ||
| 3508 | end | ||
| 3509 | local arg1 = { | ||
| 3510 | a = 0 | ||
| 3511 | } | ||
| 3512 | f2(arg1, arg2) | ||
| 3513 | local findFirstEven | ||
| 3514 | findFirstEven = function(list) | ||
| 3515 | for _index_0 = 1, #list do | ||
| 3516 | local item = list[_index_0] | ||
| 3517 | if type(item) == "table" then | ||
| 3518 | for _index_1 = 1, #item do | ||
| 3519 | local sub = item[_index_1] | ||
| 3520 | if sub % 2 == 0 then | ||
| 3521 | return sub | ||
| 3522 | end | ||
| 3523 | end | ||
| 3524 | end | ||
| 3525 | end | ||
| 3526 | return nil | ||
| 3527 | end | ||
| 3528 | local findFirstEven | ||
| 3529 | findFirstEven = function(list) | ||
| 3530 | for _index_0 = 1, #list do | ||
| 3531 | local item = list[_index_0] | ||
| 3532 | if type(item) == "table" then | ||
| 3533 | for _index_1 = 1, #item do | ||
| 3534 | local sub = item[_index_1] | ||
| 3535 | if sub % 2 == 0 then | ||
| 3536 | return sub | ||
| 3537 | end | ||
| 3538 | end | ||
| 3539 | end | ||
| 3540 | end | ||
| 3541 | return nil | ||
| 3542 | end | ||
| 3543 | local f | ||
| 3544 | f = function(...) | ||
| 3545 | local t = { | ||
| 3546 | n = select("#", ...), | ||
| 3547 | ... | ||
| 3548 | } | ||
| 3549 | print("参数个数:", t.n) | ||
| 3550 | print("表长度:", #t) | ||
| 3551 | for i = 1, t.n do | ||
| 3552 | print(t[i]) | ||
| 3553 | end | ||
| 3554 | end | ||
| 3555 | f(1, 2, 3) | ||
| 3556 | f("a", "b", "c", "d") | ||
| 3557 | f() | ||
| 3558 | local process | ||
| 3559 | process = function(...) | ||
| 3560 | local args = { | ||
| 3561 | n = select("#", ...), | ||
| 3562 | ... | ||
| 3563 | } | ||
| 3564 | local sum = 0 | ||
| 3565 | for i = 1, args.n do | ||
| 3566 | if args[i] ~= nil and type(args[i]) == "number" then | ||
| 3567 | sum = sum + args[i] | ||
| 3568 | end | ||
| 3569 | end | ||
| 3570 | return sum | ||
| 3571 | end | ||
| 3572 | process(1, nil, 3, nil, 5) | ||
| 2752 | f(function() | 3573 | f(function() |
| 2753 | return print("hello") | 3574 | return print("hello") |
| 2754 | end) | 3575 | end) |
| @@ -2874,6 +3695,28 @@ for _index_0 = 1, #_list_0 do | |||
| 2874 | _len_0 = _len_0 + 1 | 3695 | _len_0 = _len_0 + 1 |
| 2875 | end | 3696 | end |
| 2876 | doubled = _accum_0 | 3697 | doubled = _accum_0 |
| 3698 | local data = { | ||
| 3699 | a = { | ||
| 3700 | 1, | ||
| 3701 | 2, | ||
| 3702 | 3 | ||
| 3703 | }, | ||
| 3704 | b = { | ||
| 3705 | 4, | ||
| 3706 | 5, | ||
| 3707 | 6 | ||
| 3708 | } | ||
| 3709 | } | ||
| 3710 | local flat | ||
| 3711 | local _accum_0 = { } | ||
| 3712 | for k, v in pairs(data) do | ||
| 3713 | local _len_0 = #_accum_0 + 1 | ||
| 3714 | for _index_0 = 1, #v do | ||
| 3715 | local _elm_0 = v[_index_0] | ||
| 3716 | _accum_0[_len_0], _len_0 = _elm_0, _len_0 + 1 | ||
| 3717 | end | ||
| 3718 | end | ||
| 3719 | flat = _accum_0 | ||
| 2877 | local x_coords = { | 3720 | local x_coords = { |
| 2878 | 4, | 3721 | 4, |
| 2879 | 5, | 3722 | 5, |
| @@ -2964,8 +3807,7 @@ local slice | |||
| 2964 | local _accum_0 = { } | 3807 | local _accum_0 = { } |
| 2965 | local _len_0 = 1 | 3808 | local _len_0 = 1 |
| 2966 | local _list_0 = items | 3809 | local _list_0 = items |
| 2967 | local _max_0 = 5 | 3810 | for _index_0 = 1, 5 do |
| 2968 | for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do | ||
| 2969 | local item = _list_0[_index_0] | 3811 | local item = _list_0[_index_0] |
| 2970 | _accum_0[_len_0] = item | 3812 | _accum_0[_len_0] = item |
| 2971 | _len_0 = _len_0 + 1 | 3813 | _len_0 = _len_0 + 1 |
| @@ -2975,7 +3817,8 @@ local slice | |||
| 2975 | local _accum_0 = { } | 3817 | local _accum_0 = { } |
| 2976 | local _len_0 = 1 | 3818 | local _len_0 = 1 |
| 2977 | local _list_0 = items | 3819 | local _list_0 = items |
| 2978 | for _index_0 = 2, #_list_0 do | 3820 | local _max_0 = #_list_0 |
| 3821 | for _index_0 = 2, _max_0 do | ||
| 2979 | local item = _list_0[_index_0] | 3822 | local item = _list_0[_index_0] |
| 2980 | _accum_0[_len_0] = item | 3823 | _accum_0[_len_0] = item |
| 2981 | _len_0 = _len_0 + 1 | 3824 | _len_0 = _len_0 + 1 |
| @@ -2985,12 +3828,46 @@ local slice | |||
| 2985 | local _accum_0 = { } | 3828 | local _accum_0 = { } |
| 2986 | local _len_0 = 1 | 3829 | local _len_0 = 1 |
| 2987 | local _list_0 = items | 3830 | local _list_0 = items |
| 2988 | for _index_0 = 1, #_list_0, 2 do | 3831 | local _max_0 = #_list_0 |
| 3832 | for _index_0 = 1, _max_0, 2 do | ||
| 2989 | local item = _list_0[_index_0] | 3833 | local item = _list_0[_index_0] |
| 2990 | _accum_0[_len_0] = item | 3834 | _accum_0[_len_0] = item |
| 2991 | _len_0 = _len_0 + 1 | 3835 | _len_0 = _len_0 + 1 |
| 2992 | end | 3836 | end |
| 2993 | slice = _accum_0 | 3837 | slice = _accum_0 |
| 3838 | local slice | ||
| 3839 | local _accum_0 = { } | ||
| 3840 | local _len_0 = 1 | ||
| 3841 | local _list_0 = items | ||
| 3842 | local _min_0 = #_list_0 + -4 + 1 | ||
| 3843 | local _max_0 = #_list_0 + -1 + 1 | ||
| 3844 | for _index_0 = _min_0, _max_0 do | ||
| 3845 | local item = _list_0[_index_0] | ||
| 3846 | _accum_0[_len_0] = item | ||
| 3847 | _len_0 = _len_0 + 1 | ||
| 3848 | end | ||
| 3849 | slice = _accum_0 | ||
| 3850 | local reverse_slice | ||
| 3851 | local _accum_0 = { } | ||
| 3852 | local _len_0 = 1 | ||
| 3853 | local _list_0 = items | ||
| 3854 | local _min_0 = #_list_0 + -1 + 1 | ||
| 3855 | for _index_0 = _min_0, 1, -1 do | ||
| 3856 | local item = _list_0[_index_0] | ||
| 3857 | _accum_0[_len_0] = item | ||
| 3858 | _len_0 = _len_0 + 1 | ||
| 3859 | end | ||
| 3860 | reverse_slice = _accum_0 | ||
| 3861 | local sub_list | ||
| 3862 | local _accum_0 = { } | ||
| 3863 | local _len_0 = 1 | ||
| 3864 | local _list_0 = items | ||
| 3865 | for _index_0 = 2, 4 do | ||
| 3866 | local _item_0 = _list_0[_index_0] | ||
| 3867 | _accum_0[_len_0] = _item_0 | ||
| 3868 | _len_0 = _len_0 + 1 | ||
| 3869 | end | ||
| 3870 | sub_list = _accum_0 | ||
| 2994 | for i = 10, 20 do | 3871 | for i = 10, 20 do |
| 2995 | print(i) | 3872 | print(i) |
| 2996 | end | 3873 | end |
| @@ -3001,8 +3878,7 @@ for key, value in pairs(object) do | |||
| 3001 | print(key, value) | 3878 | print(key, value) |
| 3002 | end | 3879 | end |
| 3003 | local _list_0 = items | 3880 | local _list_0 = items |
| 3004 | local _max_0 = 4 | 3881 | for _index_0 = 2, 4 do |
| 3005 | for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do | ||
| 3006 | local item = _list_0[_index_0] | 3882 | local item = _list_0[_index_0] |
| 3007 | print(item) | 3883 | print(item) |
| 3008 | end | 3884 | end |
| @@ -3020,12 +3896,24 @@ local _len_0 = 1 | |||
| 3020 | for i = 1, 20 do | 3896 | for i = 1, 20 do |
| 3021 | if i % 2 == 0 then | 3897 | if i % 2 == 0 then |
| 3022 | _accum_0[_len_0] = i * 2 | 3898 | _accum_0[_len_0] = i * 2 |
| 3899 | _len_0 = _len_0 + 1 | ||
| 3023 | else | 3900 | else |
| 3024 | _accum_0[_len_0] = i | 3901 | _accum_0[_len_0] = i |
| 3902 | _len_0 = _len_0 + 1 | ||
| 3025 | end | 3903 | end |
| 3026 | _len_0 = _len_0 + 1 | ||
| 3027 | end | 3904 | end |
| 3028 | doubled_evens = _accum_0 | 3905 | doubled_evens = _accum_0 |
| 3906 | local first_large | ||
| 3907 | local _accum_0 | ||
| 3908 | local _list_0 = numbers | ||
| 3909 | for _index_0 = 1, #_list_0 do | ||
| 3910 | local n = _list_0[_index_0] | ||
| 3911 | if n > 10 then | ||
| 3912 | _accum_0 = n | ||
| 3913 | break | ||
| 3914 | end | ||
| 3915 | end | ||
| 3916 | first_large = _accum_0 | ||
| 3029 | local func_a | 3917 | local func_a |
| 3030 | func_a = function() | 3918 | func_a = function() |
| 3031 | for i = 1, 10 do | 3919 | for i = 1, 10 do |
| @@ -3174,7 +4062,7 @@ if "Robert" == name then | |||
| 3174 | elseif "Dan" == name or "Daniel" == name then | 4062 | elseif "Dan" == name or "Daniel" == name then |
| 3175 | print("你的名字是Dan") | 4063 | print("你的名字是Dan") |
| 3176 | else | 4064 | else |
| 3177 | print("我不知道你的名字") | 4065 | print("我不认识你,你的名字是" .. tostring(name)) |
| 3178 | end | 4066 | end |
| 3179 | local b = 1 | 4067 | local b = 1 |
| 3180 | local next_number | 4068 | local next_number |
| @@ -3274,6 +4162,192 @@ if _tab_0 then | |||
| 3274 | end | 4162 | end |
| 3275 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) | 4163 | print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) |
| 3276 | end | 4164 | end |
| 4165 | local _exp_0 = tb | ||
| 4166 | local _type_0 = type(_exp_0) | ||
| 4167 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 4168 | local _match_0 = false | ||
| 4169 | if _tab_0 then | ||
| 4170 | if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then | ||
| 4171 | _match_0 = true | ||
| 4172 | print("1, 2, 3") | ||
| 4173 | end | ||
| 4174 | end | ||
| 4175 | if not _match_0 then | ||
| 4176 | local _match_1 = false | ||
| 4177 | if _tab_0 then | ||
| 4178 | local b = _exp_0[2] | ||
| 4179 | if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then | ||
| 4180 | _match_1 = true | ||
| 4181 | print("1, " .. tostring(b) .. ", 3") | ||
| 4182 | end | ||
| 4183 | end | ||
| 4184 | if not _match_1 then | ||
| 4185 | if _tab_0 then | ||
| 4186 | local b = _exp_0[3] | ||
| 4187 | if b == nil then | ||
| 4188 | b = 3 | ||
| 4189 | end | ||
| 4190 | if 1 == _exp_0[1] and 2 == _exp_0[2] then | ||
| 4191 | print("1, 2, " .. tostring(b)) | ||
| 4192 | end | ||
| 4193 | end | ||
| 4194 | end | ||
| 4195 | end | ||
| 4196 | local _exp_0 = tb | ||
| 4197 | local _type_0 = type(_exp_0) | ||
| 4198 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 4199 | local _match_0 = false | ||
| 4200 | if _tab_0 then | ||
| 4201 | local result = _exp_0.result | ||
| 4202 | if true == _exp_0.success and result ~= nil then | ||
| 4203 | _match_0 = true | ||
| 4204 | print("成功", result) | ||
| 4205 | end | ||
| 4206 | end | ||
| 4207 | if not _match_0 then | ||
| 4208 | local _match_1 = false | ||
| 4209 | if _tab_0 then | ||
| 4210 | if false == _exp_0.success then | ||
| 4211 | _match_1 = true | ||
| 4212 | print("失败", result) | ||
| 4213 | end | ||
| 4214 | end | ||
| 4215 | if not _match_1 then | ||
| 4216 | print("无效值") | ||
| 4217 | end | ||
| 4218 | end | ||
| 4219 | local _exp_0 = tb | ||
| 4220 | local _type_0 = type(_exp_0) | ||
| 4221 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 4222 | local _match_0 = false | ||
| 4223 | if _tab_0 then | ||
| 4224 | local content | ||
| 4225 | do | ||
| 4226 | local _obj_0 = _exp_0.data | ||
| 4227 | local _type_1 = type(_obj_0) | ||
| 4228 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 4229 | content = _obj_0.content | ||
| 4230 | end | ||
| 4231 | end | ||
| 4232 | local _val_0 | ||
| 4233 | do | ||
| 4234 | local _obj_0 = _exp_0.data | ||
| 4235 | if _obj_0 ~= nil then | ||
| 4236 | _val_0 = _obj_0.type | ||
| 4237 | end | ||
| 4238 | end | ||
| 4239 | if "success" == _val_0 and content ~= nil then | ||
| 4240 | _match_0 = true | ||
| 4241 | print("成功", content) | ||
| 4242 | end | ||
| 4243 | end | ||
| 4244 | if not _match_0 then | ||
| 4245 | local _match_1 = false | ||
| 4246 | if _tab_0 then | ||
| 4247 | local content | ||
| 4248 | do | ||
| 4249 | local _obj_0 = _exp_0.data | ||
| 4250 | local _type_1 = type(_obj_0) | ||
| 4251 | if "table" == _type_1 or "userdata" == _type_1 then | ||
| 4252 | content = _obj_0.content | ||
| 4253 | end | ||
| 4254 | end | ||
| 4255 | local _val_0 | ||
| 4256 | do | ||
| 4257 | local _obj_0 = _exp_0.data | ||
| 4258 | if _obj_0 ~= nil then | ||
| 4259 | _val_0 = _obj_0.type | ||
| 4260 | end | ||
| 4261 | end | ||
| 4262 | if "error" == _val_0 and content ~= nil then | ||
| 4263 | _match_1 = true | ||
| 4264 | print("失败", content) | ||
| 4265 | end | ||
| 4266 | end | ||
| 4267 | if not _match_1 then | ||
| 4268 | print("无效值") | ||
| 4269 | end | ||
| 4270 | end | ||
| 4271 | local _exp_0 = tb | ||
| 4272 | local _type_0 = type(_exp_0) | ||
| 4273 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 4274 | if _tab_0 then | ||
| 4275 | local fourth = _exp_0[4] | ||
| 4276 | local _val_0 | ||
| 4277 | do | ||
| 4278 | local _obj_0 = _exp_0[1] | ||
| 4279 | if _obj_0 ~= nil then | ||
| 4280 | _val_0 = _obj_0.a | ||
| 4281 | end | ||
| 4282 | end | ||
| 4283 | local _val_1 | ||
| 4284 | do | ||
| 4285 | local _obj_0 = _exp_0[1] | ||
| 4286 | if _obj_0 ~= nil then | ||
| 4287 | _val_1 = _obj_0.b | ||
| 4288 | end | ||
| 4289 | end | ||
| 4290 | local _val_2 | ||
| 4291 | do | ||
| 4292 | local _obj_0 = _exp_0[2] | ||
| 4293 | if _obj_0 ~= nil then | ||
| 4294 | _val_2 = _obj_0.a | ||
| 4295 | end | ||
| 4296 | end | ||
| 4297 | local _val_3 | ||
| 4298 | do | ||
| 4299 | local _obj_0 = _exp_0[2] | ||
| 4300 | if _obj_0 ~= nil then | ||
| 4301 | _val_3 = _obj_0.b | ||
| 4302 | end | ||
| 4303 | end | ||
| 4304 | local _val_4 | ||
| 4305 | do | ||
| 4306 | local _obj_0 = _exp_0[3] | ||
| 4307 | if _obj_0 ~= nil then | ||
| 4308 | _val_4 = _obj_0.a | ||
| 4309 | end | ||
| 4310 | end | ||
| 4311 | local _val_5 | ||
| 4312 | do | ||
| 4313 | local _obj_0 = _exp_0[3] | ||
| 4314 | if _obj_0 ~= nil then | ||
| 4315 | _val_5 = _obj_0.b | ||
| 4316 | end | ||
| 4317 | end | ||
| 4318 | 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 | ||
| 4319 | print("匹配成功", fourth) | ||
| 4320 | end | ||
| 4321 | end | ||
| 4322 | local segments = { | ||
| 4323 | "admin", | ||
| 4324 | "users", | ||
| 4325 | "logs", | ||
| 4326 | "view" | ||
| 4327 | } | ||
| 4328 | local _type_0 = type(segments) | ||
| 4329 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 4330 | if _tab_0 then | ||
| 4331 | local groups | ||
| 4332 | do | ||
| 4333 | local _accum_0 = { } | ||
| 4334 | local _len_0 = 1 | ||
| 4335 | local _max_0 = #segments + -3 + 1 | ||
| 4336 | for _index_0 = 1, _max_0 do | ||
| 4337 | local _item_0 = segments[_index_0] | ||
| 4338 | _accum_0[_len_0] = _item_0 | ||
| 4339 | _len_0 = _len_0 + 1 | ||
| 4340 | end | ||
| 4341 | groups = _accum_0 | ||
| 4342 | end | ||
| 4343 | local resource = segments[#segments - 1] | ||
| 4344 | local action = segments[#segments] | ||
| 4345 | if resource ~= nil and action ~= nil then | ||
| 4346 | print("Group:", groups) | ||
| 4347 | print("Resource:", resource) | ||
| 4348 | print("Action:", action) | ||
| 4349 | end | ||
| 4350 | end | ||
| 3277 | local Inventory | 4351 | local Inventory |
| 3278 | local _class_0 | 4352 | local _class_0 |
| 3279 | local _base_0 = { | 4353 | local _base_0 = { |
| @@ -3930,6 +5004,10 @@ do | |||
| 3930 | _with_1["key-name"] = value | 5004 | _with_1["key-name"] = value |
| 3931 | end | 5005 | end |
| 3932 | _with_0[#_with_0 + 1] = "abc" | 5006 | _with_0[#_with_0 + 1] = "abc" |
| 5007 | local _with_0 = obj | ||
| 5008 | if _with_0 ~= nil then | ||
| 5009 | print(obj.name) | ||
| 5010 | end | ||
| 3933 | do | 5011 | do |
| 3934 | local var = "hello" | 5012 | local var = "hello" |
| 3935 | print(var) | 5013 | 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/destructure.lua b/spec/outputs/destructure.lua index 44da58b..4e19aca 100644 --- a/spec/outputs/destructure.lua +++ b/spec/outputs/destructure.lua | |||
| @@ -621,4 +621,114 @@ 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 | ||
| 714 | do | ||
| 715 | local _list_0 = items | ||
| 716 | for _index_0 = 1, #_list_0 do | ||
| 717 | local _des_0 = _list_0[_index_0] | ||
| 718 | local a, b = _des_0.a, _des_0.b | ||
| 719 | print(a, b) | ||
| 720 | end | ||
| 721 | local _list_1 = items | ||
| 722 | for _index_0 = 1, #_list_1 do | ||
| 723 | local _des_0 = _list_1[_index_0] | ||
| 724 | local a, b = _des_0.a, _des_0.b | ||
| 725 | print(a, b) | ||
| 726 | end | ||
| 727 | for _des_0 in pairs(data) do | ||
| 728 | local body = _des_0.body | ||
| 729 | if body then | ||
| 730 | print(body) | ||
| 731 | end | ||
| 732 | end | ||
| 733 | end | ||
| 624 | return nil | 734 | return nil |
diff --git a/spec/outputs/funcs.lua b/spec/outputs/funcs.lua index c1735c4..db7ed67 100644 --- a/spec/outputs/funcs.lua +++ b/spec/outputs/funcs.lua | |||
| @@ -283,4 +283,157 @@ do | |||
| 283 | end | 283 | end |
| 284 | print(func()) | 284 | print(func()) |
| 285 | end | 285 | end |
| 286 | local _anon_func_0 = function(_arg_0) | ||
| 287 | local _accum_0 = { } | ||
| 288 | local _len_0 = 1 | ||
| 289 | local _max_0 = #_arg_0 | ||
| 290 | for _index_0 = 1, _max_0 do | ||
| 291 | local _item_0 = _arg_0[_index_0] | ||
| 292 | _accum_0[_len_0] = _item_0 | ||
| 293 | _len_0 = _len_0 + 1 | ||
| 294 | end | ||
| 295 | return _accum_0 | ||
| 296 | end | ||
| 297 | do | ||
| 298 | local f | ||
| 299 | f = function(_arg_0) | ||
| 300 | local a, b, c | ||
| 301 | a, b, c = _arg_0.a, _arg_0.b, _arg_0.c | ||
| 302 | return print(a, b, c) | ||
| 303 | end | ||
| 304 | f = function(_arg_0) | ||
| 305 | local a, b, c | ||
| 306 | a, b, c = _arg_0.a, _arg_0.b, _arg_0.c | ||
| 307 | return print(a, b, c) | ||
| 308 | end | ||
| 309 | local g | ||
| 310 | g = function(x, _arg_0) | ||
| 311 | local y | ||
| 312 | y = _arg_0.y | ||
| 313 | return print(x, y) | ||
| 314 | end | ||
| 315 | local i | ||
| 316 | i = function(_arg_0) | ||
| 317 | local ax, by | ||
| 318 | ax, by = _arg_0.a, _arg_0.b | ||
| 319 | if ax == nil then | ||
| 320 | ax = 0 | ||
| 321 | end | ||
| 322 | if by == nil then | ||
| 323 | by = 0 | ||
| 324 | end | ||
| 325 | return print(ax, by) | ||
| 326 | end | ||
| 327 | j = function(name, _arg_0) | ||
| 328 | local uid, role | ||
| 329 | uid, role = _arg_0.id, _arg_0.role | ||
| 330 | if uid == nil then | ||
| 331 | uid = "n/a" | ||
| 332 | end | ||
| 333 | if role == nil then | ||
| 334 | role = "guest" | ||
| 335 | end | ||
| 336 | return print(name, uid, role) | ||
| 337 | end | ||
| 338 | local m | ||
| 339 | m = function(_arg_0) | ||
| 340 | local name, age, ver | ||
| 341 | name, age, ver = _arg_0.user.name, _arg_0.user.age, _arg_0.meta.ver | ||
| 342 | if ver == nil then | ||
| 343 | ver = 1 | ||
| 344 | end | ||
| 345 | return print(name, age, ver) | ||
| 346 | end | ||
| 347 | local m1 | ||
| 348 | m1 = function(_arg_0) | ||
| 349 | local name, age, meta | ||
| 350 | name, age, meta = _arg_0.user.name, _arg_0.user.age, _arg_0.meta | ||
| 351 | if meta == nil then | ||
| 352 | meta = { } | ||
| 353 | end | ||
| 354 | return print(name, age, meta and meta.ver or "nil") | ||
| 355 | end | ||
| 356 | local new | ||
| 357 | new = function(self, _arg_0) | ||
| 358 | local name, age | ||
| 359 | name, age = _arg_0.name, _arg_0.age | ||
| 360 | if name == nil then | ||
| 361 | name = "anon" | ||
| 362 | end | ||
| 363 | if age == nil then | ||
| 364 | age = 0 | ||
| 365 | end | ||
| 366 | self.name = name | ||
| 367 | self.age = age | ||
| 368 | end | ||
| 369 | local set | ||
| 370 | set = function(self, _arg_0) | ||
| 371 | local name, age | ||
| 372 | name, age = _arg_0.name, _arg_0.age | ||
| 373 | if name == nil then | ||
| 374 | name = self.name | ||
| 375 | end | ||
| 376 | if age == nil then | ||
| 377 | age = self.age | ||
| 378 | end | ||
| 379 | self.name = name | ||
| 380 | self.age = age | ||
| 381 | end | ||
| 382 | local logKV | ||
| 383 | logKV = function(_arg_0, ...) | ||
| 384 | local k, v | ||
| 385 | k, v = _arg_0.k, _arg_0.v | ||
| 386 | print("kv:", k, v) | ||
| 387 | return print("rest count:", select("#", ...)) | ||
| 388 | end | ||
| 389 | do | ||
| 390 | local foo | ||
| 391 | foo = function(_arg_0) | ||
| 392 | local a, b | ||
| 393 | a, b = _arg_0.a, _arg_0.b | ||
| 394 | if b == nil then | ||
| 395 | b = 0 | ||
| 396 | end | ||
| 397 | return print(a, b) | ||
| 398 | end | ||
| 399 | end | ||
| 400 | local t1 | ||
| 401 | t1 = function(_arg_0, x) | ||
| 402 | local a | ||
| 403 | a = _arg_0.a | ||
| 404 | return print(a, x) | ||
| 405 | end | ||
| 406 | local t2 | ||
| 407 | t2 = function(_arg_0) | ||
| 408 | local a | ||
| 409 | a = _arg_0.a | ||
| 410 | return print(a) | ||
| 411 | end | ||
| 412 | local w | ||
| 413 | w = function(id, _arg_0, _arg_1) | ||
| 414 | local x, y | ||
| 415 | x, y = _arg_0.x, _arg_0.y | ||
| 416 | if x == nil then | ||
| 417 | x = 0 | ||
| 418 | end | ||
| 419 | if y == nil then | ||
| 420 | y = 0 | ||
| 421 | end | ||
| 422 | local flag | ||
| 423 | flag = _arg_1.flag | ||
| 424 | return print(id, x, y, flag) | ||
| 425 | end | ||
| 426 | local g1 | ||
| 427 | g1 = function(_arg_0) | ||
| 428 | local a, ax | ||
| 429 | a, ax = _arg_0.a, _arg_0.a | ||
| 430 | return print(a, ax) | ||
| 431 | end | ||
| 432 | local g4 | ||
| 433 | g4 = function(_arg_0) | ||
| 434 | local a, b, rest | ||
| 435 | a, b, rest = _arg_0.a, _arg_0.b, _anon_func_0(_arg_0) | ||
| 436 | return print(a, b) | ||
| 437 | end | ||
| 438 | end | ||
| 286 | return nil | 439 | return nil |
diff --git a/spec/outputs/global.lua b/spec/outputs/global.lua index 54a21a9..3918f85 100644 --- a/spec/outputs/global.lua +++ b/spec/outputs/global.lua | |||
| @@ -93,3 +93,28 @@ do | |||
| 93 | FooBar = "pascal case" | 93 | FooBar = "pascal case" |
| 94 | FOOBAR = "all uppercase" | 94 | FOOBAR = "all uppercase" |
| 95 | end | 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/import_global.lua b/spec/outputs/import_global.lua new file mode 100644 index 0000000..895daf9 --- /dev/null +++ b/spec/outputs/import_global.lua | |||
| @@ -0,0 +1,131 @@ | |||
| 1 | do | ||
| 2 | local print <const> = print | ||
| 3 | local math <const> = math | ||
| 4 | print("hello") | ||
| 5 | math.random(10) | ||
| 6 | end | ||
| 7 | do | ||
| 8 | local print <const> = print | ||
| 9 | local value = 1 | ||
| 10 | value = value + 2 | ||
| 11 | print(value) | ||
| 12 | end | ||
| 13 | do | ||
| 14 | local print | ||
| 15 | print = function(msg) | ||
| 16 | return msg | ||
| 17 | end | ||
| 18 | do | ||
| 19 | local math <const> = math | ||
| 20 | print("local") | ||
| 21 | math.random(1) | ||
| 22 | end | ||
| 23 | end | ||
| 24 | do | ||
| 25 | local print <const> = print | ||
| 26 | local tostring | ||
| 27 | tostring = function(v) | ||
| 28 | return "local" | ||
| 29 | end | ||
| 30 | tostring("value") | ||
| 31 | print(tostring(123)) | ||
| 32 | end | ||
| 33 | do | ||
| 34 | local func | ||
| 35 | func = function(x, y) | ||
| 36 | local type <const> = type | ||
| 37 | local tostring <const> = tostring | ||
| 38 | local print <const> = print | ||
| 39 | return type(x, tostring(y, print)) | ||
| 40 | end | ||
| 41 | func(1, 2) | ||
| 42 | end | ||
| 43 | do | ||
| 44 | local xpcall <const> = xpcall | ||
| 45 | local func <const> = func | ||
| 46 | local world <const> = world | ||
| 47 | local tostring <const> = tostring | ||
| 48 | local print <const> = print | ||
| 49 | xpcall(function() | ||
| 50 | return func("hello " .. tostring(world)) | ||
| 51 | end, function(err) | ||
| 52 | return print(err) | ||
| 53 | end) | ||
| 54 | end | ||
| 55 | do | ||
| 56 | local print <const> = print | ||
| 57 | print(FLAG) | ||
| 58 | FLAG = 123 | ||
| 59 | end | ||
| 60 | do | ||
| 61 | local print <const> = print | ||
| 62 | Foo = 10 | ||
| 63 | print(Foo) | ||
| 64 | Foo = Foo + 2 | ||
| 65 | end | ||
| 66 | do | ||
| 67 | local print <const> = print | ||
| 68 | Bar = 1 | ||
| 69 | Baz = 2 | ||
| 70 | print(Bar, Baz) | ||
| 71 | end | ||
| 72 | do | ||
| 73 | local y <const> = y | ||
| 74 | x = 3434 | ||
| 75 | if y then | ||
| 76 | x = 10 | ||
| 77 | end | ||
| 78 | end | ||
| 79 | do | ||
| 80 | local lowercase <const> = lowercase | ||
| 81 | local tostring <const> = tostring | ||
| 82 | local Uppercase <const> = Uppercase | ||
| 83 | local foobar = "all " .. tostring(lowercase) | ||
| 84 | FooBar = "pascal case" | ||
| 85 | FOOBAR = "all " .. tostring(Uppercase) | ||
| 86 | end | ||
| 87 | do | ||
| 88 | local setmetatable <const> = setmetatable | ||
| 89 | local print <const> = print | ||
| 90 | do | ||
| 91 | local _class_0 | ||
| 92 | local _base_0 = { } | ||
| 93 | if _base_0.__index == nil then | ||
| 94 | _base_0.__index = _base_0 | ||
| 95 | end | ||
| 96 | _class_0 = setmetatable({ | ||
| 97 | __init = function() end, | ||
| 98 | __base = _base_0, | ||
| 99 | __name = "A" | ||
| 100 | }, { | ||
| 101 | __index = _base_0, | ||
| 102 | __call = function(cls, ...) | ||
| 103 | local _self_0 = setmetatable({ }, _base_0) | ||
| 104 | cls.__init(_self_0, ...) | ||
| 105 | return _self_0 | ||
| 106 | end | ||
| 107 | }) | ||
| 108 | _base_0.__class = _class_0 | ||
| 109 | A = _class_0 | ||
| 110 | end | ||
| 111 | Flag = 1 | ||
| 112 | const, x, y = "const", 1, 2 | ||
| 113 | print(math, table) | ||
| 114 | end | ||
| 115 | do | ||
| 116 | local X <const> = X | ||
| 117 | X:func(1, 2, 3) | ||
| 118 | X.tag = "abc" | ||
| 119 | end | ||
| 120 | local _anon_func_0 = function(func) | ||
| 121 | return func | ||
| 122 | end | ||
| 123 | do | ||
| 124 | local func <const> = func | ||
| 125 | local pcall <const> = pcall | ||
| 126 | local f | ||
| 127 | f = function() | ||
| 128 | func() | ||
| 129 | return pcall(_anon_func_0, func) | ||
| 130 | end | ||
| 131 | end | ||
diff --git a/spec/outputs/lists.lua b/spec/outputs/lists.lua index 48ec9c8..75f04fa 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,570 @@ 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 _call_0 | ||
| 474 | do | ||
| 475 | local _item_0 = globalTB | ||
| 476 | _call_0 = _item_0[#_item_0] | ||
| 477 | end | ||
| 478 | return _call_0["end"](_call_0, 123) | ||
| 479 | end | ||
| 480 | local _anon_func_1 = function(a) | ||
| 481 | local _item_0 | ||
| 482 | do | ||
| 483 | local _accum_0 = { } | ||
| 484 | local _len_0 = 1 | ||
| 485 | local _list_0 = a.b.c | ||
| 486 | local _max_5 = #_list_0 + -5 + 1 | ||
| 487 | for _index_0 = 5, _max_5 do | ||
| 488 | local _item_1 = _list_0[_index_0] | ||
| 489 | _accum_0[_len_0] = _item_1 | ||
| 490 | _len_0 = _len_0 + 1 | ||
| 491 | end | ||
| 492 | _item_0 = _accum_0 | ||
| 493 | end | ||
| 494 | return _item_0[#_item_0 - 2] | ||
| 495 | end | ||
| 496 | local _anon_func_2 = function(x) | ||
| 497 | if x ~= nil then | ||
| 498 | local _obj_0 = x.y | ||
| 499 | if _obj_0 ~= nil then | ||
| 500 | local _obj_1 = _obj_0(x).z | ||
| 501 | if _obj_1 ~= nil then | ||
| 502 | local _obj_2 = _obj_1[#_obj_1 - 3] | ||
| 503 | if _obj_2 ~= nil then | ||
| 504 | local _accum_0 = { } | ||
| 505 | local _len_0 = 1 | ||
| 506 | local _max_5 = #_obj_2 + -3 + 1 | ||
| 507 | for _index_0 = 1, _max_5 do | ||
| 508 | local _item_0 = _obj_2[_index_0] | ||
| 509 | _accum_0[_len_0] = _item_0 | ||
| 510 | _len_0 = _len_0 + 1 | ||
| 511 | end | ||
| 512 | return _accum_0 | ||
| 513 | end | ||
| 514 | return nil | ||
| 515 | end | ||
| 516 | return nil | ||
| 517 | end | ||
| 518 | return nil | ||
| 519 | end | ||
| 520 | return nil | ||
| 521 | end | ||
| 522 | do | ||
| 523 | local f | ||
| 524 | f = function() | ||
| 525 | return print(_anon_func_0(globalTB), _anon_func_1(a), _anon_func_2(x)) | ||
| 526 | end | ||
| 527 | end | ||
| 528 | do | ||
| 529 | local tb = { | ||
| 530 | 1, | ||
| 531 | 2, | ||
| 532 | 3 | ||
| 533 | } | ||
| 534 | tb[#tb] = 40 | ||
| 535 | tb[#tb - 1] = 20 | ||
| 536 | end | ||
| 537 | do | ||
| 538 | a = "x" | ||
| 539 | b = a | ||
| 540 | c = a | ||
| 541 | local lst = { } | ||
| 542 | lst[#lst] = a | ||
| 543 | lst[#lst - 1] = b | ||
| 544 | end | ||
| 545 | do | ||
| 546 | local y, z | ||
| 547 | x, y, z = 1, 2, 3 | ||
| 548 | local arr = { } | ||
| 549 | local head | ||
| 550 | arr[#arr], head = x, y | ||
| 551 | arr[#arr] = z | ||
| 552 | end | ||
| 553 | do | ||
| 554 | local triple = { | ||
| 555 | "keep", | ||
| 556 | "skip", | ||
| 557 | "tail" | ||
| 558 | } | ||
| 559 | local head, tailv = triple[1], triple[3] | ||
| 560 | local buf = { } | ||
| 561 | buf[#buf] = head | ||
| 562 | buf[#buf] = tailv | ||
| 563 | end | ||
| 564 | do | ||
| 565 | local src = { | ||
| 566 | "a", | ||
| 567 | "", | ||
| 568 | "c", | ||
| 569 | nil, | ||
| 570 | "d" | ||
| 571 | } | ||
| 572 | local collected = { } | ||
| 573 | for _index_0 = 1, #src do | ||
| 574 | local item = src[_index_0] | ||
| 575 | if item and #item > 0 then | ||
| 576 | collected[#collected] = item | ||
| 577 | end | ||
| 578 | end | ||
| 579 | end | ||
| 580 | do | ||
| 581 | local nums = { | ||
| 582 | 1, | ||
| 583 | 2, | ||
| 584 | 3, | ||
| 585 | 4, | ||
| 586 | 5 | ||
| 587 | } | ||
| 588 | local last_two | ||
| 589 | do | ||
| 590 | local _accum_0 = { } | ||
| 591 | local _len_0 = 1 | ||
| 592 | for _index_0 = 1, #nums do | ||
| 593 | local v = nums[_index_0] | ||
| 594 | if v > 3 then | ||
| 595 | _accum_0[_len_0] = v | ||
| 596 | _len_0 = _len_0 + 1 | ||
| 597 | end | ||
| 598 | end | ||
| 599 | last_two = _accum_0 | ||
| 600 | end | ||
| 601 | nums[#nums] = last_two[1] | ||
| 602 | nums[#nums] = last_two[2] | ||
| 603 | end | ||
| 604 | do | ||
| 605 | local store = { } | ||
| 606 | store[#store] = { | ||
| 607 | meta = { | ||
| 608 | id = 1, | ||
| 609 | ok = true | ||
| 610 | }, | ||
| 611 | payload = { | ||
| 612 | 10, | ||
| 613 | 20 | ||
| 614 | } | ||
| 615 | } | ||
| 616 | store[#store] = { | ||
| 617 | meta = { | ||
| 618 | id = 1, | ||
| 619 | ok = false | ||
| 620 | }, | ||
| 621 | payload = { | ||
| 622 | 10, | ||
| 623 | 20, | ||
| 624 | 30 | ||
| 625 | } | ||
| 626 | } | ||
| 627 | end | ||
| 628 | local _anon_func_3 = function(tb) | ||
| 629 | local _item_0 = tb.tmp | ||
| 630 | return _item_0[#_item_0] | ||
| 631 | end | ||
| 632 | do | ||
| 633 | local f | ||
| 634 | f = function() | ||
| 635 | local q = { } | ||
| 636 | do | ||
| 637 | local _accum_0 = { } | ||
| 638 | local _len_0 = 1 | ||
| 639 | for n = 1, 4 do | ||
| 640 | _accum_0[_len_0] = n | ||
| 641 | _len_0 = _len_0 + 1 | ||
| 642 | end | ||
| 643 | tb.tmp = _accum_0 | ||
| 644 | end | ||
| 645 | if #tb.tmp >= 3 then | ||
| 646 | q[#q] = { | ||
| 647 | head = tb.tmp[1], | ||
| 648 | tail = _anon_func_3(tb) | ||
| 649 | } | ||
| 650 | end | ||
| 651 | end | ||
| 652 | end | ||
| 653 | do | ||
| 654 | local make_pair | ||
| 655 | make_pair = function(a, b) | ||
| 656 | return { | ||
| 657 | a, | ||
| 658 | b | ||
| 659 | } | ||
| 660 | end | ||
| 661 | local pairs = { } | ||
| 662 | local p1 = make_pair(7, 8) | ||
| 663 | pairs[#pairs] = p1 | ||
| 664 | local k, v = "key", 42 | ||
| 665 | pairs[#pairs] = { | ||
| 666 | k = k, | ||
| 667 | v = v | ||
| 668 | } | ||
| 669 | end | ||
| 670 | do | ||
| 671 | local cfg = { | ||
| 672 | mode = "safe", | ||
| 673 | tags = { } | ||
| 674 | } | ||
| 675 | if cfg.mode == "safe" then | ||
| 676 | cfg.mode = "fast" | ||
| 677 | local _obj_0 = cfg.tags | ||
| 678 | _obj_0[#_obj_0] = "newbie" | ||
| 679 | end | ||
| 680 | end | ||
| 681 | do | ||
| 682 | local mat = { | ||
| 683 | { | ||
| 684 | 1, | ||
| 685 | 2 | ||
| 686 | }, | ||
| 687 | { | ||
| 688 | 3, | ||
| 689 | 4 | ||
| 690 | }, | ||
| 691 | { | ||
| 692 | 5, | ||
| 693 | 6 | ||
| 694 | } | ||
| 695 | } | ||
| 696 | local last_row = mat[#mat] | ||
| 697 | local rows = { } | ||
| 698 | rows[#rows] = last_row[1] | ||
| 699 | end | ||
| 700 | do | ||
| 701 | local kv = { } | ||
| 702 | kv[#kv] = { | ||
| 703 | k = "a", | ||
| 704 | v = 1 | ||
| 705 | } | ||
| 706 | kv[#kv] = { | ||
| 707 | k = "b", | ||
| 708 | v = 2 | ||
| 709 | } | ||
| 710 | local pair_last = kv[#kv] | ||
| 711 | local dict = { } | ||
| 712 | dict[pair_last.k] = pair_last.v | ||
| 713 | dict[pair_last.k] = 3 | ||
| 714 | end | ||
| 715 | do | ||
| 716 | local base | ||
| 717 | do | ||
| 718 | local _accum_0 = { } | ||
| 719 | local _len_0 = 1 | ||
| 720 | for i = 1, 4 do | ||
| 721 | _accum_0[_len_0] = i | ||
| 722 | _len_0 = _len_0 + 1 | ||
| 723 | end | ||
| 724 | base = _accum_0 | ||
| 725 | end | ||
| 726 | local pack = { } | ||
| 727 | pack[#pack] = { | ||
| 728 | base[1], | ||
| 729 | base[#base] | ||
| 730 | } | ||
| 731 | pack[#pack] = { | ||
| 732 | first = base[1], | ||
| 733 | last = base[#base] | ||
| 734 | } | ||
| 735 | end | ||
| 736 | do | ||
| 737 | local opts = { | ||
| 738 | limit = 10 | ||
| 739 | } | ||
| 740 | local limit, offset = opts.limit, opts.offset | ||
| 741 | if offset == nil then | ||
| 742 | offset = 0 | ||
| 743 | end | ||
| 744 | local pages = { } | ||
| 745 | pages[#pages] = { | ||
| 746 | limit = limit, | ||
| 747 | offset = offset | ||
| 748 | } | ||
| 749 | end | ||
| 750 | do | ||
| 751 | local chain = { | ||
| 752 | a = { | ||
| 753 | b = { | ||
| 754 | c = 0 | ||
| 755 | } | ||
| 756 | }, | ||
| 757 | list = { | ||
| 758 | { | ||
| 759 | x = 0 | ||
| 760 | }, | ||
| 761 | { | ||
| 762 | x = 0 | ||
| 763 | } | ||
| 764 | } | ||
| 765 | } | ||
| 766 | chain.a.b.c = 1 | ||
| 767 | chain.list[1].x = 10; | ||
| 768 | ((function() | ||
| 769 | local _item_0 = chain.list | ||
| 770 | return _item_0[#_item_0] | ||
| 771 | end)()).x = 20 | ||
| 772 | local _obj_0 = chain.list | ||
| 773 | _obj_0[#_obj_0 - 1] = { | ||
| 774 | x = 30 | ||
| 775 | } | ||
| 776 | end | ||
| 777 | do | ||
| 778 | local node = { | ||
| 779 | left = { | ||
| 780 | v = 0 | ||
| 781 | }, | ||
| 782 | right = { | ||
| 783 | v = 0 | ||
| 784 | } | ||
| 785 | } | ||
| 786 | local bag = { } | ||
| 787 | local left, right = node.left, node.right | ||
| 788 | bag[#bag], left.v, right.v = "k", 1, 2 | ||
| 789 | end | ||
| 790 | do | ||
| 791 | local a1, a2, a3 = 100, 200, 300 | ||
| 792 | local mix = { } | ||
| 793 | local meta | ||
| 794 | mix[#mix], mix[#mix], meta = a1, a2, { | ||
| 795 | tag = "ok" | ||
| 796 | } | ||
| 797 | end | ||
| 798 | do | ||
| 799 | local cfg2 = { | ||
| 800 | limit = 5, | ||
| 801 | opts = { | ||
| 802 | flag = false | ||
| 803 | } | ||
| 804 | } | ||
| 805 | local lim, opt2 = cfg2.limit, cfg2.opts | ||
| 806 | local bucket = { | ||
| 807 | xs = { } | ||
| 808 | } | ||
| 809 | local _obj_0 = bucket.xs | ||
| 810 | _obj_0[#_obj_0] = lim | ||
| 811 | bucket.flag = true | ||
| 812 | local _obj_1 = opt2.flags | ||
| 813 | _obj_1[#_obj_1 + 1] = 123 | ||
| 814 | end | ||
| 815 | do | ||
| 816 | local ret2 | ||
| 817 | ret2 = function() | ||
| 818 | return 7, 8 | ||
| 819 | end | ||
| 820 | local box = { } | ||
| 821 | local x1 | ||
| 822 | box[#box], x1 = ret2() | ||
| 823 | end | ||
| 824 | do | ||
| 825 | local q = { | ||
| 826 | 1, | ||
| 827 | 2 | ||
| 828 | } | ||
| 829 | local lastq = q[#q] | ||
| 830 | q[#q - 1] = lastq * 10 | ||
| 831 | end | ||
| 832 | do | ||
| 833 | local mat2 = [[9,8], [7,6]] | ||
| 834 | local t = { | ||
| 835 | hold = nil | ||
| 836 | } | ||
| 837 | t.hold = mat2[#mat2][1] | ||
| 838 | end | ||
| 839 | do | ||
| 840 | local f | ||
| 841 | f = function() | ||
| 842 | local _obj_0 | ||
| 843 | do | ||
| 844 | local _item_0 = globalTB | ||
| 845 | _obj_0 = _item_0[#_item_0] | ||
| 846 | end | ||
| 847 | _obj_0[#_obj_0] = 1 | ||
| 848 | end | ||
| 849 | local f1 | ||
| 850 | f1 = function() | ||
| 851 | do | ||
| 852 | local _item_0 = globalTB | ||
| 853 | do | ||
| 854 | local _item_1 = _item_0[#_item_0] | ||
| 855 | return _item_1[#_item_1 - 1] | ||
| 856 | end | ||
| 857 | end | ||
| 858 | end | ||
| 859 | end | ||
| 860 | do | ||
| 861 | do | ||
| 862 | local _obj_0 = tbA | ||
| 863 | local _len_0 = #_obj_0 + 1 | ||
| 864 | local _list_0 = tbB | ||
| 865 | for _index_0 = 1, #_list_0 do | ||
| 866 | local _elm_0 = _list_0[_index_0] | ||
| 867 | _obj_0[_len_0], _len_0 = _elm_0, _len_0 + 1 | ||
| 868 | end | ||
| 869 | end | ||
| 870 | a = 1 | ||
| 871 | do | ||
| 872 | local _obj_0 = tb | ||
| 873 | local _len_0 = #_obj_0 + 1 | ||
| 874 | for _index_0 = 1, #x do | ||
| 875 | local _elm_0 = x[_index_0] | ||
| 876 | _obj_0[_len_0], _len_0 = _elm_0, _len_0 + 1 | ||
| 877 | end | ||
| 878 | end | ||
| 879 | b[#b + 1] = 3 | ||
| 880 | c = 4 | ||
| 881 | local data = { | ||
| 882 | a = { | ||
| 883 | 1, | ||
| 884 | 2, | ||
| 885 | 3 | ||
| 886 | }, | ||
| 887 | b = { | ||
| 888 | 4, | ||
| 889 | 5, | ||
| 890 | 6 | ||
| 891 | } | ||
| 892 | } | ||
| 893 | local flat | ||
| 894 | local _accum_0 = { } | ||
| 895 | for k, v in pairs(data) do | ||
| 896 | local _len_0 = #_accum_0 + 1 | ||
| 897 | for _index_0 = 1, #v do | ||
| 898 | local _elm_0 = v[_index_0] | ||
| 899 | _accum_0[_len_0], _len_0 = _elm_0, _len_0 + 1 | ||
| 900 | end | ||
| 901 | end | ||
| 902 | flat = _accum_0 | ||
| 903 | end | ||
| 330 | return nil | 904 | return nil |
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 4d31574..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 |
| @@ -213,6 +217,13 @@ function tb:func() | |||
| 213 | end | 217 | end |
| 214 | end | 218 | end |
| 215 | 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 | ||
| 216 | local sel | 227 | local sel |
| 217 | sel = function(a, b, c) | 228 | sel = function(a, b, c) |
| 218 | if a then | 229 | if a then |
| @@ -317,7 +328,7 @@ print((setmetatable({ | |||
| 317 | return 998 | 328 | return 998 |
| 318 | end | 329 | end |
| 319 | })) | 330 | })) |
| 320 | print("current line: " .. tostring(323)) | 331 | print("current line: " .. tostring(349)) |
| 321 | do | 332 | do |
| 322 | do | 333 | do |
| 323 | -- TODO | 334 | -- TODO |
| @@ -330,10 +341,8 @@ local _1 | |||
| 330 | _1 = function() | 341 | _1 = function() |
| 331 | print(1) | 342 | print(1) |
| 332 | local _accum_0 = { } | 343 | local _accum_0 = { } |
| 333 | local _len_0 = 1 | ||
| 334 | while false do | 344 | while false do |
| 335 | break | 345 | break |
| 336 | _len_0 = _len_0 + 1 | ||
| 337 | end | 346 | end |
| 338 | return _accum_0 | 347 | return _accum_0 |
| 339 | end | 348 | end |
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..bdfd676 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\t- \"one\"\n\t- \"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 040a325..eb4543c 100644 --- a/spec/outputs/syntax.lua +++ b/spec/outputs/syntax.lua | |||
| @@ -5,9 +5,9 @@ func(arg1, arg2, another, arg3) | |||
| 5 | local we | 5 | local we |
| 6 | here, we = function() end, yeah | 6 | here, we = function() end, yeah |
| 7 | local the, different | 7 | local the, different |
| 8 | the, different = function() | 8 | the, different = (function() |
| 9 | return approach | 9 | return approach |
| 10 | end, yeah | 10 | end), yeah |
| 11 | dad() | 11 | dad() |
| 12 | dad(lord) | 12 | dad(lord) |
| 13 | hello(one, two)(); | 13 | hello(one, two)(); |
| @@ -430,4 +430,94 @@ do | |||
| 430 | local f2 | 430 | local f2 |
| 431 | f2 = function() end | 431 | f2 = function() end |
| 432 | end | 432 | end |
| 433 | do | ||
| 434 | if res ~= "" then | ||
| 435 | return res | ||
| 436 | end | ||
| 437 | end | ||
| 438 | do | ||
| 439 | return res((function() | ||
| 440 | if res ~= "" then | ||
| 441 | end | ||
| 442 | end)()) | ||
| 443 | end | ||
| 444 | do | ||
| 445 | x = 1 | ||
| 446 | y = 2 | ||
| 447 | i = i + 1 | ||
| 448 | j = j + 1 | ||
| 449 | if condition then | ||
| 450 | setup() | ||
| 451 | run() | ||
| 452 | cleanup() | ||
| 453 | end | ||
| 454 | a = 1 | ||
| 455 | local b = 2 | ||
| 456 | local c = a + b | ||
| 457 | print(a) | ||
| 458 | print(b) | ||
| 459 | print(c) | ||
| 460 | f = function() | ||
| 461 | a = 1 | ||
| 462 | b = 2 | ||
| 463 | return a + b | ||
| 464 | end | ||
| 465 | a = 1 | ||
| 466 | b = 2 | ||
| 467 | local success, result = pcall(function() | ||
| 468 | return func() | ||
| 469 | end) | ||
| 470 | if success then | ||
| 471 | print(result) | ||
| 472 | end | ||
| 473 | local value = "foo" | ||
| 474 | print(value) | ||
| 475 | value = value .. "bar" | ||
| 476 | print(value) | ||
| 477 | do | ||
| 478 | if ok then | ||
| 479 | print("ok!") | ||
| 480 | end | ||
| 481 | return 42 | ||
| 482 | end | ||
| 483 | for i = 1, 3 do | ||
| 484 | print(i) | ||
| 485 | goto _continue_0 | ||
| 486 | ::_continue_0:: | ||
| 487 | end | ||
| 488 | local n = 0 | ||
| 489 | while n < 2 do | ||
| 490 | print("n=", n) | ||
| 491 | n = n + 1 | ||
| 492 | end | ||
| 493 | local obj = { } | ||
| 494 | obj:set(10) | ||
| 495 | obj:get() | ||
| 496 | print("done") | ||
| 497 | do | ||
| 498 | local _with_0 = tbl | ||
| 499 | _with_0:push(1) | ||
| 500 | print("push") | ||
| 501 | end | ||
| 502 | a = 5 | ||
| 503 | if a > 3 then | ||
| 504 | print("big") | ||
| 505 | b = a * 2 | ||
| 506 | print(b) | ||
| 507 | else | ||
| 508 | print("small") | ||
| 509 | b = a | ||
| 510 | end | ||
| 511 | xpcall(function() | ||
| 512 | x = 1 | ||
| 513 | y = 2 | ||
| 514 | return print(x + y) | ||
| 515 | end, function(err) | ||
| 516 | return print("error:", err) | ||
| 517 | end) | ||
| 518 | end | ||
| 519 | local q = 1 | ||
| 520 | local w = 2 | ||
| 521 | local e = 3 | ||
| 522 | print(q, w, e) | ||
| 433 | return nil | 523 | return nil |
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/test/format_spec.lua b/spec/outputs/test/format_spec.lua index ed0fbee..7aa85cd 100644 --- a/spec/outputs/test/format_spec.lua +++ b/spec/outputs/test/format_spec.lua | |||
| @@ -122,7 +122,7 @@ return describe("format", function() | |||
| 122 | local original_ast = yue.to_ast(code) | 122 | local original_ast = yue.to_ast(code) |
| 123 | assert.is_not_nil(original_ast) | 123 | assert.is_not_nil(original_ast) |
| 124 | rewriteLineCol(original_ast) | 124 | rewriteLineCol(original_ast) |
| 125 | local formated = yue.format(code) | 125 | local formated = yue.format(code, 0, false) |
| 126 | local ast = yue.to_ast(formated) | 126 | local ast = yue.to_ast(formated) |
| 127 | assert.is_not_nil(ast) | 127 | assert.is_not_nil(ast) |
| 128 | rewriteLineCol(ast) | 128 | rewriteLineCol(ast) |
diff --git a/spec/outputs/try_catch.lua b/spec/outputs/try_catch.lua index efd92c6..edb2341 100644 --- a/spec/outputs/try_catch.lua +++ b/spec/outputs/try_catch.lua | |||
| @@ -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() |
| @@ -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 d4ad56a..e00d016 100644 --- a/spec/outputs/unicode/assign.lua +++ b/spec/outputs/unicode/assign.lua | |||
| @@ -43,10 +43,8 @@ do | |||
| 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/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/funcs.lua b/spec/outputs/unicode/funcs.lua index 6e94587..06b24b1 100644 --- a/spec/outputs/unicode/funcs.lua +++ b/spec/outputs/unicode/funcs.lua | |||
| @@ -24,7 +24,7 @@ _u5f00(function() | |||
| 24 | end) | 24 | end) |
| 25 | local _u53d8_u91cfh | 25 | local _u53d8_u91cfh |
| 26 | _u53d8_u91cfh = function() | 26 | _u53d8_u91cfh = function() |
| 27 | return _ud83d_udc4b | 27 | return _u1f44b |
| 28 | end | 28 | end |
| 29 | _u5403(function() end, _u4e16_u754c); | 29 | _u5403(function() end, _u4e16_u754c); |
| 30 | (function() end)() | 30 | (function() end)() |
diff --git a/spec/outputs/unicode/import.lua b/spec/outputs/unicode/import.lua index 7c31ceb..e055c81 100644 --- a/spec/outputs/unicode/import.lua +++ b/spec/outputs/unicode/import.lua | |||
| @@ -11,10 +11,10 @@ local _u5b57_u6bb5x, _u5b57_u6bb5y, _u5b57_u6bb5z = _u9053_u5177_u7ec4["字段x" | |||
| 11 | return _fn_0(_base_0, ...) | 11 | return _fn_0(_base_0, ...) |
| 12 | end | 12 | end |
| 13 | end)(), _u9053_u5177_u7ec4["字段z"] | 13 | end)(), _u9053_u5177_u7ec4["字段z"] |
| 14 | local _u9886_u4e3b, _ud83d_udc7b | 14 | local _u9886_u4e3b, _u1f47b |
| 15 | do | 15 | do |
| 16 | local _obj_1 = _u627e_u5230("我的表") | 16 | local _obj_1 = _u627e_u5230("我的表") |
| 17 | _u9886_u4e3b, _ud83d_udc7b = _obj_1["领主"], (function() | 17 | _u9886_u4e3b, _u1f47b = _obj_1["领主"], (function() |
| 18 | local _base_0 = _obj_1 | 18 | local _base_0 = _obj_1 |
| 19 | local _fn_0 = _base_0["👻"] | 19 | local _fn_0 = _base_0["👻"] |
| 20 | return _fn_0 and function(...) | 20 | return _fn_0 and function(...) |
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 b14f571..b4e78cd 100644 --- a/spec/outputs/unicode/macro.lua +++ b/spec/outputs/unicode/macro.lua | |||
| @@ -216,17 +216,15 @@ do | |||
| 216 | end | 216 | end |
| 217 | local _ = require('下划线') | 217 | local _ = require('下划线') |
| 218 | local _anon_func_0 = function(_) | 218 | local _anon_func_0 = function(_) |
| 219 | do | 219 | local _call_0 = (_({ |
| 220 | local _call_0 = (_({ | 220 | 1, |
| 221 | 1, | 221 | 2, |
| 222 | 2, | 222 | 3, |
| 223 | 3, | 223 | 4, |
| 224 | 4, | 224 | -2, |
| 225 | -2, | 225 | 3 |
| 226 | 3 | 226 | })) |
| 227 | })) | 227 | return _call_0["链"](_call_0) |
| 228 | return _call_0["链"](_call_0) | ||
| 229 | end | ||
| 230 | end | 228 | end |
| 231 | local _call_0 = ((function() | 229 | local _call_0 = ((function() |
| 232 | local _call_0 = ((function() | 230 | local _call_0 = ((function() |
| @@ -241,17 +239,15 @@ local _call_0 = ((function() | |||
| 241 | end)()) | 239 | end)()) |
| 242 | local _u7ed3_u679ca = _call_0["取值"](_call_0) | 240 | local _u7ed3_u679ca = _call_0["取值"](_call_0) |
| 243 | local _anon_func_1 = function(_) | 241 | local _anon_func_1 = function(_) |
| 244 | do | 242 | local _call_1 = (_({ |
| 245 | local _call_1 = (_({ | 243 | 1, |
| 246 | 1, | 244 | 2, |
| 247 | 2, | 245 | 3, |
| 248 | 3, | 246 | 4, |
| 249 | 4, | 247 | -2, |
| 250 | -2, | 248 | 3 |
| 251 | 3 | 249 | })) |
| 252 | })) | 250 | return _call_1["链"](_call_1) |
| 253 | return _call_1["链"](_call_1) | ||
| 254 | end | ||
| 255 | end | 251 | end |
| 256 | do | 252 | do |
| 257 | local _call_1 = ((function() | 253 | local _call_1 = ((function() |
| @@ -270,10 +266,8 @@ do | |||
| 270 | end) | 266 | end) |
| 271 | end | 267 | end |
| 272 | local _anon_func_2 = function(_u539f_u70b9) | 268 | local _anon_func_2 = function(_u539f_u70b9) |
| 273 | do | 269 | local _call_1 = _u539f_u70b9["变换"]["根节点"]["游戏对象"] |
| 274 | local _call_1 = _u539f_u70b9["变换"]["根节点"]["游戏对象"] | 270 | return _call_1["父节点"](_call_1) |
| 275 | return _call_1["父节点"](_call_1) | ||
| 276 | end | ||
| 277 | end | 271 | end |
| 278 | local _call_1 = ((function() | 272 | local _call_1 = ((function() |
| 279 | local _call_1 = ((function() | 273 | local _call_1 = ((function() |
| @@ -365,10 +359,8 @@ local _1 | |||
| 365 | _1 = function() | 359 | _1 = function() |
| 366 | _u6253_u5370(1) | 360 | _u6253_u5370(1) |
| 367 | local _accum_0 = { } | 361 | local _accum_0 = { } |
| 368 | local _len_0 = 1 | ||
| 369 | while false do | 362 | while false do |
| 370 | break | 363 | break |
| 371 | _len_0 = _len_0 + 1 | ||
| 372 | end | 364 | end |
| 373 | return _accum_0 | 365 | return _accum_0 |
| 374 | 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/syntax.lua b/spec/outputs/unicode/syntax.lua index 1984f40..f5d5d8a 100644 --- a/spec/outputs/unicode/syntax.lua +++ b/spec/outputs/unicode/syntax.lua | |||
| @@ -5,9 +5,9 @@ _u51fd_u6570(_u53c2_u65701, _u53c2_u65702, _u53e6_u5916, _u53c2_u65703) | |||
| 5 | local _u6211_u4eec | 5 | local _u6211_u4eec |
| 6 | _u8fd9_u91cc, _u6211_u4eec = function() end, _u662f_u7684 | 6 | _u8fd9_u91cc, _u6211_u4eec = function() end, _u662f_u7684 |
| 7 | local _u8fd9_u4e2a, _u4e0d_u540c | 7 | local _u8fd9_u4e2a, _u4e0d_u540c |
| 8 | _u8fd9_u4e2a, _u4e0d_u540c = function() | 8 | _u8fd9_u4e2a, _u4e0d_u540c = (function() |
| 9 | return _u65b9_u6cd5 | 9 | return _u65b9_u6cd5 |
| 10 | end, _u662f_u7684 | 10 | end), _u662f_u7684 |
| 11 | _u7238_u7238() | 11 | _u7238_u7238() |
| 12 | _u7238_u7238(_u4e3b) | 12 | _u7238_u7238(_u4e3b) |
| 13 | _u4f60_u597d(_u4e00, _u4e8c)(); | 13 | _u4f60_u597d(_u4e00, _u4e8c)(); |
| @@ -286,10 +286,8 @@ _ = 5 - _u4ec0_u4e48(_u65e0_u804a) | |||
| 286 | _u4ec0_u4e48(_u65e0_u804a - 5) | 286 | _u4ec0_u4e48(_u65e0_u804a - 5) |
| 287 | _u53d8_u91cfx = _u4f60_u597d - _u4e16_u754c - _u67d0_u7269 | 287 | _u53d8_u91cfx = _u4f60_u597d - _u4e16_u754c - _u67d0_u7269 |
| 288 | local _anon_func_0 = function(_u4ec0_u4e48) | 288 | local _anon_func_0 = function(_u4ec0_u4e48) |
| 289 | do | 289 | local _call_8 = _u4ec0_u4e48 |
| 290 | local _call_8 = _u4ec0_u4e48 | 290 | return _call_8["酷"](_call_8, 100) |
| 291 | return _call_8["酷"](_call_8, 100) | ||
| 292 | end | ||
| 293 | end | 291 | end |
| 294 | (function(_u67d0_u7269) | 292 | (function(_u67d0_u7269) |
| 295 | if _u67d0_u7269 == nil then | 293 | if _u67d0_u7269 == nil 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/whitespace.lua b/spec/outputs/unicode/whitespace.lua index d026abb..7a83d9f 100644 --- a/spec/outputs/unicode/whitespace.lua +++ b/spec/outputs/unicode/whitespace.lua | |||
| @@ -82,12 +82,12 @@ v = function() | |||
| 82 | return _u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc | 82 | return _u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc |
| 83 | end | 83 | end |
| 84 | local v1, v2, v3 | 84 | local v1, v2, v3 |
| 85 | v1, v2, v3 = function() | 85 | v1, v2, v3 = (function() |
| 86 | return _u53d8_u91cfa | 86 | return _u53d8_u91cfa |
| 87 | end, _u53d8_u91cfb, _u53d8_u91cfc | 87 | end), _u53d8_u91cfb, _u53d8_u91cfc |
| 88 | local _u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc, _u53d8_u91cfd, _u53d8_u91cfe, _u53d8_u91cff = 1, f2({ | 88 | local _u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc, _u53d8_u91cfd, _u53d8_u91cfe, _u53d8_u91cff = 1, (f2({ |
| 89 | abc = abc | 89 | abc = abc |
| 90 | }), 3, 4, _u51fd_u65705(abc), 6 | 90 | })), 3, 4, _u51fd_u65705(abc), 6 |
| 91 | for _u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc in pairs(_u5bf9_u8c61tb) do | 91 | for _u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc in pairs(_u5bf9_u8c61tb) do |
| 92 | _u6253_u5370(_u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc) | 92 | _u6253_u5370(_u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc) |
| 93 | end | 93 | end |
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..9f97681 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(...) |
| @@ -306,3 +294,75 @@ join = function(...) | |||
| 306 | end | 294 | end |
| 307 | return nil | 295 | return nil |
| 308 | end | 296 | end |
| 297 | do | ||
| 298 | local f1 | ||
| 299 | f1 = function(...) | ||
| 300 | local t = { | ||
| 301 | n = select("#", ...), | ||
| 302 | ... | ||
| 303 | } | ||
| 304 | print(t.n) | ||
| 305 | print(#t) | ||
| 306 | for i = 1, t.n do | ||
| 307 | print(t[i]) | ||
| 308 | end | ||
| 309 | end | ||
| 310 | f1(1, 2, 3) | ||
| 311 | f1("a", "b", "c", "d") | ||
| 312 | f1() | ||
| 313 | local f2 | ||
| 314 | f2 = function(...) | ||
| 315 | local args = { | ||
| 316 | n = select("#", ...), | ||
| 317 | ... | ||
| 318 | } | ||
| 319 | print("args count:", args.n) | ||
| 320 | print("args length:", #args) | ||
| 321 | for i = 1, args.n do | ||
| 322 | if args[i] == nil then | ||
| 323 | print("position", i, "is nil") | ||
| 324 | else | ||
| 325 | print("position", i, ":", args[i]) | ||
| 326 | end | ||
| 327 | end | ||
| 328 | end | ||
| 329 | f2(1, nil, 3, nil, 5) | ||
| 330 | local f3 | ||
| 331 | f3 = function(prefix, ...) | ||
| 332 | local items = { | ||
| 333 | n = select("#", ...), | ||
| 334 | ... | ||
| 335 | } | ||
| 336 | local result = { } | ||
| 337 | for i = 1, items.n do | ||
| 338 | result[i] = prefix .. tostring(items[i]) | ||
| 339 | end | ||
| 340 | return result | ||
| 341 | end | ||
| 342 | f3("item_", 1, 2, 3) | ||
| 343 | local f4 | ||
| 344 | f4 = function(...) | ||
| 345 | local empty = { | ||
| 346 | n = select("#", ...), | ||
| 347 | ... | ||
| 348 | } | ||
| 349 | print("empty count:", empty.n) | ||
| 350 | return print("empty length:", #empty) | ||
| 351 | end | ||
| 352 | f4() | ||
| 353 | local process | ||
| 354 | process = function(...) | ||
| 355 | local data = { | ||
| 356 | n = select("#", ...), | ||
| 357 | ... | ||
| 358 | } | ||
| 359 | local sum = 0 | ||
| 360 | for i = 1, data.n do | ||
| 361 | if type(data[i]) == "number" then | ||
| 362 | sum = sum + data[i] | ||
| 363 | end | ||
| 364 | end | ||
| 365 | return sum | ||
| 366 | end | ||
| 367 | return process(1, 2, 3, "skip", 5) | ||
| 368 | end | ||
diff --git a/spec/outputs/whitespace.lua b/spec/outputs/whitespace.lua index 0251968..864f085 100644 --- a/spec/outputs/whitespace.lua +++ b/spec/outputs/whitespace.lua | |||
| @@ -94,12 +94,12 @@ v = function() | |||
| 94 | return a, b, c | 94 | return a, b, c |
| 95 | end | 95 | end |
| 96 | local v1, v2, v3 | 96 | local v1, v2, v3 |
| 97 | v1, v2, v3 = function() | 97 | v1, v2, v3 = (function() |
| 98 | return a | 98 | return a |
| 99 | end, b, c | 99 | end), b, c |
| 100 | local a, b, c, d, e, f = 1, f2({ | 100 | local a, b, c, d, e, f = 1, (f2({ |
| 101 | abc = abc | 101 | abc = abc |
| 102 | }), 3, 4, f5(abc), 6 | 102 | })), 3, 4, f5(abc), 6 |
| 103 | for a, b, c in pairs(tb) do | 103 | for a, b, c in pairs(tb) do |
| 104 | print(a, b, c) | 104 | print(a, b, c) |
| 105 | end | 105 | end |
diff --git a/spec/outputs/with.lua b/spec/outputs/with.lua index 1a795c1..530915e 100644 --- a/spec/outputs/with.lua +++ b/spec/outputs/with.lua | |||
| @@ -187,4 +187,66 @@ do | |||
| 187 | return _with_0[123] | 187 | return _with_0[123] |
| 188 | end | 188 | end |
| 189 | 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 | ||
| 190 | return nil | 252 | return nil |
