comparison tools/gen_v8_binding.m4 @ 682:4a38e571cfce

Add ARRAY argument type and INHERIT supporting for STRUCT
author Thinker K.F. Li <thinker@branda.to>
date Sat, 07 Aug 2010 18:26:19 +0800
parents 40ba8915edc7
children 00a8c8a9e157
comparison
equal deleted inserted replaced
681:b601a4d6f7d1 682:4a38e571cfce
97 97
98 data = (STRUCT_TYPE *)UNWRAP(self); 98 data = (STRUCT_TYPE *)UNWRAP(self);
99 obj = value->ToObject(); 99 obj = value->ToObject();
100 v = ($][3 *)UNWRAP(obj); 100 v = ($][3 *)UNWRAP(obj);
101 data->$][1 = v; 101 data->$][1 = v;
102 }
103 ])
104 fdefine([ARRAY], [
105 static Handle<Value>
106 ]PROJ_PREFIX[]STRUCT_NAME[_get_$][1(Local<String> property, const AccessorInfo &info) {
107 Handle<Object> self = info.This();
108 STRUCT_TYPE *data;
109
110 data = (STRUCT_TYPE *)UNWRAP(self);
111 return data->$][1;
112 }
113
114 static void
115 ]PROJ_PREFIX[]STRUCT_NAME[_set_$][1(Local<String> property,
116 Local<Value> value,
117 const AccessorInfo &info) {
118 Handle<Object> self = info.This();
119 Handle<Object> obj;
120 STRUCT_TYPE *data;
121
122 data = (STRUCT_TYPE *)UNWRAP(self);
123 data->$][1 = value;
102 } 124 }
103 ]) 125 ])
104 fdefine([STR], [ 126 fdefine([STR], [
105 static Handle<Value> 127 static Handle<Value>
106 ]PROJ_PREFIX[]STRUCT_NAME[_get_$][1(Local<String> property, const AccessorInfo &info) { 128 ]PROJ_PREFIX[]STRUCT_NAME[_get_$][1(Local<String> property, const AccessorInfo &info) {
168 define([SET_ACCESSSOR], [dnl 190 define([SET_ACCESSSOR], [dnl
169 VARFRAME[]dnl 191 VARFRAME[]dnl
170 fdefine([INT], [$][1])dnl 192 fdefine([INT], [$][1])dnl
171 fdefine([NUMBER], [$][1])dnl 193 fdefine([NUMBER], [$][1])dnl
172 fdefine([OBJ], [$][1])dnl 194 fdefine([OBJ], [$][1])dnl
195 fdefine([ARRAY], [$][1])dnl
173 fdefine([STR], [$][1])dnl 196 fdefine([STR], [$][1])dnl
174 fdefine([ACCESSOR], [$][1])dnl 197 fdefine([ACCESSOR], [$][1])dnl
175 inst_temp->SetAccessor(String::New("$1"), 198 inst_temp->SetAccessor(String::New("$1"),
176 PROJ_PREFIX[]STRUCT_NAME[]_get_[]$1, 199 PROJ_PREFIX[]STRUCT_NAME[]_get_[]$1,
177 PROJ_PREFIX[]STRUCT_NAME[]_set_[]$1); 200 PROJ_PREFIX[]STRUCT_NAME[]_set_[]$1);
187 double arg_$][1; 210 double arg_$][1;
188 ])dnl 211 ])dnl
189 fdefine([OBJ], [dnl 212 fdefine([OBJ], [dnl
190 $][3 *arg_$][1; 213 $][3 *arg_$][1;
191 ])dnl 214 ])dnl
215 fdefine([ARRAY], [dnl
216 Handle<Value> arg_$][1;
217 ])dnl
192 fdefine([STR], [dnl 218 fdefine([STR], [dnl
193 char *arg_$][1; 219 char *arg_$][1;
194 ])dnl 220 ])dnl
195 fdefine([FUNC], [dnl 221 fdefine([FUNC], [dnl
196 Handle<Function> arg_$][1; 222 Handle<Function> arg_$][1;
205 !args[[i++]]->IsInt32()])dnl 231 !args[[i++]]->IsInt32()])dnl
206 fdefine([NUMBER], [ || 232 fdefine([NUMBER], [ ||
207 !args[[i++]]->IsNumber()])dnl 233 !args[[i++]]->IsNumber()])dnl
208 fdefine([OBJ], [ || 234 fdefine([OBJ], [ ||
209 !args[[i++]]->IsObject()])dnl 235 !args[[i++]]->IsObject()])dnl
236 fdefine([ARRAY], [ ||
237 !args[[i++]]->IsArray()])dnl
210 fdefine([STR], [ || 238 fdefine([STR], [ ||
211 !args[[i++]]->IsString()])dnl 239 !args[[i++]]->IsString()])dnl
212 fdefine([FUNC], [ || 240 fdefine([FUNC], [ ||
213 !args[[i++]]->IsFunction()])dnl 241 !args[[i++]]->IsFunction()])dnl
214 fdefine([SELF], [])dnl 242 fdefine([SELF], [])dnl
218 define([START_TYPE_CHK], [dnl 246 define([START_TYPE_CHK], [dnl
219 VARFRAME[]dnl 247 VARFRAME[]dnl
220 fdefine([INT], [$1->IsInt32()])dnl 248 fdefine([INT], [$1->IsInt32()])dnl
221 fdefine([NUMBER], [$1->IsNumber()])dnl 249 fdefine([NUMBER], [$1->IsNumber()])dnl
222 fdefine([OBJ], [$1->IsObject()])dnl 250 fdefine([OBJ], [$1->IsObject()])dnl
251 fdefine([ARRAY], [$1->IsArray()])dnl
223 fdefine([STR], [$1->IsString()])dnl 252 fdefine([STR], [$1->IsString()])dnl
224 fdefine([FUNC], [$1->IsFunction()])dnl 253 fdefine([FUNC], [$1->IsFunction()])dnl
225 ]) 254 ])
226 255
227 define([START_METHOD_ARG_ASSIGN], [dnl 256 define([START_METHOD_ARG_ASSIGN], [dnl
233 arg_$][1 = args[[i++]]->NumberValue(); 262 arg_$][1 = args[[i++]]->NumberValue();
234 ])dnl 263 ])dnl
235 fdefine([OBJ], [dnl 264 fdefine([OBJ], [dnl
236 arg_$][1 = ($][3 *)UNWRAP(args[[i++]]->ToObject()); 265 arg_$][1 = ($][3 *)UNWRAP(args[[i++]]->ToObject());
237 ])dnl 266 ])dnl
267 fdefine([ARRAY], [dnl
268 arg_$][1 = args[[i++]];
269 ])dnl
238 fdefine([STR], [dnl 270 fdefine([STR], [dnl
239 arg_$][1 = strdup(*String::Utf8Value(args[[i++]]->ToString())); 271 arg_$][1 = strdup(*String::Utf8Value(args[[i++]]->ToString()));
240 ])dnl 272 ])dnl
241 fdefine([FUNC], [dnl 273 fdefine([FUNC], [dnl
242 arg_$][1 = args[[i++]].As<Function>(); 274 arg_$][1 = args[[i++]].As<Function>();
253 fdefine([NUMBER], [dnl 285 fdefine([NUMBER], [dnl
254 $1 = $2->NumberValue(); 286 $1 = $2->NumberValue();
255 ])dnl 287 ])dnl
256 fdefine([OBJ], [dnl 288 fdefine([OBJ], [dnl
257 $1 = ($][2 *)UNWRAP($2->ToObject()); 289 $1 = ($][2 *)UNWRAP($2->ToObject());
290 ])dnl
291 fdefine([ARRAY], [dnl
292 $1 = $2;
258 ])dnl 293 ])dnl
259 fdefine([STR], [dnl 294 fdefine([STR], [dnl
260 $1 = strdup(*String::Utf8Value($2->ToString())); 295 $1 = strdup(*String::Utf8Value($2->ToString()));
261 ])dnl 296 ])dnl
262 fdefine([FUNC], [dnl 297 fdefine([FUNC], [dnl
267 define([START_METHOD_ARG_PASS], [dnl 302 define([START_METHOD_ARG_PASS], [dnl
268 VARFRAME[]dnl 303 VARFRAME[]dnl
269 fdefine([INT], [arg_$][1])dnl 304 fdefine([INT], [arg_$][1])dnl
270 fdefine([NUMBER], [arg_$][1])dnl 305 fdefine([NUMBER], [arg_$][1])dnl
271 fdefine([OBJ], [arg_$][1])dnl 306 fdefine([OBJ], [arg_$][1])dnl
307 fdefine([ARRAY], [arg_$][1])dnl
272 fdefine([STR], [arg_$][1])dnl 308 fdefine([STR], [arg_$][1])dnl
273 fdefine([FUNC], [arg_$][1])dnl 309 fdefine([FUNC], [arg_$][1])dnl
274 fdefine([SELF], [self])dnl 310 fdefine([SELF], [self])dnl
275 fdefine([ERR], [&_err])dnl 311 fdefine([ERR], [&_err])dnl
276 fdefine([VAL], [&_err])dnl 312 fdefine([VAL], [&_err])dnl
285 double _ret; 321 double _ret;
286 ])dnl 322 ])dnl
287 fdefine([OBJ], [dnl 323 fdefine([OBJ], [dnl
288 $][2 *_ret; 324 $][2 *_ret;
289 ])dnl 325 ])dnl
326 fdefine([ARRAY], [dnl
327 Handle<Value> _ret;
328 ])dnl
290 fdefine([STR], [dnl 329 fdefine([STR], [dnl
291 char *_ret; 330 char *_ret;
292 ])dnl 331 ])dnl
293 fdefine([FUNC], [dnl 332 fdefine([FUNC], [dnl
294 Handle<Function> _ret; 333 Handle<Function> _ret;
306 fdefine([NUMBER], [dnl 345 fdefine([NUMBER], [dnl
307 double $1; 346 double $1;
308 ])dnl 347 ])dnl
309 fdefine([OBJ], [dnl 348 fdefine([OBJ], [dnl
310 $][2 *$1; 349 $][2 *$1;
350 ])dnl
351 fdefine([ARRAY], [dnl
352 Handle<Value> *$1;
311 ])dnl 353 ])dnl
312 fdefine([STR], [dnl 354 fdefine([STR], [dnl
313 char *$1; 355 char *$1;
314 ])dnl 356 ])dnl
315 fdefine([FUNC], [dnl 357 fdefine([FUNC], [dnl
320 define([START_METHOD_RET_ASSIGN], [dnl 362 define([START_METHOD_RET_ASSIGN], [dnl
321 VARFRAME[]dnl 363 VARFRAME[]dnl
322 fdefine([INT], [_ret = (int)])dnl 364 fdefine([INT], [_ret = (int)])dnl
323 fdefine([NUMBER], [_ret = (double)])dnl 365 fdefine([NUMBER], [_ret = (double)])dnl
324 fdefine([OBJ], [_ret = ($][2 *)])dnl 366 fdefine([OBJ], [_ret = ($][2 *)])dnl
367 fdefine([ARRAY], [_ret = ])dnl
325 fdefine([STR], [_ret = (char *)])dnl 368 fdefine([STR], [_ret = (char *)])dnl
326 fdefine([FUNC], [_ret = ])dnl 369 fdefine([FUNC], [_ret = ])dnl
327 fdefine([VAL], [_ret = ])dnl 370 fdefine([VAL], [_ret = ])dnl
328 ]) 371 ])
329 372
336 _ret_val = Number::New(_ret); 379 _ret_val = Number::New(_ret);
337 ])dnl 380 ])dnl
338 fdefine([OBJ], [ 381 fdefine([OBJ], [
339 _ret_val = PROJ_PREFIX[]$][1[]_new(_ret); 382 _ret_val = PROJ_PREFIX[]$][1[]_new(_ret);
340 ])dnl 383 ])dnl
384 fdefine([ARRAY], [
385 _ret_val = _ret;
386 ])dnl
341 fdefine([STR], [ 387 fdefine([STR], [
342 _ret_val = String::New(_ret); 388 _ret_val = String::New(_ret);
343 ])dnl 389 ])dnl
344 fdefine([FUNC], [ 390 fdefine([FUNC], [
345 _rt_val = _ret; 391 _rt_val = _ret;
356 define([START_METHOD], [dnl 402 define([START_METHOD], [dnl
357 dnl 403 dnl
358 dnl METHOD(name, func, arguments, cnt, ret_type, options) 404 dnl METHOD(name, func, arguments, cnt, ret_type, options)
359 dnl 405 dnl
360 define([METHOD], [ 406 define([METHOD], [
407 VARFRAME[]dnl
361 dnl 408 dnl
362 ifelse($][6, [], [], [dnl 409 ifelse($][6, [], [], [dnl
363 foreach([ITER], ]$][6[, [EXPAND([define]ITER)])dnl 410 foreach([ITER], ]$][6[, [EXPAND([fdefine]ITER)])dnl
364 ])dnl 411 ])dnl
365 dnl 412 dnl
366 static Handle<Value> 413 static Handle<Value>
367 PROJ_PREFIX[]STRUCT_NAME[]_$][1(const Arguments &args) { 414 PROJ_PREFIX[]STRUCT_NAME[]_$][1(const Arguments &args) {
368 HandleScope scope; 415 HandleScope scope;
400 ])dnl 447 ])dnl
401 scope.Close(_ret_val); 448 scope.Close(_ret_val);
402 return _ret_val; 449 return _ret_val;
403 ])dnl 450 ])dnl
404 } 451 }
405 ifelse($][6, [], [], [dnl 452 UNVARFRAME[]dnl
406 foreach([ITER], ]$][6[, [EXPAND([undefine]ITER)])dnl
407 ])dnl
408 ])dnl 453 ])dnl
409 ]) 454 ])
410 455
411 define([STOP_METHOD], [undefine([METHOD])]) 456 define([STOP_METHOD], [undefine([METHOD])])
412 457
547 Handle<ObjectTemplate> inst_temp; 592 Handle<ObjectTemplate> inst_temp;
548 Handle<ObjectTemplate> proto_temp; 593 Handle<ObjectTemplate> proto_temp;
549 594
550 func_temp = FunctionTemplate::New(]PROJ_PREFIX[$1); 595 func_temp = FunctionTemplate::New(]PROJ_PREFIX[$1);
551 func_temp->SetClassName(String::New("]STRUCT_NAME[")); 596 func_temp->SetClassName(String::New("]STRUCT_NAME["));
552 inst_temp = func_temp->InstanceTemplate(); 597 ]ifdef([INHERIT], [dnl
598 func_temp->Inherit(]PROJ_PREFIX[]INHERIT[_temp);
599 ])dnl
600 [ inst_temp = func_temp->InstanceTemplate();
553 inst_temp->SetInternalFieldCount(1); 601 inst_temp->SetInternalFieldCount(1);
554 ] 602 ]foreach([ITER], ($3), [SET_ACCESSSOR(ITER)])dnl
555 foreach([ITER], ($3), [SET_ACCESSSOR(ITER)])dnl
556 INSTALL_INDEX_FUNCTIONS[]dnl 603 INSTALL_INDEX_FUNCTIONS[]dnl
557 604
558 proto_temp = func_temp->PrototypeTemplate(); 605 proto_temp = func_temp->PrototypeTemplate();
559 foreach([ITER], ($4), [SET_METHOD(ITER)])dnl 606 foreach([ITER], ($4), [SET_METHOD(ITER)])dnl
560 607