Difference between revisions of "Terminate (event)"

From ComputerCraft Wiki
Jump to: navigation, search
(Better description and mentions on how it indirectly calls error within the bios)
Line 3: Line 3:
 
{{Event
 
{{Event
 
|name=terminate
 
|name=terminate
|desc=Fired when CTRL+T is held to terminate the running program.
+
|desc=Fired when CTRL+T is held for at least 1 second. With an unmodified bios and os.pullEvent, it indirectly calls error().
 
}}
 
}}
 
{{Example
 
{{Example
|desc=This overides the [[os.pullEvent]] function to display a custom message when a program is terminated
+
|desc=The actual terminating part of CTRL+T is defined in the bios for os.pullEvent. This can however be overridden to catch terminate and modify it's effects, as shown below. Note that holding CTRL+T, and it firing the terminate event is independent of key events and is hard coded into ComputerCraft.
|code= function os.pullEvent(_sFilter)
+
|code=function os.pullEvent(_sFilter)
 
     local event = { os.pullEventRaw(_sFilter) }
 
     local event = { os.pullEventRaw(_sFilter) }
 
     if event[1] == "terminate" then
 
     if event[1] == "terminate" then

Revision as of 20:23, 10 June 2013

This page needs some serious TLC, stat!
Please help us by cleaning it, fixing it up, or sparing it some love.
(Reason: A demonstration on the use and handling of this event would be beneficial. AfterLifeLochie 16:13, 30 November 2012 (MSK))



Grid Modem.png  Event terminate
Fired when CTRL+T is held for at least 1 second. With an unmodified bios and os.pullEvent, it indirectly calls error().
Returned Object 1 Nothing


Grid paper.png  Example
The actual terminating part of CTRL+T is defined in the bios for os.pullEvent. This can however be overridden to catch terminate and modify it's effects, as shown below. Note that holding CTRL+T, and it firing the terminate event is independent of key events and is hard coded into ComputerCraft.
Code
function os.pullEvent(_sFilter)
   local event = { os.pullEventRaw(_sFilter) }
   if event[1] == "terminate" then
     error("Terminate Event Found", 0)
   end
   return unpack(event)
 end