1 -> Generate a glue code function framework
DevEco Studio provides cross-language code editing. When developers need to use NAPI to encapsulate the interface exposed to ArkTS/JS, in the Cpp header file, right-click Generate > NAPI to quickly generate the glue code function framework of the current function or class.
- Check whether napi_init.cpp files are included in the current CPP project entry > src > main > cpp path. If the file does not exist, place the cursor in the header file (supported types: .hpp, .hxx, .hh, .h) (currently supports bool, int, string, void, float, double, std::array, std::vector and other parameter types), right-click and select Generate > NAPI to generate the glue code framework file napi_ init.cpp。
- If a napi_init.cpp file already exists or has been created in the project, right-click and select Generate > NAPI in the name of the function/class to be called in the header file, and the information of the corresponding function/class will be registered in the napi_property_descriptor field of the napi_init.cpp file.
- In the TODO position of the napi_init.cpp file, add the corresponding function implementation code.
2 -> Quickly generate function definitions across languages
Currently, you can use the Generate native implementation function to generate the corresponding function definition in a C++ file in a cross-language d.ts file.
Hover the cursor over the undefined function name, click Generate native implementation in the overlay window, or click the red light bulb icon that appears on the page, and select Generate native implementation to generate the function definition.
Top comments (0)