Method, device, equipment and medium for executing external script

Through continuous memory pool allocation and Burst compiler optimization, the memory usage and latency issues of external scripts when running in the DOTS framework are resolved, achieving efficient external script execution and improving game performance and user experience.

CN120386589BActive Publication Date: 2025-09-12HUNAN TACHYON CULTURE & TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510884977.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-06-30
Publication Date
2025-09-12
Estimated Expiration
2045-06-30

AI Technical Summary

Technical Problem

In the existing technology, when external scripts are running in the DOTS framework, data interaction is difficult, resulting in increased memory usage, causing game screen freezes and delays, and affecting user experience.

Method used

Through continuous memory pool allocation and Burst compiler optimization, external scripts are parsed into script class instances and native code is generated, achieving continuous storage and efficient execution of script structures.

Benefits of technology

It improves memory operation speed and cache hit rate, reduces external script call latency, and improves user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120386589B_ABST
    Figure CN120386589B_ABST
Patent Text Reader

Abstract

The present disclosure relates to the field of software technology, and more specifically to a method, apparatus, device, and medium for executing an external script. The method comprises: obtaining one or more script classes based on an external script; calculating the memory size occupied by a script structure corresponding to the one or more script classes; applying for corresponding memory and obtaining a corresponding memory pointer based on the calculated memory size; creating a structure for the external script based on the data of the one or more script classes and the memory pointer; storing the structure in the memory; and executing the external script by reading the structure. This solution can greatly improve the execution speed of a program when calling an external script, reduce the probability of delays caused by calling an external script, and thus significantly improve the user experience.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of software technology, and in particular to a method, apparatus, device, and medium for executing an external script. Background Art

[0002] To facilitate dynamic adjustments to game content and rules, many games support mods, allowing players to customize and extend their games. Mods exist in the form of external scripts or resource packs. Their core function is to allow non-professional developers to modify data, combine rules, or create new mechanics within the game framework. To achieve this, current games require a built-in script interpreter to parse external scripts at runtime and convert them into instruction sets or data structures that the game can understand.

[0003] DOTS (Data-Oriented Technology Stack) is a data-oriented programming framework provided by Unity. It can improve program performance. However, due to the data-oriented ECS (Entity-Component-System) architecture of DOTS and the programming language restrictions of the optimizing compiler Burst, its scripting support is not very comprehensive. In particular, there are design differences between object-oriented external scripts and DOTS's data-oriented programming approach. Generally, scripts can only run in a separate object-oriented environment, isolated from the DOTS framework.

[0004] At present, the existing technology has difficulties in data interaction because the scripts and the high-speed DOTS framework run in different environments, which increases memory usage. External scripts cannot take advantage of the performance advantages of DOTS, resulting in delays in the calling process of external scripts, which in turn causes adverse conditions such as game screen freezes and excessive loading time, affecting the user experience. Summary of the Invention

[0005] In order to solve the problems in the related art, the embodiments of the present disclosure provide a method, apparatus, device and medium for executing an external script.

[0006] In a first aspect, an embodiment of the present disclosure provides a method for executing an external script, comprising:

[0007] Get one or more script class instances based on external scripts;

[0008] Determine the memory size occupied by the script structure corresponding to the instance of the script class according to the memory size occupied by the preset structure corresponding to the script class;

[0009] Calculating the total memory size occupied by the script structures corresponding to the instances of the one or more script classes according to the memory size occupied by the script structures corresponding to the instances of the one or more script classes;

[0010] Apply for memory space based on the calculated total memory size;

[0011] Storing the script structures corresponding to the instances of the one or more script classes in the memory space;

[0012] The external script is executed by reading the script structure from the memory space.

[0013] According to an embodiment of the present disclosure, obtaining one or more instances of script classes based on an external script includes:

[0014] Parse the external script to obtain the scope;

[0015] The scope is converted into an instance of the one or more scripting classes.

[0016] According to an embodiment of the present disclosure, the scope includes at least one of the following: a scope, a key-value pair, and a lexical unit;

[0017] The script class includes any one of the following: a key-value pair, a conditional judge.

[0018] According to an embodiment of the present disclosure, the memory space is continuous;

[0019] The storing the script structures corresponding to the instances of the one or more script classes in the memory space includes continuously storing the script structures corresponding to the instances of the one or more script classes in the memory space.

[0020] According to an embodiment of the present disclosure, the preset script structure corresponding to the script class includes: value type data of the script class; and / or a pointer to reference type data of the script class.

[0021] According to an embodiment of the present disclosure, when any instance contains a reference to another instance, a memory pointer of the other instance is stored in a script structure corresponding to the instance.

[0022] According to an embodiment of the present disclosure, storing the script structures corresponding to the instances of the one or more script classes in the memory space includes:

[0023] Get the memory address of the script structure corresponding to the second instance referenced by the first instance;

[0024] Assign a value to a memory pointer in the structure of the first instance according to the memory address of the script structure corresponding to the second instance.

[0025] According to an embodiment of the present disclosure, executing the external script by reading the script structure from the memory space includes:

[0026] Generate native code based on the script structure through a compiler;

[0027] The native code is executed to execute the external script.

[0028] In a second aspect, an embodiment of the present disclosure provides a device for executing an external script, including:

[0029] A script parsing module is configured to obtain one or more instances of script classes based on an external script;

[0030] A memory preset module is configured to determine the memory size occupied by the script structure corresponding to the instance of the script class according to the memory size occupied by the preset structure corresponding to the script class;

[0031] A memory calculation module is configured to calculate a total memory size occupied by the script structures corresponding to the instances of the one or more script classes according to the memory size occupied by the script structures corresponding to the respective instances of the one or more script classes;

[0032] The memory pool management module is configured to apply for memory space according to the calculated total memory size;

[0033] a script structure management module configured to store the script structures corresponding to the instances of the one or more script classes in the memory space;

[0034] The script task execution module is configured to execute the external script by reading the script structure from the memory space.

[0035] According to an embodiment of the present disclosure, obtaining one or more instances of script classes based on an external script includes:

[0036] Parse the external script to obtain the scope;

[0037] The scope is converted into an instance of the one or more scripting classes.

[0038] According to an embodiment of the present disclosure, the scope includes at least one of the following: a scope, a key-value pair, and a lexical unit;

[0039] The script class includes any one of the following: a key-value pair, a conditional judge.

[0040] According to an embodiment of the present disclosure, the memory space is continuous;

[0041] The storing the script structures corresponding to the instances of the one or more script classes in the memory space includes continuously storing the script structures corresponding to the instances of the one or more script classes in the memory space.

[0042] According to an embodiment of the present disclosure, the preset script structure corresponding to the script class includes: value type data of the script class; and / or a pointer to reference type data of the script class.

[0043] According to an embodiment of the present disclosure, when any instance contains a reference to another instance, a memory pointer of the other instance is stored in a script structure corresponding to the instance.

[0044] According to an embodiment of the present disclosure, storing the script structures corresponding to the instances of the one or more script classes in the memory space includes:

[0045] Get the memory address of the script structure corresponding to the second instance referenced by the first instance;

[0046] Assign a value to a memory pointer in the structure of the first instance according to the memory address of the script structure corresponding to the second instance.

[0047] According to an embodiment of the present disclosure, executing the external script by reading the script structure from the memory space includes:

[0048] Generate native code based on the script structure through a compiler;

[0049] The native code is executed to execute the external script.

[0050] In a third aspect, an embodiment of the present disclosure provides an electronic device comprising a memory and a processor, wherein the memory is used to store one or more computer instructions, and wherein the one or more computer instructions are executed by the processor to implement a method as described in any one of the first aspects.

[0051] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the method as described in any one of the first aspects.

