Hello,
I don't quite understand your problem, but one thing to note is that a
function like
void my_vala_func(int[] arr)
{
...
}
in Vala translates to something like
void my_c_func(int[] arr, int arr_length)
{
...
}
in C. Note that there's an extra argument to the function: this is the
length of the array. Vala passes this implicitly (as a property of the
array object), but in C it needs to be passed explicitly (since C arrays
don't track their own length). That's why the extra argument is showing up
in the generated C code.
If your code won't compile, perhaps you could provide the specific error
messages that the compiler outputs?
- Kerrick
On Sun, May 27, 2012 at 6:30 PM, Дмитрий Петров <[email protected]> wrote:
> Hello everyone,
>
> I'm very new to vala and my current task is to build an application
> using webkit-gtk component. One thing that I can't deal with is
> how valac translates the arrays, that should be passed to the function.
>
> As an example: I need to define a javascript function that will return
> an js array object:
>
> public static JSCore.Value js_read_dir (Context ctx,
> JSCore.Object function,
> JSCore.Object thisObject,
> JSCore.Value[] arguments,
> out JSCore.Value exception) {
>
> JSCore.Value[] dirs = {};
> dirs += new JSCore.Value.string( ctx, new
> String.with_utf8_c_string ("a") );
> dirs += new JSCore.Value.string( ctx, new
> String.with_utf8_c_string ("b") );
> JSCore.Value err = new JSCore.Value.null( ctx );
>
> return new JSCore.Object.array( ctx, 2, dirs, out err);
> }
>
> Here is the method definition from the vapi file:
> [CCode (cname = "JSObjectMakeArray")]
> public Object.array (Context ctx, size_t argument_count,
> JSCore.Value[] arguments,
> out JSCore.Value exception);
>
> Everything seems ok to me, but valac adds an additional argument to
> the method call
> for some reason and this prevents the code from compiling. Here is how
> the generated
> call looks like:
>
> _tmp9_ = JSObjectMakeArray (_tmp8_, (gsize) 2, dirs, dirs_length1, &err);
>
> As you can see, there is an extra argument - dir_length1, which
> doesn't exist neither in
> bindings nor in vala code. I've searched for some examples and the
> only thing I've found
> was that people construct json strings, evaluate them and get
> the objects they need from evaluation.
>
> So, where am I wrong? How can I fix my code to use standard bindings?
>
> --
> Kind regards, Dmitry Petrov
> _______________________________________________
> vala-list mailing list
> [email protected]
> https://mail.gnome.org/mailman/listinfo/vala-list
>
_______________________________________________
vala-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/vala-list