mirror of
https://github.com/AR2000AR/openComputers_codes.git
synced 2025-09-08 14:41:14 +02:00
This commit is contained in:
@@ -1,45 +0,0 @@
|
||||
---@meta
|
||||
|
||||
---@class ComponentComputer : Component
|
||||
local computer = {}
|
||||
|
||||
---Tries to start the computer. Returns true on success, false otherwise. Note that this will also return false if the computer was already running. If the computer is currently shutting down, this will cause the computer to reboot instead.
|
||||
---@return boolean
|
||||
function computer.start()
|
||||
end
|
||||
|
||||
---Tries to stop the computer. Returns true on success, false otherwise. Also returns false if the computer is already stopped.
|
||||
---@return boolean
|
||||
function computer.stop()
|
||||
end
|
||||
|
||||
---Returns whether the computer is currently running.
|
||||
---@return boolean
|
||||
function computer.isRunning()
|
||||
end
|
||||
|
||||
---Plays a tone, useful to alert users via audible feedback. Supports frequencies from 20 to 2000Hz, with a duration of up to 5 seconds.
|
||||
---@param frequency number
|
||||
---@param duration number
|
||||
function computer.beep(frequency, duration)
|
||||
end
|
||||
|
||||
---Returns a table of device information. Note that this is architecture-specific and some may not implement it at all.
|
||||
---@return table
|
||||
function computer.getDeviceInfo()
|
||||
end
|
||||
|
||||
---Attempts to crash the computer for the specified reason.
|
||||
---@param reason string
|
||||
function computer.crash(reason)
|
||||
end
|
||||
|
||||
---Returns the computer's current architecture.
|
||||
---@return string
|
||||
function computer.getArchitecture()
|
||||
end
|
||||
|
||||
---Returns whether or not the computer is, in fact, a robot.
|
||||
---@return boolean
|
||||
function computer.isRobot()
|
||||
end
|
@@ -1,136 +0,0 @@
|
||||
---@meta
|
||||
---@class ComponentData : Component
|
||||
local data = {}
|
||||
|
||||
--#region Tier 1 Callbacks
|
||||
|
||||
---Computes CRC-32 hash of the data. Result is in binary format.
|
||||
---@param data string
|
||||
---@return string
|
||||
function data.crc32(data)
|
||||
end
|
||||
|
||||
---Applies base64 decoding to the data.
|
||||
---@param data string
|
||||
---@return string
|
||||
function data.decode64(data)
|
||||
end
|
||||
|
||||
---Applies base64 encoding to the data. Result is in binary format.
|
||||
---@param data string
|
||||
---@return string
|
||||
function data.encode64(data)
|
||||
end
|
||||
|
||||
---Computes MD5 hash of the data. Result is in binary format
|
||||
---@param data string
|
||||
---@return string
|
||||
function data.md5(data)
|
||||
end
|
||||
|
||||
---Computes SHA2-256 hash of the data. Result is in binary format.
|
||||
---@param data string
|
||||
---@return string
|
||||
function data.sha256(data)
|
||||
end
|
||||
|
||||
---Applies deflate compression to the data.
|
||||
---@param data string
|
||||
---@return string
|
||||
function data.deflate(data)
|
||||
end
|
||||
|
||||
---Applies inflate decompression to the data.
|
||||
---@param data string
|
||||
---@return string
|
||||
function data.inflate(data)
|
||||
end
|
||||
|
||||
---The maximum size of data that can be passed to other functions of the card.
|
||||
---@return number
|
||||
function data.getLimit()
|
||||
end
|
||||
|
||||
--endregion
|
||||
|
||||
--#region Tier 2 Callbacks
|
||||
|
||||
---Applies AES encryption to the data using the key and (preferably) random IV.
|
||||
---@param data string
|
||||
---@param key string
|
||||
---@param iv string
|
||||
---@return string
|
||||
function data.encrypt(data, key, iv)
|
||||
end
|
||||
|
||||
---Reverses AES encryption on the data using the key and the IV.
|
||||
---@param data string
|
||||
---@param key string
|
||||
---@param iv string
|
||||
---@return string
|
||||
function data.decrypt(data, key, iv)
|
||||
end
|
||||
|
||||
---Generates a random binary string of len length.
|
||||
---@param len number
|
||||
---@return string
|
||||
function data.random(len)
|
||||
end
|
||||
|
||||
--#endregion
|
||||
|
||||
--#region Tier 3 Callbacks
|
||||
|
||||
---@class EcKey
|
||||
local ecKey = {}
|
||||
|
||||
---is the key public
|
||||
---@return boolean
|
||||
function ecKey.isPublic()
|
||||
end
|
||||
|
||||
---serialize the key to save it
|
||||
---@return string
|
||||
function ecKey.serialize()
|
||||
end
|
||||
|
||||
---@class EcKeyPublic : EcKey
|
||||
|
||||
---@class EcKeyPrivate :EcKey
|
||||
|
||||
---Generates a public/private key pair for various cryptiographic functions.\
|
||||
---Optional second parameter specifies key length, 256 or 384 bits accepted.\
|
||||
---Key types include “ec-public” and “ec-private”. Keys can be serialized with\
|
||||
---key.serialize():string Keys also contain the function key.isPublic():boolean
|
||||
---@param bitLen? 256 | 384
|
||||
---@return EcKeyPublic publicKey, EcKeyPrivate privateKey
|
||||
function data.generateKeyPair(bitLen)
|
||||
end
|
||||
|
||||
---Generates a signiture of data using a private key. If signature is present\
|
||||
---verifies the signature using the public key, the previously generated\
|
||||
---signature string and the original string.
|
||||
---@param data string
|
||||
---@param key EcKey
|
||||
---@param sig? string
|
||||
---@return string|boolean
|
||||
function data.ecdsa(data, key, sig)
|
||||
end
|
||||
|
||||
--- Generates a Diffie-Hellman shared key using the first user's private key and\
|
||||
--- the second user's public key. An example of a basic key relation:\
|
||||
--- ecdh(userA.private, userB.public) == ecdh(userB.private, userA.public)
|
||||
---@param privateKey EcKeyPrivate
|
||||
---@param publicKey EcKeyPublic
|
||||
---@return string
|
||||
function data.ecdh(privateKey, publicKey)
|
||||
end
|
||||
|
||||
---Transforms a key from string to it's arbitrary type.
|
||||
---@param data string
|
||||
---@param type "ec-public" | "ec-private"
|
||||
---@return table
|
||||
function data.deserializeKey(data, type)
|
||||
end
|
||||
|
||||
--#endregion
|
@@ -1,20 +0,0 @@
|
||||
---@meta
|
||||
|
||||
---@class ComponentDiskDrive : Component
|
||||
local disk_drive = {}
|
||||
|
||||
---Eject the currently present medium from the drive.
|
||||
---@param velocity? number
|
||||
---@return boolean
|
||||
function disk_drive.eject(velocity)
|
||||
end
|
||||
|
||||
---Check whether some medium is currently in the drive.
|
||||
---@return boolean
|
||||
function disk_drive.isEmpty()
|
||||
end
|
||||
|
||||
---Return the internal floppy disk address.
|
||||
---@return string|nil address, string|nil reason
|
||||
function disk_drive.media()
|
||||
end
|
@@ -1,54 +0,0 @@
|
||||
---@meta
|
||||
|
||||
---@class ComponentDrive : Component
|
||||
local drive = {}
|
||||
|
||||
---Read a single byte at the specified offset.
|
||||
---@param offset number
|
||||
---@return number
|
||||
function drive.readByte(offset)
|
||||
end
|
||||
|
||||
---Write a single byte to the specified offset.
|
||||
---@param offset number
|
||||
---@param value number
|
||||
function drive.writeByte(offset, value)
|
||||
end
|
||||
|
||||
---Returns the size of a single sector on the drive, in bytes.
|
||||
---@return number
|
||||
function drive.getSectorSize()
|
||||
end
|
||||
|
||||
---Get the current label of the drive.
|
||||
---@return string
|
||||
function drive.getLabel()
|
||||
end
|
||||
|
||||
---Sets the label of the drive. Returns the new value, which may be truncated.
|
||||
---@param value string
|
||||
---@return string
|
||||
function drive.setLabel(value)
|
||||
end
|
||||
|
||||
---Read the current contents of the specified sector.
|
||||
---@param sector number
|
||||
---@return string
|
||||
function drive.readSector(sector)
|
||||
end
|
||||
|
||||
---Write the specified contents to the specified sector.
|
||||
---@param sector number
|
||||
---@param value string
|
||||
function drive.writeSector(sector, value)
|
||||
end
|
||||
|
||||
---Returns the number of platters in the drive.
|
||||
---@return number
|
||||
function drive.getPlatterCount()
|
||||
end
|
||||
|
||||
---Returns the total capacity of the drive, in bytes.
|
||||
---@return number
|
||||
function drive.getCapacity()
|
||||
end
|
@@ -1,114 +0,0 @@
|
||||
---@meta
|
||||
|
||||
---@class ComponentFilesystem : Component
|
||||
local filesytem = {}
|
||||
|
||||
---The currently used capacity of the file system, in bytes.
|
||||
---@return number bytes
|
||||
function filesytem.spaceUsed()
|
||||
end
|
||||
|
||||
---Opens a new file descriptor and returns its handle.
|
||||
---@param path string
|
||||
---@param mode? string
|
||||
---@return number hanlde
|
||||
---@nodiscard
|
||||
function filesytem.open(path, mode)
|
||||
end
|
||||
|
||||
---Seeks in an open file descriptor with the specified handle. Returns the new pointer position.
|
||||
---@param handle number
|
||||
---@param whence string
|
||||
---@param offset number
|
||||
---@return number
|
||||
function filesytem.seek(handle, whence, offset)
|
||||
end
|
||||
|
||||
---Creates a directory at the specified absolute path in the file system. Creates parent directories, if necessary.
|
||||
---@param path string
|
||||
---@return boolean
|
||||
function filesytem.makeDirectory(path)
|
||||
end
|
||||
|
||||
---Returns whether an object exists at the specified absolute path in the file system.
|
||||
---@param path string
|
||||
---@return boolean
|
||||
function filesytem.exists(path)
|
||||
end
|
||||
|
||||
---Returns whether the file system is read-only.
|
||||
---@return boolean
|
||||
function filesytem.isReadOnly()
|
||||
end
|
||||
|
||||
---Writes the specified data to an open file descriptor with the specified handle.
|
||||
---@param handle number
|
||||
---@param value string
|
||||
---@return boolean
|
||||
function filesytem.write(handle, value)
|
||||
end
|
||||
|
||||
---The overall capacity of the file system, in bytes.
|
||||
---@return number
|
||||
function filesytem.spaceTotal()
|
||||
end
|
||||
|
||||
---Returns whether the object at the specified absolute path in the file system is a directory.
|
||||
---@param path string
|
||||
---@return boolean
|
||||
function filesytem.isDirectory(path)
|
||||
end
|
||||
|
||||
---Renames/moves an object from the first specified absolute path in the file system to the second.
|
||||
---@param from string
|
||||
---@param to any
|
||||
---@return boolean
|
||||
function filesytem.rename(from, to)
|
||||
end
|
||||
|
||||
---Returns a list of names of objects in the directory at the specified absolute path in the file system.
|
||||
---@param path string
|
||||
---@return table
|
||||
function filesytem.list(path)
|
||||
end
|
||||
|
||||
---Returns the (real world) timestamp of when the object at the specified absolute path in the file system was modified.
|
||||
---@param path string
|
||||
---@return number
|
||||
function filesytem.lastModified(path)
|
||||
end
|
||||
|
||||
---Get the current label of the file system.
|
||||
---@return string
|
||||
function filesytem.getLabel()
|
||||
end
|
||||
|
||||
---Removes the object at the specified absolute path in the file system.
|
||||
---@param path string
|
||||
---@return boolean
|
||||
function filesytem.remove(path)
|
||||
end
|
||||
|
||||
---Closes an open file descriptor with the specified handle.
|
||||
---@param handle number
|
||||
function filesytem.close(handle)
|
||||
end
|
||||
|
||||
---Returns the size of the object at the specified absolute path in the file system.
|
||||
---@param path string
|
||||
---@return number
|
||||
function filesytem.size(path)
|
||||
end
|
||||
|
||||
---Reads up to the specified amount of data from an open file descriptor with the specified handle. Returns nil when EOF is reached.
|
||||
---@param handle number
|
||||
---@param count number
|
||||
---@return string or nil
|
||||
function filesytem.read(handle, count)
|
||||
end
|
||||
|
||||
---Sets the label of the file system. Returns the new value, which may be truncated.
|
||||
---@param value string
|
||||
---@return string
|
||||
function filesytem.setLabel(value)
|
||||
end
|
@@ -1,208 +0,0 @@
|
||||
---@meta
|
||||
|
||||
---@class ComponentGPU : Component
|
||||
local gpu = {}
|
||||
|
||||
---Tries to bind the GPU to a screen with the specified address. Returns true on success, false and an error message on failure. Resets the screen's settings if reset is 'true'. A GPU can only be bound to one screen at a time. All operations on it will work on the bound screen. If you wish to control multiple screens at once, you'll need to put more than one graphics card into your computer.
|
||||
---@param address string
|
||||
---@param reset? boolean
|
||||
---@return boolean sucess, string|nil reason
|
||||
function gpu.bind(address, reset)
|
||||
end
|
||||
|
||||
---Get the address of the screen the GPU is bound to. Since 1.3.2.
|
||||
---@return string address
|
||||
function gpu.getScreen()
|
||||
end
|
||||
|
||||
---Gets the current background color. This background color is applied to all “pixels” that get changed by other operations.
|
||||
---Note that the returned number is either an RGB value in hexadecimal format, i.e. 0xRRGGBB, or a palette index. The second returned value indicates which of the two it is (true for palette color, false for RGB value).
|
||||
---@return number color, boolean isPaletteIndex
|
||||
function gpu.getBackground()
|
||||
end
|
||||
|
||||
---Sets the background color to apply to “pixels” modified by other operations from now on. The returned value is the old background color, as the actual value it was set to (i.e. not compressed to the color space currently set). The first value is the previous color as an RGB value. If the color was from the palette, the second value will be the index in the palette. Otherwise it will be nil. Note that the color is expected to be specified in hexadecimal RGB format, i.e. 0xRRGGBB. This is to allow uniform color operations regardless of the color depth supported by the screen and GPU.
|
||||
---@param color number
|
||||
---@param isPaletteIndex? boolean
|
||||
---@return number previousColor, number|nil paletIndex
|
||||
function gpu.setBackground(color, isPaletteIndex)
|
||||
end
|
||||
|
||||
---Like getBackground, but for the foreground color.
|
||||
---@return number color, boolean isPaletteIndex
|
||||
function gpu.getForeground()
|
||||
end
|
||||
|
||||
---Like setBackground, but for the foreground color.
|
||||
---@param color number
|
||||
---@param isPaletteIndex? boolean
|
||||
---@return number previousColor, number|nil paletIndex
|
||||
function gpu.setForeground(color, isPaletteIndex)
|
||||
end
|
||||
|
||||
---Gets the RGB value of the color in the palette at the specified index.
|
||||
---@param index number
|
||||
---@return number color rbg color
|
||||
function gpu.getPaletteColor(index)
|
||||
end
|
||||
|
||||
---Sets the RGB value of the color in the palette at the specified index.
|
||||
---@param index number
|
||||
---@param value number rbg color
|
||||
---@return number oldPatetteColor rbg color
|
||||
function gpu.setPaletteColor(index, value)
|
||||
end
|
||||
|
||||
---Gets the maximum supported color depth supported by the GPU and the screen it is bound to (minimum of the two).
|
||||
---@return number maxDepth maximum color depth
|
||||
function gpu.maxDepth()
|
||||
end
|
||||
|
||||
---The currently set color depth of the GPU/screen, in bits. Can be 1, 4 or 8.
|
||||
---@return number colorDepth color depth
|
||||
function gpu.getDepth()
|
||||
end
|
||||
|
||||
---Sets the color depth to use. Can be up to the maximum supported color depth. If a larger or invalid value is provided it will throw an error. Returns the old depth as one of the strings OneBit, FourBit, or EightBit.
|
||||
---@param bit number
|
||||
function gpu.setDepth(bit)
|
||||
end
|
||||
|
||||
---Gets the maximum resolution supported by the GPU and the screen it is bound to (minimum of the two).
|
||||
---@return number x, number y
|
||||
function gpu.maxResolution()
|
||||
end
|
||||
|
||||
---Gets the currently set resolution.
|
||||
---@return number x, number y
|
||||
function gpu.getResolution()
|
||||
end
|
||||
|
||||
---Sets the specified resolution. Can be up to the maximum supported resolution. If a larger or invalid resolution is provided it will throw an error. Returns true if the resolution was changed (may return false if an attempt was made to set it to the same value it was set before), false otherwise.
|
||||
---@return number oldX, number oldY
|
||||
function gpu.setResolution(width, height)
|
||||
end
|
||||
|
||||
---Get the current viewport resolution.
|
||||
---@return number x, number y
|
||||
function gpu.getViewport()
|
||||
end
|
||||
|
||||
---Set the current viewport resolution. Returns true if it was changed (may return false if an attempt was made to set it to the same value it was set before), false otherwise. This makes it look like screen resolution is lower, but the actual resolution stays the same. Characters outside top-left corner of specified size are just hidden, and are intended for rendering or storing things off-screen and copying them to the visible area when needed. Changing resolution will change viewport to whole screen.
|
||||
---@param width number
|
||||
---@param height number
|
||||
---@return boolean
|
||||
function gpu.setViewport(width, height)
|
||||
end
|
||||
|
||||
---Gets the size in blocks of the screen the graphics card is bound to. For simple screens and robots this will be one by one. Deprecated, use screen.getAspectRatio() instead.
|
||||
---@deprecated
|
||||
---@return number x, number y
|
||||
function gpu.getSize()
|
||||
end
|
||||
|
||||
---Gets the character currently being displayed at the specified coordinates. The second and third returned values are the fore- and background color, as hexvalues. If the colors are from the palette, the fourth and fifth values specify the palette index of the color, otherwise they are nil.
|
||||
---@return string character, number foreground, number background, number|nil frgPaletIndex, number|nil bgrPaletIndex
|
||||
function gpu.get(x, y)
|
||||
end
|
||||
|
||||
---Writes a string to the screen, starting at the specified coordinates. The string will be copied to the screen's buffer directly, in a single row. This means even if the specified string contains line breaks, these will just be printed as special characters, the string will not be displayed over multiple lines. Returns true if the string was set to the buffer, false otherwise.
|
||||
---The optional fourth argument makes the specified text get printed vertically instead, if true.
|
||||
---@param x number
|
||||
---@param y number
|
||||
---@param value string
|
||||
---@param vertical? boolean
|
||||
function gpu.set(x, y, value, vertical)
|
||||
end
|
||||
|
||||
---Copies a portion of the screens buffer to another location. The source rectangle is specified by the x, y, width and height parameters. The target rectangle is defined by x + tx, y + ty, width and height. Returns true on success, false otherwise.
|
||||
---@param x number
|
||||
---@param y number
|
||||
---@param width number
|
||||
---@param height number
|
||||
---@param tx number
|
||||
---@param ty number
|
||||
---@return boolean
|
||||
function gpu.copy(x, y, width, height, tx, ty)
|
||||
end
|
||||
|
||||
---Fills a rectangle in the screen buffer with the specified character. The target rectangle is specified by the x and y coordinates and the rectangle's width and height. The fill character char must be a string of length one, i.e. a single character. Returns true on success, false otherwise.
|
||||
---Note that filling screens with spaces ( ) is usually less expensive, i.e. consumes less energy, because it is considered a “clear” operation (see config).
|
||||
---@param x number
|
||||
---@param y number
|
||||
---@param width number
|
||||
---@param height number
|
||||
---@param char string
|
||||
---@return boolean
|
||||
function gpu.fill(x, y, width, height, char)
|
||||
end
|
||||
|
||||
--#region video_buffer
|
||||
|
||||
--Returns the index of the currently selected buffer. 0 is reserved for the screen, and may return 0 even when there is no screen
|
||||
---@return number index
|
||||
function gpu.getActiveBuffer()
|
||||
end
|
||||
|
||||
--Sets the active buffer to index. 0 is reserved for the screen and can be set even when there is no screen. Returns nil for an invalid index (0 is valid even with no screen)
|
||||
---@param index number
|
||||
---@return number previousIndex
|
||||
function gpu.setActiveBuffer(index)
|
||||
end
|
||||
|
||||
---Returns an array of all current page indexes (0 is not included in this list, that is reserved for the screen).
|
||||
---@return table
|
||||
function gpu.buffers()
|
||||
end
|
||||
|
||||
---Allocates a new buffer with dimensions width*heigh (gpu max resolution by default). Returns the index of this new buffer or error when there is not enough video memory. A buffer can be allocated even when there is no screen bound to this gpu. Index 0 is always reserved for the screen and thus the lowest possible index of an allocated buffer is always 1.
|
||||
---@param width? number
|
||||
---@param height? number
|
||||
---@return number
|
||||
function gpu.allocateBuffer(width, height)
|
||||
end
|
||||
|
||||
---Removes buffer at index (default: current buffer index). Returns true if the buffer was removed. When you remove the currently selected buffer, the gpu automatically switches back to index 0 (reserved for a screen)
|
||||
---@param index? number
|
||||
---@return boolean
|
||||
function gpu.freeBuffer(index)
|
||||
end
|
||||
|
||||
---Removes all buffers, freeing all video memory. The buffer index is always 0 after this call.
|
||||
function gpu.freeAllBuffers()
|
||||
end
|
||||
|
||||
---Returns the total memory size of the gpu vram. This does not include the screen.
|
||||
---@return number
|
||||
function gpu.totalMemory()
|
||||
end
|
||||
|
||||
---Returns the total free memory not allocated to buffers. This does not include the screen.
|
||||
---@return number
|
||||
function gpu.freeMemory()
|
||||
end
|
||||
|
||||
---Returns the buffer size at index (default: current buffer index). Returns the screen resolution for index 0. Returns nil for invalid indexes
|
||||
---@param index? number
|
||||
---@return number, number
|
||||
function gpu.getBufferSize(index)
|
||||
end
|
||||
|
||||
---Copy a region from buffer to buffer, screen to buffer, or buffer to screen. Defaults:
|
||||
--- - dst = 0, the screen
|
||||
--- - col, row = 1,1
|
||||
--- - width, height = resolution of the destination buffer
|
||||
--- - src = the current buffer
|
||||
--- - fromCol, fromRow = 1,1 bitblt should preform very fast on repeated use. If the buffer is dirty there is an initial higher cost to sync the buffer with the destination object. If you have a large number of updates to make with frequent bitblts, consider making multiple and smaller buffers. If you plan to use a static buffer (one with few or no updatse), then a large buffer is just fine. Returns true on success
|
||||
---@param dst? number
|
||||
---@param col? number
|
||||
---@param row? number
|
||||
---@param width? number
|
||||
---@param height? number
|
||||
---@param src? number
|
||||
---@param fromCol? number
|
||||
---@param fromRow? number
|
||||
function gpu.bitblt(dst, col, row, width, height, src, fromCol, fromRow)
|
||||
end
|
||||
|
||||
---#endregion
|
@@ -1,93 +0,0 @@
|
||||
---@meta
|
||||
|
||||
---@class ComponentInternet : Component
|
||||
local internet = {}
|
||||
|
||||
--#region component
|
||||
|
||||
---Returns whether TCP connections can be made (config setting).
|
||||
---@return boolean
|
||||
function internet.isTcpEnabled()
|
||||
end
|
||||
|
||||
---Returns whether HTTP requests can be made (config setting).
|
||||
---@return boolean
|
||||
function internet.isHttpEnabled()
|
||||
end
|
||||
|
||||
---Opens a new TCP connection. Returns the handle of the connection.
|
||||
---@param address string
|
||||
---@param port? number
|
||||
---@return TcpSocket
|
||||
function internet.connect(address, port)
|
||||
end
|
||||
|
||||
---Sends a new HTTP request. Returns the handle of the connection.
|
||||
---@param url string
|
||||
---@param postData? string
|
||||
---@param headers? table
|
||||
---@return HttpRequest
|
||||
function internet.request(url, postData, headers)
|
||||
end
|
||||
|
||||
--#endregion
|
||||
|
||||
--#region tcp socket
|
||||
|
||||
---@class TcpSocket
|
||||
local TcpSocket = {}
|
||||
|
||||
---Tries to read data from the socket stream. Returns the read byte array.
|
||||
---@param n? number
|
||||
---@return string
|
||||
function TcpSocket.read(n)
|
||||
end
|
||||
|
||||
---Closes an open socket stream.
|
||||
function TcpSocket.close()
|
||||
end
|
||||
|
||||
---Tries to write data to the socket stream. Returns the number of bytes written.
|
||||
---@param data string
|
||||
---@return number
|
||||
function TcpSocket.write(data)
|
||||
end
|
||||
|
||||
---Ensures a socket is connected. Errors if the connection failed.
|
||||
---@return boolean
|
||||
function TcpSocket.finishConnect()
|
||||
end
|
||||
|
||||
---Returns the id for this socket.
|
||||
---@return string
|
||||
function TcpSocket.id()
|
||||
end
|
||||
|
||||
--#endregion
|
||||
|
||||
--#region http request object
|
||||
|
||||
---@class HttpRequest
|
||||
local HttpRequest = {}
|
||||
|
||||
---Tries to read data from the response. Returns the read byte array.
|
||||
---@param n? number
|
||||
---@return string
|
||||
function HttpRequest.read(n)
|
||||
end
|
||||
|
||||
---Get response code, message and headers.
|
||||
---@return number status, string statusName, table headers
|
||||
function HttpRequest.response()
|
||||
end
|
||||
|
||||
---Closes an open socket stream.
|
||||
function HttpRequest.close()
|
||||
end
|
||||
|
||||
---Ensures a response is available. Errors if the connection failed.
|
||||
---@return boolean
|
||||
function HttpRequest.finishConnect()
|
||||
end
|
||||
|
||||
--#endregion
|
@@ -1,48 +0,0 @@
|
||||
---@meta
|
||||
|
||||
---@alias ModemSafeType string | number | number | boolean
|
||||
---@class ComponentModem : Component
|
||||
local modem = {}
|
||||
|
||||
---@return boolean
|
||||
function modem.isWireless()
|
||||
end
|
||||
|
||||
---@deprecated
|
||||
---@return number
|
||||
function modem.maxPacketSize()
|
||||
end
|
||||
|
||||
---@param port number
|
||||
---@return boolean
|
||||
function modem.isOpen(port)
|
||||
end
|
||||
|
||||
---@param port number
|
||||
function modem.open(port)
|
||||
end
|
||||
|
||||
---@param port number?
|
||||
---@return boolean
|
||||
function modem.close(port)
|
||||
end
|
||||
|
||||
---@param address string
|
||||
---@param port number
|
||||
---@varargs ModemSafeType
|
||||
function modem.send(address, port, ...)
|
||||
end
|
||||
|
||||
---@param port number
|
||||
---@varargs ModemSafeType
|
||||
function modem.broadcast(port, ...)
|
||||
end
|
||||
|
||||
---@return number
|
||||
function modem.getStrength()
|
||||
end
|
||||
|
||||
---@param message string
|
||||
---@param fuzzy boolean?
|
||||
function modem.setWakeMessage(message, fuzzy)
|
||||
end
|
@@ -1,20 +0,0 @@
|
||||
---@meta
|
||||
|
||||
---@class ComponentOsCardWriter : Component
|
||||
local os_cardwriter = {}
|
||||
|
||||
---writes data to an magnetic/rfid card, 3rd parameter sets the card to readonly
|
||||
---@param data string
|
||||
---@param displayName string
|
||||
---@param locked boolean
|
||||
---@param color colors
|
||||
---@return boolean cardWritten
|
||||
function os_cardwriter.write(data, displayName, locked, color)
|
||||
end
|
||||
|
||||
---flashes data to an eeprom
|
||||
---@param data string
|
||||
---@param title string
|
||||
---@param writelock boolean
|
||||
function os_cardwriter.flash(data, title, writelock)
|
||||
end
|
@@ -1,23 +0,0 @@
|
||||
---@meta
|
||||
|
||||
---@class ComponentOsMagReader : Component
|
||||
local os_magreader = {}
|
||||
|
||||
---Sets the event name returned when you click it with a card, default is magData
|
||||
---@param eventName string
|
||||
function os_magreader.setEventName(eventName)
|
||||
end
|
||||
|
||||
---Enables/disables automatic lights on the magreader. If true, it will function as it normally does when clicked with a card. If false, you have to call setLightState to change the lights on the magreader. default is true.
|
||||
---@param enableLights boolean
|
||||
function os_magreader.swipeIndicator(enableLights)
|
||||
end
|
||||
|
||||
---Sets the light state of the magreader. Takes in a number from 0 to 7. default is 0\
|
||||
--- - 1 : red\
|
||||
--- - 2 : yellow\
|
||||
--- - 4 : green
|
||||
---@param lightState number light state as a binary number (1 : red, 3 red + yellow)
|
||||
---@return boolean lightChanged
|
||||
function os_magreader.setLightState(lightState)
|
||||
end
|
@@ -1,80 +0,0 @@
|
||||
---@meta
|
||||
|
||||
---@class ComponentStargate
|
||||
local stargate = {}
|
||||
|
||||
---@alias stargateState
|
||||
--- | "Idle" # Operating and ready to dial
|
||||
--- | "Dialling" # In the process of dialling an address
|
||||
--- | "Opening" # Finished dialling, wormhole in transient phase
|
||||
--- | "Connected" # Wormhole is stable
|
||||
--- | "Closing" # Wormhole is shutting down
|
||||
--- | "Offline" # Interface not connected to a functioning stargate
|
||||
|
||||
---@alias stargateDirection
|
||||
--- | "Outgoing" # Connection was dialled from this end
|
||||
--- | "Incoming" # Connection was dialled from the other end
|
||||
--- | "" # Not connected
|
||||
|
||||
---@alias irisState
|
||||
--- | "Closed"
|
||||
--- | "Opening"
|
||||
--- | "Open"
|
||||
--- | "Closing"
|
||||
--- | "Offline"
|
||||
|
||||
---Return the gate state
|
||||
---@return stargateState state
|
||||
---@return number engaged
|
||||
---@return stargateDirection direction number of engared chevron
|
||||
function stargate.stargateState()
|
||||
end
|
||||
|
||||
---Returns the amount of energy in the gate's internal buffer plus the buffers of any attached Stargate Power Units. This is the energy available for the next dialling operation. If the interface is not connected to a functioning stargate, zero is returned.
|
||||
---@return number su
|
||||
function stargate.energyAvailable()
|
||||
end
|
||||
|
||||
---Returns the amount of energy that would be needed to connect to the stargate at the given address.
|
||||
---@param address string
|
||||
---@return number su
|
||||
function stargate.energyToDial(address)
|
||||
end
|
||||
|
||||
---Returns the address of the attached stargate. If the interface is not connected to a functioning stargate, an empty string is returned.
|
||||
---@return string
|
||||
function stargate.localAddress()
|
||||
end
|
||||
|
||||
---Returns the address of the connected stargate. If there is no connection, or the interface is not connected to a functioning stargate, an empty string is returned.
|
||||
---@return string
|
||||
function stargate.remoteAddress()
|
||||
end
|
||||
|
||||
---Dials the given address.
|
||||
---@param address string
|
||||
function stargate.dial(address)
|
||||
end
|
||||
|
||||
---Closes any open connection.
|
||||
function stargate.disconnect()
|
||||
end
|
||||
|
||||
---Returns a string indicating the state of the iris: Closed, Opening, Open, Closing. Returns Offline if no iris is fitted or the interface is not connected to a functioning stargate.
|
||||
---@return irisState
|
||||
function stargate.irisState()
|
||||
end
|
||||
|
||||
---Closes the iris, if fitted.
|
||||
function stargate.closeIris()
|
||||
end
|
||||
|
||||
---Opens the iris, if fitted.
|
||||
function stargate.openIris()
|
||||
end
|
||||
|
||||
---Sends a message through an open connection to any stargate interfaces attached to the destination stargate. Any number of arguments may be passed. The message is delivered to connected computers as an sgMessageReceived event. Has no effect if no stargate connection is open.
|
||||
---@param arg string|number|boolean
|
||||
---@param ... string|number|boolean
|
||||
function stargate.sendMessage(arg, ...)
|
||||
end
|
@@ -1,132 +0,0 @@
|
||||
---@meta
|
||||
|
||||
---@class ComponentTransposer
|
||||
local transposer = {}
|
||||
|
||||
---Transfer some fluids between two fluid handlers (pipes or tanks, etc). sourceSide is the side pulled from and sinkSide is the side transferred to. The side value is a integral value representing the cardinal directions (east, west, south, north), up, and down. The sides library has these values for convenience. count is the number of millibuckets to transfers. Returns true and the number of millibuckets transfered on success, or false and an error message on failure.
|
||||
---@param sourceSide side
|
||||
---@param sinkSide side
|
||||
---@param count number
|
||||
---@return boolean, number
|
||||
function transposer.transferFluid(sourceSide, sinkSide, count)
|
||||
end
|
||||
|
||||
---Store an item stack description in the specified slot of the database with the specified address.
|
||||
---@param side side
|
||||
---@param slot number
|
||||
---@param dbAddress string
|
||||
---@param dbSlot number
|
||||
---@return boolean
|
||||
function transposer.store(side, slot, dbAddress, dbSlot)
|
||||
end
|
||||
|
||||
---Compare an item in the specified slot in the inventory on the specified side with one in the database with the specified address.
|
||||
---@param side side
|
||||
---@param slot number
|
||||
---@param dbAddress string
|
||||
---@param dbSlot number
|
||||
---@param checkNBT? boolean
|
||||
---@return boolean
|
||||
function transposer.compareStackToDatabase(side, slot, dbAddress, dbSlot, checkNBT)
|
||||
end
|
||||
|
||||
---Get number of items in the specified slot of the inventory on the specified side of the device.
|
||||
---@param side side
|
||||
---@param slot number
|
||||
---@return number
|
||||
function transposer.getSlotStackSize(side, slot)
|
||||
end
|
||||
|
||||
---Get the maximum number of items in the specified slot of the inventory on the specified side of the device.
|
||||
---@param side side
|
||||
---@param slot number
|
||||
---@return number
|
||||
function transposer.getSlotMaxStackSize(side, slot)
|
||||
end
|
||||
|
||||
---Get the the name of the inventory on the specified side of the device.
|
||||
---@param side side
|
||||
---@return string
|
||||
function transposer.getInventoryName(side)
|
||||
end
|
||||
|
||||
---Get the number of slots in the inventory on the specified side of the device.
|
||||
---@param side side
|
||||
---@return number
|
||||
function transposer.getInventorySize(side)
|
||||
end
|
||||
|
||||
---Get a description of the fluid in the the specified tank on the specified side.
|
||||
---@param side side
|
||||
---@param tank number
|
||||
---@return table
|
||||
function transposer.getFluidInTank(side, tank)
|
||||
end
|
||||
|
||||
---Get the amount of fluid in the specified tank on the specified side.
|
||||
---@param side side
|
||||
---@param tank number
|
||||
---@return number
|
||||
function transposer.getTankLevel(side, tank)
|
||||
end
|
||||
|
||||
---Transfer some items between two inventories.
|
||||
---@param sourceSide side
|
||||
---@param sinkSide side
|
||||
---@param count? number
|
||||
---@param sourceSlot? number
|
||||
---@param sinkSlot? number
|
||||
---@return number
|
||||
function transposer.transferItem(sourceSide, sinkSide, count, sourceSlot, sinkSlot)
|
||||
end
|
||||
|
||||
---Get whether the items in the two specified slots of the inventory on the specified side of the device are of the same type.
|
||||
---@param side side
|
||||
---@param slotA number
|
||||
---@param slotB number
|
||||
---@param checkNBT? boolean
|
||||
---@return boolean
|
||||
function transposer.compareStacks(side, slotA, slotB, checkNBT)
|
||||
end
|
||||
|
||||
---Get whether the items in the two specified slots of the inventory on the specified side of the device are equivalent (have shared OreDictionary IDs).
|
||||
---@param side side
|
||||
---@param slotA number
|
||||
---@param slotB number
|
||||
---@return boolean
|
||||
function transposer.areStacksEquivalent(side, slotA, slotB)
|
||||
end
|
||||
|
||||
---Get the number of tanks available on the specified side.
|
||||
---@param side side
|
||||
---@return number
|
||||
function transposer.getTankCount(side)
|
||||
end
|
||||
|
||||
---Get a description of the stack in the inventory on the specified side of the device.
|
||||
---@param side side
|
||||
---@param slot number
|
||||
---@return table
|
||||
function transposer.getStackInSlot(side, slot)
|
||||
end
|
||||
|
||||
---Get the capacity of the specified tank on the specified side.
|
||||
---@param side side
|
||||
---@param tank number
|
||||
---@return number
|
||||
function transposer.getTankCapacity(side, tank)
|
||||
end
|
||||
|
||||
---Get a description of all stacks in the inventory on the specified side of the device.\
|
||||
---The return value is callable. Calling it will return a table describing the stack in the inventory or nothing if the iterator reaches end.\
|
||||
---The return value provides the followings callbacks:\
|
||||
---Returns ALL the stack in the this.array. Memory intensive.\
|
||||
---getAll():table\
|
||||
---Returns the number of elements in the this.array.\
|
||||
---count():number\
|
||||
---Reset the iterator index so that the next call will return the first element.\
|
||||
---reset()
|
||||
---@param side side
|
||||
---@return userdata
|
||||
function transposer.getAllStacks(side)
|
||||
end
|
@@ -1,31 +0,0 @@
|
||||
---@meta
|
||||
|
||||
---@class ComponentTunnel : Component
|
||||
local tunnel = {}
|
||||
|
||||
---Sends the specified data to the card this one is linked to.
|
||||
---@param ... string|number|boolean data
|
||||
function tunnel.send(...)
|
||||
end
|
||||
|
||||
---Gets the maximum packet size (config setting).
|
||||
---@return number
|
||||
function tunnel.maxPacketSize()
|
||||
end
|
||||
|
||||
---Gets the tunnel address of the link card. This is also available in linkChannel using an inventory controller and getting the stack from an inventory slot.
|
||||
---@return string
|
||||
function tunnel.getChannel()
|
||||
end
|
||||
|
||||
---Gets the current wake-up message. When the network card detects the wake message (a string in the first argument of a network packet), on any port and the machine is off, the machine is started. This is the same functionality also provided by robots, cases, servers, drones, and tablets.
|
||||
---@return string
|
||||
function tunnel.getWakeMessage()
|
||||
end
|
||||
|
||||
---Sets the wake-up message to the specified string. The message matching can be fuzzy (default is false). A fuzzy match ignores additional trailing arguments in the network packet.
|
||||
---@param message string
|
||||
---@param fuzzy boolean
|
||||
---@return string
|
||||
function tunnel.setWakeMessage(message, fuzzy)
|
||||
end
|
@@ -1,195 +0,0 @@
|
||||
---@meta
|
||||
|
||||
---@param idx number
|
||||
---@param var any
|
||||
---@vararg 'string' | 'table' | 'number' | 'boolean' | 'userdata' | 'nil' | 'function'
|
||||
function checkArg(idx, var, ...)
|
||||
end
|
||||
|
||||
component = {
|
||||
doc = function(...)
|
||||
end,
|
||||
fields = function(...)
|
||||
end,
|
||||
invoke = function(...)
|
||||
end,
|
||||
list = function(...)
|
||||
end,
|
||||
methods = function(...)
|
||||
end,
|
||||
proxy = function(...)
|
||||
end,
|
||||
slot = function(...)
|
||||
end,
|
||||
type = function(...)
|
||||
end
|
||||
}
|
||||
|
||||
computer = {}
|
||||
|
||||
_VERSION = 5.3
|
||||
|
||||
_OSVERSION = "OpenOS 1.7.7"
|
||||
|
||||
computer = require("computer")
|
||||
|
||||
string = require("string")
|
||||
math = require("math")
|
||||
table = require("table")
|
||||
debug = {
|
||||
getinfo = function(...)
|
||||
end,
|
||||
traceback = function(...)
|
||||
end,
|
||||
getlocal = function(...)
|
||||
end,
|
||||
getupvalue = function(...)
|
||||
end,
|
||||
}
|
||||
coroutine = require("coroutine")
|
||||
local bit32 = {}
|
||||
|
||||
---Returns the number x shifted disp bits to the right. The number disp may be any representable integer. Negative displacements shift to the left.\
|
||||
---This shift operation is what is called arithmetic shift. Vacant bits on the left are filled with copies of the higher bit of x; vacant bits on the right are filled with zeros. In particular, displacements with absolute values higher than 31 result in zero or 0xFFFFFFFF (all original bits are shifted out).
|
||||
---@param x number
|
||||
---@param disp number
|
||||
---@return number
|
||||
function bit32.arshift(x, disp)
|
||||
end
|
||||
|
||||
---Returns the bitwise and of its operands.
|
||||
---@param ... number
|
||||
---@return number
|
||||
function bit32.band(...)
|
||||
end
|
||||
|
||||
---Returns the bitwise negation of x. For any integer x, the following identity holds:\
|
||||
---`assert(bit32.bnot(x) == (-1 - x) % 2^32)`
|
||||
---@param x number
|
||||
---@return number
|
||||
function bit32.bnot(x)
|
||||
end
|
||||
|
||||
---Returns the bitwise or of its operands.
|
||||
---@param ... number
|
||||
---@return number
|
||||
function bit32.bor(...)
|
||||
end
|
||||
|
||||
---Returns a boolean signaling whether the bitwise and of its operands is different from zero.
|
||||
---@param ... number
|
||||
---@return boolean
|
||||
function bit32.btest(...)
|
||||
end
|
||||
|
||||
---Returns the bitwise exclusive or of its operands.
|
||||
---@param ... number
|
||||
---@return number
|
||||
function bit32.bxor(...)
|
||||
end
|
||||
|
||||
---Returns the unsigned number formed by the bits field to field + width - 1 from n. Bits are numbered from 0 (least significant) to 31 (most significant). All accessed bits must be in the range [0, 31].\
|
||||
---The default for width is 1.
|
||||
---@param n number
|
||||
---@param filed number
|
||||
---@param width? number
|
||||
---@return number
|
||||
function bit32.extract(n, filed, width)
|
||||
end
|
||||
|
||||
---Returns the number x rotated disp bits to the left. The number disp may be any representable integer.\
|
||||
---For any valid displacement, the following identity holds:\
|
||||
---`assert(bit32.lrotate(x, disp) == bit32.lrotate(x, disp % 32))`\
|
||||
---In particular, negative displacements rotate to the right.
|
||||
---@param x number
|
||||
---@param disp any
|
||||
---@return number
|
||||
function bit32.lrotate(x, disp)
|
||||
end
|
||||
|
||||
---Returns the number x shifted disp bits to the left. The number disp may be any representable integer. Negative displacements shift to the right. In any direction, vacant bits are filled with zeros. In particular, displacements with absolute values higher than 31 result in zero (all bits are shifted out).\
|
||||
---For positive displacements, the following equality holds:\
|
||||
---`assert(bit32.lshift(b, disp) == (b * 2^disp) % 2^32)`
|
||||
---@param x number
|
||||
---@param disp any
|
||||
---@return number
|
||||
function bit32.lshift(x, disp)
|
||||
end
|
||||
|
||||
---Returns a copy of n with the bits field to field + width - 1 replaced by the value v. See bit32.extract for details about field and width.
|
||||
---@param n number
|
||||
---@param v number
|
||||
---@param field number
|
||||
---@param width number
|
||||
---@return number
|
||||
function bit32.replace(n, v, field, width)
|
||||
end
|
||||
|
||||
---Returns the number x rotated disp bits to the right. The number disp may be any representable integer.\
|
||||
---For any valid displacement, the following identity holds:\
|
||||
---`assert(bit32.rrotate(x, disp) == bit32.rrotate(x, disp % 32))`\
|
||||
---In particular, negative displacements rotate to the left.
|
||||
---@param x number
|
||||
---@param disp any
|
||||
---@return number
|
||||
function bit32.rrotate(x, disp)
|
||||
end
|
||||
|
||||
---Returns the number x shifted disp bits to the right. The number disp may be any representable integer. Negative displacements shift to the left. In any direction, vacant bits are filled with zeros. In particular, displacements with absolute values higher than 31 result in zero (all bits are shifted out).\
|
||||
---For positive displacements, the following equality holds:\
|
||||
---assert(bit32.rshift(b, disp) == math.floor(b % 2^32 / 2^disp))\
|
||||
---This shift operation is what is called logical shift.
|
||||
---@param x number
|
||||
---@param disp number
|
||||
---@return number
|
||||
function bit32.rshift(x, disp)
|
||||
end
|
||||
|
||||
os = {
|
||||
clock = function(...)
|
||||
end,
|
||||
date = function(...)
|
||||
end,
|
||||
difftime = function(...)
|
||||
end,
|
||||
time = function(...)
|
||||
end,
|
||||
}
|
||||
|
||||
unicode = {
|
||||
char = function(...)
|
||||
end,
|
||||
charWidth = function(...)
|
||||
end,
|
||||
isWide = function(...)
|
||||
end,
|
||||
len = function(...)
|
||||
end,
|
||||
lower = function(...)
|
||||
end,
|
||||
reverse = function(...)
|
||||
end,
|
||||
sub = function(...)
|
||||
end,
|
||||
upper = function(...)
|
||||
end,
|
||||
wlen = function(...)
|
||||
end,
|
||||
wtrunc = function(...)
|
||||
end,
|
||||
}
|
||||
|
||||
utf8 = {
|
||||
char = function(...)
|
||||
end,
|
||||
charpattern = function(...)
|
||||
end,
|
||||
codes = function(...)
|
||||
end,
|
||||
codepoint = function(...)
|
||||
end,
|
||||
len = function(...)
|
||||
end,
|
||||
offset = function(...)
|
||||
end,
|
||||
}
|
@@ -1,101 +0,0 @@
|
||||
---@meta
|
||||
---@class bit32lib
|
||||
local bit32 = {}
|
||||
|
||||
---Returns the number x shifted disp bits to the right. The number disp may be any representable integer. Negative displacements shift to the left.\
|
||||
---This shift operation is what is called arithmetic shift. Vacant bits on the left are filled with copies of the higher bit of x; vacant bits on the right are filled with zeros. In particular, displacements with absolute values higher than 31 result in zero or 0xFFFFFFFF (all original bits are shifted out).
|
||||
---@param x number
|
||||
---@param disp number
|
||||
---@return number
|
||||
function bit32.arshift(x, disp)
|
||||
end
|
||||
|
||||
---Returns the bitwise and of its operands.
|
||||
---@param ... number
|
||||
---@return number
|
||||
function bit32.band(...)
|
||||
end
|
||||
|
||||
---Returns the bitwise negation of x. For any integer x, the following identity holds:\
|
||||
---`assert(bit32.bnot(x) == (-1 - x) % 2^32)`
|
||||
---@param x number
|
||||
---@return number
|
||||
function bit32.bnot(x)
|
||||
end
|
||||
|
||||
---Returns the bitwise or of its operands.
|
||||
---@param ... number
|
||||
---@return number
|
||||
function bit32.bor(...)
|
||||
end
|
||||
|
||||
---Returns a boolean signaling whether the bitwise and of its operands is different from zero.
|
||||
---@param ... number
|
||||
---@return boolean
|
||||
function bit32.btest(...)
|
||||
end
|
||||
|
||||
---Returns the bitwise exclusive or of its operands.
|
||||
---@param ... number
|
||||
---@return number
|
||||
function bit32.bxor(...)
|
||||
end
|
||||
|
||||
---Returns the unsigned number formed by the bits field to field + width - 1 from n. Bits are numbered from 0 (least significant) to 31 (most significant). All accessed bits must be in the range [0, 31].\
|
||||
---The default for width is 1.
|
||||
---@param n number
|
||||
---@param filed number
|
||||
---@param width? number
|
||||
---@return number
|
||||
function bit32.extract(n, filed, width)
|
||||
end
|
||||
|
||||
---Returns the number x rotated disp bits to the left. The number disp may be any representable integer.\
|
||||
---For any valid displacement, the following identity holds:\
|
||||
---`assert(bit32.lrotate(x, disp) == bit32.lrotate(x, disp % 32))`\
|
||||
---In particular, negative displacements rotate to the right.
|
||||
---@param x number
|
||||
---@param disp any
|
||||
---@return number
|
||||
function bit32.lrotate(x, disp)
|
||||
end
|
||||
|
||||
---Returns the number x shifted disp bits to the left. The number disp may be any representable integer. Negative displacements shift to the right. In any direction, vacant bits are filled with zeros. In particular, displacements with absolute values higher than 31 result in zero (all bits are shifted out).\
|
||||
---For positive displacements, the following equality holds:\
|
||||
---`assert(bit32.lshift(b, disp) == (b * 2^disp) % 2^32)`
|
||||
---@param x number
|
||||
---@param disp any
|
||||
---@return number
|
||||
function bit32.lshift(x, disp)
|
||||
end
|
||||
|
||||
---Returns a copy of n with the bits field to field + width - 1 replaced by the value v. See bit32.extract for details about field and width.
|
||||
---@param n number
|
||||
---@param v number
|
||||
---@param field number
|
||||
---@param width? number
|
||||
---@return number
|
||||
function bit32.replace(n, v, field, width)
|
||||
end
|
||||
|
||||
---Returns the number x rotated disp bits to the right. The number disp may be any representable integer.\
|
||||
---For any valid displacement, the following identity holds:\
|
||||
---`assert(bit32.rrotate(x, disp) == bit32.rrotate(x, disp % 32))`\
|
||||
---In particular, negative displacements rotate to the left.
|
||||
---@param x number
|
||||
---@param disp any
|
||||
---@return number
|
||||
function bit32.rrotate(x, disp)
|
||||
end
|
||||
|
||||
---Returns the number x shifted disp bits to the right. The number disp may be any representable integer. Negative displacements shift to the left. In any direction, vacant bits are filled with zeros. In particular, displacements with absolute values higher than 31 result in zero (all bits are shifted out).\
|
||||
---For positive displacements, the following equality holds:\
|
||||
---assert(bit32.rshift(b, disp) == math.floor(b % 2^32 / 2^disp))\
|
||||
---This shift operation is what is called logical shift.
|
||||
---@param x number
|
||||
---@param disp number
|
||||
---@return number
|
||||
function bit32.rshift(x, disp)
|
||||
end
|
||||
|
||||
return bit32
|
@@ -1,42 +0,0 @@
|
||||
---@meta
|
||||
|
||||
---@class bufferLib
|
||||
local buffer = {}
|
||||
|
||||
---Creates a new buffered `stream`, wrapping stream with read-write `mode`.\
|
||||
---`mode` can be readonly (r or `nil`), read-write (rw), or write-only (w).
|
||||
---@param mode readmode
|
||||
---@param stream table
|
||||
---@return buffer
|
||||
function buffer.new(mode, stream)
|
||||
end
|
||||
|
||||
---@class buffer
|
||||
local buffer = {}
|
||||
|
||||
function buffer:flush()
|
||||
end
|
||||
|
||||
function buffer:close()
|
||||
end
|
||||
|
||||
function buffer:setvbuf(mode, size)
|
||||
end
|
||||
|
||||
function buffer:write(...)
|
||||
end
|
||||
|
||||
function buffer:lines(line_format)
|
||||
end
|
||||
|
||||
function buffer:read(...)
|
||||
end
|
||||
|
||||
function buffer:getTimeout()
|
||||
end
|
||||
|
||||
function buffer:setTimeout(timeout)
|
||||
end
|
||||
|
||||
function buffer:seek(whence, offset)
|
||||
end
|
@@ -1,19 +0,0 @@
|
||||
---@meta
|
||||
|
||||
---@alias colors
|
||||
--- | 0 # white
|
||||
--- | 1 # orange
|
||||
--- | 2 # magenta
|
||||
--- | 3 # lightblue
|
||||
--- | 4 # yellow
|
||||
--- | 5 # lime
|
||||
--- | 6 # pink
|
||||
--- | 7 # gray
|
||||
--- | 8 # silver
|
||||
--- | 9 # cyan
|
||||
--- | 10 # purple
|
||||
--- | 11 # blue
|
||||
--- | 12 # brown
|
||||
--- | 13 # green
|
||||
--- | 14 # red
|
||||
--- | 15 # black
|
@@ -1,107 +0,0 @@
|
||||
---@meta
|
||||
|
||||
---@class Component
|
||||
---@field slot number
|
||||
---@field type string
|
||||
---@field address string
|
||||
|
||||
---The component API is used to access and interact with components available to a computer.
|
||||
---@class componentlib
|
||||
---@field transposer ComponentTransposer
|
||||
---@field modem ComponentModem
|
||||
---@field tunnel ComponentTunnel
|
||||
---@field internet ComponentInternet
|
||||
---@field gpu ComponentGPU
|
||||
---@field drive ComponentDrive
|
||||
---@field disk_drive ComponentDiskDrive
|
||||
---@field filesystem ComponentFilesystem
|
||||
---@field data ComponentData
|
||||
---@field computer ComponentComputer
|
||||
---@field os_magreader ComponentOsMagReader
|
||||
---@field os_cardwriter ComponentOsCardWriter
|
||||
---@field stargate ComponentStargate
|
||||
local component = {}
|
||||
|
||||
---Returns the documentation string for the method with the specified name of the component with the specified address, if any. Note that you can also get this string by using tostring on a method in a proxy, for example tostring(component.screen.isOn).
|
||||
---@param address string
|
||||
---@param method string
|
||||
---@return string documentation
|
||||
function component.doc(address, method)
|
||||
end
|
||||
|
||||
---Calls the method with the specified name on the component with the specified address, passing the remaining arguments as arguments to that method. Returns the result of the method call, i.e. the values returned by the method. Depending on the called method's implementation this may throw.
|
||||
---@param address string
|
||||
---@param method string
|
||||
---@param ... unknown
|
||||
---@return unknown ...
|
||||
function component.invoke(address, method, ...)
|
||||
end
|
||||
|
||||
---Returns a table with all components currently attached to the computer, with address as a key and component type as a value. It also provides iterator syntax via __call, so you can use it like so: for address, componentType in component.list() do ... end\
|
||||
---If filter is set this will only return components that contain the filter string (this is not a pattern/regular expression). For example, component.list("red") will return redstone components.\
|
||||
---If true is passed as a second parameter, exact matching is enforced, e.g. red will not match redstone.
|
||||
---@param filter? string
|
||||
---@param exact? boolean
|
||||
---@return function iterator
|
||||
function component.list(filter, exact)
|
||||
end
|
||||
|
||||
---Returns a table with the names of all methods provided by the component with the specified address. The names are the keys in the table, the values indicate whether the method is called directly or not.
|
||||
---@param address string
|
||||
---@return table methodeNames
|
||||
function component.methods(address)
|
||||
end
|
||||
|
||||
---Gets a 'proxy' object for a component that provides all methods the component provides as fields, so they can be called more directly (instead of via invoke). This is what's used to generate 'primaries' of the individual component types, i.e. what you get via component.blah.\
|
||||
---For example, you can use it like so: component.proxy(component.list("redstone")()).getInput(sides.north), which gets you a proxy for the first redstone component returned by the component.list iterator, and then calls getInput on it.\
|
||||
---Note that proxies will always have at least two fields, type with the component's type name, and address with the component's address.
|
||||
---@param address string
|
||||
---@return Component proxy
|
||||
function component.proxy(address)
|
||||
end
|
||||
|
||||
---Get the component type of the component with the specified address.
|
||||
---@param address string
|
||||
---@return string type
|
||||
function component.type(address)
|
||||
end
|
||||
|
||||
---Return slot number which the component is installed into. Returns -1 if it doesn't otherwise make sense.
|
||||
---@param address string
|
||||
---@return number slotNumber
|
||||
function component.slot(address)
|
||||
end
|
||||
|
||||
---Undocumented
|
||||
---@param address string
|
||||
---@return string
|
||||
function component.fields(address)
|
||||
end
|
||||
|
||||
---Tries to resolve an abbreviated address to a full address. Returns the full address on success, or nil and an error message otherwise. Optionally filters by component type.
|
||||
---@param address string
|
||||
---@param componentType string
|
||||
---@return string|nil address, string|nil reason
|
||||
function component.get(address, componentType)
|
||||
end
|
||||
|
||||
---Checks if there is a primary component of the specified component type.
|
||||
---@param componentType string
|
||||
---@return boolean componentAvailable
|
||||
function component.isAvailable(componentType)
|
||||
end
|
||||
|
||||
---Gets the proxy for the primary component of the specified type. Throws an error if there is no primary component of the specified type.
|
||||
---@param componentType string
|
||||
---@return Component proxy
|
||||
function component.getPrimary(componentType)
|
||||
end
|
||||
|
||||
---Sets a new primary component for the specified component type. The address may be abbreviated, but must be valid if it is not nil. Triggers the component_unavailable and component_available signals if set to nil or a new value, respectively.\
|
||||
---Note that the component API has a metatable that allows the following syntax:
|
||||
---@param componentType string
|
||||
---@param address string
|
||||
function component.setPrimary(componentType, address)
|
||||
end
|
||||
|
||||
return component
|
@@ -1,114 +0,0 @@
|
||||
---@meta
|
||||
|
||||
---@class computerlib
|
||||
local computer = {}
|
||||
|
||||
---The component address of this computer.
|
||||
---@return string
|
||||
function computer.address()
|
||||
end
|
||||
|
||||
---The component address of the computer's temporary file system (if any), used for mounting it on startup.
|
||||
---@return string
|
||||
function computer.tmpAddress()
|
||||
end
|
||||
|
||||
---The amount of memory currently unused, in bytes. If this gets close to zero your computer will probably soon crash with an out of memory error. Note that for OpenOS, it is highly recommended to at least have 1x tier 1.5 RAM stick or more. The os will boot on a single tier 1 ram stick, but quickly and easily run out of memory.
|
||||
---@return number
|
||||
function computer.freeMemory()
|
||||
end
|
||||
|
||||
---The total amount of memory installed in this computer, in bytes.
|
||||
---@return number
|
||||
function computer.totalMemory()
|
||||
end
|
||||
|
||||
---The amount of energy currently available in the network the computer is in. For a robot this is the robot's own energy / fuel level.
|
||||
---@return number
|
||||
function computer.energy()
|
||||
end
|
||||
|
||||
---The maximum amount of energy that can be stored in the network the computer is in. For a robot this is the size of the robot's internal buffer (what you see in the robot's GUI).
|
||||
---@return number
|
||||
function computer.maxEnergy()
|
||||
end
|
||||
|
||||
---The time in real world seconds this computer has been running, measured based on the world time that passed since it was started - meaning this will not increase while the game is paused, for example.
|
||||
---@return number
|
||||
function computer.uptime()
|
||||
end
|
||||
|
||||
---Shuts down the computer. Optionally reboots the computer, if reboot is true, i.e. shuts down, then starts it again automatically. This function never returns. This example will reboot the computer if it has been running for at least 300 seconds(5 minutes)
|
||||
---```lua
|
||||
--- local computer = require("computer")
|
||||
--- if computer.uptime() >= 300 then
|
||||
--- computer.shutdown(true)
|
||||
--- end
|
||||
---```
|
||||
---@param reboot? boolean
|
||||
function computer.shutdown(reboot)
|
||||
end
|
||||
|
||||
---Get the address of the filesystem component from which to try to boot first. New since OC 1.3.
|
||||
---@return string
|
||||
function computer.getBootAddress()
|
||||
end
|
||||
|
||||
---Set the address of the filesystem component from which to try to boot first. Call with nil / no arguments to clear. New since OC 1.3.
|
||||
---@param address string
|
||||
function computer.setBootAddress(address)
|
||||
end
|
||||
|
||||
---Returns the current runlevel the computer is in. Current Runlevels in OpenOS are:\
|
||||
---S: Single-User mode, no components or filesystems initialized yet\
|
||||
---1: Single-User mode, filesystems and components initialized - OpenOS finished booting
|
||||
---@return string|number
|
||||
function computer.runlevel()
|
||||
end
|
||||
|
||||
---A list of all users registered on this computer, as a tuple. To iterate the result as a list, use table.pack on it, first. Please see the user rights documentation.
|
||||
---@return string, ...
|
||||
function computer.users()
|
||||
end
|
||||
|
||||
---Registers a new user with this computer. Returns true if the user was successfully added. Returns nil and an error message otherwise.\
|
||||
---The user must be currently in the game. The user will gain full access rights on the computer. In the shell, useradd USER is a command line option to invoke this method.
|
||||
---@param name string
|
||||
---@return boolean or nil, string
|
||||
function computer.addUser(name)
|
||||
end
|
||||
|
||||
---Unregisters a user from this computer. Returns true if the user was removed, false if they weren't registered in the first place.\
|
||||
---The user will lose all access to this computer. When the last user is removed from the user list, the computer becomes accessible to all players. userdel USER is a command line option to invoke this method.
|
||||
---@param name string
|
||||
---@return boolean
|
||||
function computer.removeUser(name)
|
||||
end
|
||||
|
||||
---Pushes a new signal into the queue. Signals are processed in a FIFO order. The signal has to at least have a name. Arguments to pass along with it are optional. Note that the types supported as signal parameters are limited to the basic types nil, boolean, number, string, and tables. Yes tables are supported (keep reading). Threads and functions are not supported.\
|
||||
---Note that only tables of the supported types are supported. That is, tables must compose types supported, such as other strings and numbers, or even sub tables. But not of functions or threads.
|
||||
---@param name string
|
||||
---@param ...? any
|
||||
function computer.pushSignal(name, ...)
|
||||
end
|
||||
|
||||
---Tries to pull a signal from the queue, waiting up to the specified amount of time before failing and returning nil. If no timeout is specified waits forever.\
|
||||
---The first returned result is the signal name, following results correspond to what was pushed in pushSignal, for example. These vary based on the event type. Generally it is more convenient to use event.pull from the event library. The return value is the very same, but the event library provides some more options.
|
||||
---@param timeout? number
|
||||
---@return string signalName, any ...
|
||||
function computer.pullSignal(timeout)
|
||||
end
|
||||
|
||||
---if frequency is a number it value must be between 20 and 2000.\
|
||||
---Causes the computer to produce a beep sound at frequency Hz for duration seconds. This method is overloaded taking a single string parameter as a pattern of dots . and dashes - for short and long beeps respectively.
|
||||
---@param frequency? number|string
|
||||
---@param duration? number
|
||||
function computer.beep(frequency, duration)
|
||||
end
|
||||
|
||||
---Returns a table of information about installed devices in the computer.
|
||||
---@return table
|
||||
function computer.getDeviceInfo()
|
||||
end
|
||||
|
||||
return computer
|
@@ -1,114 +0,0 @@
|
||||
---@diagnostic disable: redefined-local
|
||||
---@meta
|
||||
|
||||
---@class eventlib
|
||||
local event = {}
|
||||
|
||||
---Register a new event listener that should be called for events with the specified name.\
|
||||
---event - name of the signal to listen to.\
|
||||
---callback - the function to call if this signal is received. The function will receive the event name it was registered for as first parameter, then all remaining parameters as defined by the signal that caused the event.\
|
||||
---Returns: number, the event id which can be canceled via event.cancel, if the event was successfully registered, false if this function was already registered for this event type.
|
||||
---@param event string
|
||||
---@param callback function
|
||||
---@return number|boolean
|
||||
function event.listen(event, callback)
|
||||
end
|
||||
|
||||
---Unregister a previously registered event listener.\
|
||||
---event - name of the signal to unregister.\
|
||||
---callback - the function that was used to register for this event.\
|
||||
---Returns: true if the event was successfully unregistered, false if this function was not registered for this event type.\
|
||||
---Note: An event listeners may return false to unregister themselves, which is equivalent to calling event.ignore and passing the listener with the event name it was registered for.
|
||||
---@param event string
|
||||
---@param callback function
|
||||
---@return boolean
|
||||
function event.ignore(event, callback)
|
||||
end
|
||||
|
||||
---Cancels a timer previously created with event.timer.\
|
||||
---timerId - a timer ID as returned by event.timer.\
|
||||
---Returns: true if the timer was stopped, false if there was no timer with the specified ID.
|
||||
---@param timerId number
|
||||
---@return boolean
|
||||
function event.cancel(timerId)
|
||||
end
|
||||
|
||||
---Starts a new timer that will be called after the time specified in interval.\
|
||||
---interval - time in seconds between each invocation of the callback function. Can be a fraction like 0.05.\
|
||||
---callback - the function to call.\
|
||||
---times - how many times the function will be called. If omitted the function will be called once. Pass math.huge for infinite repeat.\
|
||||
---Returns: a timer ID that can be used to cancel the timer at any time.\
|
||||
---Note: the timer resolution can vary. If the computer is idle and enters sleep mode, it will only be woken in a game tick, so the time the callback is called may be up to 0.05 seconds off.
|
||||
---@param interval number
|
||||
---@param callback function
|
||||
---@param times? number
|
||||
---@return number
|
||||
function event.timer(interval, callback, times)
|
||||
end
|
||||
|
||||
---Pulls and returns the next available event from the queue, or waits until one becomes available.\
|
||||
---timeout - if passed the function will wait for a new event for this many seconds at maximum then returns nil if no event was queued during that time.\
|
||||
---name - an event pattern that will act as a filter. If given then only events that match this pattern will be returned. Can be nil in which case the event names will not be filtered. See string.match on how to use patterns.\
|
||||
---… - any number of parameters in the same order as defined by the signal that is expected. Those arguments will act as filters for the additional arguments returned by the signal. Direct equality is used to determine if the argument is equal to the given filter. Can be nil in which case this particular argument will not be filtered.\
|
||||
---Filter example:\
|
||||
---The touch signal (when a player clicks on a tier two or three screen) has the signature screenX: number, screenY: number, playerName: string\
|
||||
---To only pull clicks by player “Steve” you'd do:\
|
||||
---local _, x, y = event.pull("touch", nil, nil, "Steve")
|
||||
---@param timeout number
|
||||
---@param name string
|
||||
---@param ... any
|
||||
---@return string, any ...
|
||||
---@overload fun(name:string,...:any):string, ...:any
|
||||
function event.pull(timeout, name, ...)
|
||||
end
|
||||
|
||||
---(Since 1.5.9) Pulls and returns the next available event from the queue, or waits until one becomes available but allows filtering by specifying filter function. timeout - if passed the function will wait for a new event for this many seconds at maximum then returns nil if no event was queued during that time.\
|
||||
---filter - if passed the function will use it as a filtering function of events. Allows for advanced filtering.\
|
||||
---Example:
|
||||
---```lua
|
||||
---local allowedPlayers = {"Kubuxu", "Sangar", "Magik6k", "Vexatos"}
|
||||
---local function filter(name, ...)
|
||||
--- if name ~= "key_up" and name ~= "key_down" and name ~= "touch" then
|
||||
--- return false
|
||||
--- end
|
||||
--- local nick
|
||||
--- if name == "touch" then
|
||||
--- nick = select(3, ...)
|
||||
--- else
|
||||
--- nick = select(4, ...)
|
||||
--- end
|
||||
--- for _, allowed in ipairs(allowedPlayers) do
|
||||
--- if nick == allowed then
|
||||
--- return true
|
||||
--- end
|
||||
--- end
|
||||
--- return false
|
||||
---end
|
||||
---local e = {event.pullFiltered(filter)} -- We are pulling key_up, key_down and click events for unlimited amount of time. The filter will ensure that only events caused by players in allowedPlayers are pulled.
|
||||
---```
|
||||
---@param timeout number
|
||||
---@param filter? function
|
||||
---@return string, any ...
|
||||
---@overload fun(filer:function):string,...:any
|
||||
function event.pullFiltered(timeout, filter)
|
||||
end
|
||||
|
||||
---As its arguments pullMultiple accepts multiple event names to be pulled, allowing basic filtering of multiple events at once.
|
||||
---@param ... string
|
||||
---@return any ...
|
||||
function event.pullMultiple(...)
|
||||
end
|
||||
|
||||
---Global event callback error handler. If an event listener throws an error, we handle it in this function to avoid it bubbling into unrelated code (that only triggered the execution by calling event.pull). Per default, this logs errors into a file on the temporary file system.\
|
||||
---You can replace this function with your own if you want to handle event errors in a different way.
|
||||
---@param message any
|
||||
function event.onError(message)
|
||||
end
|
||||
|
||||
---This is only an alias to computer.pushSignal. This does not modify the arguments in any way. It seemed logical to add the alias to the event library because there is also an event.pull for signals.
|
||||
---@param name string
|
||||
---@param ... any
|
||||
function event.push(name, ...)
|
||||
end
|
||||
|
||||
return event
|
@@ -1,190 +0,0 @@
|
||||
---@meta
|
||||
|
||||
---@class filesystemlib
|
||||
local filesystem = {}
|
||||
|
||||
---Returns whether autorun is currently enabled. If this is true, newly mounted file systems will be checked for a file named autorun[.lua] in their root directory. If such a file exists, it is executed.
|
||||
---@return boolean
|
||||
function filesystem.isAutorunEnabled()
|
||||
end
|
||||
|
||||
---Sets whether autorun files should be ran on startup.
|
||||
---@param value boolean
|
||||
function filesystem.setAutorunEnabled(value)
|
||||
end
|
||||
|
||||
---Returns the canonical form of the specified path, i.e. a path containing no “indirections” such as . or ... For example, the paths /tmp/../bin/ls.lua and /bin/./ls.lua are equivalent, and their canonical form is /bin/ls.lua.\
|
||||
---Note that this function truncates relative paths to their topmost “known” directory. For example, ../bin/ls.lua becomes bin/ls.lua. It stays a relative path, however - mind the lack of a leading slash.
|
||||
---@param path string
|
||||
---@return string
|
||||
function filesystem.canonical(path)
|
||||
end
|
||||
|
||||
---Returns a table containing one entry for each canonical segment of the given path. Examples:\
|
||||
--- - filesystem.segments("foo/bar") → {"foo","bar"}\
|
||||
--- - filesystem.segments("foo/bar/../baz") → {"foo","baz"}\
|
||||
---@param path string
|
||||
---@return table
|
||||
function filesystem.segments(path)
|
||||
end
|
||||
|
||||
---Concatenates two or more paths. Note that all paths other than the first are treated as relative paths, even if they begin with a slash. The canonical form of the resulting concatenated path is returned, so fs.concat("a", "..") results in an empty string.
|
||||
---@param pathA string
|
||||
---@param pathB string
|
||||
---@param ... string
|
||||
---@return string
|
||||
function filesystem.concat(pathA, pathB, ...)
|
||||
end
|
||||
|
||||
---Returns the path component of a path to a file, i.e. everything before the last slash in the canonical form of the specified path.
|
||||
---@param path string
|
||||
---@return string
|
||||
function filesystem.path(path)
|
||||
end
|
||||
|
||||
---Returns the file name component of a path to a file, i.e. everything after the last slash in the canonical form of the specified path.
|
||||
---@param path string
|
||||
---@return string
|
||||
function filesystem.name(path)
|
||||
end
|
||||
|
||||
---Mounts a file system at the specified path. The first parameter can be either a file system component's proxy, its address or its label. The second is a path into the global directory tree. Returns true if the file system was successfully mounted, nil and an error message otherwise.
|
||||
---@param fs ComponentFilesystem|string
|
||||
---@param path string
|
||||
---@return string
|
||||
function filesystem.mount(fs, path)
|
||||
end
|
||||
|
||||
---This is similar to component.proxy, except that the specified string may also be a file system component's label. We check for the label first, if no file system has the specified label we fall back to component.proxy. Returns the proxy of the specified file system, or nil and an error message if no file system matching the specified filter was found.
|
||||
---@param filter string
|
||||
---@return table or nil, string
|
||||
function filesystem.proxy(filter)
|
||||
end
|
||||
|
||||
---Returns an iterator function over all currently mounted file system component's proxies and the paths at which they are mounted. This means the same proxy may appear multiple times, but with different mount paths.
|
||||
---@return function -> table, string
|
||||
function filesystem.mounts()
|
||||
end
|
||||
|
||||
---Unmounts a file system. The parameter can either be a file system component's proxy or (abbreviated) address, in which case all mount points of this file system will be removed, or a path into the global directory structure, in which case the file system mount containing that directory will be unmounted.
|
||||
---@param fsOrPath string|ComponentFilesystem
|
||||
---@return boolean
|
||||
function filesystem.umount(fsOrPath)
|
||||
end
|
||||
|
||||
---Checks if the object at the specified path is a symlink, if so returns the path to where it links (as of 1.3.3).
|
||||
---@param path string
|
||||
---@return boolean, string|nil
|
||||
function filesystem.isLink(path)
|
||||
end
|
||||
|
||||
---Creates a symbolic link to the specified target path at the specified path. This is a 'soft' link, i.e. it the target file does not actually have to exist at the time of creation, and the link will not be deleted if the target file is deleted. Symbolic links do not persist across reboots.
|
||||
---@param target string
|
||||
---@param linkpath string
|
||||
---@return boolean|nil, string
|
||||
function filesystem.link(target, linkpath)
|
||||
end
|
||||
|
||||
---Gets the file system component's proxy that contains the specified path. Returns the proxy and mount path, or nil and an error message.
|
||||
---@param path string
|
||||
---@return table, string or nil, string
|
||||
function filesystem.get(path)
|
||||
end
|
||||
|
||||
---Checks whether a file or folder exist at the specified path.
|
||||
---@param path string
|
||||
---@return boolean
|
||||
function filesystem.exists(path)
|
||||
end
|
||||
|
||||
---Gets the file size of the file at the specified location. Returns 0 if the path points to anything other than a file.
|
||||
---@param path string
|
||||
---@return number
|
||||
function filesystem.size(path)
|
||||
end
|
||||
|
||||
---Gets whether the path points to a directory. Returns false if not, either because the path points to a file, or file.exists(path) is false.
|
||||
---@param path string
|
||||
---@return boolean
|
||||
function filesystem.isDirectory(path)
|
||||
end
|
||||
|
||||
---Returns the real world unix timestamp of the last time the file at the specified path was modified. For directories this is usually the time of their creation.
|
||||
---@param path string
|
||||
---@return number
|
||||
function filesystem.lastModified(path)
|
||||
end
|
||||
|
||||
---Returns an iterator over all elements in the directory at the specified path. Returns nil and an error messages if the path is invalid or some other error occurred.\
|
||||
---Note that directories usually are postfixed with a slash, to allow identifying them without an additional call to fs.isDirectory.
|
||||
---@param path string
|
||||
---@return function -> string or nil, string
|
||||
function filesystem.list(path)
|
||||
end
|
||||
|
||||
---Creates a new directory at the specified path. Creates any parent directories that do not exist yet, if necessary. Returns true on success, nil and an error message otherwise.
|
||||
---@param path string
|
||||
---@return boolean|nil, string
|
||||
function filesystem.makeDirectory(path)
|
||||
end
|
||||
|
||||
---Deletes a file or folder. If the path specifies a folder, deletes all files and subdirectories in the folder, recursively. Return true on success, nil and an error message otherwise.
|
||||
---@param path string
|
||||
---@return boolean|nil, string
|
||||
function filesystem.remove(path)
|
||||
end
|
||||
|
||||
---Renames a file or folder. If the paths point to different file system components this will only work for files, because it actually perform a copy operation, followed by a deletion if the copy succeeds.\
|
||||
---Returns true on success, nil and an error message otherwise.
|
||||
---@param oldPath string
|
||||
---@param newPath string
|
||||
---@return boolean|nil, string
|
||||
function filesystem.rename(oldPath, newPath)
|
||||
end
|
||||
|
||||
---Copies a file to the specified location. The target path has to contain the target file name. Does not support folders.
|
||||
---@param fromPath string
|
||||
---@param toPath string
|
||||
---@return boolean|nil, string
|
||||
function filesystem.copy(fromPath, toPath)
|
||||
end
|
||||
|
||||
---@class FileHandler
|
||||
local file
|
||||
|
||||
---Opens a file at the specified path for reading or writing. If mode is not specified it defaults to “r”. Possible modes are: r, rb, w, wb, a and ab.\
|
||||
---Returns a file stream (see below) on success, nil and an error message otherwise.\
|
||||
---Note that you can only open a limited number of files per file system at the same time. Files will be automatically closed when the garbage collection kicks in, but it is generally a good idea to call close on the file stream when done with the file.\
|
||||
---Important*: it is generally recommended to use io.open instead of this function, to get a buffered wrapper for the file stream.\
|
||||
---When opening files directly via the file system API you will get a file stream, a table with four functions. These functions are thin wrappers to the file system proxy's callbacks, which also means that read/write operations are not buffered, and can therefore be slow when reading few bytes often. You'll usually want to use io.open instead.
|
||||
---@param path string
|
||||
---@param mode readmode
|
||||
---@return FileHandler|nil fileHandler, string|nil reason
|
||||
function filesystem.open(path, mode)
|
||||
end
|
||||
|
||||
---Closes the file stream, releasing the handle on the underlying file system.
|
||||
function file:close()
|
||||
end
|
||||
|
||||
---Tries to read the specified number of bytes from the file stream. Returns the read string, which may be shorter than the specified number. Returns nil when the end of the stream was reached. Returns nil and an error message if some error occurred.
|
||||
---@param n number
|
||||
---@return string|nil, string|nil reason
|
||||
function file:read(n)
|
||||
end
|
||||
|
||||
---Jumps to the specified position in the file stream, if possible. Only supported by file streams opened in read mode. The first parameter determines the relative location to seek from and can be cur for the current position, set for the beginning of the stream and end for the end of the stream. The second parameter is the offset by which to modify the position. Returns the new position or nil and an error message if some error occurred.\
|
||||
---The default value for the second parameter is 0, so f:seek("set") will reset the position to the start of the file, f:seek("cur") will return the current position in the file.
|
||||
---@param whence string
|
||||
---@param offset? number
|
||||
---@return number|nil, string|nil reason
|
||||
function file:seek(whence, offset)
|
||||
end
|
||||
|
||||
---Writes the specified data to the stream. Returns true on success, nil and an error message otherwise.
|
||||
---@param str any
|
||||
---@return boolean|nil, string|nil reason
|
||||
function file:write(str)
|
||||
end
|
||||
|
||||
return filesystem
|
@@ -1,110 +0,0 @@
|
||||
---@diagnostic disable: redundant-parameter
|
||||
---@meta
|
||||
|
||||
---@class iolib
|
||||
local io = {}
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
---Equivalent to file:close(). Without a file, closes the default output file.
|
||||
---@param file? file*
|
||||
---@return boolean? suc
|
||||
---@return ("exit"|"signal")? exitcode
|
||||
---@return integer? code:
|
||||
function io.close(file)
|
||||
end
|
||||
|
||||
---Equivalent to io.output():flush().
|
||||
function io.flush()
|
||||
end
|
||||
|
||||
---Opens the given file name in read mode and returns an iterator function that works like file:lines(···) over the opened file. When the iterator function detects the end of file, it returns nil (to finish the loop) and automatically closes the file.\
|
||||
---The call io.lines() (with no file name) is equivalent to io.input():lines(); that is, it iterates over the lines of the default input file. In this case it does not close the file when the loop ends.\
|
||||
---In case of errors this function raises the error, instead of returning an error code.
|
||||
---@param filename string
|
||||
---@param ... readmode
|
||||
---@return fun():any, ...unknown
|
||||
function io.lines(filename, ...)
|
||||
end
|
||||
|
||||
---This function opens a file, in the mode specified in the string mode. It returns a new file handle, or, in case of errors, nil plus an error message.\
|
||||
---The mode string can be any of the following:
|
||||
--- - "r": read mode (the default);
|
||||
--- - "w": write mode;
|
||||
--- - "a": append mode;
|
||||
--- - "r+": update mode, all previous data is preserved;
|
||||
--- - "w+": update mode, all previous data is erased;
|
||||
--- - "a+": append update mode, previous data is preserved, writing is only allowed at the end of file.
|
||||
---
|
||||
---The mode string can also have a 'b' at the end, which is needed in some systems to open the file in binary mode.
|
||||
---@param path string
|
||||
---@param mode readmode
|
||||
---@return file*? file, string? reason
|
||||
function io.open(path, mode)
|
||||
end
|
||||
|
||||
---Return the filestream for the given file descriptor of file path.\
|
||||
---If file is provided, the newly created steam will be given the file descriptor fd
|
||||
---@param fd number
|
||||
---@param file? string|table
|
||||
---@param mode? readmode
|
||||
---@return file*
|
||||
function io.stream(fd, file, mode)
|
||||
end
|
||||
|
||||
---When called with a file name, it opens the named file (in text mode), and sets its handle as the default input file. When called with a file handle, it simply sets this file handle as the default input file. When called without parameters, it returns the current default input file.\
|
||||
---In case of errors this function raises the error, instead of returning an error code.
|
||||
---@param file? file*|string
|
||||
---@return file*
|
||||
function io.input(file)
|
||||
end
|
||||
|
||||
---Similar to io.input, but operates over the default output file.
|
||||
---@param file? file*|string
|
||||
---@return file*
|
||||
function io.output(file)
|
||||
end
|
||||
|
||||
---Similar to io.input, but operates over the default error file.
|
||||
---@param file? file*|string
|
||||
---@return file*
|
||||
function io.error(file)
|
||||
end
|
||||
|
||||
---Starts program prog in a separated process and returns a file handle that you can use to read data from this program (if mode is "r", the default) or to write data to this program (if mode is "w").
|
||||
---@param prog string
|
||||
---@param mode? "r"|"w"
|
||||
---@param env? table
|
||||
function io.popen(prog, mode, env)
|
||||
end
|
||||
|
||||
---Equivalent to io.input():read(···).
|
||||
---@param ... readmode
|
||||
---@return any,....any
|
||||
function io.read(...)
|
||||
end
|
||||
|
||||
---Returns a handle for a temporary file. This file is opened in update mode and it is automatically removed when the program ends.
|
||||
---@return file*
|
||||
function io.tmpfile()
|
||||
end
|
||||
|
||||
---Checks whether obj is a valid file handle. Returns the string "file" if obj is an open file handle, "closed file" if obj is a closed file handle, or nil if obj is not a file handle.
|
||||
---@param object table
|
||||
---@return "file"|"closed file"|nil
|
||||
function io.type(object)
|
||||
end
|
||||
|
||||
---Equivalent to io.output():write(···).
|
||||
---@param ... string|number
|
||||
---@return file*?, string? errmsg
|
||||
function io.write(...)
|
||||
end
|
||||
|
||||
---@unknown
|
||||
function io.dup(fd)
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
return io
|
@@ -1,51 +0,0 @@
|
||||
---@meta
|
||||
|
||||
---@class oslib
|
||||
local os = {}
|
||||
|
||||
---Returns an approximation of the amount in seconds of CPU time used by the program.
|
||||
---@return number
|
||||
function os.clock()
|
||||
end
|
||||
|
||||
---Returns a string or a table containing date and time, formatted according to the given string format.\
|
||||
---If the time argument is present, this is the time to be formatted (see the os.time function for a description of this value). Otherwise, date formats the current time.\
|
||||
---If format starts with '!', then the date is formatted in Coordinated Universal Time. After this optional character, if format is the string "*t", then date returns a table with the following fields: year (four digits), month (1–12), day (1–31), hour (0–23), min (0–59), sec (0–61), wday (weekday, Sunday is 1), yday (day of the year), and isdst (daylight saving flag, a boolean). This last field may be absent if the information is not available.\
|
||||
---If format is not "*t", then date returns the date as a string, formatted according to the same rules as the ISO C function strftime.\
|
||||
---When called without arguments, date returns a reasonable date and time representation that depends on the host system and on the current locale (that is, os.date() is equivalent to os.date("%c")).\
|
||||
---On non-Posix systems, this function may be not thread safe because of its reliance on C function gmtime and C function localtime.
|
||||
---@param format? string
|
||||
---@param time? string | number
|
||||
---@return string | table
|
||||
function os.date(format, time)
|
||||
end
|
||||
|
||||
function os.execute()
|
||||
end
|
||||
|
||||
---@param code? any
|
||||
---@param close? any
|
||||
function os.exit(code, close)
|
||||
end
|
||||
|
||||
function os.setenv()
|
||||
end
|
||||
|
||||
function os.remove()
|
||||
end
|
||||
|
||||
function os.rename()
|
||||
end
|
||||
|
||||
function os.time()
|
||||
end
|
||||
|
||||
function os.tmpname()
|
||||
end
|
||||
|
||||
---Sleep for x seconds
|
||||
---@param time? number
|
||||
function os.sleep(time)
|
||||
end
|
||||
|
||||
return os
|
@@ -1,23 +0,0 @@
|
||||
---@meta
|
||||
---@class libserialization
|
||||
local serialization = {}
|
||||
|
||||
---Generates a string from an object that can be parsed again using serialization.unserialize. The generated output is Lua code. Supports basic types (nil, boolean, number, string) and tables without cycles (will error out when cycles are detected, unless in pretty print mode). Properly handles NaN values and infinity.\
|
||||
---The pretty mode can be used to generate output for display to the user, this output will in most circumstances not be readable with serialization.unserialize.\
|
||||
---The value of pretty defines the number of entries that will be printed.\
|
||||
---If pretty is set to true it will by default print 10 entries.\
|
||||
---This function can be useful for sending messages via a network card.
|
||||
---@param value any
|
||||
---@param pretty? boolean|number
|
||||
---@return string
|
||||
function serialization.serialize(value, pretty)
|
||||
end
|
||||
|
||||
---Restores an object previously saved with serialization.serialize.\
|
||||
---Contents
|
||||
---@param value string
|
||||
---@return any
|
||||
function serialization.unserialize(value)
|
||||
end
|
||||
|
||||
return serialization
|
@@ -1,67 +0,0 @@
|
||||
---@meta
|
||||
---@class shellLib
|
||||
local shell = {}
|
||||
|
||||
---Gets the value of a specified alias, if any. If there is no such alias returns `nil`.
|
||||
---@param alias string
|
||||
---@return string
|
||||
function shell.getAlias(alias)
|
||||
end
|
||||
|
||||
---Defines a new alias or updates an existing one. Pass `nil` as the value to remove an alias. Note that aliases are not limited to program names, you can include parameters as well. For example, `view` is a default alias for `edit -r`.
|
||||
---@param alias string
|
||||
---@param value? string
|
||||
function shell.setAlias(alias, value)
|
||||
end
|
||||
|
||||
---Returns an iterator over all known aliases.
|
||||
---@return function
|
||||
function shell.aliases()
|
||||
end
|
||||
|
||||
---Gets the path to the current working directory. This is an alias for `os.getenv("PWD")`.
|
||||
---@return string
|
||||
function shell.getWorkingDirectory()
|
||||
end
|
||||
|
||||
---Sets the current working directory. This is a checked version of `os.setenv("PWD", dir)`.
|
||||
---@param dir string
|
||||
function shell.setWorkingDirectory(dir)
|
||||
end
|
||||
|
||||
---Gets the search path used by `shell.resolve`. This can contain multiple paths, separated by colons (`:`).\
|
||||
---This is an alias for `os.getenv("PATH")`.
|
||||
---@return string
|
||||
function shell.getPath()
|
||||
end
|
||||
|
||||
---Sets the search path. Note that this will replace the previous search paths. To add a new path to the search paths, do this:\
|
||||
---`shell.setPath(shell.getPath() .. ":/some/path")`\
|
||||
---This is an alias for `os.setenv("PATH", value)`.
|
||||
---@param value string
|
||||
function shell.setPath(value)
|
||||
end
|
||||
|
||||
---Tries to “resolve” a path, optionally also checking for files with the specified extension, in which case `path` would only contain the name. This first searches the working directory, then all entries in the search path (see `getPath`/`setPath`).\
|
||||
---If no file with the exact specified name exists and an extension is provided, it will also check for a file with that name plus the specified extension, i.e. for path .. "." .. ext.
|
||||
---@param path string
|
||||
---@param ext? string
|
||||
---@return string
|
||||
function shell.resolve(path, ext)
|
||||
end
|
||||
|
||||
---Runs the specified command. This runs the default shell (see `os.getenv("SHELL")`) and passes the command to it. `env` is the environment table to use for the shell, and thus for the called program, in case you wish to sandbox it or avoid it cluttering the caller's namespace. Additional arguments are passed directly to the first program started based on the command, so you can pass non-string values to programs.\
|
||||
---Returns values similar to `pcall` and `coroutine.resume`: the first returned value is a boolean indicating success or error. In case of errors, the second returned value is a detailed error message. Otherwise the remaining returned values are the values that were returned by the specified program when it terminated.
|
||||
---@param command string
|
||||
---@param env? table
|
||||
---@param ... any
|
||||
---@return boolean, any ...
|
||||
function shell.execute(command, env, ...)
|
||||
end
|
||||
|
||||
---Utility methods intended for programs to parse their arguments. Will return two tables, the first one containing any “normal” parameters, the second containing “options”. Options are indicated by a leading `-`, and all options must only be a single character, since multiple characters following a single `-` will be interpreted as multiple options. Options specified with 2 dashes are not split and can have multiple letters. Also, 2-dash options can be given values by using an equal sign.
|
||||
---@return table args, table opts
|
||||
function shell.parse(...)
|
||||
end
|
||||
|
||||
return shell
|
@@ -1,42 +0,0 @@
|
||||
---@meta
|
||||
|
||||
---@alias side
|
||||
--- | 0 # "bottom",
|
||||
--- | 1 # "top",
|
||||
--- | 2 # "back",
|
||||
--- | 3 # "front",
|
||||
--- | 4 # "right",
|
||||
--- | 5 # "left",
|
||||
|
||||
---@class sideslib
|
||||
local sides = {
|
||||
[0] = "bottom",
|
||||
[1] = "top",
|
||||
[2] = "back",
|
||||
[3] = "front",
|
||||
[4] = "right",
|
||||
[5] = "left",
|
||||
[6] = "unknown",
|
||||
bottom = 0,
|
||||
top = 1,
|
||||
back = 2,
|
||||
front = 3,
|
||||
right = 4,
|
||||
left = 5,
|
||||
unknown = 6,
|
||||
down = 0,
|
||||
up = 1,
|
||||
north = 2,
|
||||
south = 3,
|
||||
west = 4,
|
||||
east = 5,
|
||||
negy = 0,
|
||||
posy = 1,
|
||||
negz = 2,
|
||||
posz = 3,
|
||||
negx = 4,
|
||||
posx = 5,
|
||||
forward = 3
|
||||
}
|
||||
|
||||
return sides
|
@@ -1,103 +0,0 @@
|
||||
---@meta
|
||||
|
||||
---@termLib
|
||||
local term = {}
|
||||
|
||||
---Returns whether the term API is available for use, i.e. whether a primary GPU and screen are present. In other words, whether term.read and term.write will actually do something.
|
||||
---@return boolean
|
||||
function term.isAvailable()
|
||||
end
|
||||
|
||||
---(new in OpenOS 1.6)\
|
||||
---Gets the width, height, x offset, y offset, relative x, and relative y values.
|
||||
---@return number, number, number, number, number, number
|
||||
function term.getViewport()
|
||||
end
|
||||
|
||||
---(new in OpenOS 1.6)\
|
||||
---Gets the gpu proxy used by the term api.
|
||||
---@return table
|
||||
function term.gpu()
|
||||
end
|
||||
|
||||
---(new in OpenOS 1.6)\
|
||||
---Acts exactly like event.pull taking the same parameters and returning the same results. This method is used to blink the cursor while waiting for an event result.
|
||||
---@param ...? any
|
||||
---@return any ...
|
||||
function term.pull(...)
|
||||
end
|
||||
|
||||
---Gets the current position of the cursor.
|
||||
---@return number, number
|
||||
function term.getCursor()
|
||||
end
|
||||
|
||||
---Sets the cursor position to the specified coordinates.
|
||||
---@param col number
|
||||
---@param row number
|
||||
function term.setCursor(col, row)
|
||||
end
|
||||
|
||||
---Gets whether the cursor blink is currently enabled, i.e whether the cursor alternates between the actual “pixel” displayed at the cursor position and a fully white block every half second.
|
||||
---@return boolean
|
||||
function term.getCursorBlink()
|
||||
end
|
||||
|
||||
---Sets whether cursor blink should be enabled or not.
|
||||
---@param enabled boolean
|
||||
function term.setCursorBlink(enabled)
|
||||
end
|
||||
|
||||
---Clears the complete screen and resets the cursor position to (1, 1).\
|
||||
function term.clear()
|
||||
end
|
||||
|
||||
---Clears the line the cursor is currently on and resets the cursor's horizontal position to 1.\
|
||||
function term.clearLine()
|
||||
end
|
||||
|
||||
---Read some text from the terminal, i.e. allow the user to input some text. For example, this is used by the shell and Lua interpreter to read user input. This will make the rest of the current line, starting at the current cursor position, an editable area. It allows input, deletion and navigating to the left and right via the arrow keys and home/end keys.\
|
||||
---since OpenOS 1.6 the parameter list as specified here is considered deprecated. The first parameter is an options argument. The indexed array values are treated as history, named keys take the place of legacy arguments. For compatibility, OpenOS 1.6 will respect the previous usage, i.e. parameter list.\
|
||||
---The new ops parameter supports a new key, nowrap. The default behavior of term.read wrap the cursor and input vertically. Legacy behavior scrolled the input horizontally, i.e. term.read({nowrap=true})\
|
||||
---The optional history table can be used to provide predefined text that can be cycled through via the up and down arrow keys. It must be a sequence (i.e. the keys must be a gap-less integral interval starting at 1). This is used for the command history in shell and Lua interpreter, for example. If text is entered and confirmed with enter, it will be added to the end of this table.\
|
||||
---The dobreak parameter, when set to false (nil defaults to true!) will not enter a new line after input was completed (e.g. by the user pressing enter).\
|
||||
---The hint parameter is used for tab completion. It can either be a table with strings or a function that returns a table of strings and takes two parameters, the current text and the position in that text, i.e. the signature of the callback is function(line:string, pos:number):table.\
|
||||
---The pwchar parameter, when given, causes input to be masked using the first char of the given string. For example, providing "*" will make all entered characters appear as stars. The returned value will still be the actual text inserted, of course.\
|
||||
---The function will return a string if input was successful, nil if the pipe was closed (^d), or false if the pipe was interrupted (^c)\
|
||||
---Note: io.stdin:read() uses this function.\
|
||||
---Note 2: This will return the entered string with the \n (new line character). If you want only the entered string to be returned, use io.read().
|
||||
---@param history? table
|
||||
---@param dobreak? boolean
|
||||
---@param hint? table|function
|
||||
---@param pwchar? string
|
||||
---@return string
|
||||
---@overload fun(options:table):string
|
||||
function term.read(history, dobreak, hint, pwchar)
|
||||
end
|
||||
|
||||
---Allows writing optionally wrapped text to the terminal starting at the current cursor position, updating the cursor accordingly. It automatically converts tab characters to spaces using text.detab. If wrap is true, it will automatically word-wrap the text. It will scroll the displayed buffer if the cursor exceeds the bottom of the display area, but not if it exceeds the right of the display area (when wrap is false).\
|
||||
---Note: This method respects io redirection. That is to say, term.write writes to the same stream as io.stdout
|
||||
---@param value string
|
||||
---@param wrap? boolean
|
||||
function term.write(value, wrap)
|
||||
end
|
||||
|
||||
---(new in OpenOS 1.6)\
|
||||
---Binds a gpu proxy (not address) to the terminal. This method is called automatically during boot when the gpu and screen become available. Note that if manually rebinding a terminal to a screen with different width and height, the terminal draw area will be truncated and not maximized. This changes the gpu used in all terminal output, not just via the term api, i.e. io.write, print, io.stdout:write, etc all use the same output stream, and term.bind is used to change the gpu used.
|
||||
---@param gpu ComponentGPU
|
||||
function term.bind(gpu)
|
||||
end
|
||||
|
||||
---(new in OpenOS 1.6)\
|
||||
---Convenience method, simply calls getScreen on the terminal's bound gpu (see term.bind)
|
||||
---@return string
|
||||
function term.screen()
|
||||
end
|
||||
|
||||
---(new in OpenOS 1.6)\
|
||||
---Gets the address of the keyboard the terminal is accepting key events from.
|
||||
---@return string
|
||||
function term.keyboard()
|
||||
end
|
||||
|
||||
return term
|
@@ -1,94 +0,0 @@
|
||||
---@meta
|
||||
|
||||
---@class libtext
|
||||
local text = {}
|
||||
|
||||
text.syntax = {"^%d?>>?&%d+", "^%d?>>?", ">>?", "<%&%d+", "<", ";", "&&", "||?"}
|
||||
|
||||
---trim whitespace
|
||||
---@param value string
|
||||
---@return string
|
||||
function text.trim(value)
|
||||
end
|
||||
|
||||
--- used by lib/sh
|
||||
---Escape magic char like %s
|
||||
---@param txt string
|
||||
---@return string string, number count
|
||||
function text.escapeMagic(txt)
|
||||
end
|
||||
|
||||
---undo escaped char
|
||||
---@param txt string
|
||||
---@return string string, number count
|
||||
function text.removeEscapes(txt)
|
||||
end
|
||||
|
||||
---separate string value into an array of words delimited by whitespace\
|
||||
---groups by quotes\
|
||||
---options is a table used for internal undocumented purposes
|
||||
---@param value string
|
||||
---@param options table
|
||||
---@return table
|
||||
function text.tokenize(value, options)
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
---like tokenize, but does not drop any text such as whitespace
|
||||
---splits input into an array for sub strings delimited by delimiters
|
||||
---delimiters are included in the result if not dropDelims
|
||||
---@param input string
|
||||
---@param delimiters string
|
||||
---@param dropDelims? boolean
|
||||
---@param di? number
|
||||
---@return table
|
||||
function text.split(input, delimiters, dropDelims, di)
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
---replace tabs `\t` with spaces
|
||||
---@param value string
|
||||
---@param tabWidth? number default 8
|
||||
---@return string
|
||||
function text.detab(value, tabWidth)
|
||||
end
|
||||
|
||||
---add spaces to the left to fit specified length
|
||||
---@param value? string
|
||||
---@param length number
|
||||
---@return string
|
||||
function text.padLeft(value, length)
|
||||
end
|
||||
|
||||
---add spaces to the right to fit specified length
|
||||
---@param value? string
|
||||
---@param length number
|
||||
---@return string
|
||||
function text.padRight(value, length)
|
||||
end
|
||||
|
||||
---Wrap the string over multipes line of prefered widht and maxWidth
|
||||
---@param value string
|
||||
---@param width number
|
||||
---@param maxWidth number
|
||||
---@return string line,string value, boolean end
|
||||
function text.wrap(value, width, maxWidth)
|
||||
end
|
||||
|
||||
---Iterator over the wrapped lines
|
||||
---@param value string
|
||||
---@param width number
|
||||
---@param maxWidth number
|
||||
---@return function
|
||||
function text.wrappedLines(value, width, maxWidth)
|
||||
local line
|
||||
return function()
|
||||
if value then
|
||||
line, value = text.wrap(value, width, maxWidth)
|
||||
return line
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return text
|
@@ -1,66 +0,0 @@
|
||||
---@meta
|
||||
|
||||
---@class threadapi
|
||||
local thread = {}
|
||||
|
||||
---Starts a new thread executing the function `thread_proc` and returns its thread handle, see Thread Handle API. This method takes an optional `...` which is passed to `thread_proc`. The runtime of the thread continues autonomously.
|
||||
---@param thread_proc function
|
||||
---@param ... any
|
||||
---@return thread
|
||||
function thread.create(thread_proc, ...)
|
||||
end
|
||||
|
||||
---Waits for the array of `threads` to complete. This blocking call can return in `timeout` seconds if provided. Returns success and an error message on failure. A thread is “completed” under multiple conditions, see `t:join()` for details.
|
||||
---@param threads table<thread>
|
||||
---@param timeout? number
|
||||
function thread.waitForAll(threads, timeout)
|
||||
end
|
||||
|
||||
--Returns the current thread `t` object. The init process does not represent a thread and nothing is returned from this method if called from the init process and not inside any thread.
|
||||
---@return thread? t
|
||||
function thread.current()
|
||||
end
|
||||
|
||||
---@class thread
|
||||
local t = {}
|
||||
|
||||
|
||||
---Resumes (or thaws) a suspended thread. Returns success and an error message on failure. A thread begins its life already in a running state and thus basic thread workflows will not ever need to call `t:resume()`. A “running” thread will autonomously continue until it completes. `t:resume()` is only necessary to resume a thread that has been suspended(`t:suspend()`). Note that because you are not directly resuming the thread any exceptions thrown from the thread are absorbed by the threading library and not exposed to your process.\
|
||||
--- - At this time there is no way to hook in an exception handler for threads but for now `event.onError` is used to print the error message to “/tmp/event.log”. Please note that currently the hard interrupt exception is only thrown once, and the behavior of a process with threads when a hard interrupt is thrown is unspecified. At this time, any one of the threads or the parent process may take the exception. These details are not part of the specification for threads and any part of this implementation detail may change later.
|
||||
---@return boolean,string
|
||||
function t:resume()
|
||||
end
|
||||
|
||||
---Suspends (or freezes) a running thread. Returns success and an error message on failure. A “suspended” thread never autonomously wakes up and dies as soon as its parent process (if attached) closes. A suspended thread ignores events. That means any event listeners or timers created inside the thread will not respond to event notifications. Note that threads do not buffer event signals and a suspended thread may miss event signals it was waiting for. For example, if a thread was last waiting on `event.pull("modem_message")` and is “suspended” and a “modem_message” is received by the computer then the thread will miss the event and never know it happened. Please note that if you suspend a thread that is blocked waiting for an event, it is unspecified which event the thread will receive when it is next resumed.\
|
||||
---Suspending the current thread causes the thread to immediately yield and does not resume until `t:resume()` is called explicitly elsewhere.
|
||||
---@return boolean,string
|
||||
function t:suspend()
|
||||
end
|
||||
|
||||
---Stabby stab! Kills the thread dead. The thread is terminated and will not continue its thread function. Any event registrations it made will die with it. Keep in mind that the core underlying Lua type is a coroutine which is not a preemptive thread. Thus, the thread's stopping points are deterministic, meaning that you can predict exactly where the thread will stop.
|
||||
function t:kill()
|
||||
end
|
||||
|
||||
--- Returns the thread status as a string.\
|
||||
--- - “running”\
|
||||
--- A running thread will continue (autonomously reactivating) after yields and blocking calls until its thread function exits. This is the default and initial state of a created thread. A thread remains in the “running” state even when blocked or not active. A running thread can be suspended(`t:suspend()`) or killed (`t:kill()`) but not resumed(`t:resume()`). A running thread will block calls to `t:join()` and block its parent from closing. Unlike a coroutine which appears “suspended” when not executing in this very moment, a thread state remains “running” even when waiting for an event.\
|
||||
--- - “suspended”\
|
||||
--- A suspended thread will remain suspended and never self resume execution of its thread function. A suspended thread is automatically killed when its attached parent closes or when you attempt to `t:join()` it. A suspended thread ignores event signals, and any event registrations made from the context of the thread, or any child threads created therein, also ignore any event signals. A suspended thread's children behave as if suspended even if their status is “running”. A suspended thread can be resumed(`t:resume()`) or killed (`t:kill()`) but not suspended(`t:suspend()`).\
|
||||
--- - “dead”\
|
||||
--- A dead thread has completed or aborted its execution or has been terminated. It cannot be resumed(`t:resume()`) nor suspended(`t:suspend()`). A dead thread does not block a parent process from closing. Killing a dead thread is not an error but does nothing.
|
||||
---@return "running"|"suspended"|"dead"
|
||||
function t:status()
|
||||
end
|
||||
|
||||
---Attaches a thread to a process, conventionally known as a child thread or attached thread. `level` is an optional used to get parent processes, 0 or nil uses the currently running process. When initially created a thread is already attached to the current process. This method returns nil and an error message if `level` refers to a nonexistent process, otherwise it returns truthy. An attached thread blocks its parent process from closing until the thread dies (or is killed, or the parent process aborts).
|
||||
---@param level? number
|
||||
---@return boolean,string
|
||||
function t:attach(level)
|
||||
end
|
||||
|
||||
---Detaches a thread from its parent if it has one. Returns nil and an error message if no action was taken, otherwise returns self (handy if you want to create and detach a thread in one line). A detached thread will continue to run until the computer is shutdown or rebooted, or the thread dies.
|
||||
---@return thread,string
|
||||
function t:detach()
|
||||
end
|
||||
|
||||
return thread
|
Reference in New Issue
Block a user