To be more specific, when a function calls a function, the first isn't necessarily removed from the function stack - it usually stays there, so that when the second function finishes (and
returns), the first can carry on from where it left off. The idea is that whatever function is on top of the stack is active - new functions get piled on top, and as they complete, they get removed.
If you never allow your functions to return, but instead have them continue to call fresh instances of themselves over and over again, eventually Lua runs out of the memory reserved for such shenanigans and the function stack overflows. In the case of LuaJ (used by ComputerCraft), this leads to the precise error you're getting.
For eg, this sort of thing:
Spoiler
function display()
while disasterstatus == false do
p = peripheral.wrap("top")
p.clear()
p.setCursorPos(1,1)
p.setTextColor(colors.green)
p.write(counttime)
sleep(1)
display()
end
if disasterstatus == true then
p.clear()
p.setCursorPos(1,1)
p.setTextColor(colors.red)
p.write("SYSTEM FAILURE")
sleep(2)
display()
end
end
… could be re-written like this:
Spoiler
local function display()
local p = peripheral.wrap("top")
while true do
p.clear()
p.setCursorPos(1,1)
if not disasterstatus then
p.setTextColor(colors.green)
p.write(counttime)
sleep(1)
else
p.setTextColor(colors.red)
p.write("SYSTEM FAILURE")
sleep(2)
end
end
end