Sha256: 45c2b9f1e0b4066cec90a4bfc6a9d5decb6d37d06f4431f2c2ca672c24141359

Contents?: true

Size: 903 Bytes

Versions: 5

Compression:

Stored size: 903 Bytes

Contents

#ifndef __V8_REF_H
#define __V8_REF_H

#include <ruby.h>
#include <v8.h>

using namespace v8;

/*
 * The objectRef keeps a persistent V8 handle, so ruby object can access
 * a reference to it.
 *
 */
struct v8_ref {
  v8_ref(Handle<void> object, VALUE orig=Qnil);
  virtual ~v8_ref();
  void set(const char *name, VALUE ref);
  Persistent<void> handle;
  VALUE references;
  VALUE origin;
};

/* API */
VALUE v8_ref_new(VALUE obj, Handle<void> handle, VALUE orig=Qnil);
VALUE v8_ref_orig(VALUE obj);
void v8_ref_set(VALUE obj, const char *name, VALUE ref);

/*
 * Gets reference to V8 object from related ruby object, and reflects
 * it to specified type.
 *
 *   v8_ref_get<String>(rb_str_value);
 *   v8_ref_get<Integer>(rb_int_value);
 *
 */
template <class T> Local<T> v8_ref_get(VALUE obj)
{
  v8_ref* r = 0;
  Data_Get_Struct(obj, struct v8_ref, r);
  return (T*)*r->handle;
}

#endif//__V8_REF_H

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mustang-0.2.2 ext/v8/v8_ref.h
mustang-0.2.1 ext/v8/v8_ref.h
mustang-0.2.0 ext/v8/v8_ref.h
mustang-0.1.1 ext/v8/v8_ref.h
mustang-0.1.0 ext/v8/v8_ref.h