Permalink
Browse files

initial commit

Only an "address" function so far :D
  • Loading branch information...
0 parents commit b150c2c92a4722ad038da7071984feb6424ea144 @TooTallNate committed May 1, 2012
Showing with 86 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +8 −0 binding.gyp
  3. +16 −0 package.json
  4. +35 −0 src/binding.cc
  5. +26 −0 test.js
@@ -0,0 +1 @@
+/build
@@ -0,0 +1,8 @@
+{
+ 'targets': [
+ {
+ 'target_name': 'binding',
+ 'sources': [ 'src/binding.cc' ]
+ }
+ ]
+}
@@ -0,0 +1,16 @@
+{ "name": "ref"
+, "description": "Native Buffer extensions"
+, "keywords": [ "native", "buffer", "extensions", "c++" ]
+, "version": "0.0.0"
+, "author": "Nathan Rajlich <nathan@tootallnate.net> (http://tootallnate.net)"
+, "repository": { "type": "git", "url": "git://github.com/TooTallNate/ref.git" }
+, "main": "./index.js"
+, "scripts": {
+ "test": "mocha --reporter spec"
+ }
+, "devDependencies": {
+ "mocha": "*"
+ , "canvas": "*"
+ }
+, "engines": { "node": "*" }
+}
@@ -0,0 +1,35 @@
+#include <v8.h>
+#include <node.h>
+#include <node_buffer.h>
+
+using namespace v8;
+using namespace node;
+
+namespace {
+
+
+Handle<Value> Address(const Arguments& args) {
+ HandleScope scope;
+
+ Local<Value> buf = args[0];
+ if (!Buffer::HasInstance(buf)) {
+ return ThrowException(Exception::TypeError(
+ String::New("address: Buffer instance expected")));
+ }
+
+ size_t address = (size_t)Buffer::Data(buf.As<Object>());
+ Local<Number> ret = Number::New(address);
+
+ return scope.Close(ret);
+}
+
+
+
+} // anonymous namespace
+
+void init (Handle<Object> target) {
+ HandleScope scope;
+
+ NODE_SET_METHOD(target, "address", Address);
+}
+NODE_MODULE(binding, init);
@@ -0,0 +1,26 @@
+
+var ref = require('./build/Release/binding')
+
+var b = Buffer('hello world')
+var ad = ref.address(b)
+console.error(ad, b)
+
+var b = b.slice(1)
+var ad = ref.address(b)
+console.error(ad, b)
+
+var b = b.slice(1)
+var ad = ref.address(b)
+console.error(ad, b)
+
+var b = b.slice(1)
+var ad = ref.address(b)
+console.error(ad, b)
+
+var b = b.slice(1)
+var ad = ref.address(b)
+console.error(ad, b)
+
+var b = b.slice(1)
+var ad = ref.address(b)
+console.error(ad, b)

0 comments on commit b150c2c

Please sign in to comment.