Thank you very much for the info, Matthias. Although, I have to admit
I haven't been able to get it working properly, yet.
Is there a way to pass arguments when creating new instances using
this method? I'm running in to issues where I define the constructor
for a function:
... = FunctionTemplate::New(constructor_callback);
Handle<Value> constructor_callback(const Arguments& args[])
{
if (args.Length() != 3)
{
return throwArgLengthException(3);
}
}
------
Now, when I call NewInstance() on the ObjectTemplate, I guess it calls
the callback function. That in turn complains that the object needs 3
arguments (as it should).
On Jan 22, 3:53 pm, Matthias Ernst <
ernst.matth...@gmail.com> wrote:
> Create a static ObjectTemplate for "Points" and set accessors and
> functions on it.
> From the function, you return an pointTemplate->NewInstance().
>
> Here's an example I have handy for "Prices", the object being backed
> by a C++ "Price" object:
>
> +Handle<ObjectTemplate> PriceTemplate() {
> + Handle<ObjectTemplate> result = ObjectTemplate::New();
> + result->SetAccessor(String::New("amount"), GetPriceAmount);
> + result->SetAccessor(String::New("currency"), GetPriceCurrency);
> +
> + result->SetInternalFieldCount(1);
> + return Persistent<ObjectTemplate>::New(result);
> +}
> +
> +Handle<Object> WrapPrice(const Price *p) {
> + static Handle<ObjectTemplate> price_template = PriceTemplate();
> +
> + Handle<Object> result = price_template->NewInstance();
> + result->SetInternalField(0, External::New(const_cast<Price *>(p)));
> + return result;
> +}
>