Mercurial > MadButterfly
changeset 643:a65720721c60
Fix issue of exception of internal field.
img_ldr is a function to return a new img_ldr, not a constructor as in
previous implementation. This changeset fix semantic error on
xnjsmb_img_ldr_new().
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Wed, 28 Jul 2010 08:31:15 +0800 |
parents | 4f7b4ff31c0c |
children | c9f8c7e6f57e |
files | nodejs/image_ldr.cc nodejs/sample.png nodejs/shapes.cc nodejs/testcase.js |
diffstat | 4 files changed, 43 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/nodejs/image_ldr.cc Tue Jul 27 22:02:40 2010 +0800 +++ b/nodejs/image_ldr.cc Wed Jul 28 08:31:15 2010 +0800 @@ -59,7 +59,7 @@ /*! \brief Constructor function of img_ldr Javascript objects. */ static Handle<Value> -xnjsmb_img_ldr_new(const Arguments &args) { +xnjsmb_img_ldr(const Arguments &args) { HandleScope scope; int argc = args.Length(); Handle<Object> self = args.This(); @@ -82,6 +82,29 @@ return Null(); } +static Persistent<FunctionTemplate> xnjsmb_img_ldr_temp; + +static Handle<Value> +xnjsmb_img_ldr_new(const Arguments &args) { + HandleScope scope; + int argc = args.Length(); + Handle<Value> il_args[1]; + Handle<Object> img_ldr; + Handle<Function> func; + + if(argc != 1) + THROW("Invalid number of arguments (!= 1)"); + if(!args[0]->IsString()) + THROW("Invalid argument type"); + + il_args[0] = args[0]; + func = xnjsmb_img_ldr_temp->GetFunction(); + img_ldr = func->NewInstance(1, il_args); + + scope.Close(img_ldr); + return img_ldr; +} + /* @} */ /*! \brief Initialize image loader. @@ -92,6 +115,7 @@ void xnjsmb_img_ldr_init_mb_rt_temp(Handle<Object> rt_temp) { HandleScope scope; + Handle<FunctionTemplate> img_ldr_temp; Handle<FunctionTemplate> img_ldr_new_temp; Handle<ObjectTemplate> ldr_inst_temp; Handle<ObjectTemplate> ldr_proto_temp; @@ -104,15 +128,19 @@ img_data_temp = Persistent<ObjectTemplate>::New(_img_data_temp); /* Setup img_ldr class */ - img_ldr_new_temp = FunctionTemplate::New(xnjsmb_img_ldr_new); - img_ldr_new_temp->SetClassName(String::New("img_ldr")); - ldr_inst_temp = img_ldr_new_temp->InstanceTemplate(); + img_ldr_temp = FunctionTemplate::New(xnjsmb_img_ldr); + img_ldr_temp->SetClassName(String::New("img_ldr")); + ldr_inst_temp = img_ldr_temp->InstanceTemplate(); ldr_inst_temp->SetInternalFieldCount(1); /* Set method load() for img_ldr */ - ldr_proto_temp = img_ldr_new_temp->PrototypeTemplate(); + ldr_proto_temp = img_ldr_temp->PrototypeTemplate(); img_ldr_load_temp = FunctionTemplate::New(xnjsmb_img_ldr_load); SET(ldr_proto_temp, "load", img_ldr_load_temp); - + + xnjsmb_img_ldr_temp = Persistent<FunctionTemplate>::New(img_ldr_temp); + + /* Initialize img_ldr_new function */ + img_ldr_new_temp = FunctionTemplate::New(xnjsmb_img_ldr_new); SET(rt_temp, "img_ldr_new", img_ldr_new_temp->GetFunction()); }
--- a/nodejs/shapes.cc Tue Jul 27 22:02:40 2010 +0800 +++ b/nodejs/shapes.cc Wed Jul 28 08:31:15 2010 +0800 @@ -435,6 +435,7 @@ xnjsmb_init_shape_temp(); xnjsmb_init_path_temp(); xnjsmb_init_stext_temp(); + xnjsmb_init_image_temp(); temp_init_flag = 1; }
--- a/nodejs/testcase.js Tue Jul 27 22:02:40 2010 +0800 +++ b/nodejs/testcase.js Wed Jul 28 08:31:15 2010 +0800 @@ -11,6 +11,14 @@ sys.puts("coord matrix: " + [coord[0], coord[1], coord[2], coord[3], coord[4], coord[5]]); +/* Testcase for image shapes */ +var img = mb_rt.image_new(10, 10, 50, 50); +var ldr = mbfly.img_ldr_new("."); +var img_data = ldr.load("sample.png"); +var paint = mb_rt.paint_image_new(img_data); +paint.fill(img); +root.add_shape(img); + sys.puts(mb_rt.path_new); var path = mb_rt.path_new("m 100,50 L 120,50 L 200,150 L 180,150 z"); sys.puts(path);