lua-users home
lua-l archive

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


Hi,

in my application, my intention is to let the user create and destroy
the global variables as he wishes. Still, I want to have a few global
variables that will be protected from deleting (i.e., assigning nil to
them would throw an error) and I want them to act as properties (i.e.,
updating the screen (a 3D scene) in case their values have been
changed). After reading PIL 5.1, I have a pretty clear idea how to do
it:

1. Create a new Lua state,
2. keep the _G environment empty (don't load the standard libraries at
this point),
3. create _G's metatable and redefine __index() and __newindex() to
catch the access to my protected variables,
4. forward access and assignments to all other (user-created)
variables to some proxy table,
5. load the standard libraries.

My question is - is this manipulation of _G safe with regard to the
standard libraries? Don't they access the global table in some special
ways I should be aware of? Is it OK to load them only after the access
being forwarded to the proxy?

Thanks in advance,

- Peter