[DGD]Calling CPP Functions from an Extension

Felix A. Croes felix at dworkin.nl
Wed Jan 17 17:20:59 CET 2001


"Michael J. Bacon" <mj.bacon at gte.net> wrote:


>[...]
> 	Anyway, I've been playing around with dgd1.2's extension capabilities.
> Very neat I must say.  For convoluted reasons I find myself needing to call
> C++ functions from an extension.  I realize I will be unable to directly
> access class objects or advanced C++ constructs from an extension, but I
> have devised a few functions which, in theory, should act as a layer between
> the C++ objects and methods and the procedural C calls any extension would
> make.  I wrote a simple extension to test this theory, and I'm glad I did,
> because I can't get things to link.

C and C++ need a special interface to work together.  You have to do
something like:

    extern "C" {

    # include "dgd_ext.h"

    }

    void this_is_the_cpp_function(DGD_FRAME_T f, int nargs, DGD_VALUE_T *retval)
    {
	// do something
    }

    extern "C" {

    void this_is_the_relay(DGD_FRAME_T f, int nargs, DGD_VALUE_T *retval)
    {
	this_is_the_cpp_function(f, nargs, retval);
    }

    }


You may actually be able to inline this_is_the_cpp_function into
this_is_the_relay; I think the `extern "C"' stuff only affects linkage.

Regards,
Dworkin

List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list