Update bindings and autogenertor

This commit is contained in:
Ivan Danyliuk 2017-11-24 15:54:05 +02:00
parent 72a1235917
commit ab77088b54
No known key found for this signature in database
GPG Key ID: 97ED33CE024E1DBF
5 changed files with 58 additions and 86 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
node_modules/
bin/
build/
go2nodebinding

View File

@ -36,3 +36,20 @@ You should have resulting module in `build/Release` folder.
# Package module
TBD
# Autogenerate bindings from Go code
It's possible to autogenerate C++ code from status-go Go code. First, build autogenerator tool:
```
go build ./tools/go2nodebinding
```
then, run it:
```
./go2nodebinding ../status-go/lib/library.go > src/status.cpp
```
check the diff and commit.

View File

@ -1,4 +1,4 @@
// DO NOT EDIT: code is autogenerated by go2nodebinding from Go code.
// DO NOT EDIT: code is autogenerated by ./go2nodebinding from Go code.
// https://github.com/divan/go2nodebinding
#include <node.h>
@ -57,9 +57,6 @@ void _GenerateConfig(const FunctionCallbackInfo<Value>& args) {
Local<String> ret = String::NewFromUtf8(isolate, c);
args.GetReturnValue().Set(ret);
delete c;
delete arg0;
}
void _StartNode(const FunctionCallbackInfo<Value>& args) {
@ -90,9 +87,6 @@ void _StartNode(const FunctionCallbackInfo<Value>& args) {
Local<String> ret = String::NewFromUtf8(isolate, c);
args.GetReturnValue().Set(ret);
delete c;
delete arg0;
}
void _StopNode(const FunctionCallbackInfo<Value>& args) {
@ -116,8 +110,6 @@ void _StopNode(const FunctionCallbackInfo<Value>& args) {
Local<String> ret = String::NewFromUtf8(isolate, c);
args.GetReturnValue().Set(ret);
delete c;
}
void _ValidateNodeConfig(const FunctionCallbackInfo<Value>& args) {
@ -148,9 +140,6 @@ void _ValidateNodeConfig(const FunctionCallbackInfo<Value>& args) {
Local<String> ret = String::NewFromUtf8(isolate, c);
args.GetReturnValue().Set(ret);
delete c;
delete arg0;
}
void _ResetChainData(const FunctionCallbackInfo<Value>& args) {
@ -174,8 +163,6 @@ void _ResetChainData(const FunctionCallbackInfo<Value>& args) {
Local<String> ret = String::NewFromUtf8(isolate, c);
args.GetReturnValue().Set(ret);
delete c;
}
void _CallRPC(const FunctionCallbackInfo<Value>& args) {
@ -206,9 +193,6 @@ void _CallRPC(const FunctionCallbackInfo<Value>& args) {
Local<String> ret = String::NewFromUtf8(isolate, c);
args.GetReturnValue().Set(ret);
delete c;
delete arg0;
}
void _CreateAccount(const FunctionCallbackInfo<Value>& args) {
@ -239,9 +223,6 @@ void _CreateAccount(const FunctionCallbackInfo<Value>& args) {
Local<String> ret = String::NewFromUtf8(isolate, c);
args.GetReturnValue().Set(ret);
delete c;
delete arg0;
}
void _CreateChildAccount(const FunctionCallbackInfo<Value>& args) {
@ -279,10 +260,6 @@ void _CreateChildAccount(const FunctionCallbackInfo<Value>& args) {
Local<String> ret = String::NewFromUtf8(isolate, c);
args.GetReturnValue().Set(ret);
delete c;
delete arg0;
delete arg1;
}
void _RecoverAccount(const FunctionCallbackInfo<Value>& args) {
@ -320,10 +297,6 @@ void _RecoverAccount(const FunctionCallbackInfo<Value>& args) {
Local<String> ret = String::NewFromUtf8(isolate, c);
args.GetReturnValue().Set(ret);
delete c;
delete arg0;
delete arg1;
}
void _VerifyAccountPassword(const FunctionCallbackInfo<Value>& args) {
@ -368,11 +341,6 @@ void _VerifyAccountPassword(const FunctionCallbackInfo<Value>& args) {
Local<String> ret = String::NewFromUtf8(isolate, c);
args.GetReturnValue().Set(ret);
delete c;
delete arg0;
delete arg1;
delete arg2;
}
void _Login(const FunctionCallbackInfo<Value>& args) {
@ -410,10 +378,6 @@ void _Login(const FunctionCallbackInfo<Value>& args) {
Local<String> ret = String::NewFromUtf8(isolate, c);
args.GetReturnValue().Set(ret);
delete c;
delete arg0;
delete arg1;
}
void _Logout(const FunctionCallbackInfo<Value>& args) {
@ -437,8 +401,6 @@ void _Logout(const FunctionCallbackInfo<Value>& args) {
Local<String> ret = String::NewFromUtf8(isolate, c);
args.GetReturnValue().Set(ret);
delete c;
}
void _CompleteTransaction(const FunctionCallbackInfo<Value>& args) {
@ -476,10 +438,6 @@ void _CompleteTransaction(const FunctionCallbackInfo<Value>& args) {
Local<String> ret = String::NewFromUtf8(isolate, c);
args.GetReturnValue().Set(ret);
delete c;
delete arg0;
delete arg1;
}
void _CompleteTransactions(const FunctionCallbackInfo<Value>& args) {
@ -517,10 +475,6 @@ void _CompleteTransactions(const FunctionCallbackInfo<Value>& args) {
Local<String> ret = String::NewFromUtf8(isolate, c);
args.GetReturnValue().Set(ret);
delete c;
delete arg0;
delete arg1;
}
void _DiscardTransaction(const FunctionCallbackInfo<Value>& args) {
@ -551,9 +505,6 @@ void _DiscardTransaction(const FunctionCallbackInfo<Value>& args) {
Local<String> ret = String::NewFromUtf8(isolate, c);
args.GetReturnValue().Set(ret);
delete c;
delete arg0;
}
void _DiscardTransactions(const FunctionCallbackInfo<Value>& args) {
@ -584,9 +535,6 @@ void _DiscardTransactions(const FunctionCallbackInfo<Value>& args) {
Local<String> ret = String::NewFromUtf8(isolate, c);
args.GetReturnValue().Set(ret);
delete c;
delete arg0;
}
void _InitJail(const FunctionCallbackInfo<Value>& args) {
@ -615,9 +563,43 @@ void _InitJail(const FunctionCallbackInfo<Value>& args) {
InitJail(arg0);
}
delete arg0;
void _Parse(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
if (args.Length() != 2) {
// Throw an Error that is passed back to JavaScript
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, "Wrong number of arguments for Parse")));
return;
}
// Check the argument types
if (!args[0]->IsString()) {
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, "Wrong argument type for 'chatID'")));
return;
}
if (!args[1]->IsString()) {
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, "Wrong argument type for 'js'")));
return;
}
String::Utf8Value arg0Obj(args[0]->ToString());
char *arg0 = *arg0Obj;
String::Utf8Value arg1Obj(args[1]->ToString());
char *arg1 = *arg1Obj;
// Call exported Go function, which returns a C string
char *c = Parse(arg0, arg1);
Local<String> ret = String::NewFromUtf8(isolate, c);
args.GetReturnValue().Set(ret);
delete c;
}
void _CreateAndInitCell(const FunctionCallbackInfo<Value>& args) {
@ -655,10 +637,6 @@ void _CreateAndInitCell(const FunctionCallbackInfo<Value>& args) {
Local<String> ret = String::NewFromUtf8(isolate, c);
args.GetReturnValue().Set(ret);
delete c;
delete arg0;
delete arg1;
}
void _ExecuteJS(const FunctionCallbackInfo<Value>& args) {
@ -696,10 +674,6 @@ void _ExecuteJS(const FunctionCallbackInfo<Value>& args) {
Local<String> ret = String::NewFromUtf8(isolate, c);
args.GetReturnValue().Set(ret);
delete c;
delete arg0;
delete arg1;
}
void _Call(const FunctionCallbackInfo<Value>& args) {
@ -744,11 +718,6 @@ void _Call(const FunctionCallbackInfo<Value>& args) {
Local<String> ret = String::NewFromUtf8(isolate, c);
args.GetReturnValue().Set(ret);
delete c;
delete arg0;
delete arg1;
delete arg2;
}
void _StartCPUProfile(const FunctionCallbackInfo<Value>& args) {
@ -779,9 +748,6 @@ void _StartCPUProfile(const FunctionCallbackInfo<Value>& args) {
Local<String> ret = String::NewFromUtf8(isolate, c);
args.GetReturnValue().Set(ret);
delete c;
delete arg0;
}
void _StopCPUProfiling(const FunctionCallbackInfo<Value>& args) {
@ -805,8 +771,6 @@ void _StopCPUProfiling(const FunctionCallbackInfo<Value>& args) {
Local<String> ret = String::NewFromUtf8(isolate, c);
args.GetReturnValue().Set(ret);
delete c;
}
void _WriteHeapProfile(const FunctionCallbackInfo<Value>& args) {
@ -837,9 +801,6 @@ void _WriteHeapProfile(const FunctionCallbackInfo<Value>& args) {
Local<String> ret = String::NewFromUtf8(isolate, c);
args.GetReturnValue().Set(ret);
delete c;
delete arg0;
}
void _Notify(const FunctionCallbackInfo<Value>& args) {
@ -870,9 +831,6 @@ void _Notify(const FunctionCallbackInfo<Value>& args) {
Local<String> ret = String::NewFromUtf8(isolate, c);
args.GetReturnValue().Set(ret);
delete c;
delete arg0;
}
void _NotifyUsers(const FunctionCallbackInfo<Value>& args) {
@ -917,11 +875,6 @@ void _NotifyUsers(const FunctionCallbackInfo<Value>& args) {
Local<String> ret = String::NewFromUtf8(isolate, c);
args.GetReturnValue().Set(ret);
delete c;
delete arg0;
delete arg1;
delete arg2;
}
void init(Local<Object> exports) {
@ -942,6 +895,7 @@ void init(Local<Object> exports) {
NODE_SET_METHOD(exports, "DiscardTransaction", _DiscardTransaction);
NODE_SET_METHOD(exports, "DiscardTransactions", _DiscardTransactions);
NODE_SET_METHOD(exports, "InitJail", _InitJail);
NODE_SET_METHOD(exports, "Parse", _Parse);
NODE_SET_METHOD(exports, "CreateAndInitCell", _CreateAndInitCell);
NODE_SET_METHOD(exports, "ExecuteJS", _ExecuteJS);
NODE_SET_METHOD(exports, "Call", _Call);

3
test.js Normal file
View File

@ -0,0 +1,3 @@
var c = require(".")
console.log(c.GenerateConfig("data", 3, 0))

View File

@ -78,9 +78,6 @@ void _{{.Name}}(const FunctionCallbackInfo<Value>& args) {
{{if eq .ReturnsCount 1}}Local<String> ret = String::NewFromUtf8(isolate, c);
args.GetReturnValue().Set(ret);
delete c;{{end}}
{{range $index, $arg := .Params}}{{if eq .Type "*C.char"}}delete arg{{$index}};
{{end}}{{end}}
}
`))