A kind of lua script file management method that adopts machine contracting system
Technical field
The present invention relates to a kind of script, especially a kind of lua script file management method that adopts machine contracting system.
Background technology
Server end and client in online game need be applied to the lua script technology usually.These lua codes are distributed in a large amount of lua scripts usually, so these lua scripts are managed with regard to mechanism of needs.This mechanism need satisfy following demand:
1. can manage a plurality of lua scripts, these lua scripts all must be carried in the same lua virtual machine so that carry out communication;
2. not only need be able to communicate with one another but also must keep certain independence between the different lua scripts.
Lua itself provides certain mechanism to manage a plurality of lua script files, but it has the comparison critical limitations to cause and can not directly in game products, directly use:
Though 1.lua module (module) mechanism is provided self, can guarantee that a script file loads once, the conflict each other of the object of the same name of different files;
2. the tangible incidence relation of neither one between the different files is unfavorable for the tissue that programmed logic concerns.
Summary of the invention
For overcoming above-described defective, the present invention has realized a kind of management method of lua virtual machine, and existing lua virtual machine is transformed, and can manage a large amount of lua script files flexible and efficiently.
The present invention has proposed a kind of lua script file management method that adopts machine contracting system for this reason; It comprises the bag as the container of object name in the program; Each different lua script file is corresponding to a bag, each exclusive sign (ID) that has been responsible for assigning, and the father (parents) that each Bao Jun has an ID that is used to preserve the bag that current pack comprises shows and is used to preserve the name table of the name of the object that current pack refers to; Said encapsulating further is set to: separate between the bag; And set up between bag through certain applications program interface (API) and to be called the vertical linkage that comprises (include), a bag can be comprised by a plurality of bag, also can comprise a plurality of bags; But a bag only knows and oneself comprised those bags, and do not know ownly to be comprised by those bags;
Said method also includes overall situation bag, and it does not need to be configured to involved promptly visible for other all bags automatically;
Said method also includes the bag table of unified lua script file name to bag, is used for bag is retrieved;
Said method has also defined following script file and has loaded flow process:
1) search the script file that need to load whether in the bag table, then jump to 6 in this way), as otherwise continue next step;
2) newly-built bag, and distribute ID to add the bag table;
3) whether inspection includes other bag, as otherwise jump to 6), then continue next step in this way;
4) load involved bag;
5) parents with involved bag adding current pack shows;
6) loading scripts file.
As a kind of improvement of above technical scheme, said method has also been introduced overall bag, and the said overall situation encapsulates and is configured to need do not comprised by other bag promptly is that other all bags are visible automatically.
As a kind of improvement of above technical scheme, said method comprises following filename finding step:
1) search in the name table in current pack earlier, find and then finish to search, the person does not continue next step;
2) in overall situation bag, search, find and then finish to search, the person does not continue next step;
The name table of the bag of 3) successively parents table being quoted is searched.
As a kind of improvement of above technical scheme, wherein search and adopt the traversal rule of dark search earlier.
With respect to prior art, lua script management method proposed by the invention has the following advantages:
1.lua script file all is carried in the same lua virtual machine, has guaranteed the internal memory service efficiency and has carried out efficient;
2. different lua script files is separate, and the object of the same name in the different files can not conflict mutually;
3. different lua script files can carry out communication through the specific mechanism shared data;
4. though the lua virtual machine is transformed, is still kept compatible in the grammer aspect.
Description of drawings
Below in conjunction with accompanying drawing and embodiment the present invention is further specified.
Fig. 1 is the synoptic diagram of the mutual relationship of wrapping among the present invention;
The synoptic diagram that Fig. 2 forms for the structure of wrapping among the present invention;
Fig. 3 loads the synoptic diagram of flow process for script file among the present invention.
Embodiment
Technical scheme of the present invention utilizes a kind of machine contracting system to manage each lua script file, and each different lua script file is corresponding to a bag, and wherein bag is the container of object name in a kind of program, and object then is the entity of data structure or function in the program.Each bag identifies (ID) with a numeral, in a preferred embodiment, bag be designated one more than or equal to 0 integer, promptly begin to increase progressively from numeral 1.
Each bag all has oneself independently name space, the i.e. mapping table of object name and object.The present invention also includes the bag table of a unified filename to bag, and it is a kind of mapping table of key-value type, is used for the mapping of script file name to corresponding bag, is used in the present invention bag is retrieved.
In the present invention, encapsulate be configured to separate, but can through certain applications program interface (API) the bag between set up vertical linkage, this vertical linkage is called and comprises (include).That is to say that include is the address of a kind of vertical linkage between bag and the bag, also is to set up the used API name of this connection.Specifically, (include) bag A if bag B comprises, the object that then wraps A is visible for bag B; But can not set up backward linkage simultaneously,, then not allow to wrap A and comprise B if promptly bag B has comprised bag A.A bag can be comprised by a plurality of bag, also can comprise a plurality of bags.But a bag only knows and oneself comprised those bags, and do not know ownly to be comprised by those bags.Specifically as shown in Figure 1.
In addition, the present invention also includes a special overall situation bag, and Digital ID is 0, need not comprised promptly visible for other all bags automatically by other bag.
Specifically, all have during each wraps two kinds of key data structure arranged:
1. father (parents) table: a kind of by the bag set table of using, the member is by the ID of the bag of the Include of current pack institute, is used to preserve the ID of the bag that current pack comprises in the present invention;
2. name table: a kind of mapping table of key-value type, be used for of the mapping of object name to object, be used to preserve the name of the object that current pack refers in the present invention.
Its concrete structure is as shown in Figure 2.Fig. 3 has shown that its step comprises according to script file loading flow process of the present invention:
1) search the script file that need to load whether in the bag table, then jump to 6 in this way), as otherwise continue next step;
2) newly-built bag, and distribute ID to add the bag table;
3) whether inspection includes other bag, as otherwise jump to 6), then continue next step in this way;
4) load involved bag;
5) parents with involved bag adding current pack shows;
6) loading scripts file.
Lua need obtain corresponding object according to name when carrying out, this process is called as name and searches.In the present invention, searching through following steps of lua script file name realized in the present invention:
1. in the name table of current pack, search earlier, find and then finish to search;
2. in overall situation bag, search, find and then finish to search;
3. the name table of the bag of successively parents table being quoted is searched, and finds and then finishes to search.
The traversal rule of wherein searching is dark search earlier, or is called depth-first search.
Like this, with respect to prior art, lua script management method proposed by the invention has the following advantages:
1.lua script file all is carried in the same lua virtual machine, has guaranteed the internal memory service efficiency and has carried out efficient;
2. different lua script files is separate, and the object of the same name in the different files can not conflict mutually;
3. different lua script files can carry out communication through the specific mechanism shared data;
4. though the lua virtual machine is transformed, is still kept compatible in the grammer aspect.
Certainly, the present invention is except above-mentioned embodiment, and other equivalent technical solutions also should be within its protection domain.