Created
May 23, 2010 21:53
-
-
Save tmpvar/411282 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <node.h> | |
| #include <node_events.h> | |
| #include <stdlib.h> | |
| using namespace v8; | |
| using namespace node; | |
| class Parser : EventEmitter { | |
| public: | |
| static void | |
| Initialize (v8::Handle<v8::Object> target) | |
| { | |
| HandleScope scope; | |
| Local<FunctionTemplate> t = FunctionTemplate::New(New); | |
| t->Inherit(EventEmitter::constructor_template); | |
| t->InstanceTemplate()->SetInternalFieldCount(1); | |
| NODE_SET_PROTOTYPE_METHOD(t, "parse", Parse); | |
| target->Set(String::NewSymbol("Parser"), t->GetFunction()); | |
| } | |
| protected: | |
| Parser() : EventEmitter() | |
| { | |
| } | |
| static Handle<Value> | |
| Parse(const v8::Arguments& args) { | |
| //HandleScope scope; | |
| return String::New("foo"); | |
| } | |
| static Handle<Value> | |
| New (const Arguments& args) | |
| { | |
| HandleScope scope; | |
| Parser *parser = new Parser(); | |
| parser->Wrap(args.This()); | |
| return args.This(); | |
| } | |
| }; | |
| extern "C" void | |
| init (Handle<Object> target) | |
| { | |
| HandleScope scope; | |
| Parser::Initialize(target); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| tmpvar@tmpvar:~/work/javascript/addon-test$ cat sanity.js && echo "=======" && node sanity.js | |
| var test = require("./build/default/addon-test"), sys = require("sys"); | |
| sys.puts(sys.inspect(test)); | |
| ======= | |
| { Parser: [Function] } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment