Thread overview |
---|
September 22, 2009 Bindings to C library. | ||||
---|---|---|---|---|
| ||||
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. |
September 22, 2009 Re: Bindings to C library. | ||||
---|---|---|---|---|
| ||||
Posted in reply to nikita | 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(); } |
September 22, 2009 Re: Bindings to C library. | ||||
---|---|---|---|---|
| ||||
Posted in reply to nikita | 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*);
|
September 22, 2009 Re: Bindings to C library. | ||||
---|---|---|---|---|
| ||||
Posted in reply to nikita | 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.
|
September 22, 2009 Re: Bindings to C library. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jeremie Pelletier | 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.
|
September 22, 2009 Re: Bindings to C library. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trass3r | 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.
|
Copyright © 1999-2021 by the D Language Foundation