Skip to content

janekp/node

 
 

Repository files navigation

evented I/O for v8 javascript + dynamic modules

Why:

It allows to use NodeJS as a static/dynamic library and lazily load your own native extensions in the main binary.

Example:

main.cc:

#include <node.h>

namespace demo {
	v8::Handle<v8::Value> Message(const v8::Arguments &args) {
		v8::HandleScope scope;
		v8::Local<v8::String> message = v8::String::New("Hello World!");
		
		return scope.Close(message);
	}
	
	void Initialize(v8::Handle<v8::Object> target) {
		v8::HandleScope scope;
		
		NODE_SET_METHOD(target, "message", Message);
	}
}

NODE_MODULE(demo, demo::Initialize);

int main(int argc, char *argv[]) {
	node::register_dynamic_module(&demo_module);
	
	return node::Start(argc, argv);
}

main.js:

console.log(require('demo').message());

About

evented I/O for v8 javascript + dynamic modules

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 65.9%
  • C++ 20.3%
  • C 11.3%
  • D 1.0%
  • Python 1.0%
  • Shell 0.3%
  • Other 0.2%