lua-users home
lua-l archive

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

Hi Steve,

Is there a way to do it for shared upvalues? Just compile all the
functions that share those upvalues together? Is there a way to detect
that upvalues are shared?

  local up = 0
  function plus()
    up = up + 1
    print("plus", up)
  -- local up = 0
  function minus()
    up = up - 1
    print("minus", up)

What if these upvalues have the same name, but refer to different
variables (as happens if you uncomment the commented line)?

It seems like this may be possible, but is likely to require some
source code parsing/analysis.


On Thu, Jul 26, 2012 at 10:05 PM, steve donovan
<> wrote:
> On Thu, Jul 26, 2012 at 10:21 PM, Pierre-Yves Gérardy <> wrote:
>> Does that approach handle mutable upvalues?
> Yes, but slowly, since some metamethod/debug magic is needed to set
> them.  For immutables, it's much easier.
> local boo = 1
> local M = {}
> ...
> function return boo end
> ..
> OK, so to recompile we wrap it so:
> local _v = ...; local boo, M =,_v.M
> function return boo end
> and pass this chunk a table extracted from the values of its current upvalues.
> It can't of course acquire new upvalues without a complete
> recompilation of the module. That's fast enough, true, but the issue
> here is preserving module state as long as possible.
> steve d.