# HG changeset patch # User Thinker K.F. Li # Date 1280665139 -28800 # Node ID 90c7726bc95369f5d4431d50338e7674282c0a18 # Parent dde4e3cc9529733e43f048983fb747c1cb81c26a Replace part code of coord.cc by the code generated by generator diff -r dde4e3cc9529 -r 90c7726bc953 nodejs/coord.cc --- a/nodejs/coord.cc Sun Aug 01 20:17:39 2010 +0800 +++ b/nodejs/coord.cc Sun Aug 01 20:18:59 2010 +0800 @@ -16,126 +16,52 @@ using namespace v8; -static Handle -xnjsmb_coord_get_index(uint32_t index, const AccessorInfo &info) { - HandleScope scope; - Handle self; - coord_t *coord; - co_aix v; +static float +coord_get_index(coord_t *coord, Handle self, int idx, + const char **err) { + if(idx < 0 || idx >= 6) { + *err = "Invalid index: out of range"; + return 0; + } - if(index < 0 || index >= 6) - THROW("Invalid index"); - - self = info.This(); - coord = (coord_t *)UNWRAP(self); - v = coord_get_matrix(coord)[index]; - - return Number::New(v); + return coord_get_matrix(coord)[idx]; } -static Handle -xnjsmb_coord_set_index(uint32_t index, Local value, - const AccessorInfo &info) { - - HandleScope scope; - Handle self; +static float +coord_set_index(coord_t *coord, Handle self, + int idx, float v, const char **err) { Handle js_rt; redraw_man_t *rdman; - coord_t *coord; - co_aix v; + + if(idx < 0 || idx >= 6) { + *err = "Invalid index: out of range"; + return 0; + } - if(index < 0 || index >= 6) - THROW("Invalid Index"); - if(!value->IsNumber()) - THROW("Invalid value"); - - self = info.This(); - coord = (coord_t *)UNWRAP(self); - v = value->NumberValue(); - coord_get_matrix(coord)[index] = v; - + coord_get_matrix(coord)[idx] = v; + js_rt = GET(self, "mbrt")->ToObject(); rdman = xnjsmb_rt_rdman(js_rt); rdman_coord_changed(rdman, coord); - return value; + return v; } -/*! \brief Callback functio to add a shape to a coord in Javascript. - * - * coord.add_shape(shape) - */ -static Handle -xnjsmb_coord_add_shape(const Arguments &args) { - int argc = args.Length(); - Handle self = args.This(); - Handle shape_obj; - Handle rt_obj; - Handle rt_val; +static void +xnjsmb_coord_add_shape(coord_t *coord, Handle self, + shape_t *shape, const char **err) { + Handle js_rt; redraw_man_t *rdman; - coord_t *coord; - shape_t *sh; int r; - - if(argc != 1) - THROW("Invalid number of arguments (!= 1)"); - shape_obj = args[0]->ToObject(); - sh = (shape_t *)UNWRAP(shape_obj); - ASSERT(sh != NULL); - - coord = (coord_t *)UNWRAP(self); - ASSERT(coord != NULL); - - rt_val = GET(self, "mbrt"); - rt_obj = rt_val->ToObject(); - rdman = xnjsmb_rt_rdman(rt_obj); - - r = rdman_add_shape(rdman, sh, coord); + js_rt = GET(self, "mbrt")->ToObject(); + rdman = xnjsmb_rt_rdman(js_rt); + r = rdman_add_shape(rdman, shape, coord); if(r != 0) - THROW("Unknown error"); - - return Null(); + *err = "Unknown error"; } -static Persistent coord_obj_temp; - -static void -xnjsmb_init_temp(void) { - Handle add_shape_temp; - - coord_obj_temp = Persistent::New(ObjectTemplate::New()); - coord_obj_temp->SetIndexedPropertyHandler(xnjsmb_coord_get_index, - xnjsmb_coord_set_index); - coord_obj_temp->SetInternalFieldCount(1); - - add_shape_temp = FunctionTemplate::New(xnjsmb_coord_add_shape); - SET(coord_obj_temp, "add_shape", add_shape_temp); -} - -/*! \brief Create and initialize a Javascript object for a coord. - */ -static Handle -xnjsmb_coord_new_jsobj(coord_t *coord, Handle parent_obj, - Handle js_rt) { - Handle coord_obj; - static int init_temp = 0; - - if(!init_temp) { - xnjsmb_init_temp(); - init_temp = 1; - } - - coord_obj = coord_obj_temp->NewInstance(); - ASSERT(coord_obj != NULL); - WRAP(coord_obj, coord); - - if(!parent_obj.IsEmpty()) - SET(coord_obj, "parent", parent_obj); - SET(coord_obj, "mbrt", js_rt); - - return coord_obj; -} +#include "coord-inc.h" /*! \brief Create a coord object associated with the rdman of the runtime. * @@ -166,7 +92,11 @@ coord = rdman_coord_new(rdman, parent); ASSERT(coord != NULL); - coord_obj = xnjsmb_coord_new_jsobj(coord, parent_obj, js_rt); + + coord_obj = xnjsmb_auto_coord_new(coord).As(); + if(!parent_obj.IsEmpty()) + SET(coord_obj, "parent", parent_obj); + SET(coord_obj, "mbrt", js_rt); scope.Close(coord_obj); @@ -185,10 +115,17 @@ redraw_man_t *rdman; coord_t *root; Handle obj; + static int init_flag = 0; + + if(!init_flag) { + xnjsmb_auto_coord_init(); + init_flag = 1; + } rdman = xnjsmb_rt_rdman(js_rt); root = rdman_get_root(rdman); - obj = xnjsmb_coord_new_jsobj(root, Handle(NULL), js_rt); + obj = xnjsmb_auto_coord_new(root).As(); + SET(obj, "mbrt", js_rt); SET(js_rt, "root", obj); } diff -r dde4e3cc9529 -r 90c7726bc953 nodejs/coord.m4 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nodejs/coord.m4 Sun Aug 01 20:18:59 2010 +0800 @@ -0,0 +1,6 @@ +define([PROJ_PREFIX], [xnjsmb_auto_])dnl +STRUCT([coord], [coord_t], [], + [METHOD([add_shape], [xnjsmb_coord_add_shape], + (SELF, OBJ([shape], [shape_t]), ERR), 1, [])], + ((GET_INDEX, (coord_get_index, NUMBER)), + (SET_INDEX, (coord_set_index, NUMBER)))) diff -r dde4e3cc9529 -r 90c7726bc953 nodejs/wscript --- a/nodejs/wscript Sun Aug 01 20:17:39 2010 +0800 +++ b/nodejs/wscript Sun Aug 01 20:18:59 2010 +0800 @@ -24,12 +24,15 @@ conf(rule='m4 -I ${SRCDIR}/../tools gen_v8_binding.m4 ${SRC} > ${TGT}', source='observer.m4', target='observer-inc.h', name='observer-inc', shell=True, always=True, before=['cxx']) + conf(rule='m4 -I ${SRCDIR}/../tools gen_v8_binding.m4 ${SRC} > ${TGT}', + source='coord.m4', target='coord-inc.h', + name='coord-inc', shell=True, always=True, before=['cxx']) obj = conf.new_task_gen('cxx', 'shlib', 'node_addon') obj.target = 'mbfly' - obj.source = 'mbfly_njs.cc coord.cc shapes.cc paints.cc font.cc ' + \ + obj.source = 'mbfly_njs.cc shapes.cc paints.cc font.cc ' + \ 'image_ldr.cc' - obj.add_objects = 'X_supp_njs.o observer.o' + obj.add_objects = 'X_supp_njs.o observer.o coord.o' obj.staticlib = 'mbfly' obj = conf.new_task_gen('cc', 'shlib', 'node_addon') @@ -40,4 +43,9 @@ obj.target = 'observer.o' obj.source = 'observer.cc' obj.includes = '.' + + obj = conf.new_task_gen('cxx', 'shlib', 'node_addon') + obj.target = 'coord.o' + obj.source = 'coord.cc' + obj.includes = '.' pass