Difference between revisions of "Category:APIs"

From ComputerCraft Wiki
Jump to: navigation, search
 
(31 intermediate revisions by 21 users not shown)
Line 1: Line 1:
[[File:Apis.png|thumb]]An API (Application Programming Interface) is a fairly large block of code inserted or called into a program to ease on the coder. An example is a game development API that adds in features that make game development easier.
+
[[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.
  
Currently there are 20 default API's that come with ComputerCraft: [[bit (API)|bit]], [[colors (API)|colors]], [[colors (API)|colours]] (same as colors), [[coroutine (API)|coroutine]], [[disk (API)|disk]], [[fs (API)|fs]], [[help (API)|help]], [[http (API)|http]], [[io (API)|io]], [[math (API)|math]], [[os (API)|os]], [[parallel (API)|parallel]], [[rednet (API)|rednet]], [[redstone (API)|redstone]], [[redstone (API)|rs]] (shortened redstone), [[shell (API)|shell]], [[string (API)|string]], [[table (API)|table]], [[term (API)|term]], and [[textutils (API)|textutils]]. Users can also use their own API's.
+
 +
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/assets/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.
  
Users can view all the currently enabled API's by entering 'api' in their terminal.
+
ComputerCraft mods, for example mods that add custom peripherals, might also add APIs that help you work with those peripherals.
  
APIs can be used in one of 3 ways. They can be inserted directly into the code, called in through means of running it at the same time as the other code or it can be run all the time by the BIOS. So far however, there are no APIs that run straight from the BIOS, that's just a theory.
+
You can view a list of un-official API's at the [[:Category:Unofficial_APIs]] page.
  
APIs tend to be ~200 lines of code. Some APIs may be used as databases or memory storage for people. Some may be serial encoders/decoders, and some may be to assist in other forms of coding.
+
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.
 
+
Here is a list of all APIs for ComputerCraft.
+
  
 
[[Category:Lists]]
 
[[Category:Lists]]

Latest revision as of 00:31, 23 August 2013

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/assets/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.