diff options
| author | dvs1 | 2024-10-24 12:32:42 +1000 |
|---|---|---|
| committer | dvs1 | 2024-10-24 12:32:42 +1000 |
| commit | ef1287e5437b236fbd0aacb987d403f31f1214c5 (patch) | |
| tree | 5f519106df3d5c8d2f66e897b46ae156f5d4e742 | |
| parent | If espeak has something to say, it should just speak it. (diff) | |
| download | JackOnAllDevices-ef1287e5437b236fbd0aacb987d403f31f1214c5.zip JackOnAllDevices-ef1287e5437b236fbd0aacb987d403f31f1214c5.tar.gz JackOnAllDevices-ef1287e5437b236fbd0aacb987d403f31f1214c5.tar.bz2 JackOnAllDevices-ef1287e5437b236fbd0aacb987d403f31f1214c5.tar.xz | |
Introducing PolygLua, writing Lua in any language.
Basically include a script written in any script language, as a string
in your Lua code, then call it from your Lua code.
| -rwxr-xr-x | _.lua | 25 |
1 files changed, 22 insertions, 3 deletions
| @@ -1,5 +1,10 @@ | |||
| 1 | #!/usr/bin/env luajit | 1 | #!/usr/bin/env luajit |
| 2 | 2 | ||
| 3 | --[[ | ||
| 4 | |||
| 5 | TODO - 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. |
| 5 | local _ = {} | 10 | local _ = {} |
| @@ -79,7 +84,7 @@ _.readCmd = function(cmd) | |||
| 79 | end | 84 | end |
| 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 | ||
