lua-users home
lua-l archive

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


On Mon, Nov 30, 2009 at 6:12 AM, spir <denis.spir@free.fr> wrote:
> x = 1
> function f()
>  n = 1
>  function g(a)
>    print (x + n + a)
>  end
>  return g
> end
>
> g= f()
> g(1)    --> 3
>
> x = 2
> g(1)    --> 4

I believe you meant to use locals here:

local x = 1
function f()
 local n = 1
 function g(a)
   print (x + n + a)
 end
 return g
end

?

-- 
-Patrick Donnelly

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

- Benjamin Franklin