Permalink
Browse files

A few random kernel additions.

  • Loading branch information...
matthewd committed Dec 10, 2010
1 parent 9d8e998 commit 2adc5e13b3c1806acf62a43df6c0e930129a5b7b
Showing with 16 additions and 1 deletion.
  1. +16 −1 lib/capuchin/kernel.rb
View
@@ -191,7 +191,14 @@ def _js_get(k); Fixnum === k ? self[k] : js_hash[k]; end
def _js_set(k,v); Fixnum === k ? self[k] = v : js_hash[k] = v; end
def self.js_new(*args)
- new(*args)
+ if args.size == 1 && Fixnum === args.first
+ new(args.first)
+ else
+ args
+ end
+ end
+ def self.js_call(this)
+ new
end
end
class Numeric
@@ -230,6 +237,9 @@ def js_cmp; to_f; end
def js_key; intern; end
def js_truthy?; size > 0; end
def js_typeof; 'string'; end
+ def self.js_call(this, v)
+ v.to_s
+ end
end
class TrueClass
include JSComparable
@@ -371,15 +381,20 @@ def -(other)
Capuchin::Globals = Rubinius::LookupTable.new
Capuchin::Globals[:Array] = Array
+Capuchin::Globals[:String] = String
Capuchin::Globals[:Object] = Capuchin::Obj
Capuchin::Globals[:Date] = Capuchin::Function.new('Date', {}, Capuchin::DateMethods) {|| @t = Time.new }
Capuchin::Globals[:print] = Capuchin::Function.new {|x| puts x }
Capuchin::Globals[:p] = Capuchin::Function.new {|x| p [x, x.methods.grep(/^js:/)] }
+Capuchin::Globals[:gc] = Capuchin::Function.new {|x| GC.start }
Capuchin::Globals[:Math] = {
:log => Capuchin::Function.new {|n| Math.log(n.js_value) },
:pow => Capuchin::Function.new {|a,b| a.js_value ** b.js_value },
:sqrt => Capuchin::Function.new {|n| Math.sqrt(n.js_value) },
+ :sin => Capuchin::Function.new {|n| Math.sin(n.js_value) },
+ :cos => Capuchin::Function.new {|n| Math.cos(n.js_value) },
:E => Math::E,
+ :PI => Math::PI,
}
Capuchin::Globals[:run] = Capuchin::Globals[:load] = Capuchin::Function.new do |filename|
cx = Capuchin::Context.new

0 comments on commit 2adc5e1

Please sign in to comment.