Skip to content

Instantly share code, notes, and snippets.

@bodokaiser
Created April 13, 2013 16:41
Show Gist options
  • Save bodokaiser/5379132 to your computer and use it in GitHub Desktop.
Save bodokaiser/5379132 to your computer and use it in GitHub Desktop.
Gist which should export a node Buffer instance to v8 environment.
#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)
@leeight
Copy link

leeight commented May 16, 2014

scope.Close(node::Buffer::New(chunk, 4)->handle_);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment