lua-users home
lua-l archive

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

Hash: SHA1

Aleksey Cheusov wrote:
> Most applications written in C use system getopt(3) or getopt_long(3)
> and therefore follow these guidelines. These guidelines show how
> applications usually work, not only standardized `cat', `cut', `grep'
> etc. and I think apps written in Lua shell follow these rules too
> _by default_ just like all C application. Unfortunately I don't see
> such module for Lua.

I have most of a long-options-processor written in pure Lua that I use
in most of my applications. It doesn't do -- and it takes a few
shortcuts, but it handles long options, short options, "-x VALUE",
"-xVALUE", and "--x VALUE", and non-option arguments, and is probably
about 100 lines of code. It's not a standalone module but could be
easily made so, and is BSD licensed. If you want it, look at line 129
onwards of:

The do_() functions are called to process an argument, and return the
number of arguments consumed (0 or 1). argmap contains the mapping of
option names to functions. Non-option arguments are handled at the
bottom of the main loop. It's all quite crude, but should be easy to
modify to meet your requirements.

Also, happy Hogmanay.

- --
David Given
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla -