1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-22 05:03:22 +00:00

Add the rest of the feature introduction versions to the docs (#908)

This commit is contained in:
JackMacWindows 2021-08-26 03:02:58 -04:00 committed by GitHub
parent 7cac8401e8
commit 340ade170f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
43 changed files with 257 additions and 1 deletions

View File

@ -12,6 +12,7 @@
-- @treturn boolean If the path is mounted, rather than a normal file/folder.
-- @throws If the path does not exist.
-- @see getDrive
-- @since 1.87.0
function isDriveRoot(path) end
--[[- Provides completion for a file or directory name, suitable for use with
@ -30,5 +31,6 @@ included in the returned list.
@tparam[opt] boolean include_dirs When @{false}, "raw" directories will not be
included in the returned list.
@treturn { string... } A list of possible completion candidates.
@since 1.74
]]
function complete(path, location, include_files, include_dirs) end

View File

@ -2,6 +2,7 @@
-- receiving data from them.
--
-- @module http
-- @since 1.1
--- Asynchronously make a HTTP request to the given url.
--
@ -35,6 +36,11 @@
--
-- @see http.get For a synchronous way to make GET requests.
-- @see http.post For a synchronous way to make POST requests.
--
-- @changed 1.63 Added argument for headers.
-- @changed 1.80pr1 Added argument for binary handles.
-- @changed 1.80pr1.6 Added support for table argument.
-- @changed 1.86.0 Added PATCH and TRACE methods.
function request(...) end
--- Make a HTTP GET request to the given url.
@ -58,6 +64,12 @@ function request(...) end
-- @treturn string A message detailing why the request failed.
-- @treturn Response|nil The failing http response, if available.
--
-- @changed 1.63 Added argument for headers.
-- @changed 1.80pr1 Response handles are now returned on error if available.
-- @changed 1.80pr1 Added argument for binary handles.
-- @changed 1.80pr1.6 Added support for table argument.
-- @changed 1.86.0 Added PATCH and TRACE methods.
--
-- @usage Make a request to [example.tweaked.cc](https://example.tweaked.cc),
-- and print the returned page.
-- ```lua
@ -89,6 +101,13 @@ function get(...) end
-- error or connection timeout.
-- @treturn string A message detailing why the request failed.
-- @treturn Response|nil The failing http response, if available.
--
-- @since 1.31
-- @changed 1.63 Added argument for headers.
-- @changed 1.80pr1 Response handles are now returned on error if available.
-- @changed 1.80pr1 Added argument for binary handles.
-- @changed 1.80pr1.6 Added support for table argument.
-- @changed 1.86.0 Added PATCH and TRACE methods.
function post(...) end
--- Asynchronously determine whether a URL can be requested.
@ -142,6 +161,9 @@ function checkURL(url) end
-- @treturn Websocket The websocket connection.
-- @treturn[2] false If the websocket connection failed.
-- @treturn string An error message describing why the connection failed.
-- @since 1.80pr1.1
-- @changed 1.80pr1.3 No longer asynchronous.
-- @changed 1.95.3 Added User-Agent to default headers.
function websocket(url, headers) end
--- Asynchronously open a websocket.
@ -154,4 +176,6 @@ function websocket(url, headers) end
-- `ws://` or `wss://` protocol.
-- @tparam[opt] { [string] = string } headers Additional headers to send as part
-- of the initial websocket connection.
-- @since 1.80pr1.3
-- @changed 1.95.3 Added User-Agent to default headers.
function websocketAsync(url, headers) end

View File

@ -8,6 +8,7 @@ variables and functions exported by it will by available through the use of
@tparam string path The path of the API to load.
@treturn boolean Whether or not the API was successfully loaded.
@since 1.2
@deprecated When possible it's best to avoid using this function. It pollutes
the global table and can mask errors.
@ -21,6 +22,7 @@ function loadAPI(path) end
-- This effectively removes the specified table from `_G`.
--
-- @tparam string name The name of the API to unload.
-- @since 1.2
-- @deprecated See @{os.loadAPI} for why.
function unloadAPI(name) end
@ -58,6 +60,7 @@ event, printing the error "Terminated".
end
@see os.pullEventRaw To pull the terminate event.
@changed 1.3 Added filter argument.
]]
function pullEvent(filter) end

View File

@ -9,5 +9,6 @@ empty, including those outside the crafting "grid".
@treturn[1] true If crafting succeeds.
@treturn[2] false If crafting fails.
@treturn string A string describing why crafting failed.
@since 1.4
]]
function craft(limit) end

View File

