lua-users home
lua-l archive

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


My guess is that they would only be pooled if they share the same prototype, and do not use any upvalues, such as:

t = {}
for i = 1, 10 do
  t[i] = function() end
end

All entries would point to the same function since they share function definition (and prototype).
To make it find identical prototypes seems trickier, and is probably not worth the effort anyway.

On Tue, Jul 13, 2010 at 1:44 PM, Duncan Cross <duncan.cross@gmail.com> wrote:
On Tue, Jul 13, 2010 at 12:05 PM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
>> Actually, there has been a discussion to implement an optimization
>> that would make these two examples run identically.
>
> Lua 5.2 will have such optimization (thanks to a suggestion from ET).
>
> -- Roberto
>

Excellent to hear this confirmed. Out of curiosity, does it mean that
these "reusable" functions are globally pooled, a bit like strings, or
will it only apply to functions that came from exactly the same place?
For example:

 a = function()  return 5;  end
 b = function()  return 5;  end

...would a and b be the same, or different?

-Duncan