lua-users home
lua-l archive

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

It was thus said that the Great Steve Litt once stated:
> Hi all,
> I'm rewriting my UMENU program 
> ( in Lua, and so far so good. 
> So far, I see little reason to ever use Perl again :-)
> UMENU uses Perl's getopt_long. I've read all sorts of things about Lua's 
> Getopt facility, and so far it seems like yes, there's one in the standard 
> package, but some are saying it doesn't work all that well and a lot of people 
> are writing their own getopt facilities.
> Ideally, I'd like my Lua based UMENU to work with plain, ordinary, everyone 
> can install it Lua, rather than depending on special packages the user needs 
> to install, so if the one in the standard library works, that's what I'd like 
> to use. I could also just manually check for arguments -- there aren't that 
> many options to UMENU.
> So what are you all using for Getopt or preferably Getopt_long in Lua?

  I rolled my own and found it wasn't hard at all.  An example of usage:

require "org.conman.getopt"

options = {
  { 'I' , "index"    , false , function()  reindex = true end } ,
  { 'i' , "input"    , true  , function(f) input =,"r") end } ,
  { 'f' , "facility" , true  , function(f) set_syslog_facility(f) end } ,
  { 'd' , "debug"    , false , function()  debug = false end } 


First column---single letter option.
Second column---long option form
Third column---whether the option takes a parameter or not
Fourth column---function to handle the option

The code is pure Lua, and is avaiable upon request.

  -spc (It works for me)