[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Global variable __index and __newindex?
- From: julien.hamaide@...
- Date: Wed, 29 Aug 2007 21:46:22 +0200 (CEST)
> I need a way to provide an __index and __newindex method for global
> variables. Is there an easy way to go about this?
> What I mean is that if I have a variable (call it Foo) when I use it I
> it to call readers and writers in my source code instead. I know I can
> overwrite the default global handlers but that seems a bit of the wrong
> "Help I suffer from the oxymoron Corporate Security."
you can call lua_setmetatable with LUA_GLOBALSINDEX as stack index, it
will set the metable for the global table. Just set the __index and
__newindex field as usual to the metatable and it should call your method
when accessing globals