lua-users home
lua-l archive

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

On 16/01/11 10:12, Axel Kittenberger wrote:
> * Its easy enough to create similar functionality with Lua code.

See line 1452 and down here:

That's the standard logic I use for all my apps. It handles short
options (-h), long options (--help), options with arguments (-ofoo and
--output foo), and non-option arguments anywhere.

The main code that makes it all work is at line 1584 and is 30 lines
long, so it's hardly worth turning into a library.

It doesn't handle --output=foo arguments and glued-together short
options (as in tar -xvzf), but could probably be made to without much
effort; I never use these, so didn't feel any urge to scratch that
particular itch.

The only bit of the code that's possibly not clear from reading is that
each handler function gets passed a potential option argument, and
returns 0 or 1 whether it was consumed or not.

┌─── ───── ─────
│ "I have a mind like a steel trap. It's rusty and full of dead mice."
│ --- Anonymous, on rasfc

Attachment: signature.asc
Description: OpenPGP digital signature