摘要: --require("6-Coroutine")--仅加载一次,并不执行,参数为文件名不加后缀--dofile("6-Coroutine.lua") --加载并执行,参数为文件名加后缀--SayHey("kkkk")x=10 --默认是全局变量 show= function()local x = 1 阅读全文
posted @ 2016-10-27 21:47 无畏先锋 阅读(1143) 评论(0) 推荐(0) 编辑
摘要: --...表示课可见参数function alert(...)t = {...}for k , v in pairs(t) doprint(v)endendalert ("你好吗",{"error","warning"}) 阅读全文
posted @ 2016-10-27 21:17 无畏先锋 阅读(1479) 评论(0) 推荐(0) 编辑
摘要: --函数--语法 function函数名(参数) end--参数 ...表示无限多个参数--返回值用return 可以有多个返回值function add(a,b)return a +b--bodyend--委托myadd= addevent= {}event.add = addprint(eve 阅读全文
posted @ 2016-10-27 21:14 无畏先锋 阅读(2083) 评论(0) 推荐(0) 编辑
摘要: --table的嵌套playerInfo = {[1]={160701,"Unity",33},[2]={160702,"Ios",32},[3]={160403,"H5",40},}print(playerInfo[1][2])--排序函数function mysort(x,y)return x 阅读全文
posted @ 2016-10-27 21:09 无畏先锋 阅读(1621) 评论(0) 推荐(0) 编辑
摘要: --ipairs和pairs的区别arr = {1,3,[5]=5,name="kaikai",age=12, 89}--arr[4]= 23--ipairs--ipairs仅仅遍历值 按照索引升序遍历 索引中断停止遍历for i,v in ipairs(arr) doprint(i,v)end-- 阅读全文
posted @ 2016-10-27 21:06 无畏先锋 阅读(3875) 评论(2) 推荐(0) 编辑
摘要: --输入n个数--[[4blueblueredblueoutput:blue]]--输入一个数n= io.read()--循环输入n个字符串,将其记录到table中dic= {}for i = 1,n dostr = io.read()--如果字符串已经在table中存在了if dic[str] t 阅读全文
posted @ 2016-10-27 21:01 无畏先锋 阅读(539) 评论(0) 推荐(0) 编辑
摘要: --遍历数组arrAges= {1,"123",5,true,9}for i = 1,5 doprint(arrages[i])end--#运算符 取table和字符串长度--table下表从1开始for i=1,#arrAges doprint(arrAges do)end 阅读全文
posted @ 2016-10-27 20:51 无畏先锋 阅读(5785) 评论(0) 推荐(0) 编辑
摘要: --table的集合使用--tab了的key值必须是字符串类型--dic = {1,name = "lanou",age= 4,55,54}--dic.name = "蓝鸥"--dic.age= 4--print(dic.name)--print(#dic)--print(dic[2])dic = 阅读全文
posted @ 2016-10-27 19:24 无畏先锋 阅读(1096) 评论(0) 推荐(0) 编辑
摘要: --数组的长宽不比固定arr_age={1,2,3,4}arr_age[0]=1arr_age[1]=2arr_age[2]= 3--for循环 for i=起始值,终止值,增量(可省略)-- 循环体-- end--输出偶数for i=2,10,2 doprint(i)endi=2while i < 阅读全文
posted @ 2016-10-27 19:23 无畏先锋 阅读(196) 评论(0) 推荐(0) 编辑
摘要: --lua数据类型--[[nil nullboolean;boolnumber:整数string:字符创table:数组和集合]]print(type(ms)..type(true)..type(123)..type({1,2,3}))print(type(ms))print(type(true)) 阅读全文
posted @ 2016-10-27 19:21 无畏先锋 阅读(137) 评论(0) 推荐(0) 编辑