On Mon, 2007-07-16 at 16:40 -0700, Raoul Duke wrote:
> hi,
> 
> I am a cat of little brain, and while I sorta am starting to grok what
> is going on with getting Felix to talk to C++, I'm still a little
> clueless and scared (it has been a while since I've done C++ which
> doesn't help). Might anybody happen to have a few simple examples I
> could look at, besides what is in the docs (or perhaps there are
> examples in the docs I've overlooked)? In particular, as an example,
> how would one interface with Foo below, to be able to "new" up
> instances, especially heap-based ones not just stack ones, and call
> the getId() routine? Many thanks for any pointers.

First make a binding like:

///////////// foobind.flx ///////////////////////
#import <flx.flxh>
header foo_h = '#include "Foo.h"';
type foo = "Foo*" requires foo_h, package "foo";
gen _ctor_foo: int -> foo = "new Foo($1)";
proc del: foo = "delete $1;";
fun getID: foo -> int = $1.getId()";
/////////////////////////////////////

With test code:
/////// foobar.flx /////////////////
#import <flx.flxh>
include "foobind";

proc flx_main()
{
  var hitch = foo(42);
  println$ getId foo;
}
//////////////////////////////////////

and put this config for Unix:

//// config/foo.fpc /////////////////
provides_dlib: -lfoo_dynamic
provides_slib: -lfoo_static
//////////////////////////////////////

Now you need to remove (or rename) the 'main'
function in Foo.cpp, then compile something like
(RTFM here .. ):

g++ -fPIC -shared -o rtl/foo_dynamic.so foo.cpp
g++ -o rtl/foo_static.o foo.cpp
ranlib -o rtl/foo_static.a rtl/foo_static.o


Now you can run the test:

flx foobar              # dynamic
flx --static foobar     # static

BTW: I didn't try this :)

> <!--Foo.h-->
> class Foo
> {
>  public:
>   Foo(int id);
>   ~Foo();
>   int getId();
> 
>  private:
>   int _id;
> };
> 
> <!--Foo.cpp-->
> #include <stdio.h>
> #include <stdlib.h>
> #include "Foo.h"
> 
> int main()
> {
>   Foo *foo = new Foo(42);
>   printf( "%d\n", foo->getId() );
> }
> 
> Foo::Foo(int id) :
>   _id(id)
> { }
> 
> Foo::~Foo()
> { }
> 
> int Foo::getId()
> {
>   return(_id);
> }
> 
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Felix-language mailing list
> Felix-language@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/felix-language
-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to