[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua : Controlling scope
- From: lhf (Luiz Henrique de Figueiredo)
- Date: Mon, 20 Jul 1998 15:23:11 -0300
>From: Luc Van Den Borre <email@example.com>
>I suppose there's no way of having some static variables local to one file ?
>I.e. I would have two files that both have a variable called 'name' at the
>top, which can be used by all the functions in that file,
>but the variable has different values in different files...
You can declare local variables in to "top level":
function f() ... end
but you cannot use 'a' inside function bodies.
What you can do is to to use the *value* that 'a' has when 'f' is defined:
function f(x) return %a+x end
'%a' is called an upvalue.
So the value of 'a' is frozen to 102.3.
It's equivalent to having
function f(x) return 102.3+x end
except that it might be more readble.
Changes to 'a' after 'f' is defined do not affect 'f'.
>Just like in C...
Lua is not C :-)