[0052] According to the technical solution provided by the embodiment of the present disclosure, based on an external script, one or more script class instances are obtained; according to the memory size occupied by the preset structure corresponding to the script class, the memory size occupied by the script structure corresponding to the instance of the script class is determined; according to the memory size occupied by the script structure corresponding to each instance of the one or more script classes, the total memory size occupied by the script structure corresponding to the one or more script class instances is calculated; according to the total memory size calculated, memory space is applied; the script structure corresponding to each instance of the one or more script classes is stored in the memory space; and the external script is executed by reading the script structure from the memory space. The present disclosure changes the original random memory pool allocation to a continuous memory pool allocation through the script structure, so that the computer cache hit rate is greatly improved, the memory operation speed is effectively improved, thereby improving the efficiency of converting the script logic into highly optimized local code, that is, improving the efficiency of executing the script in the external script. Therefore, the above solution is applied in the DOTS framework, which can greatly improve the execution speed of the program when calling the external script, reduce the probability of delay due to calling the external script, and thus significantly improve the user experience.

[0053] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0054] Other features, objectives and advantages of the present disclosure will become more apparent through the following detailed description of non-limiting embodiments in conjunction with the accompanying drawings. In the accompanying drawings:

[0055] Figure 1 A flowchart of a method for calling an external script according to an embodiment of the present disclosure is shown.

[0056] Figure 2 Schematic diagram showing an external script calling method according to an embodiment of the present disclosure

[0057] Figure 3 A structural block diagram of an external script calling device according to an embodiment of the present disclosure is shown.

[0058] Figure 4 A structural block diagram of an electronic device according to an embodiment of the present disclosure is shown.

[0059] Figure 5 A schematic diagram showing the structure of a computer system suitable for implementing the method according to an embodiment of the present disclosure is shown. DETAILED DESCRIPTION

[0060] Hereinafter, exemplary embodiments of the present disclosure will be described in detail with reference to the accompanying drawings so that those skilled in the art can easily implement them. In addition, for the sake of clarity, parts not related to the description of the exemplary embodiments are omitted in the accompanying drawings.

[0061] In the present disclosure, it should be understood that terms such as "include" or "have" are intended to indicate the presence of features, numbers, steps, actions, components, parts, or combinations thereof disclosed in the present specification, and are not intended to exclude the possibility that one or more other features, numbers, steps, actions, components, parts, or combinations thereof exist or are added.

[0062] It should also be noted that, in the absence of conflict, the embodiments and features of the embodiments of the present disclosure may be combined with each other. The present disclosure will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.

[0063] As mentioned previously, many existing games support custom modules (mods) to allow players to customize and extend the game to facilitate dynamic adjustments to content and rules. Modules exist in the form of external scripts or resource packs. Their core function is to allow non-professional developers to modify data, combine rules, or create new mechanics within the game framework.

[0064] To achieve this goal, the game needs a built-in script interpretation architecture that covers three major technical aspects: first, define standardized script interfaces and API function libraries, and clarify the logical access points that modules can call (such as event triggering, data reading and writing); second, the script interpreter parses external scripts at runtime and converts them into instruction sets or data structures that the game can recognize. For example, the "add new weapons" instruction can be broken down into resource loading, attribute binding and other operation steps; finally, the sandbox isolation mechanism is used to limit the module's access to the core code to avoid crashes caused by logical conflicts.

[0065] Traditional script interpreters are typically based on single-threaded logic (such as MonoBehaviours) and are unable to fully utilize the computing power of multi-core CPUs, causing complex logic (such as physics simulation, AI decision-making, etc.) to become performance bottlenecks. DOTS is a high-performance programming paradigm whose core goal is to break through the performance bottlenecks of traditional object-oriented programming (OOP) and significantly improve game efficiency through data-oriented design, multi-threaded parallel computing, and efficient memory management. Currently, because scripts and the high-speed DOTS framework run in different environments, data interaction is difficult for existing technologies. External scripts cannot take advantage of the performance advantages of DOTS, and data structures are stored in memory in a random manner, increasing memory usage and reducing cache hit rates. This makes the calling process of external scripts prone to delays, which in turn causes adverse conditions such as game screen freezes and excessive loading times, affecting the user experience.

[0066] To address the above issues, the present disclosure provides a method, apparatus, and device for executing external scripts that are compatible with the DOTS framework, thereby fully leveraging the performance advantages of the DOTS framework and enabling high-speed execution of external scripts. The solutions of the embodiments of the present disclosure are applicable not only to gaming scenarios, but also to the invocation of external scripts in other software scenarios. For ease of understanding, the following description of the embodiments of the present disclosure focuses primarily on gaming scenarios.

