Mercurial > MadButterfly
comparison nodejs/coord.cc @ 661:90c7726bc953
Replace part code of coord.cc by the code generated by generator
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sun, 01 Aug 2010 20:18:59 +0800 |
parents | 6639d386db78 |
children | b6fb543d69ee |
comparison
equal
deleted
inserted
replaced
660:dde4e3cc9529 | 661:90c7726bc953 |
---|---|
14 #define ASSERT(x) | 14 #define ASSERT(x) |
15 #endif | 15 #endif |
16 | 16 |
17 using namespace v8; | 17 using namespace v8; |
18 | 18 |
19 static Handle<Value> | 19 static float |
20 xnjsmb_coord_get_index(uint32_t index, const AccessorInfo &info) { | 20 coord_get_index(coord_t *coord, Handle<Object> self, int idx, |
21 HandleScope scope; | 21 const char **err) { |
22 Handle<Object> self; | 22 if(idx < 0 || idx >= 6) { |
23 coord_t *coord; | 23 *err = "Invalid index: out of range"; |
24 co_aix v; | 24 return 0; |
25 } | |
25 | 26 |
26 if(index < 0 || index >= 6) | 27 return coord_get_matrix(coord)[idx]; |
27 THROW("Invalid index"); | |
28 | |
29 self = info.This(); | |
30 coord = (coord_t *)UNWRAP(self); | |
31 v = coord_get_matrix(coord)[index]; | |
32 | |
33 return Number::New(v); | |
34 } | 28 } |
35 | 29 |
36 static Handle<Value> | 30 static float |
37 xnjsmb_coord_set_index(uint32_t index, Local<Value> value, | 31 coord_set_index(coord_t *coord, Handle<Object> self, |
38 const AccessorInfo &info) { | 32 int idx, float v, const char **err) { |
39 | |
40 HandleScope scope; | |
41 Handle<Object> self; | |
42 Handle<Object> js_rt; | 33 Handle<Object> js_rt; |
43 redraw_man_t *rdman; | 34 redraw_man_t *rdman; |
44 coord_t *coord; | 35 |
45 co_aix v; | 36 if(idx < 0 || idx >= 6) { |
37 *err = "Invalid index: out of range"; | |
38 return 0; | |
39 } | |
46 | 40 |
47 if(index < 0 || index >= 6) | 41 coord_get_matrix(coord)[idx] = v; |
48 THROW("Invalid Index"); | 42 |
49 if(!value->IsNumber()) | |
50 THROW("Invalid value"); | |
51 | |
52 self = info.This(); | |
53 coord = (coord_t *)UNWRAP(self); | |
54 v = value->NumberValue(); | |
55 coord_get_matrix(coord)[index] = v; | |
56 | |
57 js_rt = GET(self, "mbrt")->ToObject(); | 43 js_rt = GET(self, "mbrt")->ToObject(); |
58 rdman = xnjsmb_rt_rdman(js_rt); | 44 rdman = xnjsmb_rt_rdman(js_rt); |
59 rdman_coord_changed(rdman, coord); | 45 rdman_coord_changed(rdman, coord); |
60 | 46 |
61 return value; | 47 return v; |
62 } | 48 } |
63 | 49 |
64 /*! \brief Callback functio to add a shape to a coord in Javascript. | 50 static void |
65 * | 51 xnjsmb_coord_add_shape(coord_t *coord, Handle<Object> self, |
66 * coord.add_shape(shape) | 52 shape_t *shape, const char **err) { |
67 */ | 53 Handle<Object> js_rt; |
68 static Handle<Value> | |
69 xnjsmb_coord_add_shape(const Arguments &args) { | |
70 int argc = args.Length(); | |
71 Handle<Object> self = args.This(); | |
72 Handle<Object> shape_obj; | |
73 Handle<Object> rt_obj; | |
74 Handle<Value> rt_val; | |
75 redraw_man_t *rdman; | 54 redraw_man_t *rdman; |
76 coord_t *coord; | |
77 shape_t *sh; | |
78 int r; | 55 int r; |
79 | |
80 if(argc != 1) | |
81 THROW("Invalid number of arguments (!= 1)"); | |
82 | 56 |
83 shape_obj = args[0]->ToObject(); | 57 js_rt = GET(self, "mbrt")->ToObject(); |
84 sh = (shape_t *)UNWRAP(shape_obj); | 58 rdman = xnjsmb_rt_rdman(js_rt); |
85 ASSERT(sh != NULL); | 59 r = rdman_add_shape(rdman, shape, coord); |
86 | |
87 coord = (coord_t *)UNWRAP(self); | |
88 ASSERT(coord != NULL); | |
89 | |
90 rt_val = GET(self, "mbrt"); | |
91 rt_obj = rt_val->ToObject(); | |
92 rdman = xnjsmb_rt_rdman(rt_obj); | |
93 | |
94 r = rdman_add_shape(rdman, sh, coord); | |
95 if(r != 0) | 60 if(r != 0) |
96 THROW("Unknown error"); | 61 *err = "Unknown error"; |
97 | |
98 return Null(); | |
99 } | 62 } |
100 | 63 |
101 static Persistent<ObjectTemplate> coord_obj_temp; | 64 #include "coord-inc.h" |
102 | |
103 static void | |
104 xnjsmb_init_temp(void) { | |
105 Handle<FunctionTemplate> add_shape_temp; | |
106 | |
107 coord_obj_temp = Persistent<ObjectTemplate>::New(ObjectTemplate::New()); | |
108 coord_obj_temp->SetIndexedPropertyHandler(xnjsmb_coord_get_index, | |
109 xnjsmb_coord_set_index); | |
110 coord_obj_temp->SetInternalFieldCount(1); | |
111 | |
112 add_shape_temp = FunctionTemplate::New(xnjsmb_coord_add_shape); | |
113 SET(coord_obj_temp, "add_shape", add_shape_temp); | |
114 } | |
115 | |
116 /*! \brief Create and initialize a Javascript object for a coord. | |
117 */ | |
118 static Handle<Object> | |
119 xnjsmb_coord_new_jsobj(coord_t *coord, Handle<Object> parent_obj, | |
120 Handle<Object> js_rt) { | |
121 Handle<Object> coord_obj; | |
122 static int init_temp = 0; | |
123 | |
124 if(!init_temp) { | |
125 xnjsmb_init_temp(); | |
126 init_temp = 1; | |
127 } | |
128 | |
129 coord_obj = coord_obj_temp->NewInstance(); | |
130 ASSERT(coord_obj != NULL); | |
131 WRAP(coord_obj, coord); | |
132 | |
133 if(!parent_obj.IsEmpty()) | |
134 SET(coord_obj, "parent", parent_obj); | |
135 SET(coord_obj, "mbrt", js_rt); | |
136 | |
137 return coord_obj; | |
138 } | |
139 | 65 |
140 /*! \brief Create a coord object associated with the rdman of the runtime. | 66 /*! \brief Create a coord object associated with the rdman of the runtime. |
141 * | 67 * |
142 * Two internal fields, coord and rdman. | 68 * Two internal fields, coord and rdman. |
143 */ | 69 */ |
164 parent = (coord_t *)UNWRAP(parent_obj); | 90 parent = (coord_t *)UNWRAP(parent_obj); |
165 } | 91 } |
166 | 92 |
167 coord = rdman_coord_new(rdman, parent); | 93 coord = rdman_coord_new(rdman, parent); |
168 ASSERT(coord != NULL); | 94 ASSERT(coord != NULL); |
169 coord_obj = xnjsmb_coord_new_jsobj(coord, parent_obj, js_rt); | 95 |
96 coord_obj = xnjsmb_auto_coord_new(coord).As<Object>(); | |
97 if(!parent_obj.IsEmpty()) | |
98 SET(coord_obj, "parent", parent_obj); | |
99 SET(coord_obj, "mbrt", js_rt); | |
170 | 100 |
171 scope.Close(coord_obj); | 101 scope.Close(coord_obj); |
172 | 102 |
173 return coord_obj; | 103 return coord_obj; |
174 } | 104 } |
183 void | 113 void |
184 xnjsmb_coord_mkroot(Handle<Object> js_rt) { | 114 xnjsmb_coord_mkroot(Handle<Object> js_rt) { |
185 redraw_man_t *rdman; | 115 redraw_man_t *rdman; |
186 coord_t *root; | 116 coord_t *root; |
187 Handle<Object> obj; | 117 Handle<Object> obj; |
118 static int init_flag = 0; | |
119 | |
120 if(!init_flag) { | |
121 xnjsmb_auto_coord_init(); | |
122 init_flag = 1; | |
123 } | |
188 | 124 |
189 rdman = xnjsmb_rt_rdman(js_rt); | 125 rdman = xnjsmb_rt_rdman(js_rt); |
190 root = rdman_get_root(rdman); | 126 root = rdman_get_root(rdman); |
191 obj = xnjsmb_coord_new_jsobj(root, Handle<Object>(NULL), js_rt); | 127 obj = xnjsmb_auto_coord_new(root).As<Object>(); |
128 SET(obj, "mbrt", js_rt); | |
192 | 129 |
193 SET(js_rt, "root", obj); | 130 SET(js_rt, "root", obj); |
194 } | 131 } |