diff --git a/README.rdoc b/README.rdoc index 1eb30d7..dba774f 100644 --- a/README.rdoc +++ b/README.rdoc @@ -20,6 +20,10 @@ Embed the V8 Javascript interpreter into Ruby. # evaluate some simple javascript + V8.eval("7 * 6") #=> 42 + +# embed values into the scope of your context + V8::Context.open do |cxt| cxt['foo'] = "bar" cxt.eval('foo') # => "bar" diff --git a/lib/v8/context.rb b/lib/v8/context.rb index bd5a7ba..c1c5a07 100644 --- a/lib/v8/context.rb +++ b/lib/v8/context.rb @@ -1,4 +1,6 @@ -module V8 +require 'stringio' + +module V8 class Context def initialize(opts = {}) @native = C::Context.new(opts[:with]) @@ -46,7 +48,15 @@ module V8 def self.open(opts = {}, &block) new(opts).open(&block) - end + end + + def self.eval(source) + new.eval(source) + end + + def V8.eval(*args) + V8::Context.eval(*args) + end end class ContextError < StandardError