# HG changeset patch # User Thinker K.F. Li # Date 1276063858 -28800 # Node ID d796e6b8b97e79a2bdf948eb52e0c1319163ad80 # Parent a12c3448afb69623bbb91d7991fcc07c0d4d988d Real initialize a paint_color_t object for paint_color JS obj diff -r a12c3448afb6 -r d796e6b8b97e nodejs/paints.cc --- a/nodejs/paints.cc Wed Jun 09 12:28:03 2010 +0800 +++ b/nodejs/paints.cc Wed Jun 09 14:10:58 2010 +0800 @@ -8,21 +8,46 @@ using namespace v8; +#ifndef ASSERT +#define ASSERT(x) +#endif -/*! \brief Base type of all types of paints. - */ -static Handle -xnjsmb_paint(const Arguments &args) { -} /*! \brief Constructor of color paint_color_t object for Javascript. */ static Handle xnjsmb_paint_color(const Arguments &args) { + int argc = args.Length(); + Handle self = args.This(); + Handle rt; + redraw_man_t *rdman; + paint_t *paint; + float r, g, b, a; + + if(argc != 5) + THROW("Invalid number of arguments (!= 5)"); + if(!args[0]->IsObject() || !args[1]->IsNumber() || + !args[2]->IsNumber() || !args[3]->IsNumber() || + !args[4]->IsNumber()) + THROW("Invalid argument type"); + + rt = args[0]->ToObject(); + r = args[1]->ToNumber()->Value(); + g = args[2]->ToNumber()->Value(); + b = args[3]->ToNumber()->Value(); + a = args[4]->ToNumber()->Value(); + + rdman = xnjsmb_rt_rdman(rt); + paint = rdman_paint_color_new(rdman, r, g, b, a); + ASSERT(sh != NULL); + + WRAP(self, paint); + + return Null(); } -static Persistent paint_temp; -static Persistent paint_color_temp; +static Persistent xnjsmb_paint_temp; +static Persistent xnjsmb_paint_color_temp; /*! \brief Create and return a paint_color object. */ @@ -32,7 +57,7 @@ Handle rt = args.This(); Handle paint_color_obj; Handle paint_color_func; - Handle pc_args[4]; + Handle pc_args[5]; int argc; int i; @@ -48,14 +73,14 @@ pc_args[2] = args[1]; // g pc_args[3] = args[2]; // b pc_args[4] = args[3]; // a - paint_color_func = paint_color_temp->GetFunction(); - paint_color_obj = paint_color_func->NewInstance(1, pc_args); + paint_color_func = xnjsmb_paint_color_temp->GetFunction(); + paint_color_obj = paint_color_func->NewInstance(5, pc_args); scope.Close(paint_color_obj); return paint_color_obj; } -static Persistent paint_color_new_temp; +static Persistent xnjsmb_paint_color_new_temp; /*! \brief Create templates for paint types. * @@ -64,18 +89,28 @@ static void xnjsmb_init_paints(void) { Handle temp; + Handle inst_temp; - temp = FunctionTemplate::New(xnjsmb_paint); - paint_temp = Persistent::New(temp); - paint_temp->SetClassName(String::New("paint")); + /* + * Base type of paint types. + */ + temp = FunctionTemplate::New(); + xnjsmb_paint_temp = Persistent::New(temp); + xnjsmb_paint_temp->SetClassName(String::New("paint")); + /* + * Paint color + */ temp = FunctionTemplate::New(xnjsmb_paint_color); - paint_color_temp = Persistent::New(temp); - paint_color_temp->SetClassName(String::New("paint_color")); - paint_color_temp->Inherit(paint_temp); + xnjsmb_paint_color_temp = Persistent::New(temp); + xnjsmb_paint_color_temp->SetClassName(String::New("paint_color")); + xnjsmb_paint_color_temp->Inherit(xnjsmb_paint_temp); + + inst_temp = xnjsmb_paint_color_temp->InstanceTemplate(); + inst_temp->SetInternalFieldCount(1); temp = FunctionTemplate::New(xnjsmb_paint_color_new); - paint_color_new_temp = Persistent::New(temp); + xnjsmb_paint_color_new_temp = Persistent::New(temp); } void xnjsmb_paints_init_mb_rt_temp(Handle rt_temp) { @@ -88,5 +123,5 @@ } rt_proto_temp = rt_temp->PrototypeTemplate(); - SET(rt_proto_temp, "paint_color_new", paint_color_new_temp); + SET(rt_proto_temp, "paint_color_new", xnjsmb_paint_color_new_temp); } diff -r a12c3448afb6 -r d796e6b8b97e nodejs/testcase.js --- a/nodejs/testcase.js Wed Jun 09 12:28:03 2010 +0800 +++ b/nodejs/testcase.js Wed Jun 09 14:10:58 2010 +0800 @@ -18,5 +18,7 @@ coord.add_shape(path); sys.puts(mb_rt.paint_color_new); +var paint = mb_rt.paint_color_new(1, 1, 1, 1); +sys.puts(paint); setTimeout(function() { sys.puts("timeout"); }, 1000);