Method, system and device for realizing class interface based on LUA meta-table and medium
By creating an interface class based on the LUA meta table and connecting the first activity to the second activity, the problems of low efficiency in realizing game activities and high maintenance costs are solved, improving code robustness and reducing maintenance difficulty.
Patent Information
- Application Number
- CN202510223109.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-27
- Publication Date
- 2025-07-22
AI Technical Summary
The implementation of game activities has problems of low efficiency and high maintenance costs, and the existing technology has not yet proposed an effective solution.
The interface class is created based on the LUA meta table, and the interface and behavior functions of the first activity are added to the interface class, and the interface of the first activity is connected to the second activity through the interface of the first activity, and the behavior functions of the first activity are called when the second activity is displayed in the game, so that the first activity is displayed as a sub-activity of the second activity.
Improves code robustness, reduces maintenance difficulty, reduces repetitive work, and improves the implementation efficiency of game activities.
Smart Images

Figure CN120353455A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular, to a method, system, device, and medium for implementing class interfaces based on LUA metatables. Background Art
[0002] In game development, based on the design scheme of game activities, developers often need to write programs to implement this series of game activities. Moreover, during the game operation process, game activities are reusable, and special operations in specific activities may also be applied to other activities.
[0003] In the above situation, if each game activity is implemented by writing a separate program, for example, both Activity A and Activity B are implemented by writing separate codes, there will be problems such as high code redundancy and time-consuming and laborious separate writing; if a base class is written and both Activity A and Activity B are derived from the base class, as the activities accumulate, the base class needs to support the characteristics of more activities, the code maintenance difficulty will increase, and it is not easy to modify.
[0004] Currently, there are problems of low efficiency and high maintenance cost in the implementation of game activities in related technologies, and no effective solution has been proposed. Summary of the Invention
[0005] Embodiments of this application provide a method, system, device, and medium for implementing class interfaces based on LUA metatables, so as to at least solve the problems of low efficiency and high maintenance cost in the implementation of game activities in related technologies.
[0006] In a first aspect, embodiments of this application provide a method for implementing class interfaces based on LUA metatables, and the method includes:
[0007] Create an interface class based on the LUA metatable, and add an interface for a first activity and a behavior function corresponding to the interface in the interface class;
[0008] Connect the first activity to a second activity through the interface of the first activity;
[0009] Display the second activity in the game, and at the same time, call the behavior function corresponding to the first activity interface through the second activity, and display the first activity as a sub-activity of the second activity.
[0010] In some embodiments, after creating the interface class based on the LUA metatable, the method includes:
[0011] Add an interface for a preset control and control parameters corresponding to the interface in the interface class;
[0012] Connect the preset control to a preset interface through the interface of the preset control;
[0013] Based on the control parameters corresponding to the preset control interface, monitor the preset control through the preset interface.
[0014] In some embodiments, the method includes:
[0015] The first activity is an activity in the historical version of the game, and the second activity is the activity currently displayed in the game. The program code of the first activity has been stored in the server before the current display.
[0016] In some embodiments, the method includes:
[0017] Rewrite the behavior functions of the activity interfaces added to the interface class.
[0018] In some embodiments, adding an interface of the first activity to the interface class, and the corresponding behavior functions of the interface include:
[0019] Add an interface of the first activity to the interface class, and the corresponding behavior functions of the interface, where the behavior functions include a display call behavior function and a hide call behavior function.
[0020] In a second aspect, an embodiment of the present application provides a system for implementing a class interface based on a LUA metatable. The system includes a creation module, an access module, and a call module;
[0021] The creation module is used to create an interface class using the LUA metatable, add an interface of the first activity to the interface class, and the corresponding behavior functions of the interface;
[0022] The access module is used to access the first activity into the second activity through the interface of the first activity;
[0023] The call module is used to display the second activity in the game, and at the same time call the behavior functions corresponding to the first activity interface through the second activity, and display the first activity as a sub-activity of the second activity.
[0024] In some embodiments, the system includes:
[0025] The creation module is further used to create an interface class using the LUA metatable, add an interface of a preset control to the interface class, and the corresponding control parameters of the interface;
[0026] The access module is further used to access the preset control into a preset interface through the interface of the preset control;
[0027] The calling module is further configured to monitor the preset control through the preset interface according to the control parameters corresponding to the preset control interface.
[0028] In some embodiments, the system includes:
[0029] The first activity is an activity in a historical version of the game, and the second activity is an activity currently displayed in the game. The program code of the first activity has been stored in the server before the current display.
[0030] In a third aspect, an embodiment of the present application provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the method for implementing a class interface based on a LUA metatable as described in the first aspect above is realized.
[0031] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the program is executed by a processor, the method for implementing a class interface based on a LUA metatable as described in the first aspect above is realized.
[0032] Compared with the related art, a method, a system, a device, and a medium for implementing a class interface based on a LUA metatable provided by an embodiment of the present application create an interface class based on the LUA metatable, add an interface of the first activity and a behavior function corresponding to the interface in the interface class; connect the first activity to the second activity through the interface of the first activity; display the second activity in the game, and at the same time, call the behavior function corresponding to the interface of the first activity through the second activity to display the first activity as a sub-activity of the second activity, solving the problems of low efficiency and high maintenance cost in the implementation of game activities, improving the code robustness, reducing the maintenance difficulty, and reducing the repetitive work. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments and descriptions thereof of the present application are used to explain the present application and do not constitute an improper limitation of the present application. In the drawings:
[0034] Figure 1 is a flowchart of the steps of the method for implementing a class interface based on a LUA metatable according to an embodiment of the present application;
[0035] Figure 2 is a schematic diagram of the code for implementing the first activity interface based on a LUA metatable according to an embodiment of the present application;
[0036] Figure 3 is a schematic diagram of the code for rewriting the behavior function of the interface according to an embodiment of the present application;
[0037] Figure 4 It is a schematic code diagram for integrating a first activity into a second activity according to an embodiment of the present application;
[0038] Figure 5 It is a schematic code diagram for calling a first activity behavior function according to an embodiment of the present application;
[0039] Figure 6 It is a block diagram of a system for implementing a class interface based on a LUA metatable according to an embodiment of the present application;
[0040] Figure 7 It is an internal structural schematic diagram of an electronic device according to an embodiment of the present application.
[0041] Description of the drawings: 61. Creation module; 62. Integration module; 63. Call module. Detailed implementation manners
[0042] In order to make the objectives, technical solutions and advantages of the present application more clear and understandable, the present application will be described and explained below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments provided in the present application without creative efforts fall within the scope of protection of the present application.
[0043] Obviously, the accompanying drawings in the following description are only some examples or embodiments of the present application. For those of ordinary skill in the art, the present application can be applied to other similar scenarios based on these drawings without creative efforts. In addition, it can also be understood that although the efforts made in this development process may be complex and lengthy, for those of ordinary skill in the art related to the content disclosed in the present application, some design, manufacturing or production changes based on the technical content disclosed in the present application are only conventional technical means and should not be understood as insufficient disclosure of the content of the present application.
[0044] Referring to "embodiments" in the present application means that specific features, structures or characteristics described in connection with the embodiments can be included in at least one embodiment of the present application. The phrase appears in various positions in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those of ordinary skill in the art explicitly and implicitly understand that the embodiments described in the present application can be combined with other embodiments without conflict.
[0045] Unless otherwise defined, the technical terms or scientific terms involved in this application shall have the ordinary meanings understood by those with ordinary skills in the technical field to which this application belongs. The words such as "a", "an", "one kind", "the" and the like involved in this application do not indicate a quantity limitation and may represent a singular or plural number. The terms "including", "comprising", "having" and any variations thereof involved in this application are intended to cover non-exclusive inclusion; for example, a process, method, system, product or device including a series of steps or modules (units) is not limited to the listed steps or units, but may further include steps or units not listed, or may further include other steps or units inherent to these processes, methods, products or devices. The words such as "connected", "linked", "coupled" and the like involved in this application are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The "multiple" involved in this application means two or more. "And / or" describes the association relationship of associated objects and indicates that three relationships may exist. For example, "A and / or B" may represent: A exists alone, A and B exist simultaneously, and B exists alone. The character " / " generally represents an "or" relationship between the front and rear associated objects. The terms "first", "second", "third" and the like involved in this application are only used to distinguish similar objects and do not represent a specific order for the objects.
[0046] An embodiment of this application provides a method for implementing a class interface based on a LUA metatable. Figure 1 It is a flowchart of the steps of the method for implementing a class interface based on a LUA metatable according to an embodiment of this application, as Figure 1 shown, and this method includes the following steps:
[0047] Step S102, create an interface class based on the LUA metatable, add an interface for the first activity in the interface class, and the corresponding behavior function of the interface;
[0048] Specifically, Figure 2 It is a schematic diagram of the code for implementing the first activity interface based on the LUA metatable according to an embodiment of this application, as Figure 2 shown, use Interface to declare the interface of the first activity (subActView, sub-activity), which has two behavior functions: a display call behavior function (showViewWithSubAct) and a hide call behavior function (hideViewWithSubAct).
[0049] Optionally, Figure 3 It is a schematic diagram of the code for overriding the behavior function of the interface according to an embodiment of this application, as Figure 3As shown, rewrite the behavior functions of the activity interfaces added to the interface class. For example, rewrite the display call behavior function (showViewWithSubAct) for the first activity (subActView, sub-activity).
[0050] Furthermore, when a certain interface needs to implement the functions of a certain control, an interface class can be created based on the LUA metatable, and interfaces for preset controls and the corresponding control parameters of the interfaces can be added to the interface class; the preset controls include touch controls, volume controls, rendering controls, and so on.
[0051] It should be noted that LUA is a small scripting language. The design purpose of this language is to be embedded in application programs to provide flexible extension and customization functions for application programs. LUA scripts can be easily called by C / C++ code and can also call C / C++ functions in turn, which enables LUA to be widely used in application programs. LUA provides very easy-to-use extension interfaces and mechanisms and can be compiled and run on almost all operating systems and platforms. In addition, Interface is a keyword for interface operations in object-oriented programming languages, and its function is to combine the required members to encapsulate a set of certain functions. Interface can also be used in Lua.
[0052] Step S104, connect the first activity to the second activity through the interface of the first activity;
[0053] Specifically, Figure 4 is a schematic diagram of the code for connecting the first activity to the second activity according to the embodiment of the present application, as Figure 4 shown. In addition to connecting the first activity (subActView, sub-activity) to the second activity through the access interface method (Interface:add()), its title (topTitleBox) is also connected.
[0054] Furthermore, when a certain interface needs to implement the functions of a certain control, based on the interfaces of the preset controls implemented based on the existing LUA metatable and the corresponding control parameters, the preset controls can be connected to the preset interface.
[0055] Step S106, display the second activity in the game, and at the same time call the behavior function corresponding to the first activity interface through the second activity to display the first activity as a sub-activity of the second activity.
[0056] Specifically, Figure 5 is a schematic diagram of the code for calling the behavior function of the first activity according to the embodiment of the present application, as Figure 5As shown, after the first sub-activity (subActView) is accessed by the second activity, with the second activity serving as the main activity, when the first activity is called again, the behavior functions corresponding to the interfaces will be actively invoked. For example, the showViewWithSubAct function is used to display the first activity in the form of a sub-activity of the second activity; the hideViewWithSubAct function is used to hide the first activity in the form of a sub-activity of the second activity. It should be noted that the first activity is an activity in the historical version of the game, and the second activity is the currently displayed activity in the game. The program code of the first activity was stored in the server before the current display.
[0057] Furthermore, when a certain interface needs to implement the functions of a certain control, based on the interfaces of the preset controls implemented based on the existing LUA metatables and the corresponding control parameters, the preset controls can be connected to the preset interface, and the preset controls can be monitored through the preset interface based on the control parameters corresponding to the preset control interfaces.
[0058] Through steps S102 to S106 in the embodiments of the present application, the problems of low efficiency and high maintenance cost in the implementation of game activities are solved, the code robustness is improved, the maintenance difficulty is reduced, and the repetitive work is reduced.
[0059] It should be noted that the steps shown in the above process or the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. And although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order than here.
[0060] The embodiments of the present application provide a system for implementing class interfaces based on LUA metatables. Figure 6 It is the structural block diagram of the system for implementing class interfaces based on LUA metatables according to the embodiments of the present application. As Figure 6 shown, the system includes a creation module 61, an access module 62, and a call module 63;
[0061] The creation module 61 is used to create an interface class using the LUA metatable, add the interface of the first activity, and the behavior functions corresponding to the interface in the interface class;
[0062] The access module 62 is used to connect the first activity to the second activity through the interface of the first activity;
[0063] The call module 63 is used to display the second activity in the game, and at the same time, call the behavior functions corresponding to the first activity interface through the second activity, and display the first activity as a sub-activity of the second activity.
[0064] In some of these embodiments, the creation module 61 is further configured to create an interface class using a LUA metatable, add an interface for a preset control and the corresponding control parameters of the interface to the interface class;
[0065] The access module 62 is further configured to access the preset control to a preset interface through the interface of the preset control;
[0066] The call module 63 is further configured to monitor the preset control through the preset interface according to the control parameters corresponding to the preset control interface.
[0067] In some of these embodiments, the first activity is an activity in a historical version of the game, and the second activity is an activity currently displayed in the game. The program code of the first activity has been stored in the server before the current display.
[0068] Through the creation module 61, access module 62, and call module 63 in the embodiments of the present application, the problems of low efficiency and high maintenance cost in the implementation of game activities are solved, the code robustness is improved, the maintenance difficulty is reduced, and the repetitive work is reduced.
[0069] It should be noted that the above-mentioned each module can be a functional module or a program module, and can be implemented either by software or by hardware. For the modules implemented by hardware, the above-mentioned each module can be located in the same processor; or the above-mentioned each module can also be located in different processors in any combined form.
[0070] This embodiment also provides an electronic device, including a memory and a processor. A computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0071] Optionally, the above-mentioned electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the above-mentioned processor, and the input / output device is connected to the above-mentioned processor.
[0072] It should be noted that the specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementation manners, and will not be repeated here.
[0073] In addition, in combination with the method for implementing a class interface based on a LUA metatable in the above embodiments, the embodiments of the present application can be implemented by providing a storage medium. A computer program is stored on the storage medium; when the computer program is executed by a processor, it implements any one of the above methods for implementing a class interface based on a LUA metatable.
[0074] In one embodiment, a computer device is provided, and the computer device may be a terminal. The computer device includes a processor, a memory, a network interface, a display screen, and an input device connected via a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, it implements a method for implementing a class interface based on a LUA metatable. The display screen of the computer device may be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device may be a touch layer covering the display screen, or a button, a trackball, or a touchpad provided on the computer device housing, or an external keyboard, touchpad, or mouse, etc.
[0075] In one embodiment, Figure 7 is a schematic internal structure diagram of an electronic device according to an embodiment of the present application, as Figure 7 shown, an electronic device is provided, and the electronic device may be a server, and its internal structure diagram may be as Figure 7 shown. The electronic device includes a processor, a network interface, an internal memory, and a non-volatile memory connected via an internal bus. Among them, the non-volatile memory stores an operating system, computer programs, and a database. The processor is used to provide computing and control capabilities, the network interface is used to communicate with an external terminal via a network connection, the internal memory is used to provide an environment for the operation of the operating system and computer programs, the computer program is executed by the processor to implement a method for implementing a class interface based on a LUA metatable, and the database is used to store data.
[0076] Those skilled in the art can understand that Figure 7 the structure shown in
[0077] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. This computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above various methods. Among them, any reference to a memory, storage, database, or other medium used in the various embodiments provided in the present application can include non-volatile and / or volatile memories. Non-volatile memories can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memories can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and Rambus dynamic RAM (RDRAM), etc.
[0078] Those skilled in the art should understand that the technical features of the above embodiments can be combined arbitrarily. For the sake of brevity of description, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered as the scope described in this specification.
[0079] The above embodiments merely represent several implementation manners of the present application. The description thereof is relatively specific and detailed, but it should not be construed as a limitation on the scope of the invention patent. It should be noted that for those of ordinary skill in the art, without departing from the concept of the present application, several modifications and improvements can still be made, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application should be subject to the appended claims.
Claims
1. A method for implementing a class interface based on a LUA metatable, characterized in that, The method includes: Create an interface class based on the LUA metatable, add an interface for the first activity and the corresponding behavior function for the interface in the interface class; Connect the first activity to the second activity through the interface of the first activity; Display the second activity in the game, and at the same time call the behavior function corresponding to the interface of the first activity through the second activity to display the first activity as a sub-activity of the second activity.
2. The method according to claim 1, wherein After creating the interface class based on the LUA metatable, the method includes: Add an interface for a preset control and the corresponding control parameters for the interface in the interface class; Connect the preset control to a preset interface through the interface of the preset control; Monitor the preset control through the preset interface based on the control parameters corresponding to the preset control interface.
3. The method according to claim 1, wherein The method includes: The first activity is an activity in a historical version of the game, the second activity is the activity currently displayed in the game, and the program code of the first activity was stored in the server before the current display.
4. The method according to claim 1, wherein The method includes: Rewrite the behavior function of the activity interface added in the interface class.
5. The method according to claim 1, characterized in that, Adding an interface for the first activity and the corresponding behavior function for the interface in the interface class includes: Add an interface for the first activity and the corresponding behavior function for the interface in the interface class, where the behavior function includes a display call behavior function and a hide call behavior function.
6. A system for implementing class interfaces based on LUA metatables, characterized in that, The system includes a creation module, an access module, and a call module; The creation module is used to create an interface class using the LUA metatable, add an interface for the first activity and the corresponding behavior function for the interface in the interface class; The access module is used to connect the first activity to the second activity through the interface of the first activity; The call module is used to display the second activity in the game, and at the same time call the behavior function corresponding to the interface of the first activity through the second activity to display the first activity as a sub-activity of the second activity.
7. The system according to claim 6, wherein The system includes: The creation module is further used to create an interface class using the LUA metatable, add an interface for a preset control and the corresponding control parameters for the interface in the interface class; The access module is further used to connect the preset control to a preset interface through the interface of the preset control; The call module is further used to monitor the preset control through the preset interface according to the control parameters corresponding to the preset control interface.
8. The system according to claim 6, wherein The system includes: The first activity is an activity in a historical version of the game, the second activity is the activity currently displayed in the game, and the program code of the first activity was stored in the server before the current display.
9. An electronic device, comprising a memory and a processor, characterized in that, A computer program is stored in the memory, and the processor is configured to run the computer program to execute the method for implementing a class interface based on the LUA metatable according to any one of claims 1 to 5.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method for implementing a class interface based on the LUA metatable according to any one of claims 1 to 5.