Difference between revisions of "Category:APIs"

From ComputerCraft Wiki
Jump to: navigation, search
(Undo revision 3017 by 212.181.114.58 (talk))
(Undo revision 4609 by 72.242.229.2 (talk))
Line 1: Line 1:
Great. Looking forward to itI am also inetersetd in a sidebar Navigation Widget that allows the customization of a list to be made from many options before actually executed in the loop, with a preview of its output displayed in the widget before execution.A mockup can be found here:qurl.co.uk/cc78Note, in my case: Info Type' would refer to the category from which potential posts for the list are taken. Once selected, this then populates the next box: Tag category' which actually refers to all the custom fields contained within the posts of the just selected category.Once selected, this then populates the next box: Select tags' which actually refers to the values present in posts containing the just selected custom field.Once selected, the sample output is produced in the box below of post titles successfully matching the query, whereby if the user is happy, they can then run the query to display in the loop.The box below  Display's output  refers to an idea where posts in other categories have already been linked to the posts in the  Sample Output  and can thus be displayed in the loop instead. I guess it's not relevant atm. Currently showing  refers to the currently displayed loop's active query parameters. In fact, this box would be moved over to the right column and the New Query  box below removed.
+
[[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.
 +
There are two reasons why one might want to use an API:
 +
* 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.
 +
 +
* The API may provide something it's impossible to do yourself because it has to be done in Java rather than Lua.
 +
 
 +
 +
ComputerCraft itself ships with a collection of APIs of both types. For example:
 +
 +
* 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.
 +
 +
* 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).
 +
 +
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.
 +
 
 +
ComputerCraft mods, for example mods that add custom peripherals, might also add APIs that help you work with those peripherals.
 +
 
 +
You can view a list of un-official API's at the [[:Category:Unofficial_APIs]] page.
 +
 
 +
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.
 +
 
 +
You can see a list of APIs built-in to ComputerCraft by typing "apis" in the terminal.
 +
 
 +
[[Category:Lists]]

Revision as of 13:53, 4 December 2012

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.

There are two reasons why one might want to use an API:

  • 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.
  • The API may provide something it's impossible to do yourself because it has to be done in Java rather than Lua.


ComputerCraft itself ships with a collection of APIs of both types. For example:

  • The 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.
  • The 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, but that's just a wrapper around fs).

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.loadAPI" on them.

ComputerCraft mods, for example mods that add custom peripherals, might also add APIs that help you work with those peripherals.

You can view a list of un-official API's at the Category:Unofficial_APIs page.

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.

You can see a list of APIs built-in to ComputerCraft by typing "apis" in the terminal.

Subcategories

This category has the following 2 subcategories, out of 2 total.