diff --git a/extconf.rb b/extconf.rb index 68d9634..bc38d84 100644 --- a/extconf.rb +++ b/extconf.rb @@ -2,10 +2,7 @@ require 'mkmf' CONFIG['LDSHARED'] = "g++ -shared" -#CPP.sub!(CONFIG['CPP'], 'g++ -E') -#LINK.sub!(CONFIG['CC'], 'g++') +#dir_config('v8') +#have_library('v8') - -# dir_config('v8') -# have_library('v8') create_makefile('v8') diff --git a/t.rb b/t.rb index 3bcf030..312f18a 100644 --- a/t.rb +++ b/t.rb @@ -1,6 +1,6 @@ require 'v8' -e = V8::Class.new +e = V8::Context.new e.print("Hello World") e.print("Hello World") e.print("Hello World") diff --git a/v8.cpp b/v8.cpp index af6ea08..b08e617 100644 --- a/v8.cpp +++ b/v8.cpp @@ -2,16 +2,16 @@ #include <stdio.h> #include <string.h> -typedef struct some_struct { +typedef struct v8_context { int a; -} some_struct; +} v8_context; extern "C" { void Init_v8(); } VALUE v8_allocate(VALUE clazz); -void v8_mark(some_struct *s); -void v8_free(some_struct *s); +void v8_mark(v8_context *s); +void v8_free(v8_context *s); VALUE print(VALUE object, VALUE arg); @@ -22,7 +22,7 @@ extern "C" { void Init_v8() { printf("Init_v8()\n"); rb_mModule = rb_define_module("V8"); - rb_cV8 = rb_define_class_under(rb_mModule, "Class", rb_cObject); + rb_cV8 = rb_define_class_under(rb_mModule, "Context", rb_cObject); rb_define_alloc_func(rb_cV8, v8_allocate); rb_define_method(rb_cV8, "print", (VALUE(*)(...)) print, 1); } @@ -30,25 +30,23 @@ extern "C" { VALUE v8_allocate(VALUE clazz) { printf("v8_allocate()\n"); - some_struct *s = (some_struct *)malloc(sizeof(some_struct)); - memset(s, 0, sizeof(some_struct)); + v8_context *s = new v8_context; + memset(s, 0, sizeof(v8_context)); return Data_Wrap_Struct(clazz, v8_mark, v8_free, s); } -void v8_mark(some_struct *s) { - printf("v8_mark\n"); +void v8_mark(v8_context *s) { // marked for gc? } -void v8_free(some_struct *s) { - printf("v8_free\n"); - free(s); +void v8_free(v8_context *s) { + delete s; } VALUE print(VALUE object, VALUE arg) { - some_struct* s=0; - Data_Get_Struct(object, struct some_struct, s); + v8_context* s=0; + Data_Get_Struct(object, struct v8_context, s); printf("%d %s\n", (s?s->a++:-1), RSTRING(arg)->ptr); return Qnil; }