Mercurial > MadButterfly
annotate nodejs/mbfly_njs.cc @ 567:a12c3448afb6 Android_Skia
Add dummy paint_color templates
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Wed, 09 Jun 2010 12:28:03 +0800 |
parents | c0bc60448913 |
children | 13b15b7a463b |
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); |
562
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
561
diff
changeset
|
53 xnjsmb_coord_mkroot(self); |
556
c9d23f7279a4
The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents:
548
diff
changeset
|
54 |
c9d23f7279a4
The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents:
548
diff
changeset
|
55 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
|
56 |
d61133da2845
New MadButterfly runtime object install of calling function
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
57 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
|
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 |
c9d23f7279a4
The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents:
548
diff
changeset
|
60 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
|
61 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
|
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 /* @} */ |
c9d23f7279a4
The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents:
548
diff
changeset
|
65 |
562
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
561
diff
changeset
|
66 /*! \brief Get rdman associated with the runtime. |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
561
diff
changeset
|
67 */ |
559
ef078d7c57b4
Use internal field to store njs_runtime_t object.
Thinker K.F. Li <thinker@branda.to>
parents:
558
diff
changeset
|
68 redraw_man_t * |
ef078d7c57b4
Use internal field to store njs_runtime_t object.
Thinker K.F. Li <thinker@branda.to>
parents:
558
diff
changeset
|
69 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
|
70 HandleScope scope; |
ef078d7c57b4
Use internal field to store njs_runtime_t object.
Thinker K.F. Li <thinker@branda.to>
parents:
558
diff
changeset
|
71 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
|
72 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
|
73 |
ef078d7c57b4
Use internal field to store njs_runtime_t object.
Thinker K.F. Li <thinker@branda.to>
parents:
558
diff
changeset
|
74 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
|
75 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
|
76 |
ef078d7c57b4
Use internal field to store njs_runtime_t object.
Thinker K.F. Li <thinker@branda.to>
parents:
558
diff
changeset
|
77 return rdman; |
ef078d7c57b4
Use internal field to store njs_runtime_t object.
Thinker K.F. Li <thinker@branda.to>
parents:
558
diff
changeset
|
78 } |
ef078d7c57b4
Use internal field to store njs_runtime_t object.
Thinker K.F. Li <thinker@branda.to>
parents:
558
diff
changeset
|
79 |
548 | 80 Handle<Value> |
81 hello_func(const Arguments &args) { | |
82 HandleScope scope; | |
83 | |
84 return String::Concat(String::New("World"), args[0]->ToString()); | |
85 } | |
86 | |
547
371690a166df
Remove hello.c and initial plugin at mbfly_njs.cc
Thinker K.F. Li <thinker@branda.to>
parents:
546
diff
changeset
|
87 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
|
88 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
|
89 HandleScope scope; |
562
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
561
diff
changeset
|
90 Handle<FunctionTemplate> func, mb_rt_func; |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
561
diff
changeset
|
91 Handle<ObjectTemplate> rt_instance_temp, rt_proto_temp; |
547
371690a166df
Remove hello.c and initial plugin at mbfly_njs.cc
Thinker K.F. Li <thinker@branda.to>
parents:
546
diff
changeset
|
92 |
548 | 93 func = FunctionTemplate::New(hello_func); |
94 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
|
95 |
562
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
561
diff
changeset
|
96 /* |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
561
diff
changeset
|
97 * Initialize template for MadButterfly runtime objects. |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
561
diff
changeset
|
98 */ |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
561
diff
changeset
|
99 mb_rt_func = FunctionTemplate::New(xnjsmb_new); |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
561
diff
changeset
|
100 mb_rt_func->SetClassName(String::New("mb_rt")); |
561
a3c13c2a4792
Function template on runtime object for xnjsmb_coord_new()
Thinker K.F. Li <thinker@branda.to>
parents:
559
diff
changeset
|
101 |
562
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
561
diff
changeset
|
102 rt_instance_temp = mb_rt_func->InstanceTemplate(); |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
561
diff
changeset
|
103 rt_instance_temp->SetInternalFieldCount(1); |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
561
diff
changeset
|
104 |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
561
diff
changeset
|
105 rt_proto_temp = mb_rt_func->PrototypeTemplate(); |
561
a3c13c2a4792
Function template on runtime object for xnjsmb_coord_new()
Thinker K.F. Li <thinker@branda.to>
parents:
559
diff
changeset
|
106 func = FunctionTemplate::New(xnjsmb_coord_new); |
562
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
561
diff
changeset
|
107 SET(rt_proto_temp, "coord_new", func); |
565
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
562
diff
changeset
|
108 |
567
a12c3448afb6
Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
565
diff
changeset
|
109 /* |
a12c3448afb6
Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
565
diff
changeset
|
110 * Add properties to mb_rt templates for other modules. |
a12c3448afb6
Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
565
diff
changeset
|
111 */ |
565
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
562
diff
changeset
|
112 xnjsmb_shapes_init_mb_rt_temp(mb_rt_func); |
567
a12c3448afb6
Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
565
diff
changeset
|
113 xnjsmb_paints_init_mb_rt_temp(mb_rt_func); |
562
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
561
diff
changeset
|
114 |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
561
diff
changeset
|
115 target->Set(String::New("mb_rt"), mb_rt_func->GetFunction()); |
547
371690a166df
Remove hello.c and initial plugin at mbfly_njs.cc
Thinker K.F. Li <thinker@branda.to>
parents:
546
diff
changeset
|
116 } |