Cross-language host function calling method and system

By providing a unified function call entry point in the script interpreter and triggering the host fallback call process, the integration problem caused by different function sources is solved, data transfer and error avoidance are achieved in the cross-language function call process, and the maintainability and scalability of the system are improved.

CN122220003APending Publication Date: 2026-06-16SHANGHAI TOSUN TECH LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SHANGHAI TOSUN TECH LTD
Filing Date
2026-03-19
Publication Date
2026-06-16

AI Technical Summary

Technical Problem

The different sources of functions in existing script interpreters make them difficult to integrate and maintain in an engineering manner, and data corruption or access errors are prone to occur during function calls.

Method used

A script interpreter provides a unified function call entry point, triggers the host fallback call flow, and transmits data between the host and the script interpreter through serialization and deserialization protocols, using the same protocol for data transmission to achieve cross-language function calls.

🎯Benefits of technology

It enables unified management of multiple function sources, avoids data corruption and access errors during function calls, and improves the system's scalability and maintainability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122220003A_ABST
    Figure CN122220003A_ABST
Patent Text Reader

Abstract

The present application relates to computer software technology, in particular to a cross-language host function calling method and system; wherein the cross-language host function calling method comprises: providing a unified function calling entrance by a script interpreter, and when the function calling cannot be met in the script environment, entering a host fallback calling process; and in the host fallback calling process, the script interpreter serializes the parameters related to the function calling, and delivers the serialized data and the function name to the host; the host deserializes the received data to restore the parameters, and executes the corresponding function calling based on the function name; the host serializes the function return value and / or the modified parameters after the calling is completed, and delivers them back to the script interpreter; the script interpreter deserializes the received data to restore the function return value and / or the modified parameters, and executes a write-back verification process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to computer software technology, specifically to a cross-language host function calling method and system. Background Technology

[0002] In modern software development, scripting languages ​​interact with their host environments more and more frequently. Scripting languages ​​are widely used in automotive electronics, industrial control, and embedded systems to implement flexible business logic configuration and dynamic execution capabilities. However, existing scripting languages ​​have the following technical problems regarding function calls and parameter write-back: In a typical script interpreter, functions may originate from definitions within the script, native functions built into the interpreter, FFI functions from external dynamic link libraries (DLLs), and APIs provided by the host application. Traditional approaches typically design independent call paths for each function source, resulting in scattered code, inconsistent exception and error semantics, and difficulties in engineering integration and maintenance. Furthermore, when passing structure or array parameter data between the scripting language and the host environment (such as C / Delphi), data corruption or access errors can easily occur during function calls due to differences in the data representation and memory layout of functions from different sources.

[0003] Therefore, existing technologies suffer from technical problems such as difficulty in engineering integration and maintenance due to the different sources of functions in the script interpreter, and the susceptibility to data corruption or access errors during function calls.

[0004] It should be noted that the information disclosed in this background section is only for understanding the background technology of this application concept, and therefore, the above description is not considered to constitute prior art information. Summary of the Invention

[0005] The purpose of this invention is to provide a cross-language host function calling method and system.

[0006] To address the aforementioned technical problems, this invention provides a cross-language host function calling method, comprising: A unified function call entry point is provided by the script interpreter, ensuring that function call requests from different function sources are all invoked through this unified entry point; and if the script interpreter determines during the call process that the script environment cannot satisfy the function call request, it triggers the host fallback call flow; and In the host fallback call flow, the script interpreter serializes the parameters related to the function call and passes the serialized data along with the function name to the host; the host deserializes the received data to restore the parameters and executes the corresponding function call based on the function name; after the call is completed, the host serializes the function return value and / or the modified parameters and passes them back to the script interpreter; the script interpreter deserializes the received data to restore the function return value and / or the modified parameters and executes a write-back verification process. The script interpreter and the host use the same protocol for serialization and deserialization.

[0007] In another aspect, the present invention also provides a computer apparatus configured to execute a host fallback call flow, and comprising: The data receiving module is configured to receive serialized data and function names passed from the script interpreter. The deserialization module is configured to: deserialize the received data to restore the parameters related to the function call, and execute the corresponding function call based on the function name; and The serialization module is configured to serialize the function return value and / or modified parameters after the call is completed and pass them back to the script interpreter.

