lua-users home
lua-l archive

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


> 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
> want
> 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
> way.
>
> --
> Jeremy
>
> "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

Julien Hamaide