随笔分类 -  Lua

摘要:题目: 编写一个在1,2,…,9(顺序不能变)数字之间插入+或-或什么都不插入,使得计算结果总是100的程序,并输出所有的可能性。例如:1 + 2 + 34 – 5 + 67 – 8 + 9 = 100。 lua实现1: --这道题其实就是求+、-、“”,三个符号的的组合,若把它们定义成0、1、2, 阅读全文
posted @ 2017-08-22 21:14 吴筱军 阅读(915) 评论(0) 推荐(0)
摘要:-- params@num integer -- params@radix integer 进制基数(2~) 默认为10 -- NOTE:先不输出符号 function NumberToArray(num, radix) if type(num) ~= "number" and tonumber(num) == nil then ERROR("NumberToArray"... 阅读全文
posted @ 2017-07-25 15:13 吴筱军 阅读(1712) 评论(0) 推荐(0)
摘要:因为loadstring总是在全局环境中编译它的串,所以编译出的函数访问的变量是全局变量。为了避免污染全局环境我们需要用setfenv修改函数的环境 使用: local str = "200+lv*10+growth*0.1" local val = eval(str, {lv = 3, growt 阅读全文
posted @ 2017-05-25 20:54 吴筱军 阅读(3424) 评论(0) 推荐(0)
摘要:-- local getTime = os.date(“%c”); -- %a abbreviated weekday name (e.g., Wed)-- %A full weekday name (e.g., Wednesday)-- %b abbreviated month name (e.g 阅读全文
posted @ 2017-05-06 09:43 吴筱军 阅读(2491) 评论(0) 推荐(0)
摘要:--得到星座 function DataCenter_Setting:GetConstellation(month, day) local dataInfo = {121, 220, 321, 421, 522, 622, 723, 824, 924, 1024, 1123, 1222} local Constellations = {"水瓶", "双鱼", "白羊", "金牛"... 阅读全文
posted @ 2016-12-20 16:04 吴筱军 阅读(267) 评论(0) 推荐(0)
摘要:lua中的随机数 每次随机出来的第一个数是不可靠的。 阅读全文
posted @ 2016-08-26 10:33 吴筱军 阅读(69490) 评论(3) 推荐(1)
摘要:local function GetStringWordNum(str) local fontSize = 20 local lenInByte = #str local count = 0 local i = 1 while true do local curByte = string.byte(str, i) if i ... 阅读全文
posted @ 2016-08-19 16:03 吴筱军 阅读(3382) 评论(0) 推荐(0)
摘要:Lua与C/C++交互 阅读全文
posted @ 2016-08-09 18:15 吴筱军 阅读(309) 评论(0) 推荐(0)
摘要:创建文件: os.execute('mkdir e:\\aa') 创建文件夹: os.execute("cd.>e:\\wang.ini") 阅读全文
posted @ 2016-07-24 14:08 吴筱军 阅读(3035) 评论(0) 推荐(0)
摘要:lfs.attributes(filepath [, aname]) 获取路径指定属性 lfs.chdir(path) 改变当前工作目录,成功返回true,失败返回nil加上错误信息 lfs.currentdir 获取当前工作目录,成功返回路径,失败为nil加上错误信息 lfs.dir(path) 阅读全文
posted @ 2016-07-24 12:08 吴筱军 阅读(901) 评论(0) 推荐(0)
摘要:lua中函数的upvalues是有上限的,在luaconf.h中定义: /*@@ LUAI_MAXUPVALUES is the maximum number of upvalues per function@* (must be smaller than 250).*/#define LUAI_M 阅读全文
posted @ 2016-06-15 15:41 吴筱军 阅读(1418) 评论(0) 推荐(0)
摘要:两大特点: 1. string库中所有的字符索引从前往后是1,2,...;从后往前是-1,-2,... 2. string库中所有的function都不会直接操作字符串,而是返回一个新的字符串。 库函数: 1、string.len,string.rep,string.upper,string.low 阅读全文
posted @ 2016-04-21 17:47 吴筱军 阅读(2025) 评论(0) 推荐(0)
摘要:_Account = {} --创建一张借记卡 function _Account:new( tb ) local _Tb = tb or {} _Tb._mBalance = _Tb._mBalance or 0 setmetatable(_Tb, self) self.__index = sel 阅读全文
posted @ 2016-04-11 19:52 吴筱军 阅读(868) 评论(0) 推荐(1)
摘要:1 local myTable = {} 2 3 function myTable:putMyname(val) 4 print(val) 5 print(self and self.name) 6 end 7 8 myTable.name = "Mical" 9 myTable:putMyname() 10 --结果:nil 11 -- Mic... 阅读全文
posted @ 2016-04-08 13:27 吴筱军 阅读(1274) 评论(0) 推荐(1)
摘要:Metatable: lua中的每一个表都有其Metatable,默认情况下Metatable为nil。可通过setmetatable函数设置或者改变一个表的Metatable, 也可以通过getmetatable得到一个表的Metatable。任何一个表都可以是其它表的Metatable,可以多个 阅读全文
posted @ 2016-04-07 20:20 吴筱军 阅读(405) 评论(0) 推荐(0)
摘要:os.clock ()功能:返回一个程序使用CPU时间的一个近似值最近做了一个功能,这个功能需要统计时间间隔,例如每隔0.5秒做一次调用。我用了os.clock()去统计时间,结果在pc机上都没什么问题,可当打包到手机上再运行的时候就出现了问题。最后发现实际上都8秒了,用os.clock()统计出来... 阅读全文
posted @ 2015-11-12 14:59 吴筱军 阅读(731) 评论(0) 推荐(0)
摘要:function createCountdownTimer(second) local ms = second * 1000 local function countDown() ms = ms - 1 return ms end return countDownendtimer... 阅读全文
posted @ 2015-11-02 11:54 吴筱军 阅读(1006) 评论(0) 推荐(0)
摘要:function foo() print(g or "'g' is not defined!")endfoo()env = { g = 100, print = print }setfenv(foo, env) --设置foo的环境为表envfoo()print(g or "'g' is not d... 阅读全文
posted @ 2015-11-02 11:49 吴筱军 阅读(2256) 评论(0) 推荐(0)
摘要:迭代function enum(array) local index = 1 return function() --返回迭代函数 local ret = array[index] index = index + 1 return ret endendfunction foreach(array, ... 阅读全文
posted @ 2015-11-02 11:29 吴筱军 阅读(353) 评论(0) 推荐(0)
摘要:Queue = {} function Queue.newquene() return {count = 0} end function Queue.push(queue, value) queue.count = queue.count+1 ... 阅读全文
posted @ 2015-08-26 22:54 吴筱军 阅读(1635) 评论(0) 推荐(0)