Call a C++ .dll in Croquet?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Call a C++ .dll in Croquet?

Jeff VanDrimmelen
Hey All!

I just joined the listserv, so I apologize if this has been discussed before, perhaps you can point me to a thread I can look at.  Anyway, I am working on writing an interface between the Novint Falcon ( http://home.novint.com/) haptic device and croquet.  I think I have the C++ side worked out, but I am new to Squeak.  Is there a way to call a C++ function in smalltalk?  I can't imagine I am the first to want to do this. :) 

Eventually I am also going to need to figure out the functions that smalltalks uses to move avatars around in Croquet as well.  Any pointers as I dive into this project?  Any other advise for a newbie? :) 

Thanks!  I look forward to contributing to this great project!  I saw the demonstration at UNC in July earlier this year and have been really excited about it ever since.  If you have any desire here is a short article I wrote about why Croquet is better than Second Life ( http://www.edutechie.com/2007/07/7-ways-croquet-is-better-than-second-life/).  Here's to hoping we can make it live up to it's potential. :)

~Jeff

--
Jeff VanDrimmelen
Academic Computing Expert
University of North Carolina at Chapel Hill
Reply | Threaded
Open this post in threaded view
|

Re: Call a C++ .dll in Croquet?

Andreas.Raab
Hi Jeff -

[Note that I'm assuming that you are a proficient C/C++ programmer. If
you are not, the explanation may not be too helpful]

You can call C++ Dlls just like you would call any other Dlls, by using
the foreign function interface. It is best utilized with functions that
take simple arguments (int, float, char, string) and not complex data
types (structs and classes). Have a look at the FFI examples for your
platform which show the basics of how to use it.

There is one major difference when using C++ though, and that is
name-mangling. Since name-mangling is not standardized (or at least
wasn't the last time I checked), there is no support for automatically
mangling the name of a C++ call, and you will need to use the mangled
name in the declaration. Since this is a major pain, it is often useful
to build a set of C wrapper functions (using extern "C" declarations)
that simply call the C++ function instead. Something like:

extern "C" {
   Foo* newFoo(int arg);
}

Foo* newFoo(int arg) {
   return (void*) new Foo(arg);
}

etc. Then you would use it like here:

Foo class>>new
   "Create a new instance of Foo"
   <cdecl: Foo* 'newFoo'(long) module: 'FooDll.dll'>
   ^self externalCallFailed

Oh, and the other twiddle is that calling virtual member functions is a
pain, pain, pain. If you have to do this, you will be much better off
with having a few wrappers that you compile in C.

Cheers,
   - Andreas

Jeff VanDrimmelen wrote:

> Hey All!
>
> I just joined the listserv, so I apologize if this has been discussed
> before, perhaps you can point me to a thread I can look at.  Anyway, I
> am working on writing an interface between the Novint Falcon (
> http://home.novint.com/) haptic device and croquet.  I think I have the
> C++ side worked out, but I am new to Squeak.  Is there a way to call a
> C++ function in smalltalk?  I can't imagine I am the first to want to do
> this. :)
>
> Eventually I am also going to need to figure out the functions that
> smalltalks uses to move avatars around in Croquet as well.  Any pointers
> as I dive into this project?  Any other advise for a newbie? :)
>
> Thanks!  I look forward to contributing to this great project!  I saw
> the demonstration at UNC in July earlier this year and have been really
> excited about it ever since.  If you have any desire here is a short
> article I wrote about why Croquet is better than Second Life (
> http://www.edutechie.com/2007/07/7-ways-croquet-is-better-than-second-life/).  
> Here's to hoping we can make it live up to it's potential. :)
>
> ~Jeff
>
> --
> Jeff VanDrimmelen
> Academic Computing Expert
> University of North Carolina at Chapel Hill
> * * <http://oasis.unc.edu/remedy>**