Lua script and engine communication method, system, electronic device and storage medium

By using a shared memory information cache queue for communication between the Lua script and the engine, the problems of high resource consumption and limited data length in socket technology are solved, and an efficient and flexible communication method is achieved.

CN115766609BActive Publication Date: 2025-09-09BEIJING CO WHEELS TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202211177119.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-26
Publication Date
2025-09-09
Estimated Expiration
2042-09-26

AI Technical Summary

Technical Problem

In the prior art, when the communication between the Lua script and the engine is done through socket technology, it consumes a lot of resources, is complex to create connections, and has a limited data transmission length.

Method used

Communication is carried out using a message cache queue in shared memory. The communication receiver and sender are in the same process. Data copying is avoided by judging whether the cache queue data is empty and reading or sending message data within a preset time.

Benefits of technology

It improves communication efficiency, reduces resource consumption, and makes the length of single transmission data flexible and adjustable, exceeding the maximum memory length limit of the operating system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115766609B_ABST
    Figure CN115766609B_ABST
Patent Text Reader

Abstract

The present application provides a communication method, system, electronic device and storage medium for a Lua script and an engine, the method comprising: a communication receiving end determining whether data in an information cache queue is empty; wherein the communication receiving end is a Lua script or an engine; the information cache queue is set in a shared memory of the same process as the communication receiving end and the communication sending end; when the communication receiving end determines that the data in the information cache queue is empty, determining whether the communication sending end has sent message data to the cache queue within a preset time; when the communication receiving end determines that the communication sending end has sent message data to the cache queue within the preset time, reading the message data in the information cache queue. Since the engine and Lua communicate by sharing the information cache queue in the same memory, no data copying is required, and communication efficiency is higher.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of communication between Lua scripts and engines, and in particular to a communication method, system, electronic device and storage medium between Lua scripts and engines. Background Art

[0002] Lua is a lightweight and compact scripting language written in standard C and open source. It is designed to be embedded in applications, providing flexible expansion and customization capabilities for applications. The engine is the application, and Lua scripts need to run in the engine. As an execution unit of the engine, Lua scripts need to communicate with the engine. Currently, the main technology used to achieve communication between Lua scripts and the engine is socket technology. However, when using socket technology for communication, data copying is required, connection creation consumes a lot of resources, creation is complex, and the maximum length of the received message is limited. Summary of the Invention

[0003] In view of this, the purpose of this application is to propose a communication method, system, electronic device and storage medium between a Lua script and an engine.

[0004] Based on the above purpose, the first aspect of the present application provides a communication method between a Lua script and an engine, the method being applied to a communication receiving end; the communication receiving end being a Lua script or an engine; the method comprising:

[0005] Determine whether the data in the information cache queue is empty; wherein the information cache queue is set in a shared memory in the same process of the communication receiving end and the communication sending end;

[0006] In response to determining that the data in the information cache queue is empty, determining whether the communication sending end has sent message data to the cache queue within a preset time;

[0007] In response to the communication sending end sending message data to the cache queue within a preset time, the message data in the information cache queue is read.

[0008] Based on the same inventive concept, the second aspect of the present application further provides another communication method between a Lua script and an engine, the method being applied to a communication sending end; the communication sending end being a Lua script or an engine; the method comprising:

[0009] Sending message data to the information cache queue so that the communication receiving end reads the message data in the cache queue;

[0010] The information cache queue is set in a shared memory of the same process as the communication receiving end and the communication sending end.

[0011] Based on the same inventive concept, the exemplary embodiment of the present application further provides a communication system between a Lua script and an engine, including:

[0012] A communication receiving end and a communication sending end; wherein the communication receiving end is a Lua script or an engine, and when the communication receiving end is a Lua script, the communication sending end is an engine, and when the communication receiving end is an engine, the communication sending end is a Lua script;

[0013] The communication receiving end is used to execute the communication method between the Lua script and the engine as described in the first aspect;

[0014] The communication sending end is used to execute the communication method between the Lua script and the engine as described in the second aspect.

