Cocos2d-x scripting language LUA basic syntax

Source: Internet
Author: User
Tags lua

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:

    1. Output statement
    2. Variable Definition and Assignment
    3. Method definition and invocation
    4. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.