lua-users home
lua-l archive

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


Wherever you see "function", a closure is created. Otherwise you
wouldn't be able to set the environment of the resulting function
without affecting other functions.

On Mon, Jul 12, 2010 at 7:32 PM, Geoff Leyland
<geoff_leyland@fastmail.fm> wrote:
> Hi,
>
> Does
>
> function f()
>  return function() end
> end
>
> create a closure, or are closures only created if the inner function uses one of f's locals (or a local from an outer scope) as an upvalue?  I'd like to know if the above causes any more heap allocations than:
>
> local function g() end
> function f() return g end
>
> Cheers,
> Geoff