CN114741063A - Programming frame realizing method and system based on Lua language - Google Patents

Programming frame realizing method and system based on Lua language Download PDF

Info

Publication number
CN114741063A
CN114741063A CN202210368525.5A CN202210368525A CN114741063A CN 114741063 A CN114741063 A CN 114741063A CN 202210368525 A CN202210368525 A CN 202210368525A CN 114741063 A CN114741063 A CN 114741063A
Authority
CN
China
Prior art keywords
observed person
observer
main thread
event
module
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202210368525.5A
Other languages
Chinese (zh)
Other versions
CN114741063B (en
Inventor
宋润强
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shandong Chizicheng Network Technology Co ltd
Original Assignee
Shandong Chizicheng Network Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shandong Chizicheng Network Technology Co ltd filed Critical Shandong Chizicheng Network Technology Co ltd
Priority to CN202210368525.5A priority Critical patent/CN114741063B/en
Publication of CN114741063A publication Critical patent/CN114741063A/en
Application granted granted Critical
Publication of CN114741063B publication Critical patent/CN114741063B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/315Object-oriented languages
    • AHUMAN NECESSITIES
    • A63SPORTS; GAMES; AMUSEMENTS
    • A63FCARD, BOARD, OR ROULETTE GAMES; INDOOR GAMES USING SMALL MOVING PLAYING BODIES; VIDEO GAMES; GAMES NOT OTHERWISE PROVIDED FOR
    • A63F13/00Video games, i.e. games using an electronically generated display having two or more dimensions
    • A63F13/60Generating or modifying game content before or while executing the game program, e.g. authoring tools specially adapted for game development or game-integrated level editor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Multimedia (AREA)
  • Computing Systems (AREA)
  • Stored Programmes (AREA)

Abstract

The invention relates to a programming framework implementation method and a system based on Lua language, wherein the method comprises the following steps: identifying an observer mode method in current programming code while a main thread sequentially executes the programming code written based on the Lua language inputted through an editor; in response to identifying the observer pattern method, determining an observer and an observed person from the indicators; establishing a subscription relationship between the observer and the observed person; responding to the subscription relationship, the observer monitors the observed person and receives an event when the observed person sends the event; and generating an event in response to the completion of the execution of the programming code corresponding to the observed person, and sending the event to the observer. The programming framework realized by the invention reduces the blockage of the main thread and effectively improves the operating efficiency of the editor; the game developed based on the programming framework realized by the invention can provide good experience for the user when running on the user equipment.

Description

Programming frame realizing method and system based on Lua language
Technical Field
The invention relates to the technical field of application development, in particular to a programming framework implementation method and system based on Lua language.
Background
In a sense, a programming framework refers to the underlying services that implement the full functionality common to a certain application domain and provide business writing logic. The programming personnel can use the frames to start specific application development on the basis that a general function is realized, the programming frames complete some basic works, the programming personnel only need to concentrate on finishing the business logic design of the application according to certain requirements and rules, convenience is provided for the programming development work to a great extent, and the business logic written by using the frames is simpler and easier to read.
In the field of game development, a programming framework provided by game development tools used by game developers, such as Cocos2D, Cocos3D, LibGDX, Unity, and the like, enables the game developers to flexibly use various components, tools, plug-ins, and the like to complete game development. Among many development tools, Unity is increasingly used by game developers due to its comprehensive and powerful functions, low difficulty in development and learning, cross-platform capability, and the like.
Although Unity is powerful, it also has many drawbacks. For example, as is well known, the problem of slow resource loading is caused because most resource loading is executed on the main thread due to logic inside the Unity engine, and even if some loading work can be executed on the loading thread, much work in the process needs to be completed by the main thread, so that the pressure of the main thread is not reduced, and the main thread is not only slow in loading and inefficient, but also frequently blocked. For another example, all processing operations of the editor during game running are in the same thread, and due to the defects in resource management and logic, the running efficiency of the editor is very low, and when the developed game is installed on a user terminal to run, the user terminal is stuck and generates heat, and the user experience is poor.
Disclosure of Invention
Aiming at the technical problems in the prior art, the invention provides a programming framework implementation method and system based on the Lua language, which are used for improving the application development efficiency and improving the user experience of developed games.
In order to solve the technical problem, according to an aspect of the present invention, the present invention provides a programming framework implementation method based on the Lua language, including the following steps:
identifying an observer mode method in current programming code when the main thread sequentially executes the programming code written based on the Lua language inputted through an editor;
in response to identifying the observer pattern method, determining an observer and an observed person from the indicators;
establishing a subscription relationship between the observer and the observed person;
in response to the subscription relationship, the observer listens to the observed person and receives an event when the observed person sends the event; and
an event is generated in response to the completion of the execution of programming code corresponding to the observed person and sent to the observer.
According to one aspect of the invention, the invention provides a programming framework implementation system based on a Lua language, which comprises a main thread module, a role determination module, a subscription module and an observed person module, wherein the main thread module is configured to run programming codes which are input through an editor and written based on the Lua language in a main thread sequence, monitor an observed person and receive events sent by the observed person; the role determination module is connected with the main thread module and is configured to determine an observer and an observed person according to an indicator in an observer mode method provided in programming code; the subscription module is respectively connected with the identity determination module and the main thread module and is configured to establish or release a subscription relationship between the observer and the observed person; the observed person module is connected with the identity determination module and configured to run programming code corresponding to the observed person, generate an event after the running, and send the event to the observer.
The programming frame realized based on the method replaces the original coroutine by asynchronous operation when running the programming code, realizes multithreading, reduces the blockage to the main thread of the observed person, and has no performance consumption, thereby effectively improving the running efficiency of the editor; when the game developed based on the programming framework provided by the invention runs on user equipment, no or little unrecoverable garbage is generated, the memory occupation is small, the cost is low, and the time consumption is low, so that the phenomena of jamming and equipment heating are avoided, and the user experience is improved.
Drawings
Preferred embodiments of the present invention will now be described in further detail with reference to the accompanying drawings, in which:
FIG. 1 is a flowchart of a programming framework implementation method based on the Lua language according to an embodiment of the present invention;
FIG. 2 is a functional block diagram of a Lua language-based programming framework implementation system according to one embodiment of the present invention;
FIG. 3 is a functional block diagram of a thread module according to one embodiment of the invention;
FIG. 4 is a functional block diagram of a main thread module according to another embodiment of the present invention;
FIG. 5 is a functional block diagram of a main thread module and an observed person module according to yet another embodiment of the present invention;
FIG. 6 is a functional block diagram of a subscription module according to one embodiment of the invention;
FIG. 7 is a functional block diagram of a programming framework implementation system based on the Lua language according to another embodiment of the present invention;
FIG. 8A is a display of performance test data for game A developed based on the existing Unity official development tool; and
FIG. 8B is a performance test data display of game B developed based on the development tools of the programming framework provided by the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In the following detailed description, reference is made to the accompanying drawings that form a part hereof and in which is shown by way of illustration specific embodiments of the application. In the drawings, like numerals describe substantially similar components throughout the different views. Various specific embodiments of the present application are described in sufficient detail below to enable those skilled in the art to practice the teachings of the present application. It is to be understood that other embodiments may be utilized and structural, logical or electrical changes may be made to the embodiments of the present application.
The programming framework implemented by the present invention supports programmers to program in an editor of a development tool using an observer pattern approach. The programmer writes program codes in the Lua language in the editor, defines the observer and the observed person by using specific indicators, and the programming framework performs corresponding processing according to the preset indicator meanings after identifying the indicators, so that the purposes of asynchronous operation, multithread processing and the like can be achieved.
Fig. 1 is a flowchart of a method for implementing a programming framework based on the Lua language, according to an embodiment of the present invention, where the method includes the following steps:
in step S1, a main thread is created and waits for an execution instruction of the programmer for the programming code input via the editor.
In step S2, after obtaining the operating instruction of the programmer, the programming code written based on the Lua language and input by the editor is sequentially executed in the main thread. In one embodiment, the running programming code is one or more pieces of script for performing one or more functions. Because the Lua language has the advantages of small magnitude, high performance, no limitation on a programming paradigm and the like, the script in the invention is written by the Lua language. The programmer may run his script after writing a script, or may run all scripts in the editor after writing several scripts for different functions in sequence. The invention executes the script in sequence through the created main thread.
In step S3, it is determined whether an observer mode method is provided in the current programming code, and if the observer mode method is provided in the current programming code, step S4 is performed. If not, it is determined in step S10 whether the main thread is finished, if not, the method returns to step S2 to continue executing the programming code inputted by the editor, and if the main thread is finished, that is, the current coding code is run completely, the method is finished.
In step S4, the observer and observed person are determined according to the indicators in the method.
Step S5, a subscription relationship is established between the observer and the observed person. After the subscription relationship is established between the observer and the observed person, in step S7, the observer listens to the observed person and listens to whether the observed person sends an event.
Step S6, the observed person is executed.
And step S61, determining whether the execution of the observed person is completed, if not, returning to step S6, and if the execution is completed, generating an event in step S62 and sending the event to the observer.
Step S8, determining whether the observer receives the event sent by the observed person. In one embodiment, the main thread may be used as an observer, and after the main thread establishes a subscription relationship with one or more observed persons, the observed person is listened to, and when it is listened to that an observed person sends an event, the event is received. Thus, it is determined in step S8 whether the event sent by the observed person is received, and if so, the subscription relationship between the main thread and the observed person is released in step S9, and the process returns to step S2. If the event sent by the observed person is not received, the listening to the observed person is continued in step S7.
There may be multiple observed persons in the process of executing the script code by the main thread, and thus, in one embodiment, the main thread maintains a corresponding list of the observed persons and the observed persons, and identifies an observed person and a corresponding observed person in an event generated when each observed person finishes executing, so that when the main thread monitors an event, the corresponding observed person and which observer should send the event to are determined according to an observer identifier and an observed person identifier in the event.
In the foregoing step S6, the observed person may execute in a newly created thread or a main thread, if necessary. The observed party may be in any form, such as network request, timing, delay, obtaining certain data, obtaining certain event, various data processing to be performed, etc.
For example, the programmer writes the code in the editor as shown in table 1 below and runs the code.
TABLE 1
Figure BDA0003582784820000061
When the main thread executes the above programming code, the observer mode method is provided by recognizing the current programming code through the first line "game. The method comprises the steps that a word ' observer ' is used as an indicator of an observer mode method, a current main thread is determined to be an observer according to the word ' Game ' in front of the observer, the network operation of a get request is determined to be an observed person according to the word ' WWW.get ' behind the observer, and the specific content of the request is ' http:// google. In this embodiment, a programmer adopts "Subscribe" as a subscription instruction or identifier in programming code to establish a subscription relationship between a main thread and a network operation of a get request, and this embodiment defines a declaration process of events by using action and Func < > of Unity, thereby declaring that x is returned when the get request is successful and ex is returned when the get request is failed. Since Action supports all data types, there is no problem that coroutines cannot return parameters, so that the event becomes a carrier for communication between the observer and the observed person.
Typically, the network operations in Unity (e.g., HTTP get or HTTP post) used to handle HTTP protocol needs to be completed using WWW and Coroutine. The WWW is an object of HTTP encapsulation, and Coroutine can be considered as a return value that is a function of the ietumerator, whose purpose is to open another piece of logical processing in the main thread, but unlike multithreading, Coroutine is executed inside the main thread. Specifically, a coroutine is a method of MonoBehaviour that can start a coroutine, each with an entry function, which must be an ietumerator-as-return method (entry function), interrupted with yield keys. Thus, it can be seen that the coroutine return value type must be IEnumerator, not any other value, and that coroutines cannot handle exceptions because the yield return statement cannot be surrounded by the try-catch structure. When completing operations such as network operations, coroutines are required to be completed in the main thread, and various operations are tightly coupled, thereby resulting in huge single IEnumerators. The invention solves the problem, and the observer mode provided by the invention can realize the observed person asynchronously, and the operation is safer and more efficient. By taking the foregoing code example as an example, through the framework implemented by the present invention, a network operation of get request whose request content is "http:// google. And generating an event when the network operation is completed, wherein the event return value is x when the operation is successful, and the event return value is ex when the operation is failed. And when the main thread receives the event and the return value thereof, determining that the network operation is finished, and then releasing the subscription relation between the main thread and the network operation as the observed person. Therefore, when the frame realized by the invention runs the programming code, the coroutine is replaced by asynchronous operation, the blockage of the main thread where the observed person is positioned is reduced, various operations in the main thread are decoupled, and no performance consumption exists, so that the running efficiency of the editor is effectively improved.
As can be seen from the above embodiments, since the programming framework implemented by the present invention can implement asynchronous operation, it is also able to access game objects and process game data through multiple threads. Such as shown in table 2. Two observer mode methods are included in Table 2, wherein items 1-3 are a method for implementing multi-threading, and wherein start () indicates that an observed person is a method that needs to be executed on an asynchronous thread, and is operative to put the method that needs to be executed asynchronously on the asynchronous thread, thereby implementing multi-threading. The observed person in the 4 th-7 th method is a timer that implements a timing period of 3 seconds. Any function method in the first observer mode method can be executed by Start () on an asynchronous thread, i.e., in a new thread outside of one main thread, and the timer in the second observer mode method is executed in another new thread independent of the main thread. The threads except the main thread are collectively referred to as the second threads, and the embodiment includes two second threads, and the function method and the timer with the timing period of 3 seconds, which are respectively used for realizing all business logic of the game code, can be put into the second threads and asynchronously executed with the main thread. In addition, the subscription relationship between the observer and the observed person may be established according to the subscription identifier, or the subscription relationship between the observer and the observed person may be established when the observed person needs to feed back an event to the observer without the subscription identifier.
TABLE 2
Figure BDA0003582784820000081
It can be seen from the foregoing embodiments that the programming framework implemented by the present invention implements a new chain programming structure (script codes implementing different functions are connected by semicolons, and a chain programming structure is formed by multiple script codes from top to bottom).
In order to reduce performance consumption as much as possible, after the observed person finishes executing, and the main thread receives the event sent by the observed person after finishing executing, the subscription relationship between the main thread and the observed person needs to be released in time. The subscription relationship between the main thread and the observed person can be released in various ways, for example, when the unsubscribe identifier is included in the observer pattern method, as shown in the codes "in lines 3 and 7 of table 2: addto (this) ", after sending an event generated in response to the completion of the execution of the programming code corresponding to the observed person to the main thread, releasing the subscription relationship between the main thread and the observed person while the current script ends, that is, the subscription relationship between the main thread and the observed person and the current script end at the same time. In another mode, when the main thread sequentially executes the programming codes input by the editor, after the programming codes corresponding to the observer pattern method are executed, the subscription relationship between the main thread and the observed person is released according to an instruction for releasing the subscription relationship with the observed person in the sequentially executed programming codes. As shown in table 3 below:
TABLE 3
Figure BDA0003582784820000091
The code of the aforementioned lines 1-6 is a piece of code input in the editor, and when the main thread executes the piece of code, the corresponding observed person is determined by the observer mode method identified in line 1, and in this embodiment, the observed person is a series of data processing, such as input of line 1, filtering odd numbers of the second line, and splicing a sentence character string ' whow do we employ a character string ' behind a character string composed of all numbers in the third line, insertion of the fourth line '! ", sixth line. When the observed person is determined, establishing a subscription relationship between the main thread and the observed person and determining returned content (printing the content determined after the foregoing processing in an editor). According to the code on line 5, it is defined in the code that the method is executed in the main thread, and thus the data processing corresponding to the observed person in the embodiment is performed in the main thread. When the codes are executed completely, the main thread executes the programming codes in sequence, and the subscription relation between the data processing operations and the main thread is cancelled according to the instruction of the 7 th line.
By releasing the subscription relationship between the main thread and the observed person in time, the main thread does not need to monitor the observed person any more, thereby saving the consumption of system performance.
In step S1, when the program code input via the editor is sequentially executed in the main thread, a reaction sequence is generated according to the event-driven relationship in the program code. For example, in the present invention, an observed person notifies an observer through an event, the observer reacts after receiving the event and performs corresponding logic processing, the process is a reaction, and a plurality of reaction processes having an event-driven relationship are represented as a chain structure, thereby forming a reaction sequence. As another example, when UI programming is performed using components of the UGUI, click events, value changes, etc. that are listened to the UI by an event-driven mechanism are represented as a sequence of reactions. Thus, the present invention maintains one or more reaction sequences. For example, all event-driven relationships during the course of running each frame of a game may be represented as one reaction sequence, and thus the present invention maintains a plurality of reaction sequences, each corresponding to a game frame. As another example, the present invention may derive a sequence of responses according to the time at which an event-driven relationship occurs or the thread in which the event occurs. Based on the reaction sequence, the invention can provide functions which cannot be provided in the original Unity, such as clicking, double clicking, connecting points, shielding quick clicking and the like. Such as the codes shown in table 4.
TABLE 4
Figure BDA0003582784820000101
It can be seen from the above codes that, when the observed person obtaining the data returned by processing each frame is executed, instead of returning all the data processed by each frame in a manner commonly used by Unity, the observed person queries the specified reaction in the present frame from the reaction sequence of the present frame according to the query instruction where (), and returns the relevant data in the specified reaction according to the requirement in the query instruction. When the system maintains a plurality of reaction sequences according to the game frame, firstly, the reaction sequence corresponding to the current frame is found, then, according to the specified reaction in the query instruction, as shown in table 4, the specified reaction in the where is "input.
For another example, see table 5:
TABLE 5
Figure BDA0003582784820000111
In the present embodiment, a text display component mText is used as an observer, an input box component mlnput is used as an observed person, a change in a value in an input box is observed, a value of the input box is obtained by a Where method and is processed and checked, and after Delay of 1 second by Delay, the Delay is sent to the mText text display component through an event for display.
It can be seen from the above embodiments that, in the present invention, in combination with language integrated query (Linq), when necessary, data can be obtained in a targeted manner in combination with a query instruction composed of a Linq query operator. As the Linq query operator can retrieve data from different data sources and structured data in different formats, mismatching between a programming language and a database is eliminated, the Linq query result can be directly returned without format conversion of the result, and the use is convenient.
Fig. 2 is a schematic block diagram of a Lua language-based programming framework implementation system according to an embodiment of the present invention, where the system includes a main thread module 1, a role determination module 2, a subscription module 3, and an observed person module 4, where the main thread module 1 runs programming codes written based on the Lua language input through an editor in a main thread sequence, listens to an observed person, and receives an event sent by the observed person. The role determination module 2 is connected to the main thread module 1 and is configured to determine the observer and observed person according to the indicators in the method when the observer pattern method is provided in the current programming code running in the main thread. The subscription module 3 is respectively connected with the main thread module 1, the identity determination module 2 and the observed person module 4, and establishes or releases a subscription relationship between the observer and the observed person. The observed person module 4 is connected to the identity determining module 2 and the main thread module 1, and is configured to run a programming code corresponding to the observed person, generate an event after the running is completed, and send the event to an observer in the main thread module 1.
FIG. 3 is a functional block diagram of a main thread module according to one embodiment of the invention. In this embodiment, the main thread module 1 includes a main thread unit 11 and a snoop unit 12. The main thread unit 11 is used to create a main thread, and sequentially execute the programming code written based on the Lua language inputted by the editor in the main thread, and send a notification to the role determination module when executing the observer mode method into the current programming code. The monitoring unit 12 is connected to the subscribing module 3 and the observed person module 4, and when receiving a subscription notification that a subscription relationship is established between an observer (such as the main thread) and an observed person and is sent by the subscribing module 3, monitors and receives an event sent by the observed person, and notifies the main thread unit 11 after receiving the event sent by the observed person module 4.
FIG. 4 is a functional block diagram of a main thread module according to another embodiment of the present invention. In this embodiment, the main thread module 1 further includes an execution mode identification unit 13, in addition to the main thread unit 11 and the listening unit 12, connected to the main thread unit 11, and configured to obtain an execution mode of the observed person from the observer mode method, where the execution mode includes executing the observed person in the main thread or executing the observed person in the second thread. When an observed person needs to be executed in a main thread, the main thread module 1 further includes an observed person unit 14 and a first event unit 15, the observed person unit 14 is connected to the main thread unit 11 and the execution manner identifying unit 13, respectively, and when the execution manner identifying unit 13 identifies that the observed person needs to be executed in the main thread, the observed person unit 14 is sent to the execution manner. The observed person unit 14 records the observed person and runs programming code corresponding to the observed person in the main thread. Upon completion of the execution by the observed person, the first event unit 15 is notified to generate a first event. The first event element 15 is connected to the observed person element 14, and when receiving the notification of the observed person element 14, generates a first event on demand and sends the first event to the listening element 12. The snoop unit 12 receives the first event and returns it to the main thread execution unit 11.
Fig. 5 is a functional block diagram of a main thread module and an observed person module according to yet another embodiment of the present invention. In this embodiment, the main thread module 1 includes a main thread unit 11, a listening unit 12, and an execution manner identification unit 13, and the observed person module includes a second thread unit 41 and a second event unit 42. When the execution manner of the observed person acquired by the execution manner recognition unit 13 from the observer pattern method is that the observed person is executed in the second thread, a notification is sent to the second thread unit 41. Upon receiving the notification, the second thread unit 41 creates a new thread, referred to herein as a second thread, in which the observed person is executed. The sending of the notification to the second event unit 42 is performed when the performance of the observed person is completed. The second event unit 42 generates a corresponding second event when the second thread runs the programming code corresponding to the observed person, and sends the corresponding second event to the listening unit 12 in the main thread module 1. The second thread unit 41 may create one or more second threads as needed for executing the programming codes input by the programmer via the editor in an asynchronous and multi-threaded manner.
FIG. 6 is a functional block diagram of a subscription module according to one embodiment of the invention. The subscription module 3 includes a subscription relationship establishing unit 31 and a subscription relationship releasing unit 32, where the subscription relationship establishing unit 31 is connected to the identity determining module 2, and when the identity determining module 2 determines an observer and an observed person, a subscription relationship is established between the observer and the observed person. The subscription relation releasing unit 32 is connected to the main thread module 1 and the observed person module 4, and configured to release the subscription relation between the main thread and the observed person according to an instruction from the observed person module 4 or the main thread module 1. After receiving the first event sent by the first event unit 15 from the monitoring unit 12 as shown in fig. 4, or after receiving the second event sent by the second event unit 15 from the monitoring unit 12 as shown in fig. 5, the main thread unit 11 sends a releasing instruction to the subscription relation releasing unit 32, where the releasing instruction includes the identifiers of the observer and the observed person. The subscription relation removing unit 32 removes the subscription relation between the observed person and the main thread according to the removing instruction, and notifies the monitoring unit 12. The listening unit 12 does not listen to the observed person any more after receiving the notification.
Fig. 7 is a schematic block diagram of a programming framework implementation system based on the Lua language according to an embodiment of the present invention, and compared with fig. 2, the present embodiment further includes a reaction sequence generating module 5, which is connected to the main thread module 1 and the observed person module 4, and is configured to generate a reaction sequence according to an event-driven relationship in the programming code when the main thread or the second thread runs the programming code. When the observed person unit 14 in the main thread module 1 or the second thread in the observed person module 4 executes the observed person, and when the programming code of the observed person includes the query instruction, the specified reaction is queried in the reaction sequence, and corresponding data in the specified reaction is returned to the corresponding main thread or the second thread according to the requirement, so that corresponding data can be obtained in a targeted manner, and not only is system consumption saved, but also data processing efficiency is improved.
Based on the programming framework realized by the invention, when a programmer carries out game programming on an editor of a development tool, multithreading and asynchronous operation can be realized, the blockage to a main thread is reduced, and no performance consumption exists, so that the operating efficiency of the editor is effectively improved, the development efficiency is improved, and the game development process is greatly shortened.
Fig. 8A is a performance test data display diagram of a game a developed based on an existing Unity official development tool, and fig. 8B is a performance test data display diagram of a game B developed based on a development tool of a programming framework provided by the present invention. By comparison, the game a developed based on the development tool provided by the Unity authority generates a lot of garbage (such as a plurality of gc (garpage collection) peaks indicated in the figure) which cannot be recovered during the running process, while the game B developed by the development tool applying the programming framework provided by the invention generates almost no garbage which cannot be recovered during the running process. Regarding the memory occupied by the main thread, compared with the game A, the occupation of the memory by the game B is greatly reduced, the overhead (overheads) of the game A is huge, and the overhead of the game B is zero; comparing the elapsed time for each frame, game A is 14.6 milliseconds per frame, while game B is 0.37 milliseconds per frame. Therefore, the frame editing can effectively avoid the situations of blocking, heating and the like when the game runs at the user terminal, thereby providing good experience for the user.
The above embodiments are provided only for illustrating the present invention and not for limiting the present invention, and those skilled in the art can make various changes and modifications without departing from the scope of the present invention, and therefore, all equivalent technical solutions should fall within the scope of the present invention.

Claims (14)

1. A programming framework implementation method based on Lua language comprises the following steps:
identifying an observer mode method in current programming code when the main thread sequentially executes the programming code written based on the Lua language inputted through an editor;
in response to identifying the observer pattern method, determining an observer and an observed person from the indicators;
establishing a subscription relationship between the observer and the observed person;
responding to the subscription relationship, the observer monitors the observed person and receives an event when the observed person sends the event; and
an event is generated in response to the completion of the execution of programming code corresponding to the observed person and sent to the observer.
2. The method of claim 1, wherein in response to identifying an observer pattern method, further comprising: acquiring an execution mode of an observed person from the observer mode method;
in response to the observer pattern method defining that the observed person is executed in a main thread, sequentially executing programming code corresponding to the observed person in the main thread; and
in response to the observer mode method not defining the observed person to be executed in a main thread, or creating a new thread based on an asynchronous process identifier in the observer mode method, programming code corresponding to the observed person is executed in the new thread.
3. The method of claim 1, wherein in response to identifying an observer pattern method, further comprising: and in response to the recognition of the unsubscribe identifier, after the event generated in response to the completion of the execution of the programming code corresponding to the observed person is sent to the observed person, releasing the subscription relationship between the observed person and the observer.
4. The method according to claim 1, wherein when the main thread sequentially executes the programming codes input by the editor, after the programming codes corresponding to the observer pattern method are executed, the subscription relationship between the observer and the observed person is released according to an instruction for releasing the subscription relationship between the observer and the observed person in the sequentially executed programming codes.
5. The method of claim 1, further comprising: when the main thread sequentially executes the programming code input by the editor, a reaction sequence is generated according to the event-driven relation in the programming code.
6. The method of claim 5, wherein in executing programming code corresponding to the observed person further comprises: and inquiring specified reactions in the reaction sequence according to the inquiry instructions in the programming codes, and returning data which accords with the inquiry instructions in the specified reactions to corresponding observers through generated events.
7. The method of claim 6, wherein the query instruction consists of a Linq query operator.
8. A programming framework implementation system based on Lua language comprises:
the main thread module is configured to run programming codes which are input through an editor and written based on the Lua language in the main thread sequence, monitor the observed person and receive events sent by the observed person;
a role determination module, coupled to the main thread module, configured to determine observers and observed persons according to indicators in an observer pattern method provided in programming code;
a subscription module, respectively connected to the identity determination module and the main thread module, configured to establish or release a subscription relationship between the observer and the observed person; and
an observed person module, connected with the identity determination module, configured to run programming code corresponding to the observed person, generate an event upon completion of the running and send the event to the observer.
9. The system of claim 8, wherein the main thread module comprises:
a main thread unit configured to create a main thread, and sequentially execute a programming code written based on a Lua language inputted through an editor in the main thread, and transmit a notification to the role determination module when executing an observer mode method into a current programming code; and
the monitoring unit is configured to monitor and receive an event sent by the observed person when a subscription relationship is established between the observed person and the observer, and notify the main thread unit after receiving the event.
10. The system of claim 9, wherein the main thread module further comprises an execution mode identification unit, coupled to the main thread unit, configured to obtain an observed person execution mode from the observer pattern method, the execution mode comprising executing the observed person in a main thread or executing the observed person in a secondary thread.
11. The system of claim 10, wherein the main thread module comprises:
an observed person unit connected with the main thread unit and configured to run programming code corresponding to the observed person in a main thread; and
and the first event unit is connected with the observed person unit, generates a first event when the programming code of the observed person finishes the running of a main thread, and sends the first event to the monitoring unit.
12. The system of claim 10, wherein the observed person module comprises:
a second thread unit connected with the execution manner identification unit, configured to create a second thread when an observed person is executed in the second thread, and run a programming code corresponding to the observed person in the second thread; and
and the second event unit is connected with the second thread execution unit, generates a corresponding second event when the second thread runs the programming code corresponding to the observed person, and sends the corresponding second event to the monitoring unit.
13. The system of claim 8, wherein the subscription module comprises:
a subscription relationship establishing unit configured to establish a subscription relationship between an observed person and the observer when the identity determining module determines the observed person; and
the subscription relation removing unit is respectively connected with the main thread module and the observed person module and is configured to remove the subscription relation between the observed person and the observed person according to an instruction from the observed person module or the main thread module.
14. The system of claim 8, further comprising a reaction sequence generation module, coupled to the main thread module, configured to generate a reaction sequence according to event-driven relationships in programming code.
CN202210368525.5A 2022-04-06 2022-04-06 Method and system for realizing programming framework based on Lua language Active CN114741063B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210368525.5A CN114741063B (en) 2022-04-06 2022-04-06 Method and system for realizing programming framework based on Lua language

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210368525.5A CN114741063B (en) 2022-04-06 2022-04-06 Method and system for realizing programming framework based on Lua language

Publications (2)

Publication Number Publication Date
CN114741063A true CN114741063A (en) 2022-07-12
CN114741063B CN114741063B (en) 2023-08-22

Family

ID=82280148

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210368525.5A Active CN114741063B (en) 2022-04-06 2022-04-06 Method and system for realizing programming framework based on Lua language

Country Status (1)

Country Link
CN (1) CN114741063B (en)

Citations (17)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP1056007A2 (en) * 1999-05-28 2000-11-29 Lucent Technologies Inc. System and method of exchanging information between software modules
US20040093605A1 (en) * 1998-11-13 2004-05-13 Alverson Gail A. Accessing a collection of data items in a multithreaded environment
US20070208832A1 (en) * 2006-01-31 2007-09-06 Bea Systems, Inc. RFID edge server allowing configuration updates without restart
US20110191784A1 (en) * 2010-02-02 2011-08-04 Microsoft Corporation Processing observable events using join patterns
US20120047519A1 (en) * 2010-08-18 2012-02-23 Sas Institute Inc. Techniques to remotely access object events
US20120084749A1 (en) * 2010-10-01 2012-04-05 Microsoft Corporation Programming language support for reactive programming
CN102804161A (en) * 2009-04-03 2012-11-28 社会传播公司 Application sharing
CN103268567A (en) * 2013-03-25 2013-08-28 中国科学院沈阳自动化研究所 Manufacturing management system-oriented high-efficiency large-scale event detection and handling method
CN106648816A (en) * 2016-12-09 2017-05-10 武汉斗鱼网络科技有限公司 Multithread processing system and multithread processing method
CN109254819A (en) * 2018-08-30 2019-01-22 深圳大势智能科技有限公司 Interface updating method, system, equipment and storage medium based on android system
CN109284098A (en) * 2018-09-25 2019-01-29 四川长虹电器股份有限公司 Method based on RxJava building event bus RxBus
US10223176B1 (en) * 2017-10-13 2019-03-05 Amazon Technologies, Inc. Event handler nodes for visual scripting
CN109582536A (en) * 2018-11-05 2019-04-05 广州华多网络科技有限公司 Report method, device and computer equipment of the application program without response
US10423390B1 (en) * 2015-06-04 2019-09-24 The Mathworks, Inc. Systems and methods for generating code for models having messaging semantics
CN111090423A (en) * 2019-11-26 2020-05-01 苏州思必驰信息科技有限公司 Webhook framework system and method for realizing active calling and event triggering
CN111695061A (en) * 2019-03-15 2020-09-22 北京京东尚科信息技术有限公司 Resource processing method and device, equipment and storage medium
CN114217988A (en) * 2021-12-09 2022-03-22 中信银行股份有限公司 Response type responsibility chain mode data processing method based on IO processing

Patent Citations (17)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040093605A1 (en) * 1998-11-13 2004-05-13 Alverson Gail A. Accessing a collection of data items in a multithreaded environment
EP1056007A2 (en) * 1999-05-28 2000-11-29 Lucent Technologies Inc. System and method of exchanging information between software modules
US20070208832A1 (en) * 2006-01-31 2007-09-06 Bea Systems, Inc. RFID edge server allowing configuration updates without restart
CN102804161A (en) * 2009-04-03 2012-11-28 社会传播公司 Application sharing
US20110191784A1 (en) * 2010-02-02 2011-08-04 Microsoft Corporation Processing observable events using join patterns
US20120047519A1 (en) * 2010-08-18 2012-02-23 Sas Institute Inc. Techniques to remotely access object events
US20120084749A1 (en) * 2010-10-01 2012-04-05 Microsoft Corporation Programming language support for reactive programming
CN103268567A (en) * 2013-03-25 2013-08-28 中国科学院沈阳自动化研究所 Manufacturing management system-oriented high-efficiency large-scale event detection and handling method
US10423390B1 (en) * 2015-06-04 2019-09-24 The Mathworks, Inc. Systems and methods for generating code for models having messaging semantics
CN106648816A (en) * 2016-12-09 2017-05-10 武汉斗鱼网络科技有限公司 Multithread processing system and multithread processing method
US10223176B1 (en) * 2017-10-13 2019-03-05 Amazon Technologies, Inc. Event handler nodes for visual scripting
CN109254819A (en) * 2018-08-30 2019-01-22 深圳大势智能科技有限公司 Interface updating method, system, equipment and storage medium based on android system
CN109284098A (en) * 2018-09-25 2019-01-29 四川长虹电器股份有限公司 Method based on RxJava building event bus RxBus
CN109582536A (en) * 2018-11-05 2019-04-05 广州华多网络科技有限公司 Report method, device and computer equipment of the application program without response
CN111695061A (en) * 2019-03-15 2020-09-22 北京京东尚科信息技术有限公司 Resource processing method and device, equipment and storage medium
CN111090423A (en) * 2019-11-26 2020-05-01 苏州思必驰信息科技有限公司 Webhook framework system and method for realizing active calling and event triggering
CN114217988A (en) * 2021-12-09 2022-03-22 中信银行股份有限公司 Response type responsibility chain mode data processing method based on IO processing

Non-Patent Citations (5)

* Cited by examiner, † Cited by third party
Title
LIGHTSONG: "lua OOP实现对象的链式调用", pages 1 - 5 *
RICO_WANG: "优雅的函数式编程【链式调用】", pages 1 - 3 *
前端学习站: "JavaScript中的链式操作", pages 1 - 5 *
夢曉DE光: "Unity子线程与主线程交互二(事件监听)", 《HTTPS://BLOG.CSDN.NET/QQ_34987964/ARTICLE/DETAILS/107318813》 *
夢曉DE光: "Unity子线程与主线程交互二(事件监听)", 《HTTPS://BLOG.CSDN.NET/QQ_34987964/ARTICLE/DETAILS/107318813》, 13 July 2020 (2020-07-13), pages 1 - 7 *

Also Published As

Publication number Publication date
CN114741063B (en) 2023-08-22

Similar Documents

Publication Publication Date Title
US7380239B1 (en) Method and mechanism for diagnosing computer applications using traces
CN107818431B (en) Method and system for providing order track data
CN105138312B (en) A kind of table generation method and device
CN112000350B (en) Dynamic rule updating method, device and storage medium
Wolf et al. Efficient pattern search in large traces through successive refinement
CN110737437A (en) compiling method and device based on code integration
CN113434396A (en) Interface test method, device, equipment, storage medium and program product
CN110865854B (en) Interface calling and arranging method supporting hot deployment
CN109828759B (en) Code compiling method, device, computer device and storage medium
CN112825068B (en) Data blood margin generation method and device
WO2016190869A1 (en) Determining potential test actions
CN114741063A (en) Programming frame realizing method and system based on Lua language
CN112084111A (en) Data processing method, system and device
CN111126008A (en) XSD-based code generation method and device, computer equipment and storage medium
US20220382776A1 (en) Message templatization for log analytics
CN114461454A (en) Data recovery method and device, storage medium and electronic equipment
CN114489678A (en) Method, device, storage medium and equipment for processing database script
CN113448985A (en) API (application program interface) interface generation method, calling method and device and electronic equipment
CN113703829A (en) Android life cycle multi-service distribution method and system
CN107844340B (en) Method and system for data acquisition and file downloading
Spear et al. Making performance analysis and tuning part of the software development cycle
CN111221787A (en) File processing method and device
Dumez et al. Formal specification and verification of service composition using LOTOS
CN116880920A (en) System and method for generating API (application program interface) execution log
TWI842427B (en) Software development system and software developing method

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant