[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Let's talk about __call
- From: Sean Conner <sean@...>
- Date: Fri, 22 Jul 2016 11:30:54 -0400
It was thus said that the Great Peter Aronoff once stated:
> 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.
>
> So now a user can require the module as normal, but call split using the
> module alone. I didn’t do it at the time—I thought that it was too magic
> and unnecessary since it’s easy for a user to assign the method to whatever
> short name they like when they require the module.
>
> But now I’m curious: is this pattern common in other Lua modules? I don’t
> think I’ve seen it, but perhaps I haven’t seen enough.
I've done it for a few of my modules.
uuid = require "org.conman.uuid"
syslog = require "org.conman.syslog"
syslog.open("mydemo","local1")
id = uuid()
breakdown = uuid.breakout(id)
syslog('info',"id=%s version=%d",tostring(id),breakdown.version)
-spc