Created
November 21, 2012 22:37
-
-
Save johncant/4128311 to your computer and use it in GitHub Desktop.
How to make swig-v8 work with node.js
This file contains 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
// Extra headers required at beginning of file | |
#include <node.h> | |
#include <node/v8.h> | |
#include <node/node.h> | |
// Slightly different initializer | |
// Instead of instantiating a new object like normal swig-v8 does, we pass in the object and set attributes. The object becomes the module. | |
void <MODULE NAME>_initialize(v8::Handle<v8::Object> <MODULE NAME>_obj) { | |
SWIG_InitializeModule(0); | |
v8::HandleScope scope; | |
// a class template for creating proxies of undefined types | |
SWIGV8_SWIGTYPE_Proxy_class_templ = SWIGV8_CreateClassTemplate("SwigProxy"); | |
/* create objects for namespaces */ | |
/* create class templates */ | |
/* create and register namespace objects */ | |
// .... | |
} | |
// Right at the end | |
extern "C" { | |
void init(v8::Handle<v8::Object> target) { | |
<MODULE NAME>_initialize(target); | |
} | |
NODE_MODULE(<MODULE NAME>, init); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment