[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [Suggestion] Passing upvalues to load()
- From: Tim Hill <drtimhill@...>
- Date: Tue, 6 Oct 2015 11:05:00 -0700
> On Oct 5, 2015, at 3:55 PM, Soni L. <firstname.lastname@example.org> wrote:
> I think load() should, in addition to _ENV, also take a list of upvalues, which are only used when loading bytecode.
> When loading bytecode _ENV is assumed to be the first upvalue, upvalue 0, so we just need to make it varargs for the other upvalues.
> This reduces the need for debug.upvaluejoin() (or w/e, setupvalue?) when loading bytecode.
> Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.
One caveat. In fact the assumption that _ENV is upvalue 0 (actually, they are numbered starting at 1 in the C API if I recall) is only valid if there is *only* one upvalue (which is always the case for compiled naked chunks). For “interior” functions that are extracted using something like string.dump(), the upvalue used for _ENV, if any, is arbitrarily assigned by the compiler (and not discoverable by examination of the bytecode).