lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello

I was contemplating a small lua exercise, a program for listing my currently vim'ed files a'la

local s,e,c,r,line,file,modified,pid,running
local fd = io.popen("sh -c 'vi -r 2>&1'", "r")

while (line = fd:read("*line")) do
      ^^^^^^
   if s,e,c = string.find(line, "^ *file name: ([%w%p]*)") then
      ^^^^^^^^
       file = c
   elseif s,e,c = string.find(line, "^ *modified: (%a*)") then
          ^^^^^^^^
       modified = c ~= "no"
   elseif s,e,c,r = string.find(line, "^ *process ID: (%d*)(.*)") then
          ^^^^^^^^^
       pid = c
       running = string.find(r, "(still running)", 1, true) ~= nil

       if file && modified then
           io.write(string.format("%d %8d%s %s", modified and 1 or 0,
                                  pid, running and "*" or " ", file)
       end
       file = nil
       running = nil
   end
end
fd:close()


Obviously this will not work, since assignments are not expressions in lua,
nor is there any way of embedding assignment in expressions

Is there an easy way around this that i missed. Is this even a candidate for the FAQ


Best /Flemming*
*