[Vala] correct char ** binding
- From: Jan Spurny <JSpurny seznam cz>
- To: vala-list gnome org
- Subject: [Vala] correct char ** binding
- Date: Tue, 8 Mar 2011 17:09:06 +0100
Hi,
I'm writing vapi binding for our company's C library and I found one thing which I'm unable to solve:
Problem are with two functions:
void some_parser_setup(SomeParser *self, char *name, char **location);
void some_parser_run(SomeParser *self);
which are part of some parser and they work like this:
1) 'setup' is called several times and 'registers' names with locations for them
2) 'run' runs the parser and stores parsed "names" content into newly allocated "locations"
Example in C:
-------------------------------------------
...
char *a;
char *b;
some_parser_setup(x, "variable_a", &a);
some_parser_setup(x, "variable_b", &b);
...
some_parser_run(x);
printf("a = %s, b = %s\n", a, b);
free(a);
free(b);
...
-------------------------------------------
Now I made vapi file which looks a little like this:
-----------------------------------------
[Compact]
public class SomeParser {
...
public void setup(string name, char **location);
public void run();
...
}
-----------------------------------------
and I'm using it in vala this way:
-----------------------------------------
...
char *a = null;
x.setup("variable_a", &a);
x.run();
string a_str = a;
...
--------------------------------------
The problem is when I try to use "a" (convert it into a string in this case) - it gives the following error:
--------------------------------------
test_config.vala:70.20-70.24: error: Assignment: Cannot convert from `char*' to `string?'
string a_str = a;
^^^^^
-------------------------------------
When on the other way I try to access each character separately, this works just fine (and prints correct
values):
-------------------------------------
stderr.printf("a[0] = %c\n", a[0]);
stderr.printf("a[1] = %c\n", a[1]);
stderr.printf("a[2] = %c\n", a[2]);
stderr.printf("a[3] = %c\n", a[3]);
stderr.printf("a[4] = %c\n", a[4]);
-------------------------------------
So my question is: do I have wrong binding or am I just using it wrong?
Thank you all in advance for any help or suggestion.
Jan Spurny
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]