<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://www.computercraft.info/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Minozake</id>
		<title>ComputerCraft Wiki - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="https://www.computercraft.info/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Minozake"/>
		<link rel="alternate" type="text/html" href="https://www.computercraft.info/wiki/Special:Contributions/Minozake"/>
		<updated>2026-07-11T07:42:00Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.24.1</generator>

	<entry>
		<id>https://www.computercraft.info/wiki/index.php?title=User:Minozake&amp;diff=1520</id>
		<title>User:Minozake</title>
		<link rel="alternate" type="text/html" href="https://www.computercraft.info/wiki/index.php?title=User:Minozake&amp;diff=1520"/>
				<updated>2012-05-12T20:03:57Z</updated>
		
		<summary type="html">&lt;p&gt;Minozake: /* Termination catch for infinite loop daemons */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Miscellaneous thingies ==&lt;br /&gt;
&lt;br /&gt;
So, I'm using this to post miscellaneous code snippets for other people to use until I find a wiki page for it.&lt;br /&gt;
&lt;br /&gt;
= Termination catch for infinite loop daemons =&lt;br /&gt;
&lt;br /&gt;
So, let's say you want the source of a program in the form of&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while true do&lt;br /&gt;
    shell.run(&amp;quot;prog&amp;quot;, &amp;quot;arg1&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It's all fine and good, except for a huge potential problem.  If you want to terminate it, you will just restart the program being run in the loop.  For computers with the program in their startup, it will require the computer be removed and replaced, and that will destroy the contents saved onto its disk.  That's where more complex code comes in handy.  The code follows the form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function doPullEvent ()&lt;br /&gt;
    os.pullEventRaw(&amp;quot;Terminate&amp;quot;)&lt;br /&gt;
    print(&amp;quot;Terminate caught.  Exiting.&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function doRunProg ()&lt;br /&gt;
    while true do&lt;br /&gt;
        shell.run(&amp;quot;gps&amp;quot;, &amp;quot;host&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
parallel.waitForAny(doPullEvent, doRunProg)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It works by parallelizing both functions and waiting for one of them to exit.  When one function exits, the program exits.  Since it is impossible for the loop to exit, it rests on catching the terminate event, which is already blocking until the event is caught.  You could also easily modify this to take a keypress event instead if that is what you prefer, but that will be an exercise left up to the reader.&lt;br /&gt;
&lt;br /&gt;
An example for use would be a GPS daemon.  Unfortunately, a GPS host computer at startup that just has `shell.run(&amp;quot;gps&amp;quot;, &amp;quot;host&amp;quot;)` is prone to failures due to timing problems or thunderstorms since they depend on at least 4 other computers to get up and running properly, and it will also be a problem for entire networks that base their hosting off of 4 main computers.  A workaround is to hardcode all of the computers, but that requires manual or more complex auto setups.  Running `shell.run(&amp;quot;gps&amp;quot;, &amp;quot;host&amp;quot;)` in a startup infinite loop is a fix, but it also blocks all other operation of the computer, especially if trying to debug.  Adding the termination catch so that the script is safe to run on startup is recommended and optimal.&lt;br /&gt;
&lt;br /&gt;
I will leave it as an exercise to the reader to figure out how to make this into a flexible script and make it loadable as an API.&lt;/div&gt;</summary>
		<author><name>Minozake</name></author>	</entry>

	<entry>
		<id>https://www.computercraft.info/wiki/index.php?title=User:Minozake&amp;diff=1519</id>
		<title>User:Minozake</title>
		<link rel="alternate" type="text/html" href="https://www.computercraft.info/wiki/index.php?title=User:Minozake&amp;diff=1519"/>
				<updated>2012-05-12T20:03:02Z</updated>
		
		<summary type="html">&lt;p&gt;Minozake: /* Termination catch for infinite loop daemons */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Miscellaneous thingies ==&lt;br /&gt;
&lt;br /&gt;
So, I'm using this to post miscellaneous code snippets for other people to use until I find a wiki page for it.&lt;br /&gt;
&lt;br /&gt;
= Termination catch for infinite loop daemons =&lt;br /&gt;
&lt;br /&gt;
So, let's say you want the source of a program in the form of&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while true do&lt;br /&gt;
    shell.run(&amp;quot;prog&amp;quot;, &amp;quot;arg1&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It's all fine and good, except for a huge potential problem.  If you want to terminate it, you will just restart the program being run in the loop.  For computers with the program in their startup, it will require the computer be removed and replaced, and that will destroy the contents saved onto its disk.  That's where more complex code comes in handy.  The code follows the form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function doPullEvent ()&lt;br /&gt;
    os.pullEventRaw(&amp;quot;Terminate&amp;quot;)&lt;br /&gt;
    print(&amp;quot;Terminate caught.  Exiting.&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function doRunProg ()&lt;br /&gt;
    while true do&lt;br /&gt;
        shell.run(&amp;quot;gps&amp;quot;, &amp;quot;host&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
parallel.waitForAny(doPullEvent, doRunProg)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It works by parallelizing both functions and waiting for one of them to exit.  When one exits, the program exits.  Since it is impossible for the loop to exit, it rests on catching the terminate event.  You could also easily modify this to take a keypress event instead if that is what you prefer, but that will be an exercise left up to the reader.&lt;br /&gt;
&lt;br /&gt;
An example for use would be a GPS daemon.  Unfortunately, a GPS host computer at startup that just has `shell.run(&amp;quot;gps&amp;quot;, &amp;quot;host&amp;quot;)` is prone to failures due to timing problems or thunderstorms since they depend on at least 4 other computers to get up and running properly, and it will also be a problem for entire networks that base their hosting off of 4 main computers.  A workaround is to hardcode all of the computers, but that requires manual or more complex auto setups.  Running `shell.run(&amp;quot;gps&amp;quot;, &amp;quot;host&amp;quot;)` in a startup infinite loop is a fix, but it also blocks all other operation of the computer, especially if trying to debug.  Adding the termination catch so that the script is safe to run on startup is recommended and optimal.&lt;br /&gt;
&lt;br /&gt;
I will leave it as an exercise to the reader to figure out how to make this into a flexible script and make it loadable as an API.&lt;/div&gt;</summary>
		<author><name>Minozake</name></author>	</entry>

	<entry>
		<id>https://www.computercraft.info/wiki/index.php?title=User:Minozake&amp;diff=1518</id>
		<title>User:Minozake</title>
		<link rel="alternate" type="text/html" href="https://www.computercraft.info/wiki/index.php?title=User:Minozake&amp;diff=1518"/>
				<updated>2012-05-12T19:30:12Z</updated>
		
		<summary type="html">&lt;p&gt;Minozake: Added safe terminate code&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Miscellaneous thingies ==&lt;br /&gt;
&lt;br /&gt;
So, I'm using this to post miscellaneous code snippets for other people to use until I find a wiki page for it.&lt;br /&gt;
&lt;br /&gt;
= Termination catch for infinite loop daemons =&lt;br /&gt;
&lt;br /&gt;
So, let's say you want the source of a program in the form of&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while true do&lt;br /&gt;
    shell.run(&amp;quot;prog&amp;quot;, &amp;quot;arg1&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It's all fine and good, except for a huge potential problem.  If you want to terminate it, you will just restart the program being run in the loop.  For computers with the program in their startup, it will require the computer be removed and replaced, and that will destroy the contents saved onto its disk.  That's where more complex code comes in handy.  The code follows the form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function doPullEvent ()&lt;br /&gt;
    os.pullEventRaw(&amp;quot;Terminate&amp;quot;)&lt;br /&gt;
    print(&amp;quot;Terminate caught.  Exiting.&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function doRunProg ()&lt;br /&gt;
    while true do&lt;br /&gt;
        shell.run(&amp;quot;gps&amp;quot;, &amp;quot;host&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
parallel.waitForAny(doPullEvent, doRunProg)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
An example for use would be a GPS daemon.  Unfortunately, a GPS host computer at startup that just has `shell.run(&amp;quot;gps&amp;quot;, &amp;quot;host&amp;quot;)` is prone to failures due to timing problems or thunderstorms since they depend on at least 4 other computers to get up and running properly, and it will also be a problem for entire networks that base their hosting off of 4 main computers.  A workaround is to hardcode all of the computers, but that requires manual or more complex auto setups.  Running `shell.run(&amp;quot;gps&amp;quot;, &amp;quot;host&amp;quot;)` in a startup infinite loop is a fix, but it also blocks all other operation of the computer, especially if trying to debug.  Adding the termination catch so that the script is safe to run on startup is recommended and optimal.&lt;br /&gt;
&lt;br /&gt;
I will leave it as an exercise to the reader to figure out how to make this into a flexible script and make it loadable as an API.&lt;/div&gt;</summary>
		<author><name>Minozake</name></author>	</entry>

	<entry>
		<id>https://www.computercraft.info/wiki/index.php?title=Vector_(API)&amp;diff=1517</id>
		<title>Vector (API)</title>
		<link rel="alternate" type="text/html" href="https://www.computercraft.info/wiki/index.php?title=Vector_(API)&amp;diff=1517"/>
				<updated>2012-05-12T18:51:18Z</updated>
		
		<summary type="html">&lt;p&gt;Minozake: Added link to an introduction to vectors as used in the mod.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The vector API provides methods to create and manipulate vectors.  An introduction to vectors can be found on [http://en.wikipedia.org/wiki/Euclidean_vector Wikipedia].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align: center; background: #DDDDDD&amp;quot;|Static methods&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align: center; background: #EFEFEF&amp;quot; width=&amp;quot;200px&amp;quot;|Method name&lt;br /&gt;
|style=&amp;quot;text-align: center; background: #EFEFEF&amp;quot; width=&amp;quot;*&amp;quot;|Description&lt;br /&gt;
|-&lt;br /&gt;
|vector.new(x, y, z)&lt;br /&gt;
|Creates a vector.&amp;lt;br /&amp;gt;&lt;br /&gt;
''@param'' '''x, y, z''' the vector coordinates&amp;lt;br /&amp;gt;&lt;br /&gt;
''@return'' the created vector&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align: center; background: #DDDDDD&amp;quot;|Object methods&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align: center; background: #EFEFEF&amp;quot; width=&amp;quot;200px&amp;quot;|Method name&lt;br /&gt;
|style=&amp;quot;text-align: center; background: #EFEFEF&amp;quot; width=&amp;quot;*&amp;quot;|Description&lt;br /&gt;
|-&lt;br /&gt;
|vectorA:add(vectorB)&lt;br /&gt;
|Adds vectorB to vectorA and returns the resulted vector.&lt;br /&gt;
|-&lt;br /&gt;
|vectorA:sub(vectorB)&lt;br /&gt;
|Subtracts vectorB to vectorA and returns the resulted vector.&lt;br /&gt;
|-&lt;br /&gt;
|vectorA:mul(vectorB)&lt;br /&gt;
|Multiplies vectorB with vectorA and returns the resulted vector.&lt;br /&gt;
|-&lt;br /&gt;
|vectorA:dot(vectorB)&lt;br /&gt;
|Returns the dot product of vectorA and vectorB.&lt;br /&gt;
|-&lt;br /&gt;
|vectorA:cross(vectorB)&lt;br /&gt;
|Returns the vector which resulted in the cross product of vectorA and vectorB.&lt;br /&gt;
|-&lt;br /&gt;
|vectorA:length()&lt;br /&gt;
|Returns the vector's length.&lt;br /&gt;
|-&lt;br /&gt;
|vectorA:normalize()&lt;br /&gt;
|Normalizes the vector and returns the result as a new vector.&lt;br /&gt;
|-&lt;br /&gt;
|vectorA:round()&lt;br /&gt;
|Rounds the vector coordinates to the nearest integers and returns the result as a new vector.&lt;br /&gt;
|-&lt;br /&gt;
|vectorA:tostring()&lt;br /&gt;
|Returns a string representation of the vector in the form of &amp;quot;x,y,z&amp;quot;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:APIs]]&lt;/div&gt;</summary>
		<author><name>Minozake</name></author>	</entry>

	</feed>