[0067] Figure 1 Flowchart showing the external script calling method according to an embodiment of the present disclosure. Figure 1 As shown, the external script calling method includes the following steps S101-S106:

[0068] In step S101, one or more script class instances are obtained based on the external script;

[0069] In step S102, the memory size occupied by the script structure corresponding to the instance of the script class is determined according to the memory size occupied by the preset structure corresponding to the script class;

[0070] In step S103, the total memory size occupied by the script structures corresponding to the instances of the one or more script classes is calculated according to the memory size occupied by the script structures corresponding to the respective instances of the one or more script classes;

[0071] In step S104, memory space is applied for according to the calculated total memory size;

[0072] In step S105, the script structure corresponding to each instance of the one or more script classes is stored in the memory space;

[0073] In step S106, the external script is executed by reading the script structure from the memory space.

[0074] According to an embodiment of the present disclosure, the external script is written according to a preset writing specification.

[0075] For example, taking the JSON structure external script in the DOTS architecture game as an example, the writing specifications may include: defining keywords and values ​​through key-value pairs (Binding), where the value can be a separate lexical unit (Token) or a scope (Scope) enclosed by curly braces {}, which can contain other key-value pairs. According to an embodiment of the present disclosure, curly braces {} can also be used to contain multiple lexical units instead of key-value pairs to represent intervals, arrays, etc. Scopes, key-value pairs, and lexical units can be collectively referred to as structures (Construct).

[0076] According to an embodiment of the present disclosure, in step S101, obtaining one or more script class instances based on an external script may include: parsing the external script to obtain a scope; and converting the scope into the one or more script class instances.

[0077] According to an embodiment of the present disclosure, an external script is parsed into a scope, in which other structures are nested.

[0078] After obtaining the scope, the scope is converted into an instance of a script class. The script class may include any one of the following: a key-value pair, and a conditional judge.

[0079] The following uses the JSON structure of an external Trigger (conditional judgement) script in a DOTS-based game as an example. Trigger scripts are used to determine whether a condition is met and can contain various types, such as:

[0080] 1. Ordinary trigger: trigger name = parameter

[0081] For example, is_male = true / / is judged to be male

[0082] Parameters can be complex parameters,

[0083] For example, has_opinion_modifier = {

[0084] target = xx

[0085] type = modifier_type

[0086] }

[0087] / / Judge whether there is a specific type of favorability correction for a certain character

[0088] 2. Numeric comparison trigger: trigger name >>= =<=< parameter

[0089] If age>= 16

[0090] 3. Switch the current object and make a judgment

[0091] For example, father = {

[0092] is_alive = true

[0093] }

[0094] / / Check if the father is still alive

[0095] 4. Traverse the list trigger and compare the number of objects in the list that meet the conditions with the values

[0096] For example, every_child = {

[0097] is_adult = true

[0098] Is_married = false

[0099] count>1

[0100] }

[0101] / / Judge whether the number of unmarried adult children is greater than 1

[0102] 5. Logical trigger, judging whether multiple compound conditions satisfy a certain logical relationship

[0103] If NOR = {

[0104] is_adult = true

[0105] Is_married = false

[0106] }

[0107] / / Judging that adult and unmarried cannot be true at the same time

[0108] When parsing a Trigger script, the key in a key-value pair is parsed as a conditional keyword, and the value is parsed as a conditional parameter. For example, is_male = false, where is_male is the conditional keyword and false is the conditional parameter. This script determines whether the current character is not male. Conditions can be nested. For example, NOR = { is_male = false is_adult = true} indicates that the two conditions of not being male and being an adult cannot be met at the same time. Therefore, a Trigger can also contain sub-Triggers, and the result of the sub-Trigger is used to determine whether the current Trigger is true. A base class TriggerBase can be designed, and the above-mentioned types of Triggers are all subclasses of TriggerBase. When converting to an instance of the script class, the conditional keyword obtained from the parsing is used to determine which subclass instance the parsed Construct should be further converted into.

