aboutsummaryrefslogtreecommitdiffstats
path: root/_.lua
diff options
context:
space:
mode:
Diffstat (limited to '_.lua')
-rwxr-xr-x_.lua25
1 files changed, 22 insertions, 3 deletions
diff --git a/_.lua b/_.lua
index 12d7461..e3e6a82 100755
--- a/_.lua
+++ b/_.lua
@@ -1,5 +1,10 @@
1#!/usr/bin/env luajit 1#!/usr/bin/env luajit
2 2
3--[[
4
5TODO - I should name this project PolygLua. Gluing things onto Lua, making it a polyglot language.
6
7]]
3 8
4-- Most of this _ stuff was copied from apt-panopticon. 9-- Most of this _ stuff was copied from apt-panopticon.
5local _ = {} 10local _ = {}
@@ -79,7 +84,7 @@ _.readCmd = function(cmd)
79end 84end
80 85
81__ = function(c) 86__ = function(c)
82 local exe = {status = 0, lines = {}, logging = false, showing = false, cmd = '', command = c} 87 local exe = {status = 0, lines = {}, logging = false, showing = false, cmd = '', command = c, isScript = false, script = ''}
83 local n = 0 88 local n = 0
84 89
85 exe.cmd = '{ ' 90 exe.cmd = '{ '
@@ -89,10 +94,16 @@ __ = function(c)
89 exe.cmd = exe.cmd .. l .. ' ; ' 94 exe.cmd = exe.cmd .. l .. ' ; '
90 end 95 end
91 elseif 'string' == type(c) then 96 elseif 'string' == type(c) then
97 exe.isScript = ('#!' == c:sub(1,2)) and (n == 0)
92 for l in string.gmatch(c, "\n*([^\n]+)\n*") do 98 for l in string.gmatch(c, "\n*([^\n]+)\n*") do
93 if '' ~= l then 99 if '' ~= l then
94 if ('#!' == l:sub(1,2)) and (n == 0) then 100 if exe.isScript then
95 -- TODO - should do something with this, not just run it as shell stuff. 101 if '' == exe.script then
102 exe.scriptFile = os.tmpname()
103 D('Creating temporary script file at ' .. exe.scriptFile)
104 exe.cmd = exe.cmd .. l:sub(3) .. ' ' .. exe.scriptFile .. ' ; '
105 end
106 exe.script = exe.script .. l .. '\n'
96 else 107 else
97 n = n + 1 108 n = n + 1
98 exe.cmd = exe.cmd .. l .. ' ; ' 109 exe.cmd = exe.cmd .. l .. ' ; '
@@ -100,6 +111,14 @@ __ = function(c)
100 end 111 end
101 end 112 end
102 end 113 end
114 if exe.isScript then
115 local a, e = io.open(exe.scriptFile, "w")
116 if nil == a then E("Could not open " .. exe.scriptFile) else
117 a:write(exe.script)
118 a:close()
119 end
120 exe.cmd = exe.cmd .. 'rm ' .. exe.scriptFile .. ' ; '
121 end
103 exe.cmd = exe.cmd .. ' } ' 122 exe.cmd = exe.cmd .. ' } '
104 if 1 == n then exe.cmd = c end 123 if 1 == n then exe.cmd = c end
105 124