[0015] Based on the same inventive concept, the exemplary embodiment of the present application also provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable by the processor. When the processor executes the program, it implements the communication method between the Lua script and the engine as described in the first aspect or implements the communication method between the Lua script and the engine as described in the second aspect.

[0016] Based on the same inventive concept, the exemplary embodiment of the present application also provides a non-transitory computer-readable storage medium, which stores computer instructions, and the computer instructions are used to enable a computer to execute the communication method between the Lua script and the engine as described in the first aspect or to execute the communication method between the Lua script and the engine as described in the second aspect.

[0017] From the above description, it can be seen that the communication method, system, electronic device and storage medium of the Lua script and engine provided by this application, the communication receiving end determines whether the data in the information cache queue is empty; wherein, the communication receiving end is a Lua script or engine; the information cache queue is set in the shared memory of the same process as the communication receiving end and the communication sending end; when the communication receiving end determines that the data in the information cache queue is empty, it determines whether the communication sending end has sent message data to the cache queue within a preset time; when the communication receiving end determines that the communication sending end has sent message data to the cache queue within a preset time, it reads the message data in the information cache queue. Since the engine and Lua communicate by sharing the information cache queue in the same memory, there is no need to copy data, creating a connection consumes less resources, and the communication efficiency is higher. At the same time, the maximum length of single transmission data can be flexibly configured, as long as it is not greater than the length of the information cache queue, that is, it is not greater than the maximum application memory length supported by the operating system. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] In order to more clearly illustrate the technical solutions in this application or related technologies, the following briefly introduces the drawings required for use in the embodiments or related technical descriptions. Obviously, the drawings described below are merely embodiments of this application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0019] Figure 1 This is a flow chart of a communication method between a Lua script and an engine according to an embodiment of the present application;

[0020] Figure 2 This is a flow chart of another communication method between a Lua script and an engine according to an embodiment of the present application;

[0021] Figure 3 This is a structural diagram of a communication system between a Lua script and an engine according to an embodiment of the present application;

[0022] Figure 4 This is a schematic diagram of the structure of the communication between a Lua script and an engine according to an embodiment of the present application;

[0023] Figure 5 This is a schematic structural diagram of a specific electronic device according to an embodiment of the present application. DETAILED DESCRIPTION

[0024] The principles and spirit of the present application will be described below with reference to several exemplary embodiments. It should be understood that these embodiments are provided solely to enable those skilled in the art to better understand and implement the present application, and are not intended to limit the scope of the present application in any way. Rather, these embodiments are provided to make the present application more thorough and complete, and to fully convey the scope of the present application to those skilled in the art.

[0025] According to the implementation of the present application, a communication method, system, electronic device and storage medium between a Lua script and an engine are proposed.

[0026] It should be understood herein that any number of elements in the drawings is for illustration only and not for limitation, and any naming is only for distinction and does not have any limiting meaning.

[0027] The principles and spirit of the present application are explained in detail below with reference to several representative implementations of the present application. SUMMARY OF THE INVENTION

[0029] Currently, the relevant technology mainly uses socket technology to achieve communication between Lua scripts and engines. However, when using socket technology for communication, creating a connection consumes a lot of resources, is complex to create, and the maximum length of the received message data is limited.

[0030] In order to solve the above problems, this application provides a communication method between Lua script and engine, which specifically includes:

[0031] The communication receiving end determines whether the data in the information cache queue is empty; wherein, the communication receiving end is a Lua script or engine; the information cache queue is set in the shared memory of the same process of the communication receiving end and the communication sending end; when the communication receiving end determines that the data in the information cache queue is empty, it determines whether the communication sending end has sent message data to the cache queue within a preset time; when the communication receiving end determines that the communication sending end has sent message data to the cache queue within a preset time, it reads the message data in the information cache queue. Since the engine and Lua communicate by sharing the information cache queue in the same memory, data copying is not required, and communication efficiency is higher. At the same time, the maximum length of single transmission data can be flexibly configured, as long as it is not greater than the length of the information cache queue, that is, it is not greater than the maximum application memory length supported by the operating system.

