Cocos2d-x scripting language LUA basic syntax
The previous blog provides a brief introduction to the small language of Lua. This blog will give you a little bit of the LUA syntax. It's not voluminous to tell all of Lua's grammar, and here are some of the basics of the Lua language:
- Output statement
- Variable Definition and Assignment
- Method definition and invocation
- Use of the for iterator
--Output statement, "--" staring at print ("Hello lua") for Lua language--output "Hello Lua"--Define variables. Local is the keyword of Lua, which declares a local variable, assuming that it is a global variable, local num = 100print (num)--to define the method. function is Lua's keyword, used to declare a method function SayHello ()--Method start print ("Hello Lua") End- -method End--Call Method SayHello ()--Define a method, and returns a value. LUA can return multiple values function Max (A, B) if A>b then-if inference statement, here is assumed value of a is greater than the value of B. Return Areturn Aelse --otherwise return Breturn bendend--pass in two values, 2, 3, print Max 3print (max (2,3))--For loop. Iterative 1~100. Output 1~100 value for Var=1, Doprint (Var) end
from the above code, you can see that the Lua language is a scripting language, similar to JavaScript, remove the end of the ";", there is no parenthesis "{}", the variable definition does not specify a type. Get started very fast and it's possible to speed up your code. More specific syntax. Here is a link to an online document: http://manual.luaer.cn.
Cocos2d-x scripting language LUA basic syntax