摘要: --男人类man = {name = "man",age=123}--继承空间man.__index=man--儿童类child= {}--继承setmetatable(child,man)print(child.age)yong= {}setmetatable(yong,man)child.age 阅读全文
posted @ 2016-10-27 21:50 无畏先锋 阅读(449) 评论(0) 推荐(0) 编辑
摘要: --使用table封装面向对象beauty={name = " "}--封装对象方法function beauty.init(self, name)print("十八年前的一天王小丫出生")self.name= nameend--一般使用下面这种形式function beauty:init( nam 阅读全文
posted @ 2016-10-27 21:49 无畏先锋 阅读(311) 评论(0) 推荐(0) 编辑
摘要: function SayHey(mag) for i = 1 , 3 doprint(mag)coroutine.yield()end end --创建携程(协同) coFunc= coroutine.create(SayHey)--查看携程状态print(coroutine.status(coFu 阅读全文
posted @ 2016-10-27 21:48 无畏先锋 阅读(1056) 评论(0) 推荐(0) 编辑
摘要: --require("6-Coroutine")--仅加载一次,并不执行,参数为文件名不加后缀--dofile("6-Coroutine.lua") --加载并执行,参数为文件名加后缀--SayHey("kkkk")x=10 --默认是全局变量 show= function()local x = 1 阅读全文
posted @ 2016-10-27 21:47 无畏先锋 阅读(1145) 评论(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 无畏先锋 阅读(2084) 评论(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 无畏先锋 阅读(5788) 评论(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) 编辑
摘要: isok = false;--逻辑运算符--规定nil为false--print( ms and isok)--print(4 and 5)--print (false and 13)--print(false and 13)--a or b a为true 返回a 否则返回b--print (4 a 阅读全文
posted @ 2016-10-27 19:11 无畏先锋 阅读(2190) 评论(0) 推荐(0) 编辑
摘要: --单行注释--[[多行注释]]--变量声明的时候 不需要声明类型str = "Hello World"--多个变量name,age ="LanOu",4,5,10print(str)print(name,age,ad) 阅读全文
posted @ 2016-10-27 19:09 无畏先锋 阅读(1497) 评论(0) 推荐(0) 编辑
摘要: --冒泡排序nums = {3,11,2,123,1}len = #numsfor i = 1,len-1 do for j = 1,len-i do if nums[j]>nums[j+1] then temp= nums[j+1] nums[j+1]= nums[j] nums[j]= temp 阅读全文
posted @ 2016-10-27 19:07 无畏先锋 阅读(2177) 评论(0) 推荐(0) 编辑
摘要: --男人类man = {name = "man",age=123}--继承空间man.__index=man--儿童类child= {}--继承setmetatable(child,man)print(child.age)yong= {}setmetatable(yong,man)child.age 阅读全文
posted @ 2016-10-27 19:05 无畏先锋 阅读(163) 评论(0) 推荐(0) 编辑
摘要: --使用table封装面向对象beauty={name = " "}--封装对象方法function beauty.init(self, name)print("十八年前的一天王小丫出生")self.name= nameend--一般使用下面这种形式function beauty:init( nam 阅读全文
posted @ 2016-10-27 19:03 无畏先锋 阅读(122) 评论(0) 推荐(0) 编辑
摘要: function SayHey(mag) for i = 1 , 3 doprint(mag)coroutine.yield()end end --创建携程(协同) coFunc= coroutine.create(SayHey)--查看携程状态print(coroutine.status(coFu 阅读全文
posted @ 2016-10-27 19:01 无畏先锋 阅读(1123) 评论(0) 推荐(0) 编辑
摘要: --require("6-Coroutine")--仅加载一次,并不执行--dofile("6-Coroutine.lua") --加载并执行--SayHey("kkkk")x=10 --默认是全局变量 show= function()local x = 1for i = 1 ,5 dox = x+ 阅读全文
posted @ 2016-10-27 19:00 无畏先锋 阅读(1953) 评论(0) 推荐(0) 编辑