[0032] After introducing the basic principles of the present application, various non-limiting implementation methods of the present application are described in detail below.

[0033] Application Scenario Overview

[0034] In some specific application scenarios, the communication method between the Lua script and the engine of the present application can be applied to various platforms or systems involving communication between the Lua script and the engine.

[0035] The following describes the communication method between the Lua script and the engine according to the exemplary embodiment of the present application in conjunction with specific application scenarios. It should be noted that the above application scenarios are only shown to facilitate understanding of the spirit and principles of the present application, and the embodiments of the present application are not limited in this respect. On the contrary, the embodiments of the present application can be applied to any applicable scenario.

[0036] Exemplary Methods

[0037] refer to Figure 1 The embodiment of the present application provides a communication method between a Lua script and an engine, the method being applied to a communication receiving end; the communication receiving end being a Lua script or an engine; the method comprising the following steps:

[0038] S101, determining whether the data in the information cache queue is empty; wherein the information cache queue is set in the shared memory of the same process of the communication receiving end and the communication sending end.

[0039] In specific implementations, when a communication sender communicates with a communication receiver, the sender sends (writes) the message data to be sent to the cache queue. Then, when receiving the message data, the communication receiver first determines whether the data in the information cache queue is empty. If it is not empty, it directly reads the data in the cache queue, that is, the message information.

[0040] It should be noted that the information cache queue is set in the shared memory of the same process of the communication receiving end and the communication sending end, that is, the communication receiving end and the communication sending end are in the same process, and the information cache queue is set in the shared memory of the same process. In this way, the communication receiving end can directly read the data in the shared memory when receiving message data, and no longer needs to copy the data, which makes the communication efficiency higher. Moreover, the maximum length of single transmission data can be flexibly configured, as long as it is not greater than the length supported by the information cache queue, that is, it is not greater than the maximum application memory length supported by the operating system, and there is no problem of socket maximum transmission data length limit.

[0041] It should be noted that the communication receiving end is a Lua script or an engine, and when the communication receiving end is a Lua script, the communication sending end is an engine, and when the communication receiving end is an engine, the communication sending end is a Lua script. That is, both the Lua script and the engine can serve as the communication receiving end or the communication sending end.

[0042] In some embodiments, to enable communication between Lua scripts and the engine, a separate library is pre-packaged and relied upon by both the engine and the Lua script process (the same process). This library contains three classes. The first class is the information cache queue class, which is primarily used to request cache space for sending and receiving data from the engine to the Lua script, cache space for sending and receiving data from the Lua script to the engine, and mutexes and conditional variables for sending and receiving data from the engine to the Lua script, as well as mutexes and conditional variables for sending and receiving data from the Lua script to the engine.

[0043] The second class is provided to the engine side. This class holds the object pointer of the first class, has the send interface sent by the engine to the Lua script, and is used to receive the thread object of the Lua script data. The engine asynchronously receives the data sent by the Lua script and calls the callback function registered by the upper layer. This class is then created by the engine to send data to the Lua script and asynchronously receive and process the data sent by the Lua script.

[0044] The third class is the class provided to the Lua script. This class is static and global and is initialized together when the engine is constructed. This class holds the object pointer of the first class and encapsulates the interface for the Lua script to send messages to the engine and the interface for the Lua script to receive messages sent by the engine.

[0045] When the engine needs to run a Lua script, it constructs an object of the information cache queue class. It then creates an object of the second class and passes a pointer to the information cache queue class to this object. It also passes a pointer to the information cache queue class to the third class. This completes the initialization of all objects. During the Lua script's execution, it can call the third class's transceiver interface to send data to the engine and receive messages from the engine. Specifically, the Lua script sends data to the information cache queue class by calling the third class's transceiver interface, or reads data from the information cache queue class through the third class's transceiver interface to receive messages from the engine. The engine calls the second class object to send data, and the second class asynchronously handles the engine's registered callback function to process messages received from the Lua script. When the engine finishes running the script, it destructs the second class object and the first class's information cache queue class object.

[0046] S102: In response to determining that the data in the information cache queue is empty, determining whether the communication sending end has sent message data to the cache queue within a preset time.

[0047] In specific implementations, when the receiving end determines that the data in the information cache queue is empty, it indicates that the message data sent by the receiving end has not been received. To improve communication efficiency, in this embodiment, the receiving end does not immediately terminate the reception of the message data. Instead, it further determines whether the sending end has sent message data to the cache queue within a preset time. In other words, the receiving end waits for the preset time. Optionally, the preset time can be set as needed and is not limited thereto.

[0048] S103 : In response to determining that the communication sending end has sent the message data to the cache queue within a preset time, reading the message data in the information cache queue.

[0049] In a specific implementation, when the communication receiving end determines that the communication sending end has sent message data to the cache queue within a preset time, the message data in the information cache queue is read, thereby completing the reception of this message.

[0050] In some embodiments, after determining whether the communication sending end has sent the message data to the cache queue within a preset time, the method further includes:

[0051] In response to determining that the communication sending end has not sent the message data to the cache queue within the preset time, the current message reception is terminated and a timeout reminder is sent.

[0052] In a specific implementation, when the communication receiving end determines that the communication sending end has not sent the message data to the cache queue within a preset time, the message reception is terminated and a timeout reminder is sent.

[0053] In some embodiments, determining whether the communication sending end has sent message data to the cache queue within a preset time specifically includes:

[0054] Whether the communication sending end sends the message data to the cache queue within a preset time is determined through a conditional variable.

[0055] In practice, a condition variable is a mechanism for synchronization using a global variable shared between threads. It primarily involves two actions: one thread suspends itself while waiting for the "condition of the condition variable to be satisfied"; the other thread confirms the "condition" (signals the condition to be satisfied). The condition variable allows the receiving end to promptly determine whether the sending end has sent message data to the cache queue within a preset time. Optionally, after sending message data to the information cache, the sending end sends an event to the receiving end via the condition variable, allowing the receiving end to promptly learn of the message data sent by the sending end and read it promptly.

[0056] In some embodiments, determining whether the communication sending end sends message data to the cache queue within a preset time specifically includes:

[0057] determining whether the data in the information cache queue is empty within the preset time according to a preset frequency;

[0058] In response to determining that the data in the information cache queue is empty within the preset time, determining that the communication sending end has not sent message data to the cache queue within the preset time;

[0059] In response to determining that the data in the information cache queue is not empty within the preset time, it is determined that the communication sending end has sent message data to the cache queue within the preset time.

[0060] In a specific implementation, whether the communication sending end has sent message data to the cache queue within the preset time can be determined by determining whether the data in the information cache queue is empty multiple times within the preset time. When the data in the information cache queue is determined to be empty within the preset time, it means that the communication sending end has not sent message data to the cache queue within the preset time. When the data in the information cache queue is determined to be not empty within the preset time, it means that the communication sending end has sent message data to the cache queue within the preset time. Optionally, the number of times the data in the information cache queue is determined to be empty within the preset time can be determined by a preset frequency. The specific preset frequency can be set as needed and is not limited to this.

[0061] In some embodiments, before determining whether the data in the information cache queue is empty, the method further includes:

[0062] Acquire the mutex lock of the information cache queue.

[0063] In a specific implementation, the mutex lock is used to grant the reader process and the writer process read and write permissions to the shared memory, respectively, to ensure the integrity of shared data operations. Each object is associated with a tag, referred to as a "mutual exclusion lock," which ensures that only one thread can access the object at any given time. For example, if there is a writer process A and a reader process D, and writer process A acquires the mutex lock, then reader process D will enter a blocked state and will not be unblocked until it acquires the mutex lock. In other words, only one process can perform a read or write operation at a time. In this embodiment, before determining whether the data in the information cache queue is empty, the communication receiving end first acquires the mutex lock for the information cache queue. This prevents data in the information cache queue from being changed during the determination process, thereby affecting the determination result. Optionally, the communication receiving end can release the mutex lock upon determining that the data in the information cache queue is empty. When reading message data from the information cache queue, the communication receiving end first acquires the mutex lock to prevent the read message data from being affected.

[0064] The communication method between the Lua script and the engine provided by the present application is that the communication receiving end determines whether the data in the information cache queue is empty; wherein the communication receiving end is a Lua script or an engine; the information cache queue is set in the shared memory of the same process as the communication receiving end and the communication sending end; when the communication receiving end determines that the data in the information cache queue is empty, it determines whether the communication sending end has sent message data to the cache queue within a preset time; when the communication receiving end determines that the communication sending end has sent message data to the cache queue within a preset time, it reads the message data in the information cache queue. Since the engine and Lua communicate by sharing the information cache queue in the same memory, no data copying is required, and the communication efficiency is higher. At the same time, the maximum length of single transmission data can be flexibly configured, as long as it is not greater than the length of the information cache queue, that is, it is not greater than the maximum application memory length supported by the operating system.

[0065] refer to Figure 2 , another communication method between a Lua script and an engine provided in an embodiment of the present application, the method is applied to a communication sending end; the communication sending end is a Lua script or an engine; the method includes:

[0066] Sending message data to the information cache queue so that the communication receiving end reads the message data in the cache queue;

[0067] The information cache queue is set in a shared memory of the same process as the communication receiving end and the communication sending end.

[0068] In a specific implementation, when the communication sending end wants to send a message to the communication receiving end, it sends the message data to the information cache queue, so that the communication receiving end reads the message data in the cache queue.

[0069] It should be noted that the message cache queue may store multiple historical message data. The communication sending end can sequentially number each message data sent and store it in the message cache queue in order, so that the communication receiving end can read each message data in sequence. Optionally, after reading a message data, the communication receiving end can delete the message data from the cache queue as needed to save memory.

[0070] In some embodiments, after sending the message data to the information cache queue, the method further includes:

[0071] The communication receiving end is notified through a conditional variable to read the message data in the information cache queue.

[0072] In some embodiments, before sending the message data to the information cache queue, the method further includes:

[0073] Acquire the mutex lock of the information cache queue.

[0074] In specific implementation, in order to prevent the communication sending end from being affected by the communication receiving end when sending message data to the information cache queue, the communication sending end will first obtain the mutual exclusion lock of the information cache queue before sending the message data to the information cache queue.

[0075] Exemplary devices

[0076] Based on the same inventive concept, corresponding to any of the above-mentioned embodiment methods, the present application also provides a communication system between a Lua script and an engine.

[0077] refer to Figure 3 The communication system between the Lua script and the engine includes:

[0078] A communication receiving end 101 and a communication sending end 103; wherein the communication receiving end is a Lua script or an engine, and when the communication receiving end is a Lua script, the communication sending end is an engine, and when the communication receiving end is an engine, the communication sending end is a Lua script;

[0079] The communication receiving end is used to execute the communication method between the Lua script and the engine as described in the first aspect;

[0080] The communication sending end is used to execute the communication method between the Lua script and the engine as described in the second aspect.

[0081] It should be noted that the communication receiving end 101 communicates with the communication sending end 103 through the information buffer queue 102 .

[0082] refer to Figure 4 , which is a schematic diagram of the communication structure between the Lua script and the engine in an embodiment of the present application, wherein two information cache queues are opened between the engine 201 and the Lua script 202 to perform full-duplex communication for data transmission and reception.

[0083] For the convenience of description, the above system is described as being divided into various modules according to their functions. Of course, when implementing this application, the functions of each module can be implemented in the same or multiple software and / or hardware.

[0084] The system of the above embodiment is used to implement the communication method between the corresponding Lua script and the engine in any of the above embodiments, and has the beneficial effects of the corresponding method embodiments, which will not be repeated here.

