From: Harold Hausman Date: 2007-02-18T01:07:00+09:00 Subject: Re: Using Ruby as an extension language On 2/17/07, Harold Hausman wrote: > And my other question comes from when I try to expose a new method to > the running Ruby. Here are some snippets of my code: > VALUE rb_myprint( VALUE inSelf, VALUE inString ) > { > // snip... but do stuff here, etc.... > return Qnil; > } > > and then later: > rb_define_global_function( "myprint", rb_myprint, 1 ); > > 2. When I try to compile this, I get the following error: > Error 2 error C2664: 'rb_define_global_function' : cannot convert > parameter 2 from 'VALUE (__cdecl *)(VALUE,VALUE)' to 'VALUE (__cdecl > *)(...)' d:\code\littlecoder\littlecoder.cpp 68 > So, I've found *an* answer to my question, but it feels a little nuts. Anyone care to confirm that this is the best practice for exposing C++ static methods to Ruby? typedef VALUE (*HOOK)(...); ///.... // define static functions, etc..... ///..... rb_define_global_function( "myprint", reinterpret_cast(rb_myprint), 1 ); Man, ugly things like reinterpret_cast make me wish I was working with a dynamic language... But that's the whole point of this exercise to begin with, isn't it? :P Many thanks for any input, and apologies for the answering myself noise. -Harold