From 1eb9ed57de854aa996614b7016bac04a68105389 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 7 Jul 2022 16:22:17 +0800 Subject: add spec. --- spec/inputs/macro-export.yue | 14 ++++++++++++++ spec/inputs/macro.yue | 10 ++++++++++ spec/outputs/macro.lua | 21 ++++++++++++++++++++- 3 files changed, 44 insertions(+), 1 deletion(-) (limited to 'spec') 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)-> else "#{cond}" +export macro copy = (src, dst, ...)-> + assert( + src != "_src_" and src != "_dst_" and dst != "_src_" and dst != "_dst_" + "copy targets can not be _src_ or _dst_" + ) + " +do + local _src_, _dst_ + with _dst_ = #{dst} + with _src_ = #{src} +#{table.concat (for field in *{...} + " _dst_.#{field} = _src_.#{field}"), "\n"} +" + $ -> global debugMode = true 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! if $and f1!, f2!, f3! print "OK" +item = $copy( + @ + {pos: {}, flags: flags::tonumber!} + id + connections + pos.x + pos.y + pos.z +) + macro in = (target, ...)-> values = [value for value in *{...}] $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 if (f1() and f2() and f3()) then print("OK") end +local item +do + local _src_, _dst_ + do + _dst_ = { + pos = { }, + flags = flags:tonumber() + } + do + _src_ = self + _dst_.id = _src_.id + _dst_.connections = _src_.connections + _dst_.pos.x = _src_.pos.x + _dst_.pos.y = _src_.pos.y + _dst_.pos.z = _src_.pos.z + end + item = _dst_ + end +end if (x == "Apple" or x == "Pig" or x == "Dog") then print("exist") end @@ -258,7 +277,7 @@ print((setmetatable({ return 998 end })) -print("current line: " .. tostring(261)); +print("current line: " .. tostring(271)); -- TODO do print(1) -- cgit v1.2.3-55-g6feb