lua-users home
lua-l archive

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


On Fri, Jul 22, 2016 at 5:57 AM, Patrick Donnelly <batrick@batbytes.com> wrote:
> For some slightly early "It's Friday" discussion, what do you use the
> __call metamethod for? Discuss your favorite hacks, strange problems
> solved, code golf hole-in-ones, etc.

I use __call to make interfaces for configuring objects using chained calls
and method calls, where both mutate the object and return it. E.g.

parser:option "-I" "--include"
   :description "Include locations."
   :count "*"
   :action "append"
   :init {"/usr/local/include", "/usr/include"}

For implementation see the first hundred lines or so of
argparse.lua (https://github.com/mpeterv/argparse/blob/master/src/argparse.lua),
some other methods of configuration are implemented there as well.

-- Peter