Mercurial > MadButterfly
annotate nodejs/coord.cc @ 674:5c8387fd123e
Support user defined accessors on binding generated
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Fri, 06 Aug 2010 00:50:40 +0800 |
parents | 7315c6e953c3 |
children | a588eefd3f04 |
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 |
666
b6fb543d69ee
Use binding generator to implement mb_rt
Thinker K.F. Li <thinker@branda.to>
parents:
661
diff
changeset
|
66 Handle<Value> export_xnjsmb_auto_coord_new(coord_t *coord) { |
b6fb543d69ee
Use binding generator to implement mb_rt
Thinker K.F. Li <thinker@branda.to>
parents:
661
diff
changeset
|
67 xnjsmb_auto_coord_new(coord); |
b6fb543d69ee
Use binding generator to implement mb_rt
Thinker K.F. Li <thinker@branda.to>
parents:
661
diff
changeset
|
68 } |
b6fb543d69ee
Use binding generator to implement mb_rt
Thinker K.F. Li <thinker@branda.to>
parents:
661
diff
changeset
|
69 |
562
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
70 /*! \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
|
71 * |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
72 * \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
|
73 * |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
74 * 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
|
75 * Javascript. |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
76 */ |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
77 void |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
78 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
|
79 redraw_man_t *rdman; |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
80 coord_t *root; |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
81 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
|
82 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
|
83 |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
84 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
|
85 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
|
86 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
|
87 } |
562
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
88 |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
89 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
|
90 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
|
91 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
|
92 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
|
93 |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
94 SET(js_rt, "root", obj); |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
95 } |