metakit from ruby using swig

V

Vladimir Konrad

i managet to make the metakit (http://www.equi4.com/metakit.html) work
from ruby
by using swig. it was my first usage of swig and the result is not
"rubyish", but the basic test works (can store and retrieve data).

is there any interest in this (i.e. would you like the instructions on
how i have done it)?.

vlad
 
M

M. Edward (Ed) Borasky

Vladimir said:
i managet to make the metakit (http://www.equi4.com/metakit.html) work
from ruby
by using swig. it was my first usage of swig and the result is not
"rubyish", but the basic test works (can store and retrieve data).

is there any interest in this (i.e. would you like the instructions on
how i have done it)?.

vlad
I'm interested, although I'm perfectly happy with SQLite and its Ruby
bindings. I'm just starting to get my feet wet with SWIG, so I'm
interested in that as well.
 
V

Vladimir Konrad

here it goes...


/* swig file */

%module mk4

%{
#include "mk4.h"
%}

%include "mk4.h"

/* swig file end */

metakit version (the latest .tar.gz from their web-site).

swig version:
SWIG Version 1.3.27
Copyright (c) 1995-1998
University of Utah and the Regents of the University of California
Copyright (c) 1998-2005
University of Chicago
Compiled with g++ [i686-pc-linux-gnu]

ruby version:
ruby 1.8.4 (2005-12-24) [i686-linux]

gcc version:
g++ (GCC) 4.1.1

how to wrap the metakit using swig:

1. build and install metakit (as shared object, i did not try the static
build)
2. cd to "include" directory in the metakit directory
3. create mk4.i
4. # swig -ruby -c++ mk4.i

(it will issue a lot of warnings but it generates the wrapper)

5. # g++ -c mk4_wrap.cxx -I/usr/lib/ruby/1.8/i686-linux

it will give errors but deleting the 4 offending wrapper definitions
(and
4 calls using them) will make it compile

(the -I should point to wherewer the ruby.h resides)

6. # g++ -shared mk4_wrap.o ../builds/libmk4.so -o mk4.so

note, the mk4so will depend on the location of libmk4.so, to build the
"proper" way, copy the mk4_wrap.o and libmk4.so to a common directory,
cd there and do:

# g++ -shared mk4_wrap.o libmk4.so -o mk4.so

(this way, if ld can find the libmk4.so, the mk4.so will load)

7. from ruby:
require 'mk4'
include Mk4 # optional

(the mk4.so has to be somewhere ruby can find it)

notes: i am not sure whether the removal of definitions affects the
function of metakit extension but a basic test works.

vlad

ps: if you are interested, i can send you the generated wrapper (so you
can diff it against yours to see what i removed) + simple test script by
e-mail...
 
V

Vladimir Konrad

forgot one thing, the metakit can be built as static library
(--disable-shared option for configure), and the swig wrapper library
linked against that - this way the ruby shared object (mk4.so) will not
depend on the shared library libmk4.so (basically the ruby mk4.so will
have all the functions of metakit in it)...

vlad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top