# HG changeset patch # User Thinker K.F. Li # Date 1276057683 -28800 # Node ID a12c3448afb69623bbb91d7991fcc07c0d4d988d # Parent 6639d386db786e5bbb4cb5a5ed546e9240eb90b0 Add dummy paint_color templates diff -r 6639d386db78 -r a12c3448afb6 nodejs/Makefile.am --- a/nodejs/Makefile.am Tue Jun 08 09:08:23 2010 +0800 +++ b/nodejs/Makefile.am Wed Jun 09 12:28:03 2010 +0800 @@ -1,5 +1,5 @@ -mbfly_node_SRCS = mbfly_njs.cc X_supp_njs.c coord.cc shapes.cc +mbfly_node_SRCS = mbfly_njs.cc X_supp_njs.c coord.cc shapes.cc paints.cc mbfly_node_CFLAGS= -I$(abs_top_builddir)/include \ -I$(abs_top_srcdir)/include \ -I$(prefix)/include \ diff -r 6639d386db78 -r a12c3448afb6 nodejs/mbfly_njs.cc --- a/nodejs/mbfly_njs.cc Tue Jun 08 09:08:23 2010 +0800 +++ b/nodejs/mbfly_njs.cc Wed Jun 09 12:28:03 2010 +0800 @@ -106,7 +106,11 @@ func = FunctionTemplate::New(xnjsmb_coord_new); SET(rt_proto_temp, "coord_new", func); + /* + * Add properties to mb_rt templates for other modules. + */ xnjsmb_shapes_init_mb_rt_temp(mb_rt_func); + xnjsmb_paints_init_mb_rt_temp(mb_rt_func); target->Set(String::New("mb_rt"), mb_rt_func->GetFunction()); } diff -r 6639d386db78 -r a12c3448afb6 nodejs/mbfly_njs.h --- a/nodejs/mbfly_njs.h Tue Jun 08 09:08:23 2010 +0800 +++ b/nodejs/mbfly_njs.h Wed Jun 09 12:28:03 2010 +0800 @@ -26,5 +26,7 @@ /* From shapes.cc */ void xnjsmb_shapes_init_mb_rt_temp(v8::Handle rt_temp); +/* From paints.cc */ +void xnjsmb_paints_init_mb_rt_temp(v8::Handle rt_temp); #endif /* __MBFLY_NJS_H_ */ diff -r 6639d386db78 -r a12c3448afb6 nodejs/paints.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nodejs/paints.cc Wed Jun 09 12:28:03 2010 +0800 @@ -0,0 +1,92 @@ +#include + +extern "C" { +#include "mb.h" +} + +#include "mbfly_njs.h" + +using namespace v8; + + +/*! \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) { +} + +static Persistent paint_temp; +static Persistent paint_color_temp; + +/*! \brief Create and return a paint_color object. + */ +static Handle +xnjsmb_paint_color_new(const Arguments &args) { + HandleScope scope; + Handle rt = args.This(); + Handle paint_color_obj; + Handle paint_color_func; + Handle pc_args[4]; + int argc; + int i; + + argc = args.Length(); + if(argc != 4) + THROW("Invalid number of arguments (r, g, b, a)"); + for(i = 0; i < 4; i++) + if(!args[i]->IsNumber()) + THROW("Invalid argument type"); + + pc_args[0] = rt; + pc_args[1] = args[0]; // r + 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); + + scope.Close(paint_color_obj); + return paint_color_obj; +} + +static Persistent paint_color_new_temp; + +/*! \brief Create templates for paint types. + * + * This function is only called one time for every execution. + */ +static void +xnjsmb_init_paints(void) { + Handle temp; + + temp = FunctionTemplate::New(xnjsmb_paint); + paint_temp = Persistent::New(temp); + paint_temp->SetClassName(String::New("paint")); + + 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); + + temp = FunctionTemplate::New(xnjsmb_paint_color_new); + paint_color_new_temp = Persistent::New(temp); +} + +void xnjsmb_paints_init_mb_rt_temp(Handle rt_temp) { + static int init_flag = 0; + Handle rt_proto_temp; + + if(!init_flag) { + xnjsmb_init_paints(); + init_flag = 1; + } + + rt_proto_temp = rt_temp->PrototypeTemplate(); + SET(rt_proto_temp, "paint_color_new", paint_color_new_temp); +} diff -r 6639d386db78 -r a12c3448afb6 nodejs/testcase.js --- a/nodejs/testcase.js Tue Jun 08 09:08:23 2010 +0800 +++ b/nodejs/testcase.js Wed Jun 09 12:28:03 2010 +0800 @@ -17,4 +17,6 @@ sys.puts(coord.add_shape); coord.add_shape(path); +sys.puts(mb_rt.paint_color_new); + setTimeout(function() { sys.puts("timeout"); }, 1000); diff -r 6639d386db78 -r a12c3448afb6 nodejs/wscript --- a/nodejs/wscript Tue Jun 08 09:08:23 2010 +0800 +++ b/nodejs/wscript Wed Jun 09 12:28:03 2010 +0800 @@ -23,7 +23,7 @@ obj = conf.new_task_gen('cxx', 'shlib', 'node_addon') obj.target = 'mbfly' - obj.source = 'mbfly_njs.cc coord.cc shapes.cc' + obj.source = 'mbfly_njs.cc coord.cc shapes.cc paints.cc' obj.add_objects = 'X_supp_njs.o' obj.staticlib = 'mbfly'