Bob

I have made quite a lot of progress with binding Metakit, using 
SWIG (http://www.swig.org/).  All that this needs, once you have 
SWIG, is to make a local copy of the Metakit header and run this 
SWIG file

-----------------------
 /* File : mk4.i */
%module mk4

%{
#include "mk4.h"
%}

/* First attempt at mk4 interface */

%include "mk4.h" 
----------------------

Here is a translation of part of the Metakit demo.  Notice
(1) that all the Metakit classes have an initial capital letter. This is 
a requirement of Ruby and the translation is done by SWIG, which 
also gives a warning.
(2) In this simple version some functionality is lost, in particular [ ] 
operations on the view.  Some of this can be restored by adding 
things to the SWIG interface.  I was concerned to get something 
operational.
(3) I have only tried this on Linux using SWIG 1.3.16 and gcc 3.2.


----------------------------
# test file for ruby interface for Metakit

# load the package, which must have a lower case name.
require 'mk4'

include Mk4

puts "A first test of Metakit running via Ruby"
puts "John Fletcher June 2003 [EMAIL PROTECTED]"
puts "This is intended as a translation of demo.cpp"

pName = C4_StringProp.new("name")
pCountry = C4_StringProp.new("country")

storage = C4_Storage.new("myfile.dat",1)

vAddress = storage.GetAs("address[name:S,country:S]")

row = C4_Row.new()

# These do not translate directly
#pName (row) = "John Williams"
#pCountry (row) = "UK"
#row = pName["John Williams"]
#row.pName = "John Williams"

# This has to be used instead.
pName.Set(row,"John Williams")
pCountry.Set(row,"UK")
vAddress.Add(row)

pName.Set(row,"Paco Pena")
pCountry.Set(row,"Spain")
vAddress.Add(row)

# This has added two records.

# Here is how to get data back again
s1 = pName.Get(vAddress.GetAt(1))
s2 = pCountry.Get(vAddress.GetAt(1))

puts "The country of #{s1} is #{s2}"

storage.Commit()
-------------------

Example output:

A first test of Metakit running via Ruby
John Fletcher June 2003 [EMAIL PROTECTED]
This is intended as a translation of demo.cpp
The country of Paco Pena is Spain


John Fletcher

-------------------------------------------------------------------
Dr John P. Fletcher          Tel: (44) 121 359 3611 ext 4625
Chemical Engineering and Applied Chemistry (CEAC),
School of Engineering and Applied Science (SEAS),
Aston University,            Fax: (44) 121 359 4094
Aston Triangle,              Email: [EMAIL PROTECTED]
BIRMINGHAM B4 7ET  U.K.      CEAC Web site http://www.ceac.aston.ac.uk/

_______________________________________________
metakit mailing list  -  [EMAIL PROTECTED]
http://www.equi4.com/mailman/listinfo/metakit

Reply via email to