Skip to content

Instantly share code, notes, and snippets.

@pkrumins
Created August 17, 2010 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkrumins/530018 to your computer and use it in GitHub Desktop.
Save pkrumins/530018 to your computer and use it in GitHub Desktop.
#include <cstdlib>
#include <node.h>
#include <node_buffer.h>
using namespace v8;
using namespace node;
class RetBuf : public ObjectWrap {
public:
RetBuf() {}
static void
Initialize(Handle<Object> target) {
HandleScope scope;
Local<FunctionTemplate> t = FunctionTemplate::New(New);
t->InstanceTemplate()->SetInternalFieldCount(1);
NODE_SET_PROTOTYPE_METHOD(t, "getBuf", GetBuf);
}
static Handle<Value>
GetBuf(const Arguments &args) {
HandleScope scope;
Buffer *b = Buffer::New(20);
//
// How do I return the buffer from this function?
//
}
static Handle<Value>
New(const Arguments &args) {
HandleScope scope;
RetBuf *rb = new RetBuf;
rb->Wrap(args.This());
return args.This();
}
};
extern "C" void
init(Handle<Object> target)
{
HandleScope scope;
RetBuf::Initialize(target);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment