Generate binding.gyp, binding.cc, and index.js

This commit is contained in:
Max Brunsfeld 2019-01-16 13:53:01 -08:00
parent 564c5e39b6
commit a0a3903f76
6 changed files with 96 additions and 8 deletions

View file

@ -0,0 +1,28 @@
#include "tree_sitter/parser.h"
#include <node.h>
#include "nan.h"
using namespace v8;
extern "C" TSLanguage * tree_sitter_PARSER_NAME();
namespace {
NAN_METHOD(New) {}
void Init(Handle<Object> exports, Handle<Object> module) {
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
tpl->SetClassName(Nan::New("Language").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
Local<Function> constructor = tpl->GetFunction();
Local<Object> instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_PARSER_NAME());
instance->Set(Nan::New("name").ToLocalChecked(), Nan::New("PARSER_NAME").ToLocalChecked());
module->Set(Nan::New("exports").ToLocalChecked(), instance);
}
NODE_MODULE(tree_sitter_PARSER_NAME_binding, Init)
} // namespace

View file

@ -0,0 +1,18 @@
{
"targets": [
{
"target_name": "tree_sitter_PARSER_NAME_binding",
"include_dirs": [
"<!(node -e \"require('nan')\")",
"src"
],
"sources": [
"src/parser.c",
"src/binding.cc"
],
"cflags_c": [
"-std=c99",
]
}
]
}

View file

@ -0,0 +1,9 @@
try {
module.exports = require("./build/Release/tree_sitter_PARSER_NAME_binding");
} catch (error) {
try {
module.exports = require("./build/Debug/tree_sitter_PARSER_NAME_binding");
} catch (_) {
throw error
}
}