summaryrefslogtreecommitdiff
path: root/Tools/LuaMacro/tests/dollar.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/LuaMacro/tests/dollar.lua')
-rw-r--r--Tools/LuaMacro/tests/dollar.lua22
1 files changed, 22 insertions, 0 deletions
diff --git a/Tools/LuaMacro/tests/dollar.lua b/Tools/LuaMacro/tests/dollar.lua
new file mode 100644
index 0000000..954416d
--- /dev/null
+++ b/Tools/LuaMacro/tests/dollar.lua
@@ -0,0 +1,22 @@
+local macro = require 'macro'
+
+macro.define('$',function(get)
+ local t,v = get()
+ if t == 'iden' then
+ return 'os.getenv("'..v..'")'
+ elseif t == '(' then
+ local rest = get:upto ')'
+ return 'eval("'..tostring(rest)..'")'
+ end
+end)
+
+return function()
+ return [[
+local function eval(cmd)
+ local f = io.popen(cmd,'r')
+ local res = f:read '*a'
+ f:close()
+ return res
+end
+]]
+end