Re: [Vala] Manual VAPI writing
- From: Andrea Del Signore <sejerpz tin it>
- To: Harry Van Haaren <harryhaaren gmail com>
- Cc: vala-list gnome org
- Subject: Re: [Vala] Manual VAPI writing
- Date: Tue, 29 Jun 2010 20:48:43 +0200
On Tue, 2010-06-29 at 19:17 +0100, Harry Van Haaren wrote:
Hey all,
Hi Harry,
I'm attempting to learn how to write .vapi files manually. I've looked
trough
the Jack binding, the GTK+ binding and the sfml bindings.
Yet im stumped as to how to write a wrapper for the dead-simple function
(declared in a file called bindMe.h):
*int add (int a, int b)
{
return (a + b);
}*
In my attempt I've tried the following:
*[CCode (cheader_filename="bindMe.h")]
namespace Math
{
public class AddStuff
{
public AddStuff();
[CCode (cname="add")]
public static int add (int a, int b);
}
}*
if your intent is to bind ad use the add function your binding it's
quite right, but can be simpler:
[CCode (cheader_filename="bindMe.h")]
namespace Math
{
[CCode (cname="add")]
public static int add (int a, int b);
}
as you can see in Vala you don't need any class and you can declare a
static method even in a namespace. You can even omit the static since is
implicit, but I usually keep it.
And to see if the binding worked had a .vala file (test.vala) which contains
the following:
*int main()
{
var func = new Math.AddStuff();
return 0;
}*
This is wrong, or I haven't really understand what are you trying to
achieve.
Here it is what I think you want to do:
public static int main()
{
var func = Math.add(1,2);
return 0;
}
Hope somebody can help me learn how to write bindings,I'm eyeing up some
nice audio libraries.. ;-) -Harry
Hope this helps.
Regards,
Andrea
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]