1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00

Make V8::C::String < V8::C::Value

This commit is contained in:
Charles Lowell 2012-05-04 00:04:01 -05:00
parent 30af30edee
commit d2663ba161
3 changed files with 8 additions and 2 deletions

View file

@ -1,7 +1,7 @@
#include "rr.h"
namespace rr {
VALUE defineClass(const char *name, VALUE superclass) {
VALUE defineClass(const char *name, VALUE superclass = rb_cObject) {
VALUE V8 = rb_define_module("V8");
VALUE V8_C = rb_define_module_under(V8, "C");
VALUE klass = rb_define_class_under(V8_C, name, superclass);
@ -19,6 +19,11 @@ namespace rr {
this->value = defineClass(name, superclass);
}
ClassBuilder::ClassBuilder(const char* name, const char* supername) {
VALUE superclass = defineClass(supername);
this->value = defineClass(name, superclass);
}
ClassBuilder& ClassBuilder::defineMethod(const char* name, VALUE (*impl)(VALUE)) {
rb_define_method(this->value, name, (VALUE (*)(...))impl, 0);
return *this;

View file

@ -141,6 +141,7 @@ public:
class ClassBuilder {
public:
ClassBuilder(const char* name, VALUE superclass = rb_cObject);
ClassBuilder(const char* name, const char* supername);
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));

View file

@ -6,7 +6,7 @@ VALUE String::Class;
void String::Init() {
rb_gc_register_address(&Class);
Class = ClassBuilder("String").
Class = ClassBuilder("String", "Value").
defineSingletonMethod("New", &New).
defineMethod("Utf8Value", &Utf8Value);
}