lua-users home
lua-l archive

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


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