Re: Accessing PowerLoom from Haskell
Hans Chalupsky <[email protected]> Fri, 28 Aug 2015 10:31:19 -0700
| Newsgroups | gmane.comp.ai.powerloom |
|---|---|
| Message-ID | <[email protected]> |
On 08/28/2015 12:44 AM, Anders N=E5sell wrote:
> 1. Has PowerLoom a C API? I thought it only had C++? That is good news be=
cause my understanding is that Haskell is easier to interface with C than C=
++.
It doesn't have an official C API, but you can "easily" make one =
yourself. You basically create your own little C-API library using =
extern "C" declarations, compile that in C++ and then link it with your =
C program using the extern "C" names. For example,something like this =
should work (untested :-)
extern "C" void* pli_s_evaluate(char* command, char* moduleName);
void* pli_s_evaluate(char* command, char* moduleName) {
return pli::sEvaluate(command, moduleName, NULL);
}
extern "C" char* pli_s_evaluate_to_string(char* command, char* moduleName);
char* s_evaluate_to_string(char* command, char* moduleName) {
return pli::objectToString(sEvaluate(command, moduleName, NULL));
}
You can either do everything with strings or pass PowerLoom C++ pointers =
as void* and then cast them back where necessary. I think somebody has =
done this in the past to link PowerLoom into Python, but it's been a =
while and I don't remember if there were any issues. There could be =
some problems with all the C++ constructor initialization code being run =
when your C or Haskell program starts up, but that should be solvable.
Anyway, I am sorry this isn't better supported directly from PowerLoom =
(yet), it's one of the many things on the never ending TO DO list.
Hans