Mercurial > MadButterfly
comparison tools/gen_v8_binding.m4 @ 664:08fd45d119c9
Binding generator supports self-init constructor function
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Wed, 04 Aug 2010 21:33:06 +0800 |
parents | 974d98233eab |
children | 916dc9723086 |
comparison
equal
deleted
inserted
replaced
663:974d98233eab | 664:08fd45d119c9 |
---|---|
270 define([FUNC], [_ret = ])dnl | 270 define([FUNC], [_ret = ])dnl |
271 ]) | 271 ]) |
272 | 272 |
273 define([START_METHOD_RET], [dnl | 273 define([START_METHOD_RET], [dnl |
274 define([INT], [ | 274 define([INT], [ |
275 return Integer::New(_ret); | 275 _ret_val = Integer::New(_ret); |
276 ])dnl | 276 ])dnl |
277 define([NUMBER], [ | 277 define([NUMBER], [ |
278 return Number::New(_ret); | 278 _ret_val = Number::New(_ret); |
279 ])dnl | 279 ])dnl |
280 define([OBJ], [ | 280 define([OBJ], [ |
281 return PROJ_PREFIX[]$][1[]_new(_ret); | 281 _ret_val = PROJ_PREFIX[]$][1[]_new(_ret); |
282 ])dnl | 282 ])dnl |
283 define([STR], [ | 283 define([STR], [ |
284 return String::New(_ret); | 284 _ret_val = String::New(_ret); |
285 ])dnl | 285 ])dnl |
286 define([FUNC], [ | 286 define([FUNC], [ |
287 return _ret; | 287 _rt_val = _ret; |
288 ])dnl | 288 ])dnl |
289 ]) | 289 ]) |
290 | 290 |
291 define([STOP_METHOD_ARG], [dnl | 291 define([STOP_METHOD_ARG], [dnl |
292 undefine([INT])dnl | 292 undefine([INT])dnl |
297 undefine([SELF])dnl | 297 undefine([SELF])dnl |
298 undefine([ERR])dnl | 298 undefine([ERR])dnl |
299 ]) | 299 ]) |
300 | 300 |
301 define([START_METHOD], [dnl | 301 define([START_METHOD], [dnl |
302 dnl | |
303 dnl METHOD(name, func, arguments, cnt, ret_type, options) | |
304 dnl | |
302 define([METHOD], [ | 305 define([METHOD], [ |
306 dnl | |
307 ifelse($][6, [], [], [dnl | |
308 foreach([ITER], ]$][6[, [EXPAND([define]ITER)])dnl | |
309 ])dnl | |
310 dnl | |
303 static Handle<Value> | 311 static Handle<Value> |
304 PROJ_PREFIX[]STRUCT_NAME[]_$][1(const Arguments &args) { | 312 PROJ_PREFIX[]STRUCT_NAME[]_$][1(const Arguments &args) { |
305 int i; | 313 int i; |
306 int argc = args.Length(); | 314 int argc = args.Length(); |
307 Handle<Object> self = args.This(); | 315 Handle<Object> self = args.This(); |
308 STRUCT_TYPE *_self = (STRUCT_TYPE *)UNWRAP(self); | 316 STRUCT_TYPE *_self = (STRUCT_TYPE *)UNWRAP(self); |
309 const char *_err = NULL; | 317 const char *_err = NULL; |
310 foreach([ITER], $][3, [START_METHOD_ARG_VAR[]ITER[]STOP_METHOD_ARG])dnl | 318 foreach([ITER], $][3, [START_METHOD_ARG_VAR[]ITER[]STOP_METHOD_ARG])dnl |
311 START_METHOD_RET_VAL[]$][5[]STOP_METHOD_ARG | 319 START_METHOD_RET_VAL[]$][5[]STOP_METHOD_ARG |
320 Handle<Value> _ret_val; | |
312 | 321 |
313 if(argc != $][4) | 322 if(argc != $][4) |
314 THROW("Invalid number of arguments (!=$][4)"); | 323 THROW("Invalid number of arguments (!=$][4)"); |
315 i = 0; | 324 i = 0; |
316 if(0[]dnl | 325 if(0[]dnl |
324 if(_err) | 333 if(_err) |
325 THROW(_err); | 334 THROW(_err); |
326 START_METHOD_RET[]$][5[]STOP_METHOD_ARG[]dnl | 335 START_METHOD_RET[]$][5[]STOP_METHOD_ARG[]dnl |
327 ifelse($][5, [], [ | 336 ifelse($][5, [], [ |
328 return Null(); | 337 return Null(); |
329 ])dnl | 338 ], [dnl |
330 } | 339 dnl |
340 dnl Modify returned object | |
341 dnl | |
342 ifdef([MOD], [ | |
343 MOD[](self, _ret_val); | |
344 ])dnl | |
345 return _ret_val; | |
346 ])dnl | |
347 } | |
348 ifelse($][6, [], [], [dnl | |
349 foreach([ITER], ]$][6[, [EXPAND([undefine]ITER)])dnl | |
350 ])dnl | |
331 ])dnl | 351 ])dnl |
332 ]) | 352 ]) |
333 | 353 |
334 define([STOP_METHOD], [undefine([METHOD])]) | 354 define([STOP_METHOD], [undefine([METHOD])]) |
335 | 355 |
386 inst_temp->SetIndexedPropertyHandler(PROJ_PREFIX[]STRUCT_NAME[]_get_index); | 406 inst_temp->SetIndexedPropertyHandler(PROJ_PREFIX[]STRUCT_NAME[]_get_index); |
387 ])])dnl | 407 ])])dnl |
388 undefine([FIRST])dnl | 408 undefine([FIRST])dnl |
389 ]) | 409 ]) |
390 | 410 |
391 dnl | 411 define([CTOR_INTERNAL], [dnl |
392 dnl STRUCT(struct_name, struct_type, member_vars, methods) | 412 int argc = args.Length(); |
413 Handle<Object> self = args.This(); | |
414 $4 *obj; | |
415 foreach([ITER], $2, [START_METHOD_ARG_VAR[]ITER[]STOP_METHOD_ARG])dnl | |
416 int i; | |
417 | |
418 if(argc != $3) | |
419 THROW("Invalid number of arguments (!=$][4)"); | |
420 i = 0; | |
421 if(0]dnl | |
422 [foreach([ITER], $2, [START_METHOD_ARG_TYPE_CHK[]ITER[]STOP_METHOD_ARG])) | |
423 THROW("Invalid argument type"); | |
424 | |
425 i = 0; | |
426 foreach([ITER], $2, [START_METHOD_ARG_ASSIGN[]ITER[]STOP_METHOD_ARG])dnl | |
427 | |
428 define([SEP], [])dnl | |
429 obj = ($4 *)$1(foreach([ITER], $2, [START_METHOD_ARG_PASS[]SEP[]ITER[]STOP_METHOD_ARG[]define([SEP], [, ])]));[]undefine([SEP]) | |
430 | |
431 WRAP(self, obj); | |
432 ]) | |
433 | |
434 dnl | |
435 dnl STRUCT(struct_name, struct_type, member_vars, methods, options) | |
393 dnl | 436 dnl |
394 define([STRUCT], [dnl | 437 define([STRUCT], [dnl |
395 define([STRUCT_NAME], [$1])dnl | 438 define([STRUCT_NAME], [$1])dnl |
396 define([STRUCT_TYPE], [$2])dnl | 439 define([STRUCT_TYPE], [$2])dnl |
397 dnl | 440 dnl |
398 ifelse([$5], [], [], [foreach([ITER], $5, [EXPAND([define]ITER)])])dnl | 441 ifelse([$5], [], [], [dnl |
442 foreach([ITER], $5, [dnl | |
443 EXPAND([define]ITER)[]dnl | |
444 ])dnl | |
445 ])dnl | |
399 dnl | 446 dnl |
400 [ | 447 [ |
401 /* ************************************************** | 448 /* ************************************************** |
402 * STRUCT: $1 | 449 * STRUCT: $1 |
403 * Generated by gen_v8_binding.m4 | 450 * Generated by gen_v8_binding.m4 |
404 */ | 451 */ |
405 static Handle<Value> | 452 static Handle<Value> |
406 ]PROJ_PREFIX[$1(const Arguments &args) { | 453 ]PROJ_PREFIX[$1(const Arguments &args) { |
407 } | 454 ]ifdef([CTOR], [EXPAND([CTOR_INTERNAL](EXPAND([UNQUOTE]CTOR), [$2]))])dnl |
455 return Null(); | |
456 [} | |
408 | 457 |
409 static Persistent<FunctionTemplate> ]PROJ_PREFIX[$1][_temp; | 458 static Persistent<FunctionTemplate> ]PROJ_PREFIX[$1][_temp; |
410 | 459 |
411 static Handle<Value> | 460 static Handle<Value> |
412 ]PROJ_PREFIX[$1][_new($2 *data) { | 461 ]PROJ_PREFIX[$1][_new($2 *data) { |