http://www.computercraft.info/wiki/api.php?action=feedcontributions&user=Cloudy&feedformat=atomComputerCraft Wiki - User contributions [en]2024-03-28T13:58:02ZUser contributionsMediaWiki 1.24.1http://www.computercraft.info/wiki/index.php?title=OS_(API)&diff=5050OS (API)2013-01-30T07:05:36Z<p>Cloudy: </p>
<hr />
<div>The Operating System API allows for interfacing with the Lua based Operating System itself.<br />
<br />
<table style="width: 100%; border: solid 1px black; margin: 2px; border-spacing: 0px;"><br />
<tr><td colspan="2" style="font-weight: bold; font-size: large; padding-bottom: .3em; border-bottom: solid #C9C9C9 1px; background: #D3FFC2; line-height:28px;"><br />
[[File:Grid_disk.png|24px]]&nbsp;&nbsp;<br />
OS (API)<br />
</td></tr><br />
<br />
<tr><td style="width: 350px; background: #E0E0E0; padding: .4em; font-weight:bold;">Method Name</td><td style="background: #E0E0E0; padding: .4em; font-weight:bold;">Description</td></tr><br />
<br />
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[os.version]]()</td><br />
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns the version of the OS the computer is running.</td></tr><br />
<br />
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[os.getComputerID]]()</td><br />
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns the unique ID of this computer. [[os.computerID]]() also behaves exactly the same as [[os.getComputerID]]().</td></tr><br />
<br />
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[os.getComputerLabel]]()</td><br />
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns the label of this computer.</td></tr><br />
<br />
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[os.setComputerLabel]]( label )</td><br />
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Set the label of this computer.</td></tr><br />
<br />
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[os.run]]( environment, programpath, arguments )</td><br />
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">An advanced way of starting programs. A started program will have a given <var>environment</var> table which determines what functions it has available, as well as any variables it will be able to access by default. You may prefer to use the [[Shell (API)]] unless you need to do something special.</td></tr><br />
<br />
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[#api|os.loadAPI]]( name )</td><br />
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Loads a Lua script as an API in it's own namespace (see example). It will be available to '''all''' programs that run on the terminal.</td></tr><br />
<br />
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[#api|os.unloadAPI]]( name )</td><br />
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Unloads a previously loaded API.</td></tr><br />
<br />
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[Os.pullEvent|os.pullEvent]]( target-event )</td><br />
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Blocks until the computer receives an event, or if <var>target-event</var> is specified, will block until an instance of <var>target-event</var> occurs. [[Os.pullEvent|os.pullEvent]]( target-event ) returns the event and any parameters the event may have. If a <var>target-event</var> is specified, the computer will not break for any other events (except termination).</td></tr><br />
<br />
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[#pullEvent|os.pullEventRaw]]()</td><br />
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Advanced version of pullEvent(). [[#pullEvent|os.pullEventRaw]]() will block until an event occurs, and then returns the event (any any parameters the event may have). Unlike [[Os.pullEvent|os.pullEvent]]( target-event ), this function will not break for system events, and can be used to handle termination events.</td></tr><br />
<br />
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[os.queueEvent]]( event, param1, param2, ... )</td><br />
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Adds an event to the event queue with the name <var>event</var> and the given parameters</td></tr><br />
<br />
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[os.clock]]()</td><br />
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns CPU time.</td></tr><br />
<br />
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[os.startTimer]]( timeout )</td><br />
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Queues an event to be triggered after a number of seconds (<var>timeout</var>). The ID of the timer is returned from this function to differentiate multiple timers. Timers are one-shot; once they have fired an event you will need to start another one if you need a recurring timer.</td></tr><br />
<br />
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[os.sleep]]( timeout )</td><br />
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Makes the system wait a number of seconds before continuing in the program. [[os.sleep]]( timeout ) may also be used as simply "sleep( timeout )".</td></tr><br />
<br />
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[os.time]]()</td><br />
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns the current Minecraft world time.</td></tr><br />
<br />
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[os.day]]()</td><br />
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns the current Minecraft day.</td></tr><br />
<br />
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[os.setAlarm]]( time )</td><br />
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Queues an event to be triggered at the specified Minecraft world <var>time</var>.</td></tr><br />
<br />
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[os.shutdown]]()</td><br />
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Turns off the computer.</td></tr><br />
<br />
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[os.reboot]]()</td><br />
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Reboots the computer.</td></tr><br />
</table><br />
<br />
<br />
[[Category:APIs]]<br />
<br />
== API ==<br />
<br />
API are programs which are loaded in to the OS itself, and expose functions which other programs may use. The stock [[:Category:APIs|APIs]] that ship with ComputerCraft are loaded in this way, and may be replaced by a computer's user or programs.<br />
<br />
The following is an example of a valid implementation of an API, and, it's usage after being registered:<br />
<code><br />
-- "apiTest" file<br />
function foo(bar)<br />
print(bar)<br />
end<br />
<br />
-- "program" file<br />
os.loadAPI("apiTest")<br />
apiTest.foo("this is a test")<br />
</code><br />
<br />
== <div id="pullEvent">os.pullEvent()</div> ==<br />
<br />
os.pullEvent() causes the current program to pause, retrieving the next event from the computer's queue of events. If there is no event to read, then the program will stall until such an event becomes available. Note that if a program has not attempted to pull an event in the past ten seconds, it will be forcefully terminated to prevent CPU waste in SMP environments.<br />
<br />
os.pullEvent() returns the name of the event that was read, as well as up to five parameters:<br />
<code><br />
local event, p1, p2, p3, p4, p5 = os.pullEvent()<br />
</code><br />
<br />
os.pullEvent() is usually run inside a 'while true do' loop.<br />
<br />
An advanced version of this method <code>os.pullEventRaw</code> bypasses the normal handling of events from the OS. You may use this to act on the "Terminate" event (triggered when holding Ctrl-T) for custom termination logic.</div>Cloudyhttp://www.computercraft.info/wiki/index.php?title=Category:APIs&diff=4712Category:APIs2012-12-07T03:49:39Z<p>Cloudy: Undo revision 4709 by 189.205.27.4 (talk)</p>
<hr />
<div>[[File:Apis.png|thumb|350px|API's being listed with the "apis" command run in a computer.]]An API (Application Programming Interface) is a collection of code that, rather than being run directly by the user as a program, is meant to be used by other programs. This is different from a function in that an API may contain many functions that perform related tasks; the API groups them together. It is a library of functions.<br />
There are two reasons why one might want to use an API:<br />
* The API may provide a function that you could write yourself if you had to, but using the one from the API means you don't have to do that work.<br />
<br />
* The API may provide something it's impossible to do yourself because it has to be done in Java rather than Lua.<br />
<br />
<br />
ComputerCraft itself ships with a collection of APIs of both types. For example:<br />
<br />
* The [[color (API)|color API]] provides names for the various numbers used in RedPower bundled cable, and functions that manipulate those numbers. The names for the numbers are just variables, and the functions are written in Lua (you can find this in "rom/apis/colors"). You could write the same variables and functions in your own code if you wanted, but using the API saves you from doing that.<br />
<br />
* The [[fs (API)|fs API]] provides functions to work with files. You couldn't write the functions from this API in Lua because they have to access the corresponding files in your real computer (the one running Minecraft), and the only way to do that from Lua is… through the fs API (or the [[IO (API)|io API]], but that's just a wrapper around fs).<br />
<br />
All the stock APIs of the first kind, those that are implemented in Lua, can be found in your "mods/ComputerCraft/lua/rom/apis" directory. Inside Minecraft, on a ComputerCraft computer, these appear in the directory "rom/apis". All the built-in APIs of both kinds (Lua and Java) are automatically loaded, so you don't have to use "[[OS (API)|os]].loadAPI" on them.<br />
<br />
ComputerCraft mods, for example mods that add custom peripherals, might also add APIs that help you work with those peripherals.<br />
<br />
You can view a list of un-official API's at the [[:Category:Unofficial_APIs]] page.<br />
<br />
Finally, you might find APIs written by other people that you can download, or you might write APIs yourself if you'll be using a function in many different programs and don't want to keep rewriting it. If you're playing single-player or you're running the multiplayer server, you can add those APIs to "rom/apis" and they will automatically be loaded on every computer in the world. Normally, though, you would leave the APIs somewhere else and use "os.loadAPI" to make them available to your program.<br />
<br />
You can see a list of APIs built-in to ComputerCraft by typing "apis" in the terminal.<br />
<br />
[[Category:Lists]]</div>Cloudyhttp://www.computercraft.info/wiki/index.php?title=Category:APIs&diff=4711Category:APIs2012-12-07T03:49:19Z<p>Cloudy: Reverted edits by 92.238.171.240 (talk) to last revision by 189.205.27.4</p>
<hr />
<div>Hey Dyasonhat,Looks great, amazing work, and tnahks for listening to users feedback.As I said in a previous post comment, I plan on using it to allow my users to order posts by a rating system (0-5), which I set via custom fields.As I want to use custom fields, I guess I need to premium version.What currency is R35? What would it be in a3 or $ ?Many tnahks</div>Cloudyhttp://www.computercraft.info/wiki/index.php?title=Computer&diff=4459Computer2012-12-01T13:30:37Z<p>Cloudy: </p>
<hr />
<div>The Computer is the main block of ComputerCraft. This is the computer, which is the centerpiece of this mod. From this block you will be able to use the Rednet, make programs, turn on and off redstone (And bundled cables from RedPower!), play games and much more. The Computer runs an OS called [[CraftOS]].<br />
<br />
[[Category:Blocks]]<br />
[[Category:Consoles]]<br />
== Recipe ==<br />
{{Crafting grid<br />
|A1=stone |B1=stone |C1=stone<br />
|A2=stone |B2=Redstone |C2=stone<br />
|A3=stone |B3=glass_pane |C3=stone<br />
|Output=Computer<br />
}}<br />
== Usage ==<br />
Place the Computer wherever you please, and just right click it to use.<br />
[[File:Computer-in-game.png|frame|right|The Computer in-game]]<br />
<br />
== Keyboard Shortcuts ==<br />
{| border="1" cellpadding="2" cellspacing="0"<br />
!style="background:#EEE" width="200px"|Shortcut<br />
!style="background:#EEE" width="*"|Usage<br />
|-<br />
|CTRL + T<br />
|Terminates the current program.<br />
|-<br />
|CTRL + R<br />
|Reboots the console.<br />
|-<br />
|CTRL + S<br />
|Forcefully shuts down the computer.<br />
|}<br />
NOTE: You have to hold the keyboard shortcuts down for at least 1 second!<br />
<br />
== Peripheral Functions ==<br />
'''''computer'' stands for the variable you wrapped the computer to.'''<br />
''Example:'' computer = peripheral.wrap( "top" )<br />
<br />
{| class="wikitable"<br />
!style="background:#EEE" width="210px"|Method name<br />
!style="background:#EEE" width="*"|Description<br />
|-<br />
|computer.turnOn()<br />
|Turns on the Computer or Turtle.<br />
|-<br />
|computer.shutdown()<br />
|Shuts off the Computer or Turtle.<br />
|-<br />
|computer.reboot()<br />
|Reboots the Computer or Turtle.<br />
|-<br />
|computer.getID()<br />
|Gets the ID of the Computer or Turtle.<br />
|}</div>Cloudy