On Apr 21, 2008, at 10:01 PM, Marvin Humphrey wrote:
Third... Say that you want to subclass not Scorer, but *TermScorer*,
and you try to override TermScorer_Get_Doc_Num() via the host-
language OO mechanism. The problem is that the function pointer in
TermScorer's VTable for Get_Doc_Num doesn't call back to the host
language -- so it never finds out that you've tried to override it.
You'll get the native override when invoking from the host language,
but not when invoking from within the library via the VTable.
I think I've come up with a solution, for Perl at least.
When creating the dynamic virtual table, we can iterate through a list
of the parent vtable's methods and discover whether the subclass
package defines a subroutine of the appropriate name. If it does,
then we can stuff a callback function into the vtable.
This assumes that no one will dynamically generate an overriding
function after the first time an object gets created. Should be safe,
methinks.
To pull this off, we'll need to generate callback functions for each
public method signature in the Lucy codebase. I'm thinking only public
methods primarily because not every C signature maps cleanly -- e.g.
signatures that include a function pointer as an argument.
It's not mandatory to implement this for languages other than Perl,
but obviously that would be best. I think the only thing which will
need to be host-specific is DynVT_list_overridden(CharBuf *klass).
Marvin Humphrey
Rectangular Research
http://www.rectangular.com/