comparison tools/gen_v8_binding.m4 @ 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
comparison
equal deleted inserted replaced
649:2030e5d9f7f7 650:123e7eeff10c
94 undefine([STR])dnl 94 undefine([STR])dnl
95 ]) 95 ])
96 96
97 define([START_METHOD_ARG_VAR], [dnl 97 define([START_METHOD_ARG_VAR], [dnl
98 define([INT], [dnl 98 define([INT], [dnl
99 int $][1];)dnl 99 int arg_$][1];)dnl
100 define([OBJ], [dnl 100 define([OBJ], [dnl
101 $][2 *$][1];)dnl 101 $][2 *arg_$][1];)dnl
102 define([STR], [dnl 102 define([STR], [dnl
103 char *$][1];)dnl 103 char *arg_$][1];)dnl
104 define([FUNC], [ 104 define([FUNC], [
105 Handle<Function> $][1];)dnl 105 Handle<Function> arg_$][1];)dnl
106 ]) 106 ])
107 107
108 define([START_METHOD_ARG_TYPE_CHK], [dnl 108 define([START_METHOD_ARG_TYPE_CHK], [dnl
109 define([INT], [ || 109 define([INT], [ ||
110 !args[[i++]]->IsInt32()])dnl 110 !args[[i++]]->IsInt32()])dnl
116 !args[[i++]]->IsFunction()])dnl 116 !args[[i++]]->IsFunction()])dnl
117 ]) 117 ])
118 118
119 define([START_METHOD_ARG_ASSIGN], [dnl 119 define([START_METHOD_ARG_ASSIGN], [dnl
120 define([INT], [ 120 define([INT], [
121 $][1 = args[[i++]]->Int32Value();])dnl 121 arg_$][1 = args[[i++]]->Int32Value();])dnl
122 define([OBJ], [ 122 define([OBJ], [
123 $][1 = ($][2 *)UNWRAP(args[[i++]]->ToObject());])dnl 123 arg_$][1 = ($][2 *)UNWRAP(args[[i++]]->ToObject());])dnl
124 define([STR], [ 124 define([STR], [
125 $][1 = strdup(*String::Utf8Value(args[[i++]]->ToString()));])dnl 125 arg_$][1 = strdup(*String::Utf8Value(args[[i++]]->ToString()));])dnl
126 define([FUNC], [ 126 define([FUNC], [
127 $][1 = Function::Cast(args[[i++]]);])dnl 127 arg_$][1 = Function::Cast(args[[i++]]);])dnl
128 ]) 128 ])
129 129
130 define([START_METHOD_ARG_PASS], [dnl 130 define([START_METHOD_ARG_PASS], [dnl
131 define([INT], [$][1])dnl 131 define([INT], [arg_$][1])dnl
132 define([OBJ], [$][1])dnl 132 define([OBJ], [arg_$][1])dnl
133 define([STR], [$][1])dnl 133 define([STR], [arg_$][1])dnl
134 define([FUNC], [$][1])dnl 134 define([FUNC], [arg_$][1])dnl
135 ]) 135 ])
136 136
137 define([START_METHOD_RET_VAL], [dnl 137 define([START_METHOD_RET_VAL], [dnl
138 define([INT], [ 138 define([INT], [
139 int _ret; 139 int _ret;
159 define([START_METHOD_RET], [dnl 159 define([START_METHOD_RET], [dnl
160 define([INT], [ 160 define([INT], [
161 return Integer::New(_ret); 161 return Integer::New(_ret);
162 ])dnl 162 ])dnl
163 define([OBJ], [ 163 define([OBJ], [
164 return PROJ_PREFIX[]STRUCT_NAME[]_$][1[]_new(_ret); 164 return PROJ_PREFIX[]$][1[]_new(_ret);
165 ])dnl 165 ])dnl
166 define([STR], [ 166 define([STR], [
167 return String::New(_ret); 167 return String::New(_ret);
168 ])dnl 168 ])dnl
169 define([FUNC], [ 169 define([FUNC], [
222 define([STRUCT], [dnl 222 define([STRUCT], [dnl
223 define([STRUCT_NAME], [$1])dnl 223 define([STRUCT_NAME], [$1])dnl
224 define([STRUCT_TYPE], [$2])dnl 224 define([STRUCT_TYPE], [$2])dnl
225 [ 225 [
226 /* ************************************************** 226 /* **************************************************
227 * STRUCT: $1 227 * [STRUCT]: $1
228 * Generated by gen_v8_binding.m4 228 * Generated by gen_v8_binding.m4
229 */ 229 */
230 static Handle<Value> 230 static Handle<Value>
231 ]PROJ_PREFIX[$1(const Arguments &args) { 231 ]PROJ_PREFIX[$1(const Arguments &args) {
232 } 232 }
265 foreach([ITER], ($4), [SET_METHOD(ITER)])dnl 265 foreach([ITER], ($4), [SET_METHOD(ITER)])dnl
266 266
267 PROJ_PREFIX[$1][_temp = Persistent<FunctionTemplate>::New(func_temp); 267 PROJ_PREFIX[$1][_temp = Persistent<FunctionTemplate>::New(func_temp);
268 }]dnl 268 }]dnl
269 ]) 269 ])
270
271 define([FUNCTION], [dnl
272 /* **************************************************
273 * [FUNCTION]: $1
274 * Generated by gen_v8_binding.m4
275 */
276 static Handle<Value>
277 PROJ_PREFIX[]$1(const Arguments &args) {
278 int argc = args.Length();
279 foreach([ITER], ($3), [START_METHOD_ARG_VAR[]ITER[]STOP_METHOD_ARG])dnl
280 START_METHOD_RET_VAL[]$5[]STOP_METHOD_ARG[]dnl
281
282 if(argc != $4)
283 THROW("Invalid number of arguments (!=$][4)");
284 i = 0;
285 if(0]dnl
286 [foreach([ITER], ($3), [START_METHOD_ARG_TYPE_CHK[]ITER[]STOP_METHOD_ARG]))
287 THROW("Invalid argument type");
288
289 i = 0;
290 foreach([ITER], ($3), [START_METHOD_ARG_ASSIGN[]ITER[]STOP_METHOD_ARG]))
291
292 define([SEP], [])dnl
293 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])
294 START_METHOD_RET[]$][5[]STOP_METHOD_ARG[]dnl
295 ifelse($][5, [], [
296 return Null();
297 ])dnl
298 }
299 static Persistent<FunctionTemplate> PROJ_PREFIX[]$1[]_temp;
300
301 static void
302 PROJ_PREFIX[]$1[]_init(void) {
303 Handle<FunctionTemplate> func_temp;
304
305 func_temp = FunctionTemplate::New(PROJ_PREFIX[]$1);
306 PROJ_PREFIX[]$1[]_temp = Persistent<FunctionTemplate>::New(func_temp);
307 }
308 ])
309
270 divert([])dnl 310 divert([])dnl