├── LICENSE ├── helloworld ├── helloworld.cc └── wscript ├── helloworld_eio ├── helloworld_eio.cc └── wscript └── helloworld_js └── index.js /LICENSE: -------------------------------------------------------------------------------- 1 | Public Domain Certification 2 | 3 | Copyright-Only Dedication (based on United States law) or Public Domain 4 | Certification 5 | 6 | The person or persons who have associated work with this document (the 7 | "Dedicator" or "Certifier") hereby either (a) certifies that, to the best of 8 | his knowledge, the work of authorship identified is in the public domain of the 9 | country from which the work is published, or (b) hereby dedicates whatever 10 | copyright the dedicators holds in the work of authorship identified below (the 11 | "Work") to the public domain. A certifier, moreover, dedicates any copyright 12 | interest he may have in the associated work, and for these purposes, is 13 | described as a "dedicator" below. 14 | 15 | A certifier has taken reasonable steps to verify the copyright status of this 16 | work. Certifier recognizes that his good faith efforts may not shield him from 17 | liability if in fact the work certified is not in the public domain. 18 | 19 | Dedicator makes this dedication for the benefit of the public at large and to 20 | the detriment of the Dedicator's heirs and successors. Dedicator intends this 21 | dedication to be an overt act of relinquishment in perpetuity of all present 22 | and future rights under copyright law, whether vested or contingent, in the 23 | Work. Dedicator understands that such relinquishment of all rights includes the 24 | relinquishment of all rights to enforce (by lawsuit or otherwise) those 25 | copyrights in the Work. 26 | 27 | Dedicator recognizes that, once placed in the public domain, the Work may be 28 | freely reproduced, distributed, transmitted, used, modified, built upon, or 29 | otherwise exploited by anyone for any purpose, commercial or non-commercial, 30 | and in any way, including by methods that have not yet been invented or 31 | conceived. -------------------------------------------------------------------------------- /helloworld/helloworld.cc: -------------------------------------------------------------------------------- 1 | /* This code is PUBLIC DOMAIN, and is distributed on an "AS IS" BASIS, 2 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND. See the accompanying 3 | * LICENSE file. 4 | */ 5 | 6 | #include 7 | #include 8 | 9 | using namespace node; 10 | using namespace v8; 11 | 12 | class HelloWorld: ObjectWrap 13 | { 14 | private: 15 | int m_count; 16 | public: 17 | 18 | static Persistent s_ct; 19 | static void Init(Handle target) 20 | { 21 | HandleScope scope; 22 | 23 | Local t = FunctionTemplate::New(New); 24 | 25 | s_ct = Persistent::New(t); 26 | s_ct->InstanceTemplate()->SetInternalFieldCount(1); 27 | s_ct->SetClassName(String::NewSymbol("HelloWorld")); 28 | 29 | NODE_SET_PROTOTYPE_METHOD(s_ct, "hello", Hello); 30 | 31 | target->Set(String::NewSymbol("HelloWorld"), 32 | s_ct->GetFunction()); 33 | } 34 | 35 | HelloWorld() : 36 | m_count(0) 37 | { 38 | } 39 | 40 | ~HelloWorld() 41 | { 42 | } 43 | 44 | static Handle New(const Arguments& args) 45 | { 46 | HandleScope scope; 47 | HelloWorld* hw = new HelloWorld(); 48 | hw->Wrap(args.This()); 49 | return args.This(); 50 | } 51 | 52 | static Handle Hello(const Arguments& args) 53 | { 54 | HandleScope scope; 55 | HelloWorld* hw = ObjectWrap::Unwrap(args.This()); 56 | hw->m_count++; 57 | Local result = String::New("Hello World"); 58 | return scope.Close(result); 59 | } 60 | 61 | }; 62 | 63 | Persistent HelloWorld::s_ct; 64 | 65 | extern "C" { 66 | static void init (Handle target) 67 | { 68 | HelloWorld::Init(target); 69 | } 70 | 71 | NODE_MODULE(helloworld, init); 72 | } 73 | -------------------------------------------------------------------------------- /helloworld/wscript: -------------------------------------------------------------------------------- 1 | 2 | 3 | def set_options(opt): 4 | opt.tool_options("compiler_cxx") 5 | 6 | def configure(conf): 7 | conf.check_tool("compiler_cxx") 8 | conf.check_tool("node_addon") 9 | 10 | def build(bld): 11 | obj = bld.new_task_gen("cxx", "shlib", "node_addon") 12 | obj.cxxflags = ["-g", "-D_FILE_OFFSET_BITS=64", "-D_LARGEFILE_SOURCE", "-Wall"] 13 | obj.target = "helloworld" 14 | obj.source = "helloworld.cc" 15 | -------------------------------------------------------------------------------- /helloworld_eio/helloworld_eio.cc: -------------------------------------------------------------------------------- 1 | /* This code is PUBLIC DOMAIN, and is distributed on an "AS IS" BASIS, 2 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND. See the accompanying 3 | * LICENSE file. 4 | */ 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | using namespace node; 12 | using namespace v8; 13 | 14 | #define REQ_FUN_ARG(I, VAR) \ 15 | if (args.Length() <= (I) || !args[I]->IsFunction()) \ 16 | return ThrowException(Exception::TypeError( \ 17 | String::New("Argument " #I " must be a function"))); \ 18 | Local VAR = Local::Cast(args[I]); 19 | 20 | class HelloWorldEio: ObjectWrap 21 | { 22 | private: 23 | int m_count; 24 | public: 25 | 26 | static Persistent s_ct; 27 | static void Init(Handle target) 28 | { 29 | HandleScope scope; 30 | 31 | Local t = FunctionTemplate::New(New); 32 | 33 | s_ct = Persistent::New(t); 34 | s_ct->InstanceTemplate()->SetInternalFieldCount(1); 35 | s_ct->SetClassName(String::NewSymbol("HelloWorldEio")); 36 | 37 | NODE_SET_PROTOTYPE_METHOD(s_ct, "hello", Hello); 38 | 39 | target->Set(String::NewSymbol("HelloWorldEio"), 40 | s_ct->GetFunction()); 41 | } 42 | 43 | HelloWorldEio() : 44 | m_count(0) 45 | { 46 | } 47 | 48 | ~HelloWorldEio() 49 | { 50 | } 51 | 52 | static Handle New(const Arguments& args) 53 | { 54 | HandleScope scope; 55 | HelloWorldEio* hw = new HelloWorldEio(); 56 | hw->Wrap(args.This()); 57 | return args.This(); 58 | } 59 | 60 | struct hello_baton_t { 61 | HelloWorldEio *hw; 62 | int increment_by; 63 | int sleep_for; 64 | Persistent cb; 65 | }; 66 | 67 | static Handle Hello(const Arguments& args) 68 | { 69 | HandleScope scope; 70 | 71 | REQ_FUN_ARG(0, cb); 72 | 73 | HelloWorldEio* hw = ObjectWrap::Unwrap(args.This()); 74 | 75 | hello_baton_t *baton = new hello_baton_t(); 76 | baton->hw = hw; 77 | baton->increment_by = 2; 78 | baton->sleep_for = 1; 79 | baton->cb = Persistent::New(cb); 80 | 81 | hw->Ref(); 82 | 83 | eio_custom(EIO_Hello, EIO_PRI_DEFAULT, EIO_AfterHello, baton); 84 | ev_ref(EV_DEFAULT_UC); 85 | 86 | return Undefined(); 87 | } 88 | 89 | 90 | static int EIO_Hello(eio_req *req) 91 | { 92 | hello_baton_t *baton = static_cast(req->data); 93 | 94 | sleep(baton->sleep_for); 95 | 96 | baton->hw->m_count += baton->increment_by; 97 | 98 | return 0; 99 | } 100 | 101 | static int EIO_AfterHello(eio_req *req) 102 | { 103 | HandleScope scope; 104 | hello_baton_t *baton = static_cast(req->data); 105 | ev_unref(EV_DEFAULT_UC); 106 | baton->hw->Unref(); 107 | 108 | Local argv[1]; 109 | 110 | argv[0] = String::New("Hello World"); 111 | 112 | TryCatch try_catch; 113 | 114 | baton->cb->Call(Context::GetCurrent()->Global(), 1, argv); 115 | 116 | if (try_catch.HasCaught()) { 117 | FatalException(try_catch); 118 | } 119 | 120 | baton->cb.Dispose(); 121 | 122 | delete baton; 123 | return 0; 124 | } 125 | 126 | }; 127 | 128 | Persistent HelloWorldEio::s_ct; 129 | 130 | extern "C" { 131 | static void init (Handle target) 132 | { 133 | HelloWorldEio::Init(target); 134 | } 135 | 136 | NODE_MODULE(helloworld_eio, init); 137 | } 138 | -------------------------------------------------------------------------------- /helloworld_eio/wscript: -------------------------------------------------------------------------------- 1 | 2 | 3 | def set_options(opt): 4 | opt.tool_options("compiler_cxx") 5 | 6 | def configure(conf): 7 | conf.check_tool("compiler_cxx") 8 | conf.check_tool("node_addon") 9 | 10 | def build(bld): 11 | obj = bld.new_task_gen("cxx", "shlib", "node_addon") 12 | obj.cxxflags = ["-g", "-D_FILE_OFFSET_BITS=64", "-D_LARGEFILE_SOURCE", "-Wall"] 13 | obj.target = "helloworld_eio" 14 | obj.source = "helloworld_eio.cc" 15 | -------------------------------------------------------------------------------- /helloworld_js/index.js: -------------------------------------------------------------------------------- 1 | /* This code is PUBLIC DOMAIN, and is distributed on an "AS IS" BASIS, 2 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND. See the accompanying 3 | * LICENSE file. 4 | */ 5 | 6 | HelloWorldJs = function() { 7 | this.m_count = 0; 8 | }; 9 | 10 | 11 | HelloWorldJs.prototype.hello = function() 12 | { 13 | this.m_count++; 14 | return "Hello World"; 15 | }; 16 | 17 | exports.HelloWorldJs = HelloWorldJs; 18 | --------------------------------------------------------------------------------