[0109] Specifically, the above-mentioned trigger types can be converted into the following script classes: SingleTrigger, ValueCompareTrigger, ContextChangeTrigger, ListTrigger, LogicTrigger. As can be seen from the script structure, ContextChangeTrigger, ListTrigger, and LogicTrigger contain multiple TriggerBases as sub-conditions.

[0110] In step S102, the memory size occupied by the script structure corresponding to the instance of the script class is determined according to the memory size occupied by the preset structure corresponding to the script class.

[0111] According to an embodiment of the present disclosure, each script class may have a corresponding preset structure, which has multiple preset fields and occupies a preset memory space. According to an embodiment of the present disclosure, the preset structure corresponding to the script class includes: value-type data of the script class; and / or a pointer to reference-type data of the script class.

[0112] By setting a preset script structure for each script class, after parsing and converting the external script to obtain an instance of the script class, the total memory size occupied by the script structure corresponding to the instance converted from the external script can be quickly calculated based on the number of instances of each script class and the memory size occupied by the preset structure corresponding to each script class.

[0113] In the above external Trigger script example, the corresponding script structure is designed according to the structure of each subclass. For example:

[0114] The SingleTrigger class inherits from TriggerBase and contains triggerName (trigger name) and arguments (arguments). The SingleTriggerStruct structure corresponding to the SingleTrigger class contains three fields: triggerBaseStruct, triggerName, and argument. Class identification information (for example, an enumeration) used to distinguish the current trigger type is stored in triggerBaseStruct; triggerName is used to store the trigger name; and argument is used to store the trigger's arguments.

[0115] According to an embodiment of the present disclosure, when any instance contains a reference to another instance, the script structure corresponding to that instance stores a memory pointer to the other instance. Because the memory space required to store a memory pointer is fixed, storing the memory pointer of the script structure of the referenced instance in the structure rather than directly storing the referenced instance allows references to various different instances while ensuring that the memory space occupied by the script structure remains unchanged.

[0116] In step S103 , the total memory size occupied by the script structures corresponding to the instances of the one or more script classes is calculated according to the memory size occupied by the script structures corresponding to the respective instances of the one or more script classes.

[0117] For example, assuming that the preset structure of script class A occupies X bytes, the preset structure of script class B occupies Y bytes, and the external script is converted to obtain 3 instances of script class A and 2 instances of script class B, then the script structures corresponding to the instances obtained by the external script conversion occupies a total of 3X+2Y bytes.

[0118] In step S104, memory space is applied for according to the calculated total memory size.

[0119] In the above example, the total memory size is calculated to be 3X+2Y bytes, so a memory space of 3X+2Y bytes is applied for. According to an embodiment of the present disclosure, the memory space can be a continuous memory space.

[0120] In step S105 , the script structures corresponding to the instances of the one or more script classes are stored in the memory space.

[0121] According to an embodiment of the present disclosure, the script structures corresponding to the instances of the one or more script classes can be continuously stored in the memory space. After the script structures are stored, the memory address of the script structure of the referenced instance can be obtained and assigned to the script structure of the referenced instance.

[0122] Taking two instances M (called the first instance) and N (called the second instance) with a reference relationship as an example, assuming that the first instance references the second instance, the memory address of the script structure of the second instance can be obtained and assigned to the memory pointer in the structure of the first instance used to store the script structure of the referenced instance.

[0123] According to the embodiments of the present disclosure, the structure can be memory aligned, thereby effectively reducing the memory space occupied, and after the memory alignment is performed, access to the data in the structure can be completed through a single memory access. The embodiments of the present disclosure are aimed at large-scale numerical computing scenarios, and the random memory pool allocation method in the existing technology is changed to a continuous memory pool allocation through a script structure. The continuously stored structure will trigger memory locality preloading when loading, so that the computer cache hit rate is greatly improved, and the memory operation speed is effectively improved. Therefore, this solution can effectively reduce the memory space occupied, while improving the cache hit rate and improving data access efficiency.

