diff options
| author | Li Jin <dragon-fly@qq.com> | 2022-07-07 16:22:17 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2022-07-07 16:22:17 +0800 |
| commit | 1eb9ed57de854aa996614b7016bac04a68105389 (patch) | |
| tree | 27b46d4a5482ac0ab542d18548c0691aa8115d93 | |
| parent | b26b0c3e7061cd629500994e26fa162ac2668373 (diff) | |
| download | yuescript-1eb9ed57de854aa996614b7016bac04a68105389.tar.gz yuescript-1eb9ed57de854aa996614b7016bac04a68105389.tar.bz2 yuescript-1eb9ed57de854aa996614b7016bac04a68105389.zip | |
add spec.
Diffstat (limited to '')
| -rw-r--r-- | spec/inputs/macro-export.yue | 14 | ||||
| -rw-r--r-- | spec/inputs/macro.yue | 10 | ||||
| -rw-r--r-- | spec/outputs/macro.lua | 21 |
3 files changed, 44 insertions, 1 deletions
diff --git a/spec/inputs/macro-export.yue b/spec/inputs/macro-export.yue index 22ef424..46cc608 100644 --- a/spec/inputs/macro-export.yue +++ b/spec/inputs/macro-export.yue | |||
| @@ -32,6 +32,20 @@ export macro assert = (cond)-> | |||
| 32 | else | 32 | else |
| 33 | "#{cond}" | 33 | "#{cond}" |
| 34 | 34 | ||
| 35 | export macro copy = (src, dst, ...)-> | ||
| 36 | assert( | ||
| 37 | src != "_src_" and src != "_dst_" and dst != "_src_" and dst != "_dst_" | ||
| 38 | "copy targets can not be _src_ or _dst_" | ||
| 39 | ) | ||
| 40 | " | ||
| 41 | do | ||
| 42 | local _src_, _dst_ | ||
| 43 | with _dst_ = #{dst} | ||
| 44 | with _src_ = #{src} | ||
| 45 | #{table.concat (for field in *{...} | ||
| 46 | " _dst_.#{field} = _src_.#{field}"), "\n"} | ||
| 47 | " | ||
| 48 | |||
| 35 | $ -> | 49 | $ -> |
| 36 | global debugMode = true | 50 | global debugMode = true |
| 37 | global debugMacro = true | 51 | global debugMacro = true |
diff --git a/spec/inputs/macro.yue b/spec/inputs/macro.yue index e391b9e..e4b0fc8 100644 --- a/spec/inputs/macro.yue +++ b/spec/inputs/macro.yue | |||
| @@ -24,6 +24,16 @@ if $and f1! | |||
| 24 | if $and f1!, f2!, f3! | 24 | if $and f1!, f2!, f3! |
| 25 | print "OK" | 25 | print "OK" |
| 26 | 26 | ||
| 27 | item = $copy( | ||
| 28 | @ | ||
| 29 | {pos: {}, flags: flags::tonumber!} | ||
| 30 | id | ||
| 31 | connections | ||
| 32 | pos.x | ||
| 33 | pos.y | ||
| 34 | pos.z | ||
| 35 | ) | ||
| 36 | |||
| 27 | macro in = (target, ...)-> | 37 | macro in = (target, ...)-> |
| 28 | values = [value for value in *{...}] | 38 | values = [value for value in *{...}] |
| 29 | $showMacro "in", table.concat ["#{target} == #{item}" for item in *values], " or " | 39 | $showMacro "in", table.concat ["#{target} == #{item}" for item in *values], " or " |
diff --git a/spec/outputs/macro.lua b/spec/outputs/macro.lua index b3085bb..5917f43 100644 --- a/spec/outputs/macro.lua +++ b/spec/outputs/macro.lua | |||
| @@ -6,6 +6,25 @@ end | |||
| 6 | if (f1() and f2() and f3()) then | 6 | if (f1() and f2() and f3()) then |
| 7 | print("OK") | 7 | print("OK") |
| 8 | end | 8 | end |
| 9 | local item | ||
| 10 | do | ||
| 11 | local _src_, _dst_ | ||
| 12 | do | ||
| 13 | _dst_ = { | ||
| 14 | pos = { }, | ||
| 15 | flags = flags:tonumber() | ||
| 16 | } | ||
| 17 | do | ||
| 18 | _src_ = self | ||
| 19 | _dst_.id = _src_.id | ||
| 20 | _dst_.connections = _src_.connections | ||
| 21 | _dst_.pos.x = _src_.pos.x | ||
| 22 | _dst_.pos.y = _src_.pos.y | ||
| 23 | _dst_.pos.z = _src_.pos.z | ||
| 24 | end | ||
| 25 | item = _dst_ | ||
| 26 | end | ||
| 27 | end | ||
| 9 | if (x == "Apple" or x == "Pig" or x == "Dog") then | 28 | if (x == "Apple" or x == "Pig" or x == "Dog") then |
| 10 | print("exist") | 29 | print("exist") |
| 11 | end | 30 | end |
| @@ -258,7 +277,7 @@ print((setmetatable({ | |||
| 258 | return 998 | 277 | return 998 |
| 259 | end | 278 | end |
| 260 | })) | 279 | })) |
| 261 | print("current line: " .. tostring(261)); | 280 | print("current line: " .. tostring(271)); |
| 262 | -- TODO | 281 | -- TODO |
| 263 | do | 282 | do |
| 264 | print(1) | 283 | print(1) |
