Mercurial > MadButterfly
annotate 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 |
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 |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
19 static float |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
20 coord_get_index(coord_t *coord, Handle<Object> self, int idx, |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
21 const char **err) { |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
22 if(idx < 0 || idx >= 6) { |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
23 *err = "Invalid index: out of range"; |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
24 return 0; |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
25 } |
557
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
26 |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
27 return coord_get_matrix(coord)[idx]; |
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 |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
30 static float |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
31 coord_set_index(coord_t *coord, Handle<Object> self, |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
32 int idx, float v, const char **err) { |
560
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
33 Handle<Object> js_rt; |
557
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
34 redraw_man_t *rdman; |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
35 |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
36 if(idx < 0 || idx >= 6) { |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
37 *err = "Invalid index: out of range"; |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
38 return 0; |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
39 } |
557
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
40 |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
41 coord_get_matrix(coord)[idx] = v; |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
42 |
560
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
43 js_rt = GET(self, "mbrt")->ToObject(); |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
44 rdman = xnjsmb_rt_rdman(js_rt); |
557
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
45 rdman_coord_changed(rdman, coord); |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
46 |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
47 return v; |
557
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
48 } |
560
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
49 |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
50 static void |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
51 xnjsmb_coord_add_shape(coord_t *coord, Handle<Object> self, |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
52 shape_t *shape, const char **err) { |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
53 Handle<Object> js_rt; |
566
6639d386db78
Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents:
563
diff
changeset
|
54 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
|
55 int r; |
6639d386db78
Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents:
563
diff
changeset
|
56 |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
57 js_rt = GET(self, "mbrt")->ToObject(); |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
58 rdman = xnjsmb_rt_rdman(js_rt); |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
59 r = rdman_add_shape(rdman, shape, coord); |
566
6639d386db78
Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents:
563
diff
changeset
|
60 if(r != 0) |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
61 *err = "Unknown error"; |
566
6639d386db78
Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents:
563
diff
changeset
|
62 } |
6639d386db78
Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents:
563
diff
changeset
|
63 |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
64 #include "coord-inc.h" |
562
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
65 |
560
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
66 /*! \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
|
67 * |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
68 * Two internal fields, coord and rdman. |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
69 */ |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
70 Handle<Value> |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
71 xnjsmb_coord_new(const Arguments &args) { |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
72 HandleScope scope; |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
73 Handle<Object> js_rt; |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
74 Handle<Object> coord_obj, parent_obj; |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
75 njs_runtime_t *rt; |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
76 redraw_man_t *rdman; |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
77 coord_t *coord, *parent = NULL; |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
78 int argc; |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
79 |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
80 argc = args.Length(); |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
81 if(argc > 1) |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
82 THROW("Too many arguments (> 1)"); |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
83 |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
84 js_rt = args.This(); |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
85 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
|
86 rdman = X_njs_MB_rdman(rt); |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
87 |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
88 if(argc == 1) { |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
89 parent_obj = args[0]->ToObject(); |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
90 parent = (coord_t *)UNWRAP(parent_obj); |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
91 } |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
92 |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
93 coord = rdman_coord_new(rdman, parent); |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
94 ASSERT(coord != NULL); |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
95 |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
96 coord_obj = xnjsmb_auto_coord_new(coord).As<Object>(); |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
97 if(!parent_obj.IsEmpty()) |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
98 SET(coord_obj, "parent", parent_obj); |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
99 SET(coord_obj, "mbrt", 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
|
100 |
bc207070e3d5
Fix issue of im-properly using persistent handler for coord object template.
Thinker K.F. Li <thinker@branda.to>
parents:
562
diff
changeset
|
101 scope.Close(coord_obj); |
560
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 return coord_obj; |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
104 } |
562
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
105 |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
106 /*! \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
|
107 * |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
108 * \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
|
109 * |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
110 * 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
|
111 * Javascript. |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
112 */ |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
113 void |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
114 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
|
115 redraw_man_t *rdman; |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
116 coord_t *root; |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
117 Handle<Object> obj; |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
118 static int init_flag = 0; |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
119 |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
120 if(!init_flag) { |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
121 xnjsmb_auto_coord_init(); |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
122 init_flag = 1; |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
123 } |
562
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
124 |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
125 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
|
126 root = rdman_get_root(rdman); |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
127 obj = xnjsmb_auto_coord_new(root).As<Object>(); |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
128 SET(obj, "mbrt", js_rt); |
562
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
129 |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
130 SET(js_rt, "root", obj); |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
131 } |