A graphical programming multi-language interactive thread asynchronous calling method and terminal
By introducing callback methods and unique identifiers in graphical programming, the problem of inefficient synchronous execution of graphical programming code in Unity is solved, asynchronous processing is realized, code execution efficiency is improved, and data processing is ensured.
Patent Information
- Application Number
- CN202011209995.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-03
- Publication Date
- 2025-02-14
- Estimated Expiration
- 2040-11-03
AI Technical Summary
Code scripts generated by graphical programming can usually only be executed synchronously, resulting in inefficient interface interaction in Unity, and when different building block combinations correspond to the same interface, the existing synchronization processing method cannot be effectively processed.
By introducing a callback method, a callback method with a unique identity corresponding to the interface method is generated to realize asynchronous processing. The specific steps include receiving the script generated by the graphical programming results, determining whether there is a method to call an external interface, generating a callback method, and sending a unique identifier when the interface method is executed to obtain the return value and execute the callback method.
It realizes asynchronous processing of graphical programming generated code, improves code execution efficiency, avoids the problem of data missed transmission, and implements orderly processing of return values in the case of multi-interface methods.
Smart Images

Figure CN114443019B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of graphical programming, and in particular to a graphical programming multi-language interactive thread asynchronous calling method and a terminal. Background Art
[0002] Graphical programming, such as graphical programming through Scratch and Blockly, can directly generate corresponding codes by controlling the combination of graphics, making the programming process simpler. However, the code scripts generated by graphical programming can usually only be executed synchronously. If it involves interaction with other interfaces, it is necessary to wait for the interface to return the corresponding value before subsequent operations can be performed. The code execution efficiency is slow, and running programs on Unity involves more interface interactions. For graphical programming, the script corresponding to each building block is the same, that is, different building block combinations may correspond to the same interface. The existing synchronous processing method can only enable the interface to process messages sent by different building block combinations in sequence. The scripts corresponding to different building block combinations also need to obtain the data returned by the interface before starting subsequent operations, and the code processing efficiency is low. Summary of the invention
[0003] The technical problem to be solved by the present invention is to provide a graphical programming multi-language interactive thread asynchronous calling method and terminal, so as to realize asynchronous processing of codes generated by graphical programming in Unity.
[0004] In order to solve the above technical problems, a technical solution adopted by the present invention is:
[0005] A graphical programming multi-language interactive thread asynchronous calling method, comprising the steps of:
[0006] S1, receiving a first script generated by a graphical programming result;
[0007] S2. Determine whether there is an interface method for calling an external interface in the first script. If so, generate a callback method corresponding to the interface method and having a unique identifier in the first script according to preset conditions to obtain a second script;
[0008] S3. Execute the second script, send the unique identifier as a parameter when executing the interface method, obtain the return value of the external interface called by the interface method through the unique identifier, and execute the callback method corresponding to the unique identifier.
[0009] In order to solve the above technical problems, another technical solution adopted by the present invention is:
[0010] A graphical programming multi-language interactive thread asynchronous call terminal includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the following steps are implemented:
[0011] S1, receiving a first script generated by a graphical programming result;
[0012] S2. Determine whether there is an interface method for calling an external interface in the first script. If so, generate a callback method corresponding to the interface method and having a unique identifier in the first script according to preset conditions to obtain a second script;
[0013] S3. Execute the second script, send the unique identifier as a parameter when executing the interface method, obtain the return value of the external interface called by the interface method through the unique identifier, and execute the callback method corresponding to the unique identifier.
[0014] The beneficial effects of the present invention are: generating a first script with the result of graphical programming, and introducing a callback method, making the callback method correspond to the interface method, being able to suspend the interface method, and then obtaining the return value of the external interface through the callback method for processing at a corresponding interval, and executing other parts of the code when the interface method is suspended, thereby realizing asynchronous operation, and associating the interface method and the callback method by a unique identifier, thereby avoiding the problem of erroneous data transmission when the external interface processes data sent by multiple scripts, and realizing orderly processing of return values when there are multiple interface methods in one script, thereby realizing asynchronous processing of the code generated by graphical programming. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 A flowchart of the steps of a graphical programming multi-language interactive thread asynchronous calling method according to an embodiment of the present invention;
[0016] Figure 2 A schematic diagram of the structure of a graphical programming multi-language interactive thread asynchronous call terminal according to an embodiment of the present invention;
[0017] Figure 3 A schematic diagram of a specific implementation of a graphical programming multi-language interactive thread asynchronous calling method according to an embodiment of the present invention;
[0018] Figure 4 A flowchart of a specific implementation of a graphical programming multi-language interactive thread asynchronous calling method according to an embodiment of the present invention;
[0019] Figure 5 A schematic diagram of a building block packaging process according to an embodiment of the present invention;
[0020] Figure 6A schematic diagram of a function call according to an embodiment of the present invention
[0021] Description of labels:
[0022] 1. A graphical programming multi-language interactive thread asynchronous call terminal; 2. A processor; 3. A memory. DETAILED DESCRIPTION
[0023] In order to explain the technical content, achieved objectives and effects of the present invention in detail, the following is an explanation in combination with the implementation modes and the accompanying drawings.
[0024] Please refer to Figure 1 , a graphical programming multi-language interactive thread asynchronous calling method, comprising the steps of:
[0025] S1, receiving a first script generated by a graphical programming result;
[0026] S2. Determine whether there is an interface method for calling an external interface in the first script. If so, generate a callback method corresponding to the interface method and having a unique identifier in the first script according to preset conditions to obtain a second script;
[0027] S3. Execute the second script, send the unique identifier as a parameter when executing the interface method, obtain the return value of the external interface called by the interface method through the unique identifier, and execute the callback method corresponding to the unique identifier.
[0028] From the above description, it can be seen that the beneficial effects of the present invention are: generating a first script with the result of graphical programming, and introducing a callback method, making the callback method correspond to the interface method, being able to suspend the interface method, and wait until the corresponding interval of time to obtain the return value of the external interface through the callback method for processing, and other parts of the code can be executed when the interface method is suspended, thereby realizing asynchronous operation, and by associating the interface method and the callback method through a unique identifier, the problem of erroneous data transmission can be avoided when the external interface processes data sent by multiple scripts, and orderly processing of return values can be realized when there are multiple interface methods in one script, thereby realizing asynchronous processing of the code generated by graphical programming.
[0029] Furthermore, the step of generating a callback method corresponding to the interface method and having a unique identifier in the first script according to preset conditions in S2 includes:
[0030] In the first script, a method name callback+uuid of a callback method corresponding to the interface method and having a unique identifier is generated according to preset conditions, and the uuid is the unique identifier.
[0031] From the above description, we can see that naming the callback method in the form of callback+uuid can increase the readability of the program while providing unique identification.
[0032] Furthermore, the callback method in S2 includes a method name and a method body;
[0033] After generating a callback method corresponding to the interface method and having a unique identifier in the first script according to preset conditions, the method further includes:
[0034] An index table of the method name and the method body is established, wherein the method name includes the unique identifier.
[0035] From the above description, it can be seen that by establishing an index table to store the correspondence between method names and method bodies, there is no need to directly store a relationship table between method names and method bodies, which reduces the storage volume and can improve search efficiency.
[0036] Furthermore, the method body is formed by encapsulating all logic in the first script that is executed after the interface method.
[0037] As can be seen from the above description, encapsulating the logic of all building blocks in the first script ensures that the script corresponding to the building block combination can correctly obtain the corresponding return data.
[0038] Furthermore, the S3 is specifically: executing the second script, and sending the first unique identifier of the callback method corresponding to the external interface as a parameter when calling the external interface;
[0039] Receive the return value of the external interface, the return value includes a second unique identifier, determine whether the second unique identifier is the same as the first unique identifier in the method name in the index table, and if so, execute the method body corresponding to the method name.
[0040] From the above description, it can be seen that when the external interface returns the corresponding value, it carries its corresponding second unique identifier. The script compares the second unique identifier and its own index table, executes the method body whose unique identifier in the method name in the index table is the same as the second unique identifier, and uses the unique identifier to correspond the return value to the callback method one by one, thereby achieving asynchrony without causing confusion in data sending.
[0041] Please refer to Figure 2 , a graphical programming multi-language interactive thread asynchronous call terminal, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the computer program:
[0042] S1, receiving a first script generated by a graphical programming result;
[0043] S2. Determine whether there is an interface method for calling an external interface in the first script. If so, generate a callback method corresponding to the interface method and having a unique identifier in the first script according to preset conditions to obtain a second script;
[0044] S3. Execute the second script, send the unique identifier as a parameter when executing the interface method, obtain the return value of the external interface called by the interface method through the unique identifier, and execute the callback method corresponding to the unique identifier.
[0045] The beneficial effects of the present invention are: generating a first script with the result of graphical programming, and introducing a callback method, making the callback method correspond to the interface method, being able to suspend the interface method, and then obtaining the return value of the external interface through the callback method for processing at a corresponding interval, and executing other parts of the code when the interface method is suspended, thereby realizing asynchronous operation, and associating the interface method and the callback method by a unique identifier, thereby avoiding the problem of erroneous data transmission when the external interface processes data sent by multiple scripts, and realizing orderly processing of return values when there are multiple interface methods in one script, thereby realizing asynchronous processing of the code generated by graphical programming.
[0046] Furthermore, the step of generating a callback method corresponding to the interface method and having a unique identifier in the first script according to preset conditions in S2 includes:
[0047] In the first script, a method name callback+uuid of a callback method corresponding to the interface method and having a unique identifier is generated according to preset conditions, and the uuid is the unique identifier.
[0048] From the above description, we can see that naming the callback method in the form of callback+uuid can increase the readability of the program while providing unique identification.
[0049] Furthermore, the callback method in S2 includes a method name and a method body;
[0050] After generating a callback method corresponding to the interface method and having a unique identifier in the first script according to preset conditions, the method further includes:
[0051] An index table of the method name and the method body is established, wherein the method name includes the unique identifier.
[0052] From the above description, it can be seen that by establishing an index table to store the correspondence between method names and method bodies, there is no need to directly store a relationship table between method names and method bodies, which reduces the storage volume and can improve search efficiency.
[0053] Furthermore, the method body is formed by encapsulating all logic in the first script that is executed after the interface method.
[0054] As can be seen from the above description, encapsulating the logic of all building blocks in the first script ensures that the script corresponding to the building block combination can correctly obtain the corresponding return data.
[0055] Furthermore, the S3 is specifically: executing the second script, and sending the first unique identifier of the callback method corresponding to the external interface as a parameter when calling the external interface;
[0056] Receive the return value of the external interface, the return value includes a second unique identifier, determine whether the second unique identifier is the same as the first unique identifier in the method name in the index table, and if so, execute the method body corresponding to the method name.
[0057] From the above description, it can be seen that when the external interface returns the corresponding value, it carries its corresponding second unique identifier. The script compares the second unique identifier and its own index table, executes the method body whose unique identifier in the method name in the index table is the same as the second unique identifier, and uses the unique identifier to correspond the return value to the callback method one by one, thereby achieving asynchrony without causing confusion in data sending.
[0058] Please refer to Figure 1 , Figure 3 and Figure 4 , Embodiment 1 of the present invention is:
[0059] The graphical programming multi-language interactive thread asynchronous calling method comprises the following steps:
[0060] S1, receiving a first script generated by a graphical programming result;
[0061] The user generates a first script by splicing the building blocks and combining the script code fragments corresponding to the building blocks;
[0062] S2. Determine whether there is an interface method for calling an external interface in the first script. If so, generate a callback method corresponding to the interface method and having a unique identifier in the first script according to preset conditions to obtain a second script; the callback method includes a method name and a method body;
[0063] Wherein, generating a callback method corresponding to the interface method and having a unique identifier in the first script according to preset conditions includes: generating a method name callback+uuid of a callback method corresponding to the interface method and having a unique identifier in the first script according to preset conditions, wherein the uuid is the unique identifier; the method body is formed by encapsulating all logic in the first script that is executed after the interface method; establishing an index table of the method name and the method body, wherein the method name includes the unique identifier;
[0064] Also includes:
[0065] Create an abstract syntax tree AST:
[0066] Type: dosomething
[0067] Nodename:callbackFunc
[0068] Param
[0069] Body (as the execution content of the callback)
[0070] CallbackKey (randomly generated hashcode (hash value), as a unique identifier);
[0071] S3, executing the second script, sending the unique identifier as a parameter when executing the interface method, obtaining the return value of the external interface called by the interface method through the unique identifier and executing the callback method corresponding to the unique identifier;
[0072] Specifically, executing the second script, and sending the first unique identifier of the callback method corresponding to the external interface as a parameter when calling the external interface;
[0073] Receive the return value of the external interface, the return value includes a second unique identifier, determine whether the second unique identifier is the same as the first unique identifier in the method name in the index table, and if so, execute the method body corresponding to the method name.
[0074] Please refer to Figure 3 , Embodiment 2 of the present invention is:
[0075] Apply the above graphical programming multi-language interactive thread asynchronous calling method to the actual scenario:
[0076] The above-mentioned graphical programming multi-language interactive thread asynchronous calling method can be applied in unity for graphical programming. First, the Lua code is generated according to the block splicing result and runs in the unity engine, interacting with the program logic developed under the unity engine, and then the corresponding Python code is generated and sent to the robot, running under the robot Linux. Two scripting languages are run on two platforms respectively. The editor mode in unity needs to interact with the C# language, and the Linux environment needs to interact with the C++ and Java languages. All of them need to interact through the platform language interface provided by unity or Linux.
[0077] The Lua script calls the functions in the Unity program. In the Lua script, the method name of the callback method corresponding to the interface method of the Unity program is generated in the form of "callback" + unique identifier (uuid), and the corresponding method body is generated in the preset way, and the index between the method name and the method body is established; when executing the interface method, the uuid is sent as a parameter. After the Unity program is executed, the return value is returned and "callback" is concatenated in front of the uuid and returned as an identification value. The Lua script searches for the callback method corresponding to the identification value in the index. If it exists, the return value is used as the input parameter of the callback method to execute the callback method;
[0078] Please refer to Figure 6 , generate Python code, register the callback method waiting for the execution of the class function, such as audiocallback(parameter); Python calls the class A function and calls audiocallback(parameter); the subsequent callback method search is placed in Python execution; Figure 6 There are two building blocks A and B in the program. Building block A executes the logic inside the program, and building block B needs to wait for building block A to finish running and obtain its running results before executing.
[0079] Please refer to Figure 2 , Embodiment 3 of the present invention is:
[0080] A graphical programming multi-language interactive thread asynchronous calling terminal 1 includes a processor 2, a memory 3, and a computer program stored in the memory 3 and executable on the processor 2. When the processor 2 executes the computer program, each step in the first or second embodiment is implemented.
[0081] In summary, the present invention provides a graphical programming multi-language interactive thread asynchronous calling method and terminal, receiving a first script generated according to the graphical programming result, the graphical programming is the splicing of building blocks, each building block corresponds to a code snippet, if there is an interface method for calling an external interface in the first script, then a callback method corresponding to the interface method and with a unique identifier is generated to obtain a second script, and by introducing a callback mechanism, the execution of the external interface is suspended, and the subsequent steps are executed first and then the execution value of the external interface is obtained. The unique identifier is set to identify the callback method corresponding to different interface methods, and the script can also be processed in an orderly manner when obtaining multiple return values; when calling the external interface through the interface method, the unique identifier is also used as one of the parameters so that the unique identifier can be sent together with the execution result after the external interface is executed. When the external interface executes multiple building block combinations, that is, the interface methods corresponding to multiple scripts, it can also be executed in an orderly manner and accurately return the corresponding values, so as to realize asynchronous processing of the code generated by graphical programming in Unity.
[0082] The above descriptions are merely embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent transformations made using the contents of the present invention's specification and drawings, or directly or indirectly applied in related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A graphical programming multi-language interactive thread asynchronous calling method, characterized in that: Includes steps: S1, receiving a first script generated by a graphical programming result; the graphical programming is a splicing of building blocks, each of which corresponds to a code snippet; Generate the first script by splicing the building blocks and combining the script code fragments corresponding to the building blocks; S2. Determine whether there is an interface method for calling an external interface in the first script. If so, generate a callback method corresponding to the interface method and having a unique identifier in the first script according to preset conditions to obtain a second script; the interface method can be suspended; S3, executing the second script, sending the unique identifier as a parameter when executing the interface method, obtaining the return value of the external interface called by the interface method through the unique identifier and executing the callback method corresponding to the unique identifier; The callback method in S2 includes a method name and a method body; After generating the callback method corresponding to the interface method and having a unique identifier in the first script according to the preset conditions, the method further includes: establishing an index table of the method name and the method body, wherein the method name includes the unique identifier; The method body is formed by encapsulating all logic in the first script that is executed after the interface method.
2. A graphical programming multi-language interactive thread asynchronous calling method according to claim 1, characterized in that: The step of generating a callback method corresponding to the interface method and having a unique identifier in the first script according to preset conditions in S2 includes: In the first script, a method name callback+uuid of a callback method corresponding to the interface method and having a unique identifier is generated according to preset conditions, and the uuid is the unique identifier.
3. A graphical programming multi-language interactive thread asynchronous calling method according to claim 1, characterized in that: The S3 is specifically: executing the second script, and sending the first unique identifier of the callback method corresponding to the external interface as a parameter when calling the external interface; Receive the return value of the external interface, the return value includes a second unique identifier, determine whether the second unique identifier is the same as the first unique identifier in the method name in the index table, and if so, execute the method body corresponding to the method name.
4. A graphical programming multi-language interactive thread asynchronous call terminal, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the following steps are implemented: S1, receiving a first script generated by a graphical programming result; the graphical programming is a splicing of building blocks, each of the building blocks corresponds to a code snippet; Generate the first script by splicing the building blocks and combining the script code fragments corresponding to the building blocks; S2. Determine whether there is an interface method for calling an external interface in the first script. If so, generate a callback method corresponding to the interface method and having a unique identifier in the first script according to preset conditions to obtain a second script; the interface method can be suspended; S3, executing the second script, sending the unique identifier as a parameter when executing the interface method, obtaining the return value of the external interface called by the interface method through the unique identifier and executing the callback method corresponding to the unique identifier; The callback method in S2 includes a method name and a method body; After generating the callback method corresponding to the interface method and having a unique identifier in the first script according to the preset conditions, the method further includes: establishing an index table of the method name and the method body, wherein the method name includes the unique identifier; The method body is formed by encapsulating all logic in the first script that is executed after the interface method.
5. A graphical programming multi-language interactive thread asynchronous call terminal according to claim 4, characterized in that: The step of generating a callback method corresponding to the interface method and having a unique identifier in the first script according to preset conditions in S2 includes: In the first script, a method name callback+uuid of a callback method corresponding to the interface method and having a unique identifier is generated according to preset conditions, and the uuid is the unique identifier.
6. A graphical programming multi-language interactive thread asynchronous call terminal according to claim 4, characterized in that: The S3 is specifically: executing the second script, and sending the first unique identifier of the callback method corresponding to the external interface as a parameter when calling the external interface; Receive the return value of the external interface, the return value includes a second unique identifier, determine whether the second unique identifier is the same as the first unique identifier in the method name in the index table, and if so, execute the method body corresponding to the method name.
Citation Information
Patent Citations
Interface calling method, apparatus, and terminal
CN104866383A
Method of asynchronously calling native by js in mobile application
CN105739967A
System and method for generating asynchronous interfaces and methods from synchronous interfaces and methods
CN1790260A