Mercurial > MadButterfly
annotate nodejs/mbfly_njs.cc @ 556:c9d23f7279a4 Android_Skia
The first testcase that nodejs code can show a MadButterfly window.
This testcase call MadButterfly from Javascript with nodejs framework.
The testcase show a MadButterfly window in X.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sun, 06 Jun 2010 19:13:21 +0800 |
parents | f69b0814ef3c |
children | 0ca8437a91fa |
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 |
547
371690a166df
Remove hello.c and initial plugin at mbfly_njs.cc
Thinker K.F. Li <thinker@branda.to>
parents:
546
diff
changeset
|
8 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
|
9 |
556
c9d23f7279a4
The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents:
548
diff
changeset
|
10 /*! \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
|
11 * |
c9d23f7279a4
The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents:
548
diff
changeset
|
12 * @{ |
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 /*! \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
|
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 * 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
|
18 * - 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
|
19 * - 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
|
20 * - height. |
c9d23f7279a4
The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents:
548
diff
changeset
|
21 */ |
c9d23f7279a4
The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents:
548
diff
changeset
|
22 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
|
23 xnjsmb_new(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
|
24 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
|
25 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
|
26 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
|
27 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
|
28 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
|
29 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
|
30 |
c9d23f7279a4
The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents:
548
diff
changeset
|
31 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
|
32 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
|
33 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
|
34 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
|
35 } |
c9d23f7279a4
The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents:
548
diff
changeset
|
36 |
c9d23f7279a4
The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents:
548
diff
changeset
|
37 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
|
38 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
|
39 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
|
40 } |
c9d23f7279a4
The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents:
548
diff
changeset
|
41 |
c9d23f7279a4
The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents:
548
diff
changeset
|
42 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
|
43 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
|
44 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
|
45 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
|
46 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
|
47 |
c9d23f7279a4
The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents:
548
diff
changeset
|
48 self = args.This(); |
c9d23f7279a4
The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents:
548
diff
changeset
|
49 self->Set(String::New("_njs_rt"), External::Wrap(rt)); |
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 X_njs_MB_init_handle_connection(rt); |
c9d23f7279a4
The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents:
548
diff
changeset
|
52 } |
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 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
|
55 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
|
56 } |
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 |
548 | 60 Handle<Value> |
61 hello_func(const Arguments &args) { | |
62 HandleScope scope; | |
63 | |
64 return String::Concat(String::New("World"), args[0]->ToString()); | |
65 } | |
66 | |
547
371690a166df
Remove hello.c and initial plugin at mbfly_njs.cc
Thinker K.F. Li <thinker@branda.to>
parents:
546
diff
changeset
|
67 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
|
68 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
|
69 HandleScope scope; |
548 | 70 Handle<FunctionTemplate> func; |
547
371690a166df
Remove hello.c and initial plugin at mbfly_njs.cc
Thinker K.F. Li <thinker@branda.to>
parents:
546
diff
changeset
|
71 |
548 | 72 func = FunctionTemplate::New(hello_func); |
73 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
|
74 |
c9d23f7279a4
The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents:
548
diff
changeset
|
75 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
|
76 target->Set(String::New("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
|
77 } |