Created NonStandardLuaLibs (markdown)

Florian Nücke 2013-12-06 18:39:38 -08:00
parent 9ff571f26a
commit 1715be6c26

68
NonStandardLuaLibs.md Normal file

@ -0,0 +1,68 @@
Most of Lua's standard libraries are available, although some of them may only be available partially or as re-implementations, meaning behavior may differ slightly. Libraries that are not available are the `package` library and the `debug` library. Please see [the Lua 5.2 manual](http://www.lua.org/manual/5.2/manual.html#6) for documentation on the standard libraries.
This page tries to list all *differences* to these standard libraries.
Basic Functions
---------------
The [original functions](http://www.lua.org/manual/5.2/manual.html#6.1) from the base library are available with the following differences.
- `collectgarbage` is *not* available.
- `dofile` and `loadfile` have been reimplemented to load files from mounted file system components (they use [[the filesystem API|API/Filesystem]] / reimplemented `io` library).
- `load` can only be used to load text, no binary/compiled code.
- `print` has been reimplemented to use the reimplemented `io.stdout` which uses `term.write`.
Coroutine Manipulation
----------------------
The [original functions](http://www.lua.org/manual/5.2/manual.html#6.2) from the `coroutine` library are available with no observable differences.
Note that the `coroutine.resume` and `coroutine.yield` implementations exposed to user code are wrappers that take care of aborting code that does not yield after a certain time (see config), and to allow differentiating system yields from user yields (system yields "bubble", for example this is used for the shutdown command and component API calls). This should not be noticeable from user code, however. If it is, it should be considered a bug.
String Manipulation
-------------------
The [original functions](http://www.lua.org/manual/5.2/manual.html#6.4) from the `string` library are available without alterations.
Note that the functions of the GPU API work on UTF-8 strings, and, by extension, so does `term.write` and `print`. To help you work work with UTF-8 strings, there is an additional library, [[the Unicode API|API/Unicode]].
Table Manipulation
------------------
The [original functions](http://www.lua.org/manual/5.2/manual.html#6.5) from the `table` library are available without alteration.
Mathematical Functions
----------------------
The [original functions](http://www.lua.org/manual/5.2/manual.html#6.6) from the `math` library are available with minor alterations.
- `math.random` uses a separate `java.util.Random` instance for each Lua state / computer.
- `math.randomseed` is applied to that instance.
Bitwise Operations
------------------
The [original functions](http://www.lua.org/manual/5.2/manual.html#6.7) from the `bit32` library are available without alteration.
Input and Output Facilities
---------------------------
The [original functions](http://www.lua.org/manual/5.2/manual.html#6.8) from the `io` library have been reimplemented for the most part, and work on mounted filesystem components and `term.read` / `term.write` for the standard input / output.
For the most part these should be *functionally* equivalent to the standard Lua implementation. They may return error strings that differ from vanilla Lua, though, but since that uses C library errors for the most part, which are platform dependent, it's not a very good idea to use these for program logic anyway.
- `io.popen` is *not* available. If someone could be bothered to reimplement that using coroutines that'd be pretty cool.
- `io.open` does *not* support the `+` modes, i.e. it only supports `r`, `w`, `a`, `rb`, `wb` and `ab`. Binary mode in this implementation determines whether to use UTF-8 aware string functions or not, when reading a number of chars (e.g. via `f:read(42)`).
- `io.stdin` reads data using `term.read`.
- `io.stdout` writes using `term.write`.
- `io.stderr` equals `io.stdout`, it is just an alias.
- `io.read` does *not* support the `*n` format at this point.
Operating System Facilities
---------------------------
The [original functions](http://www.lua.org/manual/5.2/manual.html#6.9) from the `os` library have been partially reimplemented.
- `os.clock` has been reimplemented to return the approximate CPU time, meaning the time the computer has actually been running in an executor thread. This is *not* the same as the time the computer has been running, for that see `[[computer.uptime|API/Computer]]`.
- `os.date` has been reimplemented to use ingame time and supports most formats.
- `os.execute` has been reimplemented to start programs from a mounted filesystem via `shell.execute`. The specified string is parsed the same as commands entered in the shell.
- `os.exit` throws an error to try and terminate the current coroutine.
- `os.getenv` is *not* available.
- `os.remove` is an alias for `filesystem.remove`.
- `os.rename` is an alias for `filesystem.rename`.
- `os.setlocale` is *not* available.
- `os.time` has been reimplemented to return the ingame time since the world has been created.
- `os.tmpname` has been reimplemented to generate an unused name in the `/tmp` mount.
Some new functions that kind of fall into this category are available in [[the computer API|API/Computer]].