--5AmtYbcgdBTTPS58
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable


OK - but here is a way to roll your own:
take one C++ file called dohello.cpp:
extern "C" {
  void Init_dohello(void);
}
#include <ruby.h>
#include <iostream>

using namespace std;

int cpp_hello()
{
    cout << "Hello World!" << endl;
        return 0;
}

static VALUE  my_hello( ) {
  cpp_hello();
  return Qtrue;
}

void
Init_dohello(void) {
        VALUE hello;
        hello =3D rb_define_module("CPPHello");
        rb_define_module_function(hello, "do_hello", ( VALUE (*)(...) ) my_=
hello, 0);
}


Take an extconf.rb file:
require 'mkmf'
have_library("stdc++")
create_makefile("dohello")


And a test.rb file:
require "dohello.so"
CPPHello.do_hello()

And stir to your liking :-)

P.S. this was done under Linux FC3 + Ruby 1.8.2


Cheers,

Piers Harding.







On Thu, May 05, 2005 at 06:49:04PM +0900, Nikolai Weibull wrote:
> Derek Haskin, May 5:
>=20
> > Does any know how I would go about making calls to a set of APIs
> > written in C++
>=20
> You could search the archives at http://ruby-talk.org/ before asking
> these questions.  Anyway, here are two links with information,=20
> http://aeditor.rubyforge.org/ruby_cplusplus/index.html and
> http://www.ruby-doc.org/docs/ProgrammingRuby/.  The first is C++
> specific, the second contains information relating to API interfacing in
> general.
>=20
> [cut disclaimer]
>=20
> Do you really, and I mean really, need to include that disclaimer?,
>         nikolai
>=20
> --=20
> Nikolai Weibull: now available free of charge at http://bitwi.se/!
> Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
> main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}

--=20
http://www.piersharding.com
http://raa.ruby-lang.org/search.rhtml?search=3Dpiers&search_target=3Downer
http://search.cpan.org/~piers/


--5AmtYbcgdBTTPS58
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFCehCxGETamPT/o4ARAgXCAKCjECsuB7gftq/7LRR9TpB64UK4aACg+qP9
xt3DUoq5GxFNf7SIi0U+gSs=
=fGt5
-----END PGP SIGNATURE-----

--5AmtYbcgdBTTPS58--


OK - but here is a way to roll your own:
take one C++ file called dohello.cpp:
extern "C" {
  void Init_dohello(void);
}
#include <ruby.h>
#include <iostream>

using namespace std;

int cpp_hello()
{
    cout << "Hello World!" << endl;
        return 0;
}

static VALUE  my_hello( ) {
  cpp_hello();
  return Qtrue;
}

void
Init_dohello(void) {
        VALUE hello;
        hello =3D rb_define_module("CPPHello");
        rb_define_module_function(hello, "do_hello", ( VALUE (*)(...) ) my_=
hello, 0);
}


Take an extconf.rb file:
require 'mkmf'
have_library("stdc++")
create_makefile("dohello")


And a test.rb file:
require "dohello.so"
CPPHello.do_hello()

And stir to your liking :-)

P.S. this was done under Linux FC3 + Ruby 1.8.2


Cheers,

Piers Harding.







On Thu, May 05, 2005 at 06:49:04PM +0900, Nikolai Weibull wrote:
> Derek Haskin, May 5:
>=20
> > Does any know how I would go about making calls to a set of APIs
> > written in C++
>=20
> You could search the archives at http://ruby-talk.org/ before asking
> these questions.  Anyway, here are two links with information,=20
> http://aeditor.rubyforge.org/ruby_cplusplus/index.html and
> http://www.ruby-doc.org/docs/ProgrammingRuby/.  The first is C++
> specific, the second contains information relating to API interfacing in
> general.
>=20
> [cut disclaimer]
>=20
> Do you really, and I mean really, need to include that disclaimer?,
>         nikolai
>=20
> --=20
> Nikolai Weibull: now available free of charge at http://bitwi.se/!
> Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
> main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}

--=20
http://www.piersharding.com
http://raa.ruby-lang.org/search.rhtml?search=3Dpiers&search_target=3Downer
http://search.cpan.org/~piers/

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFCehCxGETamPT/o4ARAgXCAKCjECsuB7gftq/7LRR9TpB64UK4aACg+qP9
xt3DUoq5GxFNf7SIi0U+gSs=
=fGt5
-----END PGP SIGNATURE-----