tree-sitter-spl/bindings/node/binding.cc

29 lines
857 B
C++
Raw Normal View History

2023-05-24 21:48:37 +02:00
#include "tree_sitter/parser.h"
#include <node.h>
#include "nan.h"
using namespace v8;
2023-05-25 05:49:04 +02:00
extern "C" TSLanguage * tree_sitter_spl();
2023-05-24 21:48:37 +02:00
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();
2023-05-25 05:49:04 +02:00
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_spl());
2023-05-24 21:48:37 +02:00
2023-05-25 05:49:04 +02:00
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("spl").ToLocalChecked());
2023-05-24 21:48:37 +02:00
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
}
2023-05-25 05:49:04 +02:00
NODE_MODULE(tree_sitter_spl_binding, Init)
2023-05-24 21:48:37 +02:00
} // namespace