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
|
|
|
|
2010-05-20 04:30:27 -04: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
|
2010-06-07 03:50:33 -04:00
|
|
|
v8_ref(v8::Handle<void> object);
|
2009-12-07 09:06:06 -05:00
|
|
|
virtual ~v8_ref();
|
2010-05-20 05:06:21 -04:00
|
|
|
void set(const char *name, VALUE ref);
|
2009-12-07 09:06:06 -05:00
|
|
|
v8::Persistent<void> handle;
|
2009-12-11 12:11:05 -05:00
|
|
|
VALUE references;
|
2009-12-07 02:20:16 -05:00
|
|
|
};
|
|
|
|
|
2010-05-20 05:06:21 -04:00
|
|
|
void rr_v8_ref_setref(VALUE handle, const char *name, VALUE ref);
|
2010-05-22 02:23:22 -04:00
|
|
|
VALUE rr_v8_ref_create(VALUE rbclass, v8::Handle<void> handle);
|
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
|
|
|
|
2010-06-14 11:27:01 -04:00
|
|
|
#endif
|