mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
Added shell for executing V8 code
This commit is contained in:
parent
21ed473b59
commit
aae681048a
2 changed files with 63 additions and 1 deletions
|
@ -1,6 +1,8 @@
|
|||
=== X.X.X 2010-XX-XX
|
||||
* n major enhancements(s)
|
||||
* added javascript shell (bin/therubyracer)
|
||||
* n minor enhancement(s)
|
||||
*added to_s method for embedded ruby objects
|
||||
* added to_s method for embedded ruby objects
|
||||
|
||||
=== 0.5.1 2010-02-17
|
||||
* 1 minor enhancement
|
||||
|
|
60
bin/therubyracer
Executable file
60
bin/therubyracer
Executable file
|
@ -0,0 +1,60 @@
|
|||
#!/usr/bin/env ruby
|
||||
lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
|
||||
$:.unshift(lib) if File.exists?(lib) unless $:.member?(lib)
|
||||
|
||||
require 'readline'
|
||||
begin
|
||||
require 'v8'
|
||||
rescue LoadError
|
||||
require 'rubygems'
|
||||
require 'v8'
|
||||
end
|
||||
|
||||
trap("SIGINT") do
|
||||
puts "^C"
|
||||
end
|
||||
|
||||
class V8::Shell
|
||||
def exit(status = 0)
|
||||
Kernel.exit(status)
|
||||
end
|
||||
|
||||
def help(*args)
|
||||
<<-HELP
|
||||
exit(status = 0)
|
||||
exit the shell
|
||||
also: quit()
|
||||
|
||||
ruby(source)
|
||||
evaluate some ruby source
|
||||
HELP
|
||||
|
||||
end
|
||||
|
||||
def to_s
|
||||
"[object TheRubyRacer]"
|
||||
end
|
||||
|
||||
def ruby(src)
|
||||
eval(src)
|
||||
end
|
||||
|
||||
alias_method :quit, :exit
|
||||
end
|
||||
|
||||
puts "help() for help"
|
||||
puts "The Ruby Racer #{V8::VERSION}"
|
||||
puts "Vroom Vroom!"
|
||||
|
||||
V8::Context.open(:with => V8::Shell.new) do |cxt|
|
||||
loop do
|
||||
line = Readline.readline('therubyracer> ', true)
|
||||
begin
|
||||
result = cxt.eval(line)
|
||||
puts(result) unless result.nil?
|
||||
|
||||
rescue StandardError => e
|
||||
puts e
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue