Cross-programming language calling method and device and electronic equipment

By using a transit runtime environment in the client/server architecture to implement cross-programming language calls, the problem of heavy development workload caused by rewriting business services in the existing technology is solved, and efficient cross-programming language data interaction is achieved.

CN120596077APending Publication Date: 2025-09-05TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410243598.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-03-04
Publication Date
2025-09-05

AI Technical Summary

Technical Problem

In the client/server architecture, existing technologies require business services to be rewritten to implement cross-programming language calls, resulting in a large amount of development work.

Method used

By calling the transit function in the first operating environment, the transit operating environment is used to realize data interaction between the first operating environment and the second operating environment, and the method is called across programming languages, including calling the first business service in the first operating environment, passing the business parameters to the second operating environment through the transit operating environment, and performing business processing in the second operating environment.

Benefits of technology

The development workload is reduced, cross-programming language calls are realized without rewriting the business service architecture in the first operating environment, and development efficiency is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120596077A_ABST
    Figure CN120596077A_ABST
Patent Text Reader

Abstract

The invention provides a cross-programming language calling method and device, electronic equipment, a computer readable storage medium and a computer program product. The cross-programming language calling method and device can be applied to various scenes such as cloud technology, artificial intelligence, intelligent traffic and auxiliary driving. The method comprises the following steps: calling a first business service in a first operation environment of a first programming language to obtain business parameters in the first operation environment; calling a first function in the first operation environment to transmit the service parameters in the first operation environment to a transfer operation environment of a transfer programming language, and transmitting the service parameters in the transfer operation environment to a second operation environment of a second programming language; and calling the second business service in the second operation environment to perform business processing according to the business parameters in the second operation environment. Through the application, the service architecture of the business service in the first operation environment can be reused, the data interaction between the first operation environment and the second operation environment is realized through the transfer operation environment, and the workload of development work is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to computer technology, and in particular to a cross-programming language calling method, device, electronic device, computer-readable storage medium, and computer program product. Background Art

[0002] As computer technology advances, programming languages ​​are also constantly evolving and changing. Programming languages ​​allow programmers to precisely define the data a computer needs to use and precisely define the actions to take in different situations. Computer-based businesses often involve using different programming languages ​​in different operating environments.

[0003] For example, in a client / server architecture, the client uses JavaScript, and Node.js provides the runtime environment for JavaScript on the server. Meanwhile, the server typically uses business services written in C++, and calls these services within the C++ runtime environment. In the solutions provided by related technologies, in order to enable Node.js to call these business services and obtain the corresponding business parameters, these business services are typically rewritten using Node.js, which undoubtedly brings a lot of work. Summary of the Invention

[0004] The present application provides a cross-programming language calling method, device, electronic device, computer-readable storage medium and computer program product, which can directly reuse the service architecture of business services in the first operating environment, realize data interaction between the first operating environment and the second operating environment through the transit operating environment, and reduce the workload of development work.

[0005] The technical solution of this application is achieved as follows:

[0006] This application provides a cross-programming language calling method, including:

[0007] Invoking a first business service in a first operating environment of a first programming language to obtain business parameters in the first operating environment;

[0008] Calling a first function in the first operating environment to pass business parameters in the first operating environment to a transit operating environment of a transit programming language, and passing the business parameters in the transit operating environment to a second operating environment of a second programming language; wherein the first function is converted from a transit function in the transit operating environment, and the transit function is converted from a second function in the second operating environment; and the second function is used to call back business parameters;

[0009] The second business service is called in the second operating environment to perform business processing according to the business parameters in the second operating environment.

[0010] The present application provides a cross-programming language calling device, comprising:

[0011] An acquisition module, configured to call a first business service in a first operating environment of a first programming language to obtain business parameters in the first operating environment;

[0012] a transfer module, configured to call a first function in the first operating environment to transfer business parameters in the first operating environment to a transit operating environment of a transit programming language, and to transfer business parameters in the transit operating environment to a second operating environment of a second programming language; wherein the first function is converted from a transit function in the transit operating environment, and the transit function is converted from a second function in the second operating environment; and the second function is used to call back business parameters;

[0013] The business processing module is used to call the second business service in the second operating environment to perform business processing according to the business parameters in the second operating environment.

[0014] In the above scheme, the input parameters of the first function include the business parameters in the first operating environment; the first function includes a transfer function pointer pointing to the transfer function; the transfer function includes a second function pointer pointing to the second function; the transfer module is also used to: transfer the business parameters received by the first function to the transfer function in the transfer operating environment through the transfer function pointer pointing to the transfer function in the first function; transfer the business parameters received by the transfer function to the second function in the second operating environment through the second function pointer pointing to the second function in the transfer function.

[0015] In the above scheme, the first function includes a data type conversion function; the transfer module is also used to: perform the following processing through the data type conversion function in the first function: identify the first data type to which the business parameters received by the first function belong; perform data type conversion processing on the business parameters belonging to the first data type to obtain business parameters belonging to the second data type; wherein the first data type corresponds to the first programming language, and the second data type corresponds to the second programming language; through the transfer function pointer pointing to the transfer function in the first function, the business parameters belonging to the second data type are transferred to the transfer function in the transfer operating environment.

[0016] In the above scheme, the transfer module is also used to: create a dynamic array and store the business parameters belonging to the second data type in the dynamic array; pass the dynamic array as a parameter to the transfer function in the transfer operating environment through the transfer function pointer pointing to the transfer function in the first function.

[0017] In the above solution, the cross-programming language calling device also includes a first prompt module, which is used to: when the data type conversion processing of the business parameter belonging to the first data type fails, output a first error prompt according to the business parameter belonging to the first data type.

[0018] In the above scheme, the cross-programming language calling device also includes a second prompt module, which is used to: compile the data type conversion function in the first function; when the compilation of the data type conversion function in the first function fails, output a second error prompt according to the data type conversion function in the first function.

[0019] In the above scheme, the cross-programming language calling device also includes a first function creation module, which is used to: perform the following processing in the transit operating environment: create a closure including a transit function pointer pointing to the transit function as a first function; perform pointer creation processing on the first function to obtain an original pointer pointing to the first function; convert the original pointer pointing to the first function into a first function pointer supporting the first programming language; the transfer module is also used to: call the first function in the first operating environment through the first function pointer pointing to the first function.

[0020] In the above solution, the first function creation module is further used to: perform heap allocation processing on the first function; and create an original pointer pointing to the first function that has been heap allocated.

[0021] In the above scheme, the second operating environment is written in the first programming language; the cross-programming language calling device also includes a transit function creation module, which is used to: perform the following processing in the transit operating environment: call the pointer acquisition function provided by the interface protocol between the first programming language and the second programming language to obtain a second function pointer pointing to the second function; encapsulate the second function pointer pointing to the second function to obtain the transit function in the transit operating environment.

[0022] In the above scheme, the second operating environment is written in the first programming language; the acquisition module is also used to: perform the following processing in the second operating environment: call the interface protocol between the first programming language and the second programming language to access the file path of the first business service in the first operating environment; call the first business service through the file path of the first business service to obtain the business parameters in the first operating environment.

[0023] In the above solution, the acquisition module is further used to: perform the following processing in the first operating environment: detect a business operation; call a first business service corresponding to the detected business operation, and obtain business parameters in the first operating environment.

[0024] In the above solution, the first operating environment, the transit operating environment and the second operating environment all run on the server side; the business processing module is also used to: call the second business service in the second operating environment to pass the business parameters in the second operating environment to the client using the second programming language; wherein, the client is used to display the business parameters in the second operating environment.

[0025] The present application provides an electronic device, including:

[0026] a memory for storing executable instructions;

[0027] The processor is used to implement the cross-programming language calling method provided by the present application when executing the executable instructions stored in the memory.

[0028] The present application provides a computer-readable storage medium storing executable instructions for causing a processor to execute instructions to implement the cross-programming language calling method provided by the present application.

[0029] The present application provides a computer program product, which includes executable instructions for causing a processor to execute and implement the cross-programming language calling method provided by the present application.

[0030] This application has the following beneficial effects:

[0031] This application calls the first business service in the first operating environment of the first programming language, obtains the business parameters in the first operating environment, and then calls the first function in the first operating environment. Since the first function is converted from the transit function in the transit operating environment, and the transit function is converted from the second function used to call back the business parameters in the second operating environment, it can overcome the differences in memory models between different programming languages. Calling the first function in the first operating environment is equivalent to calling the second function in the second operating environment. In this way, the transit operating environment can be used as a transit to realize data interaction between the first operating environment and the second operating environment, that is, the business parameters in the first operating environment can be passed to the second operating environment through the transit operating environment. In summary, this application can realize cross-programming language calls, and at the same time, there is no need to rewrite the service architecture of the business service in the first operating environment, which can effectively reduce the workload of development work. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0033] Figure 1 This is a schematic diagram of the architecture of a cross-programming language calling system provided by an embodiment of the present application;

[0034] Figure 2 This is a schematic diagram of the structure of the server provided in the embodiment of the present application;

[0035] Figure 3 This is a first flow chart of a cross-programming language calling method provided by an embodiment of the present application;

[0036] Figure 4 This is a second flow chart of the cross-programming language calling method provided in an embodiment of the present application;

[0037] Figure 5 This is a third flow chart of the cross-programming language calling method provided in an embodiment of the present application;

[0038] Figure 6 This is a fourth flow chart of the cross-programming language calling method provided in an embodiment of the present application;

[0039] Figure 7 This is a fifth flow chart of the cross-programming language calling method provided in an embodiment of the present application;

[0040] Figure 8 This is a functional relationship diagram provided by an embodiment of the present application;

[0041] Figure 9 This is a sixth flow chart of the cross-programming language calling method provided in an embodiment of the present application;

[0042] Figure 10 This is the seventh flow chart of the cross-programming language calling method provided in the embodiment of the present application. DETAILED DESCRIPTION

[0043] In order to make the purpose, technical solutions and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be regarded as limiting this application. All other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.

[0044] In the following description, references to "some embodiments" describe a subset of all possible embodiments. However, it is understood that "some embodiments" may be the same subset or different subsets of all possible embodiments, and may be combined with each other without conflict. In the following description, the term "plurality" refers to at least two.

[0045] In the following description, the terms "first\second\third" involved are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that "first\second\third" can be interchanged with a specific order or sequence where permitted, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein.

[0046] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art to which this application pertains. The terms used herein are for the purpose of describing the embodiments of this application only and are not intended to limit this application.

[0047] In the embodiments of the present application, the term "module" or "unit" refers to a computer program or a part of a computer program that has a predetermined function and works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as processing circuits or memories) or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be part of an overall module or unit that includes the function of the module or unit.

[0048] Before further explaining the embodiments of the present application in detail, the nouns and terms involved in the embodiments of the present application are explained. The nouns and terms involved in the embodiments of the present application are subject to the following interpretations.

[0049] 1) Runtime Environment (RTE): Also known as the runtime environment, it refers to the environment that a program (code) relies on during runtime, including the hardware environment (such as the CPU and memory) and the software environment (such as the operating system and runtime libraries). The runtime environment provides the program with the necessary resources and services to ensure that the program can run normally and complete its functions. In the embodiments of the present application, the runtime environment may refer to the software environment.

[0050] 2) Business: This broadly refers to various business activities enabled by computer technology. These activities can span multiple sectors, including but not limited to video platforms, social media, gaming, finance, online education, and telemedicine. In these sectors, computer technology is widely used in data processing, information exchange, transaction payments, and service provision, enabling automated, intelligent, and efficient business operations.

[0051] 3) Business services: These refer to software services implemented in programming languages ​​within a business. For example, in a video platform business, business services include user login, video playback, and video sharing; in a social media business, business services include user likes, user comments, and content sharing.

[0052] 4) Function: In computer programming, a function (also called a subroutine) is a reusable block of code that performs a specific task or operation. It typically receives input values ​​(called parameters), executes a series of statements based on those input values, and then returns a result (called a return value). The main purpose of functions is to divide a program into smaller, more manageable and maintainable parts, while also improving code modularity and readability.

[0053] 5) Function Pointer: A function pointer is a pointer variable that points to a function. A function can be thought of as an executable block of code, and a function pointer is a pointer to this block of code, allowing the program to dynamically call different functions at runtime. Function pointers can be used in function callback scenarios, where one function is passed as a parameter to another, allowing the latter to call the former at the appropriate time.

[0054] 6) JavaScript: A scripting language commonly used to implement interactive functionality on web pages. It's a dynamically typed, interpreted language originally designed for manipulating web page elements and implementing dynamic effects within a web browser. However, over time, JavaScript has evolved into a general-purpose programming language used for developing a variety of applications, including front-end, back-end, and mobile apps.

[0055] 7) Node.js: A JavaScript runtime based on the Chrome V8 engine, used to run JavaScript code on the server. It allows developers to write high-performance, scalable network applications using JavaScript.

[0056] 8) C++ Programming Language: This is a systems-level programming language that extends the C language and adds object-oriented programming and other features. C++ aims to be an efficient, portable, and extensible systems-level programming language.

[0057] 9) Rust Programming Language: This is a systems-level programming language designed to provide a balance of security, concurrency, and performance. It is designed to enable developers to write efficient, reliable, and concurrent software. In the embodiments of this application, the first programming language may be C++, the intermediate programming language may be Rust, and the second programming language may be JavaScript, but is not limited thereto.

[0058] 10) Node.js Application Programming Interface (N-API): This is a set of C / C++ APIs for developing Node.js add-ons. It allows developers to write high-performance native modules in C / C++ to extend the functionality and performance of Node.js. Through N-API, developers can create JavaScript objects, call JavaScript functions, handle JavaScript exceptions, and more. NAPI also provides tools and functions for addressing memory management, thread safety, and error handling.

[0059] The embodiments of the present application provide a cross-programming language calling method, apparatus, electronic device, computer-readable storage medium, and computer program product, which can directly reuse the service architecture of the business service in the first operating environment, realize data interaction between the first operating environment and the second operating environment by transferring the operating environment, and reduce the workload of development work. The following describes an exemplary application of the electronic device provided by the embodiment of the present application. The electronic device provided by the embodiment of the present application can be implemented as various types of terminal devices or as a server.

[0060] See also Figure 1 , Figure 1 This is an architectural diagram of a cross-programming language calling system 100 provided in an embodiment of the present application. A terminal device 400 is connected to a server 200 via a network 300, wherein the network 300 may be a wide area network or a local area network, or a combination of the two.

[0061] In some embodiments, taking the electronic device as an example, the cross-programming language calling method provided in the embodiment of the present application can also be implemented by the server. For example, the server 200 runs a first operating environment of a first programming language, a transit operating environment of a transit programming language, and a second operating environment of a second programming language. The server 200 calls a first business service in the first operating environment of the first programming language to obtain business parameters in the first operating environment; calls a first function in the first operating environment to pass the business parameters in the first operating environment to the transit operating environment of the transit programming language, and passes the business parameters in the transit operating environment to the second operating environment of the second programming language; calls a second business service in the second operating environment to perform business processing according to the business parameters in the second operating environment.

[0062] exist Figure 1 In the example, taking the server 200 as the server (backend server) of the video platform and the terminal device 400 as the client of the video platform, the first business service can be a user login service. The server obtains the user information of the logged-in user (such as user account name, user avatar, user level, etc.) by calling the user login service in the first operating environment as the business parameters in the first operating environment. For example, the user login service can be used to search the database for user information corresponding to the login credentials entered by the user (such as user name, password, or Token, etc.); the second business service can be a user information display service, which is used to transmit user information to the client so that the client can display the user information.

[0063] In some embodiments, the terminal device 400 or the server 200 can implement the cross-programming language calling method provided in the embodiments of the present application by running a computer program. For example, the computer program can be a native program or software module in the operating system; it can be a native application (APP, Application), that is, a program that needs to be installed in the operating system to run; it can also be a small program, that is, a program that can be run only by downloading it into a browser environment; it can also be a small program that can be embedded in any APP, and the small program can be controlled by the user to run or close. In short, the above-mentioned computer program can be an application, module or plug-in in any form.

[0064] In some embodiments, the server 200 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms. The terminal device 400 can be a smart phone, a tablet computer, a laptop computer, a desktop computer, an intelligent voice interaction device, a smart home appliance, a vehicle-mounted terminal, an aircraft, etc., but is not limited to this. The terminal device 400 and the server 200 can be directly or indirectly connected via wired or wireless communication, which is not limited in the embodiments of the present application.

[0065] The embodiments of the present application can be applied to various scenarios, including but not limited to cloud technology, artificial intelligence, smart transportation, assisted driving, etc.

[0066] Take the electronic device provided in the embodiment of the present application as an example, which is a server. Figure 2 , Figure 2 is a structural diagram of the server 200 provided in an embodiment of the present application, Figure 2 The server 200 shown includes: at least one processor 210, a memory 250 and at least one network interface 220. The various components in the server 200 are coupled together via a bus system 240. It is understood that the bus system 240 is used to achieve connection and communication between these components. In addition to the data bus, the bus system 240 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, the bus system 240 is not described in detail. Figure 2 Various buses are labeled as bus system 240 .

[0067] The processor 210 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc., where the general-purpose processor can be a microprocessor or any conventional processor, etc.

[0068] The memory 250 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid-state memory, hard drives, optical drives, etc. The memory 250 may optionally include one or more storage devices that are physically remote from the processor 210.

[0069] The memory 250 includes volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. The non-volatile memory may be a read-only memory (ROM), and the volatile memory may be a random access memory (RAM). The memory 250 described in the embodiments of the present application is intended to include any suitable type of memory.

[0070] In some embodiments, the memory 250 can store data to support various operations, examples of which include programs, modules, and data structures, or a subset or superset thereof, as exemplified below.

[0071] Operating system 251, including system programs for processing various basic system services and performing hardware-related tasks, such as the framework layer, core library layer, and driver layer, which are used to implement various basic services and process hardware-based tasks;

[0072] A network communication module 252 for reaching other computing devices via one or more (wired or wireless) network interfaces 220 , exemplary network interfaces 220 including Bluetooth, Wireless LAN (WiFi), and Universal Serial Bus (USB);

[0073] In some embodiments, the cross-programming language calling device provided in the embodiments of the present application can be implemented in software. Figure 2 A cross-programming language calling device 255 stored in memory 250 is shown. This device can be software in the form of a program or plug-in, and includes the following software modules: an acquisition module 2551, a delivery module 2552, and a business processing module 2553. These modules are logical and can be arbitrarily combined or further divided according to the functions they implement. The functions of each module will be described below.

[0074] The cross-programming language calling method provided by the embodiment of the present application will be explained in combination with the exemplary application and implementation of the electronic device provided by the embodiment of the present application.

[0075] See also Figure 3 , Figure 3 This is a flow chart of a cross-programming language calling method provided by an embodiment of the present application, which will be combined with Figure 3 The steps shown are explained.

[0076] In step 101, a first business service is called in a first operating environment of a first programming language to obtain business parameters in the first operating environment.

[0077] Here, a first business service is called in a first operating environment of a first programming language. The first business service is written in the first programming language. The embodiment of the present application does not limit the type of the first business service; for example, it may be a user login service. The result of calling the first business service is referred to as a business parameter, and the obtained business parameter is located in the first operating environment.

[0078] The embodiment of the present application does not limit the type of business parameters. For example, it can be the execution result of a specific data processing task, where the data processing task is such as a data acquisition task, a data calculation task, etc.

[0079] In step 102, a first function is called in the first operating environment to pass the business parameters in the first operating environment to the transit operating environment of the transit programming language, and the business parameters in the transit operating environment are passed to the second operating environment of the second programming language; wherein the first function is converted from the transit function in the transit operating environment, and the transit function is converted from the second function in the second operating environment; the second function is used to call back the business parameters.

[0080] The purpose of the embodiment of the present application is to pass business parameters in a first operating environment to a second operating environment. However, the first operating environment and the second operating environment use different programming languages, and the variable types in different programming languages ​​have different memory models. Therefore, it is not possible to directly call a function defined in another programming language across programming languages.

[0081] In view of this, an embodiment of the present application creates a second function for callback business parameters in the second operating environment (i.e., the second function is a callback function), wherein the second function is applicable to the memory model of the second programming language. Then, the second function in the second operating environment is converted into a transit function in the transit operating environment, wherein the transit function is applicable to the memory model of the transit programming language. Then, the transit function in the transit operating environment is converted into a first function in the first operating environment, wherein the first function is applicable to the memory model of the first programming language. In this way, the first function can be regarded as a second function that can be called by the first programming language. In some embodiments, the conversion of functions in different operating environments can be achieved through function pointers.

[0082] After the above conversion, the first function can be called in the first operating environment. The first function is used to pass the business parameters in the first operating environment to the transit operating environment of the transit programming language, and pass the business parameters in the transit operating environment to the second operating environment of the second programming language.

[0083] It is worth noting that the transit programming language is superior to the first programming language in terms of reliability, where reliability can be reflected in aspects such as memory safety and concurrency. In this way, it is possible to avoid memory safety issues, concurrency issues, and other problems caused by directly converting the second function in the second operating environment into the first function in the first operating environment.

[0084] In some embodiments, the first programming language is a lower-level programming language than the second programming language; the intermediate programming language is an even lower-level programming language than the second programming language. For example, the first programming language is C++, and the intermediate programming language is Rust, both of which are system-level programming languages; the second programming language is JavaScript, a scripting language, where system-level programming languages ​​are lower-level programming languages ​​than scripting languages. This approach meets the requirements of some real-world business scenarios.

[0085] In the embodiment of the present application, there may be various reasons for handing over the work of determining the service parameters to the first programming language. The following examples are provided to illustrate:

[0086] 1) Performance optimization.

[0087] For example, a large number of data processing tasks need to be performed in the business, and these tasks are less efficient when executed using the second programming language. Therefore, these tasks can be completed by the first programming language with higher execution efficiency (stronger performance), thereby improving the overall performance of the business.

[0088] 2) Utilize a library in the first programming language.

[0089] For example, a business may need to access a specific hardware device or perform complex image processing, and these functions are already supported by a ready-made program library of the first programming language. Therefore, the program library of the first programming language may be directly used to implement these functions.

[0090] 3) System-level operations.

[0091] The first programming language is a lower-level programming language than the second programming language. For example, the first programming language is a system-level programming language, and the business requires low-level system operations, such as low-level access to the file system, direct operation of the network socket, or interaction with the operating system kernel. Therefore, it is necessary to write system-level code in the first programming language to implement the low-level system operations.

[0092] Of course, the above is merely an example and does not constitute a limitation on the embodiments of the present application. The embodiments of the present application can be applied to any application scenario involving data interaction between a first programming language and a second programming language.

[0093] In step 103, the second business service is called in the second operating environment to perform business processing according to the business parameters in the second operating environment.

[0094] After the business parameters in the first operating environment are transferred to the second operating environment through the transit operating environment, the second business service can be called in the second operating environment. The second business service is used to perform business processing according to the business parameters in the second operating environment. There is no limitation on the business processing method. For example, the business parameters can be sent to a specific object; the business parameters can be further processed; or whether to execute a preset operation can be determined based on the business parameters.

[0095] In some embodiments, the first operating environment, the transit operating environment, and the second operating environment all run on the server side; the above-mentioned calling of the second business service in the second operating environment to perform business processing according to the business parameters in the second operating environment can be achieved in the following manner: calling the second business service in the second operating environment to pass the business parameters in the second operating environment to the client using the second programming language; wherein the client is used to display the business parameters in the second operating environment.

[0096] The embodiment of the present application can be applied to a client / server architecture, where the client uses a second programming language, and a second operating environment of the second programming language is provided on the server, so that the server application can be used according to the second operating environment of the second programming language; the first operating environment and the transit operating environment are both located on the server. In this case, steps 101 to 102 are all completed on the server, and considering that the business parameters located on the server ultimately need to be presented on the client, after the business parameters are passed to the second operating environment, the second business service is called in the second operating environment, and the second business service is used to pass the business parameters in the second operating environment to the client using the second programming language, so that the client can display the received business parameters. It is worth noting that the second business service and the client both use the second programming language, so data interaction can be achieved based on the second programming language.

[0097] For ease of understanding, taking the video platform business as an example, the client can refer to the client of the video platform business, for users to watch videos; the server can refer to the server of the video platform business, which is used to store user information and video data. The client will first receive the login credentials entered by the user and send the login credentials to the server. There is no limitation on the form of the login credentials, for example, it can be a username + password, or a token; there is no limitation on the way the user enters the login credentials, for example, it can be a code scan input, or it can be manual input. Then, the server calls the first business service in the first operating environment. The first business service is used to query the user information corresponding to the login credentials in the database of the video platform. The user information may include user account, user avatar, user level, etc. In this example, the user information is the business parameter. The server calls the first function in the first operating environment to pass the user information in the first operating environment to the transit operating environment of the transit programming language, and passes the user information in the transit operating environment to the second operating environment of the second programming language. The server calls the second business service in the second operating environment, and the second business service is used to transmit the user information in the second operating environment to the client. In this way, the client can display the user information in the interface of the video platform and complete the entire user login process.

[0098] Through the above method, business parameters can be passed to the client, and data interaction between the client and the server can be achieved accurately and efficiently, which is suitable for the client / server architecture.

[0099] In some embodiments, the first business service and the second business service mentioned above can also be implemented in the form of functions.

[0100] like Figure 3 As shown, the embodiment of the present application calls the first business service in the first operating environment of the first programming language, obtains the business parameters in the first operating environment, and then calls the first function in the first operating environment. Since the first function is converted from the transit function in the transit operating environment, and the transit function is converted from the second function for calling back the business parameters in the second operating environment, it is possible to overcome the differences in memory models between different programming languages. Calling the first function in the first operating environment is equivalent to calling the second function in the second operating environment. In this way, the transit operating environment can be used as a transit to realize data interaction between the first operating environment and the second operating environment, that is, the business parameters in the first operating environment can be passed to the second operating environment through the transit operating environment. In summary, the present application can realize cross-programming language calls, and at the same time, there is no need to rewrite the service architecture of the business service in the first operating environment, which can effectively reduce the workload of development work and enable developers (such as front-end developers) to better participate in business development.

[0101] In some embodiments, see Figure 4 , Figure 4 This is a flow chart of a cross-programming language calling method provided by an embodiment of the present application. Figure 3 Step 102 shown can be updated to step 201, in which the first function is called in the first operating environment to pass the business parameters received by the first function to the transit function in the transit operating environment through the transit function pointer pointing to the transit function in the first function, and the business parameters received by the transit function are passed to the second function in the second operating environment through the second function pointer pointing to the second function in the transit function.

[0102] Here, the input parameters of the first function include the call result of the first business service, that is, the business parameters in the first operating environment. At the same time, the first function includes a transfer function pointer pointing to the transfer function. In addition, the transfer function includes a second function pointer pointing to the second function.

[0103] Based on this, when the first function is called in the first operating environment, the following processing will be performed: the business parameters received by the first function are passed to the transfer function in the transfer operating environment through the transfer function pointer pointing to the transfer function in the first function, and the business parameters received by the transfer function are passed to the second function in the second operating environment through the second function pointer pointing to the second function in the transfer function. As an example, the embodiment of the present application provides the following example: Figure 8 The function relationship diagram shown in the figure is as follows. In this way, parameter transfer between different operating environments is achieved through function pointers, which improves the accuracy and reliability of parameter transfer.

[0104] In some embodiments, before the first operating environment calls the first function, the cross-programming language calling method also includes: performing the following processing in the transit operating environment: creating a closure including a transit function pointer pointing to the transit function as the first function; performing pointer creation processing on the first function to obtain an original pointer pointing to the first function; converting the original pointer pointing to the first function into a first function pointer supporting the first programming language; the above-mentioned calling of the first function in the first operating environment can be implemented in this way, including: calling the first function in the first operating environment through the first function pointer pointing to the first function.

[0105] Here, we provide an example method for creating a first function. First, a closure containing a pointer to a transfer function is created in the transfer runtime environment as the first function. It's worth noting that a closure is a special type of function that encapsulates data and behavior, allowing them to be shared and passed between functions. Closures can also be used as callback functions because they capture the context of their environment and can be executed when needed.

[0106] Then, a pointer creation process is performed on the first function to obtain an original pointer pointing to the first function. The original pointer pointing to the first function can be called by the transit programming language, but cannot be called by the first programming language. Therefore, the original pointer pointing to the first function is converted into a first function pointer that supports the first programming language. In this way, the first function pointer pointing to the first function can be called in the first operating environment through the first programming language, and then the first function is called. It is worth noting that since the first function is created in the transit operating environment, the relevant operations of the first function can be executed in the transit operating environment, and the first function can be called in the first operating environment to trigger the transit operating environment to execute the relevant operations of the first function.

[0107] Through the above method, the conversion from the transfer function to the first function can be achieved, so that the created first function contains a transfer function pointer pointing to the transfer function and can be effectively called in the first operating environment.

[0108] In some embodiments, the above-mentioned pointer creation processing for the first function can be implemented in the following manner to obtain the original pointer pointing to the first function: heap allocation processing is performed on the first function; and an original pointer pointing to the first function that has been heap allocated is created.

[0109] Here, the first function can be heap-allocated, meaning it is allocated to the heap as heap data. A raw pointer is then created to point to the heap-allocated first function (i.e., the first function on the heap). The raw pointer owns and manages the ownership of the heap data and manages the lifecycle of the heap data, including automatic resource release and memory leak prevention. For example, if the intermediate programming language is Rust, the raw pointer refers to a Box smart pointer.

[0110] The raw pointer created in this way allows memory to be allocated on the heap and its lifecycle to be managed, including automatic resource release and the avoidance of memory leaks. This solves memory management issues and effectively prevents call errors. Furthermore, it addresses concurrency safety (reducing data contention) and data ownership, providing a safer, more flexible, and more efficient calling method.

[0111] In some embodiments, the second operating environment is written in the first programming language; before the first operating environment calls the first function, the cross-programming language calling method also includes: performing the following processing in the transit operating environment: calling the pointer acquisition function provided by the interface protocol between the first programming language and the second programming language to obtain a second function pointer pointing to the second function; encapsulating the second function pointer pointing to the second function to obtain a transit function in the transit operating environment.

[0112] Here, the second operating environment is written in the first programming language. Based on this, the pointer acquisition function provided by the interface protocol between the first programming language and the second programming language can be called in the transit operating environment to obtain a second function pointer pointing to the second function, wherein the pointer acquisition function is a function provided by the interface protocol and written in the first programming language, and is used to obtain a second function pointer pointing to the second function; in the transit operating environment, the interface protocol can be called through the external function interface (Foreign Function Interface, FFI) of the transit programming language. For example, the bottom layer of the Node.js operating environment is written in the C++ programming language, then the pointer acquisition function provided by the interface protocol N-API between the C++ programming language and the JavaScript programming language can be called in the Rust operating environment to obtain a second function pointer pointing to the second function, wherein the pointer acquisition function is such as Context::get_function, Context::get_global, sys::napi_get_named_property, etc., which is not limited to this.

[0113] Then, the second function pointer pointing to the second function is encapsulated in the transit running environment to obtain the transit function in the transit running environment, thereby completing the creation of the transit function.

[0114] In the above manner, the conversion from the second function to the transit function is achieved through the interface protocol between the first programming language and the second programming language, so that the created transit function includes a second function pointer pointing to the second function.

[0115] like Figure 4 As shown, the first function created in the embodiment of the present application includes a transfer function pointer pointing to the transfer function, and the created transfer function includes a second function pointer pointing to the second function. In this way, parameter transfer between functions in different operating environments is realized through function pointers, which can improve the accuracy and orderliness of parameter transfer.

[0116] In some embodiments, see Figure 5 , Figure 5 This is a flow chart of a cross-programming language calling method provided by an embodiment of the present application. Figure 4 The illustrated step 201 can be implemented through steps 301 to 302 , which will be described in conjunction with each step.

[0117] In step 301, a data type conversion function in a first function is called in a first operating environment to identify a first data type to which a business parameter received by the first function belongs, and data type conversion is performed on the business parameter belonging to the first data type to obtain a business parameter belonging to a second data type; wherein the first data type corresponds to a first programming language, and the second data type corresponds to a second programming language.

[0118] Here, the input parameters of the first function include business parameters in the first operating environment. In addition to the transfer function pointer pointing to the transfer function, the first function also includes a data type conversion function, wherein the data type conversion function includes a conversion rule for converting a first data type of a first programming language into a second data type of a second programming language. It is worth noting that the above-mentioned first data type and second data type are essentially the embodiment of the same data type in different programming languages.

[0119] Taking the first programming language as C++ programming language and the second programming language as JavaScript programming language as an example, the following examples are given:

[0120] 1) The first data type is an integer type (such as int, short, long, long long) or a floating-point type (such as float, double, long double) in the C++ programming language, and the second data type is a number (such as Number) in the JavaScript programming language.

[0121] 2) The first data type is a character type (such as char) in the C++ programming language, and the second data type is a string type (such as String) in the JavaScript programming language.

[0122] 3) The first data type is a Boolean type (such as bool) in the C++ programming language, and the second data type is a Boolean value (such as Boolean) in the JavaScript programming language.

[0123] Based on the above premise, the data type conversion function in the first function can be called in the first operating environment. The data type conversion function is used to identify the first data type to which the business parameters received by the first function belong, and perform data type conversion processing on the business parameters belonging to the first data type to obtain business parameters belonging to the second data type.

[0124] It is worth noting that the data type conversion process only converts the data type of the business parameter, and the meaning represented by the business parameter itself remains unchanged during the data type conversion process.

[0125] In some embodiments, when data type conversion processing fails on a service parameter belonging to the first data type, a first error prompt is output according to the service parameter belonging to the first data type.

[0126] Here, during the execution of the data type conversion function, when the data type conversion processing of the business parameter belonging to the first data type fails, a first error prompt is output based on the business parameter belonging to the first data type, that is, the reason for the failure is prompted, for example, "Conversion of xx data from data type A to data type B failed". This makes it easier for developers to quickly locate the root cause of the problem and solve it, reducing the adverse impact on the business.

[0127] In some embodiments, before the first operating environment calls the first function, the cross-programming language calling method also includes: compiling the data type conversion function in the first function; when the compilation of the data type conversion function in the first function fails, outputting a second error prompt according to the data type conversion function in the first function.

[0128] Here, the data type conversion function in the first function can be compiled in advance. When the compilation of the data type conversion function in the first function fails, it proves that the data type conversion function is at risk of being unable to execute. Therefore, a second error prompt is output according to the data type conversion function in the first function. The second error prompt can include the code that failed to compile in the data type conversion function. In this way, it is convenient for developers to modify the code that failed to compile and ensure the availability of the data type conversion function.

[0129] It is worth noting that the compilation phase mainly converts source code (for example, in the form of .java files) into executable code. This process includes syntax checking, type checking, generating intermediate code, and finally generating executable code (for example, Java bytecode, usually in the form of .class files); while the runtime refers to the actual execution stage of the code, that is, executing the compiled executable code. During the runtime, the executable code is loaded into the memory and interpreted and executed by the computer or virtual machine (such as the Java virtual machine).

[0130] In step 302, the business parameters belonging to the second data type are passed to the transit function in the transit operating environment through the transit function pointer pointing to the transit function in the first function, and the business parameters belonging to the second data type are passed to the second function in the second operating environment through the second function pointer pointing to the second function in the transit function.

[0131] After the data type conversion process is completed, the business parameters of the second data type are passed to the transfer function in the transfer operating environment via the transfer function pointer in the first function pointing to the transfer function, and the business parameters of the second data type are passed to the second function in the second operating environment via the second function pointer in the transfer function pointing to the second function. Because the second data type is defined in the second programming language, the business parameters of the second data type can be used in the second operating environment via the second programming language, for example, to perform business processing based on the business parameters of the second data type.

[0132] In some embodiments, after performing data type conversion processing on the business parameters belonging to the first data type to obtain the business parameters belonging to the second data type, the cross-programming language calling method also includes: creating a dynamic array, and storing the business parameters belonging to the second data type in the dynamic array; the above-mentioned passing of the business parameters belonging to the second data type to the transit function in the transit operation environment through the transit function pointer pointing to the transit function in the first function can be achieved in the following way: passing the dynamic array as a parameter to the transit function in the transit operation environment through the transit function pointer pointing to the transit function in the first function.

[0133] Here, after obtaining the business parameters of the second data type through data type conversion, a dynamic array can be created and the business parameters of the second data type can be stored in the dynamic array. The dynamic array is an efficient and flexible data structure. Taking the Rust programming language as an example, the dynamic array can be Vec <t>.

[0134] Dynamic arrays have at least the following advantages:

[0135] 1) Dynamic size: Unlike fixed-size arrays, the size of a dynamic array can be changed dynamically at runtime, which makes it very suitable for storing data when it is not known how many elements will be needed in the end. That is, no matter how many business parameters there are, dynamic arrays can be used for storage.

[0136] 2) Efficient storage: Dynamic arrays are stored contiguously in memory, which means they can take advantage of the CPU's cache to efficiently access elements. In addition, since they are dynamically allocated, they are not limited by the stack size.

[0137] 3) Performance Optimization: Dynamic arrays can provide better performance than fixed-size arrays in some cases. For example, when elements need to be added or deleted frequently, using a dynamic array is more efficient than using a fixed-size array.

[0138] If the dynamic array already stores business parameters of the second data type, the dynamic array is passed as a parameter to the transfer function in the transfer execution environment via a transfer function pointer in the first function that points to the transfer function. Of course, the dynamic array can also be subsequently passed as a parameter to a second function in the second execution environment via a second function pointer in the transfer function that points to the second function.

[0139] The above method uses dynamic arrays to transfer business parameters. Since dynamic arrays have the characteristics of dynamic size, efficient storage, and performance optimization, they can improve the efficiency and stability of parameter transfer and support any number of business parameters, making them suitable for a variety of businesses.

[0140] like Figure 5 As shown, the embodiment of the present application takes into account the differences in data types defined in different operating environments, and therefore converts business parameters belonging to the first data type into business parameters belonging to the second data type through data type conversion processing, so that the business parameters belonging to the second data type can be used in the second operating environment through the second programming language, thereby ensuring the effectiveness of business processing.

[0141] In some embodiments, see Figure 6 , Figure 6 This is a flow chart of a cross-programming language calling method provided by an embodiment of the present application. Figure 3 Step 101 shown can be updated to step 401. In step 401, the interface protocol between the first programming language and the second programming language is called in the second operating environment to access the file path of the first business service in the first operating environment, and the first business service is called through the file path of the first business service to obtain the business parameters in the first operating environment.

[0142] Here, the interface protocol between the first and second programming languages ​​can be called in the second operating environment through the external function interface of the second programming language, thereby accessing the file path of the first business service in the first operating environment. Then, the first business service is called through the file path of the first business service to obtain the business parameters in the first operating environment. There is no restriction on the execution timing of step 401; for example, it can be called periodically or when a specific business operation is detected, such as when a user enters login credentials.

[0143] It's worth noting that the file path of the first business service is obtained by compiling the code (including the first business service) written in the first programming language in the first operating environment into a dynamic link library (DLL). A dynamic link library embodies the concept of a shared function library, providing a method for a process to call functions that are not part of its executable code. When the program runs, the dynamic linker loads the DLL into the process's address space and resolves the functions in the DLL into callable addresses. This allows the program to dynamically link to the functions in the DLL at runtime and use them to perform specific tasks.

[0144] It's worth noting that, although the first business service is called by the second runtime environment in step 401, the first business service is still executed in the first runtime environment, and the business parameters obtained are those of the first runtime environment. In other words, the second runtime environment is effectively calling the first business service on behalf of the first runtime environment.

[0145] like Figure 6 As shown, the embodiment of the present application can support the use of the first business service in the first operating environment in the second operating environment, has strong flexibility, and can effectively reduce the difficulty of developing business codes when the first programming language is more low-level than the second programming language.

[0146] In some embodiments, see Figure 7 , Figure 7 This is a flow chart of a cross-programming language calling method provided by an embodiment of the present application. Figure 3 Step 101 shown may be updated to step 501. In step 501, a business operation is detected in the first operating environment, and a first business service corresponding to the detected business operation is called to obtain business parameters in the first operating environment.

[0147] Here, the calling logic can also be preset in the first operating environment using the first programming language, that is, the first business service corresponds to a specific business operation (such as the operation of a user entering login credentials). When a business operation is detected in the first operating environment, the first business service corresponding to the detected business operation is called to obtain the business parameters in the first operating environment. Step 501 presets the calling logic of the first business service in the first operating environment to achieve automatic calling in specific circumstances, which is suitable for scenarios where the calling logic is fixed.

[0148] In some embodiments, there are multiple first business services, and different first business services correspond to different business operations.

[0149] like Figure 6 and Figure 7 As shown, the embodiment of the present application provides two methods for calling the first business service: one is to call it in the second operating environment through the interface protocol between the first programming language and the second programming language; the other is to automatically call it in the second operating environment. Either method can be selected based on actual development needs and the specific circumstances of the business.

[0150] Below, an exemplary application of the embodiment of the present application in an actual application scenario will be described. For ease of understanding, an example is given in which the first programming language is C++ programming language, the intermediate programming language is Rust programming language, and the second programming language is JavaScript programming language.

[0151] In the field of front-end (client-side) development, JavaScript is the only runtime language supported by browsers and a key technology in web development. It can be used to implement dynamic web page effects, user interaction, and data processing. With the widespread adoption of JavaScript, Node.js has emerged. Node.js provides an environment for running JavaScript on the server side, allowing front-end developers to use Node.js to develop server-side applications.

[0152] In the server-side field, basic infrastructure usually uses business services written in low-level programming languages ​​such as C++. However, Node.js currently lacks a related business service ecosystem. Rewriting these business services with Node.js will undoubtedly bring a huge workload, and Node.js cannot compare with these low-level programming languages ​​in terms of operating performance.

[0153] Therefore, after calling the business service (corresponding to the first business service above) on the C++ side (i.e., the operating environment of the C++ programming language, the same below) to obtain the business parameters, it is necessary to pass the business parameters to the JavaScript side through the callback function (corresponding to the second function above) on the JavaScript side (i.e., the operating environment of the JavaScript programming language, such as Node.js, the same below).

[0154] For example, many internet platforms currently use C++ to develop user login services. However, developers of front-end or desktop applications typically use front-end development technologies, often using Node.js, to develop server-side interfaces. This requires defining a callback function on the JavaScript side and passing it to the C++ side. When the C++ side calls the user login service and login is successful, the C++ side calls this callback function to notify the JavaScript side of service parameters, such as user information, so that the JavaScript side can display the service parameters on the front-end.

[0155] The embodiment of the present application solves the problem of how to pass the callback function on the JavaScript side to the C++ side for calling.

[0156] Since the variable types in different programming languages ​​are different in memory models, it is impossible to directly call the function defined in another programming language across programming languages, so it is necessary to convert the memory model of the function defined in one programming language to the memory model of the function in another programming language. Since the bottom layer of Node.js is written in C++ programming language, it is possible to use C++ programming language to write native modules based on N-API interface protocol, and it can be called in Node.js. However, the embodiment of the present application chooses to use Rust programming language as a transit, uses Rust programming language to write native modules to Node.js call, converts the incoming JavaScript function (i.e., the callback function on the JavaScript side) into Rust function (corresponding to the transit function above) by Rust programming language, and then converts the Rust function into C++ function and passes it to the C++ side call.

[0157] Compared to using only the N-API interface protocol, the benefits of using Rust as a transit layer include at least:

[0158] 1) Memory Safety: The Rust programming language is a memory-safe programming language that uses an ownership and borrowing system to catch memory errors such as null pointer references and buffer overflows at compile time. This reduces potential memory safety issues and improves the reliability of the code.

[0159] 2) Concurrency: The Rust programming language has built-in concurrency support, and through the ownership and borrowing system, thread safety can be checked at compile time. This makes it easier and safer to write concurrent code through the Rust programming language.

[0160] 3) Performance: The Rust programming language offers execution efficiency comparable to that of the C++ programming language. Its zero-cost abstractions and zero-runtime overhead design make it possible to write high-performance extensions while maintaining code readability and maintainability.

[0161] 4) Ecosystem: The Rust programming language has an active developer community and a rich ecosystem. Developers can leverage various libraries and tools in the Rust ecosystem to improve development efficiency and code quality, effectively reducing development difficulty for developers.

[0162] 5) Cross-platform support: The Rust programming language has good cross-platform support and can run on multiple operating systems. This makes it easy to build and deploy extensions to different platforms.

[0163] As an example, the present application provides the following embodiments: Figure 9 The flowchart of the cross-programming language calling method shown in FIG.

[0164] Will combine Figure 9 , explained in step-by-step form.

[0165] 1) Define JavaScript functions on the JavaScript side.

[0166] Here, a JavaScript function is defined on the JavaScript side. The JavaScript function is a callback function. The JavaScript function can be set to receive parameters of any number and data type, for example, it can be set to receive three parameters.

[0167] 2) Define C++ functions on the C++ side.

[0168] Here, a C++ function func is defined on the C++ side. Assuming that the C++ side is used to implement the user login service, after obtaining the user information through some previously defined C++ logic, the C++ function is called on the C++ side to send the user information to the JavaScript side. Among them, the variable type of func is a function pointer type, that is, func is called through the function pointer.

[0169] After defining the basic logic above, the remaining question is how to connect the JavaScript side with the C++ side, that is, to convert the callback defined on the JavaScript side into the func required by the C++ side.

[0170] 3) Compile the C++ code into a dynamic link library.

[0171] Considering that different programming languages ​​cannot communicate directly, the C++ code is compiled into a dynamic link library (i.e., a binary file). In this way, the Rust programming language can be used to call this dynamic link library to obtain user information on the C++ side.

[0172] 4) Convert the JavaScript function to a Rust function on the Rust side.

[0173] Here, a Rust function JsFunction is defined on the Rust side to represent the JavaScript function on the Rust side. JsFunction is implemented by interacting with the N-API on the C++ side through the FFI on the Rust side. On the Rust side, JsFunction is a smart pointer that encapsulates the N-API function object. For example, the raw pointer to the JavaScript function (corresponding to the second function pointer above) can be obtained through the Context::get_function function, Context::get_global function, or sys::napi_get_named_property function provided by N-API, and the raw pointer to the JavaScript function is encapsulated as JsFunction. JsFunction also includes a field RawJsValue, which is a raw pointer to user information. This pointer is safely encapsulated on the Rust side to prevent illegal access.

[0174] 5) Convert the Rust function to a C++ function on the Rust side.

[0175] Here, a closure (lambda) is created on the Rust side, and then converted to a C function pointer (corresponding to the first function pointer above) so that it can be called from the C++ side. In other words, the closure can be treated as a C++ function (func). The creation process is shown below.

[0176] The closure receives several *mut c_void parameters, which are pointers to user information on the C++ side. In the closure, these *mut c_void parameters are placed in an array arg_arr and a dynamic array Vec is created. <jsunknown>,Thing <jsunknown>The elements in are user information on the JavaScript side obtained by performing data type conversion on the parameters in arg_arr through the get_js_function_call_value function (corresponding to the data type conversion function above).

[0177] Then, the closure calls *js_function_ptr (corresponding to the transfer function pointer above) and converts Vec <jsunknown>Passed as a parameter to *js_function_ptr to pass the user information on the JavaScript side to JsFunction through *js_function_ptr.

[0178] Next, the closure is encapsulated as a Closure3 object, and the Closure3 object is converted to a Box (i.e., heap allocation is performed) to obtain the original pointer corresponding to the Box. In this way, memory leaks are effectively avoided based on the Box.

[0179] Finally, use std::mem::transmute to convert the original pointer corresponding to the Box into a C function pointer so that it can be called by the C++ side.

[0180] Through the above steps 1) to 5), after the C++ side completes the business service call, it can call the C++ function to pass the business parameters to the JavaScript side through the Rust side so that the JavaScript side can further apply it.

[0181] It is worth noting that, considering the difference between the data type defined on the C++ side (corresponding to the first data type above) and the data type defined on the JavaScript side (corresponding to the second data type above), the get_js_function_call_value function can be used to convert user information belonging to the C++ data type into user information belonging to the JavaScript data type, so that the correct strings, numbers and other variables can be obtained in the callback function.

[0182] As an example, the embodiment of the present application is Figure 9 Provided on the basis of Figure 10 A flow chart of the cross-programming language calling method shown in the figure will be combined with Figure 10 Explain the logic of the get_js_function_call_value function.

[0183] First, in the get_js_function_call_value function, the func_arg_type.get_type().unwrap() function is used to retrieve the func_arg_type . This represents the C++ data type of the user information. Then, a match statement is used to perform different processing based on the func_arg_type . Specifically, the C++ data type represented by func_arg_type is converted to a JavaScript data type. If the func_arg_type type is ValueType::Number , the func_arg_type is forcibly converted to a number, which is then converted to the DataType enumeration type. Finally, a match statement is used to perform different processing based on the DataType enumeration type.

[0184] For example, if DataType is DataType::I32, then func_arg_ptr (representing user information belonging to the DataType::I32 data type) will be converted to I32, and then the env.create_int32 method will be used to create a JsUnknown. The JsUnknown is the converted user information belonging to the I32 data type.

[0185] If DataType is DataType::Boolean, then func_arg_ptr is checked to see if it is 0. If so, a JsUnknown representing false is created; otherwise, a JsUnknown representing true is created. This JsUnknown is the user information of the Boolean data type obtained by the conversion.

[0186] If DataType is DataType::String, func_arg_ptr is converted to *mut c_char, and a CString is created using the CString::from_raw method. The CString is then converted to a String, and the env.create_string method is used to create a JsUnknown. This JsUnknown is the user information of the String data type obtained from the conversion.

[0187] Through the embodiments of the present application, at least the following technical effects can be achieved:

[0188] 1) Directly reuse the basic service architecture of underlying programming languages ​​such as C++ / C without rewriting old code, enabling rapid business development and deployment.

[0189] 2) Effectively reduce the difficulty for front-end developers to develop server-side applications, facilitate improving development efficiency, and enable front-end developers to better participate in the development of server-side applications.

[0190] 3) It has a wide range of applications and can be applied to various business scenarios that adopt client / server architecture and can support a variety of business services.

[0191] 4) By combining function pointers, FFI, and N-API, and using the Rust side as a transit layer, the efficiency, accuracy, and security of business parameter transmission can be improved, making business operations more stable and secure.

[0192] 5) Through data type conversion processing, the JavaScript side can obtain variables of the correct data type, which facilitates further application on the JavaScript side, such as displaying variables (such as user information) on the front-end interface.

[0193] The following continues to describe the exemplary structure of the cross-programming language calling device 255 provided in the embodiment of the present application implemented as a software module. In some embodiments, such as Figure 2 As shown, the software modules stored in the cross-programming language calling device 255 of the memory 250 may include: an acquisition module 2551, used to call the first business service in the first operating environment of the first programming language to obtain the business parameters in the first operating environment; a transfer module 2552, used to call the first function in the first operating environment to transfer the business parameters in the first operating environment to the transit operating environment of the transit programming language, and transfer the business parameters in the transit operating environment to the second operating environment of the second programming language; wherein the first function is converted from the transit function in the transit operating environment, and the transit function is converted from the second function in the second operating environment; the second function is used to call back the business parameters; a business processing module 2553, used to call the second business service in the second operating environment to perform business processing according to the business parameters in the second operating environment.

[0194] In some embodiments, the input parameters of the first function include business parameters in the first operating environment; the first function includes a transit function pointer pointing to the transit function; the transit function includes a second function pointer pointing to the second function; the transfer module 2552 is also used to: pass the business parameters received by the first function to the transit function in the transit operating environment through the transit function pointer pointing to the transit function in the first function; pass the business parameters received by the transit function to the second function in the second operating environment through the second function pointer pointing to the second function in the transit function.

[0195] In some embodiments, the first function includes a data type conversion function; the transfer module 2552 is also used to: perform the following processing through the data type conversion function in the first function: identify the first data type to which the business parameters received by the first function belong; perform data type conversion processing on the business parameters belonging to the first data type to obtain business parameters belonging to the second data type; wherein the first data type corresponds to the first programming language, and the second data type corresponds to the second programming language; and pass the business parameters belonging to the second data type to the transfer function in the transfer operating environment through the transfer function pointer pointing to the transfer function in the first function.

[0196] In some embodiments, the transfer module 2552 is also used to: create a dynamic array and store business parameters belonging to the second data type in the dynamic array; pass the dynamic array as a parameter to the transfer function in the transfer operating environment through the transfer function pointer pointing to the transfer function in the first function.

[0197] In some embodiments, the cross-programming language calling device 255 includes a first prompt module for outputting a first error prompt according to the business parameter belonging to the first data type when data type conversion processing fails on the business parameter belonging to the first data type.

[0198] In some embodiments, the cross-programming language calling device 255 includes a second prompt module, which is used to: compile the data type conversion function in the first function; when the compilation of the data type conversion function in the first function fails, output a second error prompt according to the data type conversion function in the first function.

[0199] In some embodiments, the cross-programming language calling device 255 includes a first function creation module, which is used to: perform the following processing in the transit operating environment: create a closure including a transit function pointer pointing to the transit function as the first function; perform pointer creation processing on the first function to obtain an original pointer pointing to the first function; convert the original pointer pointing to the first function into a first function pointer supporting the first programming language; the transfer module 2552 is also used to: call the first function in the first operating environment through the first function pointer pointing to the first function.

[0200] In some embodiments, the first function creation module is further used to: perform heap allocation processing on the first function; and create an original pointer pointing to the first function that has been heap allocated.

[0201] In some embodiments, the second operating environment is written in the first programming language; the cross-programming language calling device 255 includes a transit function creation module, which is used to: perform the following processing in the transit operating environment: call the pointer acquisition function provided by the interface protocol between the first programming language and the second programming language to obtain a second function pointer pointing to the second function; encapsulate the second function pointer pointing to the second function to obtain a transit function in the transit operating environment.

[0202] In some embodiments, the second operating environment is written in the first programming language; the acquisition module 2551 is also used to: perform the following processing in the second operating environment: call the interface protocol between the first programming language and the second programming language to access the file path of the first business service in the first operating environment; call the first business service through the file path of the first business service to obtain the business parameters in the first operating environment.

