# HG changeset patch # User Thinker K.F. Li # Date 1280338635 -28800 # Node ID 2030e5d9f7f730f430846e678aa525647717c445 # Parent e13dbfd37eab728e8395974982b6cb7f1588a73b Support return value for methodes of JS binding diff -r e13dbfd37eab -r 2030e5d9f7f7 nodejs/observer.m4 --- a/nodejs/observer.m4 Thu Jul 29 01:02:29 2010 +0800 +++ b/nodejs/observer.m4 Thu Jul 29 01:37:15 2010 +0800 @@ -7,6 +7,7 @@ STRUCT([subject], [subject_t], [], [METHOD([add_event_observer], [subject_add_event_observer], - (INT([type]), FUNC([handler])), 2), + (INT([type]), FUNC([handler])), 2, + [OBJ([observer], [observer_t])]), METHOD([remove_observer], [subject_remove_observer], - (OBJ([observer], [observer_t])), 1)]) + (OBJ([observer], [observer_t])), 1, [])]) diff -r e13dbfd37eab -r 2030e5d9f7f7 tools/gen_v8_binding.m4 --- a/tools/gen_v8_binding.m4 Thu Jul 29 01:02:29 2010 +0800 +++ b/tools/gen_v8_binding.m4 Thu Jul 29 01:37:15 2010 +0800 @@ -134,6 +134,43 @@ define([FUNC], [$][1])dnl ]) +define([START_METHOD_RET_VAL], [dnl +define([INT], [ + int _ret; +])dnl +define([OBJ], [ + $][2 *_ret; +])dnl +define([STR], [ + char *_ret; +])dnl +define([FUNC], [ + Handle _ret; +])dnl +]) + +define([START_METHOD_RET_ASSIGN], [dnl +define([INT], [_ret = ])dnl +define([OBJ], [_ret = ])dnl +define([STR], [_ret = ])dnl +define([FUNC], [_ret = ])dnl +]) + +define([START_METHOD_RET], [dnl +define([INT], [ + return Integer::New(_ret); +])dnl +define([OBJ], [ + return PROJ_PREFIX[]STRUCT_NAME[]_$][1[]_new(_ret); +])dnl +define([STR], [ + return String::New(_ret); +])dnl +define([FUNC], [ + return _ret; +])dnl +]) + define([STOP_METHOD_ARG], [dnl undefine([INT])dnl undefine([OBJ])dnl @@ -149,7 +186,8 @@ int argc = args.Length(); Handle self = args.This(); STRUCT_TYPE *_self = (STRUCT_TYPE *)UNWRAP(self); -foreach([ITER], $][3, [START_METHOD_ARG_VAR[]ITER[]STOP_METHOD_ARG]) +foreach([ITER], $][3, [START_METHOD_ARG_VAR[]ITER[]STOP_METHOD_ARG])dnl +START_METHOD_RET_VAL[]$][5[]STOP_METHOD_ARG if(argc != $][4) THROW("Invalid number of arguments (!=$][4)"); @@ -161,7 +199,11 @@ i = 0; foreach([ITER], $][3, [START_METHOD_ARG_ASSIGN[]ITER[]STOP_METHOD_ARG])) - $][2(_self[]foreach([ITER], $][3, [START_METHOD_ARG_PASS[], ITER[]STOP_METHOD_ARG])); + START_METHOD_RET_ASSIGN[]$][5[]STOP_METHOD_ARG[]$][2(_self[]foreach([ITER], $][3, [START_METHOD_ARG_PASS[], ITER[]STOP_METHOD_ARG])); +START_METHOD_RET[]$][5[]STOP_METHOD_ARG[]dnl +ifelse($][5, [], [ + return Null(); +])dnl } ])dnl ])