[0008] Thirdly, the present invention also provides a script interpreter, which is configured in a host computer and includes: The unified invocation module is configured to: provide a unified function invocation entry point so that function invocation requests from different function sources are all invoked through the unified function invocation entry point; and if it is determined during the invocation process that the script environment cannot meet the function invocation request, trigger the host fallback invocation process; The serialization module is configured to serialize the parameters related to the function call and pass the serialized data along with the function name to the host. The deserialization module is configured to deserialize function return values ​​and / or modified parameters from the host to restore the function return values ​​and / or modified parameters. The write-back verification module is configured to execute the write-back verification process.

[0009] Fourthly, the present invention also provides a cross-language host function call system for executing the cross-language host function call method as described above, comprising: a computer device and a script interpreter; The computer device is configured as a host; A unified function call entry point is provided by the script interpreter, ensuring that function call requests from different function sources are all invoked through this unified entry point; and if the script interpreter determines during the call process that the script environment cannot satisfy the function call request, it triggers the host fallback call flow; and In the host fallback call flow, the script interpreter serializes the parameters related to the function call and passes the serialized data along with the function name of the function to be called to the host; the host deserializes the received data to restore the parameters and executes the corresponding function call based on the function name; after the call is completed, the host serializes the function return value and / or the modified parameters and passes them back to the script interpreter; the script interpreter deserializes the received data to restore the function return value and / or the modified parameters and executes a write-back verification process. The script interpreter and the host use the same protocol for serialization and deserialization.

[0010] Fifthly, the present invention also provides a method for a computer device to execute a host fallback call flow, comprising: Receives serialized data and the name of the function to be called from the script interpreter; The received data is deserialized to restore the parameters related to the function call, and the corresponding function call is executed based on the function name; and After the call is complete, the function return value and / or the modified parameters are serialized and passed back to the script interpreter.

[0011] In a sixth aspect, the present invention also provides a non-transitory computer-readable storage medium storing instructions that, when executed by a processor, cause the processor to perform the method described above for executing a host fallback call flow of a computer device.

[0012] In a seventh aspect, the present invention also provides an electronic device, comprising: Non-transitory computer-readable storage medium; processor; The non-transitory computer-readable storage medium stores instructions that, when executed by a processor, cause the processor to perform the method described above for executing a host fallback call flow of a computer device.

[0013] Eighthly, the present invention also provides a computer program product including instructions that, when executed by a processor, cause the processor to perform the method described above for a computer device to execute a host fallback call flow.

[0014] The beneficial effects of this invention are that the cross-language host function call method of this invention provides a unified function call entry point through the script interpreter, realizes unified management of multiple function sources, and enters the host fallback call process when the script environment cannot meet the function call requirements. In the host fallback call process, data transfer between the script interpreter and the host is realized through a unified serialization protocol, thus realizing cross-language host function calls and avoiding the problems of data corruption or access errors during function calls.

[0015] Other features and advantages of the invention will be set forth in the following description, and will be apparent in part from the description, or may be learned by practicing the invention. The objects and other advantages of the invention are realized and obtained through the structures particularly pointed out in the description and the drawings.

[0016] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description

[0017] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.

[0018] Figure 1 The diagram illustrates the steps of a cross-language host function call method as described in some embodiments; Figure 2 A schematic block diagram of a computer device involved in some embodiments is shown; Figure 3 A block diagram illustrating the principle of a script interpreter as described in some embodiments is shown; Figure 4 A schematic diagram of the cross-language host function call method system involved in some embodiments is shown; Figure 5 Block diagrams illustrating the principles of electronic hardware platforms involved in some embodiments are shown. Detailed Implementation

[0019] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0020] In a typical script interpreter, functions may originate from definitions within the script, native functions built into the interpreter, FFI functions from external dynamic link libraries (DLLs), and APIs provided by the host application. Traditional approaches typically design independent call paths for each function source, resulting in scattered code, inconsistent exception and error semantics, and difficulties in engineering integration and maintenance. Furthermore, when passing structure or array parameter data between the scripting language and the host environment (such as C / Delphi), data corruption or access errors can easily occur during function calls due to differences in the data representation and memory layout of functions from different sources.

[0021] Therefore, existing technologies suffer from technical problems such as difficulty in engineering integration and maintenance due to the different sources of functions in the script interpreter, and the susceptibility to data corruption or access errors during function calls.

[0022] Therefore, at least one embodiment provides a cross-language host function call method, comprising: a script interpreter providing a unified function call entry point so that function call requests from different function sources are all invoked through the unified function call entry point; and triggering a host fallback call process if the script interpreter determines that the script environment cannot satisfy the function call request during the call process; and in the host fallback call process, the script interpreter serializes the parameters related to the function call and transmits the serialized data and the function name to the host; the host deserializes the received data to restore the parameters and executes the corresponding function call based on the function name; after the call is completed, the host serializes the function return value and / or the modified parameters and transmits them back to the script interpreter; the script interpreter deserializes the received data to restore the function return value and / or the modified parameters and executes a write-back verification process; wherein the script interpreter and the host use the same protocol for serialization and deserialization.

[0023] This cross-language host function call method provides a unified function call entry point through the script interpreter, enabling unified management of multiple function sources. When the script environment cannot meet the function call requirements, it enters the host fallback call process. In the host fallback call process, a unified serialization protocol is used to achieve data transfer between the script interpreter and the host, thus realizing cross-language host function calls and avoiding data corruption or access errors during function calls.

[0024] The various non-limiting embodiments of the present disclosure will now be described in detail with reference to the accompanying drawings.

[0025] like Figure 1 As shown, some embodiments provide a cross-language host function call method, including: Step S101: The script interpreter provides a unified function call entry point so that function call requests from different function sources are all invoked through the unified function call entry point; and if the script interpreter determines that the script environment cannot satisfy the function call request during the call process, it triggers the host fallback call process. In step S102, during the host fallback call process, the script interpreter serializes the parameters related to the function call and transmits the serialized data along with the function name to the host; the host deserializes the received data to restore the parameters and executes the corresponding function call based on the function name; after the call is completed, the host serializes the function return value and / or the modified parameters and transmits them back to the script interpreter; the script interpreter deserializes the received data to restore the function return value and / or the modified parameters and executes the write-back verification process. The script interpreter and the host use the same protocol for serialization and deserialization.

[0026] Specifically, the script interpreter and the host must use the same serialization protocol (such as JSON) to correctly parse and restore the parameter data and avoid data corruption caused by protocol mismatch.

[0027] In some embodiments, the parameters associated with the function call include: parameters passed by value and / or parameters passed by reference.

[0028] In some embodiments, both the script interpreter and the host use the JSON protocol for serialization and deserialization.

[0029] In some embodiments, the method for performing the write-back verification process includes: If the script interpreter detects that the parameter passed by value was modified by the host during the call based on the function return value and / or the modified parameter, it will handle the error and terminate the current function call. If the script interpreter detects that the parameters passed by reference were modified by the host during the call based on the function return value and / or the modified parameters, it will deserialize the modified parameters and write them back to the memory of the variable, array, or structure.

[0030] The following case study details the process of calling a cross-language host function.

[0031] In automotive electronic bus communication systems, scripts need to call the CAN message transmission and reception API functions provided by the host. The script passes a CAN message structure variable, and the host needs to write the message content back to this variable after receiving the message. This case uses the following CAN message function as a specific example: / / Function name: com.receive_can; / / Functionality: Receives a message frame from the CAN bus and fills the received data into the passed-in structure; / / Parameter description: / / msg - A TCAN structure reference used to receive CAN message data, passed by reference; / / timeout - timeout duration (milliseconds), passed by value; / / Return value: 0 indicates success, non-zero indicates an error code; Script calling code: int com.receive_can(&msg, timeout); The TCAN structure is defined as follows: struct TCAN { int FIdentifier; / / CAN identifier (11-bit or 29-bit) int FDLC; / / Data length code (0-8) int FIdxChn; / / Channel index int FProperties; / / Property flags int FTimeUS; / / Timestamp (microseconds) int FData[8]; / / Data byte array }; Below is an example of a script call: void main(void) { TCAN msg; / / Declare CAN message structure msg.FIdentifier = 0; / / Initialize the identifier to 0 msg.FDLC = 0; / / Initialize data length to 0 int timeout = 5000; / / Timeout of 5 seconds / / Call the host API function to receive CAN messages / / Note: msg uses the & operator to be passed by reference, while timeout is passed by value; int result = com.receive_can(&msg, timeout); if (result == 0) { / / Received successfully, message has been modified by the host. printf("Received CAN ID: 0x%X\n", msg.FIdentifier); printf("Data[0]: 0x%X\n", msg.FData[0]); } } In the host fallback call flow, the script interpreter serializes the current value of the msg parameter passed by reference into a string: {"FIdentifier":0,"FDLC":0, "FIdxChn":0,"FProperties":0, "FTimeUS":0,"FData":[0,0,0,0,0,0,0,0]}, retrieve the value "5000" of the timeout parameter passed by value, and then pass the function name "com.receive_can" along with the string parameter array and the value "5000" of the timeout parameter to the host; After the host performs deserialization, it executes CAN bus reception to obtain the following CAN message data: FIdentifier = 0x123.