@ -99,6 +99,7 @@ public final String[] list( String path ) throws LuaException
* @throws LuaException On argument errors.
* @cc.tparam string path The first part of the path. For example, a parent directory path.
* @cc.tparam string ... Additional parts of the path to combine.
* @cc.changed 1.95.0 Now supports multiple arguments.
* @cc.usage Combine several file paths together
* <pre>{@code
* fs.combine("/rom/programs", "../apis", "parallel.lua")
@ -126,6 +127,7 @@ public final String combine( IArguments arguments ) throws LuaException
*
* @param path The path to get the name from.
* @return The final part of the path (the file name).
* @cc.since 1.2
* @cc.usage Get the file name of {@code rom/startup.lua}
* <pre>{@code
* fs.getName("rom/startup.lua")
@ -143,6 +145,7 @@ public final String getName( String path )
*
* @param path The path to get the directory from.
* @return The path with the final part removed (the parent directory).
* @cc.since 1.63
* @cc.usage Get the directory name of {@code rom/startup.lua}
* <pre>{@code
* fs.getDir("rom/startup.lua")
@ -161,6 +164,7 @@ public final String getDir( String path )
* @param path The file to get the file size of.
* @return The size of the file, in bytes.
* @throws LuaException If the path doesn't exist.
* @cc.since 1.3
*/
@LuaFunction
public final long getSize( String path ) throws LuaException
@ -459,6 +463,7 @@ public final Object[] getDrive( String path ) throws LuaException
* @throws LuaException If the path doesn't exist.
* @see #getCapacity To get the capacity of this drive.
* @cc.treturn number|"unlimited" The amount of free space available, in bytes, or "unlimited".
* @cc.since 1.4
*/
@LuaFunction
public final Object getFreeSpace( String path ) throws LuaException
@ -485,6 +490,7 @@ public final Object getFreeSpace( String path ) throws LuaException
* @param path The wildcard-qualified path to search for.
* @return A list of paths that match the search string.
* @throws LuaException If the path doesn't exist.
* @cc.since 1.6
*/
@LuaFunction
public final String[] find( String path ) throws LuaException
@ -509,6 +515,7 @@ public final String[] find( String path ) throws LuaException
* @see #getFreeSpace To get the free space available on this drive.
* @cc.treturn number|nil This drive's capacity. This will be nil for "read-only" drives, such as the ROM or
* treasure disks.
* @cc.since 1.87.0
*/
@LuaFunction
public final Object getCapacity( String path ) throws LuaException
@ -539,6 +546,9 @@ public final Object getCapacity( String path ) throws LuaException
* @cc.treturn { size = number, isDir = boolean, isReadOnly = boolean, created = number, modified = number } The resulting attributes.
* @see #getSize If you only care about the file's size.
* @see #isDir If you only care whether a path is a directory or not.
* @cc.since 1.87.0
* @cc.changed 1.91.0 Renamed `modification` field to `modified`.
* @cc.changed 1.95.2 Added `isReadOnly` to attributes.
*/
@LuaFunction
public final Map<String, Object> attributes( String path ) throws LuaException

View File

@ -338,6 +338,7 @@ public final double clock()
* }</pre>
* @cc.since 1.2
* @cc.changed 1.80pr1 Add support for getting the local local and UTC time.
* @cc.changed 1.82.0 Arguments are now case insensitive.
* @cc.changed 1.83.0 {@link #time(IArguments)} now accepts table arguments and converts them to UNIX timestamps.
*/
@LuaFunction
@ -374,6 +375,7 @@ public final Object time( IArguments args ) throws LuaException
* @return The day depending on the selected locale.
* @throws LuaException If an invalid locale is passed.
* @cc.since 1.48
* @cc.changed 1.82.0 Arguments are now case insensitive.
*/
@LuaFunction
public final int day( Optional<String> args ) throws LuaException

View File

@ -47,6 +47,7 @@ public String[] getNames()
* @cc.treturn number The green channel, will be between 0 and 1.
* @cc.treturn number The blue channel, will be between 0 and 1.
* @see TermMethods#setPaletteColour(IArguments) To change the palette colour.
* @cc.since 1.81.0
*/
@LuaFunction( { "nativePaletteColour", "nativePaletteColor" } )
public final Object[] nativePaletteColour( int colour ) throws LuaException

View File

@ -112,6 +112,7 @@ public final void setCursorPos( int x, int y ) throws LuaException
*
* @return If the cursor is blinking.
* @throws LuaException (hidden) If the terminal cannot be found.
* @cc.since 1.80pr1.9
*/
@LuaFunction
public final boolean getCursorBlink() throws LuaException
@ -179,6 +180,7 @@ public final void clearLine() throws LuaException
* @return The current text colour.
* @throws LuaException (hidden) If the terminal cannot be found.
* @cc.see colors For a list of colour constants, returned by this function.
* @cc.since 1.74
*/
@LuaFunction( { "getTextColour", "getTextColor" } )
public final int getTextColour() throws LuaException
@ -192,6 +194,8 @@ public final int getTextColour() throws LuaException
* @param colourArg The new text colour.
* @throws LuaException (hidden) If the terminal cannot be found.
* @cc.see colors For a list of colour constants.
* @cc.since 1.45
* @cc.changed 1.80pr1 Standard computers can now use all 16 colors, being changed to grayscale on screen.
*/
@LuaFunction( { "setTextColour", "setTextColor" } )
public final void setTextColour( int colourArg ) throws LuaException
@ -211,6 +215,7 @@ public final void setTextColour( int colourArg ) throws LuaException
* @return The current background colour.
* @throws LuaException (hidden) If the terminal cannot be found.
* @cc.see colors For a list of colour constants, returned by this function.
* @cc.since 1.74
*/
@LuaFunction( { "getBackgroundColour", "getBackgroundColor" } )
public final int getBackgroundColour() throws LuaException
@ -225,6 +230,8 @@ public final int getBackgroundColour() throws LuaException
* @param colourArg The new background colour.
* @throws LuaException (hidden) If the terminal cannot be found.
* @cc.see colors For a list of colour constants.
* @cc.since 1.45
* @cc.changed 1.80pr1 Standard computers can now use all 16 colors, being changed to grayscale on screen.
*/
@LuaFunction( { "setBackgroundColour", "setBackgroundColor" } )
public final void setBackgroundColour( int colourArg ) throws LuaException
@ -245,6 +252,7 @@ public final void setBackgroundColour( int colourArg ) throws LuaException
*
* @return Whether this terminal supports colour.
* @throws LuaException (hidden) If the terminal cannot be found.
* @cc.since 1.45
*/
@LuaFunction( { "isColour", "isColor" } )
public final boolean getIsColour() throws LuaException
@ -267,6 +275,8 @@ public final boolean getIsColour() throws LuaException
* @param backgroundColour The corresponding background colours.
* @throws LuaException If the three inputs are not the same length.
* @cc.see colors For a list of colour constants, and their hexadecimal values.
* @cc.since 1.74
* @cc.changed 1.80pr1 Standard computers can now use all 16 colors, being changed to grayscale on screen.
* @cc.usage Prints "Hello, world!" in rainbow text.
* <pre>{@code
* term.blit("Hello, world!","01234456789ab","0000000000000")
@ -319,6 +329,7 @@ public final void blit( String text, String textColour, String backgroundColour
* }</pre>
* @cc.see colors.unpackRGB To convert from the 24-bit format to three separate channels.
* @cc.see colors.packRGB To convert from three separate channels to the 24-bit format.
* @cc.since 1.80pr1
*/
@LuaFunction( { "setPaletteColour", "setPaletteColor" } )
public final void setPaletteColour( IArguments args ) throws LuaException
@ -348,6 +359,7 @@ public final void setPaletteColour( IArguments args ) throws LuaException
* @cc.treturn number The red channel, will be between 0 and 1.
* @cc.treturn number The green channel, will be between 0 and 1.
* @cc.treturn number The blue channel, will be between 0 and 1.
* @cc.since 1.80pr1
*/
@LuaFunction( { "getPaletteColour", "getPaletteColor" } )
public final Object[] getPaletteColour( int colourArg ) throws LuaException

View File

@ -61,6 +61,7 @@ public static BinaryReadableHandle of( ReadableByteChannel channel )
* @cc.treturn [1] nil If we are at the end of the file.
* @cc.treturn [2] number The value of the byte read. This is returned when the {@code count} is absent.
* @cc.treturn [3] string The bytes read as a string. This is returned when the {@code count} is given.
* @cc.changed 1.80pr1 Now accepts an integer argument to read multiple bytes, returning a string instead of a number.
*/
@LuaFunction
public final Object[] read( Optional<Integer> countArg ) throws LuaException
@ -145,6 +146,7 @@ public final Object[] read( Optional<Integer> countArg ) throws LuaException
* @return The file, or {@code null} if at the end of it.
* @throws LuaException If the file has been closed.
* @cc.treturn string|nil The remaining contents of the file, or {@code nil} if we are at the end.
* @cc.since 1.80pr1
*/
@LuaFunction
public final Object[] readAll() throws LuaException
@ -182,6 +184,8 @@ public final Object[] readAll() throws LuaException
* @return The read string.
* @throws LuaException If the file has been closed.
* @cc.treturn string|nil The read line or {@code nil} if at the end of the file.
* @cc.since 1.80pr1.9
* @cc.changed 1.81.0 `\r` is now stripped.
*/
@LuaFunction
public final Object[] readLine( Optional<Boolean> withTrailingArg ) throws LuaException
@ -259,6 +263,7 @@ public static class Seekable extends BinaryReadableHandle
* @cc.treturn [1] number The new position.
* @cc.treturn [2] nil If seeking failed.
* @cc.treturn string The reason seeking failed.
* @cc.since 1.80pr1.9
*/
@LuaFunction
public final Object[] seek( Optional<String> whence, Optional<Long> offset ) throws LuaException

View File

@ -55,6 +55,7 @@ public static BinaryWritableHandle of( WritableByteChannel channel )
* @throws LuaException If the file has been closed.
* @cc.tparam [1] number The byte to write.
* @cc.tparam [2] string The string to write.
* @cc.changed 1.80pr1 Now accepts a string to write multiple bytes.
*/
@LuaFunction
public final void write( IArguments arguments ) throws LuaException
@ -130,6 +131,7 @@ public Seekable( SeekableByteChannel seekable, TrackingCloseable closeable )
* @cc.treturn [1] number The new position.
* @cc.treturn [2] nil If seeking failed.
* @cc.treturn string The reason seeking failed.
* @cc.since 1.80pr1.9
*/
@LuaFunction
public final Object[] seek( Optional<String> whence, Optional<Long> offset ) throws LuaException

View File

@ -50,6 +50,7 @@ public EncodedReadableHandle( @Nonnull BufferedReader reader )
* @return The read string.
* @throws LuaException If the file has been closed.
* @cc.treturn string|nil The read line or {@code nil} if at the end of the file.
* @cc.changed 1.81.0 Added option to return trailing newline.
*/
@LuaFunction
public final Object[] readLine( Optional<Boolean> withTrailingArg ) throws LuaException
@ -116,6 +117,7 @@ public final Object[] readAll() throws LuaException
* @throws LuaException When trying to read a negative number of characters.
* @throws LuaException If the file has been closed.
* @cc.treturn string|nil The read characters, or {@code nil} if at the of the file.
* @cc.since 1.80pr1.4
*/
@LuaFunction
public final Object[] read( Optional<Integer> countA ) throws LuaException

View File

@ -46,6 +46,7 @@ public HttpResponseHandle( @Nonnull HandleGeneric reader, int responseCode, Stri
* @return The response code and message.
* @cc.treturn number The response code (i.e. 200)
* @cc.treturn string The response message (i.e. "OK")
* @cc.changed 1.80pr1.13 Added response message return value.
*/
@LuaFunction
public final Object[] getResponseCode()

View File

@ -55,6 +55,8 @@ public WebsocketHandle( Websocket websocket, Options options, Channel channel )
* @cc.treturn [1] string The received message.
* @cc.treturn boolean If this was a binary message.
* @cc.treturn [2] nil If the websocket was closed while waiting, or if we timed out.
* @cc.changed 1.80pr1.13 Added return value indicating whether the message was binary.
* @cc.changed 1.87.0 Added timeout argument.
*/
@LuaFunction
public final MethodResult receive( Optional<Double> timeout ) throws LuaException
@ -74,6 +76,7 @@ public final MethodResult receive( Optional<Double> timeout ) throws LuaExceptio
* @param binary Whether this message should be treated as a
* @throws LuaException If the message is too large.
* @throws LuaException If the websocket has been closed.
* @cc.changed 1.81.0 Added argument for binary mode.
*/
@LuaFunction
public final void send( Object message, Optional<Boolean> binary ) throws LuaException

View File

@ -25,6 +25,7 @@
/**
* @cc.module commands
* @cc.since 1.7
*/
public class CommandAPI implements ILuaAPI
{
@ -90,6 +91,8 @@ private Object[] doCommand( String command )
* @cc.treturn { string... } The output of this command, as a list of lines.
* @cc.treturn number|nil The number of "affected" objects, or `nil` if the command failed. The definition of this
* varies from command to command.
* @cc.changed 1.71 Added return value with command output.
* @cc.changed 1.85.0 Added return value with the number of affected objects.
* @cc.usage Set the block above the command computer to stone.
* <pre>{@code
* commands.exec("setblock ~ ~1 ~ minecraft:stone")
@ -193,6 +196,7 @@ public final Object[] getBlockPosition()
* @return A list of information about each block.
* @throws LuaException If the coordinates are not within the world.
* @throws LuaException If trying to get information about more than 4096 blocks.
* @cc.since 1.76
*/
@LuaFunction( mainThread = true )
public final List<Map<?, ?>> getBlockInfos( int minX, int minY, int minZ, int maxX, int maxY, int maxZ ) throws LuaException
@ -245,6 +249,7 @@ public final Object[] getBlockPosition()
* @param z The z position of the block to query.
* @return The given block's information.
* @throws LuaException If the coordinates are not within the world, or are not currently loaded.
* @cc.changed 1.76 Added block state info to return value
*/
@LuaFunction( mainThread = true )
public final Map<?, ?> getBlockInfo( int x, int y, int z ) throws LuaException

View File

@ -186,6 +186,7 @@ public final void ejectDisk()
*
* @return The ID of the disk in the drive, or {@code nil} if no disk with an ID is inserted.
* @cc.treturn number The The ID of the disk in the drive, or {@code nil} if no disk with an ID is inserted.
* @cc.since 1.4
*/
@LuaFunction
public final Object[] getDiskID()

View File

@ -187,6 +187,7 @@ public final MethodResult callRemote( IComputerAccess computer, ILuaContext cont
*
* @return The current computer's name.
* @cc.treturn string|nil The current computer's name on the wired network.
* @cc.since 1.80pr1.7
*/
@LuaFunction
public final Object[] getNameLocal()

View File

@ -71,6 +71,7 @@ public final void setTextScale( double scaleArg ) throws LuaException
*
* @return The monitor's current scale.
* @throws LuaException If the monitor cannot be found.
* @cc.since 1.81.0
*/
@LuaFunction
public final double getTextScale() throws LuaException

View File

@ -35,6 +35,7 @@
* Speakers allow playing notes and other sounds.
*
* @cc.module speaker
* @cc.since 1.80pr1
*/
public abstract class SpeakerPeripheral implements IPeripheral
{

View File

@ -29,6 +29,7 @@
* The turtle API allows you to control your turtle.
*
* @cc.module turtle
* @cc.since 1.3
*/
public class TurtleAPI implements ILuaAPI
{
@ -142,6 +143,7 @@ public final MethodResult turnRight()
* @return The turtle command result.
* @cc.treturn boolean Whether a block was broken.
* @cc.treturn string|nil The reason no block was broken.
* @cc.changed 1.6 Added optional side argument.
*/
@LuaFunction
public final MethodResult dig( Optional<TurtleSide> side )
@ -157,6 +159,7 @@ public final MethodResult dig( Optional<TurtleSide> side )
* @return The turtle command result.
* @cc.treturn boolean Whether a block was broken.
* @cc.treturn string|nil The reason no block was broken.
* @cc.changed 1.6 Added optional side argument.
*/
@LuaFunction
public final MethodResult digUp( Optional<TurtleSide> side )
@ -172,6 +175,7 @@ public final MethodResult digUp( Optional<TurtleSide> side )
* @return The turtle command result.
* @cc.treturn boolean Whether a block was broken.
* @cc.treturn string|nil The reason no block was broken.
* @cc.changed 1.6 Added optional side argument.
*/
@LuaFunction
public final MethodResult digDown( Optional<TurtleSide> side )
@ -192,6 +196,7 @@ public final MethodResult digDown( Optional<TurtleSide> side )
* @cc.tparam [opt] string text When placing a sign, set its contents to this text.
* @cc.treturn boolean Whether the block could be placed.
* @cc.treturn string|nil The reason the block was not placed.
* @cc.since 1.4
*/
@LuaFunction
public final MethodResult place( IArguments args )
@ -208,6 +213,7 @@ public final MethodResult place( IArguments args )
* @cc.treturn boolean Whether the block could be placed.
* @cc.treturn string|nil The reason the block was not placed.
* @see #place For more information about placing items.
* @cc.since 1.4
*/
@LuaFunction
public final MethodResult placeUp( IArguments args )
@ -224,6 +230,7 @@ public final MethodResult placeUp( IArguments args )
* @cc.treturn boolean Whether the block could be placed.
* @cc.treturn string|nil The reason the block was not placed.
* @see #place For more information about placing items.
* @cc.since 1.4
*/
@LuaFunction
public final MethodResult placeDown( IArguments args )
@ -241,6 +248,7 @@ public final MethodResult placeDown( IArguments args )
* @cc.treturn boolean Whether items were dropped.
* @cc.treturn string|nil The reason the no items were dropped.
* @see #select
* @cc.since 1.31
*/
@LuaFunction
public final MethodResult drop( Optional<Integer> count ) throws LuaException
@ -258,6 +266,7 @@ public final MethodResult drop( Optional<Integer> count ) throws LuaException
* @cc.treturn boolean Whether items were dropped.
* @cc.treturn string|nil The reason the no items were dropped.
* @see #select
* @cc.since 1.4
*/
@LuaFunction
public final MethodResult dropUp( Optional<Integer> count ) throws LuaException
@ -275,6 +284,7 @@ public final MethodResult dropUp( Optional<Integer> count ) throws LuaException
* @cc.treturn boolean Whether items were dropped.
* @cc.treturn string|nil The reason the no items were dropped.
* @see #select
* @cc.since 1.4
*/
@LuaFunction
public final MethodResult dropDown( Optional<Integer> count ) throws LuaException
@ -377,6 +387,7 @@ public final MethodResult detectDown()
*
* @return If the block and item are equal.
* @cc.treturn boolean If the block and item are equal.
* @cc.since 1.31
*/
@LuaFunction
public final MethodResult compare()
@ -389,6 +400,7 @@ public final MethodResult compare()
*
* @return If the block and item are equal.
* @cc.treturn boolean If the block and item are equal.
* @cc.since 1.31
*/
@LuaFunction
public final MethodResult compareUp()
@ -401,6 +413,7 @@ public final MethodResult compareUp()
*
* @return If the block and item are equal.
* @cc.treturn boolean If the block and item are equal.
* @cc.since 1.31
*/
@LuaFunction
public final MethodResult compareDown()
@ -415,6 +428,8 @@ public final MethodResult compareDown()
* @return The turtle command result.
* @cc.treturn boolean Whether an entity was attacked.
* @cc.treturn string|nil The reason nothing was attacked.
* @cc.since 1.4
* @cc.changed 1.6 Added optional side argument.
*/
@LuaFunction
public final MethodResult attack( Optional<TurtleSide> side )
@ -429,6 +444,8 @@ public final MethodResult attack( Optional<TurtleSide> side )
* @return The turtle command result.
* @cc.treturn boolean Whether an entity was attacked.
* @cc.treturn string|nil The reason nothing was attacked.
* @cc.since 1.4
* @cc.changed 1.6 Added optional side argument.
*/
@LuaFunction
public final MethodResult attackUp( Optional<TurtleSide> side )
@ -443,6 +460,8 @@ public final MethodResult attackUp( Optional<TurtleSide> side )
* @return The turtle command result.
* @cc.treturn boolean Whether an entity was attacked.
* @cc.treturn string|nil The reason nothing was attacked.
* @cc.since 1.4
* @cc.changed 1.6 Added optional side argument.
*/
@LuaFunction
public final MethodResult attackDown( Optional<TurtleSide> side )
@ -460,6 +479,8 @@ public final MethodResult attackDown( Optional<TurtleSide> side )
* @throws LuaException If given an invalid number of items.
* @cc.treturn boolean Whether items were picked up.
* @cc.treturn string|nil The reason the no items were picked up.
* @cc.since 1.4
* @cc.changed 1.6 Added an optional limit argument.
*/
@LuaFunction
public final MethodResult suck( Optional<Integer> count ) throws LuaException
@ -475,6 +496,8 @@ public final MethodResult suck( Optional<Integer> count ) throws LuaException
* @throws LuaException If given an invalid number of items.
* @cc.treturn boolean Whether items were picked up.
* @cc.treturn string|nil The reason the no items were picked up.
* @cc.since 1.4
* @cc.changed 1.6 Added an optional limit argument.
*/
@LuaFunction
public final MethodResult suckUp( Optional<Integer> count ) throws LuaException
@ -490,6 +513,8 @@ public final MethodResult suckUp( Optional<Integer> count ) throws LuaException
* @throws LuaException If given an invalid number of items.
* @cc.treturn boolean Whether items were picked up.
* @cc.treturn string|nil The reason the no items were picked up.
* @cc.since 1.4
* @cc.changed 1.6 Added an optional limit argument.
*/
@LuaFunction
public final MethodResult suckDown( Optional<Integer> count ) throws LuaException
@ -505,6 +530,7 @@ public final MethodResult suckDown( Optional<Integer> count ) throws LuaExceptio
* @cc.treturn [2] "unlimited" If turtles do not consume fuel when moving.
* @see #getFuelLimit()
* @see #refuel(Optional)
* @cc.since 1.4
*/
@LuaFunction
public final Object getFuelLevel()
@ -547,6 +573,7 @@ public final Object getFuelLevel()
* }</pre>
* @see #getFuelLevel()
* @see #getFuelLimit()
* @cc.since 1.4
*/
@LuaFunction
public final MethodResult refuel( Optional<Integer> countA ) throws LuaException
@ -563,6 +590,7 @@ public final MethodResult refuel( Optional<Integer> countA ) throws LuaException
* @return If the items are the same.
* @throws LuaException If the slot is out of range.
* @cc.treturn boolean If the two items are equal.
* @cc.since 1.4
*/
@LuaFunction
public final MethodResult compareTo( int slot ) throws LuaException
@ -579,6 +607,7 @@ public final MethodResult compareTo( int slot ) throws LuaException
* @throws LuaException If the slot is out of range.
* @throws LuaException If the number of items is out of range.
* @cc.treturn boolean If some items were successfully moved.
* @cc.since 1.45
*/
@LuaFunction
public final MethodResult transferTo( int slotArg, Optional<Integer> countArg ) throws LuaException
@ -593,6 +622,7 @@ public final MethodResult transferTo( int slotArg, Optional<Integer> countArg )
*
* @return The current slot.
* @see #select
* @cc.since 1.6
*/
@LuaFunction
public final int getSelectedSlot()
@ -610,6 +640,7 @@ public final int getSelectedSlot()
* @cc.treturn [2] "unlimited" If turtles do not consume fuel when moving.
* @see #getFuelLevel()
* @see #refuel(Optional)
* @cc.since 1.6
*/
@LuaFunction
public final Object getFuelLimit()
@ -628,6 +659,7 @@ public final Object getFuelLimit()
* @cc.treturn [1] true If the item was equipped.
* @cc.treturn [2] false If we could not equip the item.
* @cc.treturn [2] string The reason equipping this item failed.
* @cc.since 1.6
* @see #equipRight()
*/
@LuaFunction
@ -647,7 +679,8 @@ public final MethodResult equipLeft()
* @cc.treturn [1] true If the item was equipped.
* @cc.treturn [2] false If we could not equip the item.
* @cc.treturn [2] string The reason equipping this item failed.
* @see #equipRight()
* @cc.since 1.6
* @see #equipLeft()
*/
@LuaFunction
public final MethodResult equipRight()
@ -661,6 +694,8 @@ public final MethodResult equipRight()
* @return The turtle command result.
* @cc.treturn boolean Whether there is a block in front of the turtle.
* @cc.treturn table|string Information about the block in front, or a message explaining that there is no block.
* @cc.since 1.64
* @cc.changed 1.76 Added block state to return value.
* @cc.usage <pre>{@code
* local has_block, data = turtle.inspect()
* if has_block then
@ -686,6 +721,7 @@ public final MethodResult inspect()
* @return The turtle command result.
* @cc.treturn boolean Whether there is a block above the turtle.
* @cc.treturn table|string Information about the above below, or a message explaining that there is no block.
* @cc.since 1.64
*/
@LuaFunction
public final MethodResult inspectUp()
@ -699,6 +735,7 @@ public final MethodResult inspectUp()
* @return The turtle command result.
* @cc.treturn boolean Whether there is a block below the turtle.
* @cc.treturn table|string Information about the block below, or a message explaining that there is no block.
* @cc.since 1.64
*/
@LuaFunction
public final MethodResult inspectDown()
@ -716,6 +753,7 @@ public final MethodResult inspectDown()
* @return The command result.
* @throws LuaException If the slot is out of range.
* @cc.treturn nil|table Information about the given slot, or {@code nil} if it is empty.
* @cc.since 1.64
* @cc.usage Print the current slot, assuming it contains 13 dirt.
*
* <pre>{@code

View File

@ -204,6 +204,7 @@ black = 0x8000
--
-- @tparam number ... The colors to combine.
-- @treturn number The union of the color sets given in `...`
-- @since 1.2
-- @usage
-- ```lua
-- colors.combine(colors.white, colors.magenta, colours.lightBlue)
@ -229,6 +230,7 @@ end
-- @tparam number colors The color from which to subtract.
-- @tparam number ... The colors to subtract.
-- @treturn number The resulting color.
-- @since 1.2
-- @usage
-- ```lua
-- colours.subtract(colours.lime, colours.orange, colours.white)
@ -251,6 +253,7 @@ end
-- @tparam number colors A color, or color set
-- @tparam number color A color or set of colors that `colors` should contain.
-- @treturn boolean If `colors` contains all colors within `color`.
-- @since 1.2
-- @usage
-- ```lua
-- colors.test(colors.combine(colors.white, colors.magenta, colours.lightBlue), colors.lightBlue)
@ -273,6 +276,7 @@ end
-- colors.packRGB(0.7, 0.2, 0.6)
-- -- => 0xb23399
-- ```
-- @since 1.81.0
function packRGB(r, g, b)
expect(1, r, "number")
expect(2, g, "number")
@ -295,6 +299,7 @@ end
-- -- => 0.7, 0.2, 0.6
-- ```
-- @see colors.packRGB
-- @since 1.81.0
function unpackRGB(rgb)
expect(1, rgb, "number")
return
@ -325,6 +330,8 @@ end
-- colors.rgb8(0.7, 0.2, 0.6)
-- -- => 0xb23399
-- ```
-- @since 1.80pr1
-- @changed 1.81.0 Deprecated in favor of colors.(un)packRGB.
function rgb8(r, g, b)
if g == nil and b == nil then
return unpackRGB(r)
@ -345,6 +352,7 @@ end
--
-- @tparam number color The color to convert.
-- @treturn string The blit hex code of the color.
-- @since 1.94.0
function toBlit(color)
expect(1, color, "number")
return color_hex_lookup[color] or

View File

@ -2,6 +2,7 @@
--
-- @see colors
-- @module colours
-- @since 1.2
local colours = _ENV
for k, v in pairs(colors) do

View File

@ -10,6 +10,7 @@
-- like a disk.
--
-- @module disk
-- @since 1.2
local function isDrive(name)
if type(name) ~= "string" then
@ -163,6 +164,7 @@ end
--
-- @tparam string name The name of the disk drive.
-- @treturn string|nil The disk ID, or `nil` if the drive does not contain a floppy disk.
-- @since 1.4
function getID(name)
if isDrive(name) then
return peripheral.call(name, "getDiskID")

View File

@ -21,6 +21,7 @@
-- [1]: http://www.computercraft.info/forums2/index.php?/topic/3088-how-to-guide-gps-global-position-system/
--
-- @module gps
-- @since 1.31
local expect = dofile("rom/modules/main/cc/expect.lua").expect

View File

@ -1,6 +1,7 @@
--- Provides an API to read help files.
--
-- @module help
-- @since 1.2
local expect = dofile("rom/modules/main/cc/expect.lua").expect
@ -35,6 +36,8 @@ local extensions = { "", ".md", ".txt" }
-- @treturn string|nil The path to the given topic's help file, or `nil` if it
-- cannot be found.
-- @usage help.lookup("disk")
-- @changed 1.80pr1 Now supports finding .txt files.
-- @changed 1.97.0 Now supports finding Markdown files.
function lookup(topic)
expect(1, topic, "string")
-- Look on the path variable
@ -96,6 +99,7 @@ end
--
-- @tparam string prefix The prefix to match
-- @treturn table A list of matching topics.
-- @since 1.74
function completeTopic(sText)
expect(1, sText, "string")
local tTopics = topics()

View File

@ -65,6 +65,30 @@ handleMetatable = {
return true
end,
--[[- Returns an iterator that, each time it is called, returns a new
line from the file.
This can be used in a for loop to iterate over all lines of a file
Once the end of the file has been reached, @{nil} will be returned. The file is
*not* automatically closed.
@param ... The argument to pass to @{Handle:read} for each line.
@treturn function():string|nil The line iterator.
@throws If the file cannot be opened for reading
@since 1.3
@see io.lines
@usage Iterate over every line in a file and print it out.
```lua
local file = io.open("/rom/help/intro.txt")
for line in file:lines() do
print(line)
end
file:close()
```
]]
lines = function(self, ...)
if type_of(self) ~= "table" or getmetatable(self) ~= handleMetatable then
error("bad argument #1 (FILE expected, got " .. type_of(self) .. ")", 2)
@ -81,6 +105,23 @@ handleMetatable = {
end
end,
--[[- Reads data from the file, using the specified formats. For each
format provided, the function returns either the data read, or `nil` if
no data could be read.
The following formats are available:
- `l`: Returns the next line (without a newline on the end).
- `L`: Returns the next line (with a newline on the end).
- `a`: Returns the entire rest of the file.
- ~~`n`: Returns a number~~ (not implemented in CC).
These formats can be preceded by a `*` to make it compatible with Lua 5.1.
If no format is provided, `l` is assumed.
@param ... The formats to use.
@treturn (string|nil)... The data read from the file.
]]
read = function(self, ...)
if type_of(self) ~= "table" or getmetatable(self) ~= handleMetatable then
error("bad argument #1 (FILE expected, got " .. type_of(self) .. ")", 2)
@ -124,6 +165,23 @@ handleMetatable = {
return table.unpack(output, 1, n)
end,
--[[- Seeks the file cursor to the specified position, and returns the
new position.
`whence` controls where the seek operation starts, and is a string that
may be one of these three values:
- `set`: base position is 0 (beginning of the file)
- `cur`: base is current position
- `end`: base is end of file
The default value of `whence` is `cur`, and the default value of `offset`
is 0. This means that `file:seek()` without arguments returns the current
position without moving.
@tparam[opt] string whence The place to set the cursor from.
@tparam[opt] number offset The offset from the start to move to.
@treturn number The new location of the file cursor.
]]
seek = function(self, whence, offset)
if type_of(self) ~= "table" or getmetatable(self) ~= handleMetatable then
error("bad argument #1 (FILE expected, got " .. type_of(self) .. ")", 2)
@ -154,6 +212,7 @@ handleMetatable = {
-- @treturn[1] Handle The current file, allowing chained calls.
-- @treturn[2] nil If the file could not be written to.
-- @treturn[2] string The error message which occurred while writing.
-- @changed 1.81.0 Multiple arguments are now allowed.
write = function(self, ...)
if type_of(self) ~= "table" or getmetatable(self) ~= handleMetatable then
error("bad argument #1 (FILE expected, got " .. type_of(self) .. ")", 2)
@ -217,6 +276,7 @@ stderr = defaultError
--
-- @see Handle:close
-- @see io.output
-- @since 1.55
function close(file)
if file == nil then return currentOutput:close() end
@ -230,6 +290,7 @@ end
--
-- @see Handle:flush
-- @see io.output
-- @since 1.55
function flush()
return currentOutput:flush()
end
@ -239,6 +300,7 @@ end
-- @tparam[opt] Handle|string file The new input file, either as a file path or pre-existing handle.
-- @treturn Handle The current input file.
-- @throws If the provided filename cannot be opened for reading.
-- @since 1.55
function input(file)
if type_of(file) == "string" then
local res, err = open(file, "rb")
@ -271,6 +333,7 @@ In this case, the handle is not used.
@see Handle:lines
@see io.input
@since 1.55
@usage Iterate over every line in a file and print it out.
```lua
@ -326,6 +389,7 @@ end
-- @tparam[opt] Handle|string file The new output file, either as a file path or pre-existing handle.
-- @treturn Handle The current output file.
-- @throws If the provided filename cannot be opened for writing.
-- @since 1.55
function output(file)
if type_of(file) == "string" then
local res, err = open(file, "wb")
@ -374,6 +438,7 @@ end
-- documentation} there for full details.
--
-- @tparam string ... The strings to write
-- @changed 1.81.0 Multiple arguments are now allowed.
function write(...)
return currentOutput:write(...)
end

View File

@ -6,6 +6,7 @@
-- the underlying numerical values.
--
-- @module keys
-- @since 1.4
local expect = dofile("rom/modules/main/cc/expect.lua").expect

View File

@ -2,6 +2,7 @@
-- image files. You can use the `colors` API for easier color manipulation.
--
-- @module paintutils
-- @since 1.45
local expect = dofile("rom/modules/main/cc/expect.lua").expect
@ -47,6 +48,7 @@ end
-- @tparam string image The string containing the raw-image data.
-- @treturn table The parsed image data, suitable for use with
-- @{paintutils.drawImage}.
-- @since 1.80pr1
function parseImage(image)
expect(1, image, "string")
local tImage = {}

View File

@ -13,6 +13,7 @@ etc) can safely be used in one without affecting the event queue accessed by
the other.
@module parallel
@since 1.2
]]
local function create(...)

View File

@ -15,6 +15,7 @@
-- determine where given messages should be sent in the first place.
--
-- @module rednet
-- @since 1.2
local expect = dofile("rom/modules/main/cc/expect.lua").expect
@ -80,6 +81,7 @@ end
-- @tparam[opt] string modem Which modem to check. If not given, all connected
-- modems will be checked.
-- @treturn boolean If the given modem is open.
-- @since 1.31
function isOpen(modem)
expect(1, modem, "string", "nil")
if modem then
@ -114,6 +116,8 @@ particular protocol.
@treturn boolean If this message was successfully sent (i.e. if rednet is
currently @{rednet.open|open}). Note, this does not guarantee the message was
actually _received_.
@changed 1.6 Added protocol parameter.
@changed 1.82.0 Now returns whether the message was successfully sent.
@see rednet.receive
@usage Send a message to computer #2.
@ -166,6 +170,7 @@ end
-- using @{rednet.receive} one can filter to only receive messages sent under a
-- particular protocol.
-- @see rednet.receive
-- @changed 1.6 Added protocol parameter.
function broadcast(message, sProtocol)
expect(2, sProtocol, "string", "nil")
send(CHANNEL_BROADCAST, message, sProtocol)
@ -185,6 +190,7 @@ received.
@treturn[2] nil If the timeout elapsed and no message was received.
@see rednet.broadcast
@see rednet.send
@changed 1.6 Added protocol filter parameter.
@usage Receive a rednet message.
local id, message = rednet.receive()
@ -262,6 +268,7 @@ end
-- @throws If trying to register a hostname which is reserved, or currently in use.
-- @see rednet.unhost
-- @see rednet.lookup
-- @since 1.6
function host(sProtocol, sHostname)
expect(1, sProtocol, "string")
expect(2, sHostname, "string")
@ -280,6 +287,7 @@ end
-- respond to @{rednet.lookup} requests.
--
-- @tparam string sProtocol The protocol to unregister your self from.
-- @since 1.6
function unhost(sProtocol)
expect(1, sProtocol, "string")
tHostnames[sProtocol] = nil
@ -299,6 +307,7 @@ end
-- protocol, or @{nil} if none exist.
-- @treturn[2] number|nil The computer ID with the provided hostname and protocol,
-- or @{nil} if none exists.
-- @since 1.6
function lookup(sProtocol, sHostname)
expect(1, sProtocol, "string")
expect(2, sHostname, "string", "nil")

View File

@ -5,6 +5,7 @@
-- `/.settings` file. One can then use @{settings.save} to update the file.
--
-- @module settings
-- @since 1.78
local expect = dofile("rom/modules/main/cc/expect.lua")
local type, expect, field = type, expect.expect, expect.field
@ -40,6 +41,7 @@ for _, v in ipairs(valid_types) do valid_types[v] = true end
-- setting has not been changed.
-- - `type`: Require values to be of this type. @{set|Setting} the value to another type
-- will error.
-- @since 1.87.0
function define(name, options)
expect(1, name, "string")
expect(2, options, "table", "nil")
@ -67,6 +69,7 @@ end
-- for that.
--
-- @tparam string name The name of this option
-- @since 1.87.0
function undefine(name)
expect(1, name, "string")
details[name] = nil
@ -111,6 +114,7 @@ end
-- this setting. If not given, it will use the setting's default value if given,
-- or `nil` otherwise.
-- @return The setting's, or the default if the setting has not been changed.
-- @changed 1.87.0 Now respects default value if pre-defined and `default` is unset.
function get(name, default)
expect(1, name, "string")
local result = values[name]
@ -130,6 +134,7 @@ end
-- @treturn { description? = string, default? = any, type? = string, value? = any }
-- Information about this setting. This includes all information from @{settings.define},
-- as well as this setting's value.
-- @since 1.87.0
function getDetails(name)
expect(1, name, "string")
local deets = copy(details[name]) or {}
@ -189,6 +194,7 @@ end
-- corrupted.
--
-- @see settings.save
-- @changed 1.87.0 `sPath` is now optional.
function load(sPath)
expect(1, sPath, "string", "nil")
local file = fs.open(sPath or ".settings", "r")
@ -226,6 +232,7 @@ end
-- @treturn boolean If the settings were successfully saved.
--
-- @see settings.load
-- @changed 1.87.0 `sPath` is now optional.
function save(sPath)
expect(1, sPath, "string", "nil")
local file = fs.open(sPath or ".settings", "w")

View File

@ -31,6 +31,7 @@ local term = _ENV
-- @tparam Redirect target The terminal redirect the @{term} API will draw to.
-- @treturn Redirect The previous redirect object, as returned by
-- @{term.current}.
-- @since 1.31
-- @usage
-- Redirect to a monitor on the right of the computer.
-- term.redirect(peripheral.wrap("right"))
@ -56,6 +57,7 @@ end
--- Returns the current terminal object of the computer.
--
-- @treturn Redirect The current terminal redirect
-- @since 1.6
-- @usage
-- Create a new @{window} which draws to the current redirect target
-- window.create(term.current(), 1, 1, 10, 10)
@ -70,6 +72,7 @@ end
-- terminal object, and so drawing may interfere with other programs.
--
-- @treturn Redirect The native terminal redirect.
-- @since 1.6
term.native = function()
return native
end

View File

@ -2,6 +2,7 @@
-- manipulating strings.
--
-- @module textutils
-- @since 1.2
local expect = dofile("rom/modules/main/cc/expect.lua")
local expect, field = expect.expect, expect.field
@ -17,6 +18,7 @@ local wrap = dofile("rom/modules/main/cc/strings.lua").wrap
-- Defaults to 20.
-- @usage textutils.slowWrite("Hello, world!")
-- @usage textutils.slowWrite("Hello, world!", 5)
-- @since 1.3
function slowWrite(text, rate)
expect(2, rate, "number", "nil")
rate = rate or 20
@ -222,6 +224,7 @@ end
--
-- @tparam {string...}|number ... The rows and text colors to display.
-- @usage textutils.tabulate(colors.orange, { "1", "2", "3" }, colors.lightBlue, { "A", "B", "C" })
-- @since 1.3
function tabulate(...)
return tabulateCommon(false, ...)
end
@ -236,6 +239,7 @@ end
-- @usage textutils.tabulate(colors.orange, { "1", "2", "3" }, colors.lightBlue, { "A", "B", "C" })
-- @see textutils.tabulate
-- @see textutils.pagedPrint
-- @since 1.3
function pagedTabulate(...)
return tabulateCommon(true, ...)
end
@ -625,6 +629,7 @@ do
-- @return[1] The deserialised object
-- @treturn[2] nil If the object could not be deserialised.
-- @treturn string A message describing why the JSON string is invalid.
-- @since 1.87.0
unserialise_json = function(s, options)
expect(1, s, "string")
expect(2, options, "table", "nil")
@ -669,6 +674,8 @@ serialised. This includes functions and tables which appear multiple
times.
@see cc.pretty.pretty An alternative way to display a table, often more suitable for
pretty printing.
@since 1.3
@changed 1.97.0 Added `opts` argument.
@usage Pretty print a basic table.
textutils.serialise({ 1, 2, 3, a = 1, ["another key"] = { true } })
@ -702,6 +709,7 @@ serialise = serialize -- GB version
-- @tparam string s The serialised string to deserialise.
-- @return[1] The deserialised object
-- @treturn[2] nil If the object could not be deserialised.
-- @since 1.3
function unserialize(s)
expect(1, s, "string")
local func = load("return " .. s, "unserialize", "t", {})
@ -734,6 +742,7 @@ unserialise = unserialize -- GB version
-- serialised. This includes functions and tables which appear multiple
-- times.
-- @usage textutils.serializeJSON({ values = { 1, "2", true } })
-- @since 1.7
function serializeJSON(t, bNBTStyle)
expect(1, t, "table", "string", "number", "boolean")
expect(2, bNBTStyle, "boolean", "nil")
@ -751,6 +760,7 @@ unserialiseJSON = unserialise_json
-- @tparam string str The string to encode
-- @treturn string The encoded string.
-- @usage print("https://example.com/?view=" .. textutils.urlEncode("some text&things"))
-- @since 1.31
function urlEncode(str)
expect(1, str, "string")
if str then
@ -790,6 +800,7 @@ local tEmpty = {}
-- @see shell.setCompletionFunction
-- @see _G.read
-- @usage textutils.complete( "pa", _ENV )
-- @since 1.74
function complete(sSearchText, tSearchTable)
expect(1, sSearchText, "string")
expect(2, tSearchTable, "table", "nil")

View File

@ -5,6 +5,7 @@
-- [wiki]: http://en.wikipedia.org/wiki/Euclidean_vector
--
-- @module vector
-- @since 1.31
--- A 3-dimensional vector, with `x`, `y`, and `z` values.
--

View File

@ -26,6 +26,7 @@
-- terminal display as its parent, and only one of which is visible at a time.
--
-- @module window
-- @since 1.6
local expect = dofile("rom/modules/main/cc/expect.lua").expect

View File

@ -4,6 +4,7 @@
-- @module cc.completion
-- @see cc.shell.completion For additional helpers to use with
-- @{shell.setCompletionFunction}.
-- @since 1.85.0
local expect = require "cc.expect".expect

View File

@ -2,6 +2,8 @@
function arguments are well-formed and of the correct type.
@module cc.expect
@since 1.84.0
@changed 1.96.0 The module can now be called directly as a function, which wraps around `expect.expect`.
@usage Define a basic function and check it has the correct arguments.
local expect = require "cc.expect"
@ -97,6 +99,7 @@ end
-- @tparam number max The maximum value, if nil then `math.huge` is used.
-- @return The given `value`.
-- @throws If the value is outside of the allowed range.
-- @since 1.96.0
local function range(num, min, max)
expect(1, num, "number")
min = expect(2, min, "number", "nil") or -math.huge

View File

@ -5,6 +5,7 @@
-- text.
--
-- @module cc.image.nft
-- @since 1.90.0
-- @usage Load an image from `example.nft` and draw it.
--
-- local nft = require "cc.image.nft"

View File

@ -15,6 +15,7 @@ The structure of this module is based on [A Prettier Printer][prettier].
[prettier]: https://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf "A Prettier Printer"
@module cc.pretty
@since 1.87.0
@usage Print a table to the terminal
local pretty = require "cc.pretty"
@ -457,6 +458,7 @@ end
-- - `function_source`: Show where the function was defined, instead of
-- `function: xxxxxxxx` (`false` by default).
-- @treturn Doc The object formatted as a document.
-- @changed 1.88.0 Added `options` argument.
-- @usage Display a table on the screen
--
-- local pretty = require "cc.pretty"

View File

@ -6,6 +6,7 @@
-- custom shell or when running programs yourself.
--
-- @module cc.require
-- @since 1.88.0
-- @usage Construct the package and require function, and insert them into a
-- custom environment.
--

View File

@ -8,6 +8,7 @@ and so are not directly usable with the @{shell.setCompletionFunction}. Instead,
wrap them using @{build}, or your own custom function.
@module cc.shell.completion
@since 1.85.0
@see cc.completion For more general helpers, suitable for use with @{_G.read}.
@see shell.setCompletionFunction
@ -89,6 +90,7 @@ end
-- @tparam { string... } previous The shell arguments before this one.
-- @tparam number starting Which argument index this program and args start at.
-- @treturn { string... } A list of suffixes of matching programs or arguments.
-- @since 1.97.0
local function programWithArgs(shell, text, previous, starting)
if #previous + 1 == starting then
local tCompletionInfo = shell.getCompletionInfo()

View File

@ -1,6 +1,7 @@
--- Various utilities for working with strings and text.
--
-- @module cc.strings
-- @since 1.95.0
-- @see textutils For additional string related utilities.
local expect = (require and require("cc.expect") or dofile("rom/modules/main/cc/expect.lua")).expect

View File

@ -15,6 +15,7 @@
-- not available to @{os.loadAPI|APIs}.
--
-- @module[module] multishell
-- @since 1.6
local expect = dofile("rom/modules/main/cc/expect.lua").expect

View File

@ -56,6 +56,7 @@ end
-- @tparam string command The program to execute.
-- @tparam string ... Arguments to this program.
-- @treturn boolean Whether the program exited successfully.
-- @since 1.88.0
-- @usage Run `paint my-image` from within your program:
--
-- shell.execute("paint", "my-image")
@ -131,6 +132,8 @@ end
--
-- shell.run("paint", "my-image")
-- @see shell.execute Run a program directly without parsing the arguments.
-- @changed 1.80pr1 Programs now get their own environment instead of sharing the same one.
-- @changed 1.83.0 `arg` is now added to the environment.
function shell.run(...)
local tWords = tokenise(...)
local sCommand = tWords[1]
@ -193,6 +196,7 @@ end
-- for from the @{shell.dir|current directory}, rather than the computer's root.
--
-- @tparam string path The new program path.
-- @since 1.2
function shell.setPath(path)
expect(1, path, "string")
sPath = path
@ -235,6 +239,7 @@ end
-- @tparam string command The name of the program
-- @treturn string|nil The absolute path to the program, or @{nil} if it could
-- not be found.
-- @since 1.2
-- @usage Locate the `hello` program.
--
-- shell.resolveProgram("hello")
@ -283,6 +288,7 @@ end
-- start with `.`.
-- @treturn { string } A list of available programs.
-- @usage textutils.tabulate(shell.programs())
-- @since 1.2
function shell.programs(include_hidden)
expect(1, include_hidden, "boolean", "nil")
@ -387,6 +393,7 @@ end
-- @see shell.completeProgram
-- @see shell.setCompletionFunction
-- @see shell.getCompletionInfo
-- @since 1.74
function shell.complete(sLine)
expect(1, sLine, "string")
if #sLine > 0 then
@ -462,6 +469,7 @@ end
-- @see cc.shell.completion Various utilities to help with writing completion functions.
-- @see shell.complete
-- @see _G.read For more information about completion.
-- @since 1.74
function shell.setCompletionFunction(program, complete)
expect(1, program, "string")
expect(2, complete, "function")
@ -484,6 +492,7 @@ end
--- Returns the path to the currently running program.
--
-- @treturn string The absolute path to the running program.
-- @since 1.3
function shell.getRunningProgram()
if #tProgramStack > 0 then
return tProgramStack[#tProgramStack]
@ -495,6 +504,7 @@ end
--
-- @tparam string command The name of the alias to add.
-- @tparam string program The name or path to the program.
-- @since 1.2
-- @usage Alias `vim` to the `edit` program
--
-- shell.setAlias("vim", "edit")
@ -543,6 +553,7 @@ if multishell then
-- @tparam string ... The command line to run.
-- @see shell.run
-- @see multishell.launch
-- @since 1.6
-- @usage Launch the Lua interpreter and switch to it.
--
-- local id = shell.openTab("lua")
@ -566,6 +577,7 @@ if multishell then
--
-- @tparam number id The tab to switch to.
-- @see multishell.setFocus
-- @since 1.6
function shell.switchTab(id)
expect(1, id, "number")
multishell.setFocus(id)