]> git.r.bdr.sh - rbdr/tree-sitter-api-notation/blame - bindings/node/binding.cc
Use the plugin path as the tree-sitter config
[rbdr/tree-sitter-api-notation] / bindings / node / binding.cc
CommitLineData
dc87cd89
RBR
1#include "tree_sitter/parser.h"
2#include <node.h>
3#include "nan.h"
4
5using namespace v8;
6
0e6205eb 7extern "C" TSLanguage * tree_sitter_api_notation();
dc87cd89
RBR
8
9namespace {
10
11NAN_METHOD(New) {}
12
13void Init(Local<Object> exports, Local<Object> module) {
14 Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
15 tpl->SetClassName(Nan::New("Language").ToLocalChecked());
16 tpl->InstanceTemplate()->SetInternalFieldCount(1);
17
18 Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
19 Local<Object> instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
0e6205eb 20 Nan::SetInternalFieldPointer(instance, 0, tree_sitter_api_notation());
dc87cd89 21
0e6205eb 22 Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("api_notation").ToLocalChecked());
dc87cd89
RBR
23 Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
24}
25
0e6205eb 26NODE_MODULE(tree_sitter_api_notation_binding, Init)
dc87cd89
RBR
27
28} // namespace