[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Another puzzle for you all, with upvalues
- From: "Vincent PENQUERC'H" <vpenquerch@...>
- Date: Wed, 20 Oct 1999 17:24:43 +0200
That's me again (sorry):
In the following code, I can redefine print and still use its
original implementation, but this does not work for t.a, though
when the upvalue %t.a is used, the a field of the t table is
already set to the right function.
The result is an infinite recursion thru the redefined t.a, which
never calls the original implementation. This means that the value
of the upvalue is the new implementation, and not the previous one,
so I guess the value in t.a was not frozen before the new field was
replaced. Or something like that.
So, basically, it works with a global but not with a global's field.
Is that expected behavior too, or am I just trying to write so sick
and nasty code ?? :)
Here is the code:
--
function print(s)
%print("Message: "..s)
end
t={}
t.a = function(s)
print(s)
end
t.a = function(s)
print(s)
%t.a(s)
end
print("Hello, world") -- this one works
t.a("Hi, world") -- this one loops
--vp