« Return to Thread: C++/OCaml bindings and the C++ std namespace

Re: C++/OCaml bindings and the C++ std namespace

by wsfulton :: Rate this Message:

Reply to Author | View in Thread

Guillaume Yziquel wrote:

> Hello.
>
> I managed to bind an C++ library with Objective Caml. cf. below for the
> toploop.
>
> However, I needed to add a function converting a C char * to a C++
> std::string:
>
>> yziquel@seldon:~/svn/main/libmorfo-ocaml$ cat freeling.i
>> %module freeling
>> %{
>>
>> #include "freeling.h"
>>
>> std::string string_of_chars (char * c)
>> {
>>   std:string s (c);
>>   return s;
>> }
>>
>> %}
>>
>> class tokenizer {
>>    public:
>>        /// Constructor
>>        tokenizer(const std::string &);
>>
>>        /// tokenize string with default options
>>        std::list<word> tokenize(const std::string &);
>>        /// tokenize string with default options, tracking offset in given int param.
>>        std::list<word> tokenize(const std::string &, unsigned long &);
>> };
>>
>> std::string string_of_chars (char *);
>
> There doesn't seem to be a standard way to convert an OCaml string to a
> std::string. So I was wondering if there was a way to do something like
>
>> class std::string {
>>   public
>>     string(char *)
>> };
>
> Moreover, it seems to me that the OCaml support in Swig isn't very well
> suited for the needs of OCamlers. The Camlp4 syntax extension is
> something that I really do not like, and the binded code is pretty much
> typed in a way I dislike.
>
> What documentation should I start reading to modify or rewrite the OCaml
> plugin? Or, at least, to see what I could do?
>
Guillaume, the OCaml module has been neglected for a few years and it
has very few users. The generated code used to compile quite cleanly
with older versions of Ocaml, but not so now. Feel free to improve the
wrappers, I suggest you discuss the development of it on the swig-devel
mailing list. You might want to contact the original Ocaml developer Art
Yerkes, see the README file. The developer documentation is in the
Doc/Devel directory. Also see Doc/Manual/Extending.html.

William


------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

 « Return to Thread: C++/OCaml bindings and the C++ std namespace