comparison tools/gen_v8_binding.m4 @ 659:d4aa1cce0af7

Supporting setter/Getter of index of objects for JS
author Thinker K.F. Li <thinker@branda.to>
date Sun, 01 Aug 2010 11:28:09 +0800
parents 32d0eef1ee46
children dde4e3cc9529
comparison
equal deleted inserted replaced
658:62c2de99b03a 659:d4aa1cce0af7
11 11
12 define([COUNT],[ifelse([$*],[],0,[$#])]) 12 define([COUNT],[ifelse([$*],[],0,[$#])])
13 13
14 define([IMPORT],[define([$1],[$2$1(]$[]@[)])]) 14 define([IMPORT],[define([$1],[$2$1(]$[]@[)])])
15 15
16 define([EXPAND], [$1])
17
16 define([PROJ_PREFIX], [xnjsmb_]) 18 define([PROJ_PREFIX], [xnjsmb_])
17 19
18 define([START_ACCESSOR], [dnl 20 define([START_ACCESSOR], [dnl
19 divert([-1])dnl 21 divert([-1])dnl
20 define([INT], [ 22 define([INT], [
36 38
37 data = (STRUCT_TYPE *)UNWRAP(self); 39 data = (STRUCT_TYPE *)UNWRAP(self);
38 data->$][1 = value->Int32Value(); 40 data->$][1 = value->Int32Value();
39 } 41 }
40 ]) 42 ])
41 define([OBJ], [ 43 define([NUMBER], [
42 static Handle<Value> 44 static Handle<Value>
43 ]PROJ_PREFIX[]STRUCT_NAME[_get_$][1(Local<String> property, const AccessorInfo &info) { 45 ]PROJ_PREFIX[]STRUCT_NAME[_get_$][1(Local<String> property, const AccessorInfo &info) {
44 Handle<Object> self = info.This(); 46 Handle<Object> self = info.This();
45 STRUCT_TYPE *data; 47 STRUCT_TYPE *data;
46 48
47 data = (STRUCT_TYPE *)UNWRAP(self); 49 data = (STRUCT_TYPE *)UNWRAP(self);
48 return ]PROJ_PREFIX[$][2_new(($][3 *)data->$][1); 50 return Number::New(data->$][1);
49 } 51 }
50 52
51 static void 53 static void
52 ]PROJ_PREFIX[]STRUCT_NAME[_set_$][1(Local<String> property, 54 ]PROJ_PREFIX[]STRUCT_NAME[_set_$][1(Local<String> property,
53 Local<Value> value, 55 Local<Value> value,
54 const AccessorInfo &info) { 56 const AccessorInfo &info) {
55 Handle<Object> self = info.This(); 57 Handle<Object> self = info.This();
58 STRUCT_TYPE *data;
59
60 data = (STRUCT_TYPE *)UNWRAP(self);
61 data->$][1 = value->NumberValue();
62 }
63 ])
64 define([OBJ], [
65 static Handle<Value>
66 ]PROJ_PREFIX[]STRUCT_NAME[_get_$][1(Local<String> property, const AccessorInfo &info) {
67 Handle<Object> self = info.This();
68 STRUCT_TYPE *data;
69
70 data = (STRUCT_TYPE *)UNWRAP(self);
71 return ]PROJ_PREFIX[$][2_new(($][3 *)data->$][1);
72 }
73
74 static void
75 ]PROJ_PREFIX[]STRUCT_NAME[_set_$][1(Local<String> property,
76 Local<Value> value,
77 const AccessorInfo &info) {
78 Handle<Object> self = info.This();
56 Handle<Object> obj; 79 Handle<Object> obj;
57 $][3 *v; 80 $][3 *v;
58 STRUCT_TYPE *data; 81 STRUCT_TYPE *data;
59 82
60 data = (STRUCT_TYPE *)UNWRAP(self); 83 data = (STRUCT_TYPE *)UNWRAP(self);
90 ]) 113 ])
91 114
92 define([STOP_ACCESSOR], [dnl 115 define([STOP_ACCESSOR], [dnl
93 divert([-1])dnl 116 divert([-1])dnl
94 undefine([INT]) 117 undefine([INT])
118 undefine([NUMBER])
95 undefine([OBJ]) 119 undefine([OBJ])
96 undefine([STR]) 120 undefine([STR])
97 divert([])dnl 121 divert([])dnl
98 ]) 122 ])
99 123
100 define([SET_ACCESSSOR], [dnl 124 define([SET_ACCESSSOR], [dnl
101 define([INT], [$][1])dnl 125 define([INT], [$][1])dnl
126 define([NUMBER], [$][1])dnl
102 define([OBJ], [$][1])dnl 127 define([OBJ], [$][1])dnl
103 define([STR], [$][1])dnl 128 define([STR], [$][1])dnl
104 inst_temp->SetAccessor(String::New("$1"), 129 inst_temp->SetAccessor(String::New("$1"),
105 PROJ_PREFIX[]STRUCT_NAME[]_get_[]$1, 130 PROJ_PREFIX[]STRUCT_NAME[]_get_[]$1,
106 PROJ_PREFIX[]STRUCT_NAME[]_set_[]$1); 131 PROJ_PREFIX[]STRUCT_NAME[]_set_[]$1);
107 undefine([INT])dnl 132 undefine([INT])dnl
133 undefine([NUMBER])dnl
108 undefine([OBJ])dnl 134 undefine([OBJ])dnl
109 undefine([STR])dnl 135 undefine([STR])dnl
110 ]) 136 ])
111 137
112 define([START_METHOD_ARG_VAR], [dnl 138 define([START_METHOD_ARG_VAR], [dnl
113 define([INT], [dnl 139 define([INT], [dnl
114 int arg_$][1; 140 int arg_$][1;
115 ])dnl 141 ])dnl
142 define([NUMBER], [dnl
143 double arg_$][1;
144 ])dnl
116 define([OBJ], [dnl 145 define([OBJ], [dnl
117 $][2 *arg_$][1; 146 $][2 *arg_$][1;
118 ])dnl 147 ])dnl
119 define([STR], [dnl 148 define([STR], [dnl
120 char *arg_$][1; 149 char *arg_$][1;
125 ]) 154 ])
126 155
127 define([START_METHOD_ARG_TYPE_CHK], [dnl 156 define([START_METHOD_ARG_TYPE_CHK], [dnl
128 define([INT], [ || 157 define([INT], [ ||
129 !args[[i++]]->IsInt32()])dnl 158 !args[[i++]]->IsInt32()])dnl
159 define([NUMBER], [ ||
160 !args[[i++]]->IsNumber()])dnl
130 define([OBJ], [ || 161 define([OBJ], [ ||
131 !args[[i++]]->IsObject()])dnl 162 !args[[i++]]->IsObject()])dnl
132 define([STR], [ || 163 define([STR], [ ||
133 !args[[i++]]->IsString()])dnl 164 !args[[i++]]->IsString()])dnl
134 define([FUNC], [ || 165 define([FUNC], [ ||
137 168
138 define([START_METHOD_ARG_ASSIGN], [dnl 169 define([START_METHOD_ARG_ASSIGN], [dnl
139 define([INT], [dnl 170 define([INT], [dnl
140 arg_$][1 = args[[i++]]->Int32Value(); 171 arg_$][1 = args[[i++]]->Int32Value();
141 ])dnl 172 ])dnl
173 define([NUMBER], [dnl
174 arg_$][1 = args[[i++]]->NumberValue();
175 ])dnl
142 define([OBJ], [dnl 176 define([OBJ], [dnl
143 arg_$][1 = ($][2 *)UNWRAP(args[[i++]]->ToObject()); 177 arg_$][1 = ($][2 *)UNWRAP(args[[i++]]->ToObject());
144 ])dnl 178 ])dnl
145 define([STR], [dnl 179 define([STR], [dnl
146 arg_$][1 = strdup(*String::Utf8Value(args[[i++]]->ToString())); 180 arg_$][1 = strdup(*String::Utf8Value(args[[i++]]->ToString()));
148 define([FUNC], [dnl 182 define([FUNC], [dnl
149 arg_$][1 = args[[i++]].As<Function>(); 183 arg_$][1 = args[[i++]].As<Function>();
150 ])dnl 184 ])dnl
151 ]) 185 ])
152 186
187 define([START_VALUE_ASSIGN], [dnl
188 define([INT], [dnl
189 $1 = $2->Int32Value();
190 ])dnl
191 define([NUMBER], [dnl
192 $1 = $2->NumberValue();
193 ])dnl
194 define([OBJ], [dnl
195 $1 = ($][2 *)UNWRAP($2->ToObject());
196 ])dnl
197 define([STR], [dnl
198 $1 = strdup(*String::Utf8Value($2->ToString()));
199 ])dnl
200 define([FUNC], [dnl
201 $1 = $2.As<Function>();
202 ])dnl
203 ])
204
153 define([START_METHOD_ARG_PASS], [dnl 205 define([START_METHOD_ARG_PASS], [dnl
154 define([INT], [arg_$][1])dnl 206 define([INT], [arg_$][1])dnl
207 define([NUMBER], [arg_$][1])dnl
155 define([OBJ], [arg_$][1])dnl 208 define([OBJ], [arg_$][1])dnl
156 define([STR], [arg_$][1])dnl 209 define([STR], [arg_$][1])dnl
157 define([FUNC], [arg_$][1])dnl 210 define([FUNC], [arg_$][1])dnl
158 ]) 211 ])
159 212
160 define([START_METHOD_RET_VAL], [dnl 213 define([START_METHOD_RET_VAL], [dnl
161 define([INT], [dnl 214 define([INT], [dnl
162 int _ret; 215 int _ret;
163 ])dnl 216 ])dnl
217 define([NUMBER], [dnl
218 double _ret;
219 ])dnl
164 define([OBJ], [dnl 220 define([OBJ], [dnl
165 $][2 *_ret; 221 $][2 *_ret;
166 ])dnl 222 ])dnl
167 define([STR], [dnl 223 define([STR], [dnl
168 char *_ret; 224 char *_ret;
170 define([FUNC], [dnl 226 define([FUNC], [dnl
171 Handle<Function> _ret; 227 Handle<Function> _ret;
172 ])dnl 228 ])dnl
173 ]) 229 ])
174 230
231 define([START_VAR], [dnl
232 define([INT], [dnl
233 int $1;
234 ])dnl
235 define([NUMBER], [dnl
236 double $1;
237 ])dnl
238 define([OBJ], [dnl
239 $][2 *$1;
240 ])dnl
241 define([STR], [dnl
242 char *$1;
243 ])dnl
244 define([FUNC], [dnl
245 Handle<Function> $1;
246 ])dnl
247 ])
248
175 define([START_METHOD_RET_ASSIGN], [dnl 249 define([START_METHOD_RET_ASSIGN], [dnl
176 define([INT], [_ret = (int)])dnl 250 define([INT], [_ret = (int)])dnl
251 define([NUMBER], [_ret = (double)])dnl
177 define([OBJ], [_ret = ($][2 *)])dnl 252 define([OBJ], [_ret = ($][2 *)])dnl
178 define([STR], [_ret = (char *)])dnl 253 define([STR], [_ret = (char *)])dnl
179 define([FUNC], [_ret = ])dnl 254 define([FUNC], [_ret = ])dnl
180 ]) 255 ])
181 256
182 define([START_METHOD_RET], [dnl 257 define([START_METHOD_RET], [dnl
183 define([INT], [ 258 define([INT], [
184 return Integer::New(_ret); 259 return Integer::New(_ret);
185 ])dnl 260 ])dnl
261 define([NUMBER], [
262 return Number::New(_ret);
263 ])dnl
186 define([OBJ], [ 264 define([OBJ], [
187 return PROJ_PREFIX[]$][1[]_new(_ret); 265 return PROJ_PREFIX[]$][1[]_new(_ret);
188 ])dnl 266 ])dnl
189 define([STR], [ 267 define([STR], [
190 return String::New(_ret); 268 return String::New(_ret);
194 ])dnl 272 ])dnl
195 ]) 273 ])
196 274
197 define([STOP_METHOD_ARG], [dnl 275 define([STOP_METHOD_ARG], [dnl
198 undefine([INT])dnl 276 undefine([INT])dnl
277 undefine([NUMBER])dnl
199 undefine([OBJ])dnl 278 undefine([OBJ])dnl
200 undefine([STR])dnl 279 undefine([STR])dnl
201 undefine([FUNC])dnl 280 undefine([FUNC])dnl
202 ]) 281 ])
203 282
240 ])dnl 319 ])dnl
241 $1[]dnl 320 $1[]dnl
242 undefine([METHOD])dnl 321 undefine([METHOD])dnl
243 ]) 322 ])
244 323
324 define([DEF_GET_INDEX], [
325 static Handle<Value>
326 PROJ_PREFIX[]STRUCT_NAME[]_get_index(uint32_t index, const AccessorInfo &info) {
327 Handle<Object> self = info.This();
328 STRUCT_TYPE *obj = (STRUCT_TYPE *)UNWRAP(self);
329 START_METHOD_RET_VAL[]$2[]STOP_METHOD_ARG[]dnl
330
331 _ret = $1(obj, index);
332 START_METHOD_RET[]$2[]STOP_METHOD_ARG[]dnl
333 }
334 ])
335
336 define([DEF_SET_INDEX], [
337 static Handle<Value>
338 PROJ_PREFIX[]STRUCT_NAME[]_set_index(uint32_t index, Local<Value> value,
339 const AccessorInfo &info) {
340 Handle<Object> self = info.This();
341 STRUCT_TYPE *obj = (STRUCT_TYPE *)UNWRAP(self);
342 START_VAR([in_value])[]$2[]STOP_METHOD_ARG[]dnl
343 START_METHOD_RET_VAL[]$2[]STOP_METHOD_ARG[]dnl
344
345 START_VALUE_ASSIGN(in_value, value)[]$2[]STOP_METHOD_ARG[]dnl
346 _ret = $1(obj, index, in_value);
347 START_METHOD_RET[]$2[]STOP_METHOD_ARG[]dnl
348 }
349 ])
350
351 define([INSTALL_INDEX_FUNCTIONS],[])
352
245 dnl 353 dnl
246 dnl STRUCT(struct_name, struct_type, member_vars, methods) 354 dnl STRUCT(struct_name, struct_type, member_vars, methods)
247 dnl 355 dnl
248 define([STRUCT], [dnl 356 define([STRUCT], [dnl
249 define([STRUCT_NAME], [$1])dnl 357 define([STRUCT_NAME], [$1])dnl
250 define([STRUCT_TYPE], [$2])dnl 358 define([STRUCT_TYPE], [$2])dnl
359 dnl
360 ifelse([$5], [], [], [foreach([ITER], $5, [EXPAND([define]ITER)])])dnl
361 dnl
251 [ 362 [
252 /* ************************************************** 363 /* **************************************************
253 * STRUCT: $1 364 * STRUCT: $1
254 * Generated by gen_v8_binding.m4 365 * Generated by gen_v8_binding.m4
255 */ 366 */
271 return obj; 382 return obj;
272 } 383 }
273 ]dnl 384 ]dnl
274 foreach([ITER], ($3), [START_ACCESSOR ITER STOP_ACCESSOR])dnl 385 foreach([ITER], ($3), [START_ACCESSOR ITER STOP_ACCESSOR])dnl
275 foreach([ITER], ($4), [START_METHOD ITER STOP_METHOD])dnl 386 foreach([ITER], ($4), [START_METHOD ITER STOP_METHOD])dnl
387 ifdef([GET_INDEX], [EXPAND([DEF_GET_INDEX]GET_INDEX)])dnl
388 ifdef([SET_INDEX], [EXPAND([DEF_SET_INDEX]SET_INDEX)])dnl
276 [ 389 [
277 static void 390 static void
278 ]PROJ_PREFIX[$1][_init(void) { 391 ]PROJ_PREFIX[$1][_init(void) {
279 Handle<FunctionTemplate> func_temp; 392 Handle<FunctionTemplate> func_temp;
280 Handle<ObjectTemplate> inst_temp; 393 Handle<ObjectTemplate> inst_temp;
285 inst_temp = func_temp->InstanceTemplate(); 398 inst_temp = func_temp->InstanceTemplate();
286 inst_temp->SetInternalFieldCount(1); 399 inst_temp->SetInternalFieldCount(1);
287 ] 400 ]
288 foreach([ITER], ($3), [SET_ACCESSSOR(ITER)])dnl 401 foreach([ITER], ($3), [SET_ACCESSSOR(ITER)])dnl
289 inst_temp = func_temp->InstanceTemplate(); 402 inst_temp = func_temp->InstanceTemplate();
403 INSTALL_INDEX_FUNCTIONS[]dnl
290 404
291 foreach([ITER], ($4), [SET_METHOD(ITER)])dnl 405 foreach([ITER], ($4), [SET_METHOD(ITER)])dnl
292 406
293 PROJ_PREFIX[$1][_temp = Persistent<FunctionTemplate>::New(func_temp); 407 PROJ_PREFIX[$1][_temp = Persistent<FunctionTemplate>::New(func_temp);
294 }]dnl 408 }]dnl
409 dnl
410 ifelse([$5], [], [], [foreach([ITER], $5, [dnl
411 define([DUMMY], [undefine]ITER)dnl
412 DUMMY[]dnl
413 undefine([DUMMY])])dnl
414 ])dnl
415 dnl
295 ]) 416 ])
296 417
297 dnl 418 dnl
298 dnl FUNCTION(func_name, real_func, arguments, arguement_count, return_type) 419 dnl FUNCTION(func_name, real_func, arguments, arguement_count, return_type)
299 dnl 420 dnl