Permalink
Browse files

+ 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.

[git-p4: depot-paths = "//src/RubyInline/dev/": change = 2198]
  • Loading branch information...
1 parent 6c04f9f commit 1b747dfdb43c525057c300233b6ff018b208df79 @zenspider zenspider committed Oct 16, 2005
Showing with 61 additions and 0 deletions.
  1. +10 −0 History.txt
  2. +27 −0 demo/fastmath.rb
  3. +13 −0 demo/hello.rb
  4. +11 −0 inline.rb
View
10 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
View
27 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
View
13 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 "<stdio.h>"
+ builder.c 'void hello() { puts("hello world"); }'
+ end
+end
+
+Hello.new.hello
View
11 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"
@@ -421,6 +425,13 @@ def add_link_flags(*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+.
def add_type_converter(type, r2c, c2r)

0 comments on commit 1b747df

Please sign in to comment.