Skip to content
Browse files

format wrapper

  • Loading branch information...
1 parent f2ab76b commit 6ead6df165eff6176d837614b490c60ccf711fd3 @substack committed Jun 22, 2012
Showing with 55 additions and 0 deletions.
  1. +5 −0 binding.gyp
  2. +50 −0 src/format.cc
View
5 binding.gyp
@@ -4,6 +4,11 @@
"target_name": "sox",
"sources": [ "sox.cc" ],
"libraries" : [ "-lsox" ]
+ },
+ {
+ "target_name": "format",
+ "sources": [ "src/format.cc" ],
+ "libraries" : [ "-lsox" ]
}
]
}
View
50 src/format.cc
@@ -0,0 +1,50 @@
+#include <node.h>
+#include <v8.h>
+#include <node_buffer.h>
+
+using namespace v8;
+using namespace node;
+
+#include <sox.h>
+
+class Format : public ObjectWrap {
+public:
+ static Persistent<FunctionTemplate> constructor_template;
+ sox_format_t *format;
+
+ static void Initialize (Handle<Object> target) {
+ Local<FunctionTemplate> t = FunctionTemplate::New(New);
+ constructor_template = Persistent<FunctionTemplate>::New(t);
+ constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
+ constructor_template->SetClassName(String::NewSymbol("Format"));
+
+ target->Set(
+ String::NewSymbol("Format"),
+ constructor_template->GetFunction()
+ );
+
+ NODE_SET_METHOD(target, "read", Read);
+ }
+
+ static Handle<Value> New(const Arguments &args) {
+ HandleScope scope;
+ Format *format = new Format();
+ format->Wrap(args.This());
+ return args.This();
+ }
+
+ static Handle<Value> Read(const Arguments &args) {
+ HandleScope scope;
+ Handle<Value> format = constructor_template->GetFunction()->New();
+ return format;
+ }
+};
+
+Persistent<FunctionTemplate> Format::constructor_template;
+
+void init(Handle<Object> target) {
+ HandleScope scope;
+ Format::Initialize(target);
+}
+
+NODE_MODULE(format, init);

0 comments on commit 6ead6df

Please sign in to comment.
Something went wrong with that request. Please try again.