API: Difference between revisions

From OpenComputers: Rebooted
Jump to navigation Jump to search
imported>OCDoc Import
Imported from legacy OpenComputers documentation at ocdoc.cil.li
 
Clean up Markdown artifacts from DokuWiki migration
 
Line 5: Line 5:
First and foremost you should get familiar with the [http://www.lua.org/manual/5.3/manual.html Lua reference manual], if you are new to Lua. You will find most basic Lua functionality explained there, as well as a bunch of standard library functions.
First and foremost you should get familiar with the [http://www.lua.org/manual/5.3/manual.html Lua reference manual], if you are new to Lua. You will find most basic Lua functionality explained there, as well as a bunch of standard library functions.


OpenComputers makes an effort to largely emulate the standard library in areas that would usually interact with the host system - that being the I/O library. There are a few differences, which you can look up here: [[API/non-standard-lua-libs|differences in the standard libraries]]. Most notably, the debug library is mostly unavailable, and `load` only accepts text source files, no binary / pre-compiled Lua programs (for security reasons).
OpenComputers makes an effort to largely emulate the standard library in areas that would usually interact with the host system - that being the I/O library. There are a few differences, which you can look up here: [[API/non-standard-lua-libs|differences in the standard libraries]]. Most notably, the debug library is mostly unavailable, and <code>load</code> only accepts text source files, no binary / pre-compiled Lua programs (for security reasons).


These standard libraries are available in the global environment and thus are immediately available; meaning they do not need to be loaded in your scripts to be accessible.
These standard libraries are available in the global environment and thus are immediately available; meaning they do not need to be loaded in your scripts to be accessible.
Line 15: Line 15:
* [[API/non-standard-lua-libs#operating_system_facilities|os]]
* [[API/non-standard-lua-libs#operating_system_facilities|os]]
* [[API/non-standard-lua-libs#Modules|package]]
* [[API/non-standard-lua-libs#Modules|package]]
* `print` Not a library, but a commonly used standard method for printing text to stdout.
* <code>print</code> Not a library, but a commonly used standard method for printing text to stdout.


```lua print("hello world") ```
<syntaxhighlight lang="lua">
print("hello world")
</syntaxhighlight>


* [[API/non-standard-lua-libs#string_manipulation|string]]
* [[API/non-standard-lua-libs#string_manipulation|string]]
Line 26: Line 28:
Following is a description of the non-standard libraries, provided for convenience.
Following is a description of the non-standard libraries, provided for convenience.


Note that you need to `require` all non-standard APIs before you use them, i.e. all modules not listed in the [http://www.lua.org/manual/5.3/manual.html Lua reference manual] nor in [#standard_libraries]. For example, instead of simple going `local rs = component.redstone`, you now need to require the component API, like so:
Note that you need to <code>require</code> all non-standard APIs before you use them, i.e. all modules not listed in the [http://www.lua.org/manual/5.3/manual.html Lua reference manual] nor in [#standard_libraries]. For example, instead of simple going <code>local rs = component.redstone</code>, you now need to require the component API, like so:


```lua local component = require("component") local rs = component.redstone
<syntaxhighlight lang="lua">
local component = require("component") local rs = component.redstone


--You can of course change the variable name: local mycomp = require("component") local rs = mycomp.redstone ``` The same applies for all other APIs listed below (even `sides` and `colors`).
--You can of course change the variable name: local mycomp = require("component") local rs = mycomp.redstone
</syntaxhighlight> The same applies for all other APIs listed below (even <code>sides</code> and <code>colors</code>).


The standard libraries aside, OpenComputers comes with a couple of additional, built-in libraries. Here is a list of all these libraries. Note that some of these may not be usable depending on your configuration (HTTP) and context (Robot library on computers), but they'll still be there.
The standard libraries aside, OpenComputers comes with a couple of additional, built-in libraries. Here is a list of all these libraries. Note that some of these may not be usable depending on your configuration (HTTP) and context (Robot library on computers), but they'll still be there.


'' [[API/buffer|buffer]]: a Lua `FILE''` API buffer implementation for wrapping streams. - [[API/colors|colors]]: a global table that allows referencing standard Minecraft colors by name. - [[API/component|component]]: look-up and management of components attached to the computer. - [[API/computer|computer]]: information on and interactions with the computer the Lua state is running on. - [[API/event|event]]: an event system, often used by libraries, for pulling and registering handlers to signals. - [[API/UUID|uuid]]: creates long unique identifier strings in the common 8-4-4-4-12 format. - [[API/filesystem|filesystem]]: abstracted interaction with file system components. - [[API/internet|internet]]: a wrapper for Internet Card functionality. - [[API/keyboard|keyboard]]: a table of key codes by name and pressed key tracking. - [[API/note|note]]: converts music notes between their real name, their MIDI code and their frequency - [[API/process|process]]: keeps track of running programs and their environments. - [[API/rc|rc]]: provides automatic program execution and service management. - [[API/robot|robot]]: abstracted access to robot actions. - [[API/serialization|serialization]]: allows serialization of values, e.g. for sending them via the network. - [[API/shell|shell]]: working path tracking and program execution. - [[API/sides|sides]]: a global table that allows referencing sides by name. - [[API/term|term]]: provides the concept of the cursor, to read and write from keyboard input and screen output, respectively. - [[API/text|text]]: provides text utilities such as tab to space conversion. - [[API/thread|thread]]: provides autonomous and non-blocking cooperative threads. - [[API/transforms|transforms]]: provides helpful and advanced table manipulators. - [[API/unicode|unicode]]: provides Unicode aware implementations of some functions in the string library.
'' [[API/buffer|buffer]]: a Lua <code>FILE''</code> API buffer implementation for wrapping streams. - [[API/colors|colors]]: a global table that allows referencing standard Minecraft colors by name. - [[API/component|component]]: look-up and management of components attached to the computer. - [[API/computer|computer]]: information on and interactions with the computer the Lua state is running on. - [[API/event|event]]: an event system, often used by libraries, for pulling and registering handlers to signals. - [[API/UUID|uuid]]: creates long unique identifier strings in the common 8-4-4-4-12 format. - [[API/filesystem|filesystem]]: abstracted interaction with file system components. - [[API/internet|internet]]: a wrapper for Internet Card functionality. - [[API/keyboard|keyboard]]: a table of key codes by name and pressed key tracking. - [[API/note|note]]: converts music notes between their real name, their MIDI code and their frequency - [[API/process|process]]: keeps track of running programs and their environments. - [[API/rc|rc]]: provides automatic program execution and service management. - [[API/robot|robot]]: abstracted access to robot actions. - [[API/serialization|serialization]]: allows serialization of values, e.g. for sending them via the network. - [[API/shell|shell]]: working path tracking and program execution. - [[API/sides|sides]]: a global table that allows referencing sides by name. - [[API/term|term]]: provides the concept of the cursor, to read and write from keyboard input and screen output, respectively. - [[API/text|text]]: provides text utilities such as tab to space conversion. - [[API/thread|thread]]: provides autonomous and non-blocking cooperative threads. - [[API/transforms|transforms]]: provides helpful and advanced table manipulators. - [[API/unicode|unicode]]: provides Unicode aware implementations of some functions in the string library.


== Contents ==
== Contents ==


{{:API/contents}}
{{:API/contents}}

Latest revision as of 20:27, 24 August 2026

APIs

Standard Libraries

First and foremost you should get familiar with the Lua reference manual, if you are new to Lua. You will find most basic Lua functionality explained there, as well as a bunch of standard library functions.

OpenComputers makes an effort to largely emulate the standard library in areas that would usually interact with the host system - that being the I/O library. There are a few differences, which you can look up here: differences in the standard libraries. Most notably, the debug library is mostly unavailable, and load only accepts text source files, no binary / pre-compiled Lua programs (for security reasons).

These standard libraries are available in the global environment and thus are immediately available; meaning they do not need to be loaded in your scripts to be accessible.

print("hello world")

Custom Libraries

Following is a description of the non-standard libraries, provided for convenience.

Note that you need to require all non-standard APIs before you use them, i.e. all modules not listed in the Lua reference manual nor in [#standard_libraries]. For example, instead of simple going local rs = component.redstone, you now need to require the component API, like so:

local component = require("component") local rs = component.redstone

--You can of course change the variable name: local mycomp = require("component") local rs = mycomp.redstone

The same applies for all other APIs listed below (even sides and colors).

The standard libraries aside, OpenComputers comes with a couple of additional, built-in libraries. Here is a list of all these libraries. Note that some of these may not be usable depending on your configuration (HTTP) and context (Robot library on computers), but they'll still be there.

buffer: a Lua FILE API buffer implementation for wrapping streams. - colors: a global table that allows referencing standard Minecraft colors by name. - component: look-up and management of components attached to the computer. - computer: information on and interactions with the computer the Lua state is running on. - event: an event system, often used by libraries, for pulling and registering handlers to signals. - uuid: creates long unique identifier strings in the common 8-4-4-4-12 format. - filesystem: abstracted interaction with file system components. - internet: a wrapper for Internet Card functionality. - keyboard: a table of key codes by name and pressed key tracking. - note: converts music notes between their real name, their MIDI code and their frequency - process: keeps track of running programs and their environments. - rc: provides automatic program execution and service management. - robot: abstracted access to robot actions. - serialization: allows serialization of values, e.g. for sending them via the network. - shell: working path tracking and program execution. - sides: a global table that allows referencing sides by name. - term: provides the concept of the cursor, to read and write from keyboard input and screen output, respectively. - text: provides text utilities such as tab to space conversion. - thread: provides autonomous and non-blocking cooperative threads. - transforms: provides helpful and advanced table manipulators. - unicode: provides Unicode aware implementations of some functions in the string library.

Contents

APIs
OpenOS buffer - colors - component - computer - event - filesystem - uuid - internet - keyboard - note - process - rc - robot - serialization - shell - sides - term - text - thread - transforms - unicode
Lua Libraries coroutine - package - io - os