lua-users home
lua-l archive

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


David Given wrote:
(Incidentally, while putting closures into the table does allow you to call methods using . --- which is a very neat trick, BTW, I'd never thought of doing it like that --- it does mean that you can't get hold of a generic method pointer. I've just written some code that does this:
Yes, you can.
If you get the instance method, you really get the closure, not the real method. But if you get the class method, this is the real method, no wrapper.

object = class()
function object.method(self)
    print(self, 'object.method')
end

o=object()
m1 = o.method -- instance method, get the wrapper
m2 = object.method -- class method, get the real one
m1()
m2()
m2(o)

(or do I miss something?)

--
()_() | Always keep the Titanic in mind when I talk        | +----
(o.o) | about security or safety, meaning that nothin      | +---+
'm m' | is fully secure.                                   |  O  |
(___) |              raffaele punto salmaso presso libero punto it
GPG fingerprint 1CF5 51D4 E528 EB87 9977  B277 BE8C BF1E 620C 40ED