]> git.kaiwu.me - klib.git/commitdiff
bugfix in os.getopt(): "-" not recognized
authorHeng Li <lh3@live.co.uk>
Mon, 2 May 2011 02:53:07 +0000 (22:53 -0400)
committerHeng Li <lh3@live.co.uk>
Mon, 2 May 2011 02:53:07 +0000 (22:53 -0400)
lua/klib.lua

index d5181c56f5fc369ff7cc735aeacac1c845ab4375..bfe52f7f7591b60bf09ceffab93e7da195d7b428 100644 (file)
@@ -72,14 +72,16 @@ function os.getopt(args, ostr)
        local arg, place = nil, 0;
        return function ()
                if place == 0 then -- update scanning pointer
-                       if #args == 0 or args[1]:sub(1, 1) ~= '-' then return nil end
+                       place = 1
+                       if #args == 0 or args[1]:sub(1, 1) ~= '-' then place = 0; return nil end
                        if #args[1] >= 2 then
+                               place = place + 1
                                if args[1]:sub(2, 2) == '-' then -- found "--"
+                                       place = 0
                                        table.remove(args, 1);
                                        return nil;
                                end
                        end
-                       place = 2
                end
                local optopt = args[1]:sub(place, place);
                place = place + 1;