Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added rb_proc_new.

  • Loading branch information...
commit 926cf63ff76f68be8e334793175916bc43d67d6a 1 parent 83cd8d2
@brixen brixen authored
View
1  kernel/common/native_method.rb
@@ -10,6 +10,7 @@ class NativeMethod < Executable
attr_reader :file
attr_reader :name
+ attr_reader :arity
#
# Load a dynamic library at path +library+, having name +extension_name+.
View
6 kernel/common/proc.rb
@@ -36,6 +36,7 @@ def self.new(method=nil, &block)
end
attr_accessor :block
+ attr_accessor :bound_method
def binding
bind = Binding.setup @block.scope, @block.method, @block.method.scope
@@ -55,6 +56,11 @@ def ==(other)
end
def arity
+ if @bound_method
+ arity = @bound_method.arity
+ arity < 0 ? -1 : arity
+ end
+
@block.arity
end
View
3  vm/builtin/proc.cpp
@@ -19,8 +19,7 @@
namespace rubinius {
void Proc::init(STATE) {
- GO(proc).set(
- state->new_class("Proc", G(object)));
+ GO(proc).set(state->new_class("Proc", G(object)));
G(proc)->set_object_type(state, ProcType);
}
View
3  vm/capi/include/ruby.h
@@ -1284,6 +1284,9 @@ VALUE rb_uint2big(unsigned long number);
/** Call #inspect on an object. */
VALUE rb_inspect(VALUE obj_handle);
+ /** Returns a Proc wrapping a C function. */
+ VALUE rb_proc_new(VALUE (*func)(ANYARGS), VALUE val);
+
VALUE rb_protect_inspect(VALUE (*func)(VALUE a, VALUE b), VALUE h_obj, VALUE h_arg);
VALUE rb_inspecting_p(VALUE obj);
View
18 vm/capi/proc.cpp
@@ -0,0 +1,18 @@
+#include "builtin/nativemethod.hpp"
+#include "builtin/proc.hpp"
+
+#include "capi/capi.hpp"
+#include "capi/include/ruby.h"
+
+using namespace rubinius;
+using namespace rubinius::capi;
+
+extern "C" {
+ VALUE rb_proc_new(VALUE (*func)(ANYARGS), VALUE val) {
+ NativeMethodEnvironment* env = NativeMethodEnvironment::get();
+
+ Proc* prc = capi::wrap_c_function((void*)func, val, ITERATE_BLOCK);
+
+ return env->get_handle(prc);
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.