lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Fri, Feb 26, 2010 at 4:36 PM, Peter Cawley <lua@corsix.org> wrote:
> 3) Inspect which upvalues are used in the resulting function, and use
> debug.upvaluejoin to convert these faux upvalues in resulting function
> into the real ones you identified in the call stack.

That's a very cool possibility!

The tricky bit however is identifying the locals. After a module is
compiled (and 'run') its locals are only accessible through the
upvalues of its functions.

module 'upvals'
local x,y = 10,20

function one() return x end

function two() return y end

Say we want to recompile 'one' later so that it returns x+y; we have
to look at the upvalues of all of the other module functions to find a
reference - in this case y can be accessed through 'two'.

This shows a limitation of any incremental compilation scheme: only
locals which are so captured can be used - otherwise they are
unreferenced and just die.  Still, within these limitations (another
is that one can't introduce a new module local) the possibilities are
very exciting.

steve d.