Mercurial > MadButterfly
changeset 649:2030e5d9f7f7
Support return value for methodes of JS binding
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Thu, 29 Jul 2010 01:37:15 +0800 |
parents | e13dbfd37eab |
children | 123e7eeff10c |
files | nodejs/observer.m4 tools/gen_v8_binding.m4 |
diffstat | 2 files changed, 47 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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, [])])
--- 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<Function> _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<Object> 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 ])