随笔分类 -  Lua

摘要:运算符重载: __add: tbl = setmetatable({ 1, 2, 33 }, { __add = function(tbl, v) -- tbl 的长度不断变化, table.insert的pos参数不能使用#tbl+1, 越界会产生 position out of bounds i 阅读全文
posted @ 2022-05-29 23:26 ascertain 阅读(27) 评论(0) 推荐(0) 编辑
摘要:function producer() local i = 0 print(coroutine.running()) while true do i = i + 1 if i > 5 then error('out of number') end print('In Producer>> corou 阅读全文
posted @ 2022-05-29 17:46 ascertain 阅读(23) 评论(0) 推荐(0) 编辑
摘要:repeat unitl 先执行循环体, 满足until条件时退出 for 阅读全文
posted @ 2022-05-29 12:59 ascertain 阅读(29) 评论(0) 推荐(0) 编辑
摘要:一维数组 模拟 二维数组 array = {} rows = 3 cols = 4 for row = 1, rows do for col = 1, cols do array[(row - 1) * cols + col] = row * col end end for row = 1, row 阅读全文
posted @ 2022-05-29 00:12 ascertain 阅读(44) 评论(0) 推荐(0) 编辑
摘要:实现continue功能: 输出odd number: b = 0 while b < 10 do if b % 2 == 0 then goto continue end print(b) :: continue :: b = b + 1 end 阅读全文
posted @ 2022-05-28 23:18 ascertain 阅读(98) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示