mirror of https://github.com/oxen-io/lokinet
initial node garbage
This commit is contained in:
parent
930b41f644
commit
ff6ab7d631
|
@ -0,0 +1,15 @@
|
|||
|
||||
{
|
||||
"targets": [
|
||||
{
|
||||
"target_name": "lokinet",
|
||||
"cflags!": [ "-fno-exceptions" ],
|
||||
"cflags_cc!": [ "-fno-exceptions" ],
|
||||
"sources": [ "lokinet.cc" ],
|
||||
"include_dirs": [
|
||||
"<!@(node -p \"require('node-addon-api').include\")"
|
||||
],
|
||||
'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ],
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
#include <napi.h>
|
||||
#include <llarp.hpp>
|
||||
|
||||
struct Lokinet : public Napi::ObjectWrap< Lokinet >
|
||||
{
|
||||
llarp::Context ctx;
|
||||
|
||||
static Napi::Object
|
||||
Init(Napi::Env env, Napi::Object exports)
|
||||
{
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
Napi::Function func =
|
||||
DefineClass(env, "Lokinet",
|
||||
{InstanceMethod("configure", &Lokinet::Configure),
|
||||
InstanceMethod("run", &Lokient::Run),
|
||||
InstanceMethod("kill", &Lokinet::Kill)});
|
||||
|
||||
constructor = Napi::Persistent(func);
|
||||
constructor.SuppressDestruct();
|
||||
|
||||
exports.Set("Lokinet", func);
|
||||
return exports;
|
||||
};
|
||||
|
||||
Napi::Value
|
||||
Configure(const Napi::CallbackInfo& info)
|
||||
{
|
||||
if(info.Length() != 1 || !info[0].IsString())
|
||||
{
|
||||
Napi::TypeError::New(env, "String expected").ThrowAsJavaScriptException();
|
||||
}
|
||||
bool result = ctx.LoadConfig(info[0].As< std::string >());
|
||||
if(result)
|
||||
{
|
||||
result &= ctx.Setup() == 0;
|
||||
}
|
||||
return Napi::Value(info.Env(), result);
|
||||
}
|
||||
|
||||
Napi::Value
|
||||
Run(const Napi::CallbackInfo& info)
|
||||
{
|
||||
bool result = ctx.Run() == 0;
|
||||
return Napi::Value(info.Env(), result);
|
||||
}
|
||||
|
||||
Napi::Value
|
||||
Kill(const Napi::CallbackInfo& info)
|
||||
{
|
||||
bool result = ctx.Stop();
|
||||
return Napi::Value(info.Env(), result);
|
||||
}
|
||||
};
|
||||
|
||||
Napi::Object
|
||||
InitAll(Napi::Env env, Napi::Object exports)
|
||||
{
|
||||
return Lokinet::Init(env, exports);
|
||||
}
|
||||
|
||||
NODE_API_MODULE(addon, InitAll)
|
|
@ -0,0 +1,2 @@
|
|||
var lokinet = require("bindings")("lokinet");
|
||||
console.log(lokinet);
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"name": "lokinet",
|
||||
"version": "0.0.0",
|
||||
"description": "lokinet god awful node binding",
|
||||
"main": "lokinet.js",
|
||||
"private": true,
|
||||
"gypfile": true,
|
||||
"dependencies": {
|
||||
"bindings": "~1.2.1",
|
||||
"node-addon-api": "^1.0.0"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue