[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: read only variables
- From: Julien Hamaide <julien.hamaide@...>
- Date: Thu, 31 Aug 2006 14:36:38 +0200
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
You can achieve this type of behavior by defining __newindex function in
the meta table of global environment.
In this function, you can achieve filtering such as
readonly_vars ={}
readonly_vars.myvar = true;
function metatable.__newindex(table, key, value)
if readonly_vars[ key ] != true then
rawset( table, key, value )
else
error( "Read only vars can't be written" )
end
if you try to do this :
myvar = "test";
it will fail.
Julien
Christopher Lux wrote:
> Hi,
> i looking for a way to to achieve read only variables at least for my
> own defined global variables. I found a way for lua 4.0 with
> lua_settagmethod but this way does not work anymore with lua 5.x. So is
> there a way to get this kind of functionality?
>
> -chris
> --Christopher Lux |
> | Bauhaus University Weimar
> | Faculty of Media - Virtual Reality Systems Group
>
>
- --
- --
Julien Hamaide
Engineering Coach
10Tacle Studios Belgium / Elsewhere Entertainment
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFE9tfW/nbvGx8yYLARAsT0AJ0R9mHyhixmkSaxnxS5vKQU0tHAeACfXlW5
9Fz38BOV6mZ+o4BD2S3LIcI=
=uxbq
-----END PGP SIGNATURE-----