lua-users home
lua-l archive

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


On Fri, Jan 15, 2010 at 4:02 PM, Rob Kendrick <rjek@rjek.com> wrote:
> Two questions:
>        1) Is there some reason I've missed why it is essential that
>           Lua behaves this way?

Consider:

local foo, err = make_foo()
if not foo then return nil, err end

local function bar () return foo, err end

local bar, err = make_err()
if not bar then return nil, err end

It's not essential that Lua behave that way but makes it easier when
the above happens.

>        2) Am I right in thinking that the value stored in the first err
>           will not be garbage collected until the scope containing both
>           errs is left?

That is correct. You can set each local to nil if those locals must
persist for some reason to allow GC to collect.

-- 
-Patrick Donnelly

"Let all men know thee, but no man know thee thoroughly: Men freely
ford that see the shallows."

- Benjamin Franklin