[0085] Based on the same inventive concept, corresponding to any of the above-mentioned embodiments and methods, the present application also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and runnable on the processor, wherein when the processor executes the program, the communication method between the Lua script and the engine described in any of the above embodiments is implemented.

[0086] Figure 5 10 is a schematic diagram showing a more specific hardware structure of an electronic device provided in this embodiment. The device may include: a processor 1010, a memory 1020, an input / output interface 1030, a communication interface 1040, and a bus 1050. The processor 1010, the memory 1020, the input / output interface 1030, and the communication interface 1040 are communicatively connected to each other within the device via the bus 1050.

[0087] The processor 1010 can be implemented using a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this specification.

[0088] The memory 1020 can be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage devices, dynamic storage devices, etc. The memory 1020 can store an operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 1020 and is called and executed by the processor 1010.

[0089] The input / output interface 1030 is used to connect input / output modules to implement information input and output. The input / output modules can be configured as components within the device (not shown in the figure) or can be externally connected to the device to provide corresponding functions. Input devices may include a keyboard, mouse, touch screen, microphone, various sensors, etc., and output devices may include a display, speaker, vibrator, indicator light, etc.

[0090] The communication interface 1040 is used to connect to a communication module (not shown) to enable communication between the device and other devices. The communication module can communicate via a wired method (such as USB, network cable, etc.) or a wireless method (such as mobile network, WiFi, Bluetooth, etc.).

[0091] The bus 1050 comprises a path for transmitting information between the various components of the device (eg, the processor 1010 , the memory 1020 , the input / output interface 1030 , and the communication interface 1040 ).

[0092] It should be noted that although the above device only shows the processor 1010, the memory 1020, the input / output interface 1030, the communication interface 1040, and the bus 1050, in a specific implementation, the device may also include other components necessary for normal operation. In addition, it will be understood by those skilled in the art that the above device may only include the components necessary to implement the embodiments of this specification, and does not necessarily include all the components shown in the figure.

[0093] The electronic device of the above embodiment is used to implement the communication method between the corresponding Lua script and the engine in any of the above embodiments, and has the beneficial effects of the corresponding method embodiment, which will not be repeated here.

[0094] Exemplary Program Products

[0095] Based on the same inventive concept, corresponding to any of the above-mentioned embodiments and methods, the present application also provides a non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute the communication method between the Lua script and the engine as described in any of the above embodiments.

[0096] The computer-readable media of this embodiment include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, read-only compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device.

[0097] The computer instructions stored in the storage medium of the above embodiment are used to enable the computer to execute a communication method between a Lua script and an engine as described in any of the above embodiments, and have the beneficial effects of the corresponding method embodiments, which will not be repeated here.

[0098] Those skilled in the art should understand that the discussion of any of the above embodiments is merely illustrative and is not intended to imply that the scope of the present application (including the claims) is limited to these examples. Within the scope of the present application, the technical features in the above embodiments or different embodiments may be combined, the steps may be implemented in any order, and there are many other variations of the different aspects of the embodiments of the present application as described above, which are not provided in detail for the sake of simplicity.

[0099] In addition, for simplicity of description and discussion, and in order not to make the embodiment of the application difficult to understand, the known power supply / ground connection with integrated circuit (IC) chip and other components may or may not be shown in the accompanying drawings provided. In addition, the device can be shown in the form of a block diagram to avoid making the embodiment of the application difficult to understand, and this also takes into account the following fact, that is, the details of the embodiment of these block diagram devices are highly dependent on the platform to be implemented in the embodiment of the application (that is, these details should be fully within the scope of understanding of those skilled in the art). When specific details (for example, circuit) are set forth to describe exemplary embodiments of the application, it will be apparent to those skilled in the art that the embodiment of the application can be implemented without these specific details or when these specific details are changed. Therefore, these descriptions should be considered to be illustrative rather than restrictive.

[0100] Although the present invention has been described in conjunction with specific embodiments thereof, many alternatives, modifications, and variations of these embodiments will be apparent to those skilled in the art based on the foregoing description. For example, other memory architectures (e.g., dynamic RAM (DRAM)) may utilize the embodiments discussed.

