From: Daniel Berger Date: 2006-10-01T08:37:28+09:00 Subject: Re: Calling an existing method with RubyInline - how? ------=_Part_26226_27544867.1159659445234 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 9/30/06, Eric Hodel wrote: > > > On Sep 29, 2006, at 9:49 PM, Daniel Berger wrote: > > > How do you call an existing function from an included header file > > using > > RubyInline? Do I have to wrap it in a 'built' function? > > This should help: > > require 'inline' > > class Foo > inline do |builder| > builder.include "" > > builder.c <<-EOF > int c_atoi(char * nptr) { > return atoi(nptr); > } > EOF > > builder.c_singleton <<-EOF > int c_atol(char * nptr) { > return atol(nptr); > } > EOF > end > > class << self; alias atol c_atol; end > alias atoi c_atoi > > end > > puts Foo.atol("5") > puts Foo.new.atoi("5") > > > For example, say I have this bit of code, and that test.h has a > > function > > defined as "const char* test_version(void)". > > From your example, probably: > > require 'inline' > > class Foo > inline do |builder| > builder.include "" > builder.add_compile_flags "-ltest" > > builder.c_singleton <<-EOF > char * foo_test_version() { > return test_version(); > } > EOF > end > > class << self; alias version foo_test_version; end > end Thanks. Is there any way to avoid having to write wrappers for existing functions? If not, could it be added as a feature? I'd like to be able to just do this: inline{ "return test_version();" } Thanks, Dan ------=_Part_26226_27544867.1159659445234--