mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
don't need the spike any more now that it's a reality :)
This commit is contained in:
parent
12c5723411
commit
21b6c91c9b
1 changed files with 0 additions and 43 deletions
43
spike.rb
43
spike.rb
|
@ -1,43 +0,0 @@
|
|||
#!/opt/local/bin/ruby
|
||||
`make all`
|
||||
require 'v8';
|
||||
|
||||
#manually run a script
|
||||
result = V8::C::Context.new.open do |cxt|
|
||||
v8_str = V8::C::String.new('1 + 1')
|
||||
v8_script = V8::C::Script.new(v8_str)
|
||||
v8_script.Run()
|
||||
end
|
||||
|
||||
puts "result: #{result}"
|
||||
|
||||
|
||||
#define eval() purely in ruby
|
||||
class V8::C::Context
|
||||
def eval(javascript)
|
||||
self.open do
|
||||
source = V8::C::String.new(javascript)
|
||||
script = V8::C::Script.new(source)
|
||||
script.Run()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
f = V8::C::FunctionTemplate.new do | foo, bar |
|
||||
"Hello!! This is ruby code #{foo} #{bar}!!!!"
|
||||
end
|
||||
|
||||
plus = V8::C::FunctionTemplate.new do |a, b|
|
||||
a + b
|
||||
end
|
||||
|
||||
o = V8::C::ObjectTemplate.new
|
||||
o.Set("hello", f)
|
||||
o.Set("plus_of_awesomeness", plus)
|
||||
V8::C::Context.new(o).open do |cxt|
|
||||
puts "r1: " + cxt.eval('plus_of_awesomeness(8, 3.4)').to_s
|
||||
puts "r2: " + cxt.eval('hello("Fred", "Wilma")')
|
||||
end
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue