by SomeCallMeTim · 13y ago · 0 comments
Not NEARLY as cool of an implementation as implementing TCP using ASCII art, but there's a command-line option parser that parses the help text to determine the command line options. [1] For example:
-- scale.lua
require 'lapp'
local args = lapp [[
Does some calculations
-o,--offset (default 0.0) Offset to add to scaled number
-s,--scale (number) Scaling factor
<number> (number ) Number to be scaled
]]
print(args.offset + args.scale * args.number)
[1] http://lua-users.org/wiki/LappFramework[1] http://www.inf.puc-rio.br/~roberto/lpeg/ [3]
[2] http://kernel.org/pub/software/scm/git/docs/git-fast-import....
[3] I actually use the re module [4] as I find the results more readable, and only use the LPeg module when I need something that the re module can't provide.
lapp has been around for four years; docopt is (looking at git commits) less than a year old. It strikes me as a natural way to do things in Lua, which is why (I suspect) it was done in Lua earlier.
One thing that positively impressed me were coroutines though. You can do some very interesting DSL things with it.