[0124] In step S106, the external script is executed by reading the script structure from the memory space.

[0125] According to an embodiment of the present disclosure, executing the external script by reading the script structure from the memory space includes: generating a task structure including a task interface or a parallel loop task interface according to the external script logic; creating a script structure array and a result array according to the script structure and the task structure; compiling the script structure array and the result array into an external script native array code by a compiler; and scheduling and running the external script native array code to execute the external script.

[0126] For example, a structure that implements the IJob or IJobParallelFor interface can be generated based on the external script logic, and the external script structure array and result array can be packaged as NativeArray (external script native array code compatible with the Burst compiler); then the Burst Job is scheduled in the main thread to execute the external script.

[0127] Figure 2 A specific example of converting an external script into a script structure is shown.

[0128] like Figure 2 As shown, the external script text is:

[0129] trigger = {

[0130] NOR = {

[0131] is_male = false

[0132] age>16

[0133] }

[0134] }

[0135] This script describes a compound judgment condition, requiring that the two conditions of not being male and being older than 16 cannot be true at the same time.

[0136] By parsing the external script, two scopes Scope_1 and Scope_2 are obtained, where Scope_1 contains Scope_2 that describes a compound condition, and Scope_2 contains Bindings of two simple conditions.

[0137] The scope is converted to three instances, Trigger_1, Trigger_2, and Trigger_3. In the object-oriented framework, these three instances are stored randomly, and Trigger_1 holds references to Trigger_2 and Trigger_3.

[0138] Determine the memory size occupied by the corresponding preset structure based on the script class to which Trigger_1, Trigger_2, and Trigger_3 belong. Calculate the total memory occupied by the script structures corresponding to these three instances and apply for a whole block of memory space.

[0139] Generate the corresponding script structures for Trigger_1, Trigger_2, and Trigger_3 and store them consecutively in memory. Since Trigger_1 references Trigger_2 and Trigger_3, the memory pointers of the script structures of Trigger_2 and Trigger_3 are stored in the script structure of Trigger_1.

[0140] The high performance of DOTS's data-oriented architecture stems from its CPU cache design, which stores data that may be used simultaneously in contiguous memory locations, significantly improving CPU cache hit rates. However, object-oriented implementations typically store data via pointers or references, resulting in randomized memory locations. Furthermore, the Burst compiler restricts most C# types to value types and pointers.

[0141] Therefore, in order to make good use of the advantages of DOTS, the embodiment of the present disclosure stores the structure obtained by script conversion in continuous memory, so that when it is executed, the reading and writing of the script content has a high cache hit rate like DOTS, and can also support Burst compilation.

[0142] To parse user-defined script languages ​​(rather than general-purpose languages ​​like Lua), a script parser must be designed. Designing a script parser within the DOTS framework is extremely difficult. Therefore, the disclosed embodiments do not directly parse scripts into script structures. Instead, they first parse them into instances of various script classes using an object-oriented approach, and then convert these instances into script structures. In other words, the script structure becomes the middleware connecting object-oriented scripts with the DOTS framework.

[0143] According to an embodiment of the present disclosure, the Burst compiler can compile programming language code into more efficient machine code. It can generate corresponding native code for different platform types and perform bottom-level optimization of the code during compilation, such as vectorization, inline optimization, instruction scheduling, etc. The embodiment of the present disclosure uses the Burst compiler to optimize and accelerate the native array code segments of the external script containing complex operations during the execution of the external script, thereby obtaining better performance than using other compilers to optimize and accelerate such code segments, thereby improving the execution speed when the program calls the external script.

[0144] Figure 3 The following is a structural block diagram of an external script calling device according to an embodiment of the present disclosure, wherein the device can be implemented as part or all of an electronic device through software, hardware, or a combination of both.

[0145] like Figure 3 As shown, the external script calling device 200 includes:

[0146] The script parsing module 201 is configured to obtain one or more instances of script classes based on the external script;

[0147] The memory preset module 202 is configured to determine the memory size occupied by the script structure corresponding to the instance of the script class according to the memory size occupied by the preset structure corresponding to the script class;

