aboutsummaryrefslogtreecommitdiff
path: root/bindings/node/binding.cc
diff options
context:
space:
mode:
authorRuben Beltran del Rio <ruben@unlimited.pizza>2023-10-04 13:39:56 +0200
committerRuben Beltran del Rio <ruben@unlimited.pizza>2023-10-04 13:39:56 +0200
commitdc87cd894bad9ad0202dcd4a89e7d0af47c53fc9 (patch)
tree19fbc45b90d717b2e150f6ab711b234d9102e423 /bindings/node/binding.cc
Initial Commit
Diffstat (limited to 'bindings/node/binding.cc')
-rw-r--r--bindings/node/binding.cc28
1 files changed, 28 insertions, 0 deletions
diff --git a/bindings/node/binding.cc b/bindings/node/binding.cc
new file mode 100644
index 0000000..54f34ac
--- /dev/null
+++ b/bindings/node/binding.cc
@@ -0,0 +1,28 @@
+#include "tree_sitter/parser.h"
+#include <node.h>
+#include "nan.h"
+
+using namespace v8;
+
+extern "C" TSLanguage * tree_sitter_apinotation();
+
+namespace {
+
+NAN_METHOD(New) {}
+
+void Init(Local<Object> exports, Local<Object> module) {
+ Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
+ tpl->SetClassName(Nan::New("Language").ToLocalChecked());
+ tpl->InstanceTemplate()->SetInternalFieldCount(1);
+
+ Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
+ Local<Object> instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
+ Nan::SetInternalFieldPointer(instance, 0, tree_sitter_apinotation());
+
+ Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("apinotation").ToLocalChecked());
+ Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
+}
+
+NODE_MODULE(tree_sitter_apinotation_binding, Init)
+
+} // namespace