Framework generation method and system based on callback function flexibility optimization
By setting and parsing callback function types in N-API tools, including asynchronous programming and arrow function types, the problem that callback functions do not support custom parameters and return values is solved, and more flexible generation of business code interface framework is achieved. .
Patent Information
- Application Number
- CN202411191454.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-28
- Publication Date
- 2024-12-20
AI Technical Summary
The callback function in the N-API tool does not support user-defined, especially callback functions that carry multiple parameters and non-null return value types, resulting in the inability to support certain scenarios such as width and color adjustment of the status bar width and color.
By setting the callback function type, including the delegate type of asynchronous programming, the specified type of hypertext preprocessor and the arrow function type, parse the number of parameters, parameter names, parameter types and return value type information, generate callback framework code and generate business code Interface framework, supports callback functions in the form of custom arrow functions.
It realizes flexibility optimization of callback functions, supports callback functions of multiple parameters and non-null return value types, and enhances the generation ability of the business code interface framework.
Smart Images

Figure CN119166116A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of software compilation, and in particular to a framework generation method and system based on callback function flexibility optimization. Background Art
[0002] The N-API framework code generation tool (i.e., N-API tool) is a tool that can generate N-API framework code, business code framework, and GN file (a configuration file for building a system) based on the ts (typescript, a computer programming language) interface file in the path specified by the user. When developing the interface between JS applications and N-API, using this N-API tool, the underlying framework developers do not need to pay attention to the upper-level application conversion logic such as Nodejs syntax and data type conversion between C++ and JS applications, but only need to pay attention to the underlying business logic, which can greatly improve the efficiency of software development.
[0003] In the N-API tool, the callback function used is a function that is passed as a parameter. In C language, callback functions can only be implemented using function pointers. In more modern programming languages such as C++, Python, and ECMAScript, functors or anonymous functions can also be used. The use of callback functions can greatly improve programming efficiency, which makes it very commonly used in modern programming. At the same time, there are some requirements that must be implemented using callback functions.
[0004] Currently, in the N-API tool, callback functions are defined through templates. Users can only define the type of one parameter, and the return value type can only be empty. User-defined callback functions are not supported, especially callback functions with multiple parameters and non-empty return values. This results in the following scenarios being unsupported by the callback tool: such as the width and color of the status bar set by the user (two parameters), and whether the adjustment is successful (bool type return value). The reason is that when the NAPI framework code generation tool parses the AsyncCallback type (asynchronous programming delegate type) or Callback type (specified type in the hypertext preprocessor) callback function, it only parses one parameter and its type, and the return value is parsed as void type by default, resulting in the non-AsyncCallback or Callback type callback tool not supporting parsing. Summary of the invention
[0005] The main purpose of the present invention is to provide a framework generation method and system based on callback function flexibility optimization, aiming to solve the problem that the callback function of the N-API tool in the prior art does not support user customization.
[0006] To achieve the above object, the present invention provides a framework generation method based on callback function flexibility optimization, the framework generation method based on callback function flexibility optimization comprises the following steps: Set the callback function type; wherein the callback function type includes: a delegate type of asynchronous programming, a specified type of a hypertext preprocessor, and an arrow function type; Parse the callback function type, number of parameters, parameter name, parameter type and return value type information; A callback framework code is generated according to the parsed information, and a business code interface framework is generated according to the callback framework code.
[0007] Optionally, the setting of the callback function type specifically includes: Define the N-API function type, set the callback function and the corresponding type, and obtain the delegate type of the asynchronous programming and the specified type of the hypertext preprocessor; Pass the arrow function to the N-API interface to obtain the arrow function type.
[0008] Optionally, the definition of the N-API function type and setting of the callback function and the corresponding type specifically include: Create an N-API function based on the creation function of the N-API tool; The callback function is created based on the creation function, and the type corresponding to the callback function is set.
[0009] Optionally, the parsing of the callback function type, number of parameters, parameter name, parameter type, and return value type information specifically includes: Determine the callback function type based on the N-API type and parse the function; Inside the callback function, a method for obtaining the number of parameters of a callback function is used to parse and obtain the number of parameters passed to the callback function; Determine the function to parse the N-API type to obtain the parameter type passed to the callback function, and determine the corresponding parameter name; According to the return value of the callback function, the type corresponding to the return value is checked using the N-API type determination function to obtain the return value type information.
[0010] Optionally, the determining function parsing based on the N-API type to obtain the parameter type passed to the callback function and determining the corresponding parameter name specifically includes: Extracting parameters passed to the callback function; Using the N-API type determination function to obtain a value pointing to an enumeration type from an incoming parameter, and determining a parameter type passed to the callback function according to the value of the enumeration type; The corresponding parameter name is determined according to the parameter type and function definition.
[0011] Optionally, generating a callback framework code according to the parsed information, and generating a business code interface framework according to the callback framework code specifically includes: According to the parsed information, define the interface of the callback function, and set the callback function to meet the expected parameter and return value requirements, so as to obtain the callback framework code; A business interface is created based on the callback framework code, and the business code interface framework is generated.
[0012] Optionally, the process generates a callback framework code according to the parsed information, and generates a business code interface framework according to the callback framework code, and then includes: Add business logic to the generated business code interface, and output business test results after compiling and running.
[0013] In addition, to achieve the above-mentioned purpose, the present invention also provides a framework generation system based on callback function flexibility optimization, wherein the framework generation system based on callback function flexibility optimization includes: A callback function setting module, used to set the callback function type; wherein the callback function type includes: a delegate type of asynchronous programming, a specified type of a hypertext preprocessor, and an arrow function type; A parsing module, used to parse the callback function type, number of parameters, parameter name, parameter type and return value type information; The code generation module is used to generate a callback framework code according to the parsed information, and to generate a business code interface framework according to the callback framework code.
[0014] In addition, to achieve the above-mentioned purpose, the present invention also provides a terminal, wherein the terminal includes: a memory, a processor, and a framework generation program based on callback function flexibility optimization stored in the memory and run on the processor, and when the framework generation program based on callback function flexibility optimization is executed by the processor, the steps of the framework generation method based on callback function flexibility optimization as described above are implemented.
[0015] In addition, to achieve the above-mentioned purpose, the present invention also provides a computer-readable storage medium, wherein the computer-readable storage medium stores a framework generation program based on callback function flexibility optimization, and when the framework generation program based on callback function flexibility optimization is executed by a processor, the steps of the framework generation method based on callback function flexibility optimization as described above are implemented.
[0016] In the present invention, by setting the callback function type; wherein the callback function type includes: the delegate type of asynchronous programming, the specified type of the hypertext preprocessor and the arrow function type; parsing the callback function type, the number of parameters, the parameter name, the parameter type and the return value type information; generating the callback framework code according to the parsed information, and generating the business code interface framework according to the callback framework code. The present invention can customize the callback function in the form of an arrow function, and define the number of callback parameters and the callback return value type, solving the problem that the number of parameters and the callback function return value cannot be customized in the N-API template, thereby generating the business code interface framework more flexibly. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 It is a flow chart of a preferred embodiment of the framework generation method based on callback function flexibility optimization of the present invention; Figure 2 It is a structural diagram of a preferred embodiment of the framework generation system based on callback function flexibility optimization of the present invention; Figure 3 It is a structural diagram of a preferred embodiment of the terminal of the present invention. DETAILED DESCRIPTION
[0018] In order to make the purpose, technical solution and advantages of the present invention clearer and more specific, the present invention is further described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0019] Currently, in the N-API tool, callback functions are defined through templates. Users can only define the type of one parameter, and the return value type can only be empty. User-defined callback functions are not supported, especially callback functions with multiple parameters and non-empty return values. This results in the following scenarios being unsupported by the callback tool: such as the width and color of the status bar set by the user (two parameters), and whether the adjustment is successful (bool type return value). The reason is that when the NAPI framework code generation tool parses the AsyncCallback type (asynchronous programming delegate type) or Callback type (specified type in the hypertext preprocessor) callback function, it only parses one parameter and its type, and the return value is parsed as void type by default, resulting in the non-AsyncCallback or Callback type callback tool not supporting parsing.
[0020] In order to solve the problem that the number of parameters and the return value of the callback function cannot be customized in the N-API template, so that the N-API tool can generate the business code interface framework more flexibly, a framework generation method based on callback function flexibility optimization is provided in an embodiment of the present invention, and the method sets the callback function type; wherein the callback function type includes: the delegate type of asynchronous programming, the specified type of the hypertext preprocessor, and the arrow function type; parses the callback function type, the number of parameters, the parameter name, the parameter type, and the return value type information; generates the callback framework code according to the parsed information, and generates the business code interface framework according to the callback framework code. The present invention can customize the callback function in the form of an arrow function, and define the number of callback parameters and the callback return value type, so as to solve the problem that the number of parameters and the return value of the callback function cannot be customized in the N-API template, thereby generating the business code interface framework more flexibly.
[0021] The framework generation method based on callback function flexibility optimization described in the preferred embodiment of the present invention is as follows: Figure 1 As shown, the framework generation method based on callback function flexibility optimization includes the following steps: Step S10, setting the callback function type; wherein the callback function type includes: a delegate type of asynchronous programming, a specified type of a hypertext preprocessor, and an arrow function type.
[0022] It should be noted that in the present application, the framework generation method based on callback function flexibility optimization is a method implemented based on the N-API framework code generation tool (i.e., N-API tool). The N-API framework (Native Application Programming Interface) is a set of native module extension development frameworks in the OpenHarmony system. The framework is developed based on the Node.js N-API specification, which can provide developers with the ability to interact between JavaScript and C / C++ modules.
[0023] It is understandable that in this application, software developers develop JS applications based on the N-API tool to obtain a business code framework; currently, the scope of support for callback functions by the N-API tool is as follows: function fun3(cb: AsyncCallback <number>): void; function fun1(cb: Callback <number>): void; In the above scope, the callback function is defined by the template; and the callback function defined by the AsyncCallback (asynchronous programming delegate type) template is: export interface AsyncCallback <t>{ (err: BusinessError, data: T): void; }; The callback function defined by the Callback type (specified type in the hypertext preprocessor) template is: export interface Callback <t>{ (data: T): void; }; Under the definition of the above two templates, users can only define the type of one parameter, and the return value type can only be empty. Currently, user-defined callback functions are not supported, especially callback functions with multiple parameters and non-empty return value types. This results in the inability to support callback tools in many scenarios. For example, when the user sets the width and color of the status bar, the adjustment cannot be successful.
[0024] In this application, based on the AsyncCallback type and Callback type, the callback support type is added: function fun9(cb: (wid: boolean, str: string, tc2:number) =>string):string; In this way, users can customize the number of callback parameters and callback return value type by customizing the callback function in the form of an arrow function, solving the problem that the number of parameters and callback function return value cannot be customized in the template.
[0025] It can be understood that in this application, the callback function refers to the function defined by the application layer arkts in OpenHarmony. This function is not called by other arkts functions, but is a function called back by the system framework layer C++.
[0026] In this application, in order to implement a callback function in the form of a custom arrow function, as well as to implement the custom number of callback parameters and callback return value type, it is first necessary to set the callback function type of the N-API tool so that the supported callback function type includes not only the AsyncCallback type or the Callback type, but also the arrow function type.
[0027] Furthermore, the setting of the callback function type specifically includes: defining the N-API function type, and setting the callback function and the corresponding type, obtaining the delegate type of the asynchronous programming and the specified type of the hypertext preprocessor; passing the arrow function to the N-API interface to obtain the arrow function type.
[0028] Specifically, in this application, in order to set the callback function type based on the N-API tool and support arrow functions; first, it is necessary to define the N-API function type in the N-API tool, and then use napi_create_function (that is, the creation function of the N-API tool) to create the callback function and set the corresponding type of the callback function; among them, the callback function types created by napi_create_function are: AsyncCallback type, Callback type; in addition, this application also passes the arrow function to the N-API interface to obtain the arrow function type; among them, the transmission process of the arrow function is just like processing an ordinary function.
[0029] Furthermore, the defining of the N-API function type and setting of the callback function and the corresponding type specifically include: creating an N-API function based on a creation function of an N-API tool; creating the callback function based on the creation function, and setting the type corresponding to the callback function.
[0030] Specifically, in this application, in the above process of defining the N-API function type, setting the callback function type and the arrow function type, it can be implemented in the following ways: 1) Define the N-API function type: use napi_value to represent the callback function, and use napi_create_function to create an N-API function.
[0031] 2) Set the callback function: Use napi_create_function to create the callback function and set its type.
[0032] One of the parameters of napi_create_function is a callback function pointer of type napi_callback.
[0033] 3) Support for arrow functions: Arrow functions are handled as JavaScript function objects in N-API and do not require special settings. Arrow functions can be passed to N-API interfaces just like normal functions.
[0034] As an example, the callback function can be set in the following way: #include<napi.h> void MyCallback(const Napi::CallbackInfo&info) { / / Process the callback } Napi::Value CreateCallbackFunction(const Napi::CallbackInfo&info) { Napi::Env env = info.Env(); / / Create callback function Napi::Function callback = Napi::Function::New(env,MyCallback); / / Return the created function return callback; } Napi::Object Init(Napi::Env env, Napi::Object exports) { exports.Set(Napi::String::New(env,"createCallbackFunction"), Napi::Function::New(env, CreateCallbackFunction)); return exports;} NODE_API_MODULE(NODE_GYP_MODULE_NAME, Init) Furthermore, arrow functions can be used as callbacks in the following ways: const addon = require('. / build / Release / addon'); const callback = addon.createCallbackFunction(); callback(() => { console.log('Callback triggered!'); }); Through the above steps, you can set the callback function type in N-API and support arrow functions as callbacks.
[0035] Step S20, parsing the callback function type, number of parameters, parameter name, parameter type and return value type information.
[0036] Specifically, in the present application, after implementing the type of the custom callback function, an arrow function type is added based on the AsyncCallback type and the Callback type to support arrow functions as callback passing; in order to enable the N-API tool to generate a business code interface framework more flexibly, it is also necessary to parse and obtain information such as the callback function type, number of parameters, parameter names, parameter types, and return value types; in the process of parsing this information, the declaration of the callback function can be obtained through header files, interface documents, or other forms of definitions, and then the type information of the callback function can be parsed according to the declaration of the callback function. The number of parameters, parameter names, parameter types, and return value types, etc., can be obtained through the corresponding function parsing.
[0037] Furthermore, the parsing of the callback function type, number of parameters, parameter names, parameter types and return value type information specifically includes: determining the callback function type based on an N-API type by parsing the function; within the callback function, using a callback function parameter number acquisition method to parse the number of parameters passed to the callback function; determining the parameter type passed to the callback function based on the N-API type by parsing the function, and determining the corresponding parameter name; and according to the return value of the callback function, using the N-API type determination function to check the type corresponding to the return value to obtain the return value type information.
[0038] Specifically, in this application, when parsing the callback function type, napi_typeof (N-API type determination function) can be used to check the parameter type passed to the callback. And use napi_is_function to confirm whether the passed object is a function. When obtaining the number of parameters, inside the callback function, use info.Length() to obtain the number of parameters passed to the callback function, where info.Length() is a method for obtaining the number of parameters of the callback function, and the number of parameters is obtained by this method; when obtaining the parameter type, the parameter type can be checked by napi_typeof, and for the specific parameter type, use napi_get_typeof; when obtaining the return value type, use napi_typeof to check its type according to the return value of the callback function.
[0039] Furthermore, the parsing of the function based on the N-API type to obtain the parameter type passed to the callback function and determine the corresponding parameter name specifically includes: extracting the parameters passed to the callback function; using the N-API type determination function to obtain a value pointing to an enumeration type from the incoming parameters, and determining the parameter type passed to the callback function according to the value of the enumeration type; determining the corresponding parameter name according to the parameter type and function definition.
[0040] Specifically, in this application, napi_get_typeof is a function in Node-API (N-API) for obtaining the type of a JavaScript value; when using napi_get_typeof to obtain the parameter type of a callback function, first, the parameter needs to be extracted from the callback function. Usually, the parameter is passed through napi_call_function or a similar N-API function; then, the napi_typeof function is used to obtain the type of a napi_value; for napi_typeof, a napi_valuetype enumeration is returned, indicating the type of the JavaScript value, such as napi_string, napi_number, etc. The parameter type passed to the callback function can be determined according to the value of the napi_valuetype enumeration type. Furthermore, according to the determined parameter type passed to the callback function, the parameter name can be determined, specifically: first, in the function document or declaration, the name and expected type of the parameter are clarified; then, in the callback function, the name is set or mapped according to the index of the parameter (info[0], info[1], etc.) and its type; finally, by combining parameter name mapping and runtime type checking, the name of the parameter can be better determined according to the type.
[0041] Step S30: Generate a callback framework code according to the parsed information, and generate a business code interface framework according to the callback framework code.
[0042] Specifically, in this application, after parsing the type information, number of parameters, parameter name, parameter type, and return value type of the callback function, the callback framework code can be generated based on the detailed information of the parameters and return values; then, based on the callback framework code, a specific business code interface framework can be generated. This usually requires integrating the callback function into the business logic and processing the input and output of the callback function, in which the corresponding interface function, class or module needs to be created, and the specific business logic needs to be implemented according to actual needs.
[0043] Furthermore, based on the parsed information, a callback framework code is generated, and based on the callback framework code, a business code interface framework is generated, specifically including: based on the parsed information, an interface of the callback function is defined, and the callback function is set to meet expected parameter and return value requirements to obtain the callback framework code; a business interface is created based on the callback framework code, and the business code interface framework is generated.
[0044] Specifically, in this application, a callback interface is defined according to the type of callback function, the number of parameters, the name and type of each parameter, and the return value type; the callback interface is an interface used to define callback methods. These methods are usually methods that need to be called after the asynchronous operation is completed. Suppose you want to design a callback framework to handle the processing logic after the asynchronous task is completed. Then, set the callback function to meet the expected parameter and return value requirements, obtain the callback framework code, create a business interface based on the callback framework code, and generate a business code interface framework; The specific process of generating the business code interface framework is as follows: A callback framework is a mechanism for triggering callbacks. It usually contains code to perform asynchronous operations and call callback methods when the operations are completed. When generating a business code interface framework, first determine the business requirements and scenarios in order to design appropriate interfaces and implementations. For example, different business operations need to be processed, and each operation may have success and failure callbacks. Then, the business interface defines the business operations and their callback methods. Therefore, multiple business interfaces need to be defined to handle different operations. Finally, provide implementations for the business interfaces, handle specific business logic, and trigger callbacks at appropriate locations.
[0045] Furthermore, the callback framework code is generated according to the parsed information, and the business code interface framework is generated according to the callback framework code, and then the business logic is added to the generated business code interface, and after compiling and running, the business test results are output.
[0046] Specifically, in this application, after creating a business interface based on the callback framework code and generating a business code interface framework, it is necessary to add business logic to the generated business code interface. In order to ensure that the callback framework and business logic can run correctly in the actual scenario, it is necessary to write test cases after compilation and running to verify whether the callback works as expected, and ensure that all exceptions are handled correctly, and finally output the business test results.
[0047] In the present invention, by setting the callback function type; wherein the callback function type includes: the delegate type of asynchronous programming, the specified type of the hypertext preprocessor and the arrow function type; parsing the callback function type, the number of parameters, the parameter name, the parameter type and the return value type information; generating the callback framework code according to the parsed information, and generating the business code interface framework according to the callback framework code. The present invention can customize the callback function in the form of an arrow function, and define the number of callback parameters and the callback return value type, solving the problem that the number of parameters and the callback function return value cannot be customized in the N-API template, thereby generating the business code interface framework more flexibly.
[0048] Furthermore, if Figure 2 As shown, based on the above-mentioned framework generation method based on callback function flexibility optimization, the present invention also provides a framework generation system based on callback function flexibility optimization, wherein the framework generation system based on callback function flexibility optimization includes: The callback function setting module 21 is used to set the callback function type; wherein the callback function type includes: a delegate type of asynchronous programming, a specified type of a hypertext preprocessor, and an arrow function type; The parsing module 22 is used to parse the callback function type, number of parameters, parameter name, parameter type and return value type information; The code generation module 23 is used to generate a callback framework code according to the parsed information, and to generate a business code interface framework according to the callback framework code.
[0049] Furthermore, if Figure 3 As shown, based on the above-mentioned framework generation method and system based on callback function flexibility optimization, the present invention also provides a terminal accordingly, and the terminal includes a processor 10, a memory 20 and a display 30. Figure 3 Only some components of the terminal are shown, but it should be understood that it is not required to implement all of the components shown, and more or fewer components may be implemented instead.
[0050] In some embodiments, the memory 20 may be an internal storage unit of the terminal, such as a hard disk or memory of the terminal. In other embodiments, the memory 20 may also be an external storage device of the terminal, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (SecureDigital, SD) card, a flash card (Flash Card), etc. equipped on the terminal. Further, the memory 20 may also include both an internal storage unit of the terminal and an external storage device. The memory 20 is used to store application software and various types of data installed on the terminal, such as the program code of the installation terminal. The memory 20 may also be used to temporarily store data that has been output or is to be output. In one embodiment, a framework generation program 40 based on callback function flexibility optimization is stored on the memory 20, and the framework generation program 40 based on callback function flexibility optimization can be executed by the processor 10, thereby realizing the framework generation method based on callback function flexibility optimization in the present application.
[0051] In some embodiments, the processor 10 may be a central processing unit (CPU), a microprocessor or other data processing chip, used to run the program code or process data stored in the memory 20, such as executing the framework generation method based on callback function flexibility optimization.
[0052] In some embodiments, the display 30 may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode) touch device, etc. The display 30 is used to display information on the terminal and to display a visual user interface. The components 10-30 of the terminal communicate with each other via a system bus.
[0053] In one embodiment, when the processor 10 executes the framework generation program 40 based on callback function flexibility optimization in the memory 20, the following steps are implemented: Set the callback function type; wherein the callback function type includes: a delegate type of asynchronous programming, a specified type of a hypertext preprocessor, and an arrow function type; Parse the callback function type, number of parameters, parameter name, parameter type and return value type information; A callback framework code is generated according to the parsed information, and a business code interface framework is generated according to the callback framework code.
[0054] Optionally, the setting of the callback function type specifically includes: Define the N-API function type, set the callback function and the corresponding type, and obtain the delegate type of the asynchronous programming and the specified type of the hypertext preprocessor; Pass the arrow function to the N-API interface to obtain the arrow function type.
[0055] Optionally, the definition of the N-API function type and setting of the callback function and the corresponding type specifically include: Create an N-API function based on the creation function of the N-API tool; The callback function is created based on the creation function, and the type corresponding to the callback function is set.
[0056] Optionally, the parsing of the callback function type, number of parameters, parameter name, parameter type, and return value type information specifically includes: Determine the callback function type based on the N-API type and parse the function; Inside the callback function, a method for obtaining the number of parameters of a callback function is used to parse and obtain the number of parameters passed to the callback function; Determine the function to parse the N-API type to obtain the parameter type passed to the callback function, and determine the corresponding parameter name; According to the return value of the callback function, the type corresponding to the return value is checked using the N-API type determination function to obtain the return value type information.
[0057] Optionally, the determining function parsing based on the N-API type to obtain the parameter type passed to the callback function and determining the corresponding parameter name specifically includes: Extracting parameters passed to the callback function; Using the N-API type determination function to obtain a value pointing to an enumeration type from an incoming parameter, and determining a parameter type passed to the callback function according to the value of the enumeration type; The corresponding parameter name is determined according to the parameter type and function definition.
[0058] Optionally, generating a callback framework code according to the parsed information, and generating a business code interface framework according to the callback framework code specifically includes: According to the parsed information, define the interface of the callback function, and set the callback function to meet the expected parameter and return value requirements, so as to obtain the callback framework code; A business interface is created based on the callback framework code, and the business code interface framework is generated.
[0059] Optionally, the process generates a callback framework code according to the parsed information, and generates a business code interface framework according to the callback framework code, and then includes: Add business logic to the generated business code interface, and output business test results after compiling and running.
[0060] The present invention also provides a computer-readable storage medium, wherein the computer-readable storage medium stores a framework generation program based on callback function flexibility optimization, and when the framework generation program based on callback function flexibility optimization is executed by a processor, the steps of the framework generation method based on callback function flexibility optimization as described above are implemented.
[0061] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal. In the absence of further restrictions, an element defined by the sentence "includes a..." does not exclude the existence of other identical elements in the process, method, article or terminal including the element.
[0062] Of course, those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing related hardware (such as a processor, a controller, etc.) through a computer program, and the program can be stored in a computer-readable storage medium that can be read by a computer, and the program can include the processes of the above-mentioned method embodiments when executed. The computer-readable storage medium can be a memory, a disk, an optical disk, etc.
[0063] It should be understood that the application of the present invention is not limited to the above examples. For ordinary technicians in this field, improvements or changes can be made based on the above description. All these improvements and changes should fall within the scope of protection of the claims attached to the present invention.< / t> < / t> < / number> < / number>
Claims
1. A framework generation method based on callback function flexibility optimization, characterized in that: The framework generation method based on callback function flexibility optimization includes: Set the callback function type; wherein the callback function type includes: a delegate type of asynchronous programming, a specified type of a hypertext preprocessor, and an arrow function type; Parse the callback function type, number of parameters, parameter name, parameter type and return value type information; A callback framework code is generated according to the parsed information, and a business code interface framework is generated according to the callback framework code.
2. The framework generation method based on callback function flexibility optimization according to claim 1 is characterized in that: The setting callback function type specifically includes: Define the N-API function type, set the callback function and the corresponding type, and obtain the delegate type of the asynchronous programming and the specified type of the hypertext preprocessor; Pass the arrow function to the N-API interface to obtain the arrow function type.
3. The framework generation method based on callback function flexibility optimization according to claim 2 is characterized in that: The definition of N-API function type and setting of callback function and corresponding type specifically include: Create an N-API function based on the creation function of the N-API tool; The callback function is created based on the creation function, and the type corresponding to the callback function is set.
4. The framework generation method based on callback function flexibility optimization according to claim 1 is characterized in that: The parsing of the callback function type, number of parameters, parameter name, parameter type and return value type information specifically includes: Determine the callback function type based on the N-API type and parse the function; Inside the callback function, a method for obtaining the number of parameters of a callback function is used to parse and obtain the number of parameters passed to the callback function; Determine the function to parse the N-API type to obtain the parameter type passed to the callback function, and determine the corresponding parameter name; According to the return value of the callback function, the type corresponding to the return value is checked using the N-API type determination function to obtain the return value type information.
5. The framework generation method based on callback function flexibility optimization according to claim 4 is characterized in that: The determining function based on the N-API type parses to obtain the parameter type passed to the callback function and determines the corresponding parameter name, specifically including: Extracting parameters passed to the callback function; Using the N-API type determination function to obtain a value pointing to an enumeration type from an incoming parameter, and determining a parameter type passed to the callback function according to the value of the enumeration type; The corresponding parameter name is determined according to the parameter type and function definition.
6. The framework generation method based on callback function flexibility optimization according to claim 1 is characterized in that: The method of generating a callback framework code according to the parsed information and generating a business code interface framework according to the callback framework code specifically includes: According to the parsed information, define the interface of the callback function, and set the callback function to meet the expected parameter and return value requirements, so as to obtain the callback framework code; A business interface is created based on the callback framework code, and the business code interface framework is generated.
7. The framework generation method based on callback function flexibility optimization according to claim 1 is characterized in that: The method generates a callback framework code based on the parsed information, and generates a business code interface framework based on the callback framework code, and then includes: Add business logic to the generated business code interface, and output business test results after compiling and running.
8. A framework generation system based on callback function flexibility optimization, characterized in that: The framework generation system based on callback function flexibility optimization includes: A callback function setting module, used to set the callback function type; wherein the callback function type includes: a delegate type of asynchronous programming, a specified type of a hypertext preprocessor, and an arrow function type; A parsing module, used to parse the callback function type, number of parameters, parameter name, parameter type and return value type information; The code generation module is used to generate a callback framework code according to the parsed information, and to generate a business code interface framework according to the callback framework code.
9. A terminal, characterized in that: The terminal includes: a memory, a processor, and a framework generation program based on callback function flexibility optimization stored in the memory and executable on the processor. When the framework generation program based on callback function flexibility optimization is executed by the processor, the steps of the framework generation method based on callback function flexibility optimization as described in any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a framework generation program based on callback function flexibility optimization, and when the framework generation program based on callback function flexibility optimization is executed by a processor, the steps of the framework generation method based on callback function flexibility optimization as described in any one of claims 1-7 are implemented.
