From 4edd85aa8156150f1fa7a3026a922b49366b642d Mon Sep 17 00:00:00 2001 From: dvs1 Date: Mon, 28 Oct 2024 10:30:16 +1000 Subject: Consistantly use single quotes for Lua strings, unless otherwise needed. Old habits die hard. lol --- PolygLua.lua | 38 ++++++++++++------------- aataaj.lua | 92 ++++++++++++++++++++++++++++++------------------------------ test_.lua | 12 ++++---- 3 files changed, 71 insertions(+), 71 deletions(-) diff --git a/PolygLua.lua b/PolygLua.lua index ed14fc5..ee775eb 100755 --- a/PolygLua.lua +++ b/PolygLua.lua @@ -2,7 +2,7 @@ --[[ PolygLua. Gluing things onto Lua, making it a polyglot language. -TODO - Make the parsing recursive. So the command "--fancy" could have it's own options table. +TODO - Make the parsing recursive. So the command '--fancy' could have it's own options table. --fancy option0 opt1=foo 'Random string!' --somethingElse When to stop and hand back? First time we see a ' -bar' or ' --foo'? @@ -23,8 +23,8 @@ _.version = '0.0 crap' _.verbosity = 2 local log = function(v, t, s) if v <= _.verbosity then - if 3 <= _.verbosity then t = os.date('!%F %T') .. " " .. t end - print(t .. ": " .. s) + if 3 <= _.verbosity then t = os.date('!%F %T') .. ' ' .. t end + print(t .. ': ' .. s) end io.flush() end @@ -106,7 +106,7 @@ _.parse = function(args, options, confFile) if nil ~= confFile then for i,v in ipairs{'/etc/', '~/.', './.'} do local p = v .. confFile .. '.conf.lua' - local h, e = io.open(p, "r") + local h, e = io.open(p, 'r') if nil ~= h then D('Found configuration file '.. p) h:close() @@ -124,7 +124,7 @@ _.parse = function(args, options, confFile) local ds = 0 if ('-' == a:sub(1, 1)) and ('-' ~= a:sub(2, 2)) then ds = 1 end if '--' == a:sub(1, 2) then ds = 2; a = a:sub(3, -1) end - local s, e = a:find("=") + local s, e = a:find('=') local k , v if nil == s then e = 0 @@ -154,11 +154,11 @@ _.runnable = function(c) end _.running = function(c) - return ( 1 ~= tonumber(__("pgrep -u $USER -cf " .. c):Do().lines[1]) ) + return ( 1 ~= tonumber(__('pgrep -u $USER -cf ' .. c):Do().lines[1]) ) end _.exists = function(f) - local h, e = io.open(f, "r") + local h, e = io.open(f, 'r') if nil == h then return false else h:close(); return true end end @@ -166,10 +166,10 @@ end _.killEmAll = function(all) for i,l in ipairs(all) do local c = 0 - while 0 ~= tonumber(__("pgrep -u $USER -xc " .. l):Do().lines[1]) do + while 0 ~= tonumber(__('pgrep -u $USER -xc ' .. l):Do().lines[1]) do local s = 'TERM' - if c > 1 then s = 'KILL'; __("sleep " .. c):Do() end - __("pkill -" .. s .. " -u $USER -x " .. l):log():Do() + if c > 1 then s = 'KILL'; __('sleep ' .. c):Do() end + __('pkill -' .. s .. ' -u $USER -x ' .. l):log():Do() c = c + 1 end end @@ -202,7 +202,7 @@ __ = function(c) end elseif 'string' == type(c) then exe.isScript = ('#!' == c:sub(1,2)) and (n == 0) - for l in string.gmatch(c, "\n*([^\n]+)\n*") do + for l in string.gmatch(c, '\n*([^\n]+)\n*') do if '' ~= l then if exe.isScript then if '' == exe.script then @@ -219,8 +219,8 @@ __ = function(c) end end if exe.isScript then - local a, e = io.open(exe.scriptFile, "w") - if nil == a then E("Could not open " .. exe.scriptFile) else + local a, e = io.open(exe.scriptFile, 'w') + if nil == a then E('Could not open ' .. exe.scriptFile) else a:write(exe.script) a:close() end @@ -241,7 +241,7 @@ __ = function(c) function exe:timeout(c) -- timeout returns a status of - command status if --preserve-status; "128+9" (actually 137) if --kill-after ends up being done; 124 if it had to TERM; command status if all went well. - -- --kill-after means "send KILL after TERM fails. + -- --kill-after means "send KILL after TERM fails". if nil == c then self.cmd = 'timeout --kill-after=10.0 --foreground 42.0s ' .. self.cmd else @@ -266,7 +266,7 @@ __ = function(c) from nil and false are considered true (in particular, the number 0 and the empty string are also true)." says the docs, I beg to differ.]] - if true == self.logging then D(" executing - " .. self.cmd) end + if true == self.logging then D(' executing - ' .. self.cmd) end --[[ Damn os.execute() Lua 5.1 says it returns "a status code, which is system-dependent" Lua 5.2 says it returns true/nil, "exit"/"signal", the status code. @@ -279,9 +279,9 @@ __ = function(c) self.lines[#self.lines] = nil if true == self.showing then for i, l in ipairs(self.lines) do I(l) end end - if (nil == self.status) then D("STATUS |" .. "NIL" .. '| ' .. self.command) - elseif (137 == self.status) or (124 == self.status) then T("timeout killed " .. self.status .. ' ' .. self.command) - elseif (0 ~= self.status) then D("STATUS |" .. self.status .. '| ' .. self.command) + if (nil == self.status) then D('STATUS |' .. 'NIL' .. '| ' .. self.command) + elseif (137 == self.status) or (124 == self.status) then T('timeout killed ' .. self.status .. ' ' .. self.command) + elseif (0 ~= self.status) then D('STATUS |' .. self.status .. '| ' .. self.command) end return self @@ -293,7 +293,7 @@ __ = function(c) if nil == after then after = '' end if '' ~= after then after = ' ; ' .. after end self.cmd = '{ ' .. self.cmd .. after .. ' ; } & ' - if true == self.logging then D(" forking - " .. self.cmd) end + if true == self.logging then D(' forking - ' .. self.cmd) end os.execute(self.cmd) return self end diff --git a/aataaj.lua b/aataaj.lua index 88eb346..5656427 100755 --- a/aataaj.lua +++ b/aataaj.lua @@ -116,8 +116,8 @@ local options = _.killEmAll{'jmcore', 'qjackctl'} -- Catia is python, and no easy way to kill it. -- Also it keeps jackdbus alive, no matter how hard you kill it. - __"pkill -TERM -u $USER -f catia":Do() - __"sleep 2":Do() + __'pkill -TERM -u $USER -f catia':Do() + __'sleep 2':Do() _.killEmAll{'jackdbus', 'a2jmidid'} os.exit(0) end @@ -145,24 +145,24 @@ local Cards = {} print('Scanning for audio devices.') local cards = __'ls -d1 /proc/asound/card[0-9]*':noErr():Do() for i,l in ipairs(cards.lines) do - local f, e = io.open(l .. '/id', "r") - if nil == f then print("Could not open " .. l .. '/id') else - Cards[l] = {path = l, name = f:read("*a"):sub(1, -2), devs = {}, captureDevs = {}, playbackDevs = {}, card=i} - if "Loopback" ~= Cards[l]['name'] then + local f, e = io.open(l .. '/id', 'r') + if nil == f then print('Could not open ' .. l .. '/id') else + Cards[l] = {path = l, name = f:read('*a'):sub(1, -2), devs = {}, captureDevs = {}, playbackDevs = {}, card=i} + if 'Loopback' ~= Cards[l]['name'] then Cards[l]['capture'] = __('ls -d1 ' .. l .. '/pcm[0-9]*c*'):noErr():Do() for j,c in ipairs(Cards[l]['capture'].lines) do - local n = c:match(".*pcm(%d+).*") + local n = c:match('.*pcm(%d+).*') Cards[l]['captureDevs'][j] = n Cards[l]['devs'][n] = n - print("\tFound capture device: " .. Cards[l]['name'] .. "\tDEVICE: " .. Cards[l]['captureDevs'][j] .. ' ' .. n) + print('\tFound capture device: ' .. Cards[l]['name'] .. '\tDEVICE: ' .. Cards[l]['captureDevs'][j] .. ' ' .. n) io.flush() end Cards[l]['playback'] = __('ls -d1 ' .. l .. '/pcm[0-9]*p*'):noErr():Do() for j,p in ipairs(Cards[l]['playback'].lines) do - local n = p:match(".*pcm(%d+).*") + local n = p:match('.*pcm(%d+).*') Cards[l]['playbackDevs'][j] = n Cards[l]['devs'][n] = n - print("\tFound playback device " .. Cards[l].card - 1 .. " : " .. Cards[l]['name'] .. "\tDEVICE: " .. Cards[l]['playbackDevs'][j] .. ' ' .. n) + print('\tFound playback device ' .. Cards[l].card - 1 .. ' : ' .. Cards[l]['name'] .. '\tDEVICE: ' .. Cards[l]['playbackDevs'][j] .. ' ' .. n) io.flush() if 'JACK' ~= arg[1] then print('\t\tALSA_CARD=' .. Cards[l].card - 1 .. ' ' .. speaker .. ' "Found playback device ' .. Cards[l].card - 1 .. ' : ' .. Cards[l]['name'] .. ' DEVICE: ' .. Cards[l]['playbackDevs'][j] .. ' ' .. n .. '"') @@ -203,8 +203,8 @@ io.flush() if 'start' == arg[1] then __('mkdir -p ' .. options.asoundrcPath.value):Do() - local a, e = io.open(options.asoundrcPath.value .. '/jack-plumbing', "w") - if nil == a then print("Could not open " .. options.asoundrcPath.value .. '/jack-plumbing') else + local a, e = io.open(options.asoundrcPath.value .. '/jack-plumbing', 'w') + if nil == a then print('Could not open ' .. options.asoundrcPath.value .. '/jack-plumbing') else a:write([[ (connect "system:capture_1" "ploop:playback_1") (connect "system:capture_2" "ploop:playback_2") @@ -218,20 +218,20 @@ if 'start' == arg[1] then ]]) a:close() end - local a, e = io.open(options.asoundrcPath.value .. '/' .. options.asoundrc.value, "w") - if nil == a then print("Could not open " .. options.asoundrcPath.value .. '/' .. options.asoundrc.value) else + local a, e = io.open(options.asoundrcPath.value .. '/' .. options.asoundrc.value, 'w') + if nil == a then print('Could not open ' .. options.asoundrcPath.value .. '/' .. options.asoundrc.value) else for i,C in pairs(Cards) do for j,c in pairs(C['devs']) do - a:write("pcm." .. C['name'] .. j .. " {\n") - a:write(" type hw\n") - a:write(" card " .. C['name'] .. "\n") - a:write(" device " .. C['devs'][j] .. "\n") - a:write("}\n") - a:write("ctl." .. C['name'] .. j .. " {\n") - a:write(" type hw\n") - a:write(" card " .. C['name'] .. "\n") - a:write(" device " .. C['devs'][j] .. "\n") - a:write("}\n\n") + a:write('pcm.' .. C['name'] .. j .. ' {\n') + a:write(' type hw\n') + a:write(' card ' .. C['name'] .. '\n') + a:write(' device ' .. C['devs'][j] .. '\n') + a:write('}\n') + a:write('ctl.' .. C['name'] .. j .. ' {\n') + a:write(' type hw\n') + a:write(' card ' .. C['name'] .. '\n') + a:write(' device ' .. C['devs'][j] .. '\n') + a:write('}\n\n') end end a:write([[ @@ -373,13 +373,13 @@ pcm.!default { end elseif 'JACK' == arg[1] then print('') - print("Start up JACK and friends.") - print("jack_control") + print('Start up JACK and friends.') + print('jack_control') __[[jack_control start jack_control ds alsa]]:Do() --jack_control dps device hw:RIG,0 while 0 ~= __'jack_control status':Do().status do - print("Waiting for JACK") + print('Waiting for JACK') __'sleep 1':Do() end if nil ~= GUI then @@ -387,7 +387,7 @@ elseif 'JACK' == arg[1] then __(GUI):forkOnce() end if _.runnable'jack-plumbing' then - print("jack-plumbing") + print('jack-plumbing') __'jack-plumbing -o /var/lib/aataaj/jack-plumbing 2>/dev/null':fork() end if _.runnable'a2j_control' then @@ -396,72 +396,72 @@ elseif 'JACK' == arg[1] then --a2j_control actually starts a2jmidid. ----a2jmidid -e -u & -- I think the jack_control start and my current alsa config means a2jmidid gets started anyway. But seem to need this bit to get the joystick covered. - print("a2j_control") + print('a2j_control') __'a2j_control --ehw && a2j_control --start':Do() --- print("sleep 2") +-- print('sleep 2') -- __('sleep 2'):Do() print("") end - local AIN = "alsa_in" + local AIN = 'alsa_in' if _.runnable'zita-a2j' then AIN = 'zita-a2j' end - local AOUT = "alsa_out" + local AOUT = 'alsa_out' if _.runnable'zita-j2a' then AOUT = 'zita-j2a' end - print("Basic ALSA sound devices converted to JACK.") + print('Basic ALSA sound devices converted to JACK.') for i,C in pairs(options.aliases.value) do print('HW playback: ' .. C['name'] .. '\tDEVICE: ' .. C['dev']) __(AOUT .. ' -j ' .. C['name'] .. ' -d ' .. C['dev']):fork() end - print("HW playback: cloop\tDEVICE: cloop") + print('HW playback: cloop\tDEVICE: cloop') -- No idea why, cloop wont work with zita-a2j. __'alsa_in -j cloop -d cloop':fork() --__[[sleep 1 -- jack_connect cloop:capture_1 system:playback_1o() -- jack_connect cloop:capture_2 system:playback_2]]:Do() - print("HW playback: ploop\tDEVICE: ploop") + print('HW playback: ploop\tDEVICE: ploop') __'alsa_out -j ploop -d ploop':fork() --__[[sleep 1 -- jack_connect system:capture_1 ploop:playback_1 -- jack_connect system:capture_2 ploop:playback_2]]:Do() - print("") + print('') - print("Rest of ALSA sound devices converted to JACK.") + print('Rest of ALSA sound devices converted to JACK.') for i,C in pairs(Cards) do for j,c in ipairs(C['playbackDevs']) do - print("HW playback: " .. C['name'] .. "\tDEVICE: " .. C['playbackDevs'][j]) - __(AOUT .. ' -j ' .. C['name'] .. "_" .. C['playbackDevs'][j] .. '-in -d ' .. C['name'] .. C['playbackDevs'][j]):fork() + print('HW playback: ' .. C['name'] .. '\tDEVICE: ' .. C['playbackDevs'][j]) + __(AOUT .. ' -j ' .. C['name'] .. '_' .. C['playbackDevs'][j] .. '-in -d ' .. C['name'] .. C['playbackDevs'][j]):fork() -- __'sleep 1':Do() -- __('jack_connect cloop:capture_1 ' .. C['name'] .. '_' .. C['playbackDevs'][j] .. '-in' .. ':playback_1'):Do() -- __('jack_connect cloop:capture_2 ' .. C['name'] .. '_' .. C['playbackDevs'][j] .. '-in' .. ':playback_2'):Do() end for j,c in ipairs(C['captureDevs']) do - print("HW capture: " .. C['name'] .. "\tDEVICE: " .. C['captureDevs'][j]) - __(AIN .. ' -j ' .. C['name'] .. "_" .. C['captureDevs'][j] .. '-out -d ' .. C['name'] .. C['captureDevs'][j]):fork() + print('HW capture: ' .. C['name'] .. '\tDEVICE: ' .. C['captureDevs'][j]) + __(AIN .. ' -j ' .. C['name'] .. '_' .. C['captureDevs'][j] .. '-out -d ' .. C['name'] .. C['captureDevs'][j]):fork() end end - print("") + print('') if _.runnable('aseqjoy') then - print("Scanning for joysticks.") + print('Scanning for joysticks.') local sticks = __'ls -1 /dev/input/js[0-9]*':noErr():Do() for i,l in ipairs(sticks.lines) do - print("aseqjoy " .. l) + print('aseqjoy ' .. l) -- Buttons switch to that numbered MIDI channel, defaults to 1. -- Axis are mapped to MIDI controllers 10 - 15 -- -r means to use high resolution MIDI values. __('aseqjoy -d ' .. l:sub(-1,-1) .. ' -r'):fork() end - print("") + print('') end if _.runnable('jack-plumbing') then print('Stop our jack-plumbing, eventually.') __'sleep 4':Do() - _.killEmAll{"jack-plumbing"} + _.killEmAll{'jack-plumbing'} end if _.runnable('~/.aataaj_JACK.lua') then diff --git a/test_.lua b/test_.lua index 452f4c9..a589a00 100755 --- a/test_.lua +++ b/test_.lua @@ -41,8 +41,8 @@ local options = _.killEmAll{'jmcore', 'qjackctl'} -- Catia is python, and no easy way to kill it. -- Also it keeps jackdbus alive, no matter how hard you kill it. - __"pkill -TERM -u $USER -f catia":Do() - __"sleep 2":Do() + __'pkill -TERM -u $USER -f catia':Do() + __'sleep 2':Do() _.killEmAll{'jackdbus', 'a2jmidid'} ]=] end @@ -51,10 +51,10 @@ local options = options['restart'] = options['start'] options['force-reload'] = options['start'] -print("start = " .. options.start.value) +print('start = ' .. options.start.value) _.parse(arg, options, 'test_') -print("start = " .. options.start.value) -print("stop = " .. options.stop.value) +print('start = ' .. options.start.value) +print('stop = ' .. options.stop.value) @@ -112,7 +112,7 @@ print(__[[#!/usr/bin/tcc -run print('') __[[#!/usr/bin/env luajit - print('Hello ' .. "world " .. [=[from]=] .. " Lua.") + print('Hello ' .. "world " .. [=[from]=] .. ' Lua.') ]]:log():show():Do() print('') -- cgit v1.1