Bonjour, je cherche à faire un binding C/Ruby, en somme embarquer un interpreteur ruby dans un programme C chargé d'ouvrir un fichier ruby et de le lire.
Voici mon code C :
#include <iostream.h>
#include "ruby.h"
VALUE cHello;
static VALUE hello_initialize(VALUE self)
{
// prototype : rb_iv_set(VALUE receveur, char* nomAttribut, VALUE valeurAttribut)
rb_iv_set(self, "@msg", rb_str_new2("Hello, World !"));
return self;
}
static VALUE hello_saluer(VALUE self)
{
// prototype : rb_iv_get(VALUE receveur, char* nomAttribut)
VALUE msg = rb_iv_get(self, "@msg");
// prototype : rb_funcall(VALUE receveur, ID nomMethode, int nbArguments, ...)
rb_funcall(self, rb_intern("puts"), 1, msg);
return self;
}
void Init_hello()
{
cHello = rb_define_class("Hello", rb_cObject);
rb_define_method(cHello, "initialize", hello_initialize, 0);
rb_define_method(cHello, "saluer", hello_saluer, 0);
}
int main( int argc, char *argv[] ) {
int rb_argc = 0; char **rb_argv = 0;
NtInitialize(&rb_argc,&rb_argv);
ruby_init();
ruby_script("embedded");
ruby_init_loadpath();
// Load my class Hello definition
Init_hello();
// Charger le script "test.rb"
rb_load_file("test.rb");
ruby_run();
return 0;
}
Or lorsque je compile (j'utilise Code::Blocks) j'obtiens le message d'erreur suivant :
C:\Documents and Settings\Dorier.PC300662625084\Mes documents\Allegruby\Allegro_and_Ruby\main.cpp|28|error: invalid conversion from `VALUE (*)(VALUE)' to `VALUE (*)(...)'|
C:\Documents and Settings\Dorier.PC300662625084\Mes documents\Allegruby\Allegro_and_Ruby\main.cpp|28|error: initializing argument 3 of `void rb_define_method(VALUE, const char*, VALUE (*)(...), int)'|
C:\Documents and Settings\Dorier.PC300662625084\Mes documents\Allegruby\Allegro_and_Ruby\main.cpp|29|error: invalid conversion from `VALUE (*)(VALUE)' to `VALUE (*)(...)'|
C:\Documents and Settings\Dorier.PC300662625084\Mes documents\Allegruby\Allegro_and_Ruby\main.cpp|29|error: initializing argument 3 of `void rb_define_method(VALUE, const char*, VALUE (*)(...), int)'|
Auriez-vous une idée d'ou ça peut venir ?
Merci de votre aide !
PS : j'ai déjà testé la bonne configuration de ruby.h pour Code::Blocks en faisant un petit programme qui lit seulement un fichier ruby. Là apparement c'est la définition des méthodes qui cloche.
__________________________
Gné !