[0032] FDLC = 8.

[0033] FData = [0xAA, 0xBB, 0xCC, 0xDD, 0x11, 0x22, 0x33, 0x44].

[0034] FTimeUs = 123456789.

[0035] Then, during the function call, the host modifies the content of the parameter `msg` and serializes the modified content as: `{"FIdentifier":291,"FDLC":8, "FIdxChn":0,"FProperties":1,` "FTimeUS":123456789,"FData":[170,187,204,221,17,34,51,68]} is passed to the script interpreter.

[0036] If the script interpreter recognizes that the parameter modified by the host is a parameter passed by reference, it will perform a write-back, which means deserializing the modified parameter content into the structure memory and writing it back to the msg variable in the original environment where the referenced parameter is located. The script interpreter will then return a value of 0 to the script.

[0037] In the above case, the function call statement in the script code (such as com.receive_can(&msg,timeout)) is interpreted and executed by the script interpreter. When the script interpreter finds that the function is not defined in the script environment, it enters the host fallback call flow.

[0038] In some embodiments, if the script interpreter determines that the script environment cannot satisfy the function call request during the call process, the method for triggering the host fallback call flow includes: when a function call is required, the script interpreter first traverses the callable functions defined in the script environment; if no callable function matching the function name of the function to be called is found, the name of the function to be called is flattened to trigger the host fallback call flow.

[0039] Specifically, a script environment failing to satisfy a function call means that no callable function matching the name of the function to be called is found among the callable functions defined in the script environment.

[0040] Specifically, when the script interpreter passes the function name to the host, it does not serialize the function name. The function name is already a plain string after being flattened, so it can be passed directly.

[0041] In some embodiments, the function sources include internal script functions, native functions built into the script interpreter, external FFI functions, and API functions provided by the host.

[0042] Specifically, the script interpreter provides a unified function call entry point (VisitFunctionCall), through which all function calls are processed. When the script interpreter encounters a function call node, it first traverses the callable functions already defined in the script environment. Callable functions already defined in the script environment include: script-internal functions (vtFunction), script interpreter-built-in native functions (vtNativeFunction), and external FFI functions registered via FFI (vtExternalFunction).

[0043] If no callable function with the same name is found in the current script environment, the script interpreter considers this a fallback request to the host environment. In this case, the script interpreter calls the `GetFullCalleeName` helper function to flatten the name of the function to be called, converting it into a dotted-part complete string. If the function name to be called is a simple variable node (TVariableNode), return the variable name directly as the complete function name; If the function name of the function to be called is a member access node (TMemberAccessNode), recursively process its object part, and then concatenate the member names with dots. For example, for the flattening of the function name "abc(d)": first, identify that this is a call to the member "c" of the "ab" object; recursively process "ab" to get the string "ab"; concatenate the member name "c" to get the full name "abc", then "abc" is the flattened function name.

