summaryrefslogtreecommitdiff
path: root/Tools/LuaMacro/tests/test-do.lua
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-11-17 23:03:07 +0800
committerchai <chaifix@163.com>2021-11-17 23:03:07 +0800
commit27d6efb5f5a076f825fe2da1875e0cabaf02b4e7 (patch)
tree44f301110bc2ea742908ed92a78eba0803cd3b60 /Tools/LuaMacro/tests/test-do.lua
parentb34310c631989551054d456eb47aaab5ded266a4 (diff)
+ LuaMacro
Diffstat (limited to 'Tools/LuaMacro/tests/test-do.lua')
-rw-r--r--Tools/LuaMacro/tests/test-do.lua28
1 files changed, 28 insertions, 0 deletions
diff --git a/Tools/LuaMacro/tests/test-do.lua b/Tools/LuaMacro/tests/test-do.lua
new file mode 100644
index 0000000..7a8697c
--- /dev/null
+++ b/Tools/LuaMacro/tests/test-do.lua
@@ -0,0 +1,28 @@
+require_ 'macro.do'
+-- unrolling a loop
+y = 0
+do_( i,1, 10,
+ y = y + i
+)
+assert(y == 55)
+
+-- do_ defined a _local_ macro 'i'
+assert(i == nil)
+
+
+-- tuples usually expand to A_1,A_2,A_3 and so forth
+tuple(3) A,B
+B = 10,20,30
+print(B)
+
+def_ do3(v,s) do_(v,1,3,s)
+
+-- but inside a do_ statements with tuples work element-wise
+-- debug_
+do_(k,1,3,
+ A = B/2
+)
+--[[
+print(A)
+--]]
+