lua-users home
lua-l archive

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

I'm of the opinion of that if you have an already working, simple
solution, why bother with another?  Of course, others might have ideas
of how a userdata might be better, but I certainly can't think of a
good reason.

If you're thinking indirection, a closure has the function call, yes,
but userdata has a tag lookup + function call.  A closure is looking
more and more the best solution to me.


On Dec 13, 2007 6:28 PM, Eric Tetz <> wrote:
> I've got a library that returns a callable object:
>   foo = import("some", "configuration", "parameters", "here")
>   ...
>   foo("user", "args", "here")
> There are no C resources associated with 'foo' that need to be
> allocated/released, and the only thing a user can do with this object
> is call it, so I can just as easily implement 'foo' as a C closure or
> as userdata with a __call metamethod. Is there a reason to prefer one
> approach over the other?
> Currently I'm using a closure because it seems simpler. The sample
> code I looked at for doing it with metatables seemed a lot more
> complicated.
> Thanks,
> Eric