Skip to content

Commit

Permalink
Update code
Browse files Browse the repository at this point in the history
  • Loading branch information
awen committed Dec 15, 2022
1 parent 5b2bf96 commit ab8f4bf
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 30 deletions.
17 changes: 11 additions & 6 deletions _example/addon/goaddon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ Value _EmptyString(const CallbackInfo& wg_info) {
char *s = new char[wg_s.length() + 1];
strcpy(s, wg_s.c_str());
bool wg_res_ = EmptyString(s);
delete [] s;
return Boolean::New(wg_env, wg_res_);
}
// ---------- GenCode ----------
Expand Down Expand Up @@ -396,6 +397,7 @@ Value _CountMap(const CallbackInfo& wg_info) {
char *obj = new char[wg_obj.length() + 1];
strcpy(obj, wg_obj.c_str());
int wg_res_ = CountMap(obj);
delete [] obj;
return Number::New(wg_env, wg_res_);
}
// ---------- GenCode ----------
Expand All @@ -413,6 +415,7 @@ Value _IsMapType(const CallbackInfo& wg_info) {
char *obj = new char[wg_obj.length() + 1];
strcpy(obj, wg_obj.c_str());
bool wg_res_ = IsMapType(obj);
delete [] obj;
return Boolean::New(wg_env, wg_res_);
}
// ---------- GenCode ----------
Expand Down Expand Up @@ -449,6 +452,7 @@ Value _CountSlice(const CallbackInfo& wg_info) {
char *s = new char[wg_s.length() + 1];
strcpy(s, wg_s.c_str());
int wg_res_ = CountSlice(s);
delete [] s;
return Number::New(wg_env, wg_res_);
}
// ---------- GenCode ----------
Expand All @@ -466,6 +470,7 @@ Value _IsSliceType(const CallbackInfo& wg_info) {
char *s = new char[wg_s.length() + 1];
strcpy(s, wg_s.c_str());
bool wg_res_ = IsSliceType(s);
delete [] s;
return Boolean::New(wg_env, wg_res_);
}
// ---------- GenCode ----------
Expand Down Expand Up @@ -673,7 +678,7 @@ static void wg_work_complete_asynccallbackreuintsum32(napi_env wg_env, napi_stat
static napi_value wg_work_asynccallbackreuintsum32(napi_env wg_env, napi_callback_info wg_info) {
size_t wg_argc = 3;
size_t wg_cb_arg_index = 2;
napi_value wg_args[wg_argc];
napi_value wg_args[3];
napi_value wg_work_name;
napi_status wg_sts;
WgAddonDataASyncCallbackReUintSum32* wg_addon = (WgAddonDataASyncCallbackReUintSum32*)malloc(sizeof(*wg_addon));
Expand Down Expand Up @@ -810,7 +815,7 @@ static void wg_work_complete_asynccallbackrearr(napi_env wg_env, napi_status wg_
static napi_value wg_work_asynccallbackrearr(napi_env wg_env, napi_callback_info wg_info) {
size_t wg_argc = 2;
size_t wg_cb_arg_index = 1;
napi_value wg_args[wg_argc];
napi_value wg_args[2];
napi_value wg_work_name;
napi_status wg_sts;
WgAddonDataASyncCallbackReArr* wg_addon = (WgAddonDataASyncCallbackReArr*)malloc(sizeof(*wg_addon));
Expand Down Expand Up @@ -936,7 +941,7 @@ static void wg_work_complete_asynccallbackreobject(napi_env wg_env, napi_status
static napi_value wg_work_asynccallbackreobject(napi_env wg_env, napi_callback_info wg_info) {
size_t wg_argc = 2;
size_t wg_cb_arg_index = 1;
napi_value wg_args[wg_argc];
napi_value wg_args[2];
napi_value wg_work_name;
napi_status wg_sts;
WgAddonDataASyncCallbackReObject* wg_addon = (WgAddonDataASyncCallbackReObject*)malloc(sizeof(*wg_addon));
Expand Down Expand Up @@ -1066,7 +1071,7 @@ static void wg_work_complete_asynccallbackrecount(napi_env wg_env, napi_status w
static napi_value wg_work_asynccallbackrecount(napi_env wg_env, napi_callback_info wg_info) {
size_t wg_argc = 2;
size_t wg_cb_arg_index = 1;
napi_value wg_args[wg_argc];
napi_value wg_args[2];
napi_value wg_work_name;
napi_status wg_sts;
WgAddonDataASyncCallbackReCount* wg_addon = (WgAddonDataASyncCallbackReCount*)malloc(sizeof(*wg_addon));
Expand Down Expand Up @@ -1194,7 +1199,7 @@ static void wg_work_complete_asynccallbackrebool(napi_env wg_env, napi_status wg
static napi_value wg_work_asynccallbackrebool(napi_env wg_env, napi_callback_info wg_info) {
size_t wg_argc = 2;
size_t wg_cb_arg_index = 1;
napi_value wg_args[wg_argc];
napi_value wg_args[2];
napi_value wg_work_name;
napi_status wg_sts;
WgAddonDataASyncCallbackReBool* wg_addon = (WgAddonDataASyncCallbackReBool*)malloc(sizeof(*wg_addon));
Expand Down Expand Up @@ -1328,7 +1333,7 @@ static void wg_work_complete_asynccallbackmarg(napi_env wg_env, napi_status wg_s
static napi_value wg_work_asynccallbackmarg(napi_env wg_env, napi_callback_info wg_info) {
size_t wg_argc = 3;
size_t wg_cb_arg_index = 1;
napi_value wg_args[wg_argc];
napi_value wg_args[3];
napi_value wg_work_name;
napi_status wg_sts;
WgAddonDataASyncCallbackMArg* wg_addon = (WgAddonDataASyncCallbackMArg*)malloc(sizeof(*wg_addon));
Expand Down
1 change: 1 addition & 0 deletions _example/addon/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const goaddon = require('bindings')('goaddon');
// JS call API
module.exports = {
intSum32 : goaddon.int_sum32,
intSum64 : goaddon.int_sum64,
Expand Down
4 changes: 2 additions & 2 deletions buildtask/dep_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func installDep(cfgs config.Config) bool {
path := tools.FormatDirPath(cfgs.OutPut)

clog.Info("Staring install npm dependencies ...")
clog.Info("Staring install dependencies ...")
// "bindings" "node-addon-api"
msg, err := cmd.RunCommand(
"./",
Expand All @@ -22,6 +22,6 @@ func installDep(cfgs config.Config) bool {
return false
}
clog.Info(msg)
clog.Info("Install npm dependencies done ~")
clog.Info("Install dependencies done ~")
return true
}
1 change: 1 addition & 0 deletions content/args/argsync/gen_arg_object_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func GenObjectArgTypeCode(name string, index string) (string, string) {
string wg_` + name + ` = wg_object_to_string(wg__` + name + `);
char *` + name + ` = new char[wg_` + name + `.length() + 1];
strcpy(` + name + `, wg_` + name + `.c_str());`

endCode := tools.FormatCodeIndentLn(`delete [] `+name+`;`, 2)
return code, endCode
}
4 changes: 2 additions & 2 deletions content/returns/resync/gen_return_array_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package resync

import (
"github.com/wenlng/gonacli/config"
args2 "github.com/wenlng/gonacli/content/args/argsync"
"github.com/wenlng/gonacli/content/args/argsync"
"github.com/wenlng/gonacli/tools"
"strings"
)
Expand All @@ -29,7 +29,7 @@ func GenReturnArrayTypeCode(export config.Export) string {
Value _` + methodName + `(const CallbackInfo& wg_info) {`
code += tools.FormatCodeIndentLn(`Env wg_env = wg_info.Env();`, 2)

c, argNames, endCode := args2.GenArgCode(args)
c, argNames, endCode := argsync.GenArgCode(args)
code += c

code += GenHandleReturnArrayCode(methodName, argNames, endCode)
Expand Down
9 changes: 5 additions & 4 deletions content/returns/resync/gen_return_boolean_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package resync

import (
"github.com/wenlng/gonacli/config"
args2 "github.com/wenlng/gonacli/content/args/argsync"
"github.com/wenlng/gonacli/content/args/argsync"
"github.com/wenlng/gonacli/tools"
"strings"
)

// 生成处理体
func GenHandleReturnBooleanCode(method string, args []string) string {
func GenHandleReturnBooleanCode(method string, args []string, endCode string) string {
code := tools.FormatCodeIndentLn(`bool wg_res_ = `+method+`(`+strings.Join(args, ",")+`);`, 2)
code += endCode
code += tools.FormatCodeIndentLn(`return Boolean::New(wg_env, wg_res_);`, 2)
return code
}
Expand All @@ -24,10 +25,10 @@ func GenReturnBooleanTypeCode(export config.Export) string {
Value _` + methodName + `(const CallbackInfo& wg_info) {`
code += tools.FormatCodeIndentLn(`Env wg_env = wg_info.Env();`, 2)

c, argNames, _ := args2.GenArgCode(args)
c, argNames, endCode := argsync.GenArgCode(args)
code += c

code += GenHandleReturnBooleanCode(methodName, argNames)
code += GenHandleReturnBooleanCode(methodName, argNames, endCode)

code += tools.FormatCodeIndentLn(`}`, 0)
return code
Expand Down
9 changes: 5 additions & 4 deletions content/returns/resync/gen_return_double_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package resync

import (
"github.com/wenlng/gonacli/config"
args2 "github.com/wenlng/gonacli/content/args/argsync"
"github.com/wenlng/gonacli/content/args/argsync"
"github.com/wenlng/gonacli/tools"
"strings"
)

// 生成处理体
func GenHandleReturnDoubleCode(method string, args []string) string {
func GenHandleReturnDoubleCode(method string, args []string, endCode string) string {
code := tools.FormatCodeIndentLn(`double wg_res_ = `+method+`(`+strings.Join(args, ",")+`);`, 2)
code += endCode
code += tools.FormatCodeIndentLn(`return Number::New(wg_env, wg_res_);`, 2)
return code
}
Expand All @@ -24,10 +25,10 @@ func GenReturnDoubleTypeCode(export config.Export) string {
Value _` + methodName + `(const CallbackInfo& wg_info) {`
code += tools.FormatCodeIndentLn(`Env wg_env = wg_info.Env();`, 2)

c, argNames, _ := args2.GenArgCode(args)
c, argNames, endCode := argsync.GenArgCode(args)
code += c

code += GenHandleReturnDoubleCode(methodName, argNames)
code += GenHandleReturnDoubleCode(methodName, argNames, endCode)

code += tools.FormatCodeIndentLn(`}`, 0)
return code
Expand Down
9 changes: 5 additions & 4 deletions content/returns/resync/gen_return_float_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package resync

import (
"github.com/wenlng/gonacli/config"
args2 "github.com/wenlng/gonacli/content/args/argsync"
"github.com/wenlng/gonacli/content/args/argsync"
"github.com/wenlng/gonacli/tools"
"strings"
)

// 生成处理体
func GenHandleReturnFloatCode(method string, args []string) string {
func GenHandleReturnFloatCode(method string, args []string, endCode string) string {
code := tools.FormatCodeIndentLn(`float wg_res_ = `+method+`(`+strings.Join(args, ",")+`);`, 2)
code += endCode
code += tools.FormatCodeIndentLn(`return Number::New(wg_env, wg_res_);`, 2)
return code
}
Expand All @@ -24,10 +25,10 @@ func GenReturnFloatTypeCode(export config.Export) string {
Value _` + methodName + `(const CallbackInfo& wg_info) {`
code += tools.FormatCodeIndentLn(`Env wg_env = wg_info.Env();`, 2)

c, argNames, _ := args2.GenArgCode(args)
c, argNames, endCode := argsync.GenArgCode(args)
code += c

code += GenHandleReturnFloatCode(methodName, argNames)
code += GenHandleReturnFloatCode(methodName, argNames, endCode)

code += tools.FormatCodeIndentLn(`}`, 0)
return code
Expand Down
9 changes: 5 additions & 4 deletions content/returns/resync/gen_return_int_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package resync

import (
"github.com/wenlng/gonacli/config"
args2 "github.com/wenlng/gonacli/content/args/argsync"
"github.com/wenlng/gonacli/content/args/argsync"
"github.com/wenlng/gonacli/tools"
"strings"
)

// 生成处理体
func GenHandleReturnIntCode(method string, args []string, varType string) string {
func GenHandleReturnIntCode(method string, args []string, varType string, endCode string) string {
code := ""

// int32 int64 uint32
Expand All @@ -20,6 +20,7 @@ func GenHandleReturnIntCode(method string, args []string, varType string) string
code = tools.FormatCodeIndentLn(`int wg_res_ = `+method+`(`+strings.Join(args, ",")+`);`, 2)
}

code += endCode
code += tools.FormatCodeIndentLn(`return Number::New(wg_env, wg_res_);`, 2)
return code
}
Expand All @@ -34,10 +35,10 @@ func GenReturnIntTypeCode(export config.Export, varType string) string {
Value _` + methodName + `(const CallbackInfo& wg_info) {`
code += tools.FormatCodeIndentLn(`Env wg_env = wg_info.Env();`, 2)

c, argNames, _ := args2.GenArgCode(args)
c, argNames, endCode := argsync.GenArgCode(args)
code += c

code += GenHandleReturnIntCode(methodName, argNames, varType)
code += GenHandleReturnIntCode(methodName, argNames, varType, endCode)

code += tools.FormatCodeIndentLn(`}`, 0)
return code
Expand Down
4 changes: 2 additions & 2 deletions content/returns/resync/gen_return_object_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package resync

import (
"github.com/wenlng/gonacli/config"
args2 "github.com/wenlng/gonacli/content/args/argsync"
"github.com/wenlng/gonacli/content/args/argsync"
"github.com/wenlng/gonacli/tools"
"strings"
)
Expand All @@ -27,7 +27,7 @@ func GenReturnObjectTypeCode(export config.Export) string {
Value _` + methodName + `(const CallbackInfo& wg_info) {`
code += tools.FormatCodeIndentLn(`Env wg_env = wg_info.Env();`, 2)

c, argNames, endCode := args2.GenArgCode(args)
c, argNames, endCode := argsync.GenArgCode(args)
code += c

code += GenHandleReturnObjectCode(methodName, argNames, endCode)
Expand Down
4 changes: 2 additions & 2 deletions content/returns/resync/gen_return_string_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package resync

import (
"github.com/wenlng/gonacli/config"
args2 "github.com/wenlng/gonacli/content/args/argsync"
"github.com/wenlng/gonacli/content/args/argsync"
"github.com/wenlng/gonacli/tools"
"strings"
)
Expand All @@ -26,7 +26,7 @@ func GenReturnStringTypeCode(export config.Export) string {
Value _` + methodName + `(const CallbackInfo& wg_info) {`
code += tools.FormatCodeIndentLn(`Env wg_env = wg_info.Env();`, 2)

c, argNames, preCode := args2.GenArgCode(args)
c, argNames, preCode := argsync.GenArgCode(args)
code += c

code += GenHandleReturnStringCode(methodName, argNames, preCode)
Expand Down

0 comments on commit ab8f4bf

Please sign in to comment.