From 31566d68cb3365ead1cdc8648c81d62ce966cb6f Mon Sep 17 00:00:00 2001 From: dvs1 Date: Fri, 25 Oct 2024 09:38:35 +1000 Subject: Just discovered the arg variable, use it and rename parseArgs() to just parse(). --- _.lua | 6 +++--- aataaj.lua | 9 ++++----- test_.lua | 10 +++++++--- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/_.lua b/_.lua index 88100aa..390d6d1 100755 --- a/_.lua +++ b/_.lua @@ -24,7 +24,7 @@ E = function(s) print('ERROR ' .. s); io.flush() end C = function(s) print('CRITICAL ' .. s); io.flush() end -_.parseArgs = function(options, args) +_.parse = function(args, options) --[[ TODO - use this for config files as well. An optional argument, the base config file name to look for. In this order, with later ones overriding earlier ones - defaults from the options table @@ -34,7 +34,7 @@ _.parseArgs = function(options, args) ]] local o = nil if 0 ~= #args then - for i,a in pairs(args) do + for i,a in ipairs(args) do local s, e = a:find("=") if nil == s then e = 0 end opt = a:sub(1, e - 1) @@ -51,7 +51,7 @@ _.parseArgs = function(options, args) for k, v in pairs(options) do h = h .. k .. ' | ' end - print('Usage: aataaj.lua {' .. string.sub(h, 1, -2) .. '}') + print('Usage: ' .. args[0] .. ' {' .. string.sub(h, 1, -2) .. '}') os.exit(0) end end diff --git a/aataaj.lua b/aataaj.lua index 06077c2..6108dd5 100755 --- a/aataaj.lua +++ b/aataaj.lua @@ -143,8 +143,7 @@ local options = ['--help'] = {help}, } -local args = {...} -_.parseArgs(options, args) +_.parse(arg, options) @@ -184,7 +183,7 @@ for i,l in ipairs(cards.lines) do Cards[l]['devs'][n] = n print("\tFound playback device " .. Cards[l].card - 1 .. " : " .. Cards[l]['name'] .. "\tDEVICE: " .. Cards[l]['playbackDevs'][j] .. ' ' .. n) io.flush() - if 'JACK' ~= args[1] then + 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 .. '"') io.flush() end @@ -221,7 +220,7 @@ print('') io.flush() -if 'start' == args[1] then +if 'start' == arg[1] then __('mkdir -p ' .. asoundrcPath):Do() local a, e = io.open(asoundrcPath .. '/jack-plumbing', "w") if nil == a then print("Could not open " .. asoundrcPath .. '/jack-plumbing') else @@ -391,7 +390,7 @@ pcm.!default { ]]) a:close() end -elseif 'JACK' == args[1] then +elseif 'JACK' == arg[1] then print('') print("Start up JACK and friends.") print("jack_control") diff --git a/test_.lua b/test_.lua index e4448d2..d29a433 100755 --- a/test_.lua +++ b/test_.lua @@ -55,8 +55,7 @@ local options = ['--help'] = {help}, } -local args = {...} -_.parseArgs(options, args) +_.parse(arg, options) @@ -137,7 +136,12 @@ print(__'command NoSuchCommand':log():show():Do().status) --__'qpdfview':forkOnce() --__'qpdfview':forkOnce() +print('') + +for i,a in ipairs(arg) do print('arg[' .. i .. '] = ' .. a) end +print('') +for k,a in pairs(arg) do print('arg[' .. k .. '] = ' .. a) end __'date':log():show():Do() __'date; sleep 5; date':log():show():Do() -print('') + -- cgit v1.1