[0203] In some embodiments, the acquisition module 2551 is further used to: perform the following processing in the first operating environment: detect a business operation; call a first business service corresponding to the detected business operation, and obtain business parameters in the first operating environment.

[0204] In some embodiments, the first operating environment, the transit operating environment, and the second operating environment all run on the server side; the business processing module 2553 is also used to: call the second business service in the second operating environment to pass the business parameters in the second operating environment to the client using the second programming language; wherein the client is used to display the business parameters in the second operating environment.

[0205] The present invention provides a computer program product or computer program, which includes executable instructions stored in a computer-readable storage medium. A processor of an electronic device reads the executable instructions from the computer-readable storage medium and executes the executable instructions, causing the electronic device to perform the cross-programming language calling method described in the present invention.

[0206] An embodiment of the present application provides a computer-readable storage medium storing executable instructions, wherein the executable instructions are stored. When the executable instructions are executed by a processor, the processor will execute the cross-programming language calling method provided by the embodiment of the present application.

[0207] In some embodiments, the computer-readable storage medium may be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, flash memory, magnetic surface storage, optical disk, or CD-ROM; or various devices including one or any combination of the above memories.

[0208] In some embodiments, executable instructions may be in the form of a program, software, software module, script, or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine, or other unit suitable for use in a computing environment.

[0209] As an example, executable instructions may, but need not, correspond to a file in a file system, may be stored as part of a file that stores other programs or data, such as in one or more scripts in a HyperText Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple coordinating files (e.g., files storing one or more modules, subroutines, or code portions).

[0210] By way of example, executable instructions may be deployed to be executed on one computing device, or on multiple computing devices at one site, or on multiple computing devices distributed across multiple sites and interconnected by a communication network.

[0211] The above are merely examples of the present application and are not intended to limit the scope of protection of the present application. Any modifications, equivalent replacements, and improvements made within the spirit and scope of the present application are included in the scope of protection of the present application.< / jsunknown> < / jsunknown> < / jsunknown> < / t>

Claims

1. A cross-programming language calling method, characterized in that: include: Invoking a first business service in a first operating environment of a first programming language to obtain business parameters in the first operating environment; Calling a first function in the first operating environment to pass business parameters in the first operating environment to a transit operating environment of a transit programming language, and passing the business parameters in the transit operating environment to a second operating environment of a second programming language; wherein the first function is converted from a transit function in the transit operating environment, and the transit function is converted from a second function in the second operating environment; and the second function is used to call back business parameters; The second business service is called in the second operating environment to perform business processing according to the business parameters in the second operating environment.

2. The method according to claim 1, characterized in that The input parameters of the first function include business parameters in the first operating environment; the first function includes a transfer function pointer pointing to the transfer function; the transfer function includes a second function pointer pointing to the second function; The transferring of the business parameters in the first operating environment to the transit operating environment of the transit programming language includes: Passing the business parameters received by the first function to the transfer function in the transfer running environment through the transfer function pointer pointing to the transfer function in the first function; The transferring of the business parameters in the transit operating environment to the second operating environment of the second programming language includes: The business parameters received by the transfer function are passed to the second function in the second operating environment through the second function pointer pointing to the second function in the transfer function.

3. The method according to claim 2, characterized in that The first function includes a data type conversion function; before passing the business parameters received by the first function to the transfer function in the transfer operation environment through the transfer function pointer in the first function pointing to the transfer function, the method further includes: The following processing is performed by the data type conversion function in the first function: Identify a first data type to which the service parameter received by the first function belongs; Performing data type conversion processing on a business parameter belonging to a first data type to obtain a business parameter belonging to a second data type; wherein the first data type corresponds to the first programming language, and the second data type corresponds to the second programming language; The transferring the service parameters received by the first function to the transfer function in the transfer operation environment through the transfer function pointer in the first function pointing to the transfer function includes: The business parameters belonging to the second data type are transferred to the transfer function in the transfer operation environment through the transfer function pointer pointing to the transfer function in the first function.

4. The method according to claim 3, characterized in that After performing data type conversion processing on the service parameters belonging to the first data type to obtain service parameters belonging to the second data type, the method further includes: Creating a dynamic array and storing the business parameters belonging to the second data type in the dynamic array; The transferring the service parameter of the second data type to the transfer function in the transfer operation environment through the transfer function pointer in the first function pointing to the transfer function includes: The dynamic array is passed as a parameter to the transfer function in the transfer running environment through the transfer function pointer pointing to the transfer function in the first function.

5. The method according to claim 3, characterized in that The method further comprises: When data type conversion processing fails on the service parameter belonging to the first data type, outputting a first error prompt according to the service parameter belonging to the first data type; Before the first operating environment calls the first function, the method further includes: Compiling the data type conversion function in the first function; When the compilation of the data type conversion function in the first function fails, a second error prompt is output according to the data type conversion function in the first function.

6. The method according to claim 2, characterized in that Before the first operating environment calls the first function, the method further includes: The following processing is performed in the transfer operation environment: Creating a closure including a transfer function pointer pointing to the transfer function as a first function; Performing pointer creation processing on the first function to obtain an original pointer pointing to the first function; Converting the original pointer pointing to the first function into a first function pointer supporting the first programming language; The calling of the first function in the first operating environment includes: The first function is called in the first operating environment through a first function pointer pointing to the first function.

7. The method according to claim 6, characterized in that The performing pointer creation processing on the first function to obtain an original pointer pointing to the first function includes: Performing heap allocation processing on the first function; A raw pointer to the heap-allocated first function is created.

8. The method according to claim 2, characterized in that The second operating environment is written in the first programming language; before the first operating environment calls the first function, the method further includes: The following processing is performed in the transfer operation environment: calling a pointer acquisition function provided by an interface protocol between the first programming language and the second programming language to obtain a second function pointer pointing to the second function; The second function pointer pointing to the second function is encapsulated to obtain a transit function in the transit running environment.

9. The method according to any one of claims 1 to 8, characterized in that The second operating environment is written in the first programming language; the first operating environment in the first programming language calls the first business service to obtain the business parameters in the first operating environment, including: The following processing is performed in the second operating environment: Invoking an interface protocol between the first programming language and the second programming language to access a file path of the first business service in the first operating environment; The first business service is called through the file path of the first business service to obtain business parameters in the first operating environment.

10. The method according to any one of claims 1 to 8, characterized in that The calling of the first business service in the first operating environment of the first programming language to obtain the business parameters in the first operating environment includes: The following processing is performed in the first operating environment: Testing business operations; A first business service corresponding to the detected business operation is called to obtain business parameters in the first operating environment.

11. The method according to any one of claims 1 to 8, characterized in that The first operating environment, the transit operating environment, and the second operating environment all run on a server; calling the second business service in the second operating environment to perform business processing according to business parameters in the second operating environment includes: Invoking a second business service in the second operating environment to pass business parameters in the second operating environment to a client using the second programming language; The client is used to display the service parameters in the second operating environment.

12. A cross-programming language calling device, characterized in that: include: An acquisition module, configured to call a first business service in a first operating environment of a first programming language to obtain business parameters in the first operating environment; a transfer module, configured to call a first function in the first operating environment to transfer business parameters in the first operating environment to a transit operating environment of a transit programming language, and to transfer business parameters in the transit operating environment to a second operating environment of a second programming language; wherein the first function is converted from a transit function in the transit operating environment, and the transit function is converted from a second function in the second operating environment; and the second function is used to call back business parameters; The business processing module is used to call the second business service in the second operating environment to perform business processing according to the business parameters in the second operating environment.

13. An electronic device, characterized in that: include: a memory for storing executable instructions; The processor is configured to implement the cross-programming language calling method according to any one of claims 1 to 11 when executing the executable instructions stored in the memory.

14. A computer-readable storage medium, characterized in that Executable instructions are stored for implementing the cross-programming language calling method according to any one of claims 1 to 11 when executed by a processor.

15. A computer program product, characterized in that The method comprises executable instructions for implementing the cross-programming language calling method according to any one of claims 1 to 11 when executed by a processor.