[racket-dev] C++ Extensions and Classes

From: Cody Eilar (cody.eilar at gmail.com)
Date: Wed Jan 22 02:57:10 EST 2014

Hi,

      This question may have been answered, but I couldn't find anything
useful. So I have been writing some racket extensions for some C++ classes
using the tutorial (http://docs.racket-lang.org/inside/overview.html)  on
the racket site and have been able to successfully load them into racket.
However I was wondering if I can use inheritance to reuse some code.

For example I have two classes that I have written in C++, Foo and Bar.

Class Foo looks like this:

Foo {
     func1() { /* ... do stuff */ }
}

Class Bar looks like this:

Bar : Foo {
     func2() { /*... do more stuff /*}
}

I've currently written a single .cpp racket extension that creates Bar and
creates the extensions for both func1() and func2(); however, I'd like to
create two racket extension classes. One extension that does only functions
inside Foo and then I just want to include Foo_ext.h (my racket extension
to Foo) in Bar_ext.h so I have access to all the functions.

So I currently have this:

Bar_ext.cpp:

func1_racket_ext() { /*... do racket stuff and run func1() */}

func2_racket_ext() {/* ... do more racket stuff and run func2() /*}

/* Scheme initializes etc... */



But what I really want is:

Foo_ext.h:

func1_racket_ext() { /*... do racket stuff and run func1() */}

/* Scheme initializes etc... */


Bar_ext.cpp:
#include "Foo_ext.h"

func2_racket_ext() {/* ... do more racket stuff and run func2() /*}

/* Scheme initializes etc... */


Is this even possible? I feel like namespace might be an issue. This would
be extremely useful for me because it would allow me to not write lots and
lots of redundant code since I have many classes that use class Foo as a
super class.

Any advice would be greatly appreciated and if you could point me to an
example (maybe there is something in the underlying racket code you can
point me to?)


Thanks again!

~Cody
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/dev/archive/attachments/20140121/8a88269c/attachment.html>

Posted on the dev mailing list.