[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua5.0 new "For" question
- From: Björn De Meyer <bjorn.demeyer@...>
- Date: Sun, 22 Dec 2002 20:58:26 +0100
Peter Hill wrote:
> itten in lua 5 ...
> My mistake. I remeber reading something about them no longer being used but
> that may have been something on the mailing list a while ago.
> They have changed nature, though. I just tried:
> local x=123
> f = function() return %x end
> Lua4.0 returns 123 as expected, while Lua5.0 doesn't even get past the
> definition of "f". It says "global upvalues are obsolete". I need to look
> more closely at the new upvalues.
AFAICS, the meraning of the word "upvalue" has completely
changed. Now, it simply refers to the "hidden parameters"
you can give a C function when you register it for use with Lua.
you can still say
f = function() return %x end
But that one seems to behave exactly the same as when not
using the %, namely it will print 456. Because of the
lexical scoping the x in the anonymous function is the
local x of fie(). The value of x is only "taken"
when f() is called.
To do what you want to do, I think you'll need to make
a little "detour".
return (function() return val; end);
f = makef(x) -- here x is passed by value and dereferenced
fie() will now print 123.
"No one knows true heroes, for they speak not of their greatness." --
Björn De Meyer