[0044] The following describes the flattening process in detail, using the function call expression "device.sensor.getValue(temp, &result)" as an example: Step 1: The script interpreter calls the member access identification function with the parameter "device.sensor.getValue" to obtain the member: getValue; Step 2: The script interpreter recursively calls the function to identify member access with the parameter "device.sensor" to obtain the member: sensor; Step 3: The script interpreter recursively calls the function to identify member access with the parameter "device" to obtain the member: device. Since this member is already a basic object, the recursion ends. Step 4: The script interpreter appends the "sensor" member of the base object device to device, making it a device.sensor object; Step 5: The script interpreter appends the "getValue" member of the device.sensor object to device.sensor, making it: device.sensor.getValue; Step 6: Obtain the function call parameters: [temp, &result]; Final output: Full Name = "device.sensor.getValue"; Arguments = [temp, &result].

[0045] Specifically, through flattening, the host can dynamically route to the corresponding processing function stored in the host environment based on the dotted name, improving the system's scalability; it also simplifies the binding complexity between the script and the host, allowing the script to directly use the namespace-style API functions provided by the host.

[0046] In some embodiments, after the host receives the serialized data and the function name of the function to be called from the script interpreter, it first checks the cache to see if there is a processing function that matches the function name of the function to be called. If there is, the function call is initiated; otherwise, the host searches for a function with the corresponding name in the function library by searching for the name of the function to be called. After loading the function with the corresponding name, the function call is initiated.

[0047] Specifically, let's take the example of a script interpreter calling a mathematical function inside a script: When the script interpreter first calls the mathematical function `math.sin`, after flattening the code, it automatically enters the host fallback call flow based on the name "math.sin". The host first checks if the function pointer "math.sin" exists in the cache. If it exists, it executes the call to `math.sin` and returns; otherwise, it searches for the corresponding library name in the function library using the function name "math.sin", obtaining the result "math.dll". The host loads `math.dll`, registers its internal functions such as `sin`, `cos`, `tan`, and `sqrt` in the cache, then executes the call to `math.sin` and returns the result.

[0048] When the script interpreter subsequently calls a mathematical function such as math.cos, the script interpreter automatically enters the host fallback call flow using the flattened name "math.cos". The host first checks if the function pointer "math.cos" exists in the cache. If it exists, it executes the call to math.cos and immediately returns the result.

[0049] The code example is as follows: / / First call of mathematical functions by the script interpreter / / math.dll has not yet been loaded. float angle = 0.785; / / 45 degrees (radians) / / First call - triggers math.dll loading float sinVal = math.sin(angle); / / → Load math.dll float cosVal = math.cos(angle); / / → Reuse the already loaded math.dll float tanVal = math.tan(angle); / / → Reuse the already loaded math.dll / / Subsequent calls do not require reloading float sqrtVal = math.sqrt(16); / / → Direct call, fast response float powVal = math.pow(2, 10); / / → Direct call Specifically, the host does not need to preload all function modules; it only needs to load them when in use, effectively saving CPU and memory resources.

[0050] like Figure 2 As shown, some embodiments also provide a computer device configured to enter a host fallback call flow, and includes: The data receiving module is configured to receive serialized data and the function name of the function to be called from the script interpreter. The deserialization module is configured to: deserialize the received data to restore the parameters related to the function call, and execute the corresponding function call based on the function name; and The serialization module is configured to serialize the function return value and / or modified parameters after the call is completed and pass them back to the script interpreter.

[0051] The specific implementation functions of the data receiving module, deserialization module, and serialization module are implemented in the computer device. For details, please refer to the aforementioned section on cross-language host function call methods, which will not be repeated here.

[0052] In some embodiments, the computer device further includes a loading module configured to: upon receiving serialized data and the function name of the function to be called from the script interpreter, first check the cache to see if there is a processing function that matches the function name of the function to be called; if so, proceed to function call; otherwise, search for a function with the corresponding name in the function library by the name of the function to be called, load the function with the corresponding name, and then proceed to function call.

[0053] The specific implementation of the loading module is carried out in the computer device. For details, please refer to the aforementioned section on cross-language host function call methods, which will not be repeated here.

[0054] like Figure 3 As shown, some embodiments also provide a script interpreter, which is configured in a host computer and includes: The unified invocation module is configured to: provide a unified function invocation entry point so that function invocation requests from different function sources are all invoked through the unified function invocation entry point; and if it is determined during the invocation process that the script environment cannot meet the function invocation request, trigger the host fallback invocation process; The serialization module is configured to serialize the parameters related to the function call and pass the serialized data along with the function name of the function to be called to the host. The deserialization module is configured to deserialize function return values ​​and / or modified parameters from the host to restore the function return values ​​and / or modified parameters. The write-back verification module is configured to execute the write-back verification process.

[0055] The specific implementation functions of the unified call module, deserialization module, serialization module, and write-back verification module are implemented in the host computer. For details, please refer to the aforementioned section on cross-language host function call methods, which will not be repeated here.

[0056] like Figure 4 As shown, some embodiments also provide a cross-language host function call system for executing the cross-language host function call method as described above, including: Computer devices and script interpreters; The computer device is configured as a host; A unified function call entry point is provided by the script interpreter, ensuring that function call requests from different function sources are all invoked through this unified entry point; and if the script interpreter determines during the call process that the script environment cannot satisfy the function call request, it triggers the host fallback call flow; and In the host fallback call flow, the script interpreter serializes the parameters related to the function call and passes the serialized data along with the function name of the function to be called to the host; the host deserializes the received data to restore the parameters and executes the corresponding function call based on the function name; after the call is completed, the host serializes the function return value and / or the modified parameters and passes them back to the script interpreter; the script interpreter deserializes the received data to restore the function return value and / or the modified parameters and executes a write-back verification process. The script interpreter and the host use the same protocol for serialization and deserialization.

[0057] For details regarding the specific implementation functions of the computer device and script interpreter, please refer to the aforementioned section on cross-language host function call methods; these details will not be repeated here.

[0058] Some embodiments also provide a method for a computer device to execute a host fallback call flow, including: receiving serialized data and the function name of a function to be called from a script interpreter; deserializing the received data to restore the parameters related to the function call, and executing the corresponding function call based on the function name; and after the call is completed, serializing the function return value and / or the modified parameters, and passing them back to the script interpreter.

[0059] The electronic devices in the embodiments of this disclosure are described below from the perspective of hardware processing: The embodiments disclosed herein do not limit the specific implementation of the electronic device.

[0060] like Figure 5 As shown, some embodiments also provide an electronic device, including: a processor, a non-transitory computer-readable storage medium, a communication bus, and a communication interface; wherein the processor, the non-transitory computer-readable storage medium, and the communication interface communicate with each other through the communication bus; the non-transitory computer-readable storage medium stores instructions that, when executed by the processor, cause the processor to perform the method of executing a host fallback call flow as described above.

[0061] In some embodiments, computer devices and industrial control computers can also be used as a type of electronic device.

[0062] Figure 5 The structure shown does not constitute a limitation on the electronic device and may include fewer or more components than shown, or combine certain components, or have different component arrangements.

[0063] In some embodiments, the communication interface may be RS232, RS485, USB, or TYPE, and can be connected to an external bus adapter. It may also include a wired or wireless network interface, which may optionally include a wired interface and / or a wireless interface (such as a Wi-Fi interface, Bluetooth interface, etc.), typically used to establish communication connections between the computer device and other electronic devices.

[0064] In some embodiments, non-transitory computer-readable storage media include, but are not limited to, flash memory, hard disks, multimedia cards, card-type memories (e.g., SD memory), magnetic storage, magnetic disks, optical disks, etc. In some embodiments, it may be an internal storage unit of a computer device, such as the hard disk of that computer device. In other embodiments, the storage medium may also be an external storage device of the computer device, such as a plug-in hard disk, SmartMedia Card (SMC), Secure Digital (SD) card, Flash Card, etc., provided on the computer device. Furthermore, the storage medium may include both internal storage units and external storage devices of the computer device. The storage medium can be used not only to store application software and various types of data installed on the computer device, such as computer program code, but also to temporarily store data that has been output or will be output.

[0065] In some embodiments, a processor may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chip, used to run program code stored in memory or process data, such as executing computer programs.

[0066] In some embodiments, the communication bus can also be an input / output bus, which may be a Peripheral Component Interconnect (PCI) bus or an Enhanced Industry Standard Architecture (EISA) bus, etc. This bus can be divided into address bus, data bus, control bus, etc.

[0067] Optionally, the computer device may also include a user interface, which may include a display, an input unit such as a keyboard, and optionally, a standard wired interface or a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, or an organic light-emitting diode (OLED) touchscreen, etc. The display may also be appropriately referred to as a screen or display unit, used to display information processed in the computer device and to display a user type table.

