Created
August 17, 2010 13:54
-
-
Save pkrumins/530018 to your computer and use it in GitHub Desktop.
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 <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