# HG changeset patch # User Thinker K.F. Li # Date 1275959303 -28800 # Node ID 6639d386db786e5bbb4cb5a5ed546e9240eb90b0 # Parent c0bc604489132ed2d3fad981e913f50f9138270b Function of add a shape to a coord in Javascript. diff -r c0bc60448913 -r 6639d386db78 nodejs/coord.cc --- a/nodejs/coord.cc Mon Jun 07 22:37:51 2010 +0800 +++ b/nodejs/coord.cc Tue Jun 08 09:08:23 2010 +0800 @@ -61,14 +61,56 @@ return value; } +/*! \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; + 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); + if(r != 0) + THROW("Unknown error"); + + return Null(); +} + 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. diff -r c0bc60448913 -r 6639d386db78 nodejs/testcase.js --- a/nodejs/testcase.js Mon Jun 07 22:37:51 2010 +0800 +++ b/nodejs/testcase.js Tue Jun 08 09:08:23 2010 +0800 @@ -14,5 +14,7 @@ sys.puts(mb_rt.path_new); var path = mb_rt.path_new("m 100,100 L 200,200"); sys.puts(path); +sys.puts(coord.add_shape); +coord.add_shape(path); setTimeout(function() { sys.puts("timeout"); }, 1000);