diff --git a/History.txt b/History.txt index 0b2be85..3a6ad10 100644 --- a/History.txt +++ b/History.txt @@ -1,3 +1,13 @@ +*** 3.5.0 / 2005-10-15 + ++ 4 minor enhancements + + Switched to install for Makefile. + + Lots of minor cleanup. + + Added add_to_init to extend init methods. Great hack! + + Added 2 demo files used in the rubyconf 2005 presentation. ++ 1 bug fix + + Fixed example in README.txt. OOPS! + *** 3.4.0 / 2005-07-13 + 2 minor enhancement diff --git a/demo/fastmath.rb b/demo/fastmath.rb new file mode 100644 index 0000000..af9aee3 --- /dev/null +++ b/demo/fastmath.rb @@ -0,0 +1,27 @@ + +begin require 'rubygems' rescue LoadError end +require 'inline' + +class FastMath + def factorial(n) + f = 1 + n.downto(2) { |x| f *= x } + return f + end + inline do |builder| + builder.c " + long factorial_c(int max) { + int i=max, result=1; + while (i >= 2) { result *= i--; } + return result; + }" + end +end + +math = FastMath.new + +if ARGV.empty? then + 30000.times do math.factorial(20); end +else + 30000.times do math.factorial_c(20); end +end diff --git a/demo/hello.rb b/demo/hello.rb new file mode 100644 index 0000000..a3bab0b --- /dev/null +++ b/demo/hello.rb @@ -0,0 +1,13 @@ +#!/usr/local/bin/ruby -w + +begin require 'rubygems' rescue LoadError end +require 'inline' + +class Hello + inline do |builder| + builder.include "" + builder.c 'void hello() { puts("hello world"); }' + end +end + +Hello.new.hello diff --git a/inline.rb b/inline.rb index 55a402e..b360b94 100644 --- a/inline.rb +++ b/inline.rb @@ -276,6 +276,7 @@ def initialize(mod) @sig = {} @flags = [] @libs = [] + @init_extra = [] end ## @@ -337,6 +338,9 @@ def build end io.puts "(VALUE(*)(ANYARGS))#{name}, #{arity});" end + + io.puts @init_extra.join("\n") unless @init_extra.empty? + io.puts io.puts " }" io.puts "#ifdef __cplusplus" @@ -420,6 +424,13 @@ def add_link_flags(*flags) @libs.push(*flags) end + ## + # Adds custom content to the end of the init function. + + def add_to_init(*src) + @init_extra.push(*src) + end + ## # Registers C type-casts +r2c+ and +c2r+ for +type+.