Paul Dixon
2012-Mar-20 11:16 UTC
[Xapian-discuss] Writing a MatchDecider and exposing it to PHP
I would like to write a MatchDecider in C++ and expose it to PHP. I'm able to compile a simple extension and use SWIG to expose a simple function to PHP, but I can't seem to hit upon the right incantation to expose my MatchDecider class. I have a header file declaring my decider, MyDecider.h #ifndef _INC_MYDECIDER_H #define?_INC_MYDECIDER_H #include <xapian/enquire.h> #include <xapian/types.h> class MyDecider : public Xapian::MatchDecider { Xapian::valueno valuenum; bool inclusive; public: MyDecider??(Xapian::valueno slot, bool inclusive_) : valuenum(slot), inclusive(inclusive_) { } bool operator()(const Xapian::Document& doc) const; }; #endif I have a very simple SWIG interface file, MyDecider.i %module mydecider %{ extern int demo_function(int x); #include <xapian.h> #include "mydecider.h" %} extern int demo_function(int x); #include <xapian.h> #include "mydecider.h" This successfully exports my 'demo_function' to PHP, but not the MyDecider class ($d=new MyDecider fails with a class not found error) I'm sure I'm doing something wrong in my SWIG interface file, but I'm very new to it...clues welcomed!
Paul Dixon
2012-Mar-20 12:02 UTC
[Xapian-discuss] Writing a MatchDecider and exposing it to PHP
Just to follow up on earlier message - I was able to get somewhere with this as my interface file %{ #include "/usr/include/xapian/enquire.h" #include "mydecider.h" %} #include "/usr/include/xapian/enquire.h" %include "mydecider.h" This created a 'proxy' PHP class, but isn't there some way to make my class a 'real' PHP class?
Olly Betts
2012-Mar-23 01:45 UTC
[Xapian-discuss] Writing a MatchDecider and exposing it to PHP
On Tue, Mar 20, 2012 at 11:16:42AM +0000, Paul Dixon wrote:> I would like to write a MatchDecider in C++ and expose it to PHP. > > I'm able to compile a simple extension and use SWIG to expose a simple > function to PHP, but I can't seem to hit upon the right incantation to > expose my MatchDecider class.I've not tried it myself, but I believe SWIG does support wrapping an extension which builds on another extension like this.> #include <xapian/enquire.h> > #include <xapian/types.h>Just include <xapian.h> in user code - the other headers are an implementation detail and might get renamed, merged, split, etc. On Tue, Mar 20, 2012 at 12:02:44PM +0000, Paul Dixon wrote:> Just to follow up on earlier message - I was able to get somewhere > with this as my interface file[...]> %include "mydecider.h"Yes, SWIG doesn't parse included files by default, and the %include tells it to.> This created a 'proxy' PHP class, but isn't there some way to make my > class a 'real' PHP class?I'm not sure I understand what you mean. You are wanting a class which wraps a C++ class, which is what a 'proxy' class is - a PHP class which forwards its methods to a C++ class, Cheers, Olly