第一次写lua 7.1
成果 function disk(tx,ty,r) --圆的特征函数 return function(x,y) return (x-tx)^2 + (y-tx)^2 <= r^2 end end function different(a ,b) --差集 return function(x,y) return a(x,y) and (not b(x,y)) end end function translate(old,tx,ty) --平移 return function(x,y) return old(x-tx,y-ty) end end -- function plot(r,m,n) io.write("P\n",m," ",n,"\n") for i =1,n do local y = (n-i*2)/n for j=1,m do local x = (m-j*2)/m io.write( r(x,y) and "1" or "0") end io.write("\n") end end c1 = disk(0,0,1) plot(different(c1,translate(c1,0.1,0)),1000,1000)
过程中出现的bug1
/usr/local/lua-5.3.5/luac53: script.lua:3: 'end' expected (to close 'function' at line 2) near '='
return (x-tx)^2 + (y-tx)^2 <= r^2 正确
return (x-tx)^2 + (y-tx)^2 = r^2 错误
过程中出现的bug2
function disk(tx,ty,r) --圆的特征函数
return function(x,y)
return (x-tx)^2 + (y-yx)^2 <= r^2 --------- 拼写错误-------错误1
end
end
print(disk(5,1,5)(5,4))t --------莫名奇妙的 t ------错误2
错误信息
错误1
/usr/local/lua-5.3.5/lua53: script.lua:3: attempt to perform arithmetic on a nil value (global 'yx')
stack traceback:
script.lua:3: in function <script.lua:2>
script.lua:7: in main chunk
[C]: in ?
Exited with error status 1
错误2
/usr/local/lua-5.3.5/luac53: script.lua:7: syntax error near <eof>
posted on 2023-07-01 11:00 omori_Sakuya 阅读(52) 评论(0) 编辑 收藏 举报
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 本地部署DeepSeek后,没有好看的交互界面怎么行!
· 趁着过年的时候手搓了一个低代码框架
· 推荐一个DeepSeek 大模型的免费 API 项目!兼容OpenAI接口!
· 用 C# 插值字符串处理器写一个 sscanf