omori-Sakuya

第一次写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   omori_Sakuya  阅读(52)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 本地部署DeepSeek后,没有好看的交互界面怎么行!
· 趁着过年的时候手搓了一个低代码框架
· 推荐一个DeepSeek 大模型的免费 API 项目!兼容OpenAI接口!
· 用 C# 插值字符串处理器写一个 sscanf
< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

导航

统计

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