lua-users home
lua-l archive

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


Good point. Slightly more expensive (a push and a hash lookup rather than an
indexing) but much more general.

Mark

on 7/26/04 9:13 AM, Jamie Webb at j@jmawebb.cjb.net wrote:

> On Mon, Jul 26, 2004 at 08:17:20AM -0700, Mark Hamburg wrote:
>> If you can live with single-inheritance, my scheme using indices in the
>> metatable will work with the type-testing technique used in Oberon. Single
>> inheritance allows us to know that a class is at a particular depth in the
>> inheritance tree. The metatable for a class can then include the appropriate
>> light userdata for each class in its inheritance hierarchy. Testing for
>> class membership then becomes something like:
>> 
>>     luaObj.metatable[ classInfo->depth ] == classInfo
> 
> You can do something rather similar that works with multiple
> inheritance by checking something like:
> 
> luaObj.metatable[ pushlightuserdata(classInfo) ] == true
> 
> -- Jamie Webb