annotate nodejs/mbfly_njs.cc @ 561:a3c13c2a4792 Android_Skia

Function template on runtime object for xnjsmb_coord_new()
author Thinker K.F. Li <thinker@branda.to>
date Mon, 07 Jun 2010 12:12:03 +0800
parents ef078d7c57b4
children 1b6402f07cd4
rev   line source
546
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 #include <stdio.h>
547
371690a166df Remove hello.c and initial plugin at mbfly_njs.cc
Thinker K.F. Li <thinker@branda.to>
parents: 546
diff changeset
2 #include <v8.h>
546
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3
556
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
4 extern "C" {
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
5 #include "X_supp_njs.h"
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
6 }
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
7
559
ef078d7c57b4 Use internal field to store njs_runtime_t object.
Thinker K.F. Li <thinker@branda.to>
parents: 558
diff changeset
8 #include "mbfly_njs.h"
ef078d7c57b4 Use internal field to store njs_runtime_t object.
Thinker K.F. Li <thinker@branda.to>
parents: 558
diff changeset
9
547
371690a166df Remove hello.c and initial plugin at mbfly_njs.cc
Thinker K.F. Li <thinker@branda.to>
parents: 546
diff changeset
10 using namespace v8;
371690a166df Remove hello.c and initial plugin at mbfly_njs.cc
Thinker K.F. Li <thinker@branda.to>
parents: 546
diff changeset
11
556
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
12 /*! \defgroup njs_template_cb Callback functions for v8 engine and nodejs.
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
13 *
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
14 * @{
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
15 */
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
16
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
17 /*! \brief to Create a njs runtime object for MadButterfly.
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
18 *
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
19 * Three arguments are requried. They are
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
20 * - display name,
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
21 * - width, and
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
22 * - height.
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
23 */
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
24 static Handle<Value>
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
25 xnjsmb_new(const Arguments &args) {
557
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
26 HandleScope scope;
556
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
27 int argc;
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
28 Handle<Value> exc;
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
29 njs_runtime_t *rt;
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
30 char *display_name;
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
31 int width, height;
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
32 Handle<Object> self;
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
33
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
34 argc = args.Length();
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
35 if(argc != 3) {
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
36 exc = Exception::Error(String::New("Need 3 arguments."));
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
37 return ThrowException(exc);
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
38 }
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
39
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
40 if(!args[0]->IsString() || !args[1]->IsInt32() || !args[2]->IsInt32()) {
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
41 exc = Exception::Error(String::New("Invalid argument type."));
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
42 return ThrowException(exc);
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
43 }
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
44
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
45 String::Utf8Value disp_utf8(args[0]->ToString());
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
46 display_name = *disp_utf8;
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
47 width = args[1]->Int32Value();
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
48 height = args[2]->Int32Value();
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
49 rt = X_njs_MB_new(display_name, width, height);
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
50
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
51 self = args.This();
559
ef078d7c57b4 Use internal field to store njs_runtime_t object.
Thinker K.F. Li <thinker@branda.to>
parents: 558
diff changeset
52 WRAP(self, rt);
556
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
53
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
54 X_njs_MB_init_handle_connection(rt);
558
d61133da2845 New MadButterfly runtime object install of calling function
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
55
d61133da2845 New MadButterfly runtime object install of calling function
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
56 return Null();
556
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
57 }
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
58
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
59 static Handle<Value>
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
60 xnjsmb_handle_connection(const Arguments &args) {
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
61 }
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
62
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
63 /* @} */
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
64
559
ef078d7c57b4 Use internal field to store njs_runtime_t object.
Thinker K.F. Li <thinker@branda.to>
parents: 558
diff changeset
65 redraw_man_t *
ef078d7c57b4 Use internal field to store njs_runtime_t object.
Thinker K.F. Li <thinker@branda.to>
parents: 558
diff changeset
66 xnjsmb_rt_rdman(Handle<Object> mbrt) {
ef078d7c57b4 Use internal field to store njs_runtime_t object.
Thinker K.F. Li <thinker@branda.to>
parents: 558
diff changeset
67 HandleScope scope;
ef078d7c57b4 Use internal field to store njs_runtime_t object.
Thinker K.F. Li <thinker@branda.to>
parents: 558
diff changeset
68 njs_runtime_t *rt;
ef078d7c57b4 Use internal field to store njs_runtime_t object.
Thinker K.F. Li <thinker@branda.to>
parents: 558
diff changeset
69 redraw_man_t *rdman;
ef078d7c57b4 Use internal field to store njs_runtime_t object.
Thinker K.F. Li <thinker@branda.to>
parents: 558
diff changeset
70
ef078d7c57b4 Use internal field to store njs_runtime_t object.
Thinker K.F. Li <thinker@branda.to>
parents: 558
diff changeset
71 rt = (njs_runtime_t *)UNWRAP(mbrt);
ef078d7c57b4 Use internal field to store njs_runtime_t object.
Thinker K.F. Li <thinker@branda.to>
parents: 558
diff changeset
72 rdman = X_njs_MB_rdman(rt);
ef078d7c57b4 Use internal field to store njs_runtime_t object.
Thinker K.F. Li <thinker@branda.to>
parents: 558
diff changeset
73
ef078d7c57b4 Use internal field to store njs_runtime_t object.
Thinker K.F. Li <thinker@branda.to>
parents: 558
diff changeset
74 return rdman;
ef078d7c57b4 Use internal field to store njs_runtime_t object.
Thinker K.F. Li <thinker@branda.to>
parents: 558
diff changeset
75 }
ef078d7c57b4 Use internal field to store njs_runtime_t object.
Thinker K.F. Li <thinker@branda.to>
parents: 558
diff changeset
76
548
f69b0814ef3c Test FunctionTemplate
Thinker K.F. Li <thinker@branda.to>
parents: 547
diff changeset
77 Handle<Value>
f69b0814ef3c Test FunctionTemplate
Thinker K.F. Li <thinker@branda.to>
parents: 547
diff changeset
78 hello_func(const Arguments &args) {
f69b0814ef3c Test FunctionTemplate
Thinker K.F. Li <thinker@branda.to>
parents: 547
diff changeset
79 HandleScope scope;
f69b0814ef3c Test FunctionTemplate
Thinker K.F. Li <thinker@branda.to>
parents: 547
diff changeset
80
f69b0814ef3c Test FunctionTemplate
Thinker K.F. Li <thinker@branda.to>
parents: 547
diff changeset
81 return String::Concat(String::New("World"), args[0]->ToString());
f69b0814ef3c Test FunctionTemplate
Thinker K.F. Li <thinker@branda.to>
parents: 547
diff changeset
82 }
f69b0814ef3c Test FunctionTemplate
Thinker K.F. Li <thinker@branda.to>
parents: 547
diff changeset
83
547
371690a166df Remove hello.c and initial plugin at mbfly_njs.cc
Thinker K.F. Li <thinker@branda.to>
parents: 546
diff changeset
84 extern "C" void
371690a166df Remove hello.c and initial plugin at mbfly_njs.cc
Thinker K.F. Li <thinker@branda.to>
parents: 546
diff changeset
85 init(Handle<Object> target) {
371690a166df Remove hello.c and initial plugin at mbfly_njs.cc
Thinker K.F. Li <thinker@branda.to>
parents: 546
diff changeset
86 HandleScope scope;
548
f69b0814ef3c Test FunctionTemplate
Thinker K.F. Li <thinker@branda.to>
parents: 547
diff changeset
87 Handle<FunctionTemplate> func;
561
a3c13c2a4792 Function template on runtime object for xnjsmb_coord_new()
Thinker K.F. Li <thinker@branda.to>
parents: 559
diff changeset
88 Handle<ObjectTemplate> rt_obj_temp;
547
371690a166df Remove hello.c and initial plugin at mbfly_njs.cc
Thinker K.F. Li <thinker@branda.to>
parents: 546
diff changeset
89
548
f69b0814ef3c Test FunctionTemplate
Thinker K.F. Li <thinker@branda.to>
parents: 547
diff changeset
90 func = FunctionTemplate::New(hello_func);
f69b0814ef3c Test FunctionTemplate
Thinker K.F. Li <thinker@branda.to>
parents: 547
diff changeset
91 target->Set(String::New("Hello"), func->GetFunction());
556
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
92
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
93 func = FunctionTemplate::New(xnjsmb_new);
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 548
diff changeset
94 target->Set(String::New("mb_rt"), func->GetFunction());
561
a3c13c2a4792 Function template on runtime object for xnjsmb_coord_new()
Thinker K.F. Li <thinker@branda.to>
parents: 559
diff changeset
95 rt_obj_temp = func->PrototypeTemplate();
a3c13c2a4792 Function template on runtime object for xnjsmb_coord_new()
Thinker K.F. Li <thinker@branda.to>
parents: 559
diff changeset
96 rt_obj_temp->SetInternalFieldCount(1);
a3c13c2a4792 Function template on runtime object for xnjsmb_coord_new()
Thinker K.F. Li <thinker@branda.to>
parents: 559
diff changeset
97
a3c13c2a4792 Function template on runtime object for xnjsmb_coord_new()
Thinker K.F. Li <thinker@branda.to>
parents: 559
diff changeset
98 func = FunctionTemplate::New(xnjsmb_coord_new);
a3c13c2a4792 Function template on runtime object for xnjsmb_coord_new()
Thinker K.F. Li <thinker@branda.to>
parents: 559
diff changeset
99 SET(rt_obj_temp, "coord_new", func);
547
371690a166df Remove hello.c and initial plugin at mbfly_njs.cc
Thinker K.F. Li <thinker@branda.to>
parents: 546
diff changeset
100 }