summaryrefslogtreecommitdiff
path: root/Tools/LuaMacro/tests/test-list.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-list.lua
parentb34310c631989551054d456eb47aaab5ded266a4 (diff)
+ LuaMacro
Diffstat (limited to 'Tools/LuaMacro/tests/test-list.lua')
-rw-r--r--Tools/LuaMacro/tests/test-list.lua36
1 files changed, 36 insertions, 0 deletions
diff --git a/Tools/LuaMacro/tests/test-list.lua b/Tools/LuaMacro/tests/test-list.lua
new file mode 100644
index 0000000..f175ccc
--- /dev/null
+++ b/Tools/LuaMacro/tests/test-list.lua
@@ -0,0 +1,36 @@
+--- sugar for making pl.List work like Python lists.
+-- The list macro is a factory which generates macros which 'shadow' the variable
+-- and kick in when they are followed by [...].
+require_ 'list'
+
+-- the two forms of 'list' initialization
+-- (altho it grabs values upto '\n', this only happens outside a () or {},
+-- so multi-line initializations are possible
+list ls,lo = {10,20,30},{'A','ay',
+ 'B','C'}
+list two
+
+-- the above statements created both the macros 'ls' and values 'ls', etc.
+two:append(1)
+two:append(2)
+
+-- seen as plain table access
+print(ls[2])
+
+-- special treatment for slice notation
+print(ls[1:2])
+
+-- if we are on the LHS, then adjust accordingly
+ls[1:2] = {11,21,22}
+
+print(ls[2:])
+
+print(ls, two, lo)
+
+-- like in Python, this makes a copy of all of the list
+print(ls[:])
+
+
+
+
+