On Tuesday, July 10, 2012 2:52:47 PM UTC+1, aludin wrote: > > Hi, > > I am trying to return "wrapped objects" from a single object playing the > role an object factory. I ve tried something like this but it does nt seem > to work: > > // the ObjectWrap factory which also inherits from ObjectWrap. > > > class NoomraEngine: public node::ObjectWrap { > > > public: > > static Persistent<FunctionTemplate> s_ct; > > static void Initialize(Handle<Object> target); > > static Handle<Value> New(const Arguments& args); > > static Handle<Value> CreateInstrument(const Arguments& args); // > factory method for returning wrapped objects. > > > > NoomraEngine(); > > virtual ~NoomraEngine(); > > }; > > > > > Handle<Value> NoomraEngine::CreateInstrument(const Arguments& args) { > > HandleScope scope; > > // determine which object to create according to args. > > // so for example if it's a VanillaEquityOptionWrapper: > > return scope.Close(VanillaEquityOptionWrapper::New(args)); > > } > > For example VanillaEquityOptionWrapper is declared as follows and should > one of the possible wrapped objects returned by NoomraEngine: > > class VanillaEquityOptionWrapper : public node::ObjectWrap { > > private: > > //VanillaEquityOption* equityOption; > > public: > > static Persistent<FunctionTemplate> create; > > static void Initialize(Handle<Object> target); > > static Handle<Value> New(const Arguments& args); > > static Handle<Value> Price(const Arguments& args); // mapped to > priceEquity for node. > > > > VanillaEquityOptionWrapper(); > > virtual ~VanillaEquityOptionWrapper(); > > }; > > > } /* namespace noomra */ > > #endif /* VANILLAEQUITYOPTIONWRAPPER_H_ */ > > Here's the node output: > > > var addon = require('noomra'); > undefined > > var engine = new addon.NoomraEngine(); > undefined > > var equity = engine.createInstrument(); > undefined > > equity.priceEquity(); > TypeError: Object #<NoomraEngine> has no method 'priceEquity' > at repl:1:8 > at REPLServer.self.eval (repl.js:111:21) > at rli.on.e (repl.js:260:20) > at REPLServer.self.eval (repl.js:118:5) > at Interface.<anonymous> (repl.js:250:12) > at Interface.EventEmitter.emit (events.js:88:17) > at Interface._onLine (readline.js:183:10) > at Interface._line (readline.js:502:8) > at Interface._ttyWrite (readline.js:720:14) > at ReadStream.<anonymous> (readline.js:105:12) > > >
What's `equity` return in the repl? And is this the full C code that you have? (side note, this should be on nodejs, not nodejs-dev)