mirror of
https://gitee.com/openharmony/napi_generator
synced 2024-11-26 18:20:35 +00:00
add napi callback snippets
Signed-off-by: chen-zhongwei050 <chenzhongwei050@chinasoftinc.com>
This commit is contained in:
parent
13f7e4f0c3
commit
4274da8b03
@ -119,6 +119,10 @@
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/napi_promise_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/napi_callback_snippets.json"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
32
src/vscode_plugin/snippets/napi_callback_snippets.json
Normal file
32
src/vscode_plugin/snippets/napi_callback_snippets.json
Normal file
@ -0,0 +1,32 @@
|
||||
{
|
||||
"Napi Callback": {
|
||||
"prefix": "napicallback",
|
||||
"body": [
|
||||
"static napi_value CallbackSample(napi_env env, napi_callback_info info)",
|
||||
"{",
|
||||
" // Todo: you can use \"napiobjectin\" command that get object value from js.",
|
||||
" // Todo: you can use \"napidoublein\" command that get double value from js.",
|
||||
" // Business code.",
|
||||
" double myRes = value0 + value1;",
|
||||
" // Todo: you can use \"napidoubleout\" command that return double to js.",
|
||||
" napi_value result;",
|
||||
" // Invokes a js function with the provided arguments and returns the result.",
|
||||
" napi_call_function(env, nullptr, args[2], 1, &doubleOut, &result);",
|
||||
" return nullptr;",
|
||||
"}",
|
||||
"EXTERN_C_START",
|
||||
"// Initialize the module.",
|
||||
"static napi_value Init(napi_env env, napi_value exports)",
|
||||
"{",
|
||||
" // Define properties and methods for a N-API object.",
|
||||
" napi_property_descriptor desc[] = {",
|
||||
" { \"callbackSample\", nullptr, CallbackSample, nullptr, nullptr, nullptr, napi_default, nullptr }",
|
||||
" };",
|
||||
" // Add an array of properties to a ArkTs object.",
|
||||
" napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);",
|
||||
" return exports;",
|
||||
"}",
|
||||
"EXTERN_C_END"
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user