Created
April 13, 2013 16:41
-
-
Save bodokaiser/5379132 to your computer and use it in GitHub Desktop.
Gist which should export a node Buffer instance to v8 environment.
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
#include <v8.h> | |
#include <node.h> | |
#include <node_buffer.h> | |
using namespace v8; | |
Handle<Value> CreateBuffer(const Arguments &args) { | |
HandleScope scope; | |
char chunk[4]; | |
chunk[0] = 0x48; | |
chunk[1] = 0x7a; | |
chunk[2] = 0xcc; | |
chunk[3] = 0x0f; | |
scope.Close(node::Buffer::New(chunk, 4)); | |
} | |
void Init(Handle<Object> exports) { | |
exports->Set(String::New("createBuffer"), | |
FunctionTemplate::New(CreateBuffer)->GetFunction()); | |
} | |
NODE_MODULE(test, Init) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
scope.Close(node::Buffer::New(chunk, 4)->handle_);