CN114741063B - Method and system for realizing programming framework based on Lua language - Google Patents

Method and system for realizing programming framework based on Lua language Download PDF

Info

Publication number
CN114741063B
CN114741063B CN202210368525.5A CN202210368525A CN114741063B CN 114741063 B CN114741063 B CN 114741063B CN 202210368525 A CN202210368525 A CN 202210368525A CN 114741063 B CN114741063 B CN 114741063B
Authority
CN
China
Prior art keywords
event
main thread
observer
observed person
observed
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.)
Active
Application number
CN202210368525.5A
Other languages
Chinese (zh)
Other versions
CN114741063A (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

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 application relates to a method and a system for realizing a programming framework based on Lua language, wherein the method comprises the following steps: identifying an observer pattern method in the current programming code when the main thread sequentially executes the programming code written based on the Lua language input through the editor; in response to identifying the observer pattern method, determining an observer and an observed person from the indicator; establishing a subscription relationship between the watcher and the watcher; in response to the subscription relationship, the watcher listens to the watcher and receives an event when the watcher sends the event; and generating an event in response to completion of execution of the programming code corresponding to the observed person, and transmitting the event to the observed person. The programming framework realized by the application reduces the blockage to the main thread and effectively improves the operation efficiency of the editor; the game developed based on the programming framework implemented by the application can provide good experience for users when running on the user equipment.

Description

Method and system for realizing programming framework based on Lua language
Technical Field
The application relates to the technical field of application development, in particular to a method and a system for realizing a programming framework based on the Lua language.
Background
In a sense, a programming framework refers to the underlying services that implement the general purpose complete functionality of a certain application domain and provides business logic. Programmers can use the frameworks to start specific application development on the basis that a general function is realized, the programming frameworks complete basic works, the programmers only need to concentrate on completing the business logic design of the application according to certain requirements and rules, convenience is provided for programming development work to a great extent, and business logic written by using the frameworks is simpler and more readable.
In the field of game development, a game development tool used by a game developer, for example, a programming framework provided by Cocos2D, cocos3D, libGDX, unity and the like, can enable the game developer to flexibly use various components, tools, plug-ins and the like to complete development work of a game. Among the many development tools, unity is being used by more and more game developers for reasons of comprehensive functions, strong capabilities, little development and learning difficulty, cross-platform capability, and the like.
Although powerful, it also has many drawbacks. For example, one of the reasons for this is that most of the resource loading is performed on the main thread due to logic in the Unity engine, and even if some loading work can be performed on the loading thread, much work of the process still needs to be performed by the main thread, so that the pressure of the main thread is not reduced, and the loading is slow and inefficient, and the main thread is often blocked. For example, all processing operations of the editor are in the same thread when the game is run, and the defects of resource management and logic result in very low running efficiency of the editor, and when the developed game is installed on a user terminal to run, the user terminal is blocked and heated, so that the user experience is poor.
Disclosure of Invention
Aiming at the technical problems in the prior art, the application provides a method and a system for realizing a programming framework 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 above technical problems, according to one aspect of the present application, a method for implementing a programming framework based on Lua language is provided, including the following steps:
identifying an observer pattern method in the current programming code when the main thread sequentially executes the programming code written based on the Lua language input through the editor;
in response to identifying the observer pattern method, determining an observer and an observed person from the indicator;
establishing a subscription relationship between the watcher and the watcher;
in response to the subscription relationship, the watcher listens to the watcher and receives an event when the watcher sends the event; and
generating an event in response to the program code execution completion corresponding to the observed person, and transmitting the event to the observed person.
According to one aspect of the present application, the present application provides a Lua language-based programming framework implementation system, which includes a main thread module, a role determination module, a subscription module, and an observed module, wherein the main thread module is configured to sequentially run programming codes written based on Lua language and input by an editor in the main thread, monitor the observed, and receive events sent by the observed; the role determination module is connected with the main thread module and is configured to determine an observer and an observed person according to indicators in an observer mode method provided in programming code; the subscription module is respectively connected with the role determination module and the main thread module and is configured to establish or unsubscribe between the observer and the observed person; the observed module is connected with the role determination module and is configured to run programming codes corresponding to the observed person, generate an event after the running is finished and send the event to the observed person.
The programming framework realized based on the method replaces the original cooperative program by asynchronous operation when the programming code is operated, thereby realizing multithreading, reducing the blockage of the main thread where the observed person is positioned, and having no performance consumption, thereby effectively improving the operation efficiency of the editor; when the game developed based on the programming framework provided by the application runs on the 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 application will be described in further detail below with reference to the attached drawing figures, wherein:
FIG. 1 is a flowchart of a method for implementing a Lua language-based programming framework, according to one embodiment of the present application;
FIG. 2 is a functional block diagram of a Lua language-based programming framework implementation system in accordance with one embodiment of the present application;
FIG. 3 is a functional block diagram of a thread module according to one embodiment of the present application;
FIG. 4 is a main thread module schematic block diagram according to another embodiment of the present application;
FIG. 5 is a functional block diagram of a main thread module and an observed module according to yet another embodiment of the present application;
FIG. 6 is a functional block diagram of a subscription module according to one embodiment of the application;
FIG. 7 is a functional block diagram of a Lua language-based programming framework implementation system in accordance with another embodiment of the present application;
FIG. 8A is a diagram showing performance test data for game A developed based on the existing Unity official development tool; and
FIG. 8B is a graphical representation of performance test data for game B developed based on the development tool of the programming framework provided by the present application.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present application more apparent, the technical solutions of the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application, and it is apparent that the described embodiments are some embodiments of the present application, but not all embodiments of the present application. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
In the following detailed description, reference is made to the accompanying drawings, which form a part hereof, and in which is shown by way of illustration specific embodiments of the application. In the drawings, like reference numerals describe substantially similar components throughout the different views. Various specific embodiments of the application are described in sufficient detail below to enable those skilled in the art to practice the teachings of the application. It is to be understood that other embodiments may be utilized or structural, logical, or electrical changes may be made to embodiments of the present application.
The programming framework implemented by the application supports programs written by programmers in an editor of a development tool in an observer mode method. The programming framework carries out corresponding processing according to preset indicator meanings after identifying the indicators, so that the purposes of asynchronous operation, multithreading and the like can be achieved.
FIG. 1 is a flowchart of a method for implementing a Lua language-based programming framework, according to one embodiment of the present application, the method comprising the steps of:
step S1, creating a main thread and waiting for a running instruction of a programming code input by a programmer to an edited device.
And S2, after the operation instruction of the programmer is obtained, the programming code written in the Lua language and input by the editor is sequentially executed in the main thread. In one embodiment, the programming code that is run 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 of programming paradigm and the like, the script is written by the Lua language. The programmer can run the script after writing one script, or can run all the scripts when sequentially writing a plurality of scripts for different functions in the editor. The application executes the script sequentially through the created main thread.
Step S3, judging whether the observer mode method is provided in the current programming code, and if so, executing step S4. If not, it is determined in step S10 whether the main thread is finished, if the main thread is not finished, the program code input via the editor is continuously executed in step S2, and if the main thread is finished, that is, all the current code codes are already run, the program code is finished.
And S4, determining the observer and the observed person according to the indicator in the method.
And S5, establishing a subscription relationship between the observer and the observed person. After a subscription relationship is established between the watcher and the watcher, in step S7, the watcher listens to the watcher, and listens to whether the watcher sends an event.
And S6, executing the observed person.
Step S61, judging whether the execution of the observed person is completed, if not, returning to step S6, if so, generating an event at step S62, and sending the event to the observed person.
Step S8, judging 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 persons are monitored, and when an event sent by the observed persons is monitored, the event is received. Thus, it is determined in step S8 whether an 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 flow returns to step S2. If no event is received from the observed person, the observed person is continuously monitored in step S7.
There may be multiple observers during the execution of the script code by the main thread, and thus, in one embodiment, the main thread Cheng Wei holds a list of correspondence of observers to observers, and identifies the observers and corresponding observers in the event that occurs when each of the observers completes execution, so that when an event is monitored by the main thread, it is determined to which observer the corresponding observer and the event should be sent based on the observer identifier and the observed identifier in the event.
In the foregoing step S6, the observed person may execute in a newly created thread or may execute in the main thread, if necessary. The observed person may be in any form, such as network request, timing, delay, acquisition of certain data, acquisition of certain events, various data processing to be performed, etc.
For example, the code written in the editor by the programmer is shown in table 1 below and runs the code.
TABLE 1
When the main thread executes the above programming code, the observer mode method is provided in the current programming code by the first line "name. The word "executable" is used as an observer mode method indicator, the current main thread is determined to be an observer according to the word "Game" in front of the observer mode method indicator, the network operation of the get request is determined to be an observed person according to the word "WWW. Get" in back of the observer mode method indicator, and the specific content of the request is "http:// google. Co. Jp/". In this embodiment, the programmer uses "subscore" as a subscription instruction or identifier in the programming code to establish a subscription relationship between the main thread and the network operation of the get request, and this embodiment defines the declaration process of the event by using the Action and Func </item of Unity, thereby declaring that x is returned when the get request is successful, and that ex is returned when the get request fails. Because the Action supports all data types, the problem that the coroutine can not return parameters does not exist, so that the event becomes a carrier for the observer to communicate with the observed person.
Typically, network operations (e.g., HTTP get or HTTP post) in Unity to handle HTTP protocol needs to be done using WWW and Coroutine. The WWW is an object of the HTTP encapsulation and Coroutine can be considered as a function of the ienumearer as the return value is to turn on another piece of logic processing in the main thread, but unlike multithreading, coroutine is executed inside the main thread. Specifically, a coroutine is started by a StartCoroutine method, which is a method of MonoBehaviour, and a coroutine can be started, each coroutine has an entry function, and the coroutine must be a method (entry function) in which an ienumearer is used as a return value, and the coroutine is interrupted by using a yieldkey. Thus, it can be seen that the coroutine return value type must be IEnumearer, but not any other value, and that coroutine cannot handle exceptions because the yield return statement cannot be surrounded by a try-catch structure. Upon completion of operations such as network operations, the coroutines are required to complete in the main thread, and the various operations are tightly coupled, resulting in a massive single ienumearates. The application solves the problem, the observer mode provided by the application can asynchronously realize the observed person, and the operation is safer and more efficient. Taking the foregoing code example as an example, by using the framework implemented by the present application, a get request with the request content "http:// google.co.jp/" can be asynchronously implemented in another thread. And generating an event when the network operation is finished, wherein the event return value is x when the operation is successful, and the event return value is ex when the operation is failed. The main thread determines that the network operation is completed when receiving the event and the return value thereof, and then releases the subscription relationship between the main thread and the network operation as the observed person. Therefore, when the programming code is operated, the framework realized by the application replaces coroutine through asynchronous operation, thereby reducing the blockage of the main thread where the observed person is positioned, decoupling various operations in the main thread, and having no any performance consumption, thereby effectively improving the operation efficiency of the editor.
As can be seen from the above embodiments, the programming framework implemented by the present application enables asynchronous operation, and thus enables access to game objects and processing of game data via multi-threading. Such as shown in table 2. Two observer mode methods are included in table 2, where 1-3 are a method for implementing multithreading, and start () indicates that an observed person is a method that needs to be executed in an asynchronous thread, and functions to put the method that needs to be executed asynchronously into the asynchronous thread, thereby implementing multithreading. The observed person in the 4-7 method is a timer with an implementation timing period of 3 seconds. Any function method in the first observer mode method can be put into an asynchronous thread execution by Start (), 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 other than the main thread are collectively called a second thread, and in this embodiment, two second threads are included, and the second threads can be put by a function method for implementing all service logic of the game code and a timer with a timing period of 3 seconds, and execute asynchronously with the main thread. In addition, the subscription relationship between the observer and the observed person can be established according to the subscription identifier, the subscription identifier is not needed, and when the observed person needs to feed back the event to the observer, the subscription relationship between the observer and the observed person can be established.
TABLE 2
As can be seen from the above embodiments, the programming framework implemented by the present application implements a new chained programming structure (the script codes implementing different functions are connected by semicolon, and a plurality of script codes form a chained programming structure from top to bottom), and the new chained programming structure can implement multiple functions in the same time period by adopting a multithreading processing mode and asynchronous operation in the execution process from top to bottom, and compared with a single thread mode, the system performance consumption is reduced, the running time of the editor is also shortened by times, and the development efficiency is effectively improved.
In order to reduce the performance consumption as much as possible, after the executed by the observed person finishes, the main thread needs to release the subscription relationship between the main thread and the observed person in time after receiving the event sent by the executed by the observed person. There may be various ways to de-subscribe between the main thread and the observed person, for example, when the observer pattern method includes de-subscription identifiers, as the codes "in lines 3 and 7 in table 2: addTo (this) ", after an event generated in response to completion of execution of the programming code corresponding to the observed person is sent to the main thread, the subscription relationship between the main thread and the observed person is released while the current script is ended, that is, the subscription relationship between the main thread and the observed person and the current script are ended simultaneously. In another mode, when the main thread sequentially executes the programming codes input through the editor, after the programming codes corresponding to the observer mode method are executed, the subscription relation between the main thread and the observed person is released according to an instruction for releasing the subscription relation between the main thread and the observed person in the sequentially executed programming codes. As shown in table 3 below:
TABLE 3 Table 3
The code of the 1 st-6 th lines is a code input in the editor, when the main thread executes the code, the corresponding observed person is determined by the observer mode method identified by the 1 st line, in this embodiment, the observed person processes a series of data, such as the 1 st line input, the second line filtering odd numbers, the third line splicing a sentence of character strings ' whow do we appreciate ' and the fourth line insertion ' after the character strings formed by all the numbers! ", printing of the sixth line. When the observed person is determined, a subscription relationship between the main thread and the observed person is established and returned content (content determined after the foregoing process is printed in the editor) is determined. According to the code of 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 present embodiment is performed in the main thread. When the main thread is executing programming code sequentially after execution of all of the code is completed, the subscription relationship between the data processing operations and the main thread is canceled according to the instruction of line 7.
By timely releasing the subscription relation between the main thread and the observed person, the main thread is not required to monitor the observed person, thereby saving the consumption of system performance.
In step S1, when the programming code input through the editor is sequentially executed in the main thread, a reaction sequence is generated according to an event-driven relationship in the programming code. For example, the observed person in the application notifies the observer through the event, the observer reacts after receiving the event, and performs corresponding logic processing, the process is a reaction, and a plurality of reaction processes with event-driven relations are expressed as a chain structure to form a reaction sequence. For another example, when UI programming is performed using components of the UGUI, click events, value changes, etc. that are listened to by the event driven mechanism to the UI are represented as a reaction sequence. Thus, the present application maintains one or more reaction sequences. For example, all event driven relationships during the execution of each frame of the game may be represented as a reaction sequence, so the present application maintains a plurality of reaction sequences, each corresponding to a game frame. For another example, the present application may obtain a reaction sequence according to the time at which the event-driven relationship occurs or the thread in which it occurs. Based on the reaction sequence, the application can provide functions which cannot be provided in the original Unity, such as single click, double click, continuous point, shielding quick click and the like. Such as the codes shown in table 4.
TABLE 4 Table 4
As can be seen from the above code, when the observed person who obtains the data returned by each frame processing is executed, not all the data processed by each frame is returned as in the usual way of Unity, but the specified reaction in the reaction sequence of the current frame is queried according to the query instruction where (), and the relevant data in the specified reaction is returned according to the requirement in the query instruction. When the system maintains a plurality of response sequences according to the game frame, the response sequence corresponding to the current frame is searched, and then the response is specified in the query instruction, as shown in Table 4, the specified response in the window is' I nput. G et M ouse B utton D own (0) And finding an event in the reaction sequence, reading corresponding parameter data from event data corresponding to the reaction according to parameters required to be returned in the query instruction, and reading coordinates corresponding to the click event and returning the coordinates as shown in table 4 when the coordinates are required to be returned.
See also for example, table 5:
TABLE 5
In the present embodiment, the text display component mText is used as an observer, the input box component mlnput is used as an observed person, the change of the value in the input box is observed, the value of the input box is obtained through the white method and is processed and checked, delay is delayed for 1 second, and then the Delay is sent to the mText text display component for displaying through an event.
As can be seen from the above embodiments, the present application can achieve targeted data acquisition in combination with language integrated query (Linq), and when necessary, with query instructions composed of Linq query operators. Because the Linq query operator can search data from different data sources and structured data in different formats, the mismatch between programming language and database is eliminated, and therefore 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 application, where the system includes a main thread module 1, a role determination module 2, a subscription module 3, and an observed module 4, where the main thread module 1 sequentially runs programming code written in Lua language input via an editor in the main thread, listens to an observed person, and receives events sent by the observed person. The role determination module 2 is connected to the main thread module 1 and is configured to determine the watcher and the watcher according to indicators in the method when a watcher mode method is provided in current programming code running in the main thread. The subscription module 3 is connected to the main thread module 1, the role determination module 2 and the observed person module 4, respectively, and establishes or de-subscribes between the observed person and the observed person. The observed module 4 is connected with the role determining module 2 and the main thread module 1, and is used for running programming codes corresponding to the observed person, generating events after running, and sending the events to the observed person in the main thread module 1.
FIG. 3 is a functional block diagram of a main thread module according to one embodiment of the application. 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 configured to create a main thread and sequentially execute the Lua-language-written programming code inputted via the editor in the main thread, and to transmit a notification to the role determination module when executing the observer mode method into the current programming code. The monitor unit 12 is connected to the subscription module 3 and the observed module 4, monitors and receives an event sent by the observed person when receiving a subscription notification sent by the subscription module 3 and establishing a subscription relationship between the observed person (such as the main thread) and the observed person, and notifies the main thread unit 11 after receiving the event sent by the observed module 4.
Fig. 4 is a functional block diagram of a main thread module according to another embodiment of the present application. In this embodiment, the main thread module 1 includes, in addition to the main thread unit 11 and the listening unit 12, an execution mode identifying unit 13, which is connected to the main thread unit 11, and is 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. The main thread module 1 further comprises an observed unit 14 and a first event unit 15 when it is required to execute an observed person in the main thread, the observed unit 14 being connected to the main thread unit 11 and the execution mode identifying unit 13, respectively, and being sent to the observed unit 14 when the execution mode identifying unit 13 identifies that it is required to execute an observed person in the main thread. The observed unit 14 records the observed person and runs the 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 unit 15 is connected to the observed unit 14, generates a first event on demand when receiving a notification from the observed unit 14, and sends the first event to the listening unit 12. The snoop unit 12 receives the first event and returns to the main thread execution unit 11.
Fig. 5 is a functional block diagram of a main thread module and an observed module according to yet another embodiment of the present application. In this embodiment, the main thread module 1 includes a main thread unit 11, a snoop unit 12, and an execution mode identifying unit 13, and the observed module includes a second thread unit 41 and a second event unit 42. When the execution mode of the observed person acquired from the observer pattern method by the execution mode identification unit 13 is execution of the observed person 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, and executes the observed person in the second thread. When the execution observed person has completed executing the transmission notification to the second event unit 42. The second event unit 42 generates a corresponding second event when the second thread runs out of the programming code corresponding to the observed person and transmits the second event to the listening unit 12 in the main thread module 1. Wherein the second thread unit 41 can create one or more second threads for executing program codes inputted by a programmer via an editor in a step-wise and multi-threaded manner according to the need.
FIG. 6 is a functional block diagram of a subscription module according to one embodiment of the application. The subscription module 3 includes a subscription relation establishment unit 31 and a subscription relation release unit 32, wherein the subscription relation establishment unit 31 is connected to the role determination module 2, and establishes a subscription relation between the watcher and the watcher when the role determination module 2 determines the watcher and the watcher. The subscription relation releasing unit 32 is connected to the main thread module 1 and the observed module 4, respectively, and is configured to release the established subscription relation of the main thread and the observed according to the instruction from the observed module 4 or the main thread module 1. When the main thread unit 11 receives the first event sent by the first event unit 15 from the monitor unit 12 as shown in fig. 4, or receives the second event sent by the second event unit 15 from the monitor unit 12 as shown in fig. 5, it sends a release instruction to the subscription relationship release unit 32, where the release instruction includes identities of the watcher and the watcher. The subscription cancel unit 32 cancels the subscription between the observed person and the main thread according to the cancel instruction, and notifies the monitor 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 Lua language-based programming framework implementation system according to an embodiment of the present application, and compared with fig. 2, the present embodiment further includes a reaction sequence generating module 5 connected to the main thread module 1 and the observed module 4, for generating 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 unit 14 in the main thread module 1 or the second thread in the observed module 4 executes the observed, when the observed programming code includes the inquiry instruction, the appointed reaction is inquired in the reaction sequence, and the corresponding data in the appointed reaction is returned to the corresponding main thread or the second thread according to the requirement, so that the corresponding data can be acquired in a targeted manner, the system consumption is saved, and the data processing efficiency is improved.
Based on the programming framework realized by the application, when a programmer carries out game programming by the editor of the development tool, multithreading and asynchronous operation can be realized, so that the blockage to the main thread is reduced, and no performance consumption is caused, thereby effectively improving the operation efficiency of the editor, improving the development efficiency and greatly shortening the game development process.
Fig. 8A is a performance test data display diagram of a game a developed based on a conventional 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 application. As can be seen by comparison, game A developed based on the development tool provided by the Unity official can generate a lot of garbage (a plurality of GC (garbage collection) peaks indicated in the figure) which cannot be recovered during operation, while game B developed by the development tool using the programming framework provided by the application can hardly generate garbage which cannot be recovered during operation. Regarding the memory occupied by the main thread, compared with game a, the memory occupied by game B is greatly reduced, the cost of game a (overheads) is huge, and the cost of game B is zero; in contrast to the time consumption of each frame, game A was 14.6 milliseconds per frame, while game B was 0.37 milliseconds per frame. Therefore, the situation of clamping, heating and the like of the game when the user terminal runs can be effectively avoided by using the framework, and good experience is provided for the user.
The above embodiments are provided for illustrating the present application and not for limiting the present application, and various changes and modifications may be made by one skilled in the relevant art without departing from the scope of the present application, therefore, all equivalent technical solutions shall fall within the scope of the present disclosure.

Claims (11)

1. The method for realizing the programming framework based on the Lua language is characterized by comprising the following steps of:
when the main thread sequentially executes the programming code input by the editor and written based on the Lua language, an observer mode method is provided in the current programming code through the identification of a first line Game. Wherein the word Observable is used as an observer mode method indicator; the word Game determines that the current main thread is an observer, determines that the network operation of a get request is an observed person according to WWW.get, responds to the completion of execution of programming codes corresponding to the observed person, generates an event after the completion of execution, and sends the event to the observer;
the observer monitors the observed person; the observed person informs the observer through the event, the observer reacts after receiving the event, the reaction process with the event driving relation is expressed as a chained structure to form a reaction sequence, and one or more reaction sequences are maintained; wherein the reaction sequence comprises: representing all event-driven relationships in the process of running each frame of game as a reaction sequence so as to maintain a plurality of reaction sequences; when the UGUI component is used for UI programming, the clicking event and value change of the UI monitored by the event driving mechanism are expressed as a reaction sequence; representing all event-driven relationships in the process of running each frame of game as a reaction sequence which corresponds to the game frames respectively; obtaining a reaction sequence according to the occurrence time of the event-driven relationship or the thread where the event occurs;
inquiring the appointed reaction in the window from the reaction sequence of the current frame according to the inquiring instruction window (), and returning the related data in the appointed reaction to the corresponding observer according to the requirement in the inquiring instruction; when the system maintains a plurality of reaction sequences according to the game frames, firstly searching the reaction sequence corresponding to the current frame, and then reacting according to the specification in the query instruction; wherein the query instruction is composed of a Linq query operator;
in response to identifying an observer pattern method, establishing a subscription relationship between the observer and the observed person; the subscription relation between the main thread and the network operation of the get request is established by adopting a subscore as a subscription instruction or identifier; and
in response to the subscription relationship, using the Unity Action and Func < > to define the declaration process of the event, declaring to return x when the get request is successful and to return ex when the get request fails, wherein the Action supports all data types.
2. The method of claim 1, wherein in response to identifying the observer pattern method, further comprising: obtaining an execution mode of an observed person from the observer mode method;
in response to defining execution of the observed person in the main thread in the observer mode method, sequentially executing programming code corresponding to the observed person in the main thread; and
in response to the observer pattern method not being defined to execute the observed person in the main thread or creating a thread according to an asynchronous process identifier in the observer pattern method, executing programming code corresponding to the observed person in the new thread.
3. The method of claim 1, wherein in response to identifying the observer pattern method, further comprising: and identifying an unsubscribe identifier in the observer mode method, and in response to the identification of the unsubscribe identifier, releasing the subscription relationship between the observer and the observed person after an event generated in response to the completion of execution of the programming code corresponding to the observed person is sent to the observer.
4. The method according to claim 1, wherein when the program codes input through the editor are sequentially executed by the main thread, after the program 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 program codes sequentially executed.
5. A Lua-language-based programming framework implementation system, characterized in that it is based on the Lua-language-based programming framework implementation method as set forth in any one of claims 1 to 4, and the Lua-language-based programming framework implementation system includes:
the main thread module is configured to sequentially run programming codes input by the editor and written based on the Lua language on the main thread, 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 an observer and an observed person from indicators in an observer mode method provided in the programming code;
a subscription module, connected to the role determination module and the main thread module, respectively, configured to establish or unsubscribe relationships between the watcher and the watcher; and
and the observed module is connected with the role determination module and is configured to run programming codes corresponding to the observed person, generate an event after the running is finished and send the event to the observed person.
6. The system of claim 5, wherein the main thread module comprises:
a main thread unit configured to create a main thread and sequentially execute the program codes written based on the Lua language input via the editor at the main thread, and to transmit a notification to the role determination module when executing the observer mode method into the current program code; and
and the monitoring unit is configured to monitor and receive the event sent by the observed person when the subscription relation is established between the observed person and the observed person, and notify the main thread unit after receiving the event.
7. The system of claim 6, wherein the main thread module further comprises an execution mode identification unit, coupled to the main thread unit, configured to obtain an observed execution mode from the observer mode method, the execution mode comprising executing an observed person in a main thread or executing an observed person in a second thread.
8. The system of claim 7, wherein the main thread module comprises:
an observed unit connected with the main thread unit and configured to run programming code corresponding to the observed unit in a main thread; and
and the first event unit is connected with the observed unit, generates a first event when the programming code of the observed is operated in the main thread, and sends the first event to the monitoring unit.
9. The system of claim 7, wherein the observed module comprises:
a second thread unit, connected to the execution mode identification unit, configured to create a second thread when executing an observed person in the second thread, and run programming code corresponding to the observed person in the second thread; and
and the second event unit is connected with the second thread unit, and generates a corresponding second event when the second thread runs out of the programming code corresponding to the observed person and sends the corresponding second event to the monitoring unit.
10. The system of claim 5, wherein the subscription module comprises:
a subscription relationship establishing unit configured to establish a subscription relationship between the watcher and the watcher when the role determination module determines the watcher; and
and a subscription relation releasing unit connected with the main thread module and the observed module respectively and configured to release subscription relation between the observed and observed according to instructions from the observed module or the main thread module.
11. The system of claim 5, further comprising a reaction sequence generation module coupled to the main thread module and configured to generate a reaction sequence according to an event-driven relationship in the 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 CN114741063A (en) 2022-07-12
CN114741063B true 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 (12)

* 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
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

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6862635B1 (en) * 1998-11-13 2005-03-01 Cray Inc. Synchronization techniques 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
US8464281B2 (en) * 2010-08-18 2013-06-11 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

Patent Citations (12)

* 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
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
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

Also Published As

Publication number Publication date
CN114741063A (en) 2022-07-12

Similar Documents

Publication Publication Date Title
US7380239B1 (en) Method and mechanism for diagnosing computer applications using traces
US7512954B2 (en) Method and mechanism for debugging a series of related events within a computer system
US8122292B2 (en) Debugging of business flows deployed in production servers
US20070168971A1 (en) Multi-tiered model-based application testing
US20050149868A1 (en) User interface application development program and development apparatus
US9729677B2 (en) Method of adding client server automation to computer languages for cloud computing
US20180173520A1 (en) Transactional distributed data analysis and transformation
CN111427784B (en) Data acquisition method, device, equipment and storage medium
Tairas et al. Visualization of clone detection results
CN114741063B (en) Method and system for realizing programming framework based on Lua language
CN113971075A (en) Method, device, equipment and storage medium for realizing consistency of transaction and message
CN102063366A (en) Method and system for debugging process
US20040153881A1 (en) Identifying solutions to computer problems in main system by service system in distributed system landscape
US8126931B2 (en) Method and apparatus for displaying the composition of a data structure during runtime
CN112825068B (en) Data blood margin generation method and device
CN117215661A (en) Event processing method, device and storage medium
CN113495723B (en) Method, device and storage medium for calling functional component
Mohsin et al. A code summarization approach for object oriented programs
CN114371848A (en) Page joint debugging method, device, equipment and storage medium
Mazinanian et al. CSSDev: refactoring duplication in cascading style sheets
CN107193670B (en) Remote management method, device and system for cluster workstations
Spear et al. Making performance analysis and tuning part of the software development cycle
CN116880920A (en) System and method for generating API (application program interface) execution log
Babaei et al. Mregtest: A replay-based regression testing tool for distributed uml-rt models
CN112965869B (en) Automatic operation and maintenance method and system for non-standardized application system

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