changeset 674:5c8387fd123e

Support user defined accessors on binding generated
author Thinker K.F. Li <thinker@branda.to>
date Fri, 06 Aug 2010 00:50:40 +0800
parents f5d2ff34c6f6
children c643af2095c5
files tools/gen_v8_binding.m4
diffstat 1 files changed, 35 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/tools/gen_v8_binding.m4	Thu Aug 05 23:33:46 2010 +0800
+++ b/tools/gen_v8_binding.m4	Fri Aug 06 00:50:40 2010 +0800
@@ -109,6 +109,38 @@
     data->$][1 = strdup(*utf8);
 }
 ])
+dnl
+dnl ACCESSOR(name, getter, setter)
+dnl
+  define([ACCESSOR], [
+static Handle<Value>
+]PROJ_PREFIX[]STRUCT_NAME[_get_$][1(Local<String> property, const AccessorInfo &info) {
+    Handle<Object> self = info.This();
+    Handle<Value> _ret;
+    STRUCT_TYPE *data;
+    const char *err = NULL;
+
+    data = (STRUCT_TYPE *)UNWRAP(self);
+    _ret = $][2(self, data, &err);
+    if(err)
+	THROW(err);
+    return _ret;
+}
+
+static void
+]PROJ_PREFIX[]STRUCT_NAME[_set_$][1(Local<String> property,
+		      Local<Value> value,
+		      const AccessorInfo &info) {
+    Handle<Object> self = info.This();
+    STRUCT_TYPE *data;
+    const char *err = NULL;
+
+    data = (STRUCT_TYPE *)UNWRAP(self);
+    $][3(self, data, value, &err);
+    if(err)
+	THROW_noret(err);
+}
+])
 divert([])dnl
 ])
 
@@ -118,6 +150,7 @@
 undefine([NUMBER])
 undefine([OBJ])
 undefine([STR])
+undefine([ACCESSOR])
 divert([])dnl
 ])
 
@@ -126,6 +159,7 @@
 define([NUMBER], [$][1])dnl
 define([OBJ], [$][1])dnl
 define([STR], [$][1])dnl
+define([ACCESSOR], [$][1])dnl
     inst_temp->SetAccessor(String::New("$1"),
 			   PROJ_PREFIX[]STRUCT_NAME[]_get_[]$1,
 			   PROJ_PREFIX[]STRUCT_NAME[]_set_[]$1);
@@ -133,6 +167,7 @@
 undefine([NUMBER])dnl
 undefine([OBJ])dnl
 undefine([STR])dnl
+undefine([ACCESSOR])dnl
 ])
 
 define([START_METHOD_ARG_VAR], [dnl