diff --git a/examples/interop.ns b/examples/interop.ns new file mode 100644 index 0000000..3606250 --- /dev/null +++ b/examples/interop.ns @@ -0,0 +1,2 @@ +myvar = Ruby.eval('Integer.new(3 + 5)') +print(myvar) diff --git a/lib/noscript/context.rb b/lib/noscript/context.rb index 2d59400..1e66817 100644 --- a/lib/noscript/context.rb +++ b/lib/noscript/context.rb @@ -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) diff --git a/test/integration_test.rb b/test/integration_test.rb index 1367cc1..94123ae 100644 --- a/test/integration_test.rb +++ b/test/integration_test.rb @@ -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 [ """