Identifying Image/Group Objects

I have memory management code which recurses through display groups and tables and removes objects with removeSelf and/or object = nil depending on their type.

I was having a hard time identifying display groups and images as type( object ) reports them both as tables.

What I did notice was that Corona added some indexed variables to group and image tables:

[lua]image[_class]
image[_proxy]
displaygroup[_proxy][/lua]

So now I have a function to check and return the type of object depending on it’s numChildren attribute for displaygroups and _class index key for images:

[lua]function checkType( object )

if type( object ) == “table” then – If it is a table then it could be a group or an image
if object.numChildren then return “group” – If it is a group
elseif object["_class"] then return “image” – If it is an image
else return “table” – If not group or image then it is a table
end
else
return type( object ) – Return standard type
end

end[/lua]

This works for the most part but I haven’t investigated what other Corona objects make use of the _class index that I’m using to identify image object types.

This seems like a convoluted way of doing it, is anyone aware of an easier method? [import]uid: 11393 topic_id: 6235 reply_id: 306235[/import]