diff --git a/ext/v8/context.cc b/ext/v8/context.cc index 809f9b8..19d2825 100644 --- a/ext/v8/context.cc +++ b/ext/v8/context.cc @@ -4,7 +4,7 @@ namespace rr { VALUE New(VALUE ContextClass) { v8::Persistent context = v8::Context::New(); - Ref ref = Ref::create(context, ContextClass); + Ref ref = Context::create(context, ContextClass); context.Dispose(); return ref; } @@ -20,9 +20,9 @@ namespace rr { } void Context::Init() { - VALUE ContextClass = defineClass("Context"); - RR_DEFINE_SINGLETON_METHOD(ContextClass, "New", &New, 0); - RR_DEFINE_METHOD(ContextClass, "Enter", &Enter, 0); - RR_DEFINE_METHOD(ContextClass, "Exit", &Exit, 0); + ClassBuilder("Context"). + defineSingletonMethod("New", &New). + defineMethod("Enter", &Enter). + defineMethod("Exit", &Exit); } } \ No newline at end of file diff --git a/ext/v8/rr.cc b/ext/v8/rr.cc index 2e2a943..5315f74 100644 --- a/ext/v8/rr.cc +++ b/ext/v8/rr.cc @@ -27,6 +27,10 @@ namespace rr { rb_define_method(this->value, name, (VALUE (*)(...))impl, 1); return *this; } + ClassBuilder& ClassBuilder::defineMethod(const char* name, VALUE (*impl)(VALUE, VALUE, VALUE)) { + rb_define_method(this->value, name, (VALUE (*)(...))impl, 2); + return *this; + } ClassBuilder& ClassBuilder::defineSingletonMethod(const char* name, VALUE (*impl)(VALUE)) { rb_define_singleton_method(this->value, name, (VALUE (*)(...))impl, 0); return *this; @@ -35,4 +39,9 @@ namespace rr { rb_define_singleton_method(this->value, name, (VALUE (*)(...))impl, 1); return *this; } + ClassBuilder& ClassBuilder::defineSingletonMethod(const char* name, VALUE (*impl)(VALUE, VALUE, VALUE)) { + rb_define_singleton_method(this->value, name, (VALUE (*)(...))impl, 2); + return *this; + } + } \ No newline at end of file diff --git a/ext/v8/rr.h b/ext/v8/rr.h index 24e902b..b985bba 100644 --- a/ext/v8/rr.h +++ b/ext/v8/rr.h @@ -129,18 +129,15 @@ public: ClassBuilder(const char* name, VALUE superclass = rb_cObject); ClassBuilder& defineMethod(const char* name, VALUE (*impl)(VALUE)); ClassBuilder& defineMethod(const char* name, VALUE (*impl)(VALUE, VALUE)); + ClassBuilder& defineMethod(const char* name, VALUE (*impl)(VALUE, VALUE, VALUE)); ClassBuilder& defineSingletonMethod(const char* name, VALUE (*impl)(VALUE)); ClassBuilder& defineSingletonMethod(const char* name, VALUE (*impl)(VALUE, VALUE)); + ClassBuilder& defineSingletonMethod(const char* name, VALUE (*impl)(VALUE, VALUE, VALUE)); inline operator VALUE() {return this->value;} private: VALUE value; }; -VALUE defineClass(const char *name, VALUE superclass = rb_cObject); -VALUE defineModule(const char *name); } -#define RR_DEFINE_METHOD(klass, name, impl, argc) rb_define_method(klass, name, (VALUE(*)(...))impl, argc) -#define RR_DEFINE_SINGLETON_METHOD(object, name, impl, argc) rb_define_singleton_method(object, name, (VALUE(*)(...))impl, argc) - #endif diff --git a/ext/v8/script.cc b/ext/v8/script.cc index bcbfa3c..3f35502 100644 --- a/ext/v8/script.cc +++ b/ext/v8/script.cc @@ -16,9 +16,9 @@ VALUE Run(VALUE self) { } void Script::Init() { - VALUE ScriptClass = defineClass("Script"); - RR_DEFINE_SINGLETON_METHOD(ScriptClass, "New", &New, 2); - RR_DEFINE_METHOD(ScriptClass, "Run", &Run, 0); + ClassBuilder("Script"). + defineSingletonMethod("New", &New). + defineMethod("Run", &Run); } } \ No newline at end of file diff --git a/ext/v8/v8.cc b/ext/v8/v8.cc index 71a4910..0a2edef 100644 --- a/ext/v8/v8.cc +++ b/ext/v8/v8.cc @@ -7,7 +7,7 @@ namespace { } } void V8::Init() { - VALUE V8Class = defineClass("V8"); - RR_DEFINE_SINGLETON_METHOD(V8Class, "IdleNotification", &IdleNotification, 0); + ClassBuilder("V8"). + defineSingletonMethod("IdleNotification", &IdleNotification); } } \ No newline at end of file