diff --git a/ext/v8/convert_ruby.h b/ext/v8/convert_ruby.h index 37cf4f3..a4354fb 100644 --- a/ext/v8/convert_ruby.h +++ b/ext/v8/convert_ruby.h @@ -44,10 +44,13 @@ template class RubyValueSource { return dest.pushBool(true); case T_FALSE: return dest.pushBool(false); - // case T_DATA: - // if (rb_is_function(value)) { - // return dest.pushCode(new Code) - // } + case T_DATA: + VALUE clsProc = rb_eval("::Proc"); + VALUE clsMethod = rb_eval("::Method"); + VALUE smartMatch = rb_intern("==="); + if (RTEST(rb_funcall(clsProc, smartMatch, value)) || RTEST(rbfuncall(clsMethod, smartMatch, value))) { + + } } return dest.pushUndefined(); } diff --git a/ext/v8/converters.h b/ext/v8/converters.h index a6af218..160a6df 100644 --- a/ext/v8/converters.h +++ b/ext/v8/converters.h @@ -11,4 +11,7 @@ typedef V8HandleSource convert_v8_to_rb_t; typedef RubyValueSource convert_rb_to_string_t; typedef V8HandleSource convert_v8_to_string_t; +extern convert_v8_to_rb_t V82RB; +extern convert_rb_to_v8_t RB2V8; + #endif \ No newline at end of file diff --git a/ext/v8/v8.cpp b/ext/v8/v8.cpp index 064c410..612dee7 100644 --- a/ext/v8/v8.cpp +++ b/ext/v8/v8.cpp @@ -28,6 +28,7 @@ extern "C" { ruby_method_class = rb_eval_string("::Method"); rb_mModule = rb_define_module("V8"); + rb_define_singleton_method(rb_mModule, "what_is_this?", (VALUE(*)(...)) v8_what_is_this, 1); //native module setup VALUE rb_mNative = rb_define_module_under(rb_mModule, "C"); @@ -37,6 +38,7 @@ extern "C" { rb_define_singleton_method(V8__C__Context, "new", (VALUE(*)(...)) v8_Context_New, -1); rb_define_method(V8__C__Context, "Global", (VALUE(*)(...)) v8_cxt_Global, 0); rb_define_method(V8__C__Context, "open", (VALUE(*)(...)) v8_cxt_open, 0); + rb_define_method(V8__C__Context, "eval", (VALUE(*)(...)) v8_cxt_eval, 1); //native String VALUE V8__C__String = rb_define_class_under(rb_mNative, "String", rb_cObject); diff --git a/ext/v8/v8_cxt.cpp b/ext/v8/v8_cxt.cpp index fcdc40e..e9cdb8f 100644 --- a/ext/v8/v8_cxt.cpp +++ b/ext/v8/v8_cxt.cpp @@ -30,20 +30,26 @@ VALUE v8_cxt_open(VALUE self) { Local cxt = V8_Ref_Get(self); Context::Scope enter(cxt); if (rb_block_given_p()) { - printf("
About to execute Ruby Block
"); VALUE result = rb_yield(self); - printf("
Ruby Block was executed
\n"); if (exceptions.HasCaught()) { return V8_Wrap_Message(exceptions.Message()); } else { - printf("
No exception
"); return result; } return result; } else { - printf("
No block given!
"); return Qnil; } } +VALUE v8_cxt_eval(VALUE self, VALUE source) { + HandleScope handles; + Local cxt = V8_Ref_Get(self); + Context::Scope enter(cxt); + Local source_str = RB2V8(source); + Local