lua-users home
lua-l archive

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

On Fri, 15 Jan 2010 16:30:40 -0500
Nevin Flanagan <> wrote:

> I can't offer an explanation (except that my understanding is that
> the "local" keyword always brings its names into scope, shadowing all
> previous uses of that name), but this behavior should be avoidable
> with code like
> 	local foo, bar, err;
> 	foo, err = make_foo()
> 	if not foo then return nil, err end
> 	bar, err = make_err()
> 	if not bar then return nil, err end

Quite.  This is precisely the type of code I'm trying to avoid.

> Another oddity of this particular processing gimmick is the ability
> to write lines like
> local _, _, _, _, test = someMultiReturnFunction()
> This actually creates four local variables named _, but only the last
> one will be accessible.

Indeed, and I think that the first three values of _ are lost and
leaked until the function exists.  This could be a problem if the
values are large and the function never exits.