[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Setting caller scope locals or upvalues
- From: Roberto Ierusalimschy <roberto@...>
- Date: Tue, 14 Feb 2023 14:59:21 -0300
> As far as I know, it’s not possible to add(create) a new upvalue for a lua function already been compiled.
>
> [...]
>
> > 2. Is there any way to create a new upvalue from C side on the caller using C api?
> No. You can only modify(or maybe delete) an existing upvalue.
>
> > 3. In case (1) and (2) are impossible, is it due to some security or limitation on generated bytecode of the function once it is interpreted by Lua?
> I am not sure. There are many way to turn the upvalue list to a dynamic list. Maybe someone could answer this question?
The real issue is deeper. The names of both upvalues and local variables
are bound during compilation, not during runtime. (They are compiled
into indices.) If they do not exist during compilation, it is impossible
to create code to access them. Even if you could create them later,
during runtime (e.g., reallocating a closure to add a new upvalue to
it), there would be no Lua code to use them.
-- Roberto