[0148] The memory calculation module 203 is configured to calculate the total memory size occupied by the script structures corresponding to the instances of the one or more script classes according to the memory size occupied by the script structures corresponding to the respective instances of the one or more script classes;

[0149] The memory pool management module 204 is configured to apply for memory space according to the calculated total memory size;

[0150] The script structure management module 205 is configured to store the script structure corresponding to each instance of the one or more script classes in the memory space;

[0151] The script task execution module 206 is configured to execute the external script by reading the script structure from the memory space.

[0152] According to an embodiment of the present disclosure, obtaining one or more instances of script classes based on an external script includes:

[0153] Parse the external script to obtain the scope;

[0154] The scope is converted into an instance of the one or more scripting classes.

[0155] According to an embodiment of the present disclosure, the scope includes at least one of the following: a scope, a key-value pair, and a lexical unit;

[0156] The script class includes any one of the following: a key-value pair, a conditional judge.

[0157] According to an embodiment of the present disclosure, the memory space is continuous;

[0158] The storing the script structures corresponding to the instances of the one or more script classes in the memory space includes continuously storing the script structures corresponding to the instances of the one or more script classes in the memory space.

[0159] According to an embodiment of the present disclosure, the preset script structure corresponding to the script class includes: value type data of the script class; and / or a pointer to reference type data of the script class.

[0160] According to an embodiment of the present disclosure, when any instance contains a reference to another instance, a memory pointer of the other instance is stored in a script structure corresponding to the instance.

[0161] According to an embodiment of the present disclosure, storing the script structures corresponding to the instances of the one or more script classes in the memory space includes:

[0162] Get the memory address of the script structure corresponding to the second instance referenced by the first instance;

[0163] Assign a value to a memory pointer in the structure of the first instance according to the memory address of the script structure corresponding to the second instance.

[0164] According to an embodiment of the present disclosure, executing the external script by reading the script structure from the memory space includes:

[0165] Generate native code based on the script structure through a compiler;

[0166] The native code is executed to execute the external script.

[0167] The present disclosure also discloses an electronic device, Figure 4 A structural block diagram of an electronic device according to an embodiment of the present disclosure is shown.

[0168] like Figure 4 As shown, the electronic device includes a memory and a processor, wherein the memory is used to store one or more computer instructions, wherein the one or more computer instructions are executed by the processor to implement the method according to an embodiment of the present disclosure.

[0169] Figure 5 A schematic diagram showing the structure of a computer system suitable for implementing the method according to an embodiment of the present disclosure is shown.

[0170] like Figure 5 As shown, the computer system includes a processing unit that can execute the various methods of the above-described embodiments based on a program stored in a read-only memory (ROM) or a program loaded from a storage unit into a random access memory (RAM). The RAM also stores various programs and data required for the operation of the computer system. The processing unit, ROM, and RAM are connected to each other via a bus. An input / output (I / O) interface is also connected to the bus.

[0171] The following components are connected to the I / O interface: an input section including a keyboard, mouse, etc.; an output section including a cathode ray tube (CRT), liquid crystal display (LCD), and speakers; a storage section including a hard disk; and a communication section including a network interface card such as a LAN card and a modem. The communication section performs communication processes via a network such as the Internet. A drive is also connected to the I / O interface as needed. Removable media such as magnetic disks, optical disks, magneto-optical disks, semiconductor memories, etc. are installed in the drive as needed, so that computer programs read from them can be installed in the storage section as needed. The processing unit can be implemented as a CPU, GPU, TPU, FPGA, NPU, or other processing unit.

[0172] In particular, according to embodiments of the present disclosure, the methods described above can be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program tangibly embodied on a machine-readable medium, the computer program comprising program code for executing the methods described above. In such embodiments, the computer program can be downloaded and installed from a network via a communication component and / or installed from removable media.

[0173] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, program segment or part of code, and the module, program segment or part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or can be implemented using a combination of dedicated hardware and computer instructions.

[0174] The units or modules involved in the embodiments described in this disclosure may be implemented by software or programmable hardware. The units or modules described may also be provided in a processor, and the names of these units or modules do not, in certain circumstances, constitute limitations on the units or modules themselves.

