lua-users home
lua-l archive

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


On Tue, 13 Nov 2001, Max Ischenko wrote:

> I'm using the following function:
>
> function foobar()
> 	local s = ''
> 	-- lengthy computation and printing report to s
> 	local t = {text=s}
> 	function foobar()
> 		return %t.text
> 	end
> 	return s
> end
>
> The purpose of rewriting the function is to use value computed in the
> first call. It works just fine.

Just a small improvement: You do not need the table around "s". Your new
function could be simply function foobar() return %s end

(You only need the "trick" with a table if you were going to change "s"
after creating the new function.)



> The question -- will GC be able to freed old contents of the foobar?

Sure.

> Doesn't %t ref. disables it?

The "%t" only prevents the collection of table "t" itself.

-- Roberto