[racket] C++ Extensions and Classes

From: Cody Eilar (cody.eilar at gmail.com)
Date: Thu Feb 6 16:56:20 EST 2014

I understand that, the issue is that I have to provide three functions that
are not static so that I can make my c++ code known to scheme. Those
functions are:

scheme_reload(Scheme_Env *env)
scheme_initialize(Scheme_Env *env)
scheme_module_name()

Each one of these functions are known to the linker. Inside the Foo_ext.cpp
file, I have these three functions implemented. But in order to use
Bar_ext.cpp I have to implement them as well, which means I have multiple
declarations to the same function. So my Bar_ext.cpp file would
Ideally look something like this:

Bar_ext.cpp
scheme_reload(Scheme_Env *env)
{
 /* Bar _ext reload stuff */
    Foo_ext.scheme_reload(env)
}

Currently, the only way I see to solve this is to use a bunch of ifdefs,
but I was curious if there was a more elegant solution.

Thanks!

On Thu, Feb 6, 2014 at 2:48 AM, David T. Pierson <dtp at mindstory.com> wrote:

> On Wed, Feb 05, 2014 at 02:16:54PM -1000, Cody Eilar wrote:
> > > 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() /*}
>
> Disclaimer: I know nothing about Racket extensions.
>
> In C++, if you want to be able to call a function from multiple .cpp
> files, you typically put the *declaration* in a header:
>
>   void func1_ext(void);
>
> The definition would still go in a .cpp file:
>
>   void func1_ext(void)
>   {
>     /*...*/
>   }
>
> You typically only put the definition in a header if you want to make an
> inline function.  It doesn't seem like you want an inline function here.
>
> Does that help?
>
> David
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140206/8483aee2/attachment.html>

Posted on the users mailing list.