[0068] When the processor executes the program, it implements the above. Figure 1 This refers to a portion of step S102 in the cross-language host function call method embodiment shown. Alternatively, the processor executes a computer program to implement the functions of each module or unit in the above-described device embodiments.

[0069] Some embodiments also provide a non-transitory computer-readable storage medium storing computer-readable instructions that, when executed by at least one processor, cause the method for executing a host fallback call flow as described above to be performed, specifically as follows: Receive serialized data and the function name of the function to be called from the script interpreter; deserialize the received data to restore the parameters related to the function call, and execute the corresponding function call based on the function name; and after the call is completed, serialize the function return value and / or the modified parameters and pass them back to the script interpreter.

[0070] Some embodiments also provide a computer program product including a readable storage medium having readable program code stored thereon, the readable program code including instructions that cause at least one processor (one or more computer devices) to perform the method of the computer device executing the host fallback call flow as described above.

[0071] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative; for example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.

[0072] In addition, the functional modules in the various embodiments of the present invention can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.

[0073] If the aforementioned functions are implemented as software functional modules and sold or used as independent products, they can be stored in a non-transitory computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention.

[0074] Based on the above-described preferred embodiments of the present invention, and through the foregoing description, those skilled in the art can make various changes and modifications without departing from the inventive concept. The technical scope of this invention is not limited to the contents of the specification, but must be determined according to the scope of the claims.

Claims

1. A cross-language host function calling method, characterized in that, include: A unified function call entry point is provided by the script interpreter so that function call requests from different function sources are all invoked through the unified function call entry point; Furthermore, if the script interpreter determines that the script environment cannot satisfy the function call request during the call process, it will trigger the host fallback call flow. In the host fallback call flow, the script interpreter serializes the parameters related to the function call and passes the serialized data and the function name of the function to be called to the host. The host deserializes the received data to restore the parameters and executes the corresponding function call based on the function name; After the call is completed, the host serializes the function return value and / or the modified parameters and passes them back to the script interpreter; The script interpreter deserializes the received data to restore the function return value and / or the modified parameters, and performs a write-back verification process. The script interpreter and the host use the same protocol for serialization and deserialization.

2. The cross-language host function calling method according to claim 1, characterized in that, The parameters related to the function call include: parameters passed by value and / or parameters passed by reference.

3. The cross-language host function calling method according to claim 2, characterized in that, The methods for performing the write-back verification process include: If the script interpreter detects that the parameter passed by value was modified by the host during the call based on the function return value and / or the modified parameter, it will handle the error and terminate the current function call. If the script interpreter detects that the parameters passed by reference were modified by the host during the call based on the function return value and / or the modified parameters, it will deserialize the modified parameters and write them back to the memory of the variable, array, or structure.

4. The cross-language host function calling method according to claim 1, characterized in that, If the script interpreter determines during the call that the script environment cannot satisfy the function call request, the methods that trigger the host fallback call flow include: When a function call is required, the script interpreter first traverses the callable functions defined in the script environment. If no callable function matching the function name to be called is found, the name of the function to be called is flattened to trigger the host fallback call process.

5. The cross-language host function calling method according to claim 4, characterized in that, The sources of these functions include internal script functions, native functions built into the script interpreter, external FFI functions, and API functions provided by the host.

6. The cross-language host function calling method according to claim 1, characterized in that, Both the script interpreter and the host use the JSON protocol for serialization and deserialization.

7. The cross-language host function calling method according to claim 1, characterized in that, After receiving the serialized data and the function name of the function to be called from the script interpreter, the host first checks the cache to see if there is a processing function that matches the function name of the function to be called. If there is, the function call is initiated; otherwise, the host searches for a function with the corresponding name in the function library based on the function name of the function to be called. After loading the function with the corresponding name, the function call is initiated.

8. A computer device, characterized in that, The computer device is configured to execute a host fallback call flow and includes: The data receiving module is configured to receive serialized data and the function name of the function to be called from the script interpreter. The deserialization module is configured to: deserialize the received data to restore the parameters related to the function call, and execute the corresponding function call based on the function name; and The serialization module is configured to serialize the function return value and / or modified parameters after the call is completed and pass them back to the script interpreter.

