Mercurial > MadButterfly
comparison 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 |
comparison
equal
deleted
inserted
replaced
555:962d8436a303 | 556:c9d23f7279a4 |
---|---|
1 #include <stdio.h> | 1 #include <stdio.h> |
2 #include <v8.h> | 2 #include <v8.h> |
3 | 3 |
4 extern "C" { | |
5 #include "X_supp_njs.h" | |
6 } | |
7 | |
4 using namespace v8; | 8 using namespace v8; |
9 | |
10 /*! \defgroup njs_template_cb Callback functions for v8 engine and nodejs. | |
11 * | |
12 * @{ | |
13 */ | |
14 | |
15 /*! \brief to Create a njs runtime object for MadButterfly. | |
16 * | |
17 * Three arguments are requried. They are | |
18 * - display name, | |
19 * - width, and | |
20 * - height. | |
21 */ | |
22 static Handle<Value> | |
23 xnjsmb_new(const Arguments &args) { | |
24 int argc; | |
25 Handle<Value> exc; | |
26 njs_runtime_t *rt; | |
27 char *display_name; | |
28 int width, height; | |
29 Handle<Object> self; | |
30 | |
31 argc = args.Length(); | |
32 if(argc != 3) { | |
33 exc = Exception::Error(String::New("Need 3 arguments.")); | |
34 return ThrowException(exc); | |
35 } | |
36 | |
37 if(!args[0]->IsString() || !args[1]->IsInt32() || !args[2]->IsInt32()) { | |
38 exc = Exception::Error(String::New("Invalid argument type.")); | |
39 return ThrowException(exc); | |
40 } | |
41 | |
42 String::Utf8Value disp_utf8(args[0]->ToString()); | |
43 display_name = *disp_utf8; | |
44 width = args[1]->Int32Value(); | |
45 height = args[2]->Int32Value(); | |
46 rt = X_njs_MB_new(display_name, width, height); | |
47 | |
48 self = args.This(); | |
49 self->Set(String::New("_njs_rt"), External::Wrap(rt)); | |
50 | |
51 X_njs_MB_init_handle_connection(rt); | |
52 } | |
53 | |
54 static Handle<Value> | |
55 xnjsmb_handle_connection(const Arguments &args) { | |
56 } | |
57 | |
58 /* @} */ | |
5 | 59 |
6 Handle<Value> | 60 Handle<Value> |
7 hello_func(const Arguments &args) { | 61 hello_func(const Arguments &args) { |
8 HandleScope scope; | 62 HandleScope scope; |
9 | 63 |
15 HandleScope scope; | 69 HandleScope scope; |
16 Handle<FunctionTemplate> func; | 70 Handle<FunctionTemplate> func; |
17 | 71 |
18 func = FunctionTemplate::New(hello_func); | 72 func = FunctionTemplate::New(hello_func); |
19 target->Set(String::New("Hello"), func->GetFunction()); | 73 target->Set(String::New("Hello"), func->GetFunction()); |
74 | |
75 func = FunctionTemplate::New(xnjsmb_new); | |
76 target->Set(String::New("mb_rt"), func->GetFunction()); | |
20 } | 77 } |