/zoeplat

To get this branch, use:
bzr branch http://9ix.org/bzr/zoeplat

« back to all changes in this revision

Viewing changes to getopt_alt.lua

  • Committer: Josh C
  • Date: 2013-03-02 20:40:57 UTC
  • Revision ID: josh@9ix.org-20130302204057-yrra0a51zgtpq2v2
zoetrope 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
 
3
 
function getopt( arg, options )
4
 
  local tab = {}
5
 
  for k, v in ipairs(arg) do
6
 
    if string.sub( v, 1, 2) == "--" then
7
 
      local x = string.find( v, "=", 1, true )
8
 
      if x then tab[ string.sub( v, 3, x-1 ) ] = string.sub( v, x+1 )
9
 
      else      tab[ string.sub( v, 3 ) ] = true
10
 
      end
11
 
    elseif string.sub( v, 1, 1 ) == "-" then
12
 
      local y = 2
13
 
      local l = string.len(v)
14
 
      local jopt
15
 
      while ( y <= l ) do
16
 
        jopt = string.sub( v, y, y )
17
 
        if string.find( options, jopt, 1, true ) then
18
 
          if y < l then
19
 
            tab[ jopt ] = string.sub( v, y+1 )
20
 
            y = l
21
 
          else
22
 
            tab[ jopt ] = arg[ k + 1 ]
23
 
          end
24
 
        else
25
 
          tab[ jopt ] = true
26
 
        end
27
 
        y = y + 1
28
 
      end
29
 
    end
30
 
  end
31
 
  return tab
32
 
end
 
 
b'\\ No newline at end of file'