lua-users home
lua-l archive

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


A general observation:

An optimizing implementation of Lua could do variable liveness analysis and reuse stack slots, resulting in the following:

function f(x)
  print(x)
  local y = g() -- this overwrites x, making it collectable
  print(y)
end

I have seen this behavior in compiled languages that use a garbage collector, the compiler translates the code into static single assignment form, and 'x' is considered dead once its value is passed to 'print', so the GC no longer traces it and 'x' disappears. 

PUC's Lua interpreter does not do this but a different implementation (JIT-based?) may well. Assuming the object is reachable until the function returns is hazardous to your health 😕