diff options
author | Li Jin <dragon-fly@qq.com> | 2021-08-23 16:51:36 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2021-08-23 16:51:36 +0800 |
commit | 05e78bb7c2afb28e392b8729388dc5257c9dbf31 (patch) | |
tree | 1eca19ba77d9eb0b829e26034d44cd07e61d63a0 | |
parent | 608d895eb523068a2a31de43fc020816b54094d0 (diff) | |
download | yuescript-05e78bb7c2afb28e392b8729388dc5257c9dbf31.tar.gz yuescript-05e78bb7c2afb28e392b8729388dc5257c9dbf31.tar.bz2 yuescript-05e78bb7c2afb28e392b8729388dc5257c9dbf31.zip |
update changelogs.
-rw-r--r-- | CHANGELOG.md | 814 |
1 files changed, 448 insertions, 366 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index d67dd81..b60bf8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md | |||
@@ -2,6 +2,92 @@ | |||
2 | 2 | ||
3 | The implementation for the original Moonscript language 0.5.0 can be found in the `0.5.0` branch of Yuescript. The Moonscript with fixes and new features is in the main branch of Yuescript. Here are the changelogs for each Yuescript version. | 3 | The implementation for the original Moonscript language 0.5.0 can be found in the `0.5.0` branch of Yuescript. The Moonscript with fixes and new features is in the main branch of Yuescript. Here are the changelogs for each Yuescript version. |
4 | 4 | ||
5 | ## v0.8.2 | ||
6 | |||
7 | ### Fixed Issues | ||
8 | |||
9 | * Simplify and extend import syntax. | ||
10 | * Report an error when destructuring nil item. | ||
11 | |||
12 | ### Added Features | ||
13 | |||
14 | * New metatable syntax. | ||
15 | ```moonscript | ||
16 | #: mt = tb | ||
17 | mt = tb.# | ||
18 | a = #: mt, value: 1 | ||
19 | b = :add#, value: 2 | ||
20 | close _ = close#: -> print "out of scope" | ||
21 | ``` | ||
22 | compiles to: | ||
23 | ```lua | ||
24 | local mt = getmetatable(tb) | ||
25 | mt = getmetatable(tb) | ||
26 | local a = setmetatable({ | ||
27 | value = 1 | ||
28 | }, mt) | ||
29 | local b = setmetatable({ | ||
30 | value = 2 | ||
31 | }, { | ||
32 | __add = add | ||
33 | }) | ||
34 | local _ <close> = setmetatable({ }, { | ||
35 | __close = function() | ||
36 | return print("out of scope") | ||
37 | end | ||
38 | }) | ||
39 | ``` | ||
40 | |||
41 | * Aliasing symbol :: with \ for writing colon chain items. | ||
42 | ```moonscript | ||
43 | tb\func1()::func2() | ||
44 | ``` | ||
45 | compiles to: | ||
46 | ```lua | ||
47 | tb:func1():func2() | ||
48 | ``` | ||
49 | |||
50 | * Add until statement. | ||
51 | ```moonscript | ||
52 | a = 3 | ||
53 | until a == 0 | ||
54 | a -= 1 | ||
55 | ``` | ||
56 | compiles to: | ||
57 | ```lua | ||
58 | local a = 3 | ||
59 | while not (a == 0) do | ||
60 | a = a - 1 | ||
61 | end | ||
62 | ``` | ||
63 | |||
64 | * Add existential check syntax for function argument as a shortcut feature to assign self field. | ||
65 | ```moonscript | ||
66 | tb\func1()::func2() | ||
67 | ``` | ||
68 | compiles to: | ||
69 | ```lua | ||
70 | tb:func1():func2() | ||
71 | ``` | ||
72 | |||
73 | * Add default value support for destructure syntax. | ||
74 | ```moonscript | ||
75 | {:name = "nameless", :job = "jobless"} = person | ||
76 | ``` | ||
77 | compiles to: | ||
78 | ```lua | ||
79 | local name, job | ||
80 | do | ||
81 | local _obj_0 = person | ||
82 | name, job = _obj_0.name, _obj_0.job | ||
83 | end | ||
84 | if name == nil then | ||
85 | name = "nameless" | ||
86 | end | ||
87 | if job == nil then | ||
88 | job = "jobless" | ||
89 | end | ||
90 | ``` | ||
5 | 91 | ||
6 | ## v0.6.7 | 92 | ## v0.6.7 |
7 | 93 | ||
@@ -9,90 +95,90 @@ The implementation for the original Moonscript language 0.5.0 can be found in th | |||
9 | 95 | ||
10 | * Simplify macro syntax. A macro function can either return a Yuescript string or a config table containing Lua codes. | 96 | * Simplify macro syntax. A macro function can either return a Yuescript string or a config table containing Lua codes. |
11 | 97 | ||
12 | ```moonscript | 98 | ```moonscript |
13 | macro localFunc = (var)-> "local #{var} = ->" | 99 | macro localFunc = (var)-> "local #{var} = ->" |
14 | $localFunc f1 | 100 | $localFunc f1 |
15 | f1 = -> "another function" | 101 | f1 = -> "another function" |
16 | 102 | ||
17 | -- or | 103 | -- or |
18 | 104 | ||
19 | macro localFunc = (var)-> | 105 | macro localFunc = (var)-> |
20 | { | 106 | { |
21 | codes: "local function #{var}() end" | 107 | codes: "local function #{var}() end" |
22 | type: "lua" | 108 | type: "lua" |
23 | locals: {var} | 109 | locals: {var} |
24 | } | 110 | } |
25 | $localFunc f2 | 111 | $localFunc f2 |
26 | f2 = -> "another function" | 112 | f2 = -> "another function" |
27 | ``` | 113 | ``` |
28 | Compiles to: | 114 | Compiles to: |
29 | ```Lua | 115 | ```Lua |
30 | local f1 | 116 | local f1 |
31 | f1 = function() end | 117 | f1 = function() end |
32 | f1 = function() | 118 | f1 = function() |
33 | return "another function" | 119 | return "another function" |
34 | end | 120 | end |
35 | local function f2() end | 121 | local function f2() end |
36 | f2 = function() | 122 | f2 = function() |
37 | return "another function" | 123 | return "another function" |
38 | end | 124 | end |
39 | ``` | 125 | ``` |
40 | 126 | ||
41 | * Change the Yuescript file extension to '.yue' because some of the Moonscript syntax is no longer supported and some codes written in Yuescript syntax won't be accepted by the Moonscript compiler. | 127 | * Change the Yuescript file extension to '.yue' because some of the Moonscript syntax is no longer supported and some codes written in Yuescript syntax won't be accepted by the Moonscript compiler. |
42 | * Disable the use of local and global statements with wildcard operators. | 128 | * Disable the use of local and global statements with wildcard operators. |
43 | * Change the backcall operator syntax, extra parentheses for multiline chains are no longer needed. | 129 | * Change the backcall operator syntax, extra parentheses for multiline chains are no longer needed. |
44 | ```moonscript | 130 | ```moonscript |
45 | readFile "example.txt" | 131 | readFile "example.txt" |
46 | |> extract language, {} | 132 | |> extract language, {} |
47 | |> parse language | 133 | |> parse language |
48 | |> emit | 134 | |> emit |
49 | |> render | 135 | |> render |
50 | 136 | ||
51 | ``` | 137 | ``` |
52 | Compiles to: | 138 | Compiles to: |
53 | ```Lua | 139 | ```Lua |
54 | return print(render(emit(parse(extract(readFile("example.txt"), language, { }), language)))) | 140 | return print(render(emit(parse(extract(readFile("example.txt"), language, { }), language)))) |
55 | ``` | 141 | ``` |
56 | 142 | ||
57 | 143 | ||
58 | ### Added Features | 144 | ### Added Features |
59 | 145 | ||
60 | * Supporting multiline chaining function call syntax. | 146 | * Supporting multiline chaining function call syntax. |
61 | ```Moonscript | 147 | ```Moonscript |
62 | result = origin | 148 | result = origin |
63 | .transform.root | 149 | .transform.root |
64 | .gameObject | 150 | .gameObject |
65 | \Parents! | 151 | \Parents! |
66 | \Descendants! | 152 | \Descendants! |
67 | \SelectEnable! | 153 | \SelectEnable! |
68 | \SelectVisible! | 154 | \SelectVisible! |
69 | \TagEqual "fx" | 155 | \TagEqual "fx" |
70 | \Where (x)-> | 156 | \Where (x)-> |
71 | if x\IsTargeted! | 157 | if x\IsTargeted! |
158 | return false | ||
159 | x.name\EndsWith "(Clone)" | ||
160 | \Destroy! | ||
161 | |||
162 | origin.transform.root.gameObject | ||
163 | \Parents!\Descendants! | ||
164 | \SelectEnable! | ||
165 | \SelectVisible! | ||
166 | \TagEqual "fx" | ||
167 | \Where (x)-> x.name\EndsWith "(Clone)" | ||
168 | \Destroy! | ||
169 | ``` | ||
170 | Compiles to: | ||
171 | ```Lua | ||
172 | local result = origin.transform.root.gameObject:Parents():Descendants():SelectEnable():SelectVisible():TagEqual("fx"):Where(function(x) | ||
173 | if x:IsTargeted() then | ||
72 | return false | 174 | return false |
73 | x.name\EndsWith "(Clone)" | 175 | end |
74 | \Destroy! | 176 | return x.name:EndsWith("(Clone)") |
75 | 177 | end):Destroy() | |
76 | origin.transform.root.gameObject | 178 | return origin.transform.root.gameObject:Parents():Descendants():SelectEnable(): SelectVisible():TagEqual("fx"):Where(function(x) |
77 | \Parents!\Descendants! | 179 | return x.name:EndsWith("(Clone)") |
78 | \SelectEnable! | 180 | end):Destroy() |
79 | \SelectVisible! | 181 | ``` |
80 | \TagEqual "fx" | ||
81 | \Where (x)-> x.name\EndsWith "(Clone)" | ||
82 | \Destroy! | ||
83 | ``` | ||
84 | Compiles to: | ||
85 | ```Lua | ||
86 | local result = origin.transform.root.gameObject:Parents():Descendants():SelectEnable():SelectVisible():TagEqual("fx"):Where(function(x) | ||
87 | if x:IsTargeted() then | ||
88 | return false | ||
89 | end | ||
90 | return x.name:EndsWith("(Clone)") | ||
91 | end):Destroy() | ||
92 | return origin.transform.root.gameObject:Parents():Descendants():SelectEnable():SelectVisible():TagEqual("fx"):Where(function(x) | ||
93 | return x.name:EndsWith("(Clone)") | ||
94 | end):Destroy() | ||
95 | ``` | ||
96 | 182 | ||
97 | 183 | ||
98 | 184 | ||
@@ -186,19 +272,17 @@ end):Destroy() | |||
186 | 272 | ||
187 | Compiles to: | 273 | Compiles to: |
188 | 274 | ||
189 | ```Lua | 275 | ```Lua |
190 | local _var_0 = setmetatable({ }, { | 276 | local a <close> = setmetatable({ }, { |
191 | __close = function(self) | 277 | __close = function(self) end |
192 | end | ||
193 | }) | 278 | }) |
194 | local a <close> = _var_0 | 279 | local b <const> = (function() |
195 | local _var_1 | 280 | if var then |
196 | if var then | 281 | return 123 |
197 | _var_1 = 123 | 282 | else |
198 | else | 283 | return 'abc' |
199 | _var_1 = 'abc' | 284 | end |
200 | end | 285 | end)() |
201 | local b <const> = _var_1 | ||
202 | ``` | 286 | ``` |
203 | 287 | ||
204 | 288 | ||
@@ -274,45 +358,45 @@ end):Destroy() | |||
274 | ### Added Features | 358 | ### Added Features |
275 | 359 | ||
276 | * Add macro functions. | 360 | * Add macro functions. |
277 | ```Moonscript | 361 | ```Moonscript |
278 | -- file 'macro.mp' | 362 | -- file 'macro.mp' |
279 | export macro config = (debugging = true)-> | 363 | export macro config = (debugging = true)-> |
280 | global debugMode = debugging == "true" | 364 | global debugMode = debugging == "true" |
281 | "" | 365 | "" |
282 | |||
283 | export macro asserts = (cond)-> | ||
284 | debugMode and "assert #{cond}" or "" | ||
285 | 366 | ||
286 | export macro assert = (cond)-> | 367 | export macro asserts = (cond)-> |
287 | debugMode and "assert #{cond}" or "#{cond}" | 368 | debugMode and "assert #{cond}" or "" |
288 | 369 | ||
289 | $config! | 370 | export macro assert = (cond)-> |
371 | debugMode and "assert #{cond}" or "#{cond}" | ||
290 | 372 | ||
291 | -- file 'main.mp' | 373 | $config! |
292 | import 'macro' as {:$config, :$assert, :$asserts} | ||
293 | 374 | ||
294 | macro and = (...)-> "#{ table.concat {...}, ' and ' }" | 375 | -- file 'main.mp' |
376 | import 'macro' as {:$config, :$assert, :$asserts} | ||
295 | 377 | ||
296 | $asserts item ~= nil | 378 | macro and = (...)-> "#{ table.concat {...}, ' and ' }" |
297 | $config false | ||
298 | value = $assert item | ||
299 | 379 | ||
300 | if $and f1!, f2!, f3! | 380 | $asserts item ~= nil |
301 | print "OK" | 381 | $config false |
302 | ``` | 382 | value = $assert item |
303 | Compiles to: | ||
304 | ```Lua | ||
305 | -- file 'macro.mp' | ||
306 | local _module_0 = { } | ||
307 | return _module_0 | ||
308 | 383 | ||
309 | -- file 'main.mp' | 384 | if $and f1!, f2!, f3! |
310 | assert(item ~= nil) | 385 | print "OK" |
311 | local value = item | 386 | ``` |
312 | if (f1() and f2() and f3()) then | 387 | Compiles to: |
313 | print("OK") | 388 | ```Lua |
314 | end | 389 | -- file 'macro.mp' |
315 | ``` | 390 | local _module_0 = { } |
391 | return _module_0 | ||
392 | |||
393 | -- file 'main.mp' | ||
394 | assert(item ~= nil) | ||
395 | local value = item | ||
396 | if (f1() and f2() and f3()) then | ||
397 | print("OK") | ||
398 | end | ||
399 | ``` | ||
316 | 400 | ||
317 | 401 | ||
318 | 402 | ||
@@ -340,70 +424,70 @@ From the original Moonscript compiler: | |||
340 | * Add option to compile Yuescript as a Lua C lib. Got Yuescript released to `Luarocks`. | 424 | * Add option to compile Yuescript as a Lua C lib. Got Yuescript released to `Luarocks`. |
341 | * Move old `export` statement functions to `global` statement to match the `local` statement. | 425 | * Move old `export` statement functions to `global` statement to match the `local` statement. |
342 | * Change `export` statement behavior to support module management. Moon codes with `export` statements can not explicitly return values in the root scope. And codes with `export default` can export only one value as the module content. Use cases: | 426 | * Change `export` statement behavior to support module management. Moon codes with `export` statements can not explicitly return values in the root scope. And codes with `export default` can export only one value as the module content. Use cases: |
343 | ```Moonscript | 427 | ```Moonscript |
344 | -- file 'Config.mp' | 428 | -- file 'Config.mp' |
345 | export default {flag:1, value:"x"} | 429 | export default {flag:1, value:"x"} |
346 | 430 | ||
347 | -- file 'Utils.mp' | 431 | -- file 'Utils.mp' |
348 | export map = (items, func)-> [func item for item in *items] | 432 | export map = (items, func)-> [func item for item in *items] |
349 | export filter = (items, func)-> [item for item in *items when func item] | 433 | export filter = (items, func)-> [item for item in *items when func item] |
350 | 434 | ||
351 | -- file 'main.mp' | 435 | -- file 'main.mp' |
352 | import 'Config' as {:flag, :value} | 436 | import 'Config' as {:flag, :value} |
353 | import 'Utils' as {:map, :filter} | 437 | import 'Utils' as {:map, :filter} |
354 | ``` | 438 | ``` |
355 | Compiles to: | 439 | Compiles to: |
356 | ```Lua | 440 | ```Lua |
357 | -- file 'Config.mp' | 441 | -- file 'Config.mp' |
358 | local _module_0 = nil | 442 | local _module_0 = nil |
359 | _module_0 = { | 443 | _module_0 = { |
360 | flag = 1, | 444 | flag = 1, |
361 | value = "x" | 445 | value = "x" |
362 | } | 446 | } |
363 | return _module_0 | 447 | return _module_0 |
364 | 448 | ||
365 | -- file 'Utils.mp' | 449 | -- file 'Utils.mp' |
366 | local _module_0 = { } | 450 | local _module_0 = { } |
367 | local map | 451 | local map |
368 | map = function(items, func) | 452 | map = function(items, func) |
369 | local _accum_0 = { } | 453 | local _accum_0 = { } |
370 | local _len_0 = 1 | 454 | local _len_0 = 1 |
371 | for _index_0 = 1, #items do | 455 | for _index_0 = 1, #items do |
372 | local item = items[_index_0] | 456 | local item = items[_index_0] |
373 | _accum_0[_len_0] = func(item) | 457 | _accum_0[_len_0] = func(item) |
374 | _len_0 = _len_0 + 1 | ||
375 | end | ||
376 | return _accum_0 | ||
377 | end | ||
378 | _module_0["map"] = map | ||
379 | local filter | ||
380 | filter = function(items, func) | ||
381 | local _accum_0 = { } | ||
382 | local _len_0 = 1 | ||
383 | for _index_0 = 1, #items do | ||
384 | local item = items[_index_0] | ||
385 | if func(item) then | ||
386 | _accum_0[_len_0] = item | ||
387 | _len_0 = _len_0 + 1 | 458 | _len_0 = _len_0 + 1 |
388 | end | 459 | end |
460 | return _accum_0 | ||
461 | end | ||
462 | _module_0["map"] = map | ||
463 | local filter | ||
464 | filter = function(items, func) | ||
465 | local _accum_0 = { } | ||
466 | local _len_0 = 1 | ||
467 | for _index_0 = 1, #items do | ||
468 | local item = items[_index_0] | ||
469 | if func(item) then | ||
470 | _accum_0[_len_0] = item | ||
471 | _len_0 = _len_0 + 1 | ||
472 | end | ||
473 | end | ||
474 | return _accum_0 | ||
389 | end | 475 | end |
390 | return _accum_0 | 476 | _module_0["filter"] = filter |
391 | end | 477 | return _module_0 |
392 | _module_0["filter"] = filter | 478 | |
393 | return _module_0 | 479 | -- file 'main.mp' |
394 | 480 | local flag, value | |
395 | -- file 'main.mp' | 481 | do |
396 | local flag, value | 482 | local _obj_0 = require('Config') |
397 | do | 483 | flag, value = _obj_0.flag, _obj_0.value |
398 | local _obj_0 = require('Config') | 484 | end |
399 | flag, value = _obj_0.flag, _obj_0.value | 485 | local map, filter |
400 | end | 486 | do |
401 | local map, filter | 487 | local _obj_0 = require('Utils') |
402 | do | 488 | map, filter = _obj_0.map, _obj_0.filter |
403 | local _obj_0 = require('Utils') | 489 | end |
404 | map, filter = _obj_0.map, _obj_0.filter | 490 | ``` |
405 | end | ||
406 | ``` | ||
407 | 491 | ||
408 | 492 | ||
409 | 493 | ||
@@ -425,110 +509,110 @@ Fix issues in original Moonscript compiler: | |||
425 | * Multi-line comment support. | 509 | * Multi-line comment support. |
426 | 510 | ||
427 | * Back call features with new operator and syntax. For example: | 511 | * Back call features with new operator and syntax. For example: |
428 | ```Moonscript | 512 | ```Moonscript |
429 | {1,2,3} | 513 | {1,2,3} |
430 | |> map((x)-> x * 2) | 514 | |> map((x)-> x * 2) |
431 | |> filter((x)-> x > 4) | 515 | |> filter((x)-> x > 4) |
432 | |> reduce(0, (a,b)-> a + b) | 516 | |> reduce(0, (a,b)-> a + b) |
433 | 517 | ||
434 | 518 | ||
435 | do | 519 | do |
436 | (data) <- http.get "ajaxtest" | 520 | (data) <- http.get "ajaxtest" |
437 | body[".result"]\html data | 521 | body[".result"]\html data |
438 | (processed) <- http.post "ajaxprocess", data | 522 | (processed) <- http.post "ajaxprocess", data |
439 | body[".result"]\append processed | 523 | body[".result"]\append processed |
440 | print "done" | 524 | print "done" |
441 | ``` | 525 | ``` |
442 |   will be compiled to: | 526 | will be compiled to: |
443 | ```Lua | 527 | ```Lua |
444 | print(reduce(filter(map({ | 528 | print(reduce(filter(map({ |
445 | 1, | 529 | 1, |
446 | 2, | 530 | 2, |
447 | 3 | 531 | 3 |
448 | }, function(x) | 532 | }, function(x) |
449 | return x * 2 | 533 | return x * 2 |
450 | end), function(x) | 534 | end), function(x) |
451 | return x > 4 | 535 | return x > 4 |
452 | end), 0, function(a, b) | 536 | end), 0, function(a, b) |
453 | return a + b | 537 | return a + b |
454 | end)) | 538 | end)) |
455 | do | 539 | do |
456 | http.get("ajaxtest", function(data) | 540 | http.get("ajaxtest", function(data) |
457 | body[".result"]:html(data) | 541 | body[".result"]:html(data) |
458 | return http.post("ajaxprocess", data, function(processed) | 542 | return http.post("ajaxprocess", data, function(processed) |
459 | body[".result"]:append(processed) | 543 | body[".result"]:append(processed) |
460 | return print("done") | 544 | return print("done") |
545 | end) | ||
461 | end) | 546 | end) |
462 | end) | 547 | end |
463 | end | 548 | ``` |
464 | ``` | ||
465 | 549 | ||
466 | * Existential operator support. Generate codes from: | 550 | * Existential operator support. Generate codes from: |
467 | ```Moonscript | 551 | ```Moonscript |
468 | func?! | 552 | func?! |
469 | 553 | ||
470 | x = tab?.value | 554 | x = tab?.value |
471 | 555 | ||
472 | print abc?["hello world"]?.xyz | 556 | print abc?["hello world"]?.xyz |
473 | 557 | ||
474 | if print and x? | 558 | if print and x? |
475 | print x | 559 | print x |
476 | ``` | 560 | ``` |
477 |   to: | 561 | to: |
478 | ```Lua | 562 | ```Lua |
479 | if func ~= nil then | 563 | if func ~= nil then |
480 | func() | 564 | func() |
481 | end | 565 | end |
482 | local x | 566 | local x |
483 | if tab ~= nil then | 567 | if tab ~= nil then |
484 | x = tab.value | 568 | x = tab.value |
485 | end | 569 | end |
486 | print((function() | 570 | print((function() |
487 | if abc ~= nil then | 571 | if abc ~= nil then |
488 | local _obj_0 = abc["hello world"] | 572 | local _obj_0 = abc["hello world"] |
489 | if _obj_0 ~= nil then | 573 | if _obj_0 ~= nil then |
490 | return _obj_0.xyz | 574 | return _obj_0.xyz |
575 | end | ||
576 | return nil | ||
491 | end | 577 | end |
492 | return nil | 578 | return nil |
579 | end)()) | ||
580 | if print and (x ~= nil) then | ||
581 | print(x) | ||
493 | end | 582 | end |
494 | return nil | 583 | ``` |
495 | end)()) | ||
496 | if print and (x ~= nil) then | ||
497 | print(x) | ||
498 | end | ||
499 | ``` | ||
500 | 584 | ||
501 | * More usages for `import` keyword. Will compile codes from: | 585 | * More usages for `import` keyword. Will compile codes from: |
502 | ```Moonscript | 586 | ```Moonscript |
503 | import 'module' | 587 | import 'module' |
504 | import "module.part" | 588 | import "module.part" |
505 | import "d-a-s-h-e-s" | 589 | import "d-a-s-h-e-s" |
506 | import "player" as Player | 590 | import "player" as Player |
507 | import "lpeg" as {:C, :Ct, :Cmt} | 591 | import "lpeg" as {:C, :Ct, :Cmt} |
508 | ``` | 592 | ``` |
509 |   to: | 593 | to: |
510 | ```Lua | 594 | ```Lua |
511 | local module = require('module') | 595 | local module = require('module') |
512 | local part = require("module.part") | 596 | local part = require("module.part") |
513 | local d_a_s_h_e_s = require("d-a-s-h-e-s") | 597 | local d_a_s_h_e_s = require("d-a-s-h-e-s") |
514 | local Player = require("player") | 598 | local Player = require("player") |
515 | local C, Ct, Cmt | 599 | local C, Ct, Cmt |
516 | do | 600 | do |
517 | local _obj_0 = require("lpeg") | 601 | local _obj_0 = require("lpeg") |
518 | C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt | 602 | C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt |
519 | end | 603 | end |
520 | ``` | 604 | ``` |
521 | 605 | ||
522 | * Can do slash call with Lua keywords. Generate codes from: | 606 | * Can do slash call with Lua keywords. Generate codes from: |
523 | ```Moonscript | 607 | ```Moonscript |
524 | c.repeat.if\then("xyz")\else res | 608 | c.repeat.if\then("xyz")\else res |
525 | ``` | 609 | ``` |
526 |   to: | 610 | to: |
527 | ```Lua | 611 | ```Lua |
528 | local _call_3 = c["repeat"]["if"] | 612 | local _call_3 = c["repeat"]["if"] |
529 | local _call_4 = _call_3["then"](_call_3, "xyz") | 613 | local _call_4 = _call_3["then"](_call_3, "xyz") |
530 | _call_4["else"](_call_4, res) | 614 | _call_4["else"](_call_4, res) |
531 | ``` | 615 | ``` |
532 | 616 | ||
533 | 617 | ||
534 | 618 | ||
@@ -537,110 +621,108 @@ _call_4["else"](_call_4, res) | |||
537 | * Left part of update statement will now accept only one assignable expression. | 621 | * Left part of update statement will now accept only one assignable expression. |
538 | * Expression list appears in the middle of the code block is not allowed. For codes like: | 622 | * Expression list appears in the middle of the code block is not allowed. For codes like: |
539 | 623 | ||
540 | ```Moonscript | 624 | ```Moonscript |
541 | -- Moonscript 0.5.0 | 625 | -- Moonscript 0.5.0 |
542 | f = (x)-> | 626 | f = (x)-> |
543 | "abc",123 -- valid meaningless codes | 627 | "abc",123 -- valid meaningless codes |
544 | x + 1 | 628 | x + 1 |
545 | ``` | 629 | ``` |
546 | 630 | in original Moonscript compiles to: | |
547 | in original Moonscript compiles to: | 631 | ```Lua |
548 | 632 | local f | |
549 | ```Lua | 633 | f = function(x) |
550 | local f | 634 | local _ = "abc", 123 -- report error in Yuescript |
551 | f = function(x) | 635 | return x + 1 |
552 | local _ = "abc", 123 -- report error in Yuescript | 636 | end |
553 | return x + 1 | 637 | ``` |
554 | end | 638 | |
555 | ``` | 639 | This feature may lead to some silenced errors. For example: |
556 | 640 | ||
557 | This feature may lead to some silenced errors. For example: | 641 | ```Moonscript |
558 | 642 | -- expected codes | |
559 | ```Moonscript | 643 | tree\addChild with Node! |
560 | -- expected codes | 644 | \addChild subNode |
561 | tree\addChild with Node! | ||
562 | \addChild subNode | ||
563 | 645 | ||
564 | -- in original Moonscript, codes will still run | 646 | -- in original Moonscript, codes will still run |
565 | -- after adding a break by mistake | 647 | -- after adding a break by mistake |
566 | tree\addChild | 648 | tree\addChild |
567 | with Node! | 649 | with Node! |
568 | \addChild subNode | 650 | \addChild subNode |
569 | ``` | 651 | ``` |
570 | 652 | ||
571 | the original Moonscript will compile these codes to: | 653 | The original Moonscript will compile these codes to: |
572 | 654 | ||
573 | ```Lua | 655 | ```Lua |
574 | -- expected codes | 656 | -- expected codes |
575 | tree:addChild((function() | 657 | tree:addChild((function() |
658 | do | ||
659 | local _with_0 = Node() | ||
660 | _with_0:addChild(subNode) | ||
661 | return _with_0 | ||
662 | end | ||
663 | end)()) | ||
664 | |||
665 | -- codes added with a break will still run | ||
666 | local _ -- report error in Yuescript instead of creating | ||
667 | do -- an anonymous function to bind the object method | ||
668 | local _base_0 = tree | ||
669 | local _fn_0 = _base_0.addChild | ||
670 | _ = function(...) | ||
671 | return _fn_0(_base_0, ...) | ||
672 | end | ||
673 | end | ||
576 | do | 674 | do |
577 | local _with_0 = Node() | 675 | local _with_0 = Node() |
578 | _with_0:addChild(subNode) | 676 | _with_0:addChild(subNode) |
579 | return _with_0 | ||
580 | end | ||
581 | end)()) | ||
582 | |||
583 | -- codes added with a break will still run | ||
584 | local _ -- report error in Yuescript instead of creating | ||
585 | do -- an anonymous function to bind the object method | ||
586 | local _base_0 = tree | ||
587 | local _fn_0 = _base_0.addChild | ||
588 | _ = function(...) | ||
589 | return _fn_0(_base_0, ...) | ||
590 | end | 677 | end |
591 | end | 678 | ``` |
592 | do | ||
593 | local _with_0 = Node() | ||
594 | _with_0:addChild(subNode) | ||
595 | end | ||
596 | ``` | ||
597 | 679 | ||
598 | * Reusing variables which help generate reduced Lua codes. | 680 | * Reusing variables which help generate reduced Lua codes. |
599 | For example, Yuescript will generate codes from: | 681 | For example, Yuescript will generate codes from: |
600 | 682 | ||
601 | ```Moonscript | 683 | ```Moonscript |
602 | with leaf | 684 | with leaf |
603 | .world 1,2,3 | 685 | .world 1,2,3 |
604 | 686 | ||
605 | with leaf | 687 | with leaf |
606 | g = .what.is.this | 688 | g = .what.is.this |
607 | print g | 689 | print g |
608 | 690 | ||
609 | for x in *something | 691 | for x in *something |
610 | print x | 692 | print x |
611 | ``` | 693 | ``` |
612 | 694 | ||
613 |   to: | 695 | to: |
614 | 696 | ||
615 | ```Lua | 697 | ```Lua |
616 | leaf.world(1, 2, 3) | 698 | leaf.world(1, 2, 3) |
617 | do | 699 | do |
618 | local g = leaf.what.is.this | 700 | local g = leaf.what.is.this |
619 | print(g) | 701 | print(g) |
620 | end | 702 | end |
621 | for _index_0 = 1, #something do | 703 | for _index_0 = 1, #something do |
622 | local x = something[_index_0] | 704 | local x = something[_index_0] |
623 | print(x) | 705 | print(x) |
624 | end | 706 | end |
625 | ``` | 707 | ``` |
626 | 708 | ||
627 |   instead of: | 709 | instead of: |
628 | 710 | ||
629 | ```lua | 711 | ```lua |
630 | do | 712 | do |
631 | local _with_0 = leaf | 713 | local _with_0 = leaf |
632 | _with_0.world(1, 2, 3) | 714 | _with_0.world(1, 2, 3) |
633 | end | 715 | end |
634 | do | 716 | do |
635 | local _with_0 = leaf | 717 | local _with_0 = leaf |
636 | local g = _with_0.what.is.this | 718 | local g = _with_0.what.is.this |
637 | end | 719 | end |
638 | local _list_0 = something | 720 | local _list_0 = something |
639 | for _index_0 = 1, #_list_0 do | 721 | for _index_0 = 1, #_list_0 do |
640 | local x = _list_0[_index_0] | 722 | local x = _list_0[_index_0] |
641 | print(x) | 723 | print(x) |
642 | end | 724 | end |
643 | ``` | 725 | ``` |
644 | 726 | ||
645 | 727 | ||
646 | 728 | ||