A method and terminal supporting dynamic hot updating of Lua scripts
By exporting Lua script's open methods into callable methods through the processor management module and program export module, and combining this with the Lua script management module to load hot-update resources, the problem of Lua script's inability to dynamically hot update is solved, achieving seamless updates and improving the program's stability and flexibility.
Patent Information
- Application Number
- CN202410855620.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-28
- Publication Date
- 2025-11-28
- Estimated Expiration
- 2044-06-28
AI Technical Summary
In existing technologies, Lua scripts cannot achieve dynamic hot updates without stopping or restarting the application, which affects application stability and user experience.
All static processors are started through the processor management module, and the open methods of the processors are exported as Lua script callable methods using the program export module. Combined with the Lua script management module, hot-updated Lua script resources are loaded and called to override the corresponding open methods.
It enables dynamic hot updates of Lua scripts, avoiding program interruption upon restart, improving program stability and flexibility, enhancing user experience, and reducing maintenance costs.
Smart Images

Figure CN118672625B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of script development, and in particular to a method and terminal that supports dynamic hot updates of Lua scripts. Background Technology
[0002] With the rapid development of computer technology and the internet, the complexity and scale of software systems are constantly increasing, making dynamic updates and flexible expansion crucial requirements in modern software development. Among numerous programming languages and technologies, Lua scripting language, due to its lightweight, high efficiency, and ease of embedding, is widely used in game development, embedded systems, and network applications. However, current technologies still present challenges for dynamic hot updates of Lua scripts, especially without stopping or restarting the application. How to achieve real-time updates and overwrites of Lua scripts has become a pressing issue.
[0003] In existing technologies, smart terminal devices (such as mobile phones, tablets, and embedded devices) typically implement complex functions by combining pre-compiled native code and scripting languages (such as Lua). The pre-compiled native code provides efficient basic functionality, while the scripting language is used to implement business logic and dynamically adjust functionality. However, because Lua scripts cannot directly replace or update the functionality of the pre-compiled native code, modifications or extensions to functionality require restarting the application or redeploying related processes, severely impacting application stability and user experience. Summary of the Invention
[0004] The technical problem to be solved by the present invention is to provide a method and terminal that support dynamic hot updates of Lua scripts, thereby solving the problem that Lua scripts cannot be dynamically hot updated.
[0005] To solve the above-mentioned technical problems, the technical solution adopted by the present invention is as follows:
[0006] A method for supporting dynamic hot updates of Lua scripts includes the following steps:
[0007] S1. The control processor management module starts all static processors;
[0008] S2. The control program export module obtains all the open methods of the static processors and exports the open methods as methods that can be called by Lua scripts;
[0009] S3. Input the hot-update Lua script resources and control the Lua script management module to load the hot-update Lua script resources;
[0010] S4. Control the Lua script management module to call the Lua hot update logic in the Lua script resource and override the corresponding open method with the Lua hot update logic.
[0011] To solve the above-mentioned technical problems, another technical solution adopted by the present invention is as follows:
[0012] A terminal supporting dynamic hot updates of Lua scripts includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it performs the following steps:
[0013] S1. The control processor management module starts all static processors;
[0014] S2. The control program export module obtains all the open methods of the static processors and exports the open methods as methods that can be called by Lua scripts;
[0015] S3. Input the hot-update Lua script resources and control the Lua script management module to load the hot-update Lua script resources;
[0016] S4. Control the Lua script management module to call the Lua hot update logic in the Lua script resource and override the corresponding open method with the Lua hot update logic.
[0017] The beneficial effects of this invention are as follows: It provides a method and terminal that support dynamic hot updates of Lua scripts. It starts all static processors through a processor management module and exports the open methods of the processors into callable methods in Lua scripts through a program export module. It exposes the functions in the native code to Lua scripts, so that Lua scripts can call these functions. In this way, the Lua script management module can dynamically update or modify the program logic according to the Lua scripts, avoiding the interruption of program operation or redeployment of corresponding processes by restarting, thereby improving the stability and flexibility of program operation. Attached Figure Description
[0018] Figure 1 This is a flowchart illustrating a method for supporting dynamic hot updates of Lua scripts in an embodiment of the present invention;
[0019] Figure 2 This is a flowchart illustrating a method for supporting dynamic hot updates of Lua scripts in an embodiment of the present invention.
[0020] Figure 3 This is a flowchart of the processor registration function module processor in the processor management module of this embodiment of the invention;
[0021] Figure 4 A flowchart for starting a static processor in the processor management module of this embodiment of the invention;
[0022] Figure 5 This is a flowchart of the method for exporting open methods from the program export module in this embodiment of the invention;
[0023] Figure 6 This is a flowchart of the input hot-update Lua script in an embodiment of the present invention;
[0024] Figure 7 A flowchart illustrating the loading of hot-updated Lua script resources by the Lua script management module in this embodiment of the invention;
[0025] Figure 8 This is a flowchart illustrating the process of the Lua script management module calling the initialization method in the Lua script in an embodiment of the present invention.
[0026] Figure 9 This is a flowchart illustrating the open method coverage in the embodiments of the present invention;
[0027] Figure 10 This is a schematic diagram of a terminal that supports dynamic hot updates of Lua scripts in an embodiment of the present invention;
[0028] Label Explanation:
[0029] 1. A terminal that supports dynamic hot updates of Lua scripts; 2. Memory; 3. Processor. Detailed Implementation
[0030] To explain in detail the technical content, objectives, and effects of the present invention, the following description is provided in conjunction with the embodiments and accompanying drawings.
[0031] Please refer to Figures 1 to 2 A method for supporting dynamic hot updates of Lua scripts includes the following steps:
[0032] S1. The control processor management module starts all static processors;
[0033] S2. The control program export module obtains all the open methods of the static processors and exports the open methods as methods that can be called by Lua scripts;
[0034] S3. Input the hot-update Lua script resources and control the Lua script management module to load the hot-update Lua script resources;
[0035] S4. Control the Lua script management module to call the Lua hot update logic in the Lua script resource and override the corresponding open method with the Lua hot update logic.
[0036] As can be seen from the above description, the beneficial effects of the present invention are as follows: all static processors are started through the processor management module, and the open methods of the processors are exported as callable methods in Lua scripts through the program export module, exposing the functions in the native code to Lua scripts, so that Lua scripts can call these functions. Thus, the program logic can be dynamically updated or modified according to Lua scripts by the Lua script management module, avoiding the interruption of program operation or redeployment of corresponding processes by restarting, thereby improving the stability and flexibility of program operation.
[0037] It is understood that, in this invention, a processor is defined as a collection of methods for implementing functions in all functional modules of a program assembly, all of which are described using a uniform format.
[0038] In this invention, a static processor is defined as a processor that can exist only once and always exists.
[0039] In this invention, an open method is defined as a method whose functionality can be directly invoked.
[0040] In this invention, hot update is defined as something that can be dynamically updated and modified;
[0041] In this invention, the original program is defined as the functional implementation code before it is hot-updated;
[0042] Specifically, the processor management module is responsible for registering all functional module processors in all assemblies and starting all static processors. It is responsible for managing and scheduling all processors.
[0043] The program export module is responsible for exporting the processor's open methods into callable methods in Lua scripts. The main function of this module is to provide an interface for Lua scripts, allowing them to call functionalities from native code.
[0044] The Lua script management module is responsible for inputting Lua script resources for hot updates, loading these resources, and calling initialization methods within the Lua scripts. If Lua hot update logic exists, it calls open methods exported by the program export module to override the original program's implementation.
[0045] In an embodiment of the present invention, step S1 specifically includes the following steps:
[0046] The processor management module controls the process to traverse all assemblies and register the functional module processors in the assemblies with the processor management module.
[0047] The processor management module determines whether the registered processor management module is a static processor; if so, the static processor is started.
[0048] As described above, by controlling the processor management module to traverse all program assemblies and register the functional module processors in the program assemblies with the processor management module, the automated management of system functional modules is realized. Furthermore, the control processor management module determines whether the registered processor is a static processor and starts the static processor, ensuring that the static processor can work normally when the system starts, thus ensuring the efficient startup and stable operation of the system's key modules.
[0049] In an embodiment of the present invention, step S2 specifically includes the following steps:
[0050] The control program export module obtains the open methods of all the static processors and creates a corresponding Lua call interface for each open method.
[0051] As described above, by controlling the program export module to obtain the open methods of all static processors and creating a corresponding Lua call interface for each open method, the standardized export of methods is achieved, enabling these methods to be flexibly called in the Lua environment. This standardized interface creation process ensures the consistency and security of method calls, thereby greatly improving the system's scalability and flexibility.
[0052] Specifically, the export module can utilize Lua's export framework, including but not limited to Xlua and ToLua, to implement the export process and create Lua call interfaces. This module only needs to export the open methods of all "processors." Unlike existing Lua frameworks that export all functional methods, this invention only requires exporting the open methods of all "processors." Specific functional methods do not need to be exported; instead, they are forwarded through the processors to achieve native function calls. Lua scripts can then call all native functions by invoking the exported "open methods of the processors."
[0053] In an embodiment of the present invention, step S3 specifically includes the following steps:
[0054] Input Lua script resources for hot reloading;
[0055] The control Lua script management module loads hot-updated Lua script resources and parses them into executable code, then places the executable code into the Lua environment.
[0056] As described above, by inputting hot-updated Lua script resources and controlling the Lua script management module to load these resources and parse them into executable code, and then placing the parsed code into the Lua environment, efficient loading and execution of script resources are achieved. This efficient loading and execution mechanism ensures the system's rapid response capability during dynamic updates, thereby improving the system's real-time performance and dynamic update capability.
[0057] In an embodiment of the present invention, step S4 specifically includes the following steps:
[0058] The Lua script management module is controlled to search for and call initialization methods that conform to the hot update logic of Lua programs in the Lua script resources;
[0059] The initialization method and the open method are matched, and the initialization method that completes the match overrides the corresponding open method.
[0060] As described above, by controlling the Lua script management module to find and call the initialization method that conforms to the hot update logic of Lua programs in Lua script resources, the automatic initialization of hot update logic is realized. Furthermore, by matching the initialization method and the open method, and overriding the corresponding open method with the matched initialization method, it is ensured that the new logic can take effect immediately. This improves the accuracy and execution efficiency of system updates and ensures the stability and reliability of the system during dynamic updates.
[0061] Please refer to Figure 10 A terminal that supports dynamic hot updates of Lua scripts includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it completes the steps of a method that supports dynamic hot updates of Lua scripts.
[0062] As described above, an execution carrier is provided to support dynamic hot updates of Lua scripts. During the execution of the above method, all static processors are started through the processor management module, and the open methods of the processors are exported as callable methods in Lua scripts through the program export module. The functions in the native code are exposed to Lua scripts, so that Lua scripts can call these functions. Thus, the Lua script management module can dynamically update or modify the program logic according to the Lua scripts, avoiding the interruption of program operation or redeployment of corresponding processes by restarting, thereby improving the stability and flexibility of program operation.
[0063] This invention provides a method and terminal for supporting dynamic hot updates of Lua scripts, mainly used to improve the flexibility of Lua script hot updates. The following is a detailed description with reference to embodiments:
[0064] Please refer to Figures 1 to 2 Embodiment 1 of the present invention is as follows:
[0065] A method for supporting dynamic hot updates of Lua scripts includes the following steps:
[0066] S1. The control processor management module starts all static processors;
[0067] S2. The control program export module obtains all open methods of static processors and exports the open methods as methods that can be called by Lua scripts;
[0068] S3. Input the hot-update Lua script resources and control the Lua script management module to load the hot-update Lua script resources;
[0069] S4. Control the Lua script management module to call the Lua hot update logic in the Lua script resources and override the corresponding open methods with the Lua hot update logic.
[0070] In this embodiment, all static processors are started through the processor management module, and the open methods of the processors are exported as callable methods in Lua scripts through the program export module. This exposes the functions in the native code to Lua scripts, allowing Lua scripts to call these functions. In this way, the Lua script management module can dynamically update or modify the program logic based on the Lua scripts, avoiding the interruption of program operation or the redeployment of corresponding processes by restarting, thereby improving the stability and flexibility of program operation.
[0071] Embodiment 2 of the present invention is as follows:
[0072] Based on Example 1, step S2 specifically includes the following steps:
[0073] The control program export module obtains all open methods of static processors and creates a corresponding Lua calling interface for each open method. By acquiring all open methods of static processors through the control program export module and creating a corresponding Lua calling interface for each open method, standardized method export is achieved, enabling these methods to be flexibly called in the Lua environment. This standardized interface creation process ensures the consistency and security of method calls, thereby significantly improving the system's scalability and flexibility.
[0074] Step S3 specifically includes the following steps: inputting the hot-updating Lua script resources; controlling the Lua script management module to load the hot-updating Lua script resources and parse them into executable code, and then placing the executable code into the Lua environment. By inputting the hot-updating Lua script resources and controlling the Lua script management module to load these resources and parse them into executable code, and then placing the parsed code into the Lua environment, efficient loading and execution of script resources is achieved. This efficient loading and execution mechanism ensures the system's rapid response capability during dynamic updates, thereby improving the system's real-time performance and dynamic update capability.
[0075] Step S4 specifically includes the following steps: controlling the Lua script management module to search for and call initialization methods that conform to the Lua program's hot update logic in Lua script resources; matching initialization methods and open methods, and overriding the corresponding open methods with the matched initialization methods. By controlling the Lua script management module to search for and call initialization methods that conform to the Lua program's hot update logic in Lua script resources, automated initialization of the hot update logic is achieved. Furthermore, by matching initialization methods and open methods, and overriding the corresponding open methods with the matched initialization methods, it is ensured that the new logic can take effect immediately. This improves the accuracy and execution efficiency of system updates, and ensures the stability and reliability of the system during dynamic updates.
[0076] Please refer to Figures 1 to 9 Embodiment 3 of the present invention is as follows:
[0077] The specific application of a method to support dynamic hot updates of Lua scripts is as follows:
[0078] In online games that require hot updates, follow these steps to achieve non-disruptive updates:
[0079] 1. The processor management module registers all functional module processors in all assemblies.
[0080] Please refer to Figure 3 In this process, first, all assemblies are retrieved. Then, each assembly is iterated over. Next, a function module processor is searched for in each assembly. Then, it is determined whether a function module processor is found. If found, the function module processor is registered to the processor management module. Then, it is determined whether there are any un-traversed assemblies. If there are, the process returns to the step of traversing each assembly. If not, the process ends. If no function module processor is found, the process returns to the step of determining whether there are any un-traversed assemblies.
[0081] 2. The processor management module starts all static processors.
[0082] Please refer to Figure 4 In this process, firstly, the processor management module retrieves all registered functional module processors. Then, it iterates through each functional module processor. Next, it determines if it is a static processor. If so, it starts the static processor. Then, it checks if there are any un-iterated processors. If there are, it returns to the step of iterating through each functional module processor. If not, it terminates. If it is not a static processor, it returns to the step of checking if there are any un-iterated processors.
[0083] 3. The open methods of the export processor in the program export module are methods that can be called in Lua scripts.
[0084] Please refer to Figure 5 In this process, firstly, the program exports the module to obtain the open methods of all processors. Then, it iterates through each open method. Next, it creates a corresponding Lua call interface for each open method. Then, it checks if there are any un-traversed open methods. If there are, it returns to the step of traversing each open method. If not, it terminates.
[0085] 4. Input Lua script resources for hot reloading
[0086] Please refer to Figure 6 In this process, first, the path to the Lua script resource for hot updates is obtained. Then, the Lua script resource file is read. Next, the Lua script resource file is parsed. Then, the parsed Lua script resources are stored. Finally, the process ends.
[0087] 5. The Lua script management module loads all hot-reloadable Lua script resources.
[0088] Please refer to Figure 7 In this process, firstly, all stored hot-update Lua script resources are retrieved. Then, each Lua script resource is iterated over. Next, each Lua script resource is parsed into executable code. Then, each parsed Lua script code is loaded into the Lua environment. Next, it is determined whether there are any unloaded Lua script resources. If there are, the process returns to the step of iterating over each Lua script resource. If not, the process ends.
[0089] 6. The Lua script management module calls the initialization method in the Lua script.
[0090] Please refer to Figure 8 In this process, the Lua scripting environment is first obtained. Then, the initialization method is searched for in the Lua scripting environment. Next, it is determined whether the initialization method is found. If found, the initialization method is called and the process ends. If not found, an error message is output and the process ends.
[0091] 7. The Lua script management module calls the program's export module to rewrite and override the corresponding implementations in the original program.
[0092] Please refer to Figure 9In this process, first, all open methods exported by the program's export module are retrieved. Then, each open method is iterated over. Next, the corresponding method implementation is searched for in the Lua script environment. Then, it is determined whether a method implementation in the Lua script is found. If found, the implementation in the Lua script is used to override the original program's implementation. Then, it is determined whether there are any un-traversed open methods. If there are, the process returns to the step of traversing each open method. If not, the process ends. If no method implementation in the Lua script is found, an error message is output, and the process returns to the step of determining whether there are any un-traversed open methods.
[0093] Please refer to Figure 10 Embodiment four of the present invention is as follows:
[0094] A terminal 1 that supports dynamic hot updates of Lua scripts includes a memory 2, a processor 3, and a computer program stored on the memory 2 and executable on the processor 3. When the processor executes the computer program, it completes the steps of any one of the methods for supporting dynamic hot updates of Lua scripts in Embodiments 1 to 3.
[0095] In summary, the method and terminal for supporting dynamic hot updates of Lua scripts provided by this invention have the following beneficial effects:
[0096] Improve development efficiency: With Lua script hot update technology, developers can dynamically update or modify program logic without restarting the program or service, thereby greatly improving development efficiency and program stability;
[0097] Enhanced program flexibility: By supporting dynamic hot updates of Lua scripts, programs gain greater flexibility and scalability. When system upgrades or logic modifications are needed, only the corresponding Lua scripts need to be updated, without modifying the original code.
[0098] Improving user experience: For applications that need to run for a long time, such as online games or cloud services, Lua script hot update technology can achieve seamless updates, avoiding service interruptions caused by updates, thereby greatly improving the user experience.
[0099] Reduced maintenance costs: Because Lua scripts can be dynamically updated, problems can be quickly fixed after they are discovered, avoiding the additional costs of restarting the service. It also reduces the risk of system crashes due to code errors.
[0100] The above description is merely an embodiment of the present invention and does not limit the patent scope of the present invention. Any equivalent modifications made based on the content of the present invention's specification and drawings, or direct or indirect applications in related technical fields, are similarly included within the patent protection scope of the present invention.
Claims
1. A method for supporting dynamic hot update of Lua scripts, characterized in that: The method comprises the steps of: S1, controlling a processor management module to start all static processors; S2, controlling a program export module to obtain open methods of all the static processors and export the open methods as methods that can be called by Lua scripts; S3, inputting hot-updated Lua script resources and controlling a Lua script management module to load the hot-updated Lua script resources; S4, controlling the Lua script management module to call Lua hot-updating logic in the Lua script resources and cover the Lua hot-updating logic on corresponding open methods; The step S1 specifically comprises the steps of: controlling the processor management module to traverse all program sets and register function module processors in the program sets to the processor management module; controlling the processor management module to determine whether the registered processor management module is a static processor, and if yes, starting the static processor; The step S3 specifically comprises the steps of: inputting hot-updated Lua script resources; controlling the Lua script management module to load the hot-updated Lua script resources and parse them into executable codes, and placing the executable codes into a Lua environment; The step S4 specifically comprises the steps of: controlling the Lua script management module to find and call an initialization method that meets the Lua program hot-updating logic in the Lua script resources; matching the initialization method and the open method, and covering the initialization method that completes the matching on the corresponding open method.
2. The method of claim 1, wherein: The step S2 specifically comprises the steps of: controlling the program export module to obtain open methods of all the static processors, and creating corresponding Lua calling interfaces for each of the open methods.
3. A terminal supporting dynamic hot update of Lua scripts, characterized in that: A computer program product, comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to complete the following steps: S1, controlling a processor management module to start all static processors; S2, controlling a program export module to obtain open methods of all the static processors and export the open methods as methods that can be called by Lua scripts; S3, inputting hot-updated Lua script resources and controlling a Lua script management module to load the hot-updated Lua script resources; S4, controlling the Lua script management module to call Lua hot-updating logic in the Lua script resources and cover the Lua hot-updating logic on corresponding open methods; The step S1 specifically comprises the steps of: controlling the processor management module to traverse all program sets and register function module processors in the program sets to the processor management module; controlling the processor management module to determine whether the registered processor management module is a static processor, and if yes, starting the static processor; The step S3 specifically comprises the steps of: inputting hot-updated Lua script resources; controlling the Lua script management module to load the hot-updated Lua script resources and parse them into executable codes, and placing the executable codes into a Lua environment; The step S4 specifically comprises the steps of: The Lua script management module is controlled to search for and call an initialization method conforming to Lua program hot update logic in the Lua script resource; The initialization method and the open method are matched, and the initialization method completing the matching is used to cover the corresponding open method.
4. The terminal supporting dynamic hot update of Lua script according to claim 3, wherein: The step S2 specifically includes steps of: The control program export module acquires open methods of all the static processors, and creates corresponding Lua calling interfaces for each open method.
Citation Information
Patent Citations
Method for dynamic update of iOS (Iphone Operation System) client based on Lua
CN104111855A
Lua-based hot update method for cross-platform application program
CN112181462A