[0101] The embodiments of the present application are intended to cover all such substitutions, modifications, and variations that fall within the broad scope of the appended claims. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the embodiments of the present application should be included in the scope of protection of this application.

Claims

1. A communication method between a Lua script and an engine, characterized in that: The method is applied to a communication receiving end; The communication receiving end is a Lua script or engine; the method includes: Determine whether the data in the information cache queue is empty; wherein the information cache queue is set in the shared memory of the same process of the communication receiving end and the communication sending end; In response to determining that the data in the information cache queue is empty, determining whether the communication sending end has sent message data to the cache queue within a preset time; In response to determining that the communication sending end has sent message data to the cache queue within a preset time, reading the message data in the information cache queue; After determining whether the communication sending end has sent the message data to the cache queue within a preset time, the method further includes: In response to determining that the communication sending end has not sent the message data to the cache queue within the preset time, the current message reception is terminated and a timeout reminder is sent.

2. The method according to claim 1, characterized in that Determining whether the communication sending end has sent message data to the cache queue within a preset time specifically includes: Whether the communication sending end sends the message data to the cache queue within a preset time is determined through a conditional variable.

3. The method according to claim 1, characterized in that Determining whether the communication sending end sends message data to the cache queue within a preset time specifically includes: determining whether the data in the information cache queue is empty within the preset time according to a preset frequency; In response to determining that the data in the information cache queue is empty within the preset time, determining that the communication sending end has not sent message data to the cache queue within the preset time; In response to determining that the data in the information cache queue is not empty within the preset time, it is determined that the communication sending end has sent message data to the cache queue within the preset time.

4. The method according to claim 1, wherein Before determining whether the data in the information cache queue is empty, the method further includes: Acquire the mutex lock of the information cache queue.

5. A communication method between a Lua script and an engine, characterized in that: The method is applied to a communication sending end; The communication sending end is a Lua script or engine; the method includes: Sending message data to the information cache queue so that the communication receiving end reads the message data in the cache queue; Wherein, the information cache queue is set in the shared memory of the same process of the communication receiving end and the communication sending end; The communication receiving end reads the message data in the cache queue, specifically including: Determine whether the data in the information cache queue is empty; In response to determining that the data in the information cache queue is empty, determining whether the communication sending end has sent message data to the cache queue within a preset time; In response to determining that the communication sending end has sent message data to the cache queue within a preset time, reading the message data in the information cache queue; After determining whether the communication sending end has sent the message data to the cache queue within a preset time, the method further includes: In response to determining that the communication sending end has not sent the message data to the cache queue within the preset time, the current message reception is terminated and a timeout reminder is sent.

6. The method according to claim 5, characterized in that After sending the message data to the information cache queue, the method further includes: The communication receiving end is notified through a conditional variable to read the message data in the information cache queue.

7. The method according to claim 5, characterized in that Before sending the message data to the information cache queue, the method further includes: Acquire the mutex lock of the information cache queue.

8. A communication system between a Lua script and an engine, characterized in that: include: A communication receiving end and a communication sending end; wherein the communication receiving end is a Lua script or an engine, and when the communication receiving end is a Lua script, the communication sending end is an engine, and when the communication receiving end is an engine, the communication sending end is a Lua script; The communication receiving end is used to perform the method according to any one of claims 1 to 4; The communication sending end is used to execute the method according to any one of claims 5 to 7.

9. An electronic device, characterized in that: The method comprises a memory, a processor, and a computer program stored in the memory and executable by the processor, wherein when the processor executes the program, the method according to any one of claims 1 to 4 is implemented, or the method according to any one of claims 5 to 7 is implemented.

10. A non-transitory computer-readable storage medium, characterized in that The non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to cause a computer to execute the method according to any one of claims 1 to 4, or to execute the method according to any one of claims 5 to 7.

Citation Information

Patent Citations

  • Method and device for processing data transmitted by serial interface

    CN104809093A