diff options
Diffstat (limited to 'Tools/LuaMacro/tests/test-list.lua')
-rw-r--r-- | Tools/LuaMacro/tests/test-list.lua | 36 |
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[:]) + + + + + |