# HG changeset patch # User Thinker K.F. Li # Date 1280633289 -28800 # Node ID d4aa1cce0af724049529722b23fda05b105c9b0a # Parent 62c2de99b03a0b62edba548f21dcd3ec69e69a3a Supporting setter/Getter of index of objects for JS diff -r 62c2de99b03a -r d4aa1cce0af7 tools/gen_v8_binding.m4 --- a/tools/gen_v8_binding.m4 Sat Jul 31 16:16:45 2010 +0800 +++ b/tools/gen_v8_binding.m4 Sun Aug 01 11:28:09 2010 +0800 @@ -13,6 +13,8 @@ define([IMPORT],[define([$1],[$2$1(]$[]@[)])]) +define([EXPAND], [$1]) + define([PROJ_PREFIX], [xnjsmb_]) define([START_ACCESSOR], [dnl @@ -38,6 +40,27 @@ data->$][1 = value->Int32Value(); } ]) + define([NUMBER], [ +static Handle +]PROJ_PREFIX[]STRUCT_NAME[_get_$][1(Local property, const AccessorInfo &info) { + Handle self = info.This(); + STRUCT_TYPE *data; + + data = (STRUCT_TYPE *)UNWRAP(self); + return Number::New(data->$][1); +} + +static void +]PROJ_PREFIX[]STRUCT_NAME[_set_$][1(Local property, + Local value, + const AccessorInfo &info) { + Handle self = info.This(); + STRUCT_TYPE *data; + + data = (STRUCT_TYPE *)UNWRAP(self); + data->$][1 = value->NumberValue(); +} +]) define([OBJ], [ static Handle ]PROJ_PREFIX[]STRUCT_NAME[_get_$][1(Local property, const AccessorInfo &info) { @@ -92,6 +115,7 @@ define([STOP_ACCESSOR], [dnl divert([-1])dnl undefine([INT]) +undefine([NUMBER]) undefine([OBJ]) undefine([STR]) divert([])dnl @@ -99,12 +123,14 @@ define([SET_ACCESSSOR], [dnl define([INT], [$][1])dnl +define([NUMBER], [$][1])dnl define([OBJ], [$][1])dnl define([STR], [$][1])dnl inst_temp->SetAccessor(String::New("$1"), PROJ_PREFIX[]STRUCT_NAME[]_get_[]$1, PROJ_PREFIX[]STRUCT_NAME[]_set_[]$1); undefine([INT])dnl +undefine([NUMBER])dnl undefine([OBJ])dnl undefine([STR])dnl ]) @@ -113,6 +139,9 @@ define([INT], [dnl int arg_$][1; ])dnl +define([NUMBER], [dnl + double arg_$][1; +])dnl define([OBJ], [dnl $][2 *arg_$][1; ])dnl @@ -127,6 +156,8 @@ define([START_METHOD_ARG_TYPE_CHK], [dnl define([INT], [ || !args[[i++]]->IsInt32()])dnl +define([NUMBER], [ || + !args[[i++]]->IsNumber()])dnl define([OBJ], [ || !args[[i++]]->IsObject()])dnl define([STR], [ || @@ -139,6 +170,9 @@ define([INT], [dnl arg_$][1 = args[[i++]]->Int32Value(); ])dnl +define([NUMBER], [dnl + arg_$][1 = args[[i++]]->NumberValue(); +])dnl define([OBJ], [dnl arg_$][1 = ($][2 *)UNWRAP(args[[i++]]->ToObject()); ])dnl @@ -150,8 +184,27 @@ ])dnl ]) +define([START_VALUE_ASSIGN], [dnl +define([INT], [dnl + $1 = $2->Int32Value(); +])dnl +define([NUMBER], [dnl + $1 = $2->NumberValue(); +])dnl +define([OBJ], [dnl + $1 = ($][2 *)UNWRAP($2->ToObject()); +])dnl +define([STR], [dnl + $1 = strdup(*String::Utf8Value($2->ToString())); +])dnl +define([FUNC], [dnl + $1 = $2.As(); +])dnl +]) + define([START_METHOD_ARG_PASS], [dnl define([INT], [arg_$][1])dnl +define([NUMBER], [arg_$][1])dnl define([OBJ], [arg_$][1])dnl define([STR], [arg_$][1])dnl define([FUNC], [arg_$][1])dnl @@ -161,6 +214,9 @@ define([INT], [dnl int _ret; ])dnl +define([NUMBER], [dnl + double _ret; +])dnl define([OBJ], [dnl $][2 *_ret; ])dnl @@ -172,8 +228,27 @@ ])dnl ]) +define([START_VAR], [dnl +define([INT], [dnl + int $1; +])dnl +define([NUMBER], [dnl + double $1; +])dnl +define([OBJ], [dnl + $][2 *$1; +])dnl +define([STR], [dnl + char *$1; +])dnl +define([FUNC], [dnl + Handle $1; +])dnl +]) + define([START_METHOD_RET_ASSIGN], [dnl define([INT], [_ret = (int)])dnl +define([NUMBER], [_ret = (double)])dnl define([OBJ], [_ret = ($][2 *)])dnl define([STR], [_ret = (char *)])dnl define([FUNC], [_ret = ])dnl @@ -183,6 +258,9 @@ define([INT], [ return Integer::New(_ret); ])dnl +define([NUMBER], [ + return Number::New(_ret); +])dnl define([OBJ], [ return PROJ_PREFIX[]$][1[]_new(_ret); ])dnl @@ -196,6 +274,7 @@ define([STOP_METHOD_ARG], [dnl undefine([INT])dnl +undefine([NUMBER])dnl undefine([OBJ])dnl undefine([STR])dnl undefine([FUNC])dnl @@ -242,12 +321,44 @@ undefine([METHOD])dnl ]) +define([DEF_GET_INDEX], [ +static Handle +PROJ_PREFIX[]STRUCT_NAME[]_get_index(uint32_t index, const AccessorInfo &info) { + Handle self = info.This(); + STRUCT_TYPE *obj = (STRUCT_TYPE *)UNWRAP(self); +START_METHOD_RET_VAL[]$2[]STOP_METHOD_ARG[]dnl + + _ret = $1(obj, index); +START_METHOD_RET[]$2[]STOP_METHOD_ARG[]dnl +} +]) + +define([DEF_SET_INDEX], [ +static Handle +PROJ_PREFIX[]STRUCT_NAME[]_set_index(uint32_t index, Local value, + const AccessorInfo &info) { + Handle self = info.This(); + STRUCT_TYPE *obj = (STRUCT_TYPE *)UNWRAP(self); +START_VAR([in_value])[]$2[]STOP_METHOD_ARG[]dnl +START_METHOD_RET_VAL[]$2[]STOP_METHOD_ARG[]dnl + +START_VALUE_ASSIGN(in_value, value)[]$2[]STOP_METHOD_ARG[]dnl + _ret = $1(obj, index, in_value); +START_METHOD_RET[]$2[]STOP_METHOD_ARG[]dnl +} +]) + +define([INSTALL_INDEX_FUNCTIONS],[]) + dnl dnl STRUCT(struct_name, struct_type, member_vars, methods) dnl define([STRUCT], [dnl define([STRUCT_NAME], [$1])dnl define([STRUCT_TYPE], [$2])dnl +dnl +ifelse([$5], [], [], [foreach([ITER], $5, [EXPAND([define]ITER)])])dnl +dnl [ /* ************************************************** * STRUCT: $1 @@ -273,6 +384,8 @@ ]dnl foreach([ITER], ($3), [START_ACCESSOR ITER STOP_ACCESSOR])dnl foreach([ITER], ($4), [START_METHOD ITER STOP_METHOD])dnl +ifdef([GET_INDEX], [EXPAND([DEF_GET_INDEX]GET_INDEX)])dnl +ifdef([SET_INDEX], [EXPAND([DEF_SET_INDEX]SET_INDEX)])dnl [ static void ]PROJ_PREFIX[$1][_init(void) { @@ -287,11 +400,19 @@ ] foreach([ITER], ($3), [SET_ACCESSSOR(ITER)])dnl inst_temp = func_temp->InstanceTemplate(); +INSTALL_INDEX_FUNCTIONS[]dnl foreach([ITER], ($4), [SET_METHOD(ITER)])dnl PROJ_PREFIX[$1][_temp = Persistent::New(func_temp); }]dnl +dnl +ifelse([$5], [], [], [foreach([ITER], $5, [dnl +define([DUMMY], [undefine]ITER)dnl +DUMMY[]dnl +undefine([DUMMY])])dnl +])dnl +dnl ]) dnl