![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LUA
文章平均质量分 60
JustEasyCode
只写最简单的代码
展开
-
《Lua》在使用过程中的问题
现在这么内卷不能再向网上上一样想的那么简单了。一个能输出全部key-value值,一个碰到nil就停止输出。只回答到这个层面是不够的。其他层面源码层面:ipairs返回未公开函数,输出接下来的下标和当前值,第一次调未公开函数,下标是0,之后内部会变成1,输出1,和对应的1的值。pairs就是调next函数,第一次传nil,接下来返回下一组key-value,https://www.kawabangga.com/posts/3063存储结构层面:table两种存储形式,一种数组,一种哈希表,所以我认原创 2022-03-27 00:16:38 · 817 阅读 · 0 评论 -
Lua程序设计第4版第20章课后练习答案
20.1--f201local function intersact(a,b) for k,c in pairs(b) do a[k] = nil end return aendlocal function toS(set) local l = {} for _ in pairs(set) do l[#l+1] = t...原创 2020-01-30 18:18:42 · 328 阅读 · 0 评论 -
Lua程序设计第4版第18章课后练习答案
–18.1 18.2其实就是闭包的运用,记住foreach迭代的规则是不变量和变量组合传入,返回索引和索引对应的值。--18.1 18.2local m = 1 --m就是步长,其实就是根据步长输出表的内容,说话都说不利索,我他吗真的是想打人,恶心local function noState(n,i) i = i+m local v= n[i] if v then...原创 2020-01-29 15:46:11 · 386 阅读 · 0 评论 -
Lua程序设计第4版第17章课后练习答案
17.1doubleList文件------ Generated by EmmyLua(https://github.com/EmmyLua)--- Created by 15240.--- DateTime: 2020/1/28 13:48--------- Generated by EmmyLua(https://github.com/EmmyLua)--- Created ...原创 2020-01-28 13:58:17 · 360 阅读 · 0 评论 -
Lua程序设计第4版第14章课后练习答案
14.1function f141(a,b) local c ={} for i = 1, #a do c[i] = {} for j = 1, #a[i] do c[i][j] = a[i][j]+b[i][j] end end for i = 1, #c do for j...原创 2020-01-27 12:40:19 · 321 阅读 · 0 评论 -
Lua程序设计第4版第13章课后练习答案
13.1function f131(un,mod) print(string.format("%u",un)) print(string.format("%u",mod)) local i = 1 while math.ult(un,i*mod)==false do i = i+1 print(string.format("i = ...原创 2020-01-27 10:36:05 · 1665 阅读 · 0 评论 -
Lua程序设计第4版第11章课后练习答案
11.1修改模式匹配中的%w+为%w%w%w%w+ for line in io.lines() do for word in string.gmatch(line,"%w%w%w%w+") do counter[word] = (counter[word] or 0)+1 end end11.2从文本文件中读取到i...原创 2020-01-25 14:11:24 · 222 阅读 · 0 评论 -
Lua程序设计第4版第10章课后练习答案
10.1function f101(str,space) str = string.gsub(str,"%s*(.-)%s*$","%1") -- 去除空格 str = str..space local t = {} for a in string.gmatch(str,".-"..space) do if a~=space then ...原创 2020-01-25 13:48:09 · 302 阅读 · 0 评论 -
Lua程序设计第4版第9章课后练习答案
这么多数学,我真做不出来。看这位仁兄的吧。答案原创 2020-01-24 14:48:36 · 378 阅读 · 0 评论 -
Lua程序设计第4版第8章课后练习答案
8.1没有switch,elseif比使用多个if性能更高8.2while(true)for 1,math.hugerepeatgoto8.3你想怎样都好8.4function room1() local move = io.read() if move == "south" then room3() elseif move == "ea...原创 2020-01-24 13:35:23 · 320 阅读 · 0 评论 -
Lua程序设计第4版第7章课后练习答案
7.1function f71(infile,outfile) -- 重定向输出 if outfile then if assert(io.open(outfile)) then print("if you confirm prease print 1") local confirm = io.read("n") ...原创 2020-01-24 13:22:02 · 325 阅读 · 0 评论 -
Lua程序设计第4版第6章课后练习答案
6.1 略6.2 用lselect(2,…)函数6.3function f63(...) local t = table.pack(...) t[t.n] = nil t.n = t.n-1 return table.unpack(t)endprint(f63(2,3,4,5))6.4说下思路pair每一个元素,把每个元素都随机从数组中选择一个索...原创 2020-01-23 17:39:53 · 548 阅读 · 0 评论 -
Lua程序设计第4版第5章练习答案
5.1monday sunday sundayt.sunday => 表中sunday对应的值t[sunday] =>sunday变量=>monday键([sunday]对应的值=>monday变量"sunday"t[t.sunday]=>monday键同上5.2同一张表的引用 一样引发异常 等同于把3当成表来用了5.3方括号内写索引值5.4每次...原创 2020-01-23 16:54:19 · 324 阅读 · 0 评论 -
Lua程序设计第4版第4章课后答案
4.1s = [==[<![CDATA[ Hello world ]]>]==]print(s)4.24.2节,多行16进制+\z4.3function f43(s,n,t) s1 = "" s2 = "" if n>1 then s1= string.sub(s,1,n-1) end s2 = ...原创 2020-01-23 16:03:56 · 487 阅读 · 0 评论 -
Lua程序设计第4版第3章课后答案
3.10x12 = 18,0xA = 10,0xFFFFFFFF = 4294967295,0x1P10 = 1024,0x0.1p1 = 0.1250xABFG中不能有G,剩下的都是错误的3.2 设maxinteger=max,mininteger = minmax+max-1 = -1-1 = -2min-1+1+min = -1+1 = 0maxmax = (min-1)(mi...原创 2020-01-23 01:37:50 · 302 阅读 · 0 评论 -
Lua第4版第2章课后答案
2.1N=8cnt1 = 0function isplaceok(a,n,c) cnt1 = cnt1+1 for i=1,n-1 do if(a[i]==c) or (a[i]-i==c-n) or (a[i]+i==c+n) then return false end end return true...原创 2020-01-22 17:05:54 · 143 阅读 · 0 评论 -
Lua程序设计第4版第一章课后答案
1.1 递归无线导致栈溢出function fact(n) if n<0 then return 0 elseif n==0 then return 1 else return n*fact(n-1) endend1.2 略1.3 略1.4___,_end,End,end,NULL可以until?不...原创 2020-01-22 16:26:57 · 200 阅读 · 0 评论 -
LUA程序设计第4版第24章练习答案
f24.1 生产者设计驱动模式function producer() while true do local x = io.read() send(x) endendfunction consumer(x) print(x) while true do print(receive()) endend...原创 2019-12-16 20:06:05 · 149 阅读 · 0 评论 -
Lua程序设计第4版第20章练习答案
--f201local function intersact(a,b) for k,c in pairs(b) do a[k] = nil end return aendlocal function toS(set) local l = {} for _ in pairs(set) do l[#l+1] = tostr...原创 2019-12-15 18:15:55 · 156 阅读 · 0 评论 -
Lua程序设计第4版第18章练习答案
--18.1 18.2function fromto(n,m) local k = 0 return function() k = k+m return n[k] endendlocal n = {1,2,3}local m = 2for i in fromto(n,m) do if i ==nil then ...原创 2019-12-11 18:30:19 · 324 阅读 · 0 评论 -
Lua程序设计第12章练习答案
两个矩阵相加,稀疏还不会function f141(a,b) local c ={} for i = 1, #a do c[i] = {} for j = 1, #a[i] do c[i][j] = a[i][j]+b[i][j] end end for i = 1, #c do ...原创 2019-12-09 11:53:21 · 165 阅读 · 0 评论