[0175] As another aspect, the present disclosure further provides a computer-readable storage medium. This computer-readable storage medium may be included in the electronic device or computer system described in the above embodiments, or may be a standalone computer-readable storage medium not incorporated into the device. The computer-readable storage medium stores one or more programs, which are used by one or more processors to execute the methods described in the present disclosure.

[0176] The above description is merely a preferred embodiment of the present disclosure and an illustration of the technical principles employed. Those skilled in the art should understand that the scope of the invention herein is not limited to technical solutions formed by specific combinations of the aforementioned technical features. It also encompasses other technical solutions formed by any combination of the aforementioned technical features or their equivalents, without departing from the inventive concept. For example, a technical solution formed by replacing the aforementioned features with (but not limited to) technical features with similar functions disclosed in this disclosure.

Claims

1. A method for executing an external script, characterized in that: include: Parsing an object-oriented external script to obtain one or more scopes, and converting the scopes into instances of one or more script classes, wherein the scopes include at least one of the following: a key-value pair and a lexical unit; and the script classes include any one of the following: a key-value pair and a conditional judge; Determining the memory size occupied by a script structure corresponding to an instance of the script class according to the memory size occupied by a preset structure corresponding to the script class, wherein the preset script structure corresponding to the script class includes: value type data of the script class; and / or a pointer to reference type data of the script class; Calculating the total memory size occupied by the script structures corresponding to the instances of the one or more script classes according to the memory size occupied by the script structures corresponding to the instances of the one or more script classes; Apply for continuous memory space based on the calculated total memory size; Continuously storing the script structures corresponding to the instances of the one or more script classes in the memory space; The object-oriented external script is executed under the DOTS framework by reading the script structure from the memory space.

2. The method for executing an external script according to claim 1, wherein: When any instance contains a reference to another instance, the script structure corresponding to the instance stores the memory pointer of the other instance.

3. The method for executing an external script according to claim 2, wherein: The step of continuously storing the script structures corresponding to the instances of the one or more script classes in the memory space includes: Get the memory address of the script structure corresponding to the second instance referenced by the first instance; Assign a value to a memory pointer in the structure of the first instance according to a memory address of the script structure corresponding to the second instance.

4. The method for executing an external script according to claim 1, wherein: The step of reading the script structure from the memory space and executing the object-oriented external script under the DOTS framework includes: Generate native code based on the script structure through a compiler; The native code is executed to execute the object-oriented external script.

5. A device for executing an external script, characterized in that: include: A script parsing module is configured to parse an object-oriented external script to obtain one or more scopes, and convert the scopes into instances of one or more script classes, wherein the scopes include at least one of the following: a key-value pair and a lexical unit; and the script classes include any one of the following: a key-value pair and a conditional judge. A memory preset module is configured to determine the memory size occupied by a script structure corresponding to an instance of the script class based on the memory size occupied by a preset structure corresponding to the script class, wherein the preset script structure corresponding to the script class includes: value type data of the script class; and / or a pointer to reference type data of the script class; A memory calculation module is configured to calculate a total memory size occupied by the script structures corresponding to the instances of the one or more script classes according to the memory size occupied by the script structures corresponding to the respective instances of the one or more script classes; The memory pool management module is configured to apply for continuous memory space according to the calculated total memory size; a script structure management module configured to continuously store the script structures corresponding to the instances of the one or more script classes in the memory space; The script task execution module is configured to execute the object-oriented external script under the DOTS framework by reading the script structure from the memory space.

6. An electronic device, characterized in that: The method comprises a memory and a processor; wherein the memory is used to store one or more computer instructions, wherein the one or more computer instructions are executed by the processor to implement the method according to any one of claims 1 to 4.

7. A computer-readable storage medium having computer instructions stored thereon, characterized in that: When the computer instructions are executed by a processor, the method according to any one of claims 1 to 4 is implemented.

Citation Information

Patent Citations

  • Method and device for uploading resource files by game engine, and computer

    CN102799456A

  • Script code execution method and device, storage medium and equipment

    CN114489859A