2009-12-07 02:20:16 -05:00
|
|
|
#ifndef _RUBY_V8_REF_
|
|
|
|
#define _RUBY_V8_REF_
|
|
|
|
|
|
|
|
#include <v8.h>
|
2009-12-11 12:11:05 -05:00
|
|
|
#include "ruby.h"
|
2009-12-07 02:20:16 -05:00
|
|
|
|
2009-12-07 02:44:18 -05:00
|
|
|
//the v8_ref wraps a v8 handle so that ruby can hold a reference to it.
|
|
|
|
|
2009-12-07 09:06:06 -05:00
|
|
|
struct v8_ref {
|
2009-12-07 02:44:18 -05:00
|
|
|
//takes a handle object and adds a new persistent handle for
|
2009-12-07 02:54:20 -05:00
|
|
|
//the referenced object
|
2009-12-11 12:11:05 -05:00
|
|
|
v8_ref(v8::Handle<void> object, VALUE ref = 0);
|
2009-12-07 09:06:06 -05:00
|
|
|
virtual ~v8_ref();
|
|
|
|
v8::Persistent<void> handle;
|
2009-12-11 12:11:05 -05:00
|
|
|
VALUE references;
|
2009-12-07 02:20:16 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//memory management
|
2009-12-07 09:06:06 -05:00
|
|
|
void v8_ref_mark(v8_ref* ref);
|
|
|
|
void v8_ref_free(v8_ref* ref);
|
2009-12-07 02:20:16 -05:00
|
|
|
|
2009-12-13 10:08:55 -05:00
|
|
|
VALUE V8_Ref_Create(VALUE ruby_class, v8::Handle<void> handle, VALUE ref = 0);
|
2009-12-07 02:20:16 -05:00
|
|
|
|
2009-12-13 10:08:55 -05:00
|
|
|
template <class T> v8::Local<T> V8_Ref_Get(VALUE object) {
|
|
|
|
v8_ref* ref = 0;
|
|
|
|
Data_Get_Struct(object, struct v8_ref, ref);
|
|
|
|
return (T *)*ref->handle;
|
|
|
|
}
|
2009-12-09 09:30:48 -05:00
|
|
|
|
2009-12-07 02:20:16 -05:00
|
|
|
#endif
|