SolutionLua syntaxMissing and alternative measures are the content to be introduced in this article, mainly to understandLUA syntax.LuaA design policy is simple. If you do not want to add any language features, try not to add them. So,LuaSome of the commonSyntax. The following is a reference in C language.
The continue statement is missing, although it has no essential impact on logical implementation. However, when programming, we feel that the code structure is not flexible.
The switch-case syntax is missing and can only be replaced by if-elseif-else. When there are many options, the code is ugly and inefficient.
There is no logical operator AND, OR, NOT, which causes a lot of inconvenience in the expression of some flag combination expressions.
In addition, I also want to talk about the following points about Lua's design:
The non-equal sign is ~ =, Not! =. Personally think! = It is more accurate to express the non-equals meaning ,~ It means "not", and "not" is different from "not equal. Of course, this may be the reason why the author is different from ours.
By default, the Division is a floating-point Division without any integer division operation. To obtain an integer, you must use the truncation function of the math library.
The Continue statement is implemented by patching.
Logical operation ,! = Operator, logical operator, bitwise operator, and shift operator are also implemented through a patch.
However, we did not find the Switch patch on Lua's official website. We found that we can use the table features of Lua, Which is elegant.
The alternative syntax of the Switch statement is one of the best, most concise, and most efficient solutions that best reflect the characteristics of Lua)
- action = {
- [1] = function (x) print(x) end,
- [2] = function (x) print( 2 * x ) end,
- ["nop"] = function (x) print(math.random()) end,
- ["my name"] = function (x) print("fred") end,
- }
-
- while true do
- key = getChar()
- x = math.ramdon()
- action[key](x)
- end
Summary: The content of the Lua syntax and alternative measures has been introduced. I hope this article will help you!