annotate nodejs/coord.cc @ 646:3a1e80de44ff

Add image support
author wycc
date Thu, 29 Jul 2010 00:12:18 +0800
parents 6639d386db78
children 90c7726bc953
rev   line source
557
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 #include <stdio.h>
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
2 #include <v8.h>
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 extern "C" {
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5 #include "mb.h"
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
6 #include "mb_X_supp.h"
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7 #include "mb_tools.h"
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
8 #include "X_supp_njs.h"
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
9 }
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10
560
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
11 #include "mbfly_njs.h"
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
12
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
13 #ifndef ASSERT
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
14 #define ASSERT(x)
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
15 #endif
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
16
557
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17 using namespace v8;
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
18
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19 static Handle<Value>
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20 xnjsmb_coord_get_index(uint32_t index, const AccessorInfo &info) {
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21 HandleScope scope;
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 Handle<Object> self;
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 coord_t *coord;
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
24 co_aix v;
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
25
560
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
26 if(index < 0 || index >= 6)
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
27 THROW("Invalid index");
557
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29 self = info.This();
560
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
30 coord = (coord_t *)UNWRAP(self);
557
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
31 v = coord_get_matrix(coord)[index];
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
32
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
33 return Number::New(v);
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34 }
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
35
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36 static Handle<Value>
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 xnjsmb_coord_set_index(uint32_t index, Local<Value> value,
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38 const AccessorInfo &info) {
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
39
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
40 HandleScope scope;
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 Handle<Object> self;
560
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
42 Handle<Object> js_rt;
557
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43 redraw_man_t *rdman;
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44 coord_t *coord;
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45 co_aix v;
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46
560
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
47 if(index < 0 || index >= 6)
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
48 THROW("Invalid Index");
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
49 if(!value->IsNumber())
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
50 THROW("Invalid value");
557
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
51
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
52 self = info.This();
560
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
53 coord = (coord_t *)UNWRAP(self);
557
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
54 v = value->NumberValue();
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
55 coord_get_matrix(coord)[index] = v;
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
56
560
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
57 js_rt = GET(self, "mbrt")->ToObject();
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
58 rdman = xnjsmb_rt_rdman(js_rt);
557
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
59 rdman_coord_changed(rdman, coord);
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
60
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
61 return value;
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
62 }
560
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
63
566
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
64 /*! \brief Callback functio to add a shape to a coord in Javascript.
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
65 *
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
66 * coord.add_shape(shape)
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
67 */
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
68 static Handle<Value>
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
69 xnjsmb_coord_add_shape(const Arguments &args) {
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
70 int argc = args.Length();
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
71 Handle<Object> self = args.This();
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
72 Handle<Object> shape_obj;
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
73 Handle<Object> rt_obj;
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
74 Handle<Value> rt_val;
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
75 redraw_man_t *rdman;
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
76 coord_t *coord;
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
77 shape_t *sh;
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
78 int r;
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
79
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
80 if(argc != 1)
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
81 THROW("Invalid number of arguments (!= 1)");
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
82
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
83 shape_obj = args[0]->ToObject();
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
84 sh = (shape_t *)UNWRAP(shape_obj);
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
85 ASSERT(sh != NULL);
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
86
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
87 coord = (coord_t *)UNWRAP(self);
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
88 ASSERT(coord != NULL);
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
89
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
90 rt_val = GET(self, "mbrt");
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
91 rt_obj = rt_val->ToObject();
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
92 rdman = xnjsmb_rt_rdman(rt_obj);
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
93
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
94 r = rdman_add_shape(rdman, sh, coord);
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
95 if(r != 0)
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
96 THROW("Unknown error");
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
97
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
98 return Null();
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
99 }
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
100
560
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
101 static Persistent<ObjectTemplate> coord_obj_temp;
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
102
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
103 static void
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
104 xnjsmb_init_temp(void) {
566
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
105 Handle<FunctionTemplate> add_shape_temp;
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
106
563
bc207070e3d5 Fix issue of im-properly using persistent handler for coord object template.
Thinker K.F. Li <thinker@branda.to>
parents: 562
diff changeset
107 coord_obj_temp = Persistent<ObjectTemplate>::New(ObjectTemplate::New());
560
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
108 coord_obj_temp->SetIndexedPropertyHandler(xnjsmb_coord_get_index,
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
109 xnjsmb_coord_set_index);
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
110 coord_obj_temp->SetInternalFieldCount(1);
566
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
111
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
112 add_shape_temp = FunctionTemplate::New(xnjsmb_coord_add_shape);
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
113 SET(coord_obj_temp, "add_shape", add_shape_temp);
560
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
114 }
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
115
563
bc207070e3d5 Fix issue of im-properly using persistent handler for coord object template.
Thinker K.F. Li <thinker@branda.to>
parents: 562
diff changeset
116 /*! \brief Create and initialize a Javascript object for a coord.
bc207070e3d5 Fix issue of im-properly using persistent handler for coord object template.
Thinker K.F. Li <thinker@branda.to>
parents: 562
diff changeset
117 */
562
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
118 static Handle<Object>
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
119 xnjsmb_coord_new_jsobj(coord_t *coord, Handle<Object> parent_obj,
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
120 Handle<Object> js_rt) {
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
121 Handle<Object> coord_obj;
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
122 static int init_temp = 0;
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
123
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
124 if(!init_temp) {
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
125 xnjsmb_init_temp();
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
126 init_temp = 1;
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
127 }
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
128
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
129 coord_obj = coord_obj_temp->NewInstance();
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
130 ASSERT(coord_obj != NULL);
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
131 WRAP(coord_obj, coord);
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
132
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
133 if(!parent_obj.IsEmpty())
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
134 SET(coord_obj, "parent", parent_obj);
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
135 SET(coord_obj, "mbrt", js_rt);
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
136
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
137 return coord_obj;
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
138 }
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
139
560
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
140 /*! \brief Create a coord object associated with the rdman of the runtime.
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
141 *
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
142 * Two internal fields, coord and rdman.
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
143 */
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
144 Handle<Value>
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
145 xnjsmb_coord_new(const Arguments &args) {
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
146 HandleScope scope;
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
147 Handle<Object> js_rt;
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
148 Handle<Object> coord_obj, parent_obj;
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
149 njs_runtime_t *rt;
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
150 redraw_man_t *rdman;
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
151 coord_t *coord, *parent = NULL;
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
152 int argc;
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
153
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
154 argc = args.Length();
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
155 if(argc > 1)
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
156 THROW("Too many arguments (> 1)");
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
157
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
158 js_rt = args.This();
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
159 rt = (njs_runtime_t *)UNWRAP(js_rt);
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
160 rdman = X_njs_MB_rdman(rt);
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
161
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
162 if(argc == 1) {
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
163 parent_obj = args[0]->ToObject();
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
164 parent = (coord_t *)UNWRAP(parent_obj);
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
165 }
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
166
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
167 coord = rdman_coord_new(rdman, parent);
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
168 ASSERT(coord != NULL);
562
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
169 coord_obj = xnjsmb_coord_new_jsobj(coord, parent_obj, js_rt);
563
bc207070e3d5 Fix issue of im-properly using persistent handler for coord object template.
Thinker K.F. Li <thinker@branda.to>
parents: 562
diff changeset
170
bc207070e3d5 Fix issue of im-properly using persistent handler for coord object template.
Thinker K.F. Li <thinker@branda.to>
parents: 562
diff changeset
171 scope.Close(coord_obj);
560
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
172
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
173 return coord_obj;
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
174 }
562
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
175
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
176 /*! \brief Initialize Javascript object for root coord of a runtime.
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
177 *
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
178 * \param js_rt is the runtime object to create the root object for.
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
179 *
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
180 * After the function, js_rt.root is the object for root coord in
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
181 * Javascript.
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
182 */
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
183 void
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
184 xnjsmb_coord_mkroot(Handle<Object> js_rt) {
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
185 redraw_man_t *rdman;
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
186 coord_t *root;
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
187 Handle<Object> obj;
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
188
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
189 rdman = xnjsmb_rt_rdman(js_rt);
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
190 root = rdman_get_root(rdman);
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
191 obj = xnjsmb_coord_new_jsobj(root, Handle<Object>(NULL), js_rt);
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
192
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
193 SET(js_rt, "root", obj);
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
194 }