我在Lua里面做了一个简单的数字破解者,我遇到了“Stack Overflow”错误(讽刺的是哦)。我不是100%这个错误实际是什么,因为当我谷歌它我得到的是这个网站iv已经使用了一段时间。我想有办法清除lua文件中的内存。这个程序运行速度非常快,它可以运行这些数字高达2147483647次,所以我假设这是一个内存问题。那么有没有办法在仍然运行脚本的同时清除lua脚本中的内存?这是我的代码:
num = 0
rand = math.random(2147483647)
function Main()
print ("Please enter your number(0 - 2147483647)")
ui = io.read("*number")
loop()
end
function loop()
if rand > ui and rand ~= ui then
rand = math.random(0, ui)
num = num + 1
print(rand)
end
if rand < ui and rand ~= ui then
rand = math.random(ui, 2147483647)
num = num + 1
print(rand)
end
if ui ~= rand then
loop()
end
if ui == rand then
print("Number Cracked - " ..ui)
print("It Took " ..num .." Trys To Crack Your Number")
done = io.read()
end
end
Main()
修改
感谢@Marc B和@ Blaatz0r对答案进行评论,我多次调用loop()并且它正在导致“Stack Overflow”,我用while循环替换它,感谢@Marc B为此,这是我的新代码:
num = 0
rand = math.random(2147483647)
function Main()
print ("Please enter your number(0 - 2147483647)")
ui = io.read("*number")
while( ui ~= rand) do
if rand > ui and rand ~= ui then
rand = math.random(0, ui)
num = num + 1
print(rand)
end
if rand < ui and rand ~= ui then
rand = math.random(ui, 2147483647)
num = num + 1
print(rand)
end
if ui == rand then
print("Number Cracked - " ..ui)
print("It Took " ..num .." Trys To Crack Your Number")
done = io.read()
end
end
end
Main()
答案 0 :(得分:0)
感谢@Marc B和@ Blaatz0r对答案进行评论,我多次调用loop()并且它正在导致“Stack Overflow”,我用while循环替换它,感谢@Marc B为此,这是我的新代码:
num = 0
rand = math.random(2147483647)
function Main()
print ("Please enter your number(0 - 2147483647)")
ui = io.read("*number")
while( ui ~= rand) do
if rand > ui and rand ~= ui then
rand = math.random(0, ui)
num = num + 1
print(rand)
end
if rand < ui and rand ~= ui then
rand = math.random(ui, 2147483647)
num = num + 1
print(rand)
end
if ui == rand then
print("Number Cracked - " ..ui)
print("It Took " ..num .." Trys To Crack Your Number")
done = io.read()
end
end
end
Main()