lua-users home
lua-l archive

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



On Aug 17, 2007, at 11:24, Stephen Kellett wrote:

I'd like to see the ability to actually get a class name for a class object. Currently when you query an object for its type (from C) you just get "Table", which is not very useful. Its much more useful to know that a "Weeble" object is possibly leaking (look there are 10,000 of the critters!) rather than noticing the Table count has increased by 10,000.

If your table happen to be a module of sort, then it will have a somewhat descriptive _NAME key, which could be used as a table type of sort.

For example:

local URL = require( 'URL' )
local anURL = URL( 'http://dev.alt.textdrive.com/browser/HTTP' )

print( Type( URL ), Type( anURL ) )

> URL URL

The 'Type' function being something along these lines:

local function Type( anObject )
    if type( anObject ) == 'table' then
return anObject._NAME or ( getmetatable( anObject ) or {} )._NAME
    end

    return type( anObject )
end