Re: [Vala] GMP vapi



On Wed, Aug 10, 2011 at 11:20:49PM +0300, Jeremiah Shaulov wrote:
Hi,

I posted gmp.vapi to live.gnome.org:
http://live.gnome.org/Vala/ExternalBindings?action=AttachFile&do=view&target=gmp.vapi

You forgot to list it in the page.


Everybody is welcome to download.

I found no way to make this binding standalone, and i wrote about this
in the list. So additional C header file is required to compile. Create
file named "gmp-vapi.h" with the following content (this is also noted
in gmp.vapi in top comment):

#include <stdio.h>
#include <string.h>
#include <gmp.h>
#
#ifndef vala_mpz_init
#
#     define vala_mpz_init(self, bitcnt) (bitcnt==0 ? \
(void)mpz_init(self) : (void)mpz_init2(self, bitcnt))
#     define vala_mpf_init(self, bitcnt) (bitcnt==0 ? \
(void)mpf_init(self) : (void)mpf_init2(self, bitcnt))
#
#     define vala_gmp_randstate_copy(from, to) \
gmp_randinit_set(to, from)
#     define vala_mpz_copy(from, to) mpz_init_set(to, from)
#     define vala_mpf_copy(from, to) mpf_init_set(to, from)
#
#endif

You don't need this header, and you don't want people to use an external
header.


Example program "test.vala":

using GLib;
using Gmp;

public class Test : Object
{     public static int main (string[] args)
      {       var a = Float.string("123.456");
              var b = Float.double(987.654);

              a.mul(a, b); // a = a * b

              Gmp.printf("Result: %Ff\n", a);

              return 0;
    }
}

Compile:

valac test2.vala --pkg gmp --vapidir="." -X -I. -X -lgmp

--vapidir="." is needed if gmp.vapi is located in current directory,
instead of default location (/usr/share/vala/vapi/).

-X -I. is needed if gmp-vapi.h is located in current directory, instead
of default location (/usr/include/).

-X -lgmp is always needed since GMP doesn't support pkg-config.

You can add this example to the wiki together with all other examples.

-- 
http://www.debian.org - The Universal Operating System



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]