Re: [Vala] Converting library by hand
- From: Frederik <scumm_fredo gmx net>
- To: vala-list <vala-list gnome org>
- Subject: Re: [Vala] Converting library by hand
- Date: Sat, 16 May 2009 17:30:09 +0200
Nicolas wrote:
Hi,
Thank you very much to answer me !
Ok, i will try to port this library by hand.
So can you give me an example to convert some kind of code for vapi file.
First:
typedef enum de_crossover_t
{
GA_DE_CROSSOVER_UNKNOWN = 0,
GA_DE_CROSSOVER_BINOMIAL = 1,
GA_DE_CROSSOVER_EXPONENTIAL = 2
} ga_de_crossover_type;
Second:
GAULFUNC population *ga_population_new( const int stable_size,
const int num_chromosome,
const int len_chromosome);
Third:
GAULFUNC boolean ga_seed_boolean_random(population *pop, entity *adam);
Thank you in advance.
Nicolas.
You could start with this 'gaul.vapi'. (attachment)
There are two alternatives for 'ga_seed_boolean_random': you can bind it
either as static function or as instance method of class 'Population'.
All classes are [Compact], because they are non-GObject types.
While writing a vapi file by hand it is helpful to look at the generated
C code of a test program that uses the newly added functions:
$ valac gaultest.vala --pkg gaul --vapidir . -C
Sometimes you can rely on the default name prefixes and sometimes you
must override them with [CCode (...)] attributes.
Best Regards,
Frederik
[CCode (lower_case_cprefix = "ga_", cheader_filename = "gaul.h")]
namespace GAUL {
[CCode (cname = "ga_de_crossover_type", cprefix = "GA_DE_CROSSOVER_")]
enum DECrossoverType {
UNKNOWN,
BINOMIAL,
EXPONENTIAL
}
[Compact]
[CCode (cname="population", free_function = "ga_extinction")]
public class Population {
public Population (int stable_size, int num_chromosome,
int len_chromosome);
public void set_mutation (double mutation);
// Alternative A:
[CCode (cname = "ga_seed_boolean_random")]
public bool seed_boolean_random (Entity adam);
}
[Compact]
[CCode (cname="entity")]
public class Entity {
}
// Alternative B:
public static bool seed_boolean_random (Population pop, Entity adam);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]