Mercurial > MadButterfly
changeset 650:123e7eeff10c
Generate JS binding for a function
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Thu, 29 Jul 2010 13:07:25 +0800 |
parents | 2030e5d9f7f7 |
children | aa52883534fc |
files | nodejs/observer.m4 tools/gen_v8_binding.m4 |
diffstat | 2 files changed, 56 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/nodejs/observer.m4 Thu Jul 29 01:37:15 2010 +0800 +++ b/nodejs/observer.m4 Thu Jul 29 13:07:25 2010 +0800 @@ -11,3 +11,5 @@ [OBJ([observer], [observer_t])]), METHOD([remove_observer], [subject_remove_observer], (OBJ([observer], [observer_t])), 1, [])]) + +FUNCTION([load], [my_load], [INT(sz), STR(name)], 2, [OBJ([test],[test_t])])
--- a/tools/gen_v8_binding.m4 Thu Jul 29 01:37:15 2010 +0800 +++ b/tools/gen_v8_binding.m4 Thu Jul 29 13:07:25 2010 +0800 @@ -96,13 +96,13 @@ define([START_METHOD_ARG_VAR], [dnl define([INT], [dnl - int $][1];)dnl + int arg_$][1];)dnl define([OBJ], [dnl - $][2 *$][1];)dnl + $][2 *arg_$][1];)dnl define([STR], [dnl - char *$][1];)dnl + char *arg_$][1];)dnl define([FUNC], [ - Handle<Function> $][1];)dnl + Handle<Function> arg_$][1];)dnl ]) define([START_METHOD_ARG_TYPE_CHK], [dnl @@ -118,20 +118,20 @@ define([START_METHOD_ARG_ASSIGN], [dnl define([INT], [ - $][1 = args[[i++]]->Int32Value();])dnl + arg_$][1 = args[[i++]]->Int32Value();])dnl define([OBJ], [ - $][1 = ($][2 *)UNWRAP(args[[i++]]->ToObject());])dnl + arg_$][1 = ($][2 *)UNWRAP(args[[i++]]->ToObject());])dnl define([STR], [ - $][1 = strdup(*String::Utf8Value(args[[i++]]->ToString()));])dnl + arg_$][1 = strdup(*String::Utf8Value(args[[i++]]->ToString()));])dnl define([FUNC], [ - $][1 = Function::Cast(args[[i++]]);])dnl + arg_$][1 = Function::Cast(args[[i++]]);])dnl ]) define([START_METHOD_ARG_PASS], [dnl -define([INT], [$][1])dnl -define([OBJ], [$][1])dnl -define([STR], [$][1])dnl -define([FUNC], [$][1])dnl +define([INT], [arg_$][1])dnl +define([OBJ], [arg_$][1])dnl +define([STR], [arg_$][1])dnl +define([FUNC], [arg_$][1])dnl ]) define([START_METHOD_RET_VAL], [dnl @@ -161,7 +161,7 @@ return Integer::New(_ret); ])dnl define([OBJ], [ - return PROJ_PREFIX[]STRUCT_NAME[]_$][1[]_new(_ret); + return PROJ_PREFIX[]$][1[]_new(_ret); ])dnl define([STR], [ return String::New(_ret); @@ -224,7 +224,7 @@ define([STRUCT_TYPE], [$2])dnl [ /* ************************************************** - * STRUCT: $1 + * [STRUCT]: $1 * Generated by gen_v8_binding.m4 */ static Handle<Value> @@ -267,4 +267,44 @@ PROJ_PREFIX[$1][_temp = Persistent<FunctionTemplate>::New(func_temp); }]dnl ]) + +define([FUNCTION], [dnl +/* ************************************************** + * [FUNCTION]: $1 + * Generated by gen_v8_binding.m4 + */ +static Handle<Value> +PROJ_PREFIX[]$1(const Arguments &args) { + int argc = args.Length(); +foreach([ITER], ($3), [START_METHOD_ARG_VAR[]ITER[]STOP_METHOD_ARG])dnl +START_METHOD_RET_VAL[]$5[]STOP_METHOD_ARG[]dnl + + if(argc != $4) + THROW("Invalid number of arguments (!=$][4)"); + i = 0; + if(0]dnl +[foreach([ITER], ($3), [START_METHOD_ARG_TYPE_CHK[]ITER[]STOP_METHOD_ARG])) + THROW("Invalid argument type"); + + i = 0; +foreach([ITER], ($3), [START_METHOD_ARG_ASSIGN[]ITER[]STOP_METHOD_ARG])) + +define([SEP], [])dnl + START_METHOD_RET_ASSIGN[]$5[]STOP_METHOD_ARG[]$2(foreach([ITER], ($3), [START_METHOD_ARG_PASS[]SEP[]ITER[]STOP_METHOD_ARG[]define([SEP], [, ])]));[]undefine([SEP]) +START_METHOD_RET[]$][5[]STOP_METHOD_ARG[]dnl +ifelse($][5, [], [ + return Null(); +])dnl +} +static Persistent<FunctionTemplate> PROJ_PREFIX[]$1[]_temp; + +static void +PROJ_PREFIX[]$1[]_init(void) { + Handle<FunctionTemplate> func_temp; + + func_temp = FunctionTemplate::New(PROJ_PREFIX[]$1); + PROJ_PREFIX[]$1[]_temp = Persistent<FunctionTemplate>::New(func_temp); +} +]) + divert([])dnl