2010-08-30 14:58:59 -04:00
|
|
|
module V8
|
|
|
|
class Portal
|
|
|
|
class Functions
|
|
|
|
def initialize(portal)
|
|
|
|
@portal = portal
|
|
|
|
@procs, @methods = {},{}
|
|
|
|
end
|
|
|
|
|
|
|
|
def [](code)
|
2010-08-30 15:23:50 -04:00
|
|
|
self.send(code.class.name, code)
|
|
|
|
end
|
|
|
|
|
|
|
|
def Proc(p)
|
|
|
|
@procs[p] ||= begin
|
|
|
|
template = C::FunctionTemplate::New() do |arguments|
|
|
|
|
rbargs = []
|
|
|
|
for i in 0..arguments.Length() - 1
|
|
|
|
rbargs << @portal.rb(arguments[i])
|
2010-08-30 14:58:59 -04:00
|
|
|
end
|
2010-08-30 15:23:50 -04:00
|
|
|
@portal.rubycall(p, *rbargs)
|
2010-08-30 14:58:59 -04:00
|
|
|
end
|
2010-08-30 15:23:50 -04:00
|
|
|
template.GetFunction()
|
2010-08-30 14:58:59 -04:00
|
|
|
end
|
|
|
|
end
|
2010-08-30 15:23:50 -04:00
|
|
|
|
|
|
|
def UnboundMethod(method)
|
|
|
|
@methods[method.to_s] ||= begin
|
2010-08-30 14:58:59 -04:00
|
|
|
template = C::FunctionTemplate::New() do |arguments|
|
|
|
|
rbargs = []
|
|
|
|
for i in 0..arguments.Length() - 1
|
|
|
|
rbargs << @portal.rb(arguments[i])
|
|
|
|
end
|
|
|
|
this = @portal.rb(arguments.This())
|
2010-08-30 15:23:50 -04:00
|
|
|
@portal.rubyprotect do
|
|
|
|
method.bind(this).call(*rbargs)
|
2010-08-30 14:58:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
template.GetFunction()
|
|
|
|
end
|
|
|
|
end
|
2010-08-30 15:23:50 -04:00
|
|
|
|
|
|
|
alias_method :Method, :Proc
|
2010-08-30 14:58:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|