Bindings for Voce library

General help with the core C language of which eC is a superset, integrating eC with other languages such as C++ at the C level, using C libraries in eC, etc.
Post Reply
mothdragon
Posts: 28
Joined: Mon Jan 18, 2010 11:56 pm

Bindings for Voce library

Post by mothdragon »

I've found a library for Voice Synthesis and Voice Recognition called Voce. Unfortunately, the library is written natively in Java(yeuch!), however it does have wrappers for C++(Yay!) I'd like to be able to use this library in eC instead, (cuz eC rocks!), and was wondering how exactly do I go about writing a wrapper for the eC language. It seems to me that it should be a fairly straightforward thing to write an eC function to call the C++ function which in turn calls the Java function, but I have no idea how to begin looking into this at all. I've tried looking up how to right bindings on the net but didn't get anything particularly helpful...

There's not very many functions in the API for this library, so it really won't take long to do this once I know how...

After the wrapper/bindings are written, they could then be submitted to the people developing Voce to help them with expanding their project. They have it listed on their list of things to do, as port Voce to other languages, as many as possible, so that everyone can easily use it. If this is submitted to them, then this would also have the benefit of advertising eC out there in a group of people who may have previously been unaware of eC. I think that would be cool too. :D
--==[[ Mothdragon ]]==--
- - - - - - - - - - - - - - - - -
Everything New is Old, Everything Old is New. Nothing exists, and it's all here.
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: Bindings for Voce library

Post by jerome »

Hi Charlie,

As I mentioned on IRC, here's what you have to do:

The way to call C++ from eC right now...
1. you write C bindings with extern "C"
2. you write eC classes that call those C functions (optional)
ideally that would become an automated process in the future :) As part of this milestone


1. It's very simple, you write a C function that calls the C++ method, but it needs an extra 'this' parameter for the class objects (You write this in a .cpp file, that includes the Voce library C++ header file)

Code: Select all

extern "C" int MyClass_MyMethod(MyClass * this, int par1, char * par2)
{
   this->MyMethod(par1, par2);
}
2. and if you want to do the eC one you turn that back into OO: (You write this in a .ec file, with a prototype for the above function, 'default' is necessary if you are inside a defined eC namespace)

Code: Select all

default int MyClass_MyMethod(MyClass * this, int par1, char * par2);
 
class MyClass
{
   int MyMethod(int par1, char * par2)
   {
      return MyClass_MyMethod(this, par1, par2);
   }
}
mothdragon
Posts: 28
Joined: Mon Jan 18, 2010 11:56 pm

Re: Bindings for Voce library

Post by mothdragon »

So does this need to get compiled as library? Or is this just a file that gets imported into the project?
--==[[ Mothdragon ]]==--
- - - - - - - - - - - - - - - - -
Everything New is Old, Everything Old is New. Nothing exists, and it's all here.
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: Bindings for Voce library

Post by jerome »

Both these files ( the .cpp and .ec file ) can be packaged in whatever way you want.

You could e.g. bundle them together with a static library from the library you're wrapping around (if you're so lucky to have such a static library) into one shared library (.dll/.so), and then the user would simply do e.g. import "voce".

You can also simply put them all into your application project, and link in the third-party library from there.

-Jerome
Post Reply