lua-users home
lua-l archive

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


No you can't! Every function is defined within a scope that always has many visible variables in scope (and not just in its environment). Not removing the visible variables that are not used by the function from the set of upvalues to include in its new closure would be a strong error. And when this set of used variables becomes empty, it makes no sense at all to instanciate dynamically a new closure (function reference): it should be static and created once by the compiler.


Le lun. 12 août 2019 à 05:02, Kaj Eijlers <bizziboi@gmail.com> a écrit :
>> Moving functions out of a loop is not as simple as you think: the loop may not be visible at all and come from an invisible outer scope

If you are not depending on an upvalue you can always return a reference to function that is defined outside the scope that's returning it and thus return a the same version every time?