Lua scriptManager Details are the content to be introduced in this article. This is not a text editor or ide, but it is actually a dll,LuaIt is the glue language. The purpose of this manager is to make C/C ++ better support.Lua.
Management in projectsScriptThe methods are separate file storage,LuaThere is no concept of engineering, so the file is the smallest unit, so the increase in the number of script files will bring a problem, name pollution. The variables defined in lua are global by default. Only the local variables are defined locally, in this way, the function you define in script a may have the same name as the function defined in script B. This does not cause any errors or warnings, because the function is a value in lua, you can modify it at any time.
Export a global function Include, which can include other scripts, just like # Include in C. In fact, it does not contain any content, but only establishes a relationship network between scripts, each script is a vertex, and Include establishes an arrival relationship. Each script is isolated, that is, the variables in different scripts can have the same name but different variables, which are implemented through the function environment.
The key thing is the priority relationship. Although there is no statement defining variables in lua, there are index and newindex events, the index event is triggered when t [k] is set for a set of values, and the newindex event is triggered when t [k] = v is set for a set of values. The latter is equivalent to defining variables, that is, the first use.
The index priority is: local> script> register-table> global. register-table is the sum of some items exported from C. The general principle is that more specific things are considered first. First, find the local variable. If the local variable is not found, find the variable in the current environment. If the local variable is not found, find the variable in other scripts that can be reached by the Include relationship. If the variable is not found, find the variable in register-table, the global variable is not found.
The newindex priority is: local> script (no include)> global. If k is local, set k to v. Otherwise, if t is table, rawget (t, k) first) if it is found, set the value. Otherwise, the value in global is global. Otherwise, set the script. There is some confusion here. In other words, there is no value in the script and global at the same time. The value in global will still affect the value in the script, that is, do not define too many global values, for example, if you write in a script:
- function print()
- end
It will think of it as global print and redefine it.
In fact, you cannot define a new global Value in the script. If you define a value that does not exist in the global, it will be converted to a value in the script environment. Except for some system functions, the exported functions are not directly stored in global, so new global values cannot be defined.
Well, it limits you and gives you flexibility. There is a global function in Global that defines the global value and accepts 1 to 2 parameters. The first parameter is the name and the second parameter is the initial value. If you call an existing global value, an error message is returned, indicating that you have redefined a value. You can write in a script as follows:
- Global("Foo")
- function Foo()
- end
In this case, Foo is not here.ScriptAnd can be accessed in other scripts without using Include.
In addition, other functions are being added, suchLuaSerialization will be added in the futureLuaUser Data and lua debugging. I still learned a lot in this process. I found that I didn't need to find any information to learn lua. I just went to the official website to check the manual. The manual has only one page, which is very convenient.
Summary: Resolve a question aboutLua scriptThe content of the manager has been introduced. I hope this article will help you!