www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Bindings to C library.

reply nikita <nikita thenews.kz> writes:
Hello.
I've started to learn D and now I'm trying to create a binding for libenca, but
 how do i translate the statement below?
| const char**  enca_get_languages         (size_t *n);

Citation from Enca's library reference manual:
| Returns list of known languages.
| The returned strings are two-letter ISO-639 language codes, the same as
enca_analyser_alloc() accepts.
| The list of languages has to be freed by caller; the strings themselves must
be considered constant and must NOT be freed.
|     n :             The number of languages will be stored here.
|     Returns : The list of languages, storing their number into *n.
Sep 21 2009
parent reply nikita <nikita thenews.kz> writes:
A-argh! Sorry, it's my inattention :)
All was very simple. Interface to c library:
extern(C)
    char** enca_get_languages(uint*);

and in main module (i'm using tango.stdc.stringz):
    uint nb_lang;
    char** row = enca_get_languages(&nb_lang);

    for (uint y = 0; y < nb_lang; y++) {
        Stdout(fromStringz(row[y])).newline();
    }
Sep 22 2009
next sibling parent reply Jeremie Pelletier <jeremiep gmail.com> writes:
nikita wrote:
 A-argh! Sorry, it's my inattention :)
 All was very simple. Interface to c library:
 extern(C)
     char** enca_get_languages(uint*);
 
 and in main module (i'm using tango.stdc.stringz):
     uint nb_lang;
     char** row = enca_get_languages(&nb_lang);
 
     for (uint y = 0; y < nb_lang; y++) {
         Stdout(fromStringz(row[y])).newline();
     }
If you are using D2, it should be: extern(C) const(char**) enca_get_languages(size_t*);
Sep 22 2009
parent nikita <nikita thenews.kz> writes:
Jeremie Pelletier Wrote:

 If you are using D2, it should be:
 
 extern(C) const(char**) enca_get_languages(size_t*);
I'm using D1, but anyway thanks for help.
Sep 22 2009
prev sibling parent reply Trass3r <mrmocool gmx.de> writes:
nikita schrieb:
 extern(C)
     char** enca_get_languages(uint*);
size_t is defined in Object.d, so it's better to use it for 64Bit compatibility.
Sep 22 2009
parent nikita <nikita thenews.kz> writes:
Trass3r Wrote:

 nikita schrieb:
 extern(C)
     char** enca_get_languages(uint*);
size_t is defined in Object.d, so it's better to use it for 64Bit compatibility.
Oh, big thanks! I didn't know that.
Sep 22 2009