Lua基础语法举例

Lua基础语法举例

ID:46865250

大小:159.50 KB

页数:17页

时间:2019-11-28

Lua基础语法举例_第1页
Lua基础语法举例_第2页
Lua基础语法举例_第3页
Lua基础语法举例_第4页
Lua基础语法举例_第5页
资源描述:

《Lua基础语法举例》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库

1、—Example1——FirstProgram.——Classichelloprogram.printOutputhelloPress'EnterJkeyfornextexample——Example2——Comments.——SinglelinecommentsinLuastartwithdoublehyphen.——[[Multiplelinecommentsstartv/ithdoublehyphenandtwosquarebrackets.andendwitht讨osquarebrackets.]]——

2、Andofcoursethisexampleproducesno——outputssinceit'sallcomments?OutputPress1EnteNkeyfornextexample——Example3—Uariables.一一Uariablesholdualuesvihichhauetypes,uariablesdonJthauetypes.a=lb=MabcMc=<>d=printprint>print>print>print>Outputnumber

3、stringtablefunctionPress9EnterJkeyfornextexample——Example4——Uariablenanes.一一Uariablenanesconsistofletters..digitsandunderscores.——Theycannotstartwithadigit.one_two_3=123——isvaliduarablename——l_two_3isnotavaliduariablename.OutputPressJEnter,keyfornextexample^—Example5

4、——MoveUariablenames.—Theunderscoreistypicallyusedtostartspecialvalues--like_UERSIONinLua.print<_UERSION>—SodonJtusevariablesthatstartwith—butasingleunderscore_isoftenusedasa——dummyuariable.OutputLua5.1PressJEnte*keyfornextexample——Example6——CaseSensitiue.一一Luaiscases

5、ensitiuesoalluariablenames&keywords——nustbeincorrectcase.ab=lAb=2AB=3printOutput123PressJEnkeyfornextexample^―Example7——Keywords.—Luareservedwordsare:and,break,do,else,elseif,—end,,false,for,functioni£.in,localsnil,not,orj.——repeatsreturn,,then,true,,until

6、,while.—Keywordscannotbeusedforuariablenanesj.—'and'isakeywordshutANDisnotsoitisalegaluariablename.AND=3print"ND〉Output3Press9Enter1keyfornextexamplea=usingle9quoted^stringanddoubleMquotedustringinside0b=JsingleJquotedJstringanddouble"quoted"stringinsideJc=[[nult

7、ipielineExample8——Strings.withJsingleJandMdoubleMquotedstringsinside.]]printdprintpFintOutputsingle'quoted'stringanddouble"quoted'stringinsidesingle9quoted^stringanddouble"quotedMstringinsidemultiplelinewith'singleJandMdoubleMquotedstringsinside.PressfEnkeyforn

8、extexample—Example9—Assignments.—Multipleassignmentsarevalid.—uarlj.uai'2=uar3,uar4a^bj-cj.dj.6=1.2,^three0,"Fmiu",5printCa^bj-cj.d

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。