lua-users home
lua-l archive

Closure or Userdata?

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


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

AltStyle によって変換されたページ (->オリジナル) /