[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Closure or Userdata?
- From: Ben <thebassplayer@...>
- Date: Thu, 13 Dec 2007 18:35:16 -0800
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
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 <email@example.com> 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