Skip to content

Commit

Permalink
Primitive ruby interoperativity
Browse files Browse the repository at this point in the history
  • Loading branch information
Josep M. Bach committed Sep 23, 2011
1 parent 7ae7520 commit 876575a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/interop.ns
@@ -0,0 +1,2 @@
myvar = Ruby.eval('Integer.new(3 + 5)')
print(myvar)
13 changes: 13 additions & 0 deletions lib/noscript/context.rb
Expand Up @@ -22,10 +22,23 @@ def self.generate
})

ctx.store_var('Object', Object.new)
ctx.store_var('Ruby', create_ruby_object)

ctx
end

def self.create_ruby_object
ruby = Object.new
ruby.add_slot('eval', lambda { |context, string|
str = string.compile(context).to_s

sandbox = ::Object.new
sandbox.extend(AST)
sandbox.instance_eval(str)
})
ruby
end

attr_accessor :lvars, :current_receiver

def initialize(parent_context = nil)
Expand Down
8 changes: 8 additions & 0 deletions test/integration_test.rb
Expand Up @@ -40,6 +40,14 @@ def test_traits
], output
end

def test_interop
output = `./bin/noscript examples/interop.ns`.split("\n")

assert_equal [
"5",
], output
end

def test_conditionals
[
"""
Expand Down

0 comments on commit 876575a

Please sign in to comment.