Script generation method, system and equipment and storage medium
By merging and simplifying Lua scripts, generating scripts that do not contain uninvoked functions solves the problem that Redis does not support inter-script references, implements code reuse and size reduction, and is suitable for scenarios where inter-script calls are not supported.
Patent Information
- Application Number
- CN202411358855.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-27
- Publication Date
- 2025-01-10
AI Technical Summary
Redis does not support referencing another script in one lua script, resulting in the inability to extract and reuse repeated functions in multiple scripts, increasing the complexity and code size of script maintenance.
By obtaining multiple Lua scripts and combining them into one, generating an abstract syntax tree, counting the calling information of functions, deleting uncalled functions, and generating a thin third Lua script, it is suitable for scenarios where scripts do not support mutual calls.
It realizes the simplification of code, reduces the code size, supports code reuse, reduces the development burden of developers, and executes script functions normally in scenarios such as Redis.
Smart Images

Figure CN119292577A_ABST
Abstract
Description
Background Art
[0002] Lua is a compact scripting language. When writing Lua scripts, for repeated code segments in different scripts, these code segments can be extracted into functions and saved as separate files. Other Lua scripts that need to use this code segment can include this Lua script file to achieve code reuse, thereby reducing the burden on code developers.
[0003] Redis is a commonly used Key-Value database that supports multiple query statements and business logic written as a Lua script and sent to the Redis server for execution. However, Redis does not support referencing another script in a Lua script, so it is impossible to extract duplicate functions in multiple scripts, increasing the complexity of script maintenance. If a Lua script that references other scripts is sent to the Redis server, it cannot be executed correctly. Summary of the invention
[0004] In response to the problems in the prior art, the purpose of the present application is to provide a script generation method, system, device and storage medium, which merge multiple scripts with dependencies into one Lua script and streamline the functions based on the abstract syntax tree, which is conducive to reducing the size of the script code.
[0005] The present application provides a script generation method, comprising the following steps:
[0006] Obtain a first Lua script, and merge the first Lua script and all second Lua scripts on which it depends to obtain a merged script, wherein the first Lua script and each of the second Lua scripts respectively include at least one function;
[0007] Performing syntax analysis on the merged script to obtain an abstract syntax tree, and counting the call information of each function in the abstract syntax tree;
[0008] Deleting uncalled functions from the abstract syntax tree according to the calling information of each function;
[0009] A third Lua script is generated based on the abstract syntax tree.
[0010] In the script generation method of the present application, first the first lua script and the second lua script it depends on are merged, the merged script includes all functions in the first lua script and all functions in the second lua script, so as to obtain a merged script containing all required functions, then the abstract syntax tree of the merged script and the call information of the function are obtained, and the uncalled functions are deleted based on the call information of the function, so that the abstract syntax tree is streamlined, and then the third lua script is generated based on the streamlined abstract syntax tree, and the third lua script generated does not include comments, and does not include uncalled functions, and the code is more streamlined, which is conducive to reducing the code size. The third lua script generated can be used for scenarios that do not support mutual calls between scripts, such as the application scenarios of Redis databases, etc. Various code editors can normally index each function in the script, and it is realized that only the third lua script needs to be executed to realize all normal functions of the script. In addition, by adopting this method, in the editing stage of the first lua script, when the developer develops the lua script, it can also reasonably extract functions and divide different lua scripts according to the custom and lua coding specifications, and can reuse repeated function codes, which reduces the development burden of the developer.
[0011] In some embodiments, a dependency statement on the second Lua script is defined in the first Lua script;
[0012] Merging the first Lua script and the second Lua script it depends on to obtain a merged script includes the following steps:
[0013] Match and obtain the dependency statements in the first Lua script;
[0014] Search the corresponding second Lua script in the dependent script directory according to the dependent statement;
[0015] The contents of all the second Lua scripts that the first Lua script depends on are added to the first Lua script to obtain the merged script.
[0016] In some embodiments, before searching for the corresponding second Lua script in the dependent script directory according to the dependent statement, the following steps are also included:
[0017] Determine the name of the dependent second Lua script according to the dependency statement;
[0018] Determine whether the script content corresponding to the second Lua script name has been added to the first Lua script;
[0019] If not, search for a corresponding second Lua script in the dependent script directory according to the dependent statement, and add the content of the second Lua script to the first Lua script.
[0020] In some embodiments, deleting uncalled functions from the abstract syntax tree according to the calling information of each function comprises the following steps:
[0021] According to the calling information of each function, the function with the calling times of 0 is deleted;
[0022] Update the call count of each function called by the deleted function;
[0023] After the call count is updated, it is determined whether there is still a function with a call count of 0. If so, the function with a call count of 0 is deleted.
[0024] In some embodiments, after deleting the uncalled functions from the abstract syntax tree according to the calling information of each function, the following steps are further included:
[0025] Determine whether there is a recursive calling function that calls itself according to the calling information of each function;
[0026] If yes, determine whether there are other functions that call the recursive calling function;
[0027] If no other function calls the recursive function, delete the recursive function.
[0028] In some embodiments, after deleting the uncalled functions from the abstract syntax tree according to the calling information of each function, the following steps are further included:
[0029] Determine whether there are two functions that call each other;
[0030] If yes, determine whether there are other functions that call the two functions that call each other;
[0031] If there is no other function that calls the two functions that call each other, the two functions that apply each other are deleted.
[0032] In some embodiments, generating a third Lua script based on the abstract syntax tree includes the following steps:
[0033] Replacing corresponding names in the abstract syntax tree based on updated variable names and / or function names to obtain an updated abstract syntax tree;
[0034] A third Lua script is generated based on the updated abstract syntax tree.
[0035] The present application also provides a script generation system, which is applied to the script generation method, and the system includes:
[0036] A script merging module, used for acquiring a first Lua script, merging the first Lua script with all second Lua scripts it depends on to obtain a merged script, wherein the first Lua script and each of the second Lua scripts respectively include at least one function;
[0037] A syntax tree generation module, used for performing syntax analysis on the merged script to obtain an abstract syntax tree, and counting the call information of each function in the abstract syntax tree;
[0038] A function processing module, used for deleting uncalled functions from the abstract syntax tree according to the calling information of each function;
[0039] A script generation module is used to generate a third Lua script based on the abstract syntax tree.
[0040] In the script generation system of the present application, the first lua script and the second lua script on which it depends are first merged by the script merging module, and the merged script includes all functions in the first lua script and all functions in the second lua script, so as to obtain a merged script containing all required functions, and then the abstract syntax tree of the merged script and the call information of the function are obtained by the syntax tree generation module, and the uncalled functions are deleted based on the call information of the function by the function processing module, so as to simplify the abstract syntax tree, and then the third lua script is generated based on the simplified abstract syntax tree by the script generation module, and the generated third lua script does not contain comments and does not contain uncalled functions, and the code is more streamlined, which is conducive to reducing the code size. The generated third lua script can be used in scenarios that do not support mutual calls between scripts, such as the application scenarios of Redis database, etc. Various code editors can normally index each function in the script, so that all normal functions of the script can be realized by executing the third lua script. Furthermore, by adopting this method, during the editing stage of the first Lua script, developers can also reasonably extract functions and divide different Lua scripts according to habits and Lua coding specifications when developing Lua scripts, and can reuse repeated function codes, thereby reducing the development burden of developers.
[0041] The present application also provides a script generation device, including:
[0042] processor;
[0043] a memory storing executable instructions of the processor;
[0044] The processor is configured to perform the steps of the script generation method by executing the executable instructions.
[0045] By adopting the script generation device provided in the present application, the processor executes the script generation method when executing the executable instructions, thereby obtaining the beneficial effects of the above-mentioned script generation method.
[0046] An embodiment of the present application also provides a computer-readable storage medium for storing a program, which implements the steps of the script generation method when executed by a processor.
[0047] By adopting the computer-readable storage medium provided in the present application, the program stored therein implements the steps of the script generation method when being executed, thereby obtaining the beneficial effects of the above-mentioned script generation method. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Other features, objects and advantages of the present application will become more apparent by reading the detailed description of non-limiting embodiments made with reference to the following drawings.
[0049] Figure 1 is a flowchart of a script generation method according to an embodiment of the present application;
[0050] Figure 2 is a flowchart of a merge script according to an embodiment of the present application;
[0051] Figure 3 is a schematic diagram of a merge script according to an embodiment of the present application;
[0052] Figure 4 is a schematic diagram of a script generation system according to an embodiment of the present application;
[0053] Figure 5 It is a structural schematic diagram of a script generating device according to an embodiment of the present application;
[0054] Figure 6 It is a schematic diagram of the structure of a computer storage medium according to an embodiment of the present application. DETAILED DESCRIPTION
[0055] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as limited to the embodiments set forth herein; rather, these embodiments are provided so that this application will be comprehensive and complete and the concepts of the example embodiments will be fully conveyed to those skilled in the art. The same reference numerals in the figures represent the same or similar structures, and thus their repeated description will be omitted. Although "first" or "second" etc. are used in this specification to represent certain features, they are only used to represent the function and are not used as a limitation on the number and importance of specific features.
[0056] like Figure 1 As shown, in one embodiment, the present application provides a script generation method, comprising the following steps:
[0057] S100: Obtain a first Lua script, and merge the first Lua script and all second Lua scripts on which it depends to obtain a merged script, wherein the first Lua script and each of the second Lua scripts respectively include at least one function;
[0058] Here, the first Lua script is a Lua script written according to the Lua general syntax, in which the dependency relationship on other scripts is defined. Here, the scripts that the first Lua script depends on are defined as all Lua scripts are defined as the second Lua script;
[0059] In this application, the definition that a first Lua script "depends on" a second Lua script refers to the need for a function in the first Lua script to utilize a function in the second Lua script during execution; the second Lua script here includes not only the Lua script directly dependent on the first Lua script (the Lua script where the function directly referenced by the function in the first Lua script is located), but also the Lua script indirectly dependent on the first Lua script (the Lua script where the function directly referenced by the function in one or several second Lua scripts is located), for example, the first Lua script a includes function a1, function a2, etc., and function a1 references function b1, then the Lua script b including the function b1 is the second Lua script that the first Lua script depends on (directly depends on), and function b1 further references function c1, then the Lua script c including the function c1 is also the second Lua script that the first Lua script depends on (indirectly depends on); each first Lua script may have one or more second Lua scripts that it depends on;
[0060] When writing a first Lua script, by defining a dependency relationship on a second Lua script, the first Lua script can call a function in the second Lua script, thereby simplifying the writing process of the first Lua script and achieving the effect of code reuse; however, when the first Lua script is directly applied to a scenario that does not support one script calling other scripts, it cannot be executed normally, therefore, the first Lua script and the second Lua script are merged, and the merged script is further processed through the following steps S200 to S400;
[0061] S200: performing syntax analysis on the merged script to obtain an abstract syntax tree, and counting the call information of each function in the abstract syntax tree;
[0062] Abstract Syntax Tree (AST) is an abstract representation of the source code structure, which expresses the syntax structure of the programming language in a tree form. The calling relationship between various functions can be obtained through the abstract syntax tree; the calling information of each function here at least includes the calling time of each function and the name of the function that calls the function;
[0063] After the merged script is parsed, the functions in the obtained abstract syntax tree include all functions in the first Lua script and all functions in the second Lua script;
[0064] S300: deleting uncalled functions from the abstract syntax tree according to the calling information of each function;
[0065] The uncalled functions here are functions that will never be called during the script execution, that is, useless functions. Deleting such functions can simplify the abstract syntax tree.
[0066] S400: Generate a third Lua script based on the abstract syntax tree;
[0067] Specifically, the abstract syntax tree is converted into a Lua script according to the syntax rules of the abstract syntax tree and the syntax rules of the Lua script, so as to obtain the third Lua script.
[0068] In the script generation method of the present application, firstly, the first lua script and the second lua script on which it depends are merged by step S100, and the merged script includes all functions in the first lua script and all functions in the second lua script, so as to obtain a merged script containing all required functions, and then the abstract syntax tree of the merged script and the call information of the function are obtained by step S200, and the uncalled functions are deleted based on the call information of the function by step S300, so as to simplify the abstract syntax tree, and then the third lua script is generated based on the simplified abstract syntax tree by step S400, and the generated third lua script does not contain comments and does not contain uncalled functions, and the code is more streamlined, which is conducive to reducing the code size. The generated third lua script can be used in scenarios that do not support mutual calls between scripts, such as the application scenarios of Redis database, etc. Various code editors can normally index each function in the script, so that all normal functions of the script can be realized by executing the third lua script. Furthermore, by adopting this method, during the editing stage of the first Lua script, developers can also reasonably extract functions and divide different Lua scripts according to habits and Lua coding specifications when developing Lua scripts, and can reuse repeated function codes, thereby reducing the development burden of developers.
[0069] In this embodiment, a dependency statement on a second Lua script is defined in the first Lua script. Specifically, according to the general syntax of Lua, the dependency statement here refers to the statement of require("module_name"). For example, two dependency statements are defined in the first Lua script: require"b" and require"c", then Lua script b and Lua script c are the second Lua scripts that the first Lua script depends on.
[0070] like Figure 2 As shown, in step S100, merging the first Lua script and the second Lua script on which it depends to obtain a merged script includes the following steps:
[0071] S110: matching and obtaining the dependency statement in the first Lua script;
[0072] That is, the require statement in the first Lua script is matched, and the name of the second Lua script that it depends on can be determined according to the module_name in the require statement;
[0073] S120: searching for a corresponding second Lua script in the dependent script directory according to the dependent statement;
[0074] The second Lua script found is the module_name.lua file;
[0075] S130: Add the contents of all the second Lua scripts that the first Lua script depends on to the first Lua script to obtain a merged script;
[0076] For example, after the content of the second Lua script is expanded, it is added to the position of the corresponding require statement in the first Lua script.
[0077] In this embodiment, in step S120, according to the dependency statement in the first lua script, the second lua script that the first lua script directly depends on is found, not only including the second lua script directly found in the dependency script directory according to the dependency script name in the dependency statement, but also including the process of finding other corresponding second lua scripts in the dependency script directory according to the dependency statement of the second lua script that has been found, namely including: judging whether the determined second lua script is defined with a dependency statement, if so, then according to the dependency statement in the determined second lua script, the corresponding lua script is found in the dependency script directory, and the lua script found is also used as the second lua script (indirect dependency) that the first lua script depends on. Therefore, in the process of expanding the second lua script, the process of multi-level expansion may be involved, for example, the first lua script depends on the second lua script b, the second lua script b depends on the second lua script c, and the second lua script depends on the second lua script d, then it is necessary to expand each second lua script step by step, and the second lua script b, the second lua script c, and the second lua script d are inserted into the first lua script step by step.
[0078] In this embodiment, in order to avoid two dependency statements depending on the same second lua script, resulting in the second lua script being repeatedly added to the first lua script after being expanded, it is necessary to record the name of the second lua script that has been added to the first lua script, and when the dependency statement of the second lua script with the same name is matched later, the content of the second lua script is no longer added to the first lua script. For example, the first lua script a directly depends on the second lua script m and the second lua script n, and the second lua script m depends on the second lua script n, then when the second lua script n is found for the second time, it can be determined that the second lua script n has been added to the first lua script, and there is no need to add it repeatedly.
[0079] Specifically, the step S120: before searching the corresponding second Lua script in the dependent script directory according to the dependent statement, further includes the following steps:
[0080] S111: Determine the name of the dependent second Lua script according to the dependency statement;
[0081] That is, according to the module_name in the require statement, it can be determined that the name of the second Lua script it depends on is module_name; the require statement here can be the require statement in the first Lua script, or it can be the require statement in the second Lua script that has been added to the first Lua script;
[0082] S112: Determine whether the script content corresponding to the second Lua script name has been added to the first Lua script;
[0083] If yes, then S113: do not add the script content corresponding to the second Lua script name to the first Lua script; that is, avoid repeatedly adding the dependent second Lua script content to the first Lua script;
[0084] If not, continue to step S120: search for the corresponding second Lua script in the dependent script directory according to the dependent statement, and execute step S130: add the content of the second Lua script to the first Lua script.
[0085] In this embodiment, the step S300: deleting uncalled functions from the abstract syntax tree according to the calling information of each function, comprises the following steps:
[0086] According to the calling information of each function, delete the functions with 0 call times. Here, the function with 0 call times is the function that has never been called by other functions. This function will never be used from beginning to end when the merged script is executed. Therefore, this function is redundant and useless. Deleting such functions can simplify the abstract syntax tree and then simplify the third Lua script generated later.
[0087] Furthermore, there may be a function A whose call count is 0, but it also calls another function B. If the called function B is only called by function A, then the function B also needs to be deleted. Therefore, in step S300, after deleting the function with a call count of 0 according to the call information of each function, the following steps are also included:
[0088] Update the call count of each function called by the deleted function;
[0089] For example, for function B, before function A is deleted, the number of calls to function B is 1 (called by function A). After function A is deleted, the number of calls to function B becomes 0.
[0090] After the call count is updated, it is determined whether there is still a function with a call count of 0. If so, the function with a call count of 0 is deleted.
[0091] In this embodiment, in step S300, after deleting uncalled functions from the abstract syntax tree according to the calling information of each function, the step further includes deleting functions that are only called by themselves, which specifically includes the following steps:
[0092] Determine whether there is a recursive calling function that calls itself based on the calling information of each function;
[0093] If yes, determine whether there are other functions that call the recursive calling function;
[0094] If no other function calls the recursive function, delete the recursive function.
[0095] For example, if a function C calls function C, then the function is defined as a recursive calling function; further determine whether there are other functions that call function C. If no other function calls function C, then function C is also a redundant and useless function and needs to be deleted to further streamline the abstract syntax tree.
[0096] In this embodiment, in step S300, after deleting the uncalled functions from the abstract syntax tree according to the calling information of each function, the method further includes deleting two functions that only call each other, which specifically includes the following steps:
[0097] Determine whether there are two functions that call each other;
[0098] If yes, determine whether there are other functions that call the two functions that call each other;
[0099] If no other function exists to call the two functions that call each other, the two functions that call each other are deleted.
[0100] For example, if function D references function E, and function E references function D, and no other function references function D and function E, then function D and function E are considered to be two functions that only call each other, that is, functions that are called in a loop. These two functions will not be run when the merged script is executed. These two functions need to be deleted to further streamline the abstract syntax tree.
[0101] In the above simplification process of the abstract syntax tree, there is no restriction on the execution order of the three steps of updating the call count of each function and deleting the function with a call count of 0, deleting the function that is only called by itself, and deleting the two functions that call each other, and these three steps need to be repeated until the abstract syntax tree no longer changes. At this point, all redundant and useless functions are deleted, and the abstract syntax tree after simplification is obtained, which is used to generate the third Lua script in the subsequent step S400.
[0102] In this embodiment, the step S400: generating a third Lua script based on the abstract syntax tree includes: converting the abstract syntax tree into a Lua script according to the syntax rules of the abstract syntax tree and the syntax rules of the Lua script, that is, obtaining the third Lua script. Furthermore, before generating the third Lua script, the variables / functions in the abstract syntax tree may be renamed as needed. The step S400 specifically includes the following steps:
[0103] Replacing corresponding names in the abstract syntax tree based on updated variable names and / or function names to obtain an updated abstract syntax tree;
[0104] Generate a third Lua script based on the updated abstract syntax tree.
[0105] When renaming variables and / or functions in the abstract syntax tree, the variable names and / or function names can be simplified and replaced with shorter codes, which can also simplify the script code, help reduce the size of the script code, make subsequent script loading and execution faster, and achieve the effect of obfuscating the code.
[0106] Combine the following Figure 3 The implementation process of the script generation method of the present application is specifically introduced with a specific example. Figure 3 The scripts in and the following description of the implementation process are only examples and are not intended to limit the scope of protection of this application. Figure 3 In the figure, the first upper box displays the content of the first Lua script a, the second box displays the content of the second Lua script b, the third box displays the content of the third Lua script c, and the lower box displays the content of the third Lua script finally obtained.
[0107] Corresponding to step S100, first obtain the file a.lua of the first lua script, match the dependency statements require "b" and require "c" in the content of a.lua, and find the files b.lua and c.lua of the second lua script based on this dependency statement, expand the content of b.lua and the content of c.lua and add them to the first lua script to obtain a merged script.
[0108] Corresponding to step S200, after the abstract syntax tree is generated based on the merged script, the call information of each function in the abstract syntax tree is counted. Among them, function Func_a2 is not called by other functions. Functions Func_b2 and Func_b3 only call each other and are not called by other functions. Function Func_c3 is recursively called by itself and is not called by other functions.
[0109] Corresponding to the above step S300, functions Function_a2, Func_b2, Func_b3 and Func_c3 need to be deleted from the abstract syntax tree.
[0110] Corresponding to the above step S400, a third Lua script is generated based on the streamlined abstract syntax tree, which no longer contains functions Func_a2, Func_b2, Func_b3 and Func_c3. The generated third Lua script can normally implement all logical functions of the first Lua script a, and does not include any comments or redundant and useless functions, and the code is more streamlined.
[0111] like Figure 4 As shown, the embodiment of the present application also provides a script generation system, which is applied to the script generation method, and the system includes:
[0112] The script merging module M100 is used to obtain a first Lua script, merge the first Lua script and all the second Lua scripts it depends on to obtain a merged script, wherein the first Lua script and each second Lua script respectively include at least one function;
[0113] The syntax tree generation module M200 is used to perform syntax analysis on the merged script to obtain an abstract syntax tree and to count the call information of each function in the abstract syntax tree;
[0114] The function processing module M300 is used to delete uncalled functions from the abstract syntax tree according to the calling information of each function;
[0115] The script generation module M400 is used to generate a third Lua script based on the abstract syntax tree.
[0116] In the script generation system of the present application, the first lua script and the second lua script on which it depends are first merged by the script merging module M100, and the merged script includes all functions in the first lua script and all functions in the second lua script, so as to obtain a merged script containing all required functions, and then the abstract syntax tree of the merged script and the call information of the function are obtained by the syntax tree generation module M200, and the uncalled functions are deleted based on the call information of the function by the function processing module M300, so as to simplify the abstract syntax tree, and then the third lua script is generated based on the simplified abstract syntax tree by the script generation module M400, and the generated third lua script does not contain comments and does not contain uncalled functions, and the code is more streamlined, which is conducive to reducing the code size. The generated third lua script can be used in scenarios that do not support mutual calls between scripts, such as the application scenarios of Redis database, etc. Various code editors can normally index each function in the script, so that all normal functions of the script can be realized by executing the third lua script. Furthermore, by adopting this method, during the editing stage of the first Lua script, developers can also reasonably extract functions and divide different Lua scripts according to habits and Lua coding specifications when developing Lua scripts, and can reuse repeated function codes, thereby reducing the development burden of developers.
[0117] An embodiment of the present application also provides a script generation device, including a processor; a memory, in which executable instructions of the processor are stored; wherein the processor is configured to perform the steps of the script generation method by executing the executable instructions.
[0118] Those skilled in the art will appreciate that various aspects of the present application may be implemented as a system, method or program product. Therefore, various aspects of the present application may be specifically implemented in the following forms, namely: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or a combination of hardware and software, which may be collectively referred to as "circuit", "module" or "system" herein.
[0119] Refer to the following Figure 5 The electronic device 600 according to this embodiment of the present application is described. Figure 5 The electronic device 600 shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0120] like Figure 5 As shown, the electronic device 600 is in the form of a general computing device. The components of the electronic device 600 may include, but are not limited to: at least one processing unit 610, at least one storage unit 620, a bus 630 connecting different system components (including the storage unit 620 and the processing unit 610), a display unit 640, etc.
[0121] The storage unit stores program codes, which can be executed by the processing unit 610, so that the processing unit 610 executes the steps of various exemplary embodiments of the present application described in the script generation method section above. For example, the processing unit 610 can execute the following steps: Figure 1 Follow the steps shown in .
[0122] The storage unit 620 may include a readable medium in the form of a volatile storage unit, such as a random access memory unit (RAM) 6201 and / or a cache memory unit 6202 , and may further include a read-only memory unit (ROM) 6203 .
[0123] The storage unit 620 may also include a program / utility 6204 having a set (at least one) of program modules 6205, such program modules 6205 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.
[0124] Bus 630 may represent one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
[0125] The electronic device 600 may also communicate with one or more external devices 700 (e.g., keyboards, pointing devices, Bluetooth devices, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 600, and / or communicate with any device that enables the electronic device 600 to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface 650. Furthermore, the electronic device 600 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) via a network adapter 660. The network adapter 660 may communicate with other modules of the electronic device 600 via a bus 630. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 600, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0126] By adopting the script generation device provided in the present application, the script generation method executed by the processor when executing executable instructions can obtain the beneficial effects of the above-mentioned script generation method.
[0127] The embodiment of the present application also provides a computer-readable storage medium for storing a program, and the steps of the script generation method are implemented when the program is executed by a processor. In some possible implementations, various aspects of the present application can also be implemented in the form of a program product, which includes a program code. When the program product is run on a terminal device, the program code is used to cause the terminal device to execute the steps according to various exemplary implementations of the present application described in the above script generation method section of this specification.
[0128] refer to Figure 6 As shown, a program product 800 for implementing the above method according to an embodiment of the present application is described, which can adopt a portable compact disk read-only memory (CD-ROM) and include program code, and can be run on a terminal device, such as a personal computer. However, the program product of the present application is not limited thereto. In this document, a readable storage medium can be any tangible medium containing or storing a program, which can be used by or in combination with an instruction execution system, an apparatus or a device.
[0129] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0130] Computer readable storage media may include data signals propagated in baseband or as part of a carrier wave, wherein readable program codes are carried. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. The readable storage medium may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, device, or device. The program codes contained on the readable storage medium may be transmitted using any suitable medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination thereof.
[0131] Program code for performing the operations of the present application may be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or cluster. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., using an Internet service provider to connect through the Internet).
[0132] By adopting the computer-readable storage medium provided by the present application, the steps of the script generation method implemented by the program stored therein when being executed, thereby obtaining the beneficial effects of the above-mentioned script generation method.
[0133] The above content is a further detailed description of the present application in combination with specific preferred implementation methods, and it cannot be determined that the specific implementation of the present application is limited to these descriptions. For ordinary technicians in the technical field to which the present application belongs, several simple deductions or substitutions can be made without departing from the concept of the present application, which should be deemed to fall within the scope of protection of the present application.
Claims
1. A script generation method, characterized in that: The steps include: Obtain a first Lua script, and merge the first Lua script and all second Lua scripts on which it depends to obtain a merged script, wherein the first Lua script and each of the second Lua scripts respectively include at least one function; Performing syntax analysis on the merged script to obtain an abstract syntax tree, and counting the call information of each function in the abstract syntax tree; Deleting uncalled functions from the abstract syntax tree according to the calling information of each function; A third Lua script is generated based on the abstract syntax tree.
2. The script generation method according to claim 1, characterized in that: A dependency statement on the second Lua script is defined in the first Lua script; Merging the first Lua script and the second Lua script it depends on to obtain a merged script includes the following steps: Match and obtain the dependency statements in the first Lua script; Search the corresponding second Lua script in the dependent script directory according to the dependent statement; After adding the contents of all the second Lua scripts that the first Lua script depends on to the first Lua script, the merged script is obtained.
3. The script generation method according to claim 2, characterized in that: Before searching the corresponding second Lua script in the dependent script directory according to the dependent statement, the following steps are also included: Determine the name of the dependent second Lua script according to the dependency statement; Determine whether the script content corresponding to the second Lua script name has been added to the first Lua script; If not, search for a corresponding second Lua script in the dependent script directory according to the dependent statement, and add the content of the second Lua script to the first Lua script.
4. The script generation method according to claim 1, characterized in that: The step of deleting uncalled functions from the abstract syntax tree according to the calling information of each function comprises the following steps: According to the calling information of each function, the function with the calling times of 0 is deleted; Update the call count of each function called by the deleted function; After the call count is updated, it is determined whether there is still a function with a call count of 0. If so, the function with a call count of 0 is deleted.
5. The script generation method according to claim 1, characterized in that: After deleting the uncalled functions from the abstract syntax tree according to the calling information of each function, the method further includes the following steps: Determine whether there is a recursive calling function that calls itself according to the calling information of each function; If yes, determine whether there are other functions that call the recursive calling function; If no other function calls the recursive function, delete the recursive function.
6. The script generation method according to claim 1, characterized in that: After deleting the uncalled functions from the abstract syntax tree according to the calling information of each function, the method further includes the following steps: Determine whether there are two functions that call each other; If yes, determine whether there are other functions that call the two functions that call each other; If there is no other function that calls the two functions that call each other, the two functions that apply each other are deleted.
7. The script generation method according to claim 1, characterized in that: Generating a third Lua script based on the abstract syntax tree includes the following steps: Replacing corresponding names in the abstract syntax tree based on updated variable names and / or function names to obtain an updated abstract syntax tree; A third Lua script is generated based on the updated abstract syntax tree.
8. A script generation system, characterized in that: The script generation method applied to any one of claims 1 to 7, wherein the system comprises: A script merging module, used for acquiring a first Lua script, merging the first Lua script with all second Lua scripts it depends on to obtain a merged script, wherein the first Lua script and each of the second Lua scripts respectively include at least one function; A syntax tree generation module, used for performing syntax analysis on the merged script to obtain an abstract syntax tree, and counting the call information of each function in the abstract syntax tree; A function processing module, used for deleting uncalled functions from the abstract syntax tree according to the calling information of each function; A script generation module is used to generate a third Lua script based on the abstract syntax tree.
9. A script generation device, characterized in that: include: processor; a memory storing executable instructions of the processor; The processor is configured to execute the steps of the script generation method according to any one of claims 1 to 7 by executing the executable instructions.
10. A computer-readable storage medium for storing a program, characterized in that: When the program is executed by a processor, the steps of the script generation method according to any one of claims 1 to 7 are implemented.