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:
parent
30af30edee
commit
d2663ba161
3 changed files with 8 additions and 2 deletions
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue