[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Method dereferencing protection
- From: RLake@...
- Date: Fri, 15 Aug 2003 09:57:52 -0500
The : vs . calling convention in Lua does certainly bite you from time to
time. But it is hard to see a way of changing it which does not seriously
change the semantics of the language.
The problem is that <object.method> is a function. It might be a function
which expects a "self" argument or not, but it is in any case a
first-class object. So it is completely legitimate to do the following:
function map_method(object, method, ...)
local meth = object[method]
for i = 1, args.n do
There is no : whatsoever in the above example, but it is certainly
expected that the method would be a "self"-style method.
Unfortunately, this opens the possibility of applying a method to a
different object. Sometimes, of course, that is actually useful, as in the
case of calling a method from a superclass:
if keycode == META "b" then
Edgar Toernig, in his Sol, has an interesting approach, but it involves
completely changing the semantics of :-style calls.
I don't really have an answer, but it is an interesting problem.