Skip to content

Commit

Permalink
Update compile command to correctly wrap output ready to run in browser
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Beynon committed Jun 11, 2011
1 parent 3fb249b commit 102a979
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion opal_lib/opal/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def compile(str)
raise "File does not exist: #{str}" unless File.exist? str
str = "\n\n#{File.read str}"
code = Opal::RubyParser.new(str).parse!.generate_top
puts code
puts "opal.run(function($runtime, self, __FILE__) { #{code} });"
end

desc "exec [FILENAME]", "Run the given ruby file"
Expand Down
4 changes: 2 additions & 2 deletions opal_lib/opal/ruby/nodes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,9 @@ def generate(opts, level)
# the args to send.

# register method_missing id if debug mode
if opts[:top].opts[:debug]
# if opts[:top].opts[:debug]
opts[:top].register_mm_id @mid
end
# end

# receiver
if @recv.is_a? NumericNode
Expand Down
14 changes: 14 additions & 0 deletions runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,20 @@ opal = {};
Fs.cwd = '/' + name;
};

/**
Just go ahead and run the given piece of code. The passed function should
take the usual runtime, self and file variables which it will be passed.
*/
Op.run = function(body) {
if (typeof body != 'function') {
throw new Error("Expected body to be a function");
}

body(Rt, Rt.top, "(opal)");

return Qnil;
};

/**
Register a package with the given package info.
Expand Down

0 comments on commit 102a979

Please sign in to comment.