lua-users home
lua-l archive

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


My guess (not having looked at the C implementation) is that it's probably
easier to create a new closure on each call than work out that there's no
need in this particular case.

In general, you do need a different closure on each call, of course.

function a()
	local i = 0;
	return function () i = i + 1; return i; end
end
	

-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of King, Mike
Sent: 13 June 2006 16:23
To: Lua list
Subject: RE: Function Addresses?

Why would it be desired to have a new anonymous function created for
each call?

function a()
	return function () end
end

print(a())
print(a())

> a() is referring to the anonymous function "function return b() end"
which
> is different to both a and b