mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
1/2 baby step, put an object into the struct.
This commit is contained in:
parent
e7caf25d09
commit
e3013b3e71
1 changed files with 9 additions and 2 deletions
11
v8.cpp
11
v8.cpp
|
@ -2,6 +2,15 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
class foo {
|
||||||
|
private:
|
||||||
|
int messageNumber=0;
|
||||||
|
public:
|
||||||
|
void print(const char* msg) {
|
||||||
|
printf("%d %s\n", ++messageNumber, msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
typedef struct v8_context {
|
typedef struct v8_context {
|
||||||
int a;
|
int a;
|
||||||
} v8_context;
|
} v8_context;
|
||||||
|
@ -20,7 +29,6 @@ VALUE rb_cV8;
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
void Init_v8() {
|
void Init_v8() {
|
||||||
printf("Init_v8()\n");
|
|
||||||
rb_mModule = rb_define_module("V8");
|
rb_mModule = rb_define_module("V8");
|
||||||
rb_cV8 = rb_define_class_under(rb_mModule, "Context", rb_cObject);
|
rb_cV8 = rb_define_class_under(rb_mModule, "Context", rb_cObject);
|
||||||
rb_define_alloc_func(rb_cV8, v8_allocate);
|
rb_define_alloc_func(rb_cV8, v8_allocate);
|
||||||
|
@ -47,7 +55,6 @@ VALUE print(VALUE object, VALUE arg)
|
||||||
{
|
{
|
||||||
v8_context* s=0;
|
v8_context* s=0;
|
||||||
Data_Get_Struct(object, struct v8_context, s);
|
Data_Get_Struct(object, struct v8_context, s);
|
||||||
printf("%d %s\n", (s?s->a++:-1), RSTRING(arg)->ptr);
|
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue