Upvalues question

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Upvalues question

Dibyendu Majumdar
I hadn't realized that when an upvalue is created, it is recursively
created up the tree of functions until the function defining the local
variable is reached. I am not sure of the question I am asking ... I
was wondering whether upvalues have function scope, i.e. each function
has a list of unique upvalues where each upvalue is identified by name
only.

Hope the question makes sense.

Regards
Dibyendu

Reply | Threaded
Open this post in threaded view
|

Re: Upvalues question

Dibyendu Majumdar
On Sun, 24 Mar 2019 at 20:58, Dibyendu Majumdar <[hidden email]> wrote:
>
> I hadn't realized that when an upvalue is created, it is recursively
> created up the tree of functions until the function defining the local
> variable is reached. I am not sure of the question I am asking ... I
> was wondering whether upvalues have function scope, i.e. each function
> has a list of unique upvalues where each upvalue is identified by name
> only.
>
> Hope the question makes sense.

I believe this is referred to as 'flat closure' in 'The Implementation
of Lua 5.0'. I didn't realize what this actually means until recently.

Reply | Threaded
Open this post in threaded view
|

Re: Upvalues question

Dirk Laurie-2
Op Ma. 25 Mrt. 2019 om 00:17 het Dibyendu Majumdar
<[hidden email]> geskryf:
> > I was wondering whether upvalues have function scope, i.e. each function
> > has a list of unique upvalues where each upvalue is identified by name
> > only.
> >
> > Hope the question makes sense.

The documentation of `debug.getupvalue (f, up)` says:

~~~~
This function returns the name and the value of the upvalue with index
up of the function f. The function returns nil if there is no upvalue
with the given index.

Variable names starting with '(' (open parenthesis) represent
variables with no known names (variables from chunks saved without
debug information).
~~~~

Thus indeed there is such a list, but it might no longer be available
at runtime.

You can see it with `luac -l -l myscript.lua`.