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 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'PolygLua.lua') 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 -- cgit v1.1