On Wed, Dec 3, 2014 at 9:26 AM, Nick Wellnhofer <[email protected]> wrote:
> With regard to the Perl bindings, this would also allow to use
> arbitrary Perl classes that don't inherit from Clownfish::Obj. So there's no
> need for inside-out instance variables which would be a big plus.
Awesome -- making it possible to use the full range of host OO options would be
a great improvement, and we should do everything we can to make that happen!
> I take the Analyzer class as an example.
You know, Analyzer doesn't even have any member variables. It's crying out to
be an interface.
>From C-space, we only need something we can invoke Clownfish-style methods on.
It's easy to generate a Clownfish wrapper around any kind of Perl object to
achieve that.
(Once you remove the requirement to duplicate the layout of inherited member
variables in memory, life gets easier.)
> public class HostTransformer extends Transformer {
> void *host_interface_obj; // SV* for Perl
> }
I think we need to tweak this idea for Go and other languages that may use
compacting garbage collection.
It is not valid to pass any Go data structure into C-space, so keeping a
reference in host_interface_obj is not possible. However, we could keep an
integer ID of some sort and use that to look up a host object in a Go-space
data structure.
> I'm probably missing some things but I wanted share my initial thoughts with
> the list.
I have to admit that I don't understand everything about the proposal. I
guess you need need a separate Transformer class because you want to exclude
concrete methods on Analyzer like Transform_Text()?
In any case, I hope that the eventual goal is to support stuff like this:
package DummyAnalyzer;
sub new { return bless {}, __PACKAGE__ }
sub transform {
my ($self, $batch) = @_;
return $batch;
}
sub dump { return { _class => __PACKAGE} }
sub load { return __PACKAGE__->new() }
package main;
my $type = Lucy::Plan::FullTextType->new(
analyzer => DummyAnalyzer->new,
);
Note that DummyAnalyzer...
* is implemented as a blessed hash
* does not have "Lucy::Analysis::Analyzer" in @ISA
* does not call SUPER::new
* does not implement DESTROY
Right now, if we supply DummyAnalyzer object as an argument to FullTextType's
constructor, we'll get an exception because DummyAnalyzer does not inherit
from Analyzer. But what we could do instead is wrap the blessed hash in a
Clownfish object which knows how to call back into Perl for each method.
Marvin Humphrey