9. The computer device according to claim 8, characterized in that, The parameters related to the function call include: parameters passed by value and / or parameters passed by reference.

10. The computer device according to claim 9, characterized in that, Also includes: The loading module is configured to: upon receiving the serialized data and the function name of the function to be called from the script interpreter, first check the cache to see if there is a processing function that matches the function name of the function to be called. If there is, proceed to the function call; otherwise, search for the function with the corresponding name in the function library, load the function with the corresponding name, and then proceed to the function call.

11. A script interpreter, characterized in that, The script interpreter is configured in the host computer and includes: The unified invocation module is configured to: provide a unified function invocation entry point so that function invocation requests from different function sources are all invoked through the unified function invocation entry point; and if it is determined during the invocation process that the script environment cannot meet the function invocation request, trigger the host fallback invocation process; The serialization module is configured to serialize the parameters related to the function call and pass the serialized data along with the function name of the function to be called to the host. The deserialization module is configured to deserialize function return values ​​and / or modified parameters from the host to restore the function return values ​​and / or modified parameters. The write-back verification module is configured to execute the write-back verification process.

12. The script interpreter according to claim 11, characterized in that, The write-back verification process includes: If the script interpreter detects that the parameter passed by value was modified by the host during the call based on the function return value and / or the modified parameter, it will handle the error and terminate the current function call. If the script interpreter detects that the parameters passed by reference were modified by the host during the call based on the function return value and / or the modified parameters, it will deserialize the modified parameters and write them back to the memory of the variable, array, or structure.

13. The script interpreter according to claim 12, characterized in that, If, during the call process, the script interpreter determines that the script environment cannot satisfy the function call request, it triggers the host fallback call flow, including: When a function call is required, the script interpreter first traverses the callable functions defined in the script environment. If no callable function matching the function name to be called is found, the name of the function to be called is flattened to trigger the host fallback call process.

14. A cross-language hosted function call system for executing the cross-language hosted function call method as described in any one of claims 1-7, characterized in that, include: Computer devices and script interpreters; The computer device is configured as a host; The script interpreter provides a unified function call entry point so that function call requests from different function sources are all invoked through the unified function call entry point; and if the script interpreter determines that the script environment cannot satisfy the function call request during the call process, it triggers the host fallback call flow. as well as In the host fallback call flow, the script interpreter serializes the parameters related to the function call and passes the serialized data along with the function name of the function to be called to the host; the host deserializes the received data to restore the parameters and executes the corresponding function call based on the function name; after the call is completed, the host serializes the function return value and / or the modified parameters and passes them back to the script interpreter; the script interpreter deserializes the received data to restore the function return value and / or the modified parameters and executes a write-back verification process. The script interpreter and the host use the same protocol for serialization and deserialization.

15. A method for a computer device to execute a host fallback call flow, characterized in that, include: Receives serialized data and the name of the function to be called from the script interpreter; The received data is deserialized to restore the parameters related to the function call, and the corresponding function call is executed based on the function name; as well as After the call is complete, the function return value and / or the modified parameters are serialized and passed back to the script interpreter.

16. The method for a computer device to execute a host fallback call flow according to claim 15, characterized in that, The parameters related to the function call include: parameters passed by value and / or parameters passed by reference.

17. The method for a computer device to execute a host fallback call flow according to claim 15, characterized in that, Also includes: After receiving the serialized data and the name of the function to be called from the script interpreter, the system first checks the cache to see if there is a processing function that matches the name of the function to be called. If there is, the function is called; otherwise, the system searches for a function with the corresponding name in the function library, loads the function with the corresponding name, and then calls the function.

18. A non-transitory computer-readable storage medium, characterized in that, The device stores instructions that, when executed by a processor, cause the processor to perform a method for executing a host fallback call flow as described in any one of claims 15-17.

19. An electronic device, characterized in that, include: Non-transitory computer-readable storage medium; processor; The non-transitory computer-readable storage medium stores instructions that, when executed by a processor, cause the processor to perform the method of executing a host fallback call flow as described in any one of claims 15-17.

20. A computer program product, characterized in that, Includes instructions that, when executed by a processor, cause the processor to perform a method for executing a host fallback call flow as described in any one of claims 15-17.