How do I return a C array of strings to be used in Vala code?

I'm using Vala to create a Linux app.

To parse JSON, I want to use C, because Vala library is complicated for me and, and it is able to run C functions. The function should return an array of strings that will be used inside Vala code.

The main problem is that unlike Vala, C does not really know what is an array of strings is. I found that the array of strings can be declared as a char*[].

I tried to:

I've made an assumption that char*[] in C, and char*[] in Vala, work differently.

Upvotes: 0

Views: 103

Answers (1)

nemequ
nemequ

Reputation: 17522

It depends on the what you want do; Vala is actually quite flexible in how it binds to C APIs since it was designed to be used with C APIs which don't know anything about Vala.

My suggestion would be to write the API you want in Vala, then use valac -C foo.vala to transpile the Vala to C code, where you can easily see the API it expects. Basically, though, for a Vala API like string[] foo(), the expected C signature would be something like gchar** foo(gint* array_length).

Upvotes: 0

Related Questions