PDA

View Full Version : Embedding Ruby


DesertPenguin
2007.01.05, 02:01 PM
I have decided to try using Ruby instead of Lua for scripting.

I keep getting the following compiler error which is confusing me:
g++ -g -c main.cpp -I/Developer/ruby-1.8.5
main.cpp: In function 'int main(int, const char**)':
main.cpp:21: error: invalid conversion from 'VALUE (*)()' to 'VALUE (*)(...)'
main.cpp:21: error: initializing argument 2 of 'void rb_define_global_function(const char*, VALUE (*)(...), int)'


My source:
VALUE callback(void)
{
printf("C callback\n");

return T_TRUE;
}

int main (int argc, const char * argv[])
{
ruby_init();

// dumps the version info to stdout
ruby_show_version();

//define that callback below
rb_define_global_function("c_callback", callback, 0);

ruby_init_loadpath();

/* //////////////////////////// */
rb_load_file("rubydefs.rb");
int status;
status = ruby_exec();
status = ruby_exec();
status = ruby_cleanup(status);
/* //////////////////////////// */
ruby_finalize();


fprintf(stdout, "this is the end");
return 0;
}


What is VALUE(*)(...) as opposed to VALUE(*)()?

Thanks for any tips....

unknown
2007.01.05, 02:51 PM
... is for variable numbe of args

OneSadCookie
2007.01.05, 04:44 PM
Ruby doesn't compile cleanly as C++; you'll need to cast all your function pointers.

DesertPenguin
2007.01.06, 12:11 AM
Thanks - Its working now with:

VALUE callback(...)
{
printf("C callback\n");

return T_TRUE;
}