Re: equivilant of 'index' tag method for globals?
Steve Dekorte <dekorte <at> slip.net>
1998-12-01 19:24:34 GMT
On Tue, 1 Dec 1998, David Jeske wrote:
> I feel like I should be able to do this, but I can't see how to do it
> with the existing fallbacks. I want to have a tag method called when a
> global variable dosn't exist.
>
> I want to do this because I want to separate 'enum' types from the
> current global table, but I want them to have global scope. In the
> end, it will look something like this:
I think this will work:
settagmethod(tag(nil), "getglobal",
function (varname)
local value = gettable(rawgetglobal("enums"), varname)
if ( value ~= nil ) then return value end
return rawgetglobal(varname)
end )
I use this sort of thing to move Lua's primatives out of globals and
into a organized namespace.
---
Steve Dekorte