L1 [variable] 01 Variable naming rules
Naming: alphanumeric underscore constitute the beginning but can not figure does not recommend Chinese name many of them do not support the Chinese , but such kind of touch Faerie in some other editors inside it
Note: The variable name must contain a certain meaning for example, we use a variable to store a value such as we age, with x = 18 others to see your source code to see where she did not understand the variable X is 18 what does it mean if we use age = 18 then he see at our own convenience is also convenient to others this is a good habit worth cultivating
Note that variable names are case sensitive
Note: Some system variable names do not take up these reserved words reserved words such as some Lua's own statements if else end function
Note: If the specification that we can differentiate our best wording for global and local variables such as global variables p_x = 14 p is the abbreviation for public local variables l_y l but at the local acronym is the actual situation need not be so little code
Tips: lua version purple cat teacher is some code lua5.3 tutorial is on this basis
Way switch
zeroBrane Studio project inside --lua interpreter -lua5.3
Ll [variable] 02. Lua statement block characteristic
Tips: The signal becomes prone to insert mode cursor
Just because the keypad is 0 insert key keypad mode switching point 0 into a wrong click leads to insert the cursor changes to insert
Here the teacher slightly raised define a variable trceprint then trceprint = print and trceprint it has the features and attributes of the print function of fact, this is to be mentioned later under Lua lua function is a data type function can be used as ordinary variables random assignment is performed such that x = 10 and x is the integer x = "test" However, if the string x is x = print this data type is a function of x is used because the function can be so under lua understanding is very special
Tips: multiple lines of code written in lua wording row
In accordance with the common specifications are generally so in other languages
age = 15; print (age) ; address = " Shandong"; print (address) at intervals of a semicolon to write multiple lines as a single line which is the most standard most commonly used to write law
But can lua lua multiple lines without any gap will automatically determine and resolve the problem as there are no big problem if the interval between the code into a blank
Conclusion: Understanding have written in this way, but for the code reader is a very bad habit or suggestions can be separated by semicolons
L1 [variable] 03. Single-line comments and multiline comments skills
Notes nothing to say
The role of the comment: make their own code or read someone else read your code structure ideas
Even if you personally spent a lot of effort to write the project code if the interval is one month or two months, you look at the code will not remember a lot of things at that time so the idea of writing a lot of projects are not one-shot deal may need to be adjusted later a these modules add new modules or other customers have requested additional time is too long forgotten once the code was thinking for our own customers is unacceptable loss so readily to write notes or worth cultivating the habit of
Multiline comments:
--[[
XXXX
--]]
Single-line comments:
--XXXXXX
Common comments and write comments when the code is inserted under the personal understanding (for reference only and only in large projects with multi-point)
1. Customer Interaction Analyzer and run the script out of the basic processes and ideas
2. List the basic flow of the code at the beginning of the current script
3 and according to several steps substantially corresponding to the filling function
- [[ Function: the daily check-ins XXapp 1 reads account information 2. try to log 3. Log successful operation check 4. Exit account 5. exception process information and feedback - ]] - 1 reading account information readaccount () - 2. attempts to log logApp () - 3. successful login operation check signApp () - 4. exit account quitApp () - 5. The exception process information and feedback errorApp ()
4 corresponding to improve the function and the body structure
Improve the function of this step is still the first to write functions and general steps and then walk to the code step inside and wait for further refinement filling
- [[ Function: responsible for reading account information corresponding to 1. Determine the account file 2. Determine the number of rows read account 3. Read the account and password and determines whether the valid simple 4. illegal or other abnormal function returns a null character returns string legitimate account password string - ]] function readaccount () - 1. determining an account files - 1--1 if the file does not exist, without performing the subsequent operation function returns an empty string - 2. read determined taking account number of rows - 3. read the account and password and determines whether the valid simple - 4. illegal function returns an empty string returns valid account password string end
Notes on the use of the overall structure is the case there are some scattered comments on the casual applications such as general and the Bank are on the same line
Print ( " readaccount " ) - to test whether a function to readaccount
If part of the code may be written to annotate code above this case may be
Tip: Quick allow multiple line comments fail
---[[
XXX
XXX
--]]
L1 [variable] 04. What is variable
The basic concept of variable nothing to say
But I remember the scope of global variables local variables such as the back is a bit frustrating to see if the teacher talked about this part of the
Ll [variable] 05. The data type nil
Nil value of only one type of the value nil
If the variable is not assigned then his value is nil
Ll [variable] 06 string data type number is
Negative integer decimal numeric considered a numeric
String
Single or double quotation marks in [[]] surrounding the string are counted and noted [[]] can be pre-formatted contents inside a large role for some of our complex string
Tips: Assignment complex string [[]]
Complex string will output the contents intact out we do not need to advance certain character in the string of escape or other pre-processing is very good
Readily mention or so later elaborate on the teacher
Data type conversion forced tostring () tonumber (), etc.
Get the current data type --- type function '
Determine whether it is a data type - type or function can also be used to determine
Ll [variable] 07 Boolean data type from other types of
In addition to nil and the corresponding false false Everything else is true no more
Roughly speaking also a little eight kinds of data types have nothing to say in more detail later
123