Skip to content

Commit

Permalink
+ Switched to install for Makefile.
Browse files Browse the repository at this point in the history
+ 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
zenspider committed Oct 16, 2005
1 parent 6c04f9f commit 1b747df
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
10 changes: 10 additions & 0 deletions 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
Expand Down
27 changes: 27 additions & 0 deletions 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
13 changes: 13 additions & 0 deletions 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
11 changes: 11 additions & 0 deletions inline.rb
Expand Up @@ -276,6 +276,7 @@ def initialize(mod)
@sig = {}
@flags = []
@libs = []
@init_extra = []
end

##
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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+.

Expand Down

0 comments on commit 1b747df

Please sign in to comment.