-
Notifications
You must be signed in to change notification settings - Fork 462
NonStandardLuaLibs
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 for documentation on the standard libraries.
This page tries to list all differences to these standard libraries.
The original functions from the base library are available with the following differences.
-
collectgarbageis not available. -
dofileandloadfilehave been reimplemented to load files from mounted file system components (they use the filesystem API / reimplementediolibrary). -
loadcan only be used to load text, no binary/compiled code. -
printhas been reimplemented to use the reimplementedio.stdoutwhich usesterm.write.
The original functions 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.
The original functions 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.
The original functions from the table library are available without alteration.
The original functions from the math library are available with minor alterations.
-
math.randomuses a separatejava.util.Randominstance for each Lua state / computer. -
math.randomseedis applied to that instance.
The original functions from the bit32 library are available without alteration.
The original functions 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.popenis not available. If someone could be bothered to reimplement that using coroutines that'd be pretty cool. -
io.opendoes not support the+modes, i.e. it only supportsr,w,a,rb,wbandab. Binary mode in this implementation determines whether to use UTF-8 aware string functions or not, when reading a number of chars (e.g. viaf:read(42)). -
io.stdinreads data usingterm.read. -
io.stdoutwrites usingterm.write. -
io.stderrequalsio.stdout, it is just an alias. -
io.readdoes not support the*nformat at this point.
The original functions from the os library have been partially reimplemented.
-
os.clockhas 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.datehas been reimplemented to use ingame time and supports most formats. -
os.executehas been reimplemented to start programs from a mounted filesystem viashell.execute. The specified string is parsed the same as commands entered in the shell. -
os.exitthrows an error to try and terminate the current coroutine. -
os.getenvis not available. -
os.removeis an alias forfilesystem.remove. -
os.renameis an alias forfilesystem.rename. -
os.setlocaleis not available. -
os.timehas been reimplemented to return the ingame time since the world has been created.
Note that this time is in "in-game seconds". To get the number of game ticks since the world was created, multiply it with1000/60/60(since there are 24000 ticks in a day) and subtract 6000. This offset of 6000 is not arbitrary, it ensures that 6 o'clock AM is actually that. Minecraft somehow thinks six o'clock in the morning is zero - probably because that's "when" a new game starts... -
os.tmpnamehas been reimplemented to generate an unused name in the/tmpmount.
One additional function has been added:
-
os.sleep(seconds: number)which allows pausing a script for the specified amount of time. Note that signals will still be processed by event handlers while the sleep is active, i.e. you cannot pull signals that were accumulated during the sleep after it ended, since no signals will remain in the queue (or at least not all of them).
Some new functions that kind of fall into this category are available in the computer API.