Mercurial > MadButterfly
changeset 680:a588eefd3f04
Refactor to xnjsmb_coord_mod().
Move code of initializing attributes of JS coord objects to
xnjsmb_coord_mod().
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Fri, 06 Aug 2010 22:56:58 +0800 |
parents | 799c852b9065 |
children | b601a4d6f7d1 |
files | nodejs/coord.cc nodejs/coord.m4 nodejs/mbfly_njs.cc nodejs/testcase.js |
diffstat | 4 files changed, 21 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/nodejs/coord.cc Fri Aug 06 19:31:37 2010 +0800 +++ b/nodejs/coord.cc Fri Aug 06 22:56:58 2010 +0800 @@ -16,6 +16,23 @@ using namespace v8; +static void +xnjsmb_coord_mod(Handle<Object> self, coord_t *coord) { + Persistent<Object> *self_hdl; + subject_t *subject; + Handle<Value> subject_o; + + /* Keep associated js object in property store for retrieving, + * later, without create new js object. + */ + self_hdl = new Persistent<Object>(self); + mb_prop_set(&coord->obj.props, PROP_JSOBJ, self_hdl); + + subject = coord->mouse_event; + subject_o = export_xnjsmb_auto_subject_new(subject); + SET(self, "mouse_event", subject_o); +} + static float coord_get_index(coord_t *coord, Handle<Object> self, int idx, const char **err) {
--- a/nodejs/coord.m4 Fri Aug 06 19:31:37 2010 +0800 +++ b/nodejs/coord.m4 Fri Aug 06 22:56:58 2010 +0800 @@ -3,4 +3,5 @@ [METHOD([add_shape], [xnjsmb_coord_add_shape], (SELF, OBJ([shape], [shape], [shape_t]), ERR), 1, [])], ((GET_INDEX, (coord_get_index, NUMBER)), - (SET_INDEX, (coord_set_index, NUMBER)))) + (SET_INDEX, (coord_set_index, NUMBER)), + ([STMOD], [xnjsmb_coord_mod])))
--- a/nodejs/mbfly_njs.cc Fri Aug 06 19:31:37 2010 +0800 +++ b/nodejs/mbfly_njs.cc Fri Aug 06 22:56:58 2010 +0800 @@ -28,22 +28,8 @@ static void xnjsmb_coord_new_mod(Handle<Object> mbrt, Handle<Value> ret) { Handle<Object> ret_obj = ret->ToObject(); - Persistent<Object> *ret_obj_hdl; - coord_t *coord; - subject_t *subject; - Handle<Value> subject_o; SET(ret_obj, "mbrt", mbrt); - coord = (coord_t *)UNWRAP(ret_obj); - /* Keep associated js object in property store for retrieving, - * later, without create new js object. - */ - ret_obj_hdl = new Persistent<Object>(ret_obj); - mb_prop_set(&coord->obj.props, PROP_JSOBJ, ret_obj_hdl); - - subject = coord->mouse_event; - subject_o = export_xnjsmb_auto_subject_new(subject); - SET(ret_obj, "subject", subject_o); } #define xnjsmb_auto_coord_new export_xnjsmb_auto_coord_new @@ -68,9 +54,7 @@ _X_njs_MB_new(Handle<Object> self, char *display_name, int width, int height) { njs_runtime_t *obj; - coord_t *root; subject_t *subject; - Handle<Object> root_o; Handle<Value> subject_o; obj = X_njs_MB_new(display_name, width, height); @@ -81,12 +65,6 @@ X_njs_MB_init_handle_connection(obj); xnjsmb_coord_mkroot(self); - root_o = GET(self, "root")->ToObject(); - root = (coord_t *)UNWRAP(root_o); - subject = root->mouse_event; - subject_o = export_xnjsmb_auto_subject_new(subject); - SET(root_o, "subject", subject_o); - subject = X_MB_kbevents(obj->xrt); subject_o = export_xnjsmb_auto_subject_new(subject); SET(self, "kbevent", subject_o);
--- a/nodejs/testcase.js Fri Aug 06 19:31:37 2010 +0800 +++ b/nodejs/testcase.js Fri Aug 06 22:56:58 2010 +0800 @@ -52,10 +52,10 @@ }, 20); setTimeout(function() { sys.puts("timeout"); }, 1000); -sys.puts(root.subject); +sys.puts(root.mouse_event); var observer; /* Mouse button pressed */ -observer = root.subject.add_event_observer(4, function(evt) { +observer = root.mouse_event.add_event_observer(4, function(evt) { sys.puts("mouse " + evt.x + " " + evt.y); });