├── .git-blame-ignore-revs ├── library ├── types │ ├── general.lua │ ├── io.lua │ ├── colors.lua │ ├── multishell.lua │ ├── shell.lua │ ├── redstone.lua │ ├── settings.lua │ ├── os.lua │ ├── textutils.lua │ ├── fs.lua │ ├── objects │ │ ├── peripheral │ │ │ ├── EnergyStorage.lua │ │ │ ├── Command.lua │ │ │ ├── Monitor.lua │ │ │ ├── Computer.lua │ │ │ ├── FluidStorage.lua │ │ │ ├── Printer.lua │ │ │ ├── Modem.lua │ │ │ ├── WiredModem.lua │ │ │ ├── Speaker.lua │ │ │ ├── Inventory.lua │ │ │ └── Drive.lua │ │ ├── file │ │ │ ├── WriteHandle.lua │ │ │ ├── ReadHandle.lua │ │ │ ├── BinaryWriteHandle.lua │ │ │ ├── BinaryReadHandle.lua │ │ │ └── Handle.lua │ │ ├── http │ │ │ ├── Websocket.lua │ │ │ ├── Response.lua │ │ │ └── BinaryResponse.lua │ │ ├── Window.lua │ │ ├── Vector.lua │ │ └── Redirect.lua │ ├── turtle.lua │ ├── http.lua │ └── events.lua ├── vector.lua ├── window.lua ├── pocket.lua ├── cc │ ├── image │ │ └── nft.lua │ ├── expect.lua │ ├── strings.lua │ ├── completion.lua │ ├── audio │ │ └── dfpwm.lua │ └── pretty.lua ├── gps.lua ├── help.lua ├── term.lua ├── parallel.lua ├── keys.lua ├── multishell.lua ├── commands.lua ├── settings.lua ├── globals.lua ├── paintutils.lua ├── io.lua ├── redstone.lua ├── disk.lua ├── rednet.lua ├── peripheral.lua ├── colors.lua ├── shell.lua ├── http.lua ├── textutils.lua └── fs.lua ├── .stylua.toml ├── README.md └── config.json /.git-blame-ignore-revs: -------------------------------------------------------------------------------- 1 | # Apply stylua 2 | c9f5024a2928e3f6ac723cea44bd77f2d7bffa67 -------------------------------------------------------------------------------- /library/types/general.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---@alias ccTweaked.epoch number A number of milliseconds since the [UNIX epoch](https://en.wikipedia.org/wiki/Unix_time). Useful for timestamping 4 | -------------------------------------------------------------------------------- /.stylua.toml: -------------------------------------------------------------------------------- 1 | column_width = 120 2 | line_endings = "Unix" 3 | indent_type = "Tabs" 4 | indent_width = 4 5 | quote_style = "AutoPreferDouble" 6 | call_parentheses = "NoSingleTable" 7 | collapse_simple_statement = "Never" -------------------------------------------------------------------------------- /library/types/io.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---@alias ccTweaked.io.readFormat 4 | ---| '"l"' # Read the next line (no trailing newline) 5 | ---| '"L"' # Read the next line (with trailing newline) 6 | ---| '"a"' # Read the remainder of the file 7 | -------------------------------------------------------------------------------- /library/types/colors.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---@alias ccTweaked.colors.color integer An integer represeting a color value. Colors can be found in the `colors` namespace, such as `colors.orange` 4 | 5 | ---@alias ccTweaked.colors.colorSet integer A set of colors (an integer representing multiple color values) 6 | -------------------------------------------------------------------------------- /library/types/multishell.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---@alias ccTweaked.multishell.PID integer Every process has an ID which is a number used to identify it. A process' ID may change as other processes are exited so you have to be careful to not refer to old IDs. The ID corresponds to a program's position in the tab list at the top of the screen. 4 | -------------------------------------------------------------------------------- /library/types/shell.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---@alias ccTweaked.shell.shellCompletionFunction fun(shell: shell, index: integer, argument: string, previous: table|nil) The completion function to use for completion 4 | 5 | ---@alias shellCompletionInfo table 6 | ---@class completionInfo 7 | ---@field fnComplete ccTweaked.shell.shellCompletionFunction 8 | -------------------------------------------------------------------------------- /library/types/redstone.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---@class ccTweaked.redstone.computerSidesTable 4 | computerSidesTable = { "top", "bottom", "left", "right", "front", "back" } 5 | 6 | ---@alias ccTweaked.redstone.signalStrength 7 | ---| 0 8 | ---| 1 9 | ---| 2 10 | ---| 3 11 | ---| 4 12 | ---| 5 13 | ---| 6 14 | ---| 7 15 | ---| 8 16 | ---| 9 17 | ---| 10 18 | ---| 11 19 | ---| 12 20 | ---| 13 21 | ---| 14 22 | ---| 15 23 | -------------------------------------------------------------------------------- /library/types/settings.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---@class ccTweaked.settings.settingOptions 4 | ---@field description string? A description of the setting 5 | ---@field default any? The default value of the setting 6 | ---@field type type? Require values to be of this type. Setting to another value will raise an error 7 | 8 | ---@class settingDetails: ccTweaked.settings.settingOptions 9 | ---@field value any The value of this setting 10 | -------------------------------------------------------------------------------- /library/vector.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---The vector API allows you to create a `Vector` object 4 | --- 5 | ---[Vectors on Wikipedia](http://en.wikipedia.org/wiki/Euclidean_vector) 6 | --- 7 | ------ 8 | ---[Official Documentation](https://tweaked.cc/module/vector.html) 9 | vector = {} 10 | 11 | ---Create a new `Vector` object with the given coordinates 12 | ---@param x number The x coordinate or direction 13 | ---@param y number The y coordinate or direction 14 | ---@param z number The z coordinate or direction 15 | ---@return ccTweaked.Vector vector A new `Vector` object 16 | ------ 17 | ---[Official Documentation](https://tweaked.cc/module/vector.html#v:new) 18 | function vector.new(x, y, z) end 19 | -------------------------------------------------------------------------------- /library/types/os.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---@alias ccTweaked.os.locale 4 | ---| '"ingame"' # The current world time 5 | ---| '"utc"' # Get the hour of the day in UTC time 6 | ---| '"local"' # Get the hour of the day in the timezone that the server is located in 7 | 8 | ---@class ccTweaked.os.dateTable 9 | ---@field year integer year number 10 | ---@field yday integer day of the year 11 | ---@field wday integer day of the week 12 | ---@field month integer month of the year 13 | ---@field day integer day of the month 14 | ---@field hour integer hour of the day 15 | ---@field min integer Minute of the hour 16 | ---@field sec integer Seconds of the minute 17 | ---@field isdst boolean If Daylight Saving Time is in effect 18 | -------------------------------------------------------------------------------- /library/types/textutils.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---@class ccTweaked.textutils.serializationOptions 4 | ---@field compact? boolean Do not emit whitespace characters 5 | ---@field allow_repetitions? boolean Relax the check for recursive tables, allowing them to appear multiple times so long as they don't appear in themselves 6 | 7 | ---@class ccTweaked.textutils.unserializeJSONOptions 8 | ---@field nbt_style? boolean When true, this will accept stringified NBT strings, as produced by many commands. 9 | ---@field parse_null? boolean When true, `null` will be parsed as `textutils.json_null` instead of `nil` 10 | ---@field parse_empty_array? boolean When false, empty arrays will be passed as a new table. By default (or when true), they are passed as `textutils.empty_json_array` 11 | -------------------------------------------------------------------------------- /library/types/fs.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---@alias ccTweaked.fs.path string A string that specifies a location in a directory structure. Components are separated by slashes `/` 4 | 5 | ---@alias ccTweaked.fs.openMode 6 | ---| '"r"' # read mode 7 | ---| '"w"' # write mode 8 | ---| '"a"' # append mode 9 | ---| '"rb"' # binary read mode 10 | ---| '"wb"' # binary write mode 11 | ---| '"ab"' # binary append mode 12 | 13 | ---@alias ccTweaked.fs.seekWhence 14 | ---| '"set"' # relative to the start of the file 15 | ---| '"cur"' # relative to the current position 16 | ---| '"end"' # relative to the end of the file 17 | 18 | ---@alias ccTweaked.fs.ASCII number An [ASCII code](https://www.rapidtables.com/code/text/ascii-table.html) that corresponds to a character 19 | 20 | ---@alias ccTweaked.fs.fileAttributes {size: number, isDir: boolean, isReadOnly: boolean, created: ccTweaked.epoch, modified: ccTweaked.epoch} 21 | -------------------------------------------------------------------------------- /library/window.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---The window API lets you create `Window` objects for redirecting the terminal 4 | ---to smaller windows 5 | --- 6 | ------ 7 | ---[Official Documentation](https://tweaked.cc/module/window.html) 8 | window = {} 9 | 10 | ---Create a `Window` object that can be used as a terminal redirect 11 | ---@param parent ccTweaked.term.Redirect|ccTweaked.peripheral.Monitor The parent terminal to draw to 12 | ---@param x number The x position of this window within the parent 13 | ---@param y number The y position of this window within the parent 14 | ---@param width number The width of this window 15 | ---@param height number The height of this window 16 | ---@param visible? boolean If this window should immediately be visible (defaults to true) 17 | ---@return Window window The window object 18 | ------ 19 | ---[Official Documentation](https://tweaked.cc/module/window.html#v:create) 20 | function window.create(parent, x, y, width, height, visible) end 21 | -------------------------------------------------------------------------------- /library/pocket.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---Functions for pocket computers 4 | --- 5 | ---This API is only available on pocket computers. This allows you to check if 6 | ---the current computer is a pocket computer 7 | --- 8 | ---``` 9 | ---if pocket then print("This is a pocket computer") end 10 | ---``` 11 | ------ 12 | ---[Official Documentation](https://tweaked.cc/module/pocket.html) 13 | pocket = {} 14 | 15 | ---Equip an upgrade from the player's inventory, prioritizing the currently 16 | ---selected slot 17 | ---@return boolean success If an item was equipped 18 | ---@return string|nil errorMessage The reason an item was not equipped 19 | ------ 20 | ---[Official Documentation](https://tweaked.cc/module/pocket.html#v:equipBack) 21 | function pocket.equipBack() end 22 | 23 | ---Remove the currently equipped upgrade 24 | ---@return boolean success If an upgrade was unequipped 25 | ---@return string errorMessage The reason why an upgrade was not unequipped 26 | ------ 27 | ---[Official Documentation](https://tweaked.cc/module/pocket.html#v:unequipBack) 28 | function pocket.unequipBack() end 29 | -------------------------------------------------------------------------------- /library/types/objects/peripheral/EnergyStorage.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---Offers methods for interacting with blocks that use Forge's energy system 4 | --- 5 | ---This works with storage blocks as well as generators and machines that consume energy 6 | --- 7 | ---🗒️ Due to limitations with Forge's energy API, you cannot measure throughput (RF used/generated per tick) 8 | --- 9 | ------ 10 | ---[Official Documentation](https://tweaked.cc/generic_peripheral/energy_storage.html) 11 | ---@class ccTweaked.peripheral.EnergyStorage 12 | EnergyStorage = {} 13 | 14 | ---Get the energy of this block 15 | ---@return number RF The energy stored in this block 16 | ------ 17 | ---[Official Documentation](https://tweaked.cc/generic_peripheral/energy_storage.html#v:getEnergy) 18 | function EnergyStorage.getEnergy() end 19 | 20 | ---Get the maximum amount of energy that this block can store 21 | ---@return number RF The capacity of this block 22 | ------ 23 | ---[Official Documentation](https://tweaked.cc/generic_peripheral/energy_storage.html#v:getEnergyCapacity) 24 | function EnergyStorage.getEnergyCapacity() end 25 | -------------------------------------------------------------------------------- /library/types/turtle.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---@alias ccTweaked.turtle.turtleSide 4 | ---| '"left"' 5 | ---| '"right"' 6 | 7 | ---@alias ccTweaked.turtle.turtleSlot 8 | ---| 1 9 | ---| 2 10 | ---| 3 11 | ---| 4 12 | ---| 5 13 | ---| 6 14 | ---| 7 15 | ---| 8 16 | ---| 9 17 | ---| 10 18 | ---| 11 19 | ---| 12 20 | ---| 13 21 | ---| 14 22 | ---| 15 23 | ---| 16 24 | 25 | ---@class ccTweaked.turtle.inspectInfo 26 | ---@field name string The name of the block 27 | ---@field state table The state of the block 28 | ---@field tags table The tags of the block 29 | 30 | ---@class ccTweaked.turtle.turtleDetails 31 | ---@field name string The name of the item 32 | ---@field count integer The number of items in this slot 33 | 34 | ---@class ccTweaked.turtle.turtleDetailsDetailed 35 | ---@field name string The name of the item 36 | ---@field count integer The number of items in this slot 37 | ---@field maxCount integer The max number of items that can be in this stack 38 | ---@field displayName string The display name of this item 39 | ---@field tags table The tags of this item 40 | -------------------------------------------------------------------------------- /library/types/objects/peripheral/Command.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---Command blocks can be used as a peripheral to allow their commands to be 4 | ---executed using a computer 5 | --- 6 | ------ 7 | ---[Official Documentation](https://tweaked.cc/peripheral/command.html) 8 | ---@class ccTweaked.peripheral.Command 9 | Command = {} 10 | 11 | ---Get the command that this command block will run 12 | ---@return string command The current command 13 | ------ 14 | ---[Official Documentation](https://tweaked.cc/peripheral/command.html#v:getCommand) 15 | function Command.getCommand() end 16 | 17 | ---Set the command block's command 18 | ---@param command string The new command 19 | ------ 20 | ---[Official Documentation](https://tweaked.cc/peripheral/command.html#v:setCommand) 21 | function Command.setCommand(command) end 22 | 23 | ---Execute the command block once 24 | ---@return boolean success If the command was executed successfully 25 | ---@return string|nil errorMessage Why the command failed 26 | ------ 27 | ---[Official Documentation](https://tweaked.cc/peripheral/command.html#v:runCommand) 28 | function Command.runCommand() end 29 | -------------------------------------------------------------------------------- /library/types/objects/peripheral/Monitor.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---Monitors are a block that can display the terminal on one side. This allows 4 | ---them to be viewed and interacted with without opening a GUI 5 | --- 6 | ---Monitors act as terminal redirects and share the same methods, as well as some additional ones 7 | --- 8 | ---Like computers, monitors come in both normal (no color) and advanced (color) varieties 9 | --- 10 | ------ 11 | ---[Official Documentation](https://tweaked.cc/peripheral/monitor.html) 12 | ---@class ccTweaked.peripheral.Monitor: ccTweaked.term.Redirect 13 | Monitor = {} 14 | 15 | ---Set the scale of text on this monitor. A larger scale will have a lower resolution but larger text 16 | ---@param scale number The scale of the monitor. Must be a multiple of 0.5 between 0.5 and 5 17 | ---@throws If the `scale` is out of range 18 | ------ 19 | ---[Official Documentation](https://tweaked.cc/peripheral/monitor.html#v:setTextScale) 20 | function Monitor.setTextScale(scale) end 21 | 22 | ---Get the current text scale 23 | ---@return number scale The current text scale for this monitor 24 | ---@throws If the monitor cannot be found 25 | ------ 26 | ---[Official Documentation](https://tweaked.cc/peripheral/monitor.html#v:getTextScale) 27 | function Monitor.getTextScale() end 28 | -------------------------------------------------------------------------------- /library/types/objects/file/WriteHandle.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---A file handle created with `fs.open()` using the `w` or `a` mode 4 | --- 5 | ------ 6 | ---[Official Documentation](https://tweaked.cc/module/fs.html#ty:WriteHandle) 7 | ---@class ccTweaked.fs.WriteHandle 8 | WriteHandle = {} 9 | 10 | ---Write a value to a file 11 | ---@param value any The value to write to the file 12 | ---@throws If the file has been closed 13 | ------ 14 | ---[Official Documentation](https://tweaked.cc/module/fs.html#ty:WriteHandle:write) 15 | function WriteHandle.write(value) end 16 | 17 | ---Write a value to a file with a trailing newline character 18 | ---@param value any The value to write to the file 19 | ---@throws If the file has been closed 20 | ------ 21 | ---[Official Documentation](https://tweaked.cc/module/fs.html#ty:WriteHandle:writeLine) 22 | function WriteHandle.writeLine(value) end 23 | 24 | ---Save the current file without closing it 25 | ---@throws If the file has been closed 26 | ------ 27 | ---[Official Documentation](https://tweaked.cc/module/fs.html#ty:WriteHandle:flush) 28 | function WriteHandle.flush() end 29 | 30 | ---Close the file, freeing it 31 | --- 32 | ---Once closed, it can no longer be written to unless it is reopened 33 | ---@throws If the file has already been closed 34 | ------ 35 | ---[Official Documentation](https://tweaked.cc/module/fs.html#ty:WriteHandle:close) 36 | function WriteHandle.close() end 37 | -------------------------------------------------------------------------------- /library/cc/image/nft.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---Module for reading and drawing "Nitrogen Fingers Text" (NFT) images. 4 | --- 5 | ---NFT images support coloured text and pixels, unlike `paintutils.parseImage` 6 | --- 7 | ---[Official Documentation](https://tweaked.cc/library/cc.image.nft.html) 8 | local nft = {} 9 | 10 | ---Parse an NFT from a string 11 | ---@param image string The image content as a string 12 | ---@return table image The parsed image data 13 | --- 14 | ---[Official Documentation](https://tweaked.cc/library/cc.image.nft.html#v:parse) 15 | function nft.parse(image) end 16 | 17 | ---Load an NFT from a file 18 | ---@param path string The filesystem path to the image file 19 | ---@return table|nil image The parsed image data or `nil` if the file could not be loaded 20 | ---@return nil|string error A message explaining why the file could not load 21 | --- 22 | ---[Official Documentation](https://tweaked.cc/library/cc.image.nft.html#v:load) 23 | function nft.load(path) end 24 | 25 | ---Draw an NFT image on the screen 26 | ---@param image table An image data table, as returned from `nft.parse()` or `nft.load()` 27 | ---@param xPos integer The x position to begin the drawing at 28 | ---@param yPos integer The y position to begin the drawing at 29 | ---@param target? ccTweaked.term.Redirect The terminal to draw to. Defaults to the current terminal 30 | --- 31 | ---[Official Documentation](https://tweaked.cc/library/cc.image.nft.html#v:draw) 32 | function nft.draw(image, xPos, yPos, target) end 33 | 34 | return nft 35 | -------------------------------------------------------------------------------- /library/types/objects/http/Websocket.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---A 4 | ---[websocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API) 5 | ---that can be used to send/receive messages to/from a web server 6 | --- 7 | ------ 8 | ---[Official Documentation](https://tweaked.cc/module/http.html#ty:Websocket) 9 | ---@class ccTweaked.http.Websocket 10 | Websocket = {} 11 | 12 | ---Wait for a message from the server 13 | ---@param timeout? number The number of seconds to wait for a message. Default to never timing out 14 | ---@return string|nil response The received message or `nil` if the websocket was closed while waiting or the timeout was reached 15 | ---@return boolean isBinary If this is a binary message 16 | ---@throws If the websocket has been closed 17 | ------ 18 | ---[Official Documentation](https://tweaked.cc/module/http.html#ty:Websocket:receive) 19 | function Websocket.receive(timeout) end 20 | 21 | ---Send a message to the server 22 | ---@param message any The message to send 23 | ---@param binary? boolean If this message is binary or not 24 | ---@throws If the message is too large 25 | ---@throws If the websocket has been closed 26 | ------ 27 | ---[Official Documentation](https://tweaked.cc/module/http.html#ty:Websocket:send) 28 | function Websocket.send(message, binary) end 29 | 30 | ---Close the websocket connection meaning you can no longer send or receive on it 31 | --- 32 | ------ 33 | ---[Official Documentation](https://tweaked.cc/module/http.html#ty:Websocket:close) 34 | function Websocket.close() end 35 | -------------------------------------------------------------------------------- /library/types/objects/peripheral/Computer.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---A computer or turtle wrapped as a peripheral 4 | --- 5 | ---A computer will have the type `computer` while a turtle will have the type 6 | ---`turtle` 7 | --- 8 | ------ 9 | ---[Official Documentation](https://tweaked.cc/peripheral/computer.html) 10 | ---@class ccTweaked.peripheral.Computer 11 | Computer = {} 12 | 13 | ---Turn the computer on 14 | --- 15 | ------ 16 | ---[Official Documentation](https://tweaked.cc/peripheral/computer.html#v:turnOn) 17 | function Computer.turnOn() end 18 | 19 | ---Shutdown the computer 20 | --- 21 | ------ 22 | ---[Official Documentation](https://tweaked.cc/peripheral/computer.html#v:shutdown) 23 | function Computer.shutdown() end 24 | 25 | ---Reboot or turn on the computer 26 | --- 27 | ------ 28 | ---[Official Documentation](https://tweaked.cc/peripheral/computer.html#v:reboot) 29 | function Computer.reboot() end 30 | 31 | ---Get the ID of the computer 32 | ---@return integer ID The ID of the computer 33 | ------ 34 | ---[Official Documentation](https://tweaked.cc/peripheral/computer.html#v:getID) 35 | function Computer.getID() end 36 | 37 | ---Get whether the computer is on or not 38 | ---@return boolean isOn If the computer is on 39 | ------ 40 | ---[Official Documentation](https://tweaked.cc/peripheral/computer.html#v:isOn) 41 | function Computer.isOn() end 42 | 43 | ---Get the label of the computer 44 | ---@return string|nil label The computer's label or `nil` if it does not have one 45 | ------ 46 | ---[Official Documentation](https://tweaked.cc/peripheral/computer.html#v:getLabel) 47 | function Computer.getLabel() end 48 | -------------------------------------------------------------------------------- /library/gps.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---Using modems and computers, you can find the GPS coordinates of other computers/turtles in the world. 4 | --- 5 | ---This functions by broadcasting a `PING` message over rednet and waiting for responses. For this to work, there must be at least 4 computers with modems to allow trilateration. Three of the computers should be in the same plane but form a triangle and not all be in a line. The fourth computer must be above or below the other three computers. 6 | --- 7 | ---You can set up a GPS host using the `gps` program. The program requires the `x`, `y`, `z` of the host **computer** not modem. 8 | --- 9 | ---You can choose which axes `x`, `y`, `z` refer to, just make sure that you are consistent with your usage. 10 | ---![](https://static.wikia.nocookie.net/minecraft_gamepedia/images/5/51/Coordinates.png/revision/latest/scale-to-width-down/200?cb=20200729013357) 11 | ------ 12 | ---[Official Documentation](https://tweaked.cc/module/gps.html) 13 | gps = {} 14 | 15 | ---The channel that GPS requests and responses are broadcast on 16 | --- 17 | ------ 18 | ---[Official Documentation](https://tweaked.cc/module/gps.html#v:CHANNEL_GPS) 19 | gps.CHANNEL_GPS = 65534 20 | 21 | ---Attempt to retrieve the location of this computer 22 | ---@param timeout number The maximum time in seconds permitted to try and retrieve location 23 | ---@param debug boolean If debugging messages should be displayed 24 | ---@return number? x This computer's `x` position 25 | ---@return number? y This computer's `y` position 26 | ---@return number? z This computer's `z` position 27 | ------ 28 | ---[Official Documentation](https://tweaked.cc/module/gps.html#v:locate) 29 | function gps.locate(timeout, debug) end 30 | -------------------------------------------------------------------------------- /library/cc/expect.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---Helper functions for validating certain values and types. 4 | --- 5 | ------ 6 | ---[Official Documentation](https://tweaked.cc/library/cc.expect.html) 7 | expect = {} 8 | 9 | 10 | ---Expect an argument to be of a certain type 11 | ---@generic T 12 | ---@param argIndex integer The index of the argument (for error reporting) 13 | ---@param value T The value to check 14 | ---@param ... type The type the value should be 15 | ---@return T value 16 | ---@throws If the value is not of one of the specified types 17 | ------ 18 | ---[Official Documentation](https://tweaked.cc/library/cc.expect.html#v:expect) 19 | function expect.expect(argIndex, value, ...) end 20 | 21 | ---Expect a field to be of a certain type 22 | ---@param tbl table The table the field belongs to 23 | ---@param key string The name of the field to check 24 | ---@param ... type The type the value should be 25 | ---@return any value The value of the field 26 | ---@throws If the value is not of one of the specified types 27 | ------ 28 | ---[Official Documentation](https://tweaked.cc/library/cc.expect.html#v:field) 29 | function expect.field(tbl, key, ...) end 30 | 31 | ---Expect a number to be within a specific range (inclusive) 32 | ---@param num number The number to confirm is in the specified range 33 | ---@param min number The minimum value, if omitted `-math.huge` is used 34 | ---@param max number The maximum value, if omitted `math.huge` is used 35 | ---@return number value The given number 36 | ---@throws If the value is outside the given range 37 | ------ 38 | ---[Official Documentation](https://tweaked.cc/library/cc.expect.html#v:range) 39 | function expect.range(num, min, max) end 40 | 41 | return expect 42 | -------------------------------------------------------------------------------- /library/types/objects/file/ReadHandle.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---A file handle created with `fs.open()` using `r` mode 4 | --- 5 | ------ 6 | ---[Official Documentation](https://tweaked.cc/module/fs.html#ty:ReadHandle) 7 | ---@class ccTweaked.fs.ReadHandle 8 | ReadHandle = {} 9 | 10 | ---Read a single line from the file 11 | ---@param includeNewline? boolean If any trailing newline characters should be included. Defaults to false 12 | ---@return string|nil line The read line or nil if the end of the file has been reached 13 | ---@throws If the file has been closed 14 | ------ 15 | ---[Official Documentation](https://tweaked.cc/module/fs.html#ty:ReadHandle:readLine) 16 | function ReadHandle.readLine(includeNewline) end 17 | 18 | ---Read the remainder of the file 19 | ---@return string|nil contents The remaining contents of the file or nil if at the end of the file 20 | ---@throws If the file has been closed 21 | ------ 22 | ---[Official Documentation](https://tweaked.cc/module/fs.html#ty:ReadHandle:readAll) 23 | function ReadHandle.readAll() end 24 | 25 | ---Read characters from the file 26 | ---@param count? number The number of characters to read. Defaults to 1 27 | ---@return string|nil characters The read character(s) or nil if at the end of the file 28 | ---@throws When trying to read a negative number of characters 29 | ---@throws If the file has been closed 30 | ------ 31 | ---[Official Documentation](https://tweaked.cc/module/fs.html#ty:ReadHandle:read) 32 | function ReadHandle.read(count) end 33 | 34 | ---Close the file, freeing it 35 | --- 36 | ---Once closed, it can no longer be read unless it is reopened 37 | ---@throws If the file has already been closed 38 | ------ 39 | ---[Official Documentation](https://tweaked.cc/module/fs.html#ty:ReadHandle:close) 40 | function ReadHandle.close() end 41 | -------------------------------------------------------------------------------- /library/cc/strings.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---Utilities for strings and text 4 | --- 5 | ------ 6 | ---[Official Documentation](https://tweaked.cc/library/cc.strings.html) 7 | strings = {} 8 | 9 | ---Wraps a block of text so that each line fits within the specified width 10 | --- 11 | ---Useful for wrapping text if not using `print` 12 | ---@param text string The string to wrap 13 | ---@param width? number The width to constrain to. Defaults to the width of the terminal 14 | ---@return string[] lines A table that contains each line as a string 15 | ------ 16 | ---[Official Documentation](https://tweaked.cc/library/cc.strings.html#v:wrap) 17 | function strings.wrap(text, width) end 18 | 19 | ---Make a string a fixed width through either truncating it or padding it with spaces 20 | ---@param line string The string to normalize 21 | ---@param width? number The width to constrain to. Defaults to the width of the terminal 22 | ---@return string normalizedString The string with the specified width 23 | --- 24 | ---[Official Documentation](https://tweaked.cc/library/cc.strings.html#v:ensure_width) 25 | function strings.ensure_width(line, width) end 26 | 27 | ---Split a string into parts, each separated by a deliminator. 28 | --- 29 | ---For instance, splitting the string `"a b c"` with the deliminator `" "`, would return a table with three strings: `"a"`, `"b"`, and `"c"`. 30 | ---By default, the deliminator is given as a [Lua pattern](https://www.lua.org/manual/5.3/manual.html#6.4.1). Passing true to the plain argument will cause the deliminator to be treated as a litteral string. 31 | ---@param str string The string to split. 32 | ---@param deliminator string The pattern to split this string on. 33 | ---@param plain? boolean Treat the deliminator as a plain string, rather than a pattern. 34 | ---@param limit? number The maximum number of elements in the returned list. 35 | ---@return string[] strings The list of split strings. 36 | --- 37 | ---[Official Documentation](https://tweaked.cc/library/cc.strings.html#v:split) 38 | function strings.split(str, deliminator, plain, limit) end 39 | 40 | return strings 41 | -------------------------------------------------------------------------------- /library/help.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---Tools for finding and specifying where help files are on this computer 4 | --- 5 | ------ 6 | ---[Official Documentation](https://tweaked.cc/module/help.html) 7 | help = {} 8 | 9 | ---Get a list of index directories where help files are searched for 10 | ---@return string indexList A colon-separated list of index directories. Paths are absolute 11 | ---## Example 12 | ---``` 13 | ---local helpPaths = {} 14 | --- 15 | -----Separate colon-separated list into table 16 | ---for match in string.gmatch(help.path(), "([^:]+)") do 17 | --- table.insert(helpPaths, match) 18 | ---end 19 | ---``` 20 | ------ 21 | ---[Official Documentation](https://tweaked.cc/module/help.html#v:path) 22 | function help.path() end 23 | 24 | ---Set where help files will be searched for 25 | ---@param indexList string A colon-separated list of index directories. Paths are absolute 26 | ---## Example 27 | ---``` 28 | ---help.setPath(help.path() .. ":/myProgram/help/") 29 | ---``` 30 | ------ 31 | ---[Official Documentation](https://tweaked.cc/module/help.html#v:setPath) 32 | function help.setPath(indexList) end 33 | 34 | ---Get the location of the help file for a topic 35 | ---@param topic string The topic to find 36 | ---@return ccTweaked.fs.path|nil path The path to the help file or `nil` if it cannot be found 37 | ---## Example 38 | ---``` 39 | ---help.lookup("disk") 40 | -----> "rom/help/disk.txt" 41 | ---``` 42 | ------ 43 | ---[Official Documentation](https://tweaked.cc/module/help.html#v:lookup) 44 | function help.lookup(topic) end 45 | 46 | ---Get a list of help topics 47 | ---@return string[] topics An array of help topics sorted A→Z 48 | ------ 49 | ---[Official Documentation](https://tweaked.cc/module/help.html#v:topics) 50 | function help.topics() end 51 | 52 | ---Get completion suggestions for help topics 53 | ---@param partial string A partially completed help topic name to complete 54 | ---@return string[] completions An array of possible completions 55 | ------ 56 | ---[Official Documentation](https://tweaked.cc/module/help.html#v:completeTopic) 57 | function help.completeTopic(partial) end 58 | -------------------------------------------------------------------------------- /library/types/objects/file/BinaryWriteHandle.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---A file handle created with `fs.open()` using `wb` or `ab` mode 4 | --- 5 | ------ 6 | ---[Official Documentation](https://tweaked.cc/module/fs.html#ty:BinaryWriteHandle) 7 | ---@class ccTweaked.fs.BinaryWriteHandle 8 | BinaryWriteHandle = {} 9 | 10 | ---Write a string or byte to the file 11 | ---@param value ccTweaked.fs.ASCII|string The string to write or an ASCII code to write 12 | ---@throws If the file has been closed 13 | ---## Examples 14 | ---``` 15 | ---local file = fs.open("myFile.txt", "wb") 16 | ---file.write("Hello World!\n") 17 | --- 18 | -----Write "Hi" 19 | ---file.write(48) 20 | ---file.write(69) 21 | --- 22 | ---file.close() 23 | ---``` 24 | ------ 25 | ---[Official Documentation](https://tweaked.cc/module/fs.html#ty:BinaryWriteHandle:write) 26 | function BinaryWriteHandle.write(value) end 27 | 28 | ---Save the current file without closing it 29 | ---@throws If the file has been closed 30 | ------ 31 | ---[Official Documentation](https://tweaked.cc/module/fs.html#ty:BinaryWriteHandle:flush) 32 | function BinaryWriteHandle.flush() end 33 | 34 | ---Close the file, freeing it 35 | --- 36 | ---Once closed, it can no longer be written to unless it is reopened 37 | ---@throws If the file has already been closed 38 | ------ 39 | ---[Official Documentation](https://tweaked.cc/module/fs.html#ty:BinaryWriteHandle:close) 40 | function BinaryWriteHandle.close() end 41 | 42 | ---Change where the "cursor" is, changing where bytes will be written to. The 43 | ---new position is an offset relative to `whence` 44 | ---@param whence? ccTweaked.fs.seekWhence What `offset` is relative to. Defaults to `cur` 45 | ---@param offset? number The offset to seek to. Defaults to 0 46 | ---@return number|nil newPosition The new file write position relative to the start of the file or nil if seeking failed 47 | ---@return string|nil errorMessage The reason seeking failed 48 | ---@throws If the file has been closed 49 | ------ 50 | ---[Official Documentation](https://tweaked.cc/module/fs.html#ty:BinaryWriteHandle:seek) 51 | function BinaryWriteHandle.seek(whence, offset) end 52 | -------------------------------------------------------------------------------- /library/types/objects/peripheral/FluidStorage.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---Offers methods for interacting with tanks and other fluid storage blocks 4 | --- 5 | ------ 6 | ---[Official Documentation](https://tweaked.cc/generic_peripheral/fluid_storage.html) 7 | ---@class ccTweaked.peripheral.FluidStorage 8 | FluidStorage = {} 9 | 10 | ---Get all "tanks" in this fluid storage 11 | --- 12 | ---Each tank either contains some amount of fluid or is empty. Tanks with fluids 13 | ---inside will return some basic information about the fluid, including its name 14 | ---and amount. 15 | --- 16 | ---The returned table is sparse, and so empty tanks will be nil - it is 17 | ---recommended to loop over using pairs rather than ipairs. 18 | ---@return table|nil[] 19 | function FluidStorage.tanks() end 20 | 21 | ---Move a fluid from one container to another connected one 22 | ---@param toName string The name of the peripheral/container to 23 | ---@param limit? number The maximum amount of fluid to move 24 | ---@param fluidName? string The name of the fluid to move. If not given, a random fluid will be moved 25 | ---@return number fluidMoved The amount of fluid moved 26 | ---@throws If the target container doesn't exist 27 | ---@throws If the target container isn't for fluids 28 | ------ 29 | ---[Official Documentation](https://tweaked.cc/generic_peripheral/fluid_storage.html#v:pushFluid) 30 | function FluidStorage.pushFluid(toName, limit, fluidName) end 31 | 32 | ---Move a fluid from a connected contained into this one 33 | --- 34 | ---Both containers must be attached through wired modems 35 | ---@param fromName string The name of the container to pull from 36 | ---@param limit? number The maximum amount of fluid to move 37 | ---@param fluidName? string The name of the fluid to move. If not given, a random fluid will be moved 38 | ---@return number fluidMoved The amount of fluid moved 39 | ---@throws If the source container doesn't exist 40 | ---@throws If the source container isn't for fluids 41 | ------ 42 | ---[Official Documentation](https://tweaked.cc/generic_peripheral/fluid_storage.html#v:pullFluid) 43 | function FluidStorage.pullFluid(fromName, limit, fluidName) end 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Lua Language Server library for CC: Tweaked 2 | This is a [Lua Language Server](https://github.com/sumneko/lua-language-server) [library](https://github.com/sumneko/lua-language-server/wiki/Libraries) for [CC: Tweaked](https://computercraft.cc)'s [APIs](https://tweaked.cc/). 3 | 4 | Before the fork, this was intended to be used in [Visual Studio Code](https://code.visualstudio.com/) with [Sumneko's Lua extension](https://marketplace.visualstudio.com/items?itemName=sumneko.lua) (`sumneko.lua`). This fork concentrates on making completions for ComputerCraft a first-class citizen in editors such as Neovim, Vim, and Emacs. 5 | 6 | ## Setup 7 | 1. Download the repository 8 | 2. If you don't already have one, create a folder, wherever you'd like, that can contain all your third-party libraries for Sumneko's Lua extension. 9 | 3. In this folder, create a new folder named `CC-Tweaked` or something similar. 10 | 4. Paste the contents from this repo in this new `CC-Tweaked` folder. 11 | 5. Open VS Code and [open the settings](https://code.visualstudio.com/docs/getstarted/settings) 12 | 6. In the searchbar, type: 13 | ```txt 14 | @ext:sumneko.lua third party library 15 | ``` 16 | 7. Select `Add Item` 17 | 8. Paste in the absolute path to the folder containing all of your libraries from step 2 (the one that contains the `CC-Tweaked` folder) 18 | 9. Then to enable third party libaries click on `Edit in settings.json` under `Check Third Party` and set `"Lua.workspace.checkThirdParty": true` 19 | 20 | Now when you trigger one of the below cases you should be prompted to set up your workspace as a `CC:Tweaked` workspace. 21 | 22 | Trigger cases: 23 | - Following phrases are found in file: 24 | - `turtle.` 25 | - `rednet.` 26 | - `redstone.` 27 | - `peripheral.` 28 | - `minecraft` 29 | - `computercraft` 30 | - File is named: 31 | - `startup.lua` 32 | 33 | After applying the workspace, you should have full autocompletion and diagnostics. 34 | 35 | > [!NOTE] 36 | > CC: Tweaked has some [seriously cursed](https://tweaked.cc/reference/feature_compat.html) support for Lua features, thus, the environment is a little messy and is not currently emulated as accurately as possible. As time goes on, we can figure out what is and isn't supported in CC:Tweaked and remove unsupported features using `config.json` from the built-in libraries of Sumneko's Lua extension. 37 | -------------------------------------------------------------------------------- /library/term.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---Interact with a computer's terminal or monitors 4 | --- 5 | ------ 6 | ---[Official Documentation](https://tweaked.cc/module/term.html) 7 | ---@class term: ccTweaked.term.Redirect 8 | term = {} 9 | 10 | ---Get the default colour value for a colour from the palette 11 | ---@param colour ccTweaked.colors.color The colour to get the default value for 12 | ---@return number r The red channel (0 - 1) 13 | ---@return number g The green channel (0 - 1) 14 | ---@return number b The blue channel (0 - 1) 15 | ---@throws If an invalid colour is given 16 | ------ 17 | ---[Official Documentation](https://tweaked.cc/module/term.html#v:nativePaletteColour) 18 | function term.nativePaletteColour(colour) end 19 | 20 | ---Get the default color value for a color from the palette 21 | ---@param color ccTweaked.colors.color The color to get the default value for 22 | ---@return number r The red channel (0 - 1) 23 | ---@return number g The green channel (0 - 1) 24 | ---@return number b The blue channel (0 - 1) 25 | ---@throws If an invalid color is given 26 | ------ 27 | ---[Official Documentation](https://tweaked.cc/module/term.html#v:nativePaletteColor) 28 | function term.nativePaletteColor(color) end 29 | 30 | ---Redirect the terminal output to a monitor, window, or any other custom 31 | ---terminal object. Once called, any calls to the `term` API will instead operate 32 | ---on the new terminal object 33 | ---@param target ccTweaked.term.Redirect The terminal object the `term` API will draw to 34 | ---@return ccTweaked.term.Redirect previous The previous terminal object that was being drawn to 35 | ---## Example 36 | ---``` 37 | ---term.redirect(peripheral.find("monitor")) 38 | ---print("Hello monitor!") 39 | ---``` 40 | ------ 41 | ---[Official Documentation](https://tweaked.cc/module/term.html#v:redirect) 42 | function term.redirect(target) end 43 | 44 | ---Get the current terminal object that the `term` API is drawing to 45 | ---@return ccTweaked.term.Redirect current The current terminal object 46 | ------ 47 | ---[Official Documentation](https://tweaked.cc/module/term.html#v:current) 48 | function term.current() end 49 | 50 | ---Get the native terminal object 51 | --- 52 | ---⚠️ It is recommended that you don't use this function unless you absolutely 53 | ---have to. In a multitask environment, `term.native()` will not be the current 54 | ---terminal object and so drawing may interfere with other programs 55 | ---@return ccTweaked.term.Redirect native The native terminal redirect 56 | function term.native() end 57 | -------------------------------------------------------------------------------- /library/types/objects/http/Response.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---A HTTP response. This provides the same methods as a file as well as some response-specific methods 4 | ---@class ccTweaked.http.Response 5 | ------ 6 | ---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response) 7 | Response = {} 8 | 9 | ---Get the response code and message returned by the server 10 | ---@return number code The response code (e.g. 200) 11 | ---@return string message The response message (e.g. "OK") 12 | ------ 13 | ---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response:getResponseCode) 14 | function Response.getResponseCode() end 15 | 16 | ---Get the [response headers](https://developer.mozilla.org/en-US/docs/Glossary/Response_header) 17 | --- 18 | ---If multiple headers are sent with the same name, they will be combined with a 19 | ---comma 20 | ---@return table 21 | ------ 22 | ---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response:getResponseHeaders) 23 | function Response.getResponseHeaders() end 24 | 25 | ---Read a single line from the response 26 | ---@param includeNewline? boolean If any trailing newline characters should be included. Defaults to false 27 | ---@return string|nil line The read line or nil if the end of the response has been reached 28 | ---@throws If the response has been closed 29 | ------ 30 | ---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response) 31 | function Response.readLine(includeNewline) end 32 | 33 | ---Read the remainder of the response 34 | ---@return string|nil contents The remaining contents of the response or nil if at the end of the response 35 | ---@throws If the response has been closed 36 | ------ 37 | ---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response) 38 | function Response.readAll() end 39 | 40 | ---Read characters from the response 41 | ---@param count? number The number of characters to read. Defaults to 1 42 | ---@return string|nil characters The read character(s) or nil if at the end of the response 43 | ---@throws When trying to read a negative number of characters 44 | ---@throws If the response has been closed 45 | ------ 46 | ---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response) 47 | function Response.read(count) end 48 | 49 | ---Close the response 50 | --- 51 | ---Once closed, it can no longer be read unless it is re-requested 52 | ---@throws If the response has already been closed 53 | ------ 54 | ---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response) 55 | function Response.close() end 56 | -------------------------------------------------------------------------------- /library/parallel.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---Offers a simple way to run multiple functions at once 4 | --- 5 | ---Functions are not actually run simultaneously, however, this API will 6 | ---automatically switch between them whenever they yield (whether that be through 7 | ---`coroutine.yield()`, or functions that call that, such as `os.pullEvent()`) 8 | --- 9 | ---Each function executed in "parallel" gets its own copy of the event queue, 10 | ---and so "event consuming" functions (again, mostly anything that causes the 11 | ---script to pause - e.g. `os.sleep`, `rednet.receive`, most of the turtle API, etc) 12 | ---can safely be used in one without affecting the event queue accessed by the 13 | ---other. 14 | --- 15 | ---⚠️ Be careful to pass in the function you want to execute in parallel and not 16 | ---the result of that function (don't *call* the function) 17 | --- 18 | ------ 19 | ---[Official Documentation](https://tweaked.cc/module/parallel.html) 20 | parallel = {} 21 | 22 | ---Switches between the execution of the functions until any one of them finishes 23 | --- 24 | ---Should one of the functions error, it will be propgated up to this 25 | ---`parallel.waitForAny()` call 26 | ---@param ... function The functions to be run in "parallel" 27 | ---## Example 28 | ---``` 29 | ---local function tick() 30 | --- while true do 31 | --- os.sleep(1) 32 | --- print("Tick") 33 | --- end 34 | ---end 35 | ---local function wait_for_q() 36 | --- repeat 37 | --- local _, key = os.pullEvent("key") 38 | --- until key == keys.q 39 | --- print("Q was pressed!") 40 | ---end 41 | --- 42 | -----Print a message every second until the q key is pressed 43 | ---parallel.waitForAny(tick, wait_for_q) 44 | ---print("Everything done!") 45 | ---``` 46 | ------ 47 | ---[Official Documentation](https://tweaked.cc/module/parallel.html#v:waitForAny) 48 | function parallel.waitForAny(...) end 49 | 50 | ---Switches between the execution of the functions until they all finish 51 | --- 52 | ---Should one of the functions error, it will be propgated up to this 53 | ---`parallel.waitForAll()` call 54 | ---@param ... function 55 | ---## Example 56 | ---``` 57 | ---local function a() 58 | --- os.sleep(1) 59 | --- print("A is done") 60 | ---end 61 | ---local function b() 62 | --- os.sleep(3) 63 | --- print("B is done") 64 | ---end 65 | --- 66 | -----Start two timers and wait for both to finish 67 | ---parallel.waitForAll(a, b) 68 | ---print("Everything done!") 69 | ---``` 70 | ------ 71 | ---[Official Documentation](https://tweaked.cc/module/parallel.html#v:waitForAll) 72 | function parallel.waitForAll(...) end 73 | -------------------------------------------------------------------------------- /library/cc/completion.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---Helper functions for completing text. Useful for `_G.read()` 4 | --- 5 | ------ 6 | ---[Official Documentation](https://tweaked.cc/library/cc.completion.html) 7 | completion = {} 8 | 9 | ---Get completions from a choice of strings 10 | ---@param text string The incomplete string 11 | ---@param choices string[] The choices to offer completions from 12 | ---@param trailingSpace? boolean Add a trailing space after the completed item 13 | ---## Example 14 | ---``` 15 | ---local completion = require "cc.completion" 16 | ---local animals = { "dog", "cat", "lion", "unicorn" } 17 | ---read(nil, nil, function(text) return completion.choice(text, animals) end) 18 | ---``` 19 | ------ 20 | ---[Official Documentation](https://tweaked.cc/library/cc.completion.html#v:choice) 21 | function completion.choice(text, choices, trailingSpace) end 22 | 23 | ---Get completions for the name of a connected peripheral 24 | ---@param text string The incomplete string 25 | ---@param trailingSpace? boolean Add a trailing space after the completed item 26 | ---## Example 27 | ---``` 28 | ---local completion = require "cc.completion" 29 | ---read(nil, nil, completion.peripheral) 30 | ---``` 31 | ------ 32 | ---[Official Documentation](https://tweaked.cc/library/cc.completion.html#v:peripheral) 33 | function completion.peripheral(text, trailingSpace) end 34 | 35 | ---Complete the side of a computer 36 | ---@param text string The incomplete string 37 | ---@param trailingSpace? boolean Add a trailing space after the completed item 38 | ---## Example 39 | ---``` 40 | ---local completion = require "cc.completion" 41 | ---read(nil, nil, completion.side) 42 | ---``` 43 | ------ 44 | ---[Official Documentation](https://tweaked.cc/library/cc.completion.html#v:side) 45 | function completion.side(text, trailingSpace) end 46 | 47 | ---Complete a setting name 48 | ---@param text string The incomplete string 49 | ---@param trailingSpace? boolean Add a trailing space after the completed item 50 | ---## Example 51 | ---``` 52 | ---local completion = require "cc.completion" 53 | ---read(nil, nil, completion.setting) 54 | ---``` 55 | ------ 56 | ---[Official Documentation](https://tweaked.cc/library/cc.completion.html#v:setting) 57 | function completion.setting(text, trailingSpace) end 58 | 59 | ---Complete the name of a Minecraft command 60 | ---@param text string The incomplete string 61 | ---@param trailingSpace? boolean Add a trailing space after the completed item 62 | ------ 63 | ---[Official Documentation](https://tweaked.cc/library/cc.completion.html#v:command) 64 | function completion.command(text, trailingSpace) end 65 | 66 | return completion 67 | -------------------------------------------------------------------------------- /library/types/http.lua: -------------------------------------------------------------------------------- 1 | ---@alias ccTweaked.http.HTTP_REQUEST_HEADERS string 2 | ---| '"A-IM"' 3 | ---| '"Accept"' 4 | ---| '"Accept-Charset"' 5 | ---| '"Accept-Encoding"' 6 | ---| '"Accept-Language"' 7 | ---| '"Accept-Datetime"' 8 | ---| '"Access-Control-Request-Method"' 9 | ---| '"Access-Control-Request-Headers"' 10 | ---| '"Authorization"' 11 | ---| '"Cache-Control"' 12 | ---| '"Connection"' 13 | ---| '"Content-Length"' 14 | ---| '"Content-Type"' 15 | ---| '"Cookie"' 16 | ---| '"Date"' 17 | ---| '"Expect"' 18 | ---| '"Forwarded"' 19 | ---| '"From"' 20 | ---| '"Host"' 21 | ---| '"If-Match"' 22 | ---| '"If-Modified-Since"' 23 | ---| '"If-None-Match"' 24 | ---| '"If-Range"' 25 | ---| '"If-Unmodified-Since"' 26 | ---| '"Max-Forwards"' 27 | ---| '"Origin"' 28 | ---| '"Pragma"' 29 | ---| '"Proxy-Authorization"' 30 | ---| '"Range"' 31 | ---| '"Referer"' 32 | ---| '"TE"' 33 | ---| '"User-Agent"' 34 | ---| '"Upgrade"' 35 | ---| '"Via"' 36 | ---| '"Warning"' 37 | 38 | ---@alias ccTweaked.http.HTTP_RESPONSE_HEADERS string 39 | ---| '"Access-Control-Allow-Origin"' 40 | ---| '"Access-Control-Allow-Credentials"' 41 | ---| '"Access-Control-Expose-Headers"' 42 | ---| '"Access-Control-Max-Age"' 43 | ---| '"Access-Control-Allow-Methods"' 44 | ---| '"Access-Control-Allow-Headers"' 45 | ---| '"Accept-Patch"' 46 | ---| '"Accept-Ranges"' 47 | ---| '"Age"' 48 | ---| '"Allow"' 49 | ---| '"Alt-Svc"' 50 | ---| '"Cache-Control"' 51 | ---| '"Connection"' 52 | ---| '"Content-Disposition"' 53 | ---| '"Content-Encoding"' 54 | ---| '"Content-Language"' 55 | ---| '"Content-Length"' 56 | ---| '"Content-Location"' 57 | ---| '"Content-Range"' 58 | ---| '"Content-Type"' 59 | ---| '"Date"' 60 | ---| '"Delta-Base"' 61 | ---| '"ETag"' 62 | ---| '"Expires"' 63 | ---| '"IM"' 64 | ---| '"Last-Modified"' 65 | ---| '"Link"' 66 | ---| '"Location"' 67 | ---| '"Pragma"' 68 | ---| '"Proxy-Authenticate"' 69 | ---| '"Public-Key-Pins"' 70 | ---| '"Retry-After"' 71 | ---| '"Server"' 72 | ---| '"Set-Cookie"' 73 | ---| '"Strict-Transport-Security"' 74 | ---| '"Trailer"' 75 | ---| '"Transfer-Encoding"' 76 | ---| '"Tk"' 77 | ---| '"Upgrade"' 78 | ---| '"Vary"' 79 | ---| '"Via"' 80 | ---| '"Warning"' 81 | ---| '"WWW-Authenticate"' 82 | 83 | ---@alias ccTweaked.http.HTTP_METHOD 84 | ---| '"GET"' 85 | ---| '"HEAD"' 86 | ---| '"POST"' 87 | ---| '"PUT"' 88 | ---| '"DELETE"' 89 | ---| '"CONNECT"' 90 | ---| '"OPTIONS"' 91 | ---| '"TRACE"' 92 | ---| '"PATCH"' 93 | 94 | ---@alias ccTweaked.http.HTTP_REQUEST {url: string, body?: string, headers?: table, binary?: boolean, method?: ccTweaked.http.HTTP_METHOD, redirect?: boolean} 95 | 96 | ---@alias ccTweaked.http.WEBSOCKET_OPTIONS {url: string, headers?: table, timeout?: number} 97 | -------------------------------------------------------------------------------- /library/types/objects/Window.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---@class Window: ccTweaked.term.Redirect 4 | Window = {} 5 | 6 | ---Get the buffered contents of a given line in this window 7 | ---@param y integer The y position of the line to get 8 | ---@return string content The text content of this line 9 | ---@return string textBlit The text colors of this line, suitable for use with `term.blit()` 10 | ---@return string backgroundBlit The background colors of this line, suitable for use with `term.blit()` 11 | ---@throws If `y` is not between 1 and this window's height 12 | ------ 13 | ---[Official Documentation](https://tweaked.cc/module/window.html#ty:Window:getLine) 14 | function Window.getLine(y) end 15 | 16 | ---Set whether this window is visible 17 | ---@param visible boolean If this window should be visible 18 | ------ 19 | ---[Official Documentation](https://tweaked.cc/module/window.html#ty:Window:setVisible) 20 | function Window.setVisible(visible) end 21 | 22 | ---Get whether this window is visible 23 | ---@return boolean visible If this window is visible 24 | ------ 25 | ---[Official Documentation](https://tweaked.cc/module/window.html#ty:Window:isVisible) 26 | function Window.isVisible() end 27 | 28 | ---Draw this window 29 | --- 30 | ---⚠️ This does nothing if the window is set to be invisible 31 | --- 32 | ------ 33 | ---[Official Documentation](https://tweaked.cc/module/window.html#ty:Window:redraw) 34 | function Window.redraw() end 35 | 36 | ---Set the current terminal's cursor to where this window's cursor is 37 | --- 38 | ---⚠️ This does nothing if the window is set to be invisible 39 | --- 40 | ------ 41 | ---[Official Documentation](https://tweaked.cc/module/window.html#ty:Window:restoreCursor) 42 | function Window.restoreCursor() end 43 | 44 | ---Get the position of the top left corner of this window 45 | ---@return number x The x position of this window 46 | ---@return number y The y position of this window 47 | ------ 48 | ---[Official Documentation](https://tweaked.cc/module/window.html#ty:Window:getPosition) 49 | function Window.getPosition() end 50 | 51 | ---Reposition, resize, or change the inheritance of this window 52 | --- 53 | ---🗒️ If you are changing the size of this window, it is recommended to fire a 54 | ---`term_resize` event to allow programs to adjust their scaling 55 | ---@param x number The new x position of this window 56 | ---@param y number The new y position of this window 57 | ---@param w? number The new width of this window 58 | ---@param h? number The new height of this window 59 | ---@param parent? ccTweaked.term.Redirect|ccTweaked.peripheral.Monitor The new `Redirect` that this window should be drawn to 60 | ------ 61 | ---[Official Documentation](https://tweaked.cc/module/window.html#ty:Window:reposition) 62 | function Window.reposition(x, y, w, h, parent) end 63 | -------------------------------------------------------------------------------- /library/types/objects/file/BinaryReadHandle.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---A file handle created with `fs.open()` using `rb` mode 4 | --- 5 | ------ 6 | ---[Official Documentation](https://tweaked.cc/module/fs.html#ty:BinaryReadHandle) 7 | ---@class ccTweaked.fs.BinaryReadHandle 8 | BinaryReadHandle = {} 9 | 10 | ---Read a number of bytes from the file 11 | ---@param count number The number of bytes to read 12 | ---@return string|nil byte The byte as a string or nil when the end of the file is reached 13 | ---@throws When trying to read a negative number of bytes 14 | ---@throws If the file has been closed 15 | ------ 16 | ---[Official Documentation](https://tweaked.cc/module/fs.html#ty:BinaryReadHandle:read) 17 | function BinaryReadHandle.read(count) end 18 | 19 | ---Read a byte from the file 20 | ---@return ccTweaked.fs.ASCII|nil byte The byte as an [ASCII code](https://www.rapidtables.com/code/text/ascii-table.html) 21 | ---@throws If the file has been closed 22 | ------ 23 | ---[Official Documentation](https://tweaked.cc/module/fs.html#ty:BinaryReadHandle:read) 24 | function BinaryReadHandle.read() end 25 | 26 | ---Read the remainder of the file 27 | ---@return string|nil contents The remaining content of the file or nil if the end of the file is reached 28 | ---@throws If the file has been closed 29 | ------ 30 | ---[Official Documentation](https://tweaked.cc/module/fs.html#ty:BinaryReadHandle:readAll) 31 | function BinaryReadHandle.readAll() end 32 | 33 | ---Read a line from the file 34 | ---@param includeNewline? boolean If any trailing newline characters should be included. Defaults to false 35 | ---@return string|nil line The read line or nil if the end of the file has been reached 36 | ---@throws If the file has been closed 37 | ------ 38 | ---[Official Documentation](https://tweaked.cc/module/fs.html#ty:BinaryReadHandle:readLine) 39 | function BinaryReadHandle.readLine(includeNewline) end 40 | 41 | ---Close the file, freeing it 42 | --- 43 | ---Once closed, it can no longer be read unless it is reopened 44 | ---@throws If the file has already been closed 45 | ------ 46 | ---[Official Documentation](https://tweaked.cc/module/fs.html#ty:BinaryReadHandle:close) 47 | function BinaryReadHandle.close() end 48 | 49 | ---Seek to a new position in the file. The new position is an offset relative to `whence` 50 | ---@param whence? ccTweaked.fs.seekWhence What `offset` is relative to. Defaults to `cur` 51 | ---@param offset? number The offset to seek to. Defaults to 0 52 | ---@return number|nil newPosition The new file read position relative to the start of the file or nil if seeking failed 53 | ---@return string|nil errorMessage The reason seeking failed 54 | ---@throws If the file has been closed 55 | ------ 56 | ---[Official Documentation](https://tweaked.cc/module/fs.html#ty:BinaryReadHandle:seek) 57 | function BinaryReadHandle.seek(whence, offset) end 58 | -------------------------------------------------------------------------------- /library/types/objects/peripheral/Printer.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---The printer peripheral allows you to print pages and books 4 | --- 5 | ------ 6 | ---[Official Documentation](https://tweaked.cc/peripheral/printer.html) 7 | ---@class ccTweaked.peripheral.Printer 8 | Printer = {} 9 | 10 | ---Writes text to the currently active page 11 | ---@param ... string|number The values to write to the current page 12 | ---@throws If no page is started 13 | ---@throws If any values couldn't be converted to a string 14 | ------ 15 | ---[Official Documentation](https://tweaked.cc/peripheral/printer.html#v:write) 16 | function Printer.write(...) end 17 | 18 | ---Get the current position of the cursor on the page 19 | ---@return number x The x position of the cursor 20 | ---@return number y The y position of the cursor 21 | ---@throws If a page isn't being printed 22 | ------ 23 | ---[Official Documentation](https://tweaked.cc/peripheral/printer.html#v:getCursorPos) 24 | function Printer.getCursorPos() end 25 | 26 | ---Set the current position of the cursor on the page 27 | ---@param x number The new x coordinate of the cursor 28 | ---@param y number The new y coordinate of the cursor 29 | ---@throws If a page isn't being printed 30 | ------ 31 | ---[Official Documentation](https://tweaked.cc/peripheral/printer.html#v:setCursorPos) 32 | function Printer.setCursorPos(x, y) end 33 | 34 | ---Get the size of the current page 35 | ---@return number width The width of the current page 36 | ---@return number height The height of the current page 37 | ---@throws If a page isn't being printed 38 | ------ 39 | ---[Official Documentation](https://tweaked.cc/peripheral/printer.html#v:getPageSize) 40 | function Printer.getPageSize() end 41 | 42 | ---Starts printing a new page 43 | ---@return boolean success Whether a new page could be started or not 44 | ------ 45 | ---[Official Documentation](https://tweaked.cc/peripheral/printer.html#v:newPage) 46 | function Printer.newPage() end 47 | 48 | ---Finish printing the current page and feed it into the output tray 49 | ---@return boolean success Whether the page could be finalized or not 50 | ---@throws If a page isn't being printed 51 | ------ 52 | ---[Official Documentation](https://tweaked.cc/peripheral/printer.html#v:endPage) 53 | function Printer.endPage() end 54 | 55 | ---Set the title of the current page 56 | ---@param title? string The title to set for the current page 57 | ---@throws If a page isn't being printed 58 | ------ 59 | ---[Official Documentation](https://tweaked.cc/peripheral/printer.html#v:setPageTitle) 60 | function Printer.setPageTitle(title) end 61 | 62 | ---Get the amount of ink remaining in the printer 63 | ---@return number ink The amount of ink left in the printer 64 | ------ 65 | ---[Official Documentation](https://tweaked.cc/peripheral/printer.html#v:getInkLevel) 66 | function Printer.getInkLevel() end 67 | 68 | ---Get the amount of paper left in the printer 69 | ---@return number pages The amount of paper left in the printer 70 | ------ 71 | ---[Official Documentation](https://tweaked.cc/peripheral/printer.html#v:getPaperLevel) 72 | function Printer.getPaperLevel() end 73 | -------------------------------------------------------------------------------- /library/keys.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---It is reccommended that you use the constant values defined here rather than 4 | ---any numerical values as they may change between versions 5 | --- 6 | ------ 7 | ---[Official Documentation](https://tweaked.cc/module/keys.html) 8 | keys = { 9 | space = 32, 10 | apostrophe = 39, 11 | comma = 44, 12 | minus = 45, 13 | period = 46, 14 | slash = 47, 15 | zero = 48, 16 | one = 49, 17 | two = 50, 18 | three = 51, 19 | four = 52, 20 | five = 53, 21 | six = 54, 22 | seven = 55, 23 | eight = 56, 24 | nine = 57, 25 | semicolon = 59, 26 | equals = 61, 27 | a = 65, 28 | b = 66, 29 | c = 67, 30 | d = 68, 31 | e = 69, 32 | f = 70, 33 | g = 71, 34 | h = 72, 35 | i = 73, 36 | j = 74, 37 | k = 75, 38 | l = 76, 39 | m = 77, 40 | n = 78, 41 | o = 79, 42 | p = 80, 43 | q = 81, 44 | r = 82, 45 | s = 83, 46 | t = 84, 47 | u = 85, 48 | v = 86, 49 | w = 87, 50 | x = 88, 51 | y = 89, 52 | z = 90, 53 | leftBracket = 91, 54 | backslash = 92, 55 | rightBracket = 93, 56 | grave = 96, 57 | enter = 257, 58 | tab = 258, 59 | backspace = 259, 60 | insert = 260, 61 | delete = 261, 62 | right = 262, 63 | left = 263, 64 | down = 264, 65 | up = 265, 66 | pageUp = 266, 67 | pageDown = 267, 68 | home = 268, 69 | ["end"] = 269, 70 | capsLock = 280, 71 | scrollLock = 281, 72 | numLock = 282, 73 | printScreen = 283, 74 | pause = 284, 75 | f1 = 290, 76 | f2 = 291, 77 | f3 = 292, 78 | f4 = 293, 79 | f5 = 294, 80 | f6 = 295, 81 | f7 = 296, 82 | f8 = 297, 83 | f9 = 298, 84 | f10 = 299, 85 | f11 = 300, 86 | f12 = 301, 87 | f13 = 302, 88 | f14 = 303, 89 | f15 = 304, 90 | f16 = 305, 91 | f17 = 306, 92 | f18 = 307, 93 | f19 = 308, 94 | f20 = 309, 95 | f21 = 310, 96 | f22 = 311, 97 | f23 = 312, 98 | f24 = 313, 99 | f25 = 314, 100 | numPad0 = 320, 101 | numPad1 = 321, 102 | numPad2 = 322, 103 | numPad3 = 323, 104 | numPad4 = 324, 105 | numPad5 = 325, 106 | numPad6 = 326, 107 | numPad7 = 327, 108 | numPad8 = 328, 109 | numPad9 = 329, 110 | numPadDecimal = 330, 111 | numPadDivide = 331, 112 | numPadMultiply = 332, 113 | numPadSubtract = 333, 114 | numPadAdd = 334, 115 | numPadEnter = 335, 116 | numPadEqual = 336, 117 | leftShift = 340, 118 | leftCtrl = 341, 119 | leftAlt = 342, 120 | leftSuper = 343, 121 | rightShift = 344, 122 | rightCtrl = 345, 123 | rightAlt = 346, 124 | menu = 348, 125 | } 126 | 127 | ---Translates a key code to a written name from the `keys` API 128 | ---@param code integer 129 | ---@return string|nil name The name of the key or nil if the code was invalid 130 | ------ 131 | ---[Official Documentation](https://tweaked.cc/module/keys.html#v:getName) 132 | function keys.getName(code) end 133 | -------------------------------------------------------------------------------- /library/cc/audio/dfpwm.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---This module converts between streams of DFPWM audio data and a list of 4 | ---amplitudes. 5 | --- 6 | ---[Dynamic Filter Pulse Width Modulation 7 | ---(DFPWM)](https://wiki.vexatos.com/dfpwm) is an audio codec designed by 8 | ---[GreaseMonkey](https://gist.github.com/iamgreaser/5890329) that is relatively 9 | ---compact compared to [pulse-code 10 | ---modulation](https://en.wikipedia.org/wiki/Pulse-code_modulation) (PCM). It 11 | ---uses only 1 bit per sample, any yet, is still simple enough to encode and 12 | ---decode in real time on CC:Tweaked computers. It is not a popular file format, 13 | ---and as a result, most audio processing tools do not have the option to export 14 | ---to it. However, the online tool [music.madefor.cc](https://music.madefor.cc/) 15 | ---can be used to convert from more standard audio formats to DFPWM. 16 | --- 17 | ---DFPWM can be read from the filesystem or a web request as a string, decoded 18 | ---to PCM, and played on a speaker peripheral. 19 | --- 20 | ---For an in-depth guide to playing audio in CC:Tweaked, see the [official 21 | ---guide](https://tweaked.cc/guide/speaker_audio.html). 22 | --- 23 | ---[Official Documentation](https://tweaked.cc/library/cc.audio.dfpwm.html) 24 | local M = {} 25 | 26 | ---Create a new encoder for converting PCM audio data into DFPWM. 27 | --- 28 | ---The returned encode function accepts a table of amplitude data between -128 29 | ---and 127 and returns encoded DFPWM data. 30 | --- 31 | ---⚠️ **Warning**: Encoders contain lots of internal state. Reusing encoders for 32 | ---multiple streams can result in incorrect audio and is not recommended. 33 | ---@return fun(PCM: integer[]): string encoder 34 | --- 35 | ---[Official Documentation](https://tweaked.cc/library/cc.audio.dfpwm.html#v:make_encoder) 36 | function M.make_encoder() end 37 | 38 | ---Helper function for encoding an entire file of audio at once. 39 | --- 40 | ---If writing many chunks to the same file, use an encoder from `make_encoder` instead. 41 | ---@param PCM integer[] 42 | ---@return string DFPWM 43 | --- 44 | ---[Official Documentation](https://tweaked.cc/library/cc.audio.dfpwm.html#v:encode) 45 | function M.encode(PCM) end 46 | 47 | ---Create a new decoder for converting DFPWM into PCM audio data. 48 | --- 49 | ---The returned decoder function accepts a string of DFPWM data and returns a 50 | ---table of amplitudes between -128 and 127. 51 | --- 52 | ---⚠️ **Warning**: Decoders contain lots of internal state. Reusing decoders for 53 | ---multiple streams can result in incorrect audio and is not recommended. 54 | ---@return fun(DFPWM: string): integer[] 55 | --- 56 | ---[Official Documentation](https://tweaked.cc/library/cc.audio.dfpwm.html#v:make_decoder) 57 | function M.make_decoder() end 58 | 59 | ---Helper function for decoding an entire file of audio at once. 60 | --- 61 | ---If processing large files, you should instead read the file in chunks and 62 | ---process it using `make_decoder`. 63 | ---@param DFPWM string DFPWM data to convert 64 | ---@return integer[] PCM 65 | --- 66 | ---[Official Documentation](https://tweaked.cc/library/cc.audio.dfpwm.html#v:decode) 67 | function M.decode(DFPWM) end 68 | 69 | return M 70 | -------------------------------------------------------------------------------- /library/types/objects/peripheral/Modem.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---Modems allow you to send messages between computers over large distances 4 | --- 5 | ---🗒️The `rednet` API builds on top of modems and is more user-friendly 6 | --- 7 | ---Modems operate on channels. Any modem can send a message on a channel, but 8 | ---only those that have opened the channel are able to receive messages. 9 | --- 10 | ---Channels are an integer between 0 and 65535 (inclusive). While these channels 11 | ---have no initial significance, certain APIs or programs can make use of 12 | ---specififc channels. For example, the `gps` module sends all of its messages on 13 | ---`gps.CHANNEL_GPS` (default is 65534), while `rednet` uses the channel equal to 14 | ---the computer's ID 15 | --- 16 | ------ 17 | ---[Official Documentation](https://tweaked.cc/peripheral/modem.html) 18 | ---@class ccTweaked.peripheral.Modem 19 | Modem = {} 20 | 21 | ---Open a channel on a modem 22 | --- 23 | ---A channel must be open in order to receive messages on it 24 | --- 25 | ---Modem can have 128 channels open at one time 26 | ---@param channel ccTweaked.peripheral.channel The channel to open (0 - 65535) 27 | ---@throws If the `channel` is out of range 28 | ---@throws If there are too many open channels 29 | ------ 30 | ---[Official Documentation](https://tweaked.cc/peripheral/modem.html#v:open) 31 | function Modem.open(channel) end 32 | 33 | ---Check if a channel is open or not 34 | ---@param channel ccTweaked.peripheral.channel The channel to check (0 - 65535) 35 | ---@return boolean isOpen If the channel is open 36 | ---@throws If the `channel` is out of range 37 | ------ 38 | ---[Official Documentation](https://tweaked.cc/peripheral/modem.html#v:isOpen) 39 | function Modem.isOpen(channel) end 40 | 41 | ---Close an open channel so that it no longer receives messages 42 | ---@param channel ccTweaked.peripheral.channel The channel to close (0 - 65535) 43 | ---@throws If the `channel` is out of range 44 | ------ 45 | ---[Official Documentation](https://tweaked.cc/peripheral/modem.html#v:close) 46 | function Modem.close(channel) end 47 | 48 | ---Close all open channels 49 | --- 50 | ------ 51 | ---[Official Documentation](https://tweaked.cc/peripheral/modem.html#v:closeAll) 52 | function Modem.closeAll() end 53 | 54 | ---Sends a message on the specified channel over the modem 55 | --- 56 | ---Modems listening on the specified channel will queue a `modem_message` event 57 | ---on any parent computers 58 | ---@param channel ccTweaked.peripheral.channel The channel to send the message on (does not need to be open) 59 | ---@param replyChannel ccTweaked.peripheral.channel The channel that responses should be sent on. This can be the same channel, but it must be opened on this computer in order to receive the replies 60 | ---@param payload boolean|string|number|table The payload of the message to send 61 | ---@throws If the channel is out of range 62 | ---## Example 63 | ---``` 64 | ---local modem = peripheral.find("modem") or error("No modem attached", 0) 65 | ---modem.transmit(15, 43, "Hello, world!") 66 | ---``` 67 | ------ 68 | ---[Official Documentation](https://tweaked.cc/peripheral/modem.html#v:transmit) 69 | function Modem.transmit(channel, replyChannel, payload) end 70 | 71 | ---Get whether this modem is wireless or wired 72 | ---@return boolean isWireless If this modem is wireless 73 | ------ 74 | ---[Official Documentation](https://tweaked.cc/peripheral/modem.html#v:isWireless) 75 | function Modem.isWireless() end 76 | -------------------------------------------------------------------------------- /library/multishell.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---Multishell can be used to run multiple programs at the same time 4 | --- 5 | ---Multishell is a program that injects its API into the shell's environment and 6 | ---it is only available on advance computers 7 | --- 8 | ---When multiple programs are running, a tab bar at the top of the screen 9 | ---appears, allow you to switch between programs. New shells can be launched 10 | ---using the `bg` or `fg` programs, by using `shell.openTab()` or 11 | ---`multishell.launch()`. 12 | --- 13 | ---Each process is identified by its PID (process ID), which corresponds to its position in 14 | ---the tab list. As these positions can change, the **PID is not constant**. 15 | ------ 16 | ---[Official Documentation](https://tweaked.cc/module/multishell.html) 17 | multishell = {} 18 | 19 | ---Get the currently opened/visible process. This is the currently selected 20 | ---process from the tab bar. 21 | ---@return ccTweaked.multishell.PID PID The ID of the focused process 22 | ------ 23 | ---[Official Documentation](https://tweaked.cc/module/multishell.html#v:getFocus) 24 | function multishell.getFocus() end 25 | 26 | ---Set the currently opened/visible process 27 | ---@param PID ccTweaked.multishell.PID The ID of the process to focus 28 | ---@return boolean success If the process was successfully changed. This will be `false` if there is no process with the given `PID` 29 | ------ 30 | ---[Official Documentation](https://tweaked.cc/module/multishell.html#v:setFocus) 31 | function multishell.setFocus(PID) end 32 | 33 | ---Get the title of the tab for the given process 34 | ---@param PID ccTweaked.multishell.PID The ID of the process to get the title of 35 | ---@return string|nil title The title of the process or `nil` if the process doesn't exist 36 | ------ 37 | ---[Official Documentation](https://tweaked.cc/module/multishell.html#v:getTitle) 38 | function multishell.getTitle(PID) end 39 | 40 | ---Set the title of the tab for the given process 41 | ---@param PID ccTweaked.multishell.PID The ID of the process that will have its title set 42 | ---@param title string The new title to set for the process 43 | ------ 44 | ---[Official Documentation](https://tweaked.cc/module/multishell.html#v:setTitle) 45 | function multishell.setTitle(PID, title) end 46 | 47 | ---Get the `PID` of the currently running process 48 | ---@return ccTweaked.multishell.PID PID The ID of the currently running process 49 | ------ 50 | ---[Official Documentation](https://tweaked.cc/module/multishell.html#v:getCurrent) 51 | function multishell.getCurrent() end 52 | 53 | ---Launch a new process in multishell mode 54 | ---@param env table The environment to load the path under. For example, passing `_E` will pass the environment you are currently using. 55 | ---@param path ccTweaked.fs.path The path to the program to launch 56 | ---@param ... any Additional arguments to pass to the program 57 | ---@return ccTweaked.multishell.PID PID The ID of the created process 58 | ---## Example 59 | ---``` 60 | ---local pENV = {} 61 | ---local path = "/add.lua" 62 | ---local PID = multishell.launch(pENV, path, 2, 2) 63 | ---multishell.setTitle(PID, "2+2=4") 64 | ---``` 65 | ------ 66 | ---[Official Documentation](https://tweaked.cc/module/multishell.html#v:launch) 67 | function multishell.launch(env, path, ...) end 68 | 69 | ---Get the number of concurrent processes within this multishell 70 | ---@return number count The number of processes running 71 | ------ 72 | ---[Official Documentation](https://tweaked.cc/module/multishell.html#v:getCount) 73 | function multishell.getCount() end 74 | -------------------------------------------------------------------------------- /library/types/objects/http/BinaryResponse.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---A HTTP response. This provides the same methods as a file as well as some response-specific methods 4 | ---@class ccTweaked.http.BinaryResponse 5 | ------ 6 | ---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response) 7 | BinaryResponse = {} 8 | 9 | ---Get the response code and message returned by the server 10 | ---@return number code The response code (e.g. 200) 11 | ---@return string message The response message (e.g. "OK") 12 | ------ 13 | ---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response:getResponseCode) 14 | function BinaryResponse.getResponseCode() end 15 | 16 | ---Get the [response headers](https://developer.mozilla.org/en-US/docs/Glossary/Response_header) 17 | --- 18 | ---If multiple headers are sent with the same name, they will be combined with a 19 | ---comma 20 | ---@return table 21 | ------ 22 | ---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response:getResponseHeaders) 23 | function BinaryResponse.getResponseHeaders() end 24 | 25 | ---Read a single line from the response 26 | ---@param includeNewline? boolean If any trailing newline characters should be included. Defaults to false 27 | ---@return string|nil line The read line or nil if the end of the response has been reached 28 | ---@throws If the response has been closed 29 | ------ 30 | ---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response) 31 | function BinaryResponse.readLine(includeNewline) end 32 | 33 | ---Read the remainder of the response 34 | ---@return string|nil contents The remaining contents of the response or nil if at the end of the response 35 | ---@throws If the response has been closed 36 | ------ 37 | ---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response) 38 | function BinaryResponse.readAll() end 39 | 40 | ---Read a number of bytes from the response 41 | ---@param count number The number of bytes to read 42 | ---@return string|nil byte The byte as a string or nil when the end of the response is reached 43 | ---@throws When trying to read a negative number of bytes 44 | ---@throws If the response has been closed 45 | ------ 46 | ---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response) 47 | function BinaryResponse.read(count) end 48 | 49 | ---Read a byte from the response 50 | ---@return ccTweaked.fs.ASCII|nil byte The byte as an [ASCII code](https://www.rapidtables.com/code/text/ascii-table.html) 51 | ---@throws If the response has been closed 52 | ------ 53 | ---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response) 54 | function BinaryResponse.read() end 55 | 56 | ---Close the response 57 | --- 58 | ---Once closed, it can no longer be read unless it is re-requested 59 | ---@throws If the response has already been closed 60 | ------ 61 | ---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response) 62 | function BinaryResponse.close() end 63 | 64 | ---Seek to a new position in the response. The new position is an offset relative to `whence` 65 | ---@param whence ccTweaked.fs.seekWhence What `offset` is relative to 66 | ---@param offset number The offset to seek to 67 | ---@return number|nil newPosition The new response read position relative to the start of the response or nil if seeking failed 68 | ---@return string|nil errorMessage The reason seeking failed 69 | ---@throws If the response has been closed 70 | ------ 71 | ---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response) 72 | function BinaryResponse.seek(whence, offset) end 73 | -------------------------------------------------------------------------------- /library/types/objects/peripheral/WiredModem.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---Modems allow you to send messages between computers over large distances 4 | --- 5 | ---🗒️The `rednet` API builds on top of modems and is more user-friendly 6 | --- 7 | ---Modems operate on channels. Any modem can send a message on a channel, but 8 | ---only those that have opened the channel are able to receive messages. 9 | --- 10 | ---Channels are an integer between 0 and 65535 (inclusive). While these channels 11 | ---have no initial significance, certain APIs or programs can make use of 12 | ---specififc channels. For example, the `gps` module sends all of its messages on 13 | ---`gps.CHANNEL_GPS` (default is 65534), while `rednet` uses the channel equal to 14 | ---the computer's ID 15 | --- 16 | ------ 17 | ---[Official Documentation](https://tweaked.cc/peripheral/modem.html) 18 | ---@class ccTweaked.peripheral.WiredModem: ccTweaked.peripheral.Modem 19 | WiredModem = {} 20 | 21 | ---List all peripherals on the wired network 22 | --- 23 | ---If this computer is attached to the network, it **will not** be included in this list 24 | ---@return string[] peripherals Remote peripheral names on the network 25 | ------ 26 | ---[Official Documentation](https://tweaked.cc/peripheral/modem.html#v:getNamesRemote) 27 | function WiredModem.getNamesRemote() end 28 | 29 | ---Get if a peripheral is available on this wired network 30 | ---@param name string The peripheral's name 31 | ---@return boolean isPresent If a peripheral with the given name is present 32 | ------ 33 | ---[Official Documentation](https://tweaked.cc/peripheral/modem.html#v:isPresentRemote) 34 | function WiredModem.isPresentRemote(name) end 35 | 36 | ---Get the type of a peripheral on this wired network 37 | ---@param name string The peripheral's name 38 | ---@return ccTweaked.peripheral.peripheralType|nil type The peripheral's type or `nil` if it is not present 39 | ------ 40 | ---[Official Documentation](https://tweaked.cc/peripheral/modem.html#v:getTypeRemote) 41 | function WiredModem.getTypeRemote(name) end 42 | 43 | ---Check that a peripheral is of a given type 44 | ---@param name string The peripheral's name 45 | ---@param type ccTweaked.peripheral.peripheralType The type to check 46 | ---@return boolean|nil isType If a peripheral has a given type or `nil` if it is not present 47 | ------ 48 | ---[Official Documentation](https://tweaked.cc/peripheral/modem.html#v:hasTypeRemote) 49 | function WiredModem.hasTypeRemote(name, type) end 50 | 51 | ---Get the names of the methods for a peripheral with the provided name 52 | ---@param name string The peripheral's name 53 | ---@return string[]|nil methods An array of method names or `nil` if it is not present 54 | ------ 55 | ---[Official Documentation](https://tweaked.cc/peripheral/modem.html#v:getMethodsRemote) 56 | function WiredModem.getMethodsRemote(name) end 57 | 58 | ---Call a method on a peripheral on this wired network 59 | ---@param name string The name of the peripheral to invoke the method on 60 | ---@param method string The name of the method to call 61 | ---@param ... any Args to pass to the method 62 | ---@return any ... The return values of the method 63 | ------ 64 | ---[Official Documentation](https://tweaked.cc/peripheral/modem.html#v:callRemote) 65 | function WiredModem.callRemote(name, method, ...) end 66 | 67 | ---Get the network name of the current computer, if the modem is on 68 | ---@return string|nil name The current computer's name on the wired network on `nil` if the modem is off 69 | ------ 70 | ---[Official Documentation](https://tweaked.cc/peripheral/modem.html#v:getNameLocal) 71 | function WiredModem.getNameLocal() end 72 | -------------------------------------------------------------------------------- /library/types/objects/peripheral/Speaker.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---The speaker peripheral allows you to play music discs, notes, Minecraft 4 | ---sounds, and custom audio 5 | --- 6 | ------ 7 | ---[Official Documentation](https://tweaked.cc/peripheral/speaker.html) 8 | ---@class ccTweaked.peripheral.Speaker 9 | Speaker = {} 10 | 11 | ---Plays a note through the speaker 12 | --- 13 | ---The pitch argument uses semitones as the unit. This directly maps to the number of clicks on a note block. For reference, 0, 12, and 24 map to F#, and 6 and 18 map to C. 14 | --- 15 | ---A maximum of 8 notes can be played in a single tick. If this limit is hit, this function will return false. 16 | ---@param instrument ccTweaked.peripheral.instrument The instrument to play on 17 | ---@param volume? number The volume to play at (0.0 - 3.0, defaults to 1.0) 18 | ---@param pitch? number The pitch to play at in semitones from 0 to 24 (defaults to 12) 19 | ---@return boolean success If the note could be played or if the limit was reached 20 | ---@throws If the `instrument` does not exist 21 | ------ 22 | ---[Official Documentation](https://tweaked.cc/peripheral/speaker.html#v:playNote) 23 | function Speaker.playNote(instrument, volume, pitch) end 24 | 25 | ---Play a Minecraft sound through the speaker 26 | --- 27 | ---Only one sound can be played at once. This function will return false if 28 | ---another sound was started this tick, or if some audio is still playing. 29 | ---@param name ccTweaked.peripheral.soundEffect The name of the sound to play 30 | ---@param volume? number The volume to play at (0.0 - 3.0, defaults to 1.0) 31 | ---@param pitch? number The speed to play at (0.5 - 2.0, defaults to 12) 32 | ---@return boolean success If the sound could be played 33 | ---@throws If the sound name was invalid 34 | ---## Example 35 | ---``` 36 | ---local speaker = peripheral.find("speaker") 37 | ---speaker.playSound("entity.creeper.primed") 38 | ---``` 39 | ------ 40 | ---[Official Documentation](https://tweaked.cc/peripheral/speaker.html#v:playSound) 41 | function Speaker.playSound(name, volume, pitch) end 42 | 43 | ---Attempt to stream audio to the speaker 44 | --- 45 | ---This accepts a list of audio samples as amplitudes between -128 and 127. 46 | ---These are stored in an internal buffer and played back at 48kHz. If this 47 | ---buffer is full, this function will return false. You should wait for a 48 | ---`speaker_audio_empty` event before trying again. 49 | --- 50 | ---🗒️ The speaker only buffers a single call to `playAudio()` at once. This means 51 | ---if you try to play a small number of samples, you'll have a lot of stutter. 52 | ---You should try to play as many samples in one call as possible (up to 53 | ---128×1024), as this reduces the chances of audio stuttering or halting, 54 | ---especially when the server or computer is lagging. 55 | ---@param audio number[] An array of amplitudes 56 | ---@param volume? number The volume to play the audio at. Defaults to the previous value given 57 | ---@return boolean success If there was room to accept the audio data 58 | ---@throws If the audio data is malformed 59 | ---## Example 60 | ---``` 61 | ---local dfpwm = require("cc.audio.dfpwm") 62 | ---local speaker = peripheral.find("speaker") 63 | --- 64 | ---local decoder = dfpwm.make_decoder() 65 | ---for chunk in io.lines("data/example.dfpwm", 16 * 1024) do 66 | --- local buffer = decoder(chunk) 67 | --- 68 | --- while not speaker.playAudio(buffer) do 69 | --- os.pullEvent("speaker_audio_empty") 70 | --- end 71 | ---end 72 | ---``` 73 | ------ 74 | ---[Official Documentation](https://tweaked.cc/peripheral/speaker.html#v:playAudio) 75 | function Speaker.playAudio(audio, volume) end 76 | 77 | ---Stop all audio being played by this speaker 78 | --- 79 | ------ 80 | ---[Official Documentation](https://tweaked.cc/peripheral/speaker.html#v:stop) 81 | function Speaker.stop() end 82 | -------------------------------------------------------------------------------- /library/commands.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---Execute [Minecraft Commands](https://minecraft.gamepedia.com/Commands) using 4 | ---a command computer 5 | --- 6 | ---This API is only available on command computers and is not accessible by 7 | ---normal players 8 | --- 9 | ------ 10 | ---[Official Documentation](https://tweaked.cc/module/commands.html) 11 | commands = {} 12 | 13 | ---The builtin commands API, without any generated command helper functions 14 | --- 15 | ------ 16 | ---[Official Documentation](https://tweaked.cc/module/commands.html#v:native) 17 | commands.native = {} 18 | 19 | ---A table of asynchronous wrappers for all commands 20 | --- 21 | ---These functions return a "task ID" 22 | --- 23 | ------ 24 | ---[Official Documentation](https://tweaked.cc/module/commands.html#v:async) 25 | commands.async = {} 26 | 27 | ---Execute a command 28 | ---@param command string The command to execute 29 | ---@return boolean success If the command executed successfully 30 | ---@return string[] output The output of this command as an array of lines 31 | ---@return number|nil affected The number of "affected" objects or `nil` if the command failed 32 | ------ 33 | ---[Official Documentation](https://tweaked.cc/module/commands.html#v:exec) 34 | function commands.exec(command) end 35 | 36 | ---Execute a command asynchronously 37 | --- 38 | ---This will return immediately and fire a `task_complete` event when it completes 39 | ---@async 40 | ---@param command string The command to execute 41 | ---@return integer taskID The ID of this task, useful for checking that the `task_complete` event is meant for this task 42 | ------ 43 | ---[Official Documentation](https://tweaked.cc/module/commands.html#v:execAsync) 44 | function commands.execAsync(command) end 45 | 46 | ---List all commands this computer has permission to execute 47 | ---@param command? string The command to complete 48 | ---@return string[] commands An array of available commands 49 | ------ 50 | ---[Official Documentation](https://tweaked.cc/module/commands.html#v:list) 51 | function commands.list(command) end 52 | 53 | ---Get the position of the current computer 54 | ---@return number x The current x position 55 | ---@return number y The current y position 56 | ---@return number z The current z position 57 | ------ 58 | ---[Official Documentation](https://tweaked.cc/module/commands.html#v:getBlockPosition) 59 | function commands.getBlockPosition() end 60 | 61 | ---Get information about a range of blocks 62 | --- 63 | ---Blocks are traversed by ascending y level, followed by z and x - the returned 64 | --table may be indexed using `x + z * width + y * depth * depth`. 65 | ---@param minX number The x coordinate to start querying at 66 | ---@param minY number The y coordinate to start querying at 67 | ---@param minZ number The z coordinate to start querying at 68 | ---@param maxX number The x coordinate to stop querying at 69 | ---@param maxY number the y coordinate to stop querying at 70 | ---@param maxZ number The z coordinate to stop querying at 71 | ---@param dimension? string The dimension to query (defaults to current) 72 | ---@return ccTweaked.turtle.turtleDetails[] details An array of details on each block 73 | ---@throws If the coordinates are not within the world 74 | ---@throws If trying to get info about more than 4096 blocks 75 | ------ 76 | ---[Official Documentation](https://tweaked.cc/module/commands.html#v:getBlockInfos) 77 | function commands.getBlockInfos(minX, minY, minZ, maxX, maxY, maxZ, dimension) end 78 | 79 | ---Get some basic info on a block 80 | ---@param x number The x position to query 81 | ---@param y number The y position to query 82 | ---@param z number The z position to query 83 | ---@param dimension? string The dimension to query (defaults to current) 84 | ---@return ccTweaked.turtle.turtleDetails 85 | ---@throws If the coordinates are not within the world or are not currently loaded 86 | function commands.getBlockInfo(x, y, z, dimension) end 87 | -------------------------------------------------------------------------------- /library/settings.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---The settings API provides a way for you to read and write settings for 4 | ---CraftOS and your programs 5 | --- 6 | ---By default, the settings API will load its configuration from the /.settings 7 | ---file. One can then use settings.save to update the file 8 | --- 9 | ------ 10 | ---[Official Documentation](https://tweaked.cc/module/settings.html) 11 | settings = {} 12 | 13 | ---Define a new setting 14 | ---@param name string The name of this option 15 | ---@param options? ccTweaked.settings.settingOptions The options of this setting 16 | ------ 17 | ---[Official Documentation](https://tweaked.cc/module/settings.html#v:define) 18 | function settings.define(name, options) end 19 | 20 | ---Remove a setting definition 21 | --- 22 | ---This does not remove the value of a set setting, `settings.unset()` can be 23 | ---used for that 24 | ---@param name string The name of the setting to delete 25 | ------ 26 | ---[Official Documentation](https://tweaked.cc/module/settings.html#v:undefine) 27 | function settings.undefine(name) end 28 | 29 | ---Set the value of a setting 30 | ---@param name string The name of the setting to set 31 | ---@param value string|boolean|number|table The new value for the setting, cannot be nil 32 | ---@throws If the value cannot be serialized by `textutils.serialize()` 33 | ------ 34 | ---[Official Documentation](https://tweaked.cc/module/settings.html#v:set) 35 | function settings.set(name, value) end 36 | 37 | ---Get the value of a setting 38 | ---@param name string The name of the setting to get 39 | ---@param default? any The value to default to. If omitted, the default will be the setting's default value if it is defined or `nil` otherwise 40 | ---@return any value The setting's value or the default value 41 | ------ 42 | ---[Official Documentation](https://tweaked.cc/module/settings.html#v:get) 43 | function settings.get(name, default) end 44 | 45 | ---Get details on a specific setting 46 | ---@param name string The name of the setting to get 47 | ---@return settingDetails details The details of this setting 48 | ------ 49 | ---[Official Documentation](https://tweaked.cc/module/settings.html#v:getDetails) 50 | function settings.getDetails(name) end 51 | 52 | ---Remove the value of a setting, setting it to it's default value 53 | --- 54 | ---`settings.get()` will return the default value until the setting's value is set or the computer is rebooted 55 | ---@param name string The name of the setting to unset 56 | ------ 57 | ---[Official Documentation](https://tweaked.cc/module/settings.html#v:unset) 58 | function settings.unset(name) end 59 | 60 | ---Reset the value of all settings to their defaults 61 | --- 62 | ------ 63 | ---[Official Documentation](https://tweaked.cc/module/settings.html#v:clear) 64 | function settings.clear() end 65 | 66 | ---Get the names of all currently defined settings 67 | ---@return string[] settings An alphabetically sorted array of all currently defined settings 68 | ------ 69 | ---[Official Documentation](https://tweaked.cc/module/settings.html#v:getNames) 70 | function settings.getNames() end 71 | 72 | ---Load settings from a file 73 | --- 74 | ---The two configurations will be merged where conflicting entries will be 75 | ---overwritten by this new file 76 | ---@param path? ccTweaked.fs.path The path to load the settings from (defaults to `.settings`) 77 | ---@return boolean success If the file was successfully loaded. This could fail due to not having permission to read the file, the file doesn't exist, or it is corrupted 78 | ------ 79 | ---[Official Documentation](https://tweaked.cc/module/settings.html#v:load) 80 | function settings.load(path) end 81 | 82 | ---Save settings to a file 83 | --- 84 | ---This will completely overwrite the target file 85 | ---@param path ccTweaked.fs.path? The path to save the file to (defaults to `.settings`) 86 | ---@return boolean success If the settings were successfully saved 87 | function settings.save(path) end 88 | -------------------------------------------------------------------------------- /library/globals.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | ---Functions defined in `bios.lua` that are in the global (_G) environment. 3 | 4 | ---Stores the current ComputerCraft and Minecraft versions, for example: 5 | ---`ComputerCraft 1.93.0 (Minecraft 1.15.2)` 6 | ---@type string 7 | _HOST = nil 8 | 9 | ---Stores the default settings as a comma-separated string as defined in the 10 | ---ComputerCraft configuration file. By default, is an empty string. 11 | ---@type string 12 | _CC_DEFAULT_SETTINGS = nil 13 | 14 | ---Pauses execution for the specified number of seconds. 15 | ---@param time number? The number of seconds to sleep for, rounded up to the nearest multiple of 0.05 16 | ---As it waits for a fixed amount of world ticks, time will automatically be 17 | ---rounded up to the nearest multiple of 0.05 seconds. If you are using 18 | ---coroutines or the parallel API, it will only pause execution of the current 19 | ---thread, not the whole program. 20 | ---## Example 21 | ---``` 22 | ---print("Going to sleep for 2 seconds!") 23 | ---sleep(2) 24 | ---print("Slept for 2 seconds!") 25 | ---``` 26 | ------ 27 | ---[Official Documentation](https://tweaked.cc/module/_G.html#v:sleep) 28 | function sleep(time) end 29 | 30 | ---Writes text to the screen with no trailing newline. Wraps text when needed. 31 | ---@param text string 32 | ---@return number lines The number of lines written 33 | ---## Example 34 | ---``` 35 | ---write("Hello World!") 36 | ---``` 37 | ------ 38 | ---[Official Documentation](https://tweaked.cc/module/_G.html#v:write) 39 | function write(text) end 40 | 41 | ---Prints the specified values to the screen, separated by spaces, wrapping when 42 | ---necessary. After printing the cursor is moved to the next line. 43 | ---@vararg any 44 | ---@return number lines The number of lines written 45 | ---## Example 46 | ---``` 47 | ---print("Hello", "World!") 48 | ---``` 49 | ------ 50 | ---[Official Documentation](https://tweaked.cc/module/_G.html#v:print) 51 | function print(...) end 52 | 53 | ---Prints the specified values to the screen in red, separated by spaces, 54 | --wrapping when necessary. After printing, the cursor is moved to the next line. 55 | ---@param ... unknown 56 | ---## Example 57 | ---``` 58 | ---printError("Something has gone terribly wrong!") 59 | ---``` 60 | ------ 61 | ---[Official Documentation](https://tweaked.cc/module/_G.html#v:printError) 62 | function printError(...) end 63 | 64 | ---Reads user input from the terminal. This automatically handles arrow keys, 65 | --pasting, character replacement, history scrollback, auto-completion, and 66 | --default values. 67 | ---@param replaceCharacter? string A character to replace each typed character. Useful for hiding passwords. 68 | ---@param history? string[] An array of strings that can be scrolled through with the arrow keys. Oldest item should be index 1 and the newest should be the highest index. 69 | ---@param completeFunction? fun(partial: string):string[] A function for completing text. The function should take the partially entered text and return an array of suggestions. 70 | ---@param default? string Text that should already be entered by default 71 | ---## Example 72 | ---Prompt user for a password 73 | ---``` 74 | ---while true do 75 | --- write("Password> ") 76 | --- local pwd = read("*") 77 | --- if pwd == "let me in" then break end 78 | --- print("Incorrect password, try again.") 79 | ---end 80 | ---print("Logged in!") 81 | ---``` 82 | ---## Example 2 83 | ---Offer history, completion, and a default value 84 | ---``` 85 | ---local completion = require "cc.completion" 86 | ---local history = { "potato", "orange", "apple" } 87 | ---local choices = { "apple", "orange", "banana", "strawberry" } 88 | ---write("> ") 89 | ---local msg = read(nil, history, function(text) return completion.choice(text, choices) end, "app") 90 | ---print(msg) 91 | ---``` 92 | ------ 93 | ---[Official Documentation](https://tweaked.cc/module/_G.html#v:read) 94 | function read(replaceCharacter, history, completeFunction, default) end 95 | -------------------------------------------------------------------------------- /library/types/objects/file/Handle.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---A file handle which can be read from and written to. Contains 4 | ---[methods](https://www.lua.org/pil/16.html#:~:text=This%20use%20of,method%20call%20as) 5 | ---for editing files. 6 | --- 7 | ---Make sure you are calling these methods like so: `myHandle:read()` 8 | --- 9 | ------ 10 | ---[Official Documentation](https://tweaked.cc/module/io.html#ty:Handle) 11 | ---@class ccTweaked.fs.Handle 12 | Handle = {} 13 | 14 | ---Close the file, freeing it 15 | ---@return true|nil success If the file was closed 16 | ---@return nil|string reason The reason it couldn't be closed 17 | ---@throws If the handle is already closed 18 | ------ 19 | ---[Official Documentation](https://tweaked.cc/module/io.html#ty:Handle:close) 20 | function Handle:close() end 21 | 22 | ---Flush any buffered output, forcing it to be written to the file 23 | ---@throws If the file has been closed 24 | ------ 25 | ---[Official Documentation](https://tweaked.cc/module/io.html#ty:Handle:flush) 26 | function Handle:flush() end 27 | 28 | ---Returns an iterator that returns a new line from the file each time it is 29 | ---called. When the end of the file has been reached, returns `nil` 30 | --- 31 | ---Useful for looping over all lines in a file 32 | ---@param format ccTweaked.io.readFormat The format each line should be read with 33 | ---@return fun(): string|nil iterator The line iterator 34 | ---@throws If the file cannot be opened for reading 35 | ---⚠️ The file is not automatically closed when the end of the file is reached 36 | --- 37 | ---❗Passing `"a"` as a format will result in an infinite loop and will crash your script after timing out 38 | ---## Example 39 | ---``` 40 | ---local file = io.open("/rom/help/intro.txt") 41 | --- 42 | -----Iterate over all lines in a file 43 | -----Read each line with a trailing newline 44 | ---for line in file:lines("L") do 45 | --- print(line) 46 | ---end 47 | --- 48 | ---file:close() 49 | ---``` 50 | ------ 51 | ---[Official Documentation](https://tweaked.cc/module/io.html#ty:Handle:lines) 52 | function Handle:lines(format) end 53 | 54 | ---Read data from the file using the specified format. For each format provided, 55 | ---returns either the data read or `nil` if no data could be read. 56 | ---@param ... ccTweaked.io.readFormat The formats to use for reading. Defaults to `l` 57 | ---@return string ... The data (as a string) read from the file or nil if no data could be read. 58 | ------ 59 | ---[Official Documentation](https://tweaked.cc/module/io.html#ty:Handle:read) 60 | function Handle:read(...) end 61 | 62 | ---Seek to a new position in the file. The new position is an offset relative to `whence` 63 | --- 64 | ---Only available if the handle was opened in binary mode 65 | ---@param whence? ccTweaked.fs.seekWhence What `offset` is relative to. Defaults to `cur` 66 | ---@param offset? number The offset to seek to. Defaults to 0 67 | ---@return number|nil newPosition The new file read position relative to the start of the file or nil if seeking failed 68 | ---@return string|nil errorMessage The reason seeking failed 69 | ---@throws If the file has been closed 70 | ------ 71 | ---[Official Documentation](https://tweaked.cc/module/io.html#ty:Handle:seek) 72 | function Handle:seek(whence, offset) end 73 | 74 | ---Set the buffering mode 75 | ---@param mode "no"|"full"|"line" The buffering mode to use 76 | ---@param size number The buffer size in bytes 77 | ---@deprecated 78 | ---[See Lua Documentation](https://www.lua.org/manual/5.1/manual.html#pdf-file:setvbuf) 79 | --- 80 | ---🚮 Deprecated, has no effect in ComputerCraft 81 | --- 82 | ------ 83 | ---[Official Documentation](https://tweaked.cc/module/io.html#ty:Handle:setvbuf) 84 | function Handle:setvbuf(mode, size) end 85 | 86 | ---Write one or more values to the file 87 | ---@param ... string|number The values to write 88 | ---@return ccTweaked.fs.Handle|nil self Returns this handler so you can chain calls. Possibly nil if file could not be written to 89 | ---@return nil|string errorMessage The reason the file couldn't be written to 90 | ---@throws If the file has been closed 91 | --- 92 | ------ 93 | ---[Official Documentation](https://tweaked.cc/module/io.html#ty:Handle:write) 94 | function Handle:write(...) end 95 | -------------------------------------------------------------------------------- /library/types/objects/peripheral/Inventory.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---Methods for interacting with inventories 4 | --- 5 | ------ 6 | ---[Official Documentation](https://tweaked.cc/generic_peripheral/inventory.html) 7 | ---@class ccTweaked.peripheral.Inventory 8 | Inventory = {} 9 | 10 | ---Get the size of this inventory 11 | ---@return number slots The number of slots in this inventory 12 | ------ 13 | ---[Official Documentation](https://tweaked.cc/generic_peripheral/inventory.html#v:size) 14 | function Inventory.size() end 15 | 16 | ---List all items in this inventory 17 | --- 18 | ---Each item in the inventory is represented by a table containing some basic 19 | ---information, much like turtle.getItemDetail includes. More information can be 20 | ---fetched with getItemDetail. The table contains the item name, the count and an 21 | ---a (potentially nil) hash of the item's nbt. This NBT data doesn't contain 22 | ---anything useful, but allows you to distinguish identical items. 23 | --- 24 | ---The returned table is sparse, and so empty slots will be nil - it is 25 | ---recommended to loop over using pairs rather than ipairs. 26 | ---@return ccTweaked.peripheral.itemList list The list of items in this inventory 27 | ---## Example 28 | ---``` 29 | ---local chest = peripheral.find("minecraft:chest") 30 | -----print all items in the adjacent chest 31 | ---for slot, item in pairs(chest.list()) do 32 | --- print(("%d x %s in slot %d"):format(item.count, item.name, slot)) 33 | ---end 34 | ---``` 35 | ------ 36 | ---[Official Documentation](https://tweaked.cc/generic_peripheral/inventory.html#v:list) 37 | function Inventory.list() end 38 | 39 | ---Get detailed information about an item in this inventory 40 | ---@param slot integer The slot to get more info about 41 | ---@return table|nil info Information about the item in the slot or `nil` if no item is present 42 | ---@throws If the slot is out of range 43 | ------ 44 | ---[Official Documentation](https://tweaked.cc/generic_peripheral/inventory.html#v:getItemDetail) 45 | function Inventory.getItemDetail(slot) end 46 | 47 | ---Get the maximum quantity of items that can be stored in this stack 48 | ---@param slot integer The slot to check 49 | ---@return integer limit The maximum number of items that can be in this stack 50 | ---@throws If the slot is out of range 51 | ------ 52 | ---[Official Documentation](https://tweaked.cc/generic_peripheral/inventory.html#v:getItemLimit) 53 | function Inventory.getItemLimit(slot) end 54 | 55 | ---Push items from this inventory to another 56 | ---@param toName string The name of the inventory to push to 57 | ---@param sourceSlot integer The slot from this inventory to push from 58 | ---@param limit? integer The maximum number of items to move (default is the stack limit) 59 | ---@param targetSlot? integer The slot in the target inventory to push the items into (by default will insert into any slot) 60 | ---@return integer quantity The number of items transferred 61 | ---@throws If the target inventory doesn't exist 62 | ---@throws If the target inventory isn't an inventory 63 | ---@throws If the `sourceSlot` is out of range 64 | ---@throws If the `targetSlot` is out of range 65 | ------ 66 | ---[Official Documentation](https://tweaked.cc/generic_peripheral/inventory.html#v:pushItems) 67 | function Inventory.pushItems(toName, sourceSlot, limit, targetSlot) end 68 | 69 | ---Pull items from another inventory into this one 70 | ---@param sourceName string The name of the inventory to pull from 71 | ---@param sourceSlot integer The slot of the source inventory to pull from 72 | ---@param limit? integer The maximum number of items to move (default is the stack limit) 73 | ---@param targetSlot? integer The slot in this inventory to push the items into (by default will insert into any slot) 74 | ---@return integer quantity The number of items transferred 75 | ---@throws If the source inventory doesn't exist 76 | ---@throws If the source inventory isn't an inventory 77 | ---@throws If the `sourceSlot` is out of range 78 | ---@throws If the `targetSlot` is out of range 79 | ------ 80 | ---[Official Documentation](https://tweaked.cc/generic_peripheral/inventory.html#v:pullItems) 81 | function Inventory.pullItems(sourceName, sourceSlot, limit, targetSlot) end 82 | -------------------------------------------------------------------------------- /library/paintutils.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---Contains utilities for drawing graphics such as pixels, lines, and images 4 | --- 5 | ------ 6 | ---[Official Documentation](https://tweaked.cc/module/paintutils.html) 7 | paintutils = {} 8 | 9 | ---Parse an image from a multi-line string 10 | ---@param image string A string containing the raw image data 11 | ---@return table imageData The parsed image data, for use with `paintutils.drawImage()` 12 | ------ 13 | ---[Official Documentation](https://tweaked.cc/module/paintutils.html#v:parseImage) 14 | function paintutils.parseImage(image) end 15 | 16 | ---Loads an image from a file 17 | --- 18 | ---These image files can be created using the `paint` program 19 | ---@param path ccTweaked.fs.path The file to load 20 | ---@return table|nil imageData The parsed image data, for use with `paintutils.drawImage()`, or `nil` if the file does not exist 21 | ---## Example 22 | ---``` 23 | ---local image = paintutils.loadImage("data/example.nfp") 24 | ---paintutils.drawImage(image, term.getCursorPos()) 25 | ---``` 26 | ------ 27 | ---[Official Documentation](https://tweaked.cc/module/paintutils.html#v:loadImage) 28 | function paintutils.loadImage(path) end 29 | 30 | ---Draws a single pixel to the current terminal 31 | --- 32 | ---`1, 1` is the top left of the terminal screen 33 | --- 34 | ---⚠️ This may change the position of the cursor and the background color. Neither may be preserved 35 | ---@param x number The x position to draw at 36 | ---@param y number The y position to draw at 37 | ---@param color? ccTweaked.colors.color The color to use for this pixel. If omitted, the color will default to the current background color 38 | ------ 39 | ---[Official Documentation](https://tweaked.cc/module/paintutils.html#v:drawPixel) 40 | function paintutils.drawPixel(x, y, color) end 41 | 42 | ---Draws a straight line between the two coordinates to the current terminal 43 | --- 44 | ---`1, 1` is the top left of the terminal screen 45 | --- 46 | ---⚠️ This may change the position of the cursor and the background color. Neither may be preserved 47 | ---@param x number The x position to start drawing at 48 | ---@param y number The y position to start drawing at 49 | ---@param x2 number The x position to stop drawing at 50 | ---@param y2 number The y position to stop drawing at 51 | ---@param color? ccTweaked.colors.color The color to use for this line. If omitted, the color will default to the current background color 52 | ------ 53 | ---[Official Documentation](https://tweaked.cc/module/paintutils.html#v:drawLine) 54 | function paintutils.drawLine(x, y, x2, y2, color) end 55 | 56 | ---Draws the outline if a box to the current terminal 57 | --- 58 | ---`1, 1` is the top left of the terminal screen 59 | --- 60 | ---⚠️ This may change the position of the cursor and the background color. Neither may be preserved 61 | ---@param x number The x position to start drawing at 62 | ---@param y number The y position to start drawing at 63 | ---@param x2 number The x position to stop drawing at 64 | ---@param y2 number The y position to stop drawing at 65 | ---@param color? ccTweaked.colors.color The color to use for this box. If omitted, the color will default to the current background color 66 | ------ 67 | ---[Official Documentation](https://tweaked.cc/module/paintutils.html#v:drawBox) 68 | function paintutils.drawBox(x, y, x2, y2, color) end 69 | 70 | ---Draws a filled box to the current terminal 71 | --- 72 | ---`1, 1` is the top left of the terminal screen 73 | --- 74 | ---⚠️ This may change the position of the cursor and the background color. Neither may be preserved 75 | ---@param x number The x position to start drawing at 76 | ---@param y number The y position to start drawing at 77 | ---@param x2 number The x position to stop drawing at 78 | ---@param y2 number The y position to stop drawing at 79 | ---@param color? ccTweaked.colors.color The color to use for this box. If omitted, the color will default to the current background color 80 | ------ 81 | ---[Official Documentation](https://tweaked.cc/module/paintutils.html#v:drawFilledBox) 82 | function paintutils.drawFilledBox(x, y, x2, y2, color) end 83 | 84 | ---Draw an image that was loaded by `paintutils.parseImage()` or `paintutils.loadImage()` 85 | ---@param image table The parsed image data 86 | ---@param x number The x position to start drawing at 87 | ---@param y number The y position to start drawing at 88 | ------ 89 | ---[Official Documentation](https://tweaked.cc/module/paintutils.html#v:drawImage) 90 | function paintutils.drawImage(image, x, y) end 91 | -------------------------------------------------------------------------------- /library/types/objects/peripheral/Drive.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---Disk drives are a peripheral which allow you to read and write to floppy 4 | ---disks and other "mountable media" (such as computers or turtles). They also 5 | ---allow you to play records. 6 | --- 7 | ---When a disk drive attaches some mount (such as a floppy disk or computer), it 8 | ---attaches a folder called disk, disk2, etc... to the root directory of the 9 | ---computer. This folder can be used to interact with the files on that disk. 10 | --- 11 | ---When a disk is inserted, a `disk` event is fired, with the side peripheral is 12 | ---on. Likewise, when the disk is detached, a `disk_eject` event is fired. 13 | --- 14 | ------ 15 | ---[Official Documentation](https://tweaked.cc/peripheral/drive.html) 16 | ---@class ccTweaked.peripheral.Drive 17 | Drive = {} 18 | 19 | ---Checks that an item is in the drive 20 | ---@return boolean present If an item is in the drive 21 | ---Supports: 💾💿🖥️ 22 | --- 23 | ------ 24 | ---[Official Documentation](https://tweaked.cc/peripheral/drive.html#v:isDiskPresent) 25 | function Drive.isDiskPresent() end 26 | 27 | ---Get the label of the inserted item. If the inserted item is a computer, 28 | ---this returns the label of the computer as read by `os.getComputerLabel()` 29 | ---@return string|nil label The label of the inserted item or `nil` if no disk is inserted or the item doesn't have a label 30 | ---Supports: 💾💿🖥️ 31 | --- 32 | ------ 33 | ---[Official Documentation](https://tweaked.cc/peripheral/drive.html#v:getDiskLabel) 34 | function Drive.getDiskLabel() end 35 | 36 | ---Set the label of an inserted item. 37 | ---@param label? string The new value for the label 38 | ---Supports: 💾💿🖥️ 39 | --- 40 | ------ 41 | ---[Official Documentation](https://tweaked.cc/peripheral/drive.html#v:setDiskLabel) 42 | function Drive.setDiskLabel(label) end 43 | 44 | ---Check if an item is present and provides a mount. For records, returns false 45 | ---@return boolean hasMount 46 | --- 47 | ---Supports: 💾💿🖥️ 48 | --- 49 | ------ 50 | ---[Official Documentation](https://tweaked.cc/peripheral/drive.html#v:hasData) 51 | function Drive.hasData() end 52 | 53 | ---Gets the path on this computer where the contents of the inserted item can be 54 | ---found 55 | ---@return ccTweaked.fs.path|nil path The path to the mount location or `nil` if the drive is empty or the inserted item cannot be mounted 56 | ---Supports: 💾💿🖥️ 57 | --- 58 | ------ 59 | ---[Official Documentation](https://tweaked.cc/peripheral/drive.html#v:getMountPath) 60 | function Drive.getMountPath() end 61 | 62 | ---Checks that the inserted item is a music disk 63 | ---@return boolean hasAudio If an item is present and is a record 64 | ---Supports: 💾💿🖥️ 65 | --- 66 | ------ 67 | ---[Official Documentation](https://tweaked.cc/peripheral/drive.html#v:hasAudio) 68 | function Drive.hasAudio() end 69 | 70 | ---Get the title of the music track from the record in the drive. This usually 71 | ---results in the same as `getLabel()` for records. 72 | ---@return string|false|nil title The track title, false if the inserted item is not a record, nil if there is no item in the drive 73 | ---Supports: 💾💿🖥️ 74 | --- 75 | ------ 76 | ---[Official Documentation](https://tweaked.cc/peripheral/drive.html#v:getAudioTitle) 77 | function Drive.getAudioTitle() end 78 | 79 | ---Plays the record in the drive 80 | --- 81 | ---Make sure to check that there is an item in the drive and that it is a record with `hasData()` 82 | --- 83 | ---Stops any already playing records. The record will stop playing when it 84 | ---reaches the end of its runtime, is removed from the drive, or when stopped 85 | ---manually by `stopAudio()` 86 | --- 87 | ---Supports: 💿 88 | --- 89 | ------ 90 | ---[Official Documentation](https://tweaked.cc/peripheral/drive.html#v:playAudio) 91 | function Drive.playAudio() end 92 | 93 | ---Stops the currently playing record that was started with `disk.playAudio()` 94 | --- 95 | ---Supports: 💿 96 | --- 97 | ------ 98 | ---[Official Documentation](https://tweaked.cc/peripheral/drive.html#v:stopAudio) 99 | function Drive.stopAudio() end 100 | 101 | ---Ejects any item that is in the drive, dropping it into the world 102 | --- 103 | ---Supports: 💾💿🖥️ 104 | --- 105 | ------ 106 | ---[Official Documentation](https://tweaked.cc/peripheral/drive.html#v:ejectDisk) 107 | function Drive.ejectDisk() end 108 | 109 | ---Get the unique identifier of the disk in the drive. Only floppy disks have an 110 | ---ID 111 | ---@return number|nil ID The ID of the floppy disk or nil if the drive is empty or does not contain a floppy disk 112 | ---Supports: 💾 113 | --- 114 | ------ 115 | ---[Official Documentation](https://tweaked.cc/peripheral/drive.html#v:getDiskID) 116 | function Drive.getDiskID() end 117 | -------------------------------------------------------------------------------- /library/types/events.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---@alias ccTweaked.os.event 4 | ---| '"alarm"' # Fired when an alarm started with `os.setAlarm()` completes. [Official Documentation](https://tweaked.cc/event/alarm.html) 5 | ---| '"char"' # Fired when a key is typed on the keyboard. Only captures characters, not control keys. [Official Documentation](https://tweaked.cc/event/char.html) 6 | ---| '"computer_command"' # Fired when the `/computercraft queue` command is run for the current computer. [Official Documentation](https://tweaked.cc/event/computer_command.html) 7 | ---| '"disk"' # Fired when a disk is inserted into an adjacent or networked disk drive. [Official Documentation](https://tweaked.cc/event/disk.html) 8 | ---| '"disk_eject"' # Fired when a disk is removed from an adjacent or networked disk drive. [Official Documentation](https://tweaked.cc/event/disk_eject.html) 9 | ---| '"http_check"' # Fired when a URL check completes. [Official Documentation](https://tweaked.cc/event/http_check.html) 10 | ---| '"http_failure"' # Fired when an HTTP request fails. [Official Documentation](https://tweaked.cc/event/http_failure.html) 11 | ---| '"http_success"' # Fired when an HTTP request succeeds. [Official Documentation](https://tweaked.cc/event/http_success.html) 12 | ---| '"key"' # Fired when any key is pressed while the terminal is focused. For text input, use a `char` event. [Official Documentation](https://tweaked.cc/event/key.html) 13 | ---| '"key_up"' # Fired when a key is released (or the terminal is closed while a key was pressed). [Official Documentation](https://tweaked.cc/event/key_up.html) 14 | ---| '"modem_message"' # Fired when a message is received on an open channel on any modem. [Official Documentation](https://tweaked.cc/event/modem_message.html) 15 | ---| '"monitor_resize"' # Fired when an adjacent or networked monitor is resized. [Official Documentation](https://tweaked.cc/event/monitor_resize.html) 16 | ---| '"monitor_touch"' # Fired when an adjacent or networked **advanced** monitor is right-clicked. [Official Documentation](https://tweaked.cc/event/monitor_touch.html) 17 | ---| '"mouse_click"' # Fired when an advanced/pocket computer is clicked with a mouse. [Official Documentation](https://tweaked.cc/event/mouse_click.html) 18 | ---| '"mouse_drag"' # Fired when the mouse is moved while a mouse button is being held. [Official Documentation](https://tweaked.cc/event/mouse_drag.html) 19 | ---| '"mouse_scroll"' # Fired when a mouse wheel is scrolled in the terminal. [Official Documentation](https://tweaked.cc/event/mouse_scroll.html) 20 | ---| '"mouse_up"' # Fired when a mouse button is released or leaves the terminal. [Official Documentation](https://tweaked.cc/event/mouse_up.html) 21 | ---| '"paste"' # Fired when text is pasted into the computer. [Official Documentation](https://tweaked.cc/event/paste.html) 22 | ---| '"peripheral"' # Fired when a peripheral is attached to a side or a modem. [Official Documentation](https://tweaked.cc/event/peripheral.html) 23 | ---| '"peripheral_detach"' # Fired when a peripheral is removed from a side or modem. [Official Documentation](https://tweaked.cc/event/peripheral_detach.html) 24 | ---| '"rednet_message"' # Fired when a message is received over rednet. [Official Documentation](https://tweaked.cc/event/rednet_message.html) 25 | ---| '"redstone"' # Fired when a redstone input on a side is changed. [Official Documentation](https://tweaked.cc/event/redstone.html) 26 | ---| '"speaker_audio_empty"' # Fired when a speaker's audio has ended. [Official Documentation](https://tweaked.cc/event/speaker_audio_empty.html) 27 | ---| '"task_complete"' # Fired when an asynchronous completes. [Official Documentation](https://tweaked.cc/event/task_complete.html) 28 | ---| '"term_resize"' # Fired when the main terminal is resized. [Official Documentation](https://tweaked.cc/event/term_resize.html) 29 | ---| '"terminate"' # Fired when `CTRL + T` is held down. [Official Documentation](https://tweaked.cc/event/terminate.html) 30 | ---| '"timer"' # Fired when a timer started with `os.startTimer()` completes. [Official Documentation](https://tweaked.cc/event/timer.html) 31 | ---| '"turtle_inventory"' # Fired when a turtle's inventory changes. [Official Documentation](https://tweaked.cc/event/turtle_inventory.html) 32 | ---| '"websocket_closed"' # Fired when a websocket connection is closed. [Official Documentation](https://tweaked.cc/event/websocket_closed.html) 33 | ---| '"websocket_failure"' # Fired when a websocket connection fails. [Official Documentation](https://tweaked.cc/event/websocket_failure.html) 34 | ---| '"websocket_message"' # Fired when a websocket message is received. [Official Documentation](https://tweaked.cc/event/websocket_message.html) 35 | ---| '"websocket_success"' # Fired when a websocket connection succeeds. [Official Documentation](https://tweaked.cc/event/websocket_success.html) 36 | ---| '"file_transfer"' # Fired when a user drags-and-drops a file on an open computer. [Official Documentation](https://tweaked.cc/event/file_transfer.html) 37 | -------------------------------------------------------------------------------- /library/types/objects/Vector.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---A 3 dimensional vector with an `x`, `y`, and `z` value 4 | --- 5 | ---These are suitable for positions or directions 6 | --- 7 | ------ 8 | ---[Official Documentation](https://tweaked.cc/module/vector.html#ty:Vector) 9 | ---@class ccTweaked.Vector 10 | ---@field x number 11 | ---@field y number 12 | ---@field z number 13 | Vector = {} 14 | 15 | ---Add two `Vector` objects together 16 | --- 17 | ---You can also take advantage of the `__add` metamethod: 18 | ---``` 19 | ---result = vector1 + vector2 20 | ---``` 21 | ---@param v ccTweaked.Vector The second `Vector` to add 22 | ---@return ccTweaked.Vector result The resulting `Vector` 23 | ------ 24 | ---[Official Documentation](https://tweaked.cc/module/vector.html#ty:Vector:add) 25 | function Vector:add(v) end 26 | 27 | ---Subtract one `Vector` from another 28 | --- 29 | ---You can also take advantage of the `__sub` metamethod: 30 | ---``` 31 | ---result = vector1 - vector2 32 | ---``` 33 | ---@param v ccTweaked.Vector The second `Vector` to subtract 34 | ---@return ccTweaked.Vector result The resulting `Vector` 35 | ------ 36 | ---[Official Documentation](https://tweaked.cc/module/vector.html#ty:Vector:sub) 37 | function Vector:sub(v) end 38 | 39 | ---Multiply a `Vector` by a scalar value, scaling it 40 | --- 41 | ---You can also take advantage of the `__mul` metamethod: 42 | ---``` 43 | ---result = vector1 * 2 44 | ---``` 45 | ---@param scalar number The scalar value to multiply with 46 | ---@return ccTweaked.Vector result The resulting `Vector` 47 | ------ 48 | ---[Official Documentation](https://tweaked.cc/module/vector.html#ty:Vector:mul) 49 | function Vector:mul(scalar) end 50 | 51 | ---Divide a `Vector` by a scalar value, scaling it 52 | --- 53 | ---You can also take advantage of the `__div` metamethod: 54 | ---``` 55 | ---result = vector1 / 2 56 | ---``` 57 | ---@param scalar number The scalar value to divide with 58 | ---@return ccTweaked.Vector result The resulting `Vector` 59 | ------ 60 | ---[Official Documentation](https://tweaked.cc/module/vector.html#ty:Vector:div) 61 | function Vector:div(scalar) end 62 | 63 | ---Negate a vector 64 | --- 65 | ---You can also take advantage of the `__unm` metamethod: 66 | ---``` 67 | ---negated = -vector1 68 | ---``` 69 | ---@return ccTweaked.Vector negated The negated `Vector` 70 | function Vector:unm() end 71 | 72 | ---Compute the dot product of two vectors 73 | ---@param v ccTweaked.Vector The second vector to use for the calculation 74 | ---@return number dot The dot product of the two vectors 75 | ------ 76 | ---[Official Documentation](https://tweaked.cc/module/vector.html#ty:Vector:dot) 77 | function Vector:dot(v) end 78 | 79 | ---Compute the cross product of two vectors 80 | ---@param v ccTweaked.Vector The second vector to use for the calculation 81 | ---@return ccTweaked.Vector cross The cross products of the two vectors 82 | ------ 83 | ---[Official Documentation](https://tweaked.cc/module/vector.html#ty:Vector:cross) 84 | function Vector:cross(v) end 85 | 86 | ---Get the length/magnitude of this vector 87 | ---@return number length The length of this vector 88 | ------ 89 | ---[Official Documentation](https://tweaked.cc/module/vector.html#ty:Vector:length) 90 | function Vector:length() end 91 | 92 | ---Divide this vector by its length, normalizing it 93 | ---@return ccTweaked.Vector normalized The normalized vector 94 | ------ 95 | ---[Official Documentation](https://tweaked.cc/module/vector.html#ty:Vector:normalize) 96 | function Vector:normalize() end 97 | 98 | ---Create a new `Vector` with each dimension rounded 99 | ---@param tolerance? number The tolerance that rounding should take place to (defaults to 1) 100 | ---@return ccTweaked.Vector rounded The rounded vector 101 | ---## Example 102 | ---``` 103 | ---local rounded = vector1:round(0.05) 104 | ---``` 105 | ------ 106 | ---[Official Documentation](https://tweaked.cc/module/vector.html#ty:Vector:round) 107 | function Vector:round(tolerance) end 108 | 109 | ---Convert this vector to a string for printing 110 | --- 111 | ---You can also take advantage of the `__tostring` metamethod: 112 | ---``` 113 | ---asString = tostring(vector1) 114 | ---``` 115 | ---@return string str The string representation of this vector 116 | ------ 117 | ---[Official Documentation](https://tweaked.cc/module/vector.html#ty:Vector:tostring) 118 | function Vector:toString() end 119 | 120 | ---Check if two vectors are equal 121 | ---@param v ccTweaked.Vector The vector to compare to 122 | ---@return boolean equal If the two vectors are equal 123 | ---## Example 124 | ---``` 125 | ---local v1 = vector.new(12.00439, 0, 0) 126 | ---local v2 = vector.new(12.00441, 0, 0) 127 | --- 128 | ---local areSimilar = v1:round(0.001):equals(v2:round(0.001)) 129 | ----->true 130 | ---``` 131 | ------ 132 | ---[Official Documentation](https://tweaked.cc/module/vector.html#ty:Vector:tostring) 133 | function Vector:equals(v) end 134 | -------------------------------------------------------------------------------- /library/io.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---Emulates Lua's [io library](https://www.lua.org/manual/5.1/manual.html#5.7) 4 | --- 5 | ------ 6 | ---[Official Documentation](https://tweaked.cc/module/io.html) 7 | io = {} 8 | 9 | ---A file handle representing the "standard input". Reading from this file will 10 | ---prompt the user for input. 11 | ------ 12 | ---[Official Documentation](https://tweaked.cc/module/io.html#v:stdin) 13 | ---@type ccTweaked.fs.Handle 14 | io.stdin = nil 15 | 16 | ---A file handle representing the "standard output". Writing to this file will 17 | ---display the written text to the screen. 18 | ------ 19 | ---[Official Documentation](https://tweaked.cc/module/io.html#v:stdout) 20 | ---@type ccTweaked.fs.Handle 21 | io.stdout = nil 22 | 23 | ---A file handle representing the "standard error" stream. 24 | ---One may use this to display error messages, writing to it will display them on the terminal. 25 | ------ 26 | ---[Official Documentation](https://tweaked.cc/module/io.html#v:stderr) 27 | ---@type ccTweaked.fs.Handle 28 | io.stderr = nil 29 | 30 | ---Close a file handle 31 | ---@param handle ccTweaked.fs.Handle The file handle to close. Defaults to the current output file 32 | ------ 33 | ---[Official Documentation](https://tweaked.cc/module/io.html#v:close) 34 | function io.close(handle) end 35 | 36 | ---Flushes the current output file, saving it without closing it 37 | ------ 38 | ---[Official Documentation](https://tweaked.cc/module/io.html#v:flush) 39 | function io.flush() end 40 | 41 | ---Get or set the current input file 42 | ---@param file? ccTweaked.fs.Handle|ccTweaked.fs.path The new input file, either as a file path or a handle 43 | ---@return ccTweaked.fs.Handle handle The current input file handle 44 | ---@throws If the provided path cannot be opened for reading 45 | ------ 46 | ---[Official Documentation](https://tweaked.cc/module/io.html#v:input) 47 | function io.input(file) end 48 | 49 | ---Open a file in read mode and return an interator that returns a new line every time it is called. Useful for looping over all lines in a file 50 | --- 51 | ---Once the end of the file has been reached, nil will be returned and the file is automatically closed. 52 | --- 53 | ---If no file name is given, the current input will be used instead. In this case, the handle is not used. 54 | ---@param path? ccTweaked.fs.path The path to the file to read lines from 55 | ---@param readMode? ccTweaked.io.readFormat How the lines should be read 56 | ---@return fun(): string iterator The line iterator 57 | ---@throws If the file cannot be opened for reading 58 | --- 59 | ---❗Passing `"a"` as a format will result in an infinite loop and will crash your script after timing out 60 | ---## Example 61 | ---``` 62 | -----Iterate over and print all lines in a file 63 | ---for line in io.lines("/rom/help/intro.txt") do 64 | --- print(line) 65 | ---end 66 | ---``` 67 | ------ 68 | ---[Official Documentation](https://tweaked.cc/module/io.html#v:lines) 69 | function io.lines(path, readMode) end 70 | 71 | ---Open a file in the mode provided 72 | ---@param path ccTweaked.fs.path The path to the file to open 73 | ---@param mode? ccTweaked.fs.openMode The mode to open the file in. Defaults to `rb` (binary read) 74 | ---@return ccTweaked.fs.Handle|nil handle The opened file or nil if an error occurred 75 | ---@return nil|string errorMessage Why the file could not be opened 76 | ------ 77 | ---[Official Documentation](https://tweaked.cc/module/io.html#v:open) 78 | function io.open(path, mode) end 79 | 80 | ---Get or set the current output file 81 | ---@param file? ccTweaked.fs.Handle|ccTweaked.fs.path The new output file, either as a file path or a handle 82 | ---@return ccTweaked.fs.Handle handle The current output file handle 83 | ---@throws If the provided path cannot be opened for writing 84 | --------- 85 | ---[Official Documentation](https://tweaked.cc/module/io.html#v:output) 86 | function io.output(file) end 87 | 88 | ---Read from the currently opened file 89 | --- 90 | ---This is equivalent to: 91 | ---``` 92 | ---local handle = io.open('/testFile.txt') 93 | ---handle:read() 94 | ---``` 95 | ---@param ... ccTweaked.io.readFormat The formats to use for reading. Defaults to `l` 96 | ---@return string ... The data (as a string) read from the file or nil if no data could be read. 97 | ------ 98 | ---[Official Documentation](https://tweaked.cc/module/io.html#v:read) 99 | function io.read(...) end 100 | 101 | ---Checks whether the provided value is a `Handle` and if it is open 102 | ---@param obj any The value to check 103 | ---@return "file"|"closed file"|nil type If the file is open (`"file"`), closed (`"closed file"`), or is not even a file `Handle` (`nil`) 104 | ------ 105 | ---[Official Documentation](https://tweaked.cc/module/io.html#v:type) 106 | function io.type(obj) end 107 | 108 | ---Write to the currently opened file 109 | --- 110 | ---This is equivalent to: 111 | ---``` 112 | ---local handle = io.open('/testFile.txt') 113 | ---handle:write() 114 | ---``` 115 | ---@param ... string The strings to write to the file 116 | ------ 117 | ---[Official Documentation](https://tweaked.cc/module/io.html#v:write) 118 | function io.write(...) end 119 | -------------------------------------------------------------------------------- /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "configs": [ 3 | { 4 | "action": "set", 5 | "key": "Lua.runtime.version", 6 | "value": "Lua 5.3" 7 | }, 8 | { 9 | "action": "add", 10 | "key": "Lua.diagnostics.globals", 11 | "value": "sleep" 12 | }, 13 | { 14 | "action": "add", 15 | "key": "Lua.diagnostics.globals", 16 | "value": "write" 17 | }, 18 | { 19 | "action": "add", 20 | "key": "Lua.diagnostics.globals", 21 | "value": "print" 22 | }, 23 | { 24 | "action": "add", 25 | "key": "Lua.diagnostics.globals", 26 | "value": "printError" 27 | }, 28 | { 29 | "action": "add", 30 | "key": "Lua.diagnostics.globals", 31 | "value": "read" 32 | }, 33 | { 34 | "action": "add", 35 | "key": "Lua.diagnostics.globals", 36 | "value": "_HOST" 37 | }, 38 | { 39 | "action": "add", 40 | "key": "Lua.diagnostics.globals", 41 | "value": "_CC_DEFAULT_SETTINGS" 42 | }, 43 | { 44 | "action": "add", 45 | "key": "Lua.diagnostics.globals", 46 | "value": "colors" 47 | }, 48 | { 49 | "action": "add", 50 | "key": "Lua.diagnostics.globals", 51 | "value": "commands" 52 | }, 53 | { 54 | "action": "add", 55 | "key": "Lua.diagnostics.globals", 56 | "value": "disk" 57 | }, 58 | { 59 | "action": "add", 60 | "key": "Lua.diagnostics.globals", 61 | "value": "fs" 62 | }, 63 | { 64 | "action": "add", 65 | "key": "Lua.diagnostics.globals", 66 | "value": "gps" 67 | }, 68 | { 69 | "action": "add", 70 | "key": "Lua.diagnostics.globals", 71 | "value": "help" 72 | }, 73 | { 74 | "action": "add", 75 | "key": "Lua.diagnostics.globals", 76 | "value": "http" 77 | }, 78 | { 79 | "action": "add", 80 | "key": "Lua.diagnostics.globals", 81 | "value": "io" 82 | }, 83 | { 84 | "action": "add", 85 | "key": "Lua.diagnostics.globals", 86 | "value": "keys" 87 | }, 88 | { 89 | "action": "add", 90 | "key": "Lua.diagnostics.globals", 91 | "value": "multishell" 92 | }, 93 | { 94 | "action": "add", 95 | "key": "Lua.diagnostics.globals", 96 | "value": "os" 97 | }, 98 | { 99 | "action": "add", 100 | "key": "Lua.diagnostics.globals", 101 | "value": "paintutils" 102 | }, 103 | { 104 | "action": "add", 105 | "key": "Lua.diagnostics.globals", 106 | "value": "parallel" 107 | }, 108 | { 109 | "action": "add", 110 | "key": "Lua.diagnostics.globals", 111 | "value": "peripheral" 112 | }, 113 | { 114 | "action": "add", 115 | "key": "Lua.diagnostics.globals", 116 | "value": "pocket" 117 | }, 118 | { 119 | "action": "add", 120 | "key": "Lua.diagnostics.globals", 121 | "value": "rednet" 122 | }, 123 | { 124 | "action": "add", 125 | "key": "Lua.diagnostics.globals", 126 | "value": "redstone" 127 | }, 128 | { 129 | "action": "add", 130 | "key": "Lua.diagnostics.globals", 131 | "value": "settings" 132 | }, 133 | { 134 | "action": "add", 135 | "key": "Lua.diagnostics.globals", 136 | "value": "shell" 137 | }, 138 | { 139 | "action": "add", 140 | "key": "Lua.diagnostics.globals", 141 | "value": "term" 142 | }, 143 | { 144 | "action": "add", 145 | "key": "Lua.diagnostics.globals", 146 | "value": "textutils" 147 | }, 148 | { 149 | "action": "add", 150 | "key": "Lua.diagnostics.globals", 151 | "value": "turtle" 152 | }, 153 | { 154 | "action": "add", 155 | "key": "Lua.diagnostics.globals", 156 | "value": "vector" 157 | }, 158 | { 159 | "action": "add", 160 | "key": "Lua.diagnostics.globals", 161 | "value": "window" 162 | } 163 | ], 164 | "files": [ 165 | "startup.lua" 166 | ], 167 | "name": "CC:Tweaked", 168 | "words": [ 169 | "colors%.%w+", 170 | "colours%.%w+", 171 | "commands%.%w+", 172 | "disk%.%w+", 173 | "fs%.%w+", 174 | "globals%.%w+", 175 | "gps%.%w+", 176 | "help%.%w+", 177 | "http%.%w+", 178 | "keys%.%w+", 179 | "multishell%.%w+", 180 | "paintutils%.%w+", 181 | "parallel%.%w+", 182 | "peripheral%.%w+", 183 | "pocket%.%w+", 184 | "rednet%.%w+", 185 | "redstone%.%w+", 186 | "settings%.%w+", 187 | "shell%.%w+", 188 | "term%.%w+", 189 | "textutils%.%w+", 190 | "turtle%.%w+", 191 | "vector%.%w+", 192 | "window%.%w+" 193 | ] 194 | } -------------------------------------------------------------------------------- /library/redstone.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---The redstone API allows you to interact with redstone I/O in binary, 4 | ---analogue, and "bundled" mode 5 | --- 6 | ---When a redstone input changes, a `redstone` event will be fired 7 | --- 8 | ------ 9 | ---[Official Documentation](https://tweaked.cc/module/redstone.html) 10 | redstone = {} 11 | 12 | ---Get the valid sides of this computer 13 | ---@return ccTweaked.redstone.computerSidesTable sides The sides of the computer 14 | ------ 15 | ---[Official Documentation](https://tweaked.cc/module/redstone.html#v:getSides) 16 | function redstone.getSides() end 17 | 18 | ---Set the binary state of a redstone signal on a specific side of this computer 19 | ---@param side ccTweaked.peripheral.computerSide The side of the computer to set the state of 20 | ---@param state boolean If the redstone should be on, with a signal strength of 15 21 | ------ 22 | ---[Official Documentation](https://tweaked.cc/module/redstone.html#v:setOutput) 23 | function redstone.setOutput(side, state) end 24 | 25 | ---Get the current redstone output state at the side of a computer 26 | ---@param side ccTweaked.peripheral.computerSide The side of the computer to check 27 | ---@return boolean state If the redstone output is on or off 28 | ------ 29 | ---[Official Documentation](https://tweaked.cc/module/redstone.html#v:getOutput) 30 | function redstone.getOutput(side) end 31 | 32 | ---Get the current redstone input of a given side 33 | ---@param side ccTweaked.peripheral.computerSide The side of the computer to check 34 | ---@return boolean state Whether the redstone input is on or off 35 | ------ 36 | ---[Official Documentation](https://tweaked.cc/module/redstone.html#v:getInput) 37 | function redstone.getInput(side) end 38 | 39 | ---Set the redstone signal strength for a given side 40 | ---@param side ccTweaked.peripheral.computerSide The side of the computer to set the signal strength for 41 | ---@param strength ccTweaked.redstone.signalStrength The strength of the analog output signal 42 | ------ 43 | ---[Official Documentation](https://tweaked.cc/module/redstone.html#v:setAnalogOutput) 44 | function redstone.setAnalogOutput(side, strength) end 45 | 46 | ---Set the redstone signal strength for a given side 47 | ---@param side ccTweaked.peripheral.computerSide The side of the computer to set the signal strength for 48 | ---@param strength ccTweaked.redstone.signalStrength The strength of the analogue output signal 49 | ------ 50 | ---[Official Documentation](https://tweaked.cc/module/redstone.html#v:setAnalogueOutput) 51 | function redstone.setAnalogueOutput(side, strength) end 52 | 53 | ---Get the redstone analog output signal strength for a given side 54 | ---@param side ccTweaked.peripheral.computerSide The side of the computer to check 55 | ---@return ccTweaked.redstone.signalStrength strength The strength of the analog output signal (0 - 15) 56 | ------ 57 | ---[Official Documentation](https://tweaked.cc/module/redstone.html#v:getAnalogOutput) 58 | function redstone.getAnalogOutput(side) end 59 | 60 | ---Get the redstone analogue output signal strength for a given side 61 | ---@param side ccTweaked.peripheral.computerSide The side of the computer to check 62 | ---@return ccTweaked.redstone.signalStrength strength The strength of the analogue output signal (0 - 15) 63 | ------ 64 | ---[Official Documentation](https://tweaked.cc/module/redstone.html#v:getAnalogueOutput) 65 | function redstone.getAnalogueOutput(side) end 66 | 67 | ---Get the current analog input strength for a given side 68 | ---@param side ccTweaked.peripheral.computerSide The side of the computer to check 69 | ---@return ccTweaked.redstone.signalStrength strength The strength of the analog input signal 70 | ------ 71 | ---[Official Documentation](https://tweaked.cc/module/redstone.html#v:getAnalogInput) 72 | function redstone.getAnalogInput(side) end 73 | 74 | ---Get the current analogue input strength for a given side 75 | ---@param side ccTweaked.peripheral.computerSide The side of the computer to check 76 | ---@return ccTweaked.redstone.signalStrength strength The strength of the analogue input signal 77 | ------ 78 | ---[Official Documentation](https://tweaked.cc/module/redstone.html#v:getAnalogueInput) 79 | function redstone.getAnalogueInput(side) end 80 | 81 | ---Set the bundled cable output for a given side 82 | --- 83 | ---🗒️ Use `colors.subtract()` and `colors.combine()` to make a color set 84 | ---@param side ccTweaked.peripheral.computerSide The side to set 85 | ---@param colorSet ccTweaked.colors.colorSet The colorSet to set for the output 86 | function redstone.setBundledOutput(side, colorSet) end 87 | 88 | ---Get the bundled cable output for a given side 89 | ---@param side ccTweaked.peripheral.computerSide The side of the computer to check 90 | ---@return ccTweaked.colors.colorSet colorSet The bundled cable output 91 | ------ 92 | ---[Official Documentation](https://tweaked.cc/module/redstone.html#v:getBundledOutput) 93 | function redstone.getBundledOutput(side) end 94 | 95 | ---Get the bundled cable input for a given side 96 | ---@param side ccTweaked.peripheral.computerSide The side of the computer to check 97 | ---@return ccTweaked.colors.colorSet colorSet The bundled cable input 98 | ------ 99 | ---[Official Documentation](https://tweaked.cc/module/redstone.html#v:getBundledInput) 100 | function redstone.getBundledInput(side) end 101 | 102 | ---Test whether a bundled input is as expected 103 | ---@param side ccTweaked.peripheral.computerSide The side of the computer to check 104 | ---@param colorSet ccTweaked.colors.colorSet The input that is expected 105 | ---@return boolean success If the test is true 106 | ------ 107 | ---[Official Documentation](https://tweaked.cc/module/redstone.html#v:testBundledInput) 108 | function redstone.testBundledInput(side, colorSet) end 109 | -------------------------------------------------------------------------------- /library/disk.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---Functions for interacting with disk drives 4 | --- 5 | ---The disk functions can be used on a locally attached or remote disk drive 6 | ---peripheral. If the drive is attached locally, you can use the side it is 7 | ---attached to, if it is remote, you have to use the name printed when enabling 8 | ---its modem (e.g. `drive_0`). 9 | --- 10 | ---💬 A disk drive can contain a floppy disk 💾, record 💿, or a computer 🖥️ 11 | ---(including pocket computer or turtle) 12 | --- 13 | ---💬 Computers, turtles, and pocket computers can be placed in a disk drive to 14 | ---access their internal drives. 15 | --- 16 | ------ 17 | ---[Official Documentation](https://tweaked.cc/module/disk.html) 18 | disk = {} 19 | 20 | ---Checks that an item is in a disk drive 21 | ---@param name ccTweaked.peripheral.computerSide|string The name of the disk drive or the side of the computer that the drive is on 22 | ---@return boolean present 23 | ---Supports: 💾💿🖥️ 24 | ---## Example 25 | ---``` 26 | ---disk.isPresent("top") 27 | ---disk.isPresent("drive_3") 28 | ---``` 29 | ------ 30 | ---[Official Documentation](https://tweaked.cc/module/disk.html#v:isPresent) 31 | function disk.isPresent(name) end 32 | 33 | ---Get the label of the inserted item. If the inserted item is a computer, 34 | ---this returns the label of the computer as read by `os.getComputerLabel()` 35 | ---@param name ccTweaked.peripheral.computerSide|string The name of the disk drive or the side of the computer that the drive is on 36 | ---Supports: 💾💿🖥️ 37 | --- 38 | ------ 39 | ---[Official Documentation](https://tweaked.cc/module/disk.html#v:getLabel) 40 | function disk.getLabel(name) end 41 | 42 | ---Set the label of an inserted item. 43 | ---@param name ccTweaked.peripheral.computerSide|string The name of the disk drive or the side of the computer that the drive is on 44 | ---@param label string The new value for the label 45 | ---Supports: 💾💿🖥️ 46 | --- 47 | ------ 48 | ---[Official Documentation](https://tweaked.cc/module/disk.html#v:setLabel) 49 | function disk.setLabel(name, label) end 50 | 51 | ---Check if an item is present and provides a mount. For records, returns false 52 | ---@param name ccTweaked.peripheral.computerSide|string The name of the disk drive or the side of the computer that the drive is on 53 | ---@return boolean hasMount 54 | ---Supports: 💾💿🖥️ 55 | --- 56 | ------ 57 | ---[Official Documentation](https://tweaked.cc/module/disk.html#v:hasData) 58 | function disk.hasData(name) end 59 | 60 | ---Gets the path on this computer where the contents of the inserted item can be 61 | ---found 62 | ---@param name ccTweaked.peripheral.computerSide|string The name of the disk drive or the side of the computer that the drive is on 63 | ---@return ccTweaked.fs.path|nil path The path to the mount location or `nil` if the drive is empty or the inserted item cannot be mounted 64 | ---Supports: 💾💿🖥️ 65 | ---## Example 66 | ---``` 67 | ---disk.getMountPath("left") 68 | ----->"/disk0" 69 | ---``` 70 | ------ 71 | ---[Official Documentation](https://tweaked.cc/module/disk.html#v:getMountPath) 72 | function disk.getMountPath(name) end 73 | 74 | ---Checks that the inserted item is a music disk 75 | ---@param name ccTweaked.peripheral.computerSide|string The name of the disk drive or the side of the computer that the drive is on 76 | ---@return boolean hasAudio If an item is present and is a record 77 | ---Supports: 💾💿🖥️ 78 | --- 79 | ------ 80 | ---[Official Documentation](https://tweaked.cc/module/disk.html#v:hasAudio) 81 | function disk.hasAudio(name) end 82 | 83 | ---Get the title of the music track from the record in the drive. This usually 84 | ---results in the same as `disk.getLabel()` for records. 85 | ---@param name ccTweaked.peripheral.computerSide|string The name of the disk drive or the side of the computer that the drive is on 86 | ---@return string|false|nil title The track title, false if the inserted item is not a record, nil if there is no item in the drive 87 | ---Supports: 💾💿🖥️ 88 | --- 89 | ------ 90 | ---[Official Documentation](https://tweaked.cc/module/disk.html#v:getAudioTitle) 91 | function disk.getAudioTitle(name) end 92 | 93 | ---Plays the record in the drive 94 | --- 95 | ---Make sure to check that there is an item in the drive and that it is a record with `disk.hasData()` 96 | --- 97 | ---Stops any already playing records. The record will stop playing when it 98 | ---reaches the end of its runtime, is removed from the drive, or when stopped 99 | ---manually by `disk.stopAudio()` 100 | ---@param name ccTweaked.peripheral.computerSide|string The name of the disk drive or the side of the computer that the drive is on 101 | ---Supports: 💿 102 | --- 103 | ------ 104 | ---[Official Documentation](https://tweaked.cc/module/disk.html#v:playAudio) 105 | function disk.playAudio(name) end 106 | 107 | ---Stops the currently playing record that was started with `disk.playAudio()` 108 | ---@param name ccTweaked.peripheral.computerSide|string? The name of the disk drive or the side of the computer that the drive is on 109 | ---Supports: 💿 110 | --- 111 | ------ 112 | ---[Official Documentation](https://tweaked.cc/module/disk.html#v:stopAudio) 113 | function disk.stopAudio(name) end 114 | 115 | ---Ejects any item that is in the drive, dropping it into the world 116 | ---@param name ccTweaked.peripheral.computerSide|string The name of the disk drive or the side of the computer that the drive is on 117 | ---Supports: 💾💿🖥️ 118 | --- 119 | ------ 120 | ---[Official Documentation](https://tweaked.cc/module/disk.html#v:eject) 121 | function disk.eject(name) end 122 | 123 | ---Get the unique identifier of the disk in the drive. Only floppy disks have an 124 | ---ID 125 | ---@param name ccTweaked.peripheral.computerSide|string The name of the disk drive or the side of the computer that the drive is on 126 | ---@return number|nil ID The ID of the floppy disk or nil if the drive is empty or does not contain a floppy disk 127 | ---Supports: 💾 128 | --- 129 | ------ 130 | ---[Official Documentation](https://tweaked.cc/module/disk.html#v:getID) 131 | function disk.getID(name) end 132 | -------------------------------------------------------------------------------- /library/cc/pretty.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---A pretty printer for formatting text in a stylized manner. 4 | --- 5 | ---Printing uses document objects to structure the text. These documents will be 6 | ---used to print the most compact layout possible 7 | --- 8 | ---Based on [*A Prettier Printer*](https://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf) 9 | ------ 10 | ---[Official Documentation](https://tweaked.cc/library/cc.pretty.html) 11 | pretty = {} 12 | 13 | ---A document contains formatted text with multiple possible layouts. 14 | ---@class ccTweaked.cc.pretty.Doc 15 | 16 | ---An empty document 17 | ---@type ccTweaked.cc.pretty.Doc 18 | ------ 19 | ---[Official Documentation](https://tweaked.cc/library/cc.pretty.html#v:empty) 20 | pretty.empty = nil 21 | 22 | ---A document with a single space in it 23 | ---@type ccTweaked.cc.pretty.Doc 24 | ------ 25 | ---[Official Documentation](https://tweaked.cc/library/cc.pretty.html#v:space) 26 | pretty.space = nil 27 | 28 | ---A line break, however when in a group and everything can fit on one line, is 29 | ---replaced with `empty` 30 | ---@type ccTweaked.cc.pretty.Doc 31 | ------ 32 | ---[Official Documentation](https://tweaked.cc/library/cc.pretty.html#v:line) 33 | pretty.line = nil 34 | 35 | ---A line break, however when in a group and everything can fit on one line, is 36 | ---replaced with `space` 37 | ---@type ccTweaked.cc.pretty.Doc 38 | ------ 39 | ---[Official Documentation](https://tweaked.cc/library/cc.pretty.html#v:space_line) 40 | pretty.space_line = nil 41 | 42 | ---Create a new `Doc` from a string 43 | ---@param text string The string to construct a document from 44 | ---@param color? ccTweaked.colors.color The color to print the text in. Defaults to the current color 45 | ---@return ccTweaked.cc.pretty.Doc doc The document containing the provided text 46 | ------ 47 | ---[Official Documentation](https://tweaked.cc/library/cc.pretty.html#v:text) 48 | function pretty.text(text, color) end 49 | 50 | ---Concatenate multiple documents into one 51 | ---@param ... ccTweaked.cc.pretty.Doc|string The documents to concat 52 | ---@return ccTweaked.cc.pretty.Doc doc The concatenated document 53 | ------ 54 | ---[Official Documentation](https://tweaked.cc/library/cc.pretty.html#v:concat) 55 | function pretty.concat(...) end 56 | 57 | ---Indents the following lines in the provided document using spaces 58 | ---@param depth integer The number of spaces to indent to 59 | ---@param doc ccTweaked.cc.pretty.Doc The document to indent 60 | ---@return ccTweaked.cc.pretty.Doc doc The nested document 61 | ------ 62 | ---[Official Documentation](https://tweaked.cc/library/cc.pretty.html#v:nest) 63 | function pretty.nest(depth, doc) end 64 | 65 | ---Build a document that is displayed on a single line if there is enough room 66 | ---or as normal if not 67 | ---@param doc ccTweaked.cc.pretty.Doc The document to make a group 68 | ---@return ccTweaked.cc.pretty.Doc doc The grouped document 69 | ---## Example 70 | ---``` 71 | ---local pretty = require("cc.pretty") 72 | --- 73 | ---pretty.print( 74 | --- pretty.group( 75 | --- pretty.concat("Hello", pretty.space_line, "World!") 76 | --- ) 77 | ---) 78 | ---``` 79 | ------ 80 | ---[Official Documentation](https://tweaked.cc/library/cc.pretty.html#v:group) 81 | function pretty.group(doc) end 82 | 83 | ---Write a doc to the terminal 84 | ---@param doc ccTweaked.cc.pretty.Doc The document to write 85 | ---@param maxWidth? number The maximum fraction of the screen width that can be written to before wrapping. Defaults to 0.6 86 | ------ 87 | ---[Official Documentation](https://tweaked.cc/library/cc.pretty.html#v:write) 88 | function pretty.write(doc, maxWidth) end 89 | 90 | ---Print a doc to the terminal with a trailing new line 91 | ---@param doc ccTweaked.cc.pretty.Doc The document to write 92 | ---@param maxWidth? number The maximum fraction of the screen width that can be written to before wrapping. Defaults to 0.6 93 | ------ 94 | ---[Official Documentation](https://tweaked.cc/library/cc.pretty.html#v:print) 95 | function pretty.print(doc, maxWidth) end 96 | 97 | ---Render a document into a string 98 | ---@param doc ccTweaked.cc.pretty.Doc The document to render 99 | ---@param width? number The maximum width of this document. Long strings will not be wrapped to fit this width, it is just used for finding the best layout 100 | ---@param maxWidth? number The maximum fraction of the screen width that can be written to before wrapping. Defaults to 0.6 101 | ---@return string rendered The rendered string 102 | ------ 103 | ---[Official Documentation](https://tweaked.cc/library/cc.pretty.html#v:render) 104 | function pretty.render(doc, width, maxWidth) end 105 | 106 | ---@class prettyOptions 107 | ---@field function_args boolean Show the arguments to a function if known, defaults to false 108 | ---@field function_source boolean Show where a function was defined, defaults to false 109 | 110 | ---Convert an object into a document that can then be displayed with `write` or `print` 111 | ---@param obj any The object to convert to a document 112 | ---@param options? prettyOptions Options for how certain things are displayed 113 | ---@return ccTweaked.cc.pretty.Doc doc The formatted document 114 | ---## Example 115 | ---``` 116 | ---local pretty = require "cc.pretty" 117 | ---pretty.print(pretty.pretty({ 1, 2, 3 })) 118 | ---``` 119 | ------ 120 | ---[Official Documentation](https://tweaked.cc/library/cc.pretty.html#v:pretty) 121 | function pretty.pretty(obj, options) end 122 | 123 | ---A shorthand that calls `pretty` and `print` 124 | ---@param obj any The object to print 125 | ---@param options? prettyOptions Options for how certain things are displayed 126 | ---@param maxWidth? number The maximum fraction of the screen width that can be written to before wrapping. Defaults to 0.6 127 | ---## Example 128 | ---``` 129 | ---local pretty = require "cc.pretty" 130 | ---pretty.pretty_print({ 1, 2, 3 }) 131 | ---``` 132 | ------ 133 | ---[Official Documentation](https://tweaked.cc/library/cc.pretty.html#v:pretty_print) 134 | function pretty.pretty_print(obj, options, maxWidth) end 135 | 136 | return pretty 137 | -------------------------------------------------------------------------------- /library/rednet.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---The rednet API provides a layer of abstraction on top of the modem peripheral 4 | ---in order to make communicating between computers easier 5 | --- 6 | ---### Basic Usage 7 | ---In order to send and receive message between two computers, they must have a 8 | ---modem attached. They can then use `rednet.open()` to start sending and 9 | ---receiving messages 10 | --- 11 | ---⚠️ Unintended computers could be listening in to messages or pretending to be 12 | ---other computers. Encrypting/signing your messages would help increase the 13 | ---security of your messages 14 | --- 15 | ---### Protocols 16 | ---Protocols provide a basic means to filter messages being sent over rednet and 17 | ---offer a basic sort of DNS that allows you to discover other computers by 18 | ---their friendly hostname 19 | --- 20 | ------ 21 | ---[Official Documentation](https://tweaked.cc/module/rednet.html) 22 | rednet = {} 23 | 24 | ---The channel that messages will be sent on by `rednet.broadcast()` 25 | --- 26 | ------ 27 | ---[Official Documentation](https://tweaked.cc/module/rednet.html#v:CHANNEL_BROADCAST) 28 | rednet.CHANNEL_BROADCAST = 65535 29 | 30 | ---The channel used to repeat messages 31 | --- 32 | ------ 33 | ---[Official Documentation](https://tweaked.cc/module/rednet.html#v:CHANNEL_REPEAT) 34 | rednet.CHANNEL_REPEAT = 65535 35 | 36 | ---The highest channel reserved by rednet for computer IDs. Computers with IDs 37 | ---greater or equal to this limit will wrap back around to 0 38 | --- 39 | ------ 40 | ---[Official Documentation](https://tweaked.cc/module/rednet.html#v:MAX_ID_CHANNELS) 41 | rednet.MAX_ID_CHANNELS = 65500 42 | 43 | ---Open a modem, allowing it to send and receive on rednet 44 | --- 45 | ---This opens two channels on the modem, one matching the ID of this computer, 46 | ---and another matching the value of `rednet.CHANNEL_BROADCAST` 47 | ---@param modem string|ccTweaked.peripheral.computerSide The name/side of the modem to open 48 | ---@throws If there is no modem with the given name 49 | ------ 50 | ---[Official Documentation](https://tweaked.cc/module/rednet.html#v:open) 51 | function rednet.open(modem) end 52 | 53 | ---Close a modem, preventing it from sending or receiving on rednet 54 | ---@param modem? string|ccTweaked.peripheral.computerSide The name/side of the modem to close. If omitted, all modems will be closed 55 | ---@throws If there is no modem with the given name 56 | ------ 57 | ---[Official Documentation](https://tweaked.cc/module/rednet.html#v:close) 58 | function rednet.close(modem) end 59 | 60 | ---Get whether a modem is currently open on rednet 61 | ---@param modem string|ccTweaked.peripheral.computerSide The name/side of the modem to check. If omitted, all modems will be checked 62 | ---@return boolean isOpen If the modem is open 63 | ------ 64 | ---[Official Documentation](https://tweaked.cc/module/rednet.html#v:isOpen) 65 | function rednet.isOpen(modem) end 66 | 67 | ---Send a message to a target computer 68 | ---@param recipient integer The ID of the computer to send the message to 69 | ---@param message number|boolean|string|table The message to send 70 | ---@param protocol? string The protocol to send the message under 71 | ---@return boolean success If the message was sent (does not guarantee that the message was received) 72 | ------ 73 | ---[Official Documentation](https://tweaked.cc/module/rednet.html#v:send) 74 | function rednet.send(recipient, message, protocol) end 75 | 76 | ---Broadcast a message over the channel defined by `rednet.CHANNEL_BROADCAST` 77 | --- 78 | ---Every device listening on rednet can receive broadcasted messages 79 | ---@param message number|boolean|string|table The message to broadcast 80 | ---@param protocol string The protocol to broadcast the message under 81 | ------ 82 | ---[Official Documentation](https://tweaked.cc/module/rednet.html#v:broadcast) 83 | function rednet.broadcast(message, protocol) end 84 | 85 | ---Receive a message over rednet 86 | ---@param protocol? string The protocol to exclusively receive messages under 87 | ---@param timeout? number The number of seconds to wait if no message is received 88 | ---@return number|nil sender The ID of the computer which sent the message or `nil` if the timeout was reached and no message was received 89 | ---@return nil|number|boolean|string|table message The received message 90 | ---@return nil|string protocol The protocol the message was sent under 91 | ------ 92 | ---[Official Documentation](https://tweaked.cc/module/rednet.html#v:receive) 93 | function rednet.receive(protocol, timeout) end 94 | 95 | ---Register this computer as hosting a specific protocol under the provided 96 | ---hostname. This allows other computers to find this one by using 97 | ---`rednet.lookup()` 98 | --- 99 | ---No two computers can share the same hostname and the hostname `localhost` is reserved. They can only share hostnames in the following scenarios: 100 | ---- They are hosting different protocols 101 | ---- They join the same network after registering 102 | ---@param protocol string The protocol this computer provides 103 | ---@param hostname string The name this computer exposes for this protocol 104 | ---@throws If the requested hostname is reserved or already in use 105 | ------ 106 | ---[Official Documentation](https://tweaked.cc/module/rednet.html#v:host) 107 | function rednet.host(protocol, hostname) end 108 | 109 | ---Stop hosting a certain protocol, preventing this computer from responding to 110 | ---`rednet.lookup()` requests 111 | ---@param protocol string The protocol to unregister from 112 | ------ 113 | ---[Official Documentation](https://tweaked.cc/module/rednet.html#v:unhost) 114 | function rednet.unhost(protocol) end 115 | 116 | ---Search the network for computers hosting a specific protocol 117 | ---@param protocol string The protocol to perform a lookup on 118 | ---@param hostname? string The hostname to search for 119 | ---@return number|nil ... The IDs of any computers that match the search critera 120 | ------ 121 | ---[Official Documentation](https://tweaked.cc/module/rednet.html#v:lookup) 122 | function rednet.lookup(protocol, hostname) end 123 | 124 | ---Listen for modem messages and convert them into rednet messages, ready for 125 | ---receiving through `rednet.receive()` 126 | --- 127 | ---⚠️ This is called on startup and should not be called manually 128 | --- 129 | ------ 130 | ---[Official Documentation](https://tweaked.cc/module/rednet.html#v:run) 131 | function rednet.run() end 132 | -------------------------------------------------------------------------------- /library/peripheral.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---Functions for finding and controlling peripherals (such as a drive, monitor, 4 | ---or turtle) attached to this computer 5 | --- 6 | ---### Referencing Peripherals 7 | ---Computers can interact with adjacent peripherals. Each peripheral is given a 8 | ---name based on which direction it is in:\ 9 | ---`"bottom"`, `"top"`, `"left"`, `"right"`, `"front"`, `"back"` 10 | --- 11 | ---It's also possible to use peripherals which are further away using modems. 12 | ---Place one modem against your computer and another modem against your 13 | ---peripheral. You can then right click the modem to use (or attach) the 14 | ---peripheral. This will print a peripheral name to chat, which can then be used 15 | ---just like a direction name to access the peripheral. You can click on the 16 | ---message to copy the name to your clipboard. 17 | --- 18 | ---### Using Peripherals 19 | ---Once you have the name of a peripheral, you can call functions on it using 20 | ---`peripheral.call()`. Once you start making a couple of peripheral 21 | ---calls this can get very repetitive, and so we can wrap a peripheral. This 22 | ---builds a table of all the peripheral's functions so you can use it like an API 23 | ---or module. 24 | --- 25 | ---### Finding Peripherals 26 | ---Sometimes you just need to know a peripheral exists. Thankfully there's 27 | ---`peripheral.find()`. This takes a peripheral type and returns all the attached 28 | ---peripherals which are of this type. 29 | --- 30 | ---What is a peripheral type though? This is a string which describes what a 31 | ---peripheral is, and so what functions are available on it. For instance, 32 | ---speakers are just called `speaker`, and monitors `monitor`. Some peripherals 33 | ---might have more than one type - a Minecraft chest is both a `minecraft:chest` 34 | ---and `inventory`. You can get all the types a peripheral has with 35 | ---`peripheral.getType()`, and check a peripheral is a specific type with 36 | ---`peripheral.hasType()`. 37 | --- 38 | ------ 39 | ---[Official Documentation](https://tweaked.cc/module/peripheral.html) 40 | peripheral = {} 41 | 42 | ---Get a list of all available peripherals 43 | --- 44 | ---If a peripheral is attached to a side, its name will be listed as the side it 45 | ---is attached to, if it is attached remotely, it will have a unique name from 46 | ---the network it is on 47 | ---@return string[] peripherals A list of the names of all of connected peripherals 48 | ------ 49 | ---[Official Documentation](https://tweaked.cc/module/peripheral.html#v:getNames) 50 | function peripheral.getNames() end 51 | 52 | ---Determines if a peripheral is present 53 | ---@param name string|ccTweaked.peripheral.computerSide The name of the device or side of the computer to check 54 | ---@return boolean isPresent If *some* peripheral is present on the specified side or with the specified name 55 | ------ 56 | ---[Official Documentation](https://tweaked.cc/module/peripheral.html#v:isPresent) 57 | function peripheral.isPresent(name) end 58 | 59 | ---Get the type(s) of a peripheral 60 | ---@param peripheral string|ccTweaked.peripheral.computerSide|ccTweaked.peripheral.wrappedPeripheral The name/side or wrapped instance of a peripheral to get the type(s) of 61 | ---@return ccTweaked.peripheral.peripheralType ... The peripheral's types or `nil` if one is not present 62 | ------ 63 | ---[Official Documentation](https://tweaked.cc/module/peripheral.html#v:getType) 64 | function peripheral.getType(peripheral) end 65 | 66 | ---Check that a peripheral has a given type 67 | ---@param peripheral string|ccTweaked.peripheral.computerSide|ccTweaked.peripheral.wrappedPeripheral The name/side or wrapped instance of a peripheral to check the type of 68 | ---@param peripheralType ccTweaked.peripheral.peripheralType The type to check 69 | ---@return boolean|nil hasType If the peripheral has the given type or `nil` if it is not present 70 | ------ 71 | ---[Official Documentation](https://tweaked.cc/module/peripheral.html#v:hasType) 72 | function peripheral.hasType(peripheral, peripheralType) end 73 | 74 | ---Get the methods for the peripheral with a given name 75 | ---@param name string|ccTweaked.peripheral.computerSide The name/side of the peripheral to get the methods of 76 | ---@return string[]|nil methods An array of method names that are provided by the peripheral or `nil` if it is not present 77 | ------ 78 | ---[Official Documentation](https://tweaked.cc/module/peripheral.html#v:getMethods) 79 | function peripheral.getMethods(name) end 80 | 81 | ---Get the name of a wrapped peripheral 82 | ---@param peripheral ccTweaked.peripheral.wrappedPeripheral The peripheral to get the name of 83 | ---@return string name The name of the peripheral 84 | ------ 85 | ---[Official Documentation](https://tweaked.cc/module/peripheral.html#v:getName) 86 | function peripheral.getName(peripheral) end 87 | 88 | ---Call a method on the peripheral with the provided name 89 | ---@param name string|ccTweaked.peripheral.computerSide The peripheral to invoke the method on 90 | ---@param method string The name of the method to call 91 | ---@param ... any Args to pass to the method 92 | ---@return any ... Return values from the method 93 | ------ 94 | ---[Official Documentation](https://tweaked.cc/module/peripheral.html#v:call) 95 | function peripheral.call(name, method, ...) end 96 | 97 | ---Get a table containing all methods available on a peripheral 98 | ---@param name string|ccTweaked.peripheral.computerSide The name of the peripheral to wrap 99 | ---@return ccTweaked.peripheral.wrappedPeripheral|nil wrappedPeripheral The table containing the peripheral's methods or `nil` if the peripheral does not exist 100 | ------ 101 | ---[Official Documentation](https://tweaked.cc/module/peripheral.html#v:wrap) 102 | function peripheral.wrap(name) end 103 | 104 | ---Find all peripherals of a given type and return them wrapped 105 | ---@param peripheralType ccTweaked.peripheral.peripheralType The type of peripheral to find 106 | ---@param filter? fun(name: string, wrapped: ccTweaked.peripheral.wrappedPeripheral): boolean A filter function that should return if the peripheral should be included in the result 107 | ---@return ccTweaked.peripheral.wrappedPeripheral[] wrappedPeripherals The wrapped peripherals that were found, if any 108 | ---## Example 109 | ---``` 110 | ---local monitors = { peripheral.find("monitor") } 111 | ---for _, monitor in pairs(monitors) do 112 | --- monitor.write("Hello") 113 | ---end 114 | ---``` 115 | ------ 116 | ---[Official Documentation](https://tweaked.cc/module/peripheral.html#v:find) 117 | function peripheral.find(peripheralType, filter) end 118 | -------------------------------------------------------------------------------- /library/colors.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---Contains constants and functions for colour values. Useful in conjunction 4 | ---with Bundled Cables from mods like [Project 5 | ---Red](https://projectredwiki.com/wiki/Main_Page), and colors on Advanced 6 | ---Computers and Advanced Monitors. 7 | --- 8 | ---For a British English version, replace colors with colours. This alternative 9 | ---API is exactly the same except the colours use British English (e.g. 10 | ---colors.gray is spelt colours.grey). 11 | --- 12 | ---On basic non-color terminals, all the colors are converted to grayscale. This 13 | ---means you can still use all 16 colors on the screen, but they will appear as 14 | ---the nearest tint of gray. You can check if a terminal supports color by using 15 | ---the function `term.isColor`. Grayscale colors are calculated by taking the 16 | ---average of the three components, i.e. `(red + green + blue) / 3`. 17 | --- 18 | ------ 19 | ---[Official Documentation](https://tweaked.cc/module/colors.html) 20 | colors = {} 21 | 22 | ---**Hex**: `#F0F0F0`\ 23 | ---**RGB**: `240, 240, 240` 24 | ---@type ccTweaked.colors.color 25 | colors.white = 1 26 | 27 | ---**Hex**: `#F2B233`\ 28 | ---**RGB**: `242, 178, 51` 29 | ---@type ccTweaked.colors.color 30 | colors.orange = 2 31 | 32 | ---**Hex**: `#E57FD8`\ 33 | ---**RGB**: `229, 127, 216` 34 | ---@type ccTweaked.colors.color 35 | colors.magenta = 4 36 | 37 | ---**Hex**: `#99B2F2`\ 38 | ---**RGB**: `153, 178, 242` 39 | ---@type ccTweaked.colors.color 40 | colors.lightBlue = 8 41 | 42 | ---**Hex**: `#DEDE6C`\ 43 | ---**RGB**: `222, 222, 108` 44 | ---@type ccTweaked.colors.color 45 | colors.yellow = 16 46 | 47 | ---**Hex**: `#7FCC19`\ 48 | ---**RGB**: `127, 204, 25` 49 | ---@type ccTweaked.colors.color 50 | colors.lime = 32 51 | 52 | ---**Hex**: `#F2B2CC`\ 53 | ---**RGB**: `242, 178, 204` 54 | ---@type ccTweaked.colors.color 55 | colors.pink = 64 56 | 57 | ---**Hex**: `#4C4C4C`\ 58 | ---**RGB**: `76, 76, 76` 59 | ---@type ccTweaked.colors.color 60 | colors.gray = 128 61 | 62 | ---**Hex**: `#999999`\ 63 | ---**RGB**: `153, 153, 153` 64 | ---@type ccTweaked.colors.color 65 | colors.lightGray = 256 66 | 67 | ---**Hex**: `#4C99B2`\ 68 | ---**RGB**: `76, 153, 178` 69 | ---@type ccTweaked.colors.color 70 | colors.cyan = 512 71 | 72 | ---**Hex**: `#B266E5`\ 73 | ---**RGB**: `178, 102, 229` 74 | ---@type ccTweaked.colors.color 75 | colors.purple = 1024 76 | 77 | ---**Hex**: `#3366CC`\ 78 | ---**RGB**: `51, 102, 204` 79 | ---@type ccTweaked.colors.color 80 | colors.blue = 2048 81 | 82 | ---**Hex**: `#7F664C`\ 83 | ---**RGB**: `127, 102, 76` 84 | ---@type ccTweaked.colors.color 85 | colors.brown = 4096 86 | 87 | ---**Hex**: `#57A64E`\ 88 | ---**RGB**: `87, 166, 78` 89 | ---@type ccTweaked.colors.color 90 | colors.green = 8192 91 | 92 | ---**Hex**: `#CC4C4C`\ 93 | ---**RGB**: `204, 76, 76` 94 | ---@type ccTweaked.colors.color 95 | colors.red = 16384 96 | 97 | ---**Hex**: `#111111`\ 98 | ---**RGB**: `17, 17, 17` 99 | ---@type ccTweaked.colors.color 100 | colors.black = 32768 101 | 102 | ---Combines colors into a set. Useful for Bundled Cables 103 | ---@vararg ccTweaked.colors.color 104 | ---@return ccTweaked.colors.colorSet set The result of combining the provided colors 105 | ---## Example 106 | ---``` 107 | ---colors.combine(colors.white, colors.magenta, colours.lightBlue) 108 | -----> 13 109 | ---``` 110 | ------ 111 | ---[Official Documentation](https://tweaked.cc/module/colors.html#v:combine) 112 | function colors.combine(...) end 113 | 114 | ---Removes one or more colors from a set. Useful for Bundled Cables. 115 | ---@param color ccTweaked.colors.color The color to subtract from 116 | ---@vararg ccTweaked.colors.color 117 | ---@return ccTweaked.colors.colorSet set The result of subtracting the provided colors 118 | ---## Example 119 | ---``` 120 | ---colors.subtract(colours.lime, colours.orange, colours.white) 121 | -----> 32 122 | ---``` 123 | ------ 124 | ---[Official Documentation](https://tweaked.cc/module/colors.html#v:subtract) 125 | function colors.subtract(color, ...) end 126 | 127 | ---Test whether a color is contained within a color set 128 | ---@param set ccTweaked.colors.colorSet 129 | ---@param color ccTweaked.colors.color 130 | ---## Example 131 | ---``` 132 | ---colors.test(colors.combine(colors.white, colors.magenta, colours.lightBlue), colors.lightBlue) 133 | -----> true 134 | ---``` 135 | ------ 136 | ---[Official Documentation](https://tweaked.cc/module/colors.html#v:test) 137 | function colors.test(set, color) end 138 | 139 | ---Combine an RGB value into one hexadecimal representation 140 | ---@param r number The red channel (0 - 1) 141 | ---@param g number The green channel (0 - 1) 142 | ---@param b number The blue channel (0 - 1) 143 | ---@return number hex The hexadecimal representation of the RGB value 144 | ---## Example 145 | ---``` 146 | ---colors.packRGB(0.7, 0.2, 0.6) 147 | -----> 0xb23399 148 | ---``` 149 | ------ 150 | ---[Official Documentation](https://tweaked.cc/module/colors.html#v:packRGB) 151 | function colors.packRGB(r, g, b) end 152 | 153 | ---Convert a hex value into separate r, g, b, values 154 | ---@param hex number 155 | ---@return number r Red component (0 - 1) 156 | ---@return number g Green component (0 - 1) 157 | ---@return number b Blue component (0 - 1) 158 | ---## Example 159 | ---``` 160 | ---colors.unpackRGB(0xb23399) 161 | -----> 0.7, 0.2, 0.6 162 | ---``` 163 | function colors.unpackRGB(hex) end 164 | 165 | ---Calls either `colors.packRGB` or `colors.unpackRGB` depending on how many 166 | ---arguments it receives. 167 | ---@deprecated 168 | ---@param r number The red channel (0 - 1) 169 | ---@param g number The green channel (0 - 1) 170 | ---@param b number The blue channel (0 - 1) 171 | ---@return number hex The hexadecimal representation of the RGB value 172 | ---🚮 **Deprecated in `v1.81.0`**, use `colors.packRGB()` 173 | ---## Example 174 | ---``` 175 | ---colors.rgb8(0.7, 0.2, 0.6) 176 | -----> 0xb23399 177 | ---``` 178 | ------ 179 | ---[Official Documentation](https://tweaked.cc/module/colors.html#v:rgb8) 180 | function colors.rgb8(r, g, b) end 181 | 182 | ---Calls either `colors.packRGB` or `colors.unpackRGB` depending on how many 183 | ---arguments it receives. 184 | ---@deprecated 185 | ---@param hex number 186 | ---@return number r Red component (0 - 1) 187 | ---@return number g Green component (0 - 1) 188 | ---@return number b Blue component (0 - 1) 189 | ---🚮 **Deprecated in `v1.81.0`**, use `colors.unpackRGB()` 190 | ---## Example 191 | ---``` 192 | ---colors.rgb8(0xb23399) 193 | -----> 0.7, 0.2, 0.6 194 | ---``` 195 | ------ 196 | ---[Official Documentation](https://tweaked.cc/module/colors.html#v:rgb8) 197 | function colors.rgb8(hex) end 198 | 199 | ---Converts a color into a blit hex character for use with `term.blit()` 200 | ---@param color ccTweaked.colors.color The color to convert 201 | ---@return string blit The blit hex character that represents the given color 202 | ---## Example 203 | ---``` 204 | ---colors.toBlit(colors.magenta) 205 | -----> "2" 206 | ---``` 207 | ------ 208 | ---[Official Documentation](https://tweaked.cc/module/colors.html#v:toBlit) 209 | function colors.toBlit(color) end 210 | -------------------------------------------------------------------------------- /library/shell.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---The shell API provides access to CraftOS's command line interface (CLI) 4 | --- 5 | ---The shell is not a "true" API. It is actually a program which injects it's 6 | ---API into the programs that it launches. This allows multiple shells to run at 7 | ---the same time but means that it isn't available in the global environment, 8 | ---meaning it is unavailable to other APIs 9 | --- 10 | ------ 11 | ---[Official Documentation](https://tweaked.cc/module/shell.html) 12 | ---@class shell 13 | shell = {} 14 | 15 | ---Run a program with the provided arguments 16 | --- 17 | ---Unlike `shell.run()`, each argument is passed to the program as-is. 18 | --- 19 | ---`shell.run("echo", "a b c")` will run echo with the arguments `a`, `b`, and 20 | ---`c`. `shell.execute("echo", "a b c")` will run echo with the argument "a b c" 21 | ---@param command string The program to execute 22 | ---@param ... string Arguments to this program 23 | ---@return boolean success Whether the program exited successfully 24 | ------ 25 | ---[Official Documentation](https://tweaked.cc/module/shell.html#v:execute) 26 | function shell.execute(command, ...) end 27 | 28 | ---Run a command with the provided arguments as if it were called from the command line 29 | ---@param command string The program to execute 30 | ---@param ... string Arguments to concatenate and pass to the program as a command line input 31 | ---@return boolean success Whether the program exited successfully 32 | ------ 33 | ---[Official Documentation](https://tweaked.cc/module/shell.html#v:run) 34 | function shell.run(command, ...) end 35 | 36 | ---Exit the current shell 37 | --- 38 | ---This will not terminate your running program, however, it will terminate the shell when the program exits 39 | --- 40 | ---If this is called on the top-level shell, the computer will shutdown 41 | --- 42 | ------ 43 | ---[Official Documentation](https://tweaked.cc/module/shell.html#v:exit) 44 | function shell.exit() end 45 | 46 | ---Get the current working directory 47 | ---@return string path The current working directory 48 | ------ 49 | ---[Official Documentation](https://tweaked.cc/module/shell.html#v:dir) 50 | function shell.dir() end 51 | 52 | ---Set the current working directory 53 | ---@param dir ccTweaked.fs.path The path to the current working directory 54 | ---@throws If the path does not exist 55 | ---@throws If the path is not a directory 56 | ------ 57 | ---[Official Documentation](https://tweaked.cc/module/shell.html#v:setDir) 58 | function shell.setDir(dir) end 59 | 60 | ---Get the path where programs are located 61 | --- 62 | ---The path is a list of diretories separated by a colon (`:`) 63 | --- 64 | ---For example, turtles will look in: 65 | ---- `/rom/programs` 66 | ---- `/rom/programs/turtle/` 67 | ---@return ccTweaked.fs.path path The current path to programs 68 | ------ 69 | ---[Official Documentation](https://tweaked.cc/module/shell.html#v:path) 70 | function shell.path() end 71 | 72 | ---Set the path where programs are located 73 | --- 74 | ---The path is a list of diretories separated by a colon (`:`) 75 | --- 76 | ---Make sure paths start with a `/` otherwise they will be searched for from the 77 | ---current working directory rather than the root of this computer 78 | ---@param path ccTweaked.fs.path The path where programs are located 79 | ------ 80 | ---[Official Documentation](https://tweaked.cc/module/shell.html#v:setPath) 81 | function shell.setPath(path) end 82 | 83 | ---Resolve a relative path to an absolute path 84 | --- 85 | ---Many APIs only take absolute paths so this function will help convert to them 86 | --- 87 | ---This does nothing if the path starts with `/` 88 | ---@param path ccTweaked.fs.path The relative path to resolve 89 | ---@return ccTweaked.fs.path absolutePath The path converted to an absolute path 90 | ------ 91 | ---[Official Documentation](https://tweaked.cc/module/shell.html#v:resolve) 92 | function shell.resolve(path) end 93 | 94 | ---Resolve a program, searching through the program `path` and list of `aliases` 95 | ---@param command string The name of the program 96 | ---@return string|nil absolutePath The absolute path to the program or `nil` if it could not be found 97 | ---## Example 98 | ---``` 99 | ---shell.resolveProgram("hello") 100 | ----- => rom/programs/fun/hello.lua 101 | ---``` 102 | ------ 103 | ---[Official Documentation](https://tweaked.cc/module/shell.html#v:resolveProgram) 104 | function shell.resolveProgram(command) end 105 | 106 | ---Get a list of all programs at `path` 107 | ---@param includeHidden? boolean If hidden files should be included (those that start with `.`) 108 | ---@return string[] programs A list of available programs 109 | ------ 110 | ---[Official Documentation](https://tweaked.cc/module/shell.html#v:programs) 111 | function shell.programs(includeHidden) end 112 | 113 | ---Complete an incomplete shell command line 114 | --- 115 | ---Completion handlers for your program can be registered with `shell.setCompletionFunction()` 116 | ---@param command string The input to complete 117 | ---@return string[]|nil completions An array of possible completions or `nil` if there are none 118 | ------ 119 | ---[Official Documentation](https://tweaked.cc/module/shell.html#v:complete) 120 | function shell.complete(command) end 121 | 122 | ---Complete the name of a program 123 | ---@param program string The name of the program to complete 124 | ---@return string[] completions An array of possible completions 125 | ------ 126 | ---[Official Documentation](https://tweaked.cc/module/shell.html#v:completeProgram) 127 | function shell.completeProgram(program) end 128 | 129 | ---Set the completion function for a specific program 130 | --- 131 | ---When the given program is entered on the command line, the provided function 132 | ---will be called to provide completions 133 | --- 134 | ---For instance, when completing `pastebin put rom/st` our pastebin completion 135 | ---function will receive the shell API, an index of `2`, `rom/st` as the current 136 | ---argument, and a "previous" table of `{ "put" }`. This function may then wish to 137 | ---return a table containing `artup.lua`, indicating the entire command should be 138 | ---completed to `pastebin put rom/startup.lua`. 139 | --- 140 | ---You can also return a space at the end of an argument to help indicate that 141 | ---another argument is desired 142 | ---@param program ccTweaked.fs.path The absolute path to the program without a leading `/` 143 | ---@param complete ccTweaked.shell.shellCompletionFunction The function to use for completions 144 | ------ 145 | ---[Official Documentation](https://tweaked.cc/module/shell.html#v:setCompletionFunction) 146 | function shell.setCompletionFunction(program, complete) end 147 | 148 | ---Get a list of all completion functions 149 | --- 150 | ---This should only be needed when creating a custom shell 151 | ---@return shellCompletionInfo 152 | ------ 153 | ---[Official Documentation](https://tweaked.cc/module/shell.html#v:getCompletionInfo) 154 | function shell.getCompletionInfo() end 155 | 156 | ---Get the path of the currently running program 157 | ---@return ccTweaked.fs.path path The path to the currently running program 158 | ------ 159 | ---[Official Documentation](https://tweaked.cc/module/shell.html#v:getRunningProgram) 160 | function shell.getRunningProgram() end 161 | 162 | ---Add an alias for a program 163 | ---@param alias string The alias to add 164 | ---@param program string|ccTweaked.fs.path The name/path of the program to alias 165 | ------ 166 | ---[Official Documentation](https://tweaked.cc/module/shell.html#v:setAlias) 167 | function shell.setAlias(alias, program) end 168 | 169 | ---Remove an alias for a program 170 | ---@param alias string The alias to remove 171 | ------ 172 | ---[Official Documentation](https://tweaked.cc/module/shell.html#v:clearAlias) 173 | function shell.clearAlias(alias) end 174 | 175 | ---Get a list of all aliases for this shell 176 | ---@return table aliases A table where the keys are the aliases and the values are the paths to the program being aliased 177 | ------ 178 | ---[Official Documentation](https://tweaked.cc/module/shell.html#v:aliases) 179 | function shell.aliases() end 180 | 181 | ---Open a new multishell tab 182 | --- 183 | ---This function is only available if the `multishell` API is 184 | ---@param ... string The command line to run 185 | ---@return ccTweaked.multishell.PID PID The ID of the process that was started 186 | ---## Example 187 | ---``` 188 | ---local id = shell.openTab("lua") 189 | ---shell.switchTab(id) 190 | ---``` 191 | ------ 192 | ---[Official Documentation](https://tweaked.cc/module/shell.html#v:openTab) 193 | function shell.openTab(...) end 194 | 195 | ---Switch to a different `multishell` tab 196 | ---@param PID ccTweaked.multishell.PID The ID of the process to switch to 197 | ------ 198 | ---[Official Documentation](https://tweaked.cc/module/shell.html#v:switchTab) 199 | function shell.switchTab(PID) end 200 | -------------------------------------------------------------------------------- /library/http.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---An API for making [HTTP 4 | ---requests](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods). Allows 5 | ---sending/receiving data to/from a web server. 6 | --- 7 | ---[Making requests to local IPs](https://tweaked.cc/guide/local_ips.html) is 8 | ---blocked by default but can be enabled in the configuration file. 9 | ------ 10 | ---[Official Documentation](https://tweaked.cc/module/http.html) 11 | http = {} 12 | 13 | ---Asynchronously make a 14 | ---[GET](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET) or 15 | ---[POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST) request 16 | --- 17 | ---When the request is completed, the `http_success` or `http_failure` event will be fired. 18 | ---@async 19 | ---@param url string The URL to make the request to 20 | ---@param body? string The body of the request. If provided, a [POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST) request will be made 21 | ---@param headers? table The [request headers](https://developer.mozilla.org/en-US/docs/Glossary/Request_header) 22 | ---@param binary? boolean If the request should be a binary request. If true, the body will not be UTF-8 encoded and the response will not be decoded 23 | ------ 24 | ---[Official Documentation](https://tweaked.cc/module/http.html#v:request) 25 | function http.request(url, body, headers, binary) end 26 | 27 | ---Asynchronously make a [HTTP request](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods) 28 | --- 29 | ---When the request is completed, the `http_success` or `http_failure` event will be fired. 30 | ---@async 31 | ---@param request ccTweaked.http.HTTP_REQUEST 32 | ---## Request Parameter Shape 33 | ---``` 34 | ---request = { 35 | --- url: string, -- The URL to make the request to 36 | --- body?: string, -- The body of the request, if it has one 37 | --- headers?: {[string] = string}, -- The request headers 38 | --- binary?: boolean, -- If the request should be a binary request. If true, the body will not be UTF-8 encoded and the response will not be decoded 39 | --- method?: string, -- The HTTP method to use 40 | --- redirect?: boolean -- Whether HTTP redirects should be followed. Defaults to true 41 | ---} 42 | ---``` 43 | ------ 44 | ---[Official Documentation](https://tweaked.cc/module/http.html#v:request) 45 | function http.request(request) end 46 | 47 | ---Make a [GET](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET) request 48 | ---@param url string The URL to make the request to 49 | ---@param headers? table The [request headers](https://developer.mozilla.org/en-US/docs/Glossary/Request_header) 50 | ---@param binary? boolean If the request should be a binary request. If true, the body will not be UTF-8 encoded and the response will not be decoded 51 | ---@return ccTweaked.http.Response|ccTweaked.http.BinaryResponse|nil response The HTTP response object. `nil` when the request fails 52 | ---@return string message Why the request failed 53 | ---@return nil|ccTweaked.http.Response|ccTweaked.http.BinaryResponse failedResponse The response object for the failed request, if available 54 | ------ 55 | ---[Official Documentation](https://tweaked.cc/module/http.html#v:get) 56 | function http.get(url, headers, binary) end 57 | 58 | ---Make a HTTP request 59 | ---@param request ccTweaked.http.HTTP_REQUEST 60 | ---@return ccTweaked.http.Response|ccTweaked.http.BinaryResponse|nil response The HTTP response object. `nil` when the request fails 61 | ---@return string message Why the request failed 62 | ---@return nil|ccTweaked.http.Response|ccTweaked.http.BinaryResponse failedResponse The response object for the failed request, if available 63 | ---## Request Parameter Shape 64 | ---``` 65 | ---request = { 66 | --- url: string, -- The URL to make the request to 67 | --- body?: string, -- The body of the request, if it has one 68 | --- headers?: {[string] = string}, -- The request headers 69 | --- binary?: boolean, -- If the request should be a binary request. If true, the body will not be UTF-8 encoded and the response will not be decoded 70 | --- method?: string, -- The HTTP method to use 71 | --- redirect?: boolean -- Whether HTTP redirects should be followed. Defaults to true 72 | ---} 73 | ---``` 74 | ------ 75 | ---[Official Documentation](https://tweaked.cc/module/http.html#v:get) 76 | function http.get(request) end 77 | 78 | ---Make a [POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST) request 79 | ---@param url string The URL to make the request to 80 | ---@param body string The body of the [POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST) request 81 | ---@param headers? table The [request headers](https://developer.mozilla.org/en-US/docs/Glossary/Request_header) 82 | ---@param binary? boolean If the request should be a binary request. If true, the body will not be UTF-8 encoded and the response will not be decoded 83 | ---@return ccTweaked.http.Response|ccTweaked.http.BinaryResponse|nil response The HTTP response object. `nil` when the request fails 84 | ---@return string message Why the request failed 85 | ---@return nil|ccTweaked.http.Response|ccTweaked.http.BinaryResponse failedResponse The response object for the failed request, if available 86 | ------ 87 | ---[Official Documentation](https://tweaked.cc/module/http.html#v:post) 88 | function http.post(url, body, headers, binary) end 89 | 90 | ---Make a HTTP request 91 | ---@param request ccTweaked.http.HTTP_REQUEST 92 | ---@return ccTweaked.http.Response|ccTweaked.http.BinaryResponse|nil response The HTTP response object. `nil` when the request fails 93 | ---@return string message Why the request failed 94 | ---@return nil|ccTweaked.http.Response|ccTweaked.http.BinaryResponse failedResponse The response object for the failed request, if available 95 | ---## Request Parameter Shape 96 | ---``` 97 | ---request = { 98 | --- url: string, -- The URL to make the request to 99 | --- body?: string, -- The body of the request, if it has one 100 | --- headers?: {[string] = string}, -- The request headers 101 | --- binary?: boolean, -- If the request should be a binary request. If true, the body will not be UTF-8 encoded and the response will not be decoded 102 | --- method?: string, -- The HTTP method to use 103 | --- redirect?: boolean -- Whether HTTP requests should be followed. Defaults to true 104 | ---} 105 | ---``` 106 | ------ 107 | ---[Official Documentation](https://tweaked.cc/module/http.html#v:post) 108 | function http.post(request) end 109 | 110 | ---Asynchronously determine if a URL can be requested 111 | --- 112 | ---This will immediately return if the URL entered is itself invalid. You will 113 | ---then want to listen to the `http_check` event which will contain more info on 114 | ---if the URL can be requested. 115 | ---@async 116 | ---@param url string The URL to check 117 | ---@return boolean valid If the URL is valid. It could still 404, this is just confirming the URL is valid (read above) 118 | ---@return nil|string message Why the URL is invalid (e.g. blocked, malformed, etc.) 119 | ------ 120 | ---[Official Documentation](https://tweaked.cc/module/http.html#v:checkURLAsync) 121 | function http.checkURLAsync(url) end 122 | 123 | ---Determine if a URL can be requested 124 | ---@param url string The URL to check 125 | ---@return boolean valid If the URL can be requested 126 | ---@return nil|string message Why the URL cannot be requested (e.g. blocked, malformed, etc.) 127 | ------ 128 | ---[Official Documentation](https://tweaked.cc/module/http.html#v:checkURL) 129 | function http.checkURL(url) end 130 | 131 | ---Open a websocket 132 | ---@param url string The URL of the websocket to connect to. Should use the `ws://` or `wss://` protocol 133 | ---@param headers? table Headers to send for the handshake 134 | ---@return ccTweaked.http.Websocket|false websocket The websocket connection object or false if it failed to connect 135 | ---@return string message Why the websocket failed to connect 136 | ------ 137 | ---[Official Documentation](https://tweaked.cc/module/http.html#v:websocket) 138 | function http.websocket(url, headers) end 139 | 140 | ---Open a websocket 141 | ---@param request ccTweaked.http.WEBSOCKET_OPTIONS Options for the websocket connection 142 | ---@return ccTweaked.http.Websocket|false websocket The websocket connection object or false if it failed to connect 143 | ---@return string message Why the websocket failed to connect 144 | ---## Request Parameter Shape 145 | ---``` 146 | ---request = { 147 | --- url: string, -- The URL of the websocket to connect to. Should use the `ws://` or `wss://` protocol 148 | --- headers?: {[string] = string}, -- Headers to send for the handshake 149 | --- timeout?: number -- The amount of seconds to wait, before potentionally timing out 150 | ---} 151 | ---``` 152 | ------ 153 | ---[Official Documentation](https://tweaked.cc/module/http.html#v:websocket) 154 | function http.websocket(request) end 155 | 156 | ---Asynchronously open a websocket 157 | --- 158 | ---Returns immediately and a `websocket_success` or `websocket_failure` event will be fired when the request is completed 159 | ---@param url string The URL of the websocket to connect to. Should use the `ws://` or `wss://` protocol 160 | ---@param headers? table Headers to send for the handshake 161 | ------ 162 | ---[Official Documentation](https://tweaked.cc/module/http.html#v:websocketAsync) 163 | function http.websocketAsync(url, headers) end 164 | -------------------------------------------------------------------------------- /library/textutils.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---Utilities for formatting and manipulating strings 4 | textutils = {} 5 | 6 | ---Write text character-by-character at the cursor position 7 | --- 8 | ---Like `_G.write()`, this function does not append a newline 9 | ---@param text string The text to write to the screen 10 | ---@param rate? number The number of characters to write per second (defaults to 20) 11 | ------ 12 | ---[Official Documentation](https://tweaked.cc/module/textutils.html#v:slowWrite) 13 | function textutils.slowWrite(text, rate) end 14 | 15 | ---Print text character-by-character at the cursor position 16 | --- 17 | ---Like `_G.print()`, this function appends a newline 18 | ---@param text string The text to print to the screen 19 | ---@param rate? number The number of characters to write per second (defaults to 20) 20 | ------ 21 | ---[Official Documentation](https://tweaked.cc/module/textutils.html#v:slowPrint) 22 | function textutils.slowPrint(text, rate) end 23 | 24 | ---Formats a time value into a readable string 25 | ---@param time number The time to format, as provided by `os.time()` 26 | ---@param twentyFourHr boolean Whether to use 24 hour time or 12 hour time 27 | ---@return string formattedTime The time formatted as a string 28 | function textutils.formatTime(time, twentyFourHr) end 29 | 30 | ---Print text to the screen 31 | --- 32 | ---Should the text not all fit on the screen, a "Press any key to continue" 33 | ---prompt will appear. Each keypress will scroll one line 34 | ---@param text string The text to print to the screen 35 | ---@param leadingLines? integer The amount of blank lines to print before the `text`. `leadingLines` + 1 will be printed. The cursor's Y position - 2 will try to fill the screen. Defaults to 0, meaning only one line is printed 36 | ---@return integer linesPrinted The number of lines that were printed 37 | ------ 38 | ---[Official Documentation](https://tweaked.cc/module/textutils.html#v:pagedPrint) 39 | function textutils.pagedPrint(text, leadingLines) end 40 | 41 | ---Print tables in a structured form 42 | --- 43 | ---This accepts multiple arguments. When encountering a table, it is treated as 44 | ---a row with column widths being auto adjusted. When encountering a number, this 45 | ---sets the text color for subsequent rows 46 | ---@param ... table|number The rows and text colors to display 47 | ---## Example 48 | ---``` 49 | ---textutils.tabulate( 50 | --- colors.orange, { "1", "2", "3" }, 51 | --- colors.lightBlue, { "A", "B", "C" } 52 | ---) 53 | ---``` 54 | ------ 55 | ---[Official Documentation](https://tweaked.cc/module/textutils.html#v:tabulate) 56 | function textutils.tabulate(...) end 57 | 58 | ---Print tables in a structured form, stopping and prompting for input should 59 | ---the result not fit on the screen 60 | --- 61 | ---This accepts multiple arguments. When encountering a table, it is treated as 62 | ---a row with column widths being auto adjusted. When encountering a number, this 63 | ---sets the text color for subsequent rows 64 | ---@param ... table|number The rows and text colors to display 65 | ------ 66 | ---[Official Documentation](https://tweaked.cc/module/textutils.html#v:pagedTabulate) 67 | function textutils.pagedTabulate(...) end 68 | 69 | ---A table representing an empty JSON array 70 | --- 71 | ---Useful to help distinguish it from an empty JSON object 72 | --- 73 | ---⚠️ This should not be modified 74 | --- 75 | ------ 76 | ---[Official Documentation](https://tweaked.cc/module/textutils.html#v:empty_json_array) 77 | textutils.empty_json_array = { 78 | __tostring = function() 79 | return "[]" 80 | end, 81 | } 82 | 83 | ---A table representing the JSON null value 84 | --- 85 | ---⚠️ This should not be modified 86 | --- 87 | ------ 88 | ---[Official Documentation](https://tweaked.cc/module/textutils.html#v:json_null) 89 | textutils.json_null = { 90 | __tostring = function() 91 | return "null" 92 | end, 93 | } 94 | 95 | ---@alias serializable string|number|table|boolean 96 | 97 | ---Get a textual representation of a Lua object, suitable for saving to a file or 98 | ---printing 99 | ---@param tbl serializable The object to convert 100 | ---@param options? ccTweaked.textutils.serializationOptions 101 | ---@return string serialized The serialized representation 102 | ---@throws if the object is a function 103 | ---@throws If the table contains a function 104 | ---@throws If the table contains tables that appear multiple times 105 | ------ 106 | ---[Official Documentation](https://tweaked.cc/module/textutils.html#v:serialize) 107 | function textutils.serialize(tbl, options) end 108 | 109 | ---Get a textual representation of a Lua object, suitable for saving to a file or 110 | ---printing 111 | ---@param t serializable The object to convert 112 | ---@param options? ccTweaked.textutils.serializationOptions 113 | ---@return string serialised The serialised representation 114 | ---@throws if the object is a function 115 | ---@throws If the table contains a function 116 | ---@throws If the table contains tables that appear multiple times 117 | ------ 118 | ---[Official Documentation](https://tweaked.cc/module/textutils.html#v:serialise) 119 | function textutils.serialise(t, options) end 120 | 121 | ---Convert a serialized string back into a Lua object 122 | ---@param str string The text to turn back into an object 123 | ---@return serializable tbl The unserialized object or `nil` if the object couldn't be unserialized 124 | ------ 125 | ---[Official Documentation](https://tweaked.cc/module/textutils.html#v:unserialize) 126 | function textutils.unserialize(str) end 127 | 128 | ---Convert a serialised string back into a Lua objct 129 | ---@param str string The text to turn back into an object 130 | ---@return serializable tbl The unserialized object or `nil` if the object couldn't be unserialized 131 | ------ 132 | ---[Official Documentation](https://tweaked.cc/module/textutils.html#v:unserialise) 133 | function textutils.unserialise(str) end 134 | 135 | ---Get a JSON representation of the given value 136 | --- 137 | ---This function attempts to guess whether a table is a JSON array or object. 138 | ---However, empty tables are assumed to be empty objects - use 139 | ---`textutils.empty_json_array` to mark an empty array. 140 | --- 141 | ---This is largely intended for interacting with various functions from the 142 | ---commands API, though may also be used in making http requests. 143 | ---@param tbl serializable The value to serialize 144 | ---@param NBTstyle? boolean If [NBT style](https://minecraft.fandom.com/wiki/NBT_format) JSON (non-quoted keys) should be output 145 | ---@return string JSON The JSON output 146 | ---@throws If the `value` contains a function 147 | ---@throws If the `value` contains tables that appear multiple times 148 | ------ 149 | ---[Official Documentation](https://tweaked.cc/module/textutils.html#v:serializeJSON) 150 | function textutils.serializeJSON(tbl, NBTstyle) end 151 | 152 | ---Get a JSON representation of the given value 153 | --- 154 | ---This function attempts to guess whether a table is a JSON array or object. 155 | ---However, empty tables are assumed to be empty objects - use 156 | ---`textutils.empty_json_array` to mark an empty array. 157 | --- 158 | ---This is largely intended for interacting with various functions from the 159 | ---commands API, though may also be used in making http requests. 160 | ---@param tbl serializable The value to serialise 161 | ---@param NBTstyle? boolean If [NBT style](https://minecraft.fandom.com/wiki/NBT_format) JSON (non-quoted keys) should be output 162 | ---@return string JSON The JSON output 163 | ---@throws If `t` contains a function 164 | ---@throws If `t` contains tables that appear multiple times 165 | ------ 166 | ---[Official Documentation](https://tweaked.cc/module/textutils.html#v:serialiseJSON) 167 | function textutils.serialiseJSON(tbl, NBTstyle) end 168 | 169 | ---Convert a serialized JSON string back into a Lua table 170 | ---@param str string The string to unserialize 171 | ---@param options? ccTweaked.textutils.unserializeJSONOptions Options for unserializing 172 | ---@return serializable|nil unserialized The unserialized object or `nil` if the object couldn't be unserialized 173 | ---@return string|nil errorMessage Why the object couldn't be unserialized 174 | ------ 175 | ---[Official Documentation](https://tweaked.cc/module/textutils.html#v:unserializeJSON) 176 | function textutils.unserializeJSON(str, options) end 177 | 178 | ---Convert a serialised JSON string back into a Lua table 179 | ---@param str string The string to unserialise 180 | ---@param options? ccTweaked.textutils.unserializeJSONOptions Options for unserialising 181 | ---@return serializable|nil unserialised The unserialised object or `nil` if the object couldn't be unserialised 182 | ---@return string|nil errorMessage Why the object couldn't be unserialised 183 | ------ 184 | ---[Official Documentation](https://tweaked.cc/module/textutils.html#v:unserialiseJSON) 185 | function textutils.unserialiseJSON(str, options) end 186 | 187 | ---Encode a string to make it safe to use as a URL 188 | ---@param str string The string to encode 189 | ---@return string url The encoded url 190 | ------ 191 | ---[Official Documentation](https://tweaked.cc/module/textutils.html#v:urlEncode) 192 | function textutils.urlEncode(str) end 193 | 194 | ---Get completions for Lua expressions 195 | ---@param searchText string The text to complete 196 | ---@param searchTable? table A table to find variables in, defaulting to `_G`. It will also search through a parent metatable using the `__index` metamethod 197 | ---@return string[] completions A possibly empty array of completions 198 | ------ 199 | ---[Official Documentation](https://tweaked.cc/module/textutils.html#v:complete) 200 | function textutils.complete(searchText, searchTable) end 201 | -------------------------------------------------------------------------------- /library/types/objects/Redirect.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---A base class for all objects that interact with a terminal (e.g. `term` and monitors) 4 | ---@class ccTweaked.term.Redirect 5 | Redirect = {} 6 | 7 | ---Write `text` at the current cursor position, moving the cursor to the end of the text 8 | --- 9 | ---🗒️Unlike `_G.write()` and `_G.print()`, this function does not wrap text 10 | ---@param text string|number The text to write 11 | ------ 12 | ---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:write) 13 | function Redirect.write(text) end 14 | 15 | ---Move all positions up or down 16 | ---@param y number The number of lines to move by (can be negative) 17 | ------ 18 | ---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:scroll) 19 | function Redirect.scroll(y) end 20 | 21 | ---Get the current position of the cursor 22 | ---@return integer x The current x position 23 | ---@return integer y The current y position 24 | ------ 25 | ---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:getCursorPos) 26 | function Redirect.getCursorPos() end 27 | 28 | ---Set the position of the cursor 29 | ---@param x number The new x position 30 | ---@param y number The new y position 31 | ------ 32 | ---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:setCursorPos) 33 | function Redirect.setCursorPos(x, y) end 34 | 35 | ---Check if the cursor is currently blinking 36 | ---@return boolean isBlinking If the cursor is currently blinking 37 | ------ 38 | ---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:getCursorBlink) 39 | function Redirect.getCursorBlink() end 40 | 41 | ---Set whether the cursor should be visible and blinking at the current cursor position 42 | ---@param blink boolean If the cursor should be blinking 43 | ------ 44 | ---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:setCursorBlink) 45 | function Redirect.setCursorBlink(blink) end 46 | 47 | ---Get the size of the terminal 48 | ---@return integer width The terminal's width 49 | ---@return integer height The terminal's height 50 | ------ 51 | ---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:getSize) 52 | function Redirect.getSize() end 53 | 54 | ---Clears the terminal, filling it with the current background color 55 | --- 56 | ------ 57 | ---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:clear) 58 | function Redirect.clear() end 59 | 60 | ---Clears the line the cursor is on, filling it with the current background color 61 | --- 62 | ------ 63 | ---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:clearLine) 64 | function Redirect.clearLine() end 65 | 66 | ---Get the current text color that text would be drawn in 67 | ---@return ccTweaked.colors.color textColor The current text color 68 | ------ 69 | ---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:getTextColor) 70 | function Redirect.getTextColor() end 71 | 72 | ---Get the current text colour that text would be drawn in 73 | ---@return ccTweaked.colors.color textColour The current text colour 74 | ------ 75 | ---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:getTextColour) 76 | function Redirect.getTextColour() end 77 | 78 | ---Set the colour that text should be drawn in 79 | ---@param colour ccTweaked.colors.color The new colour text should be drawn in 80 | ------ 81 | ---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:setTextColour) 82 | function Redirect.setTextColour(colour) end 83 | 84 | ---Set the color that text should be drawn in 85 | ---@param color ccTweaked.colors.color The new color text should be drawn in 86 | ------ 87 | ---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:setTextColor) 88 | function Redirect.setTextColor(color) end 89 | 90 | ---Get the current background colour 91 | --- 92 | ---This is used when writing text and clearing the terminal 93 | ---@return ccTweaked.colors.color backgroundColour The current background colour 94 | ------ 95 | ---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:getBackgroundColour) 96 | function Redirect.getBackgroundColour() end 97 | 98 | ---Get the current background color 99 | --- 100 | ---This is used when writing text and clearing the terminal 101 | ---@return ccTweaked.colors.color backgroundColor The current background color 102 | ------ 103 | ---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:getBackgroundColor) 104 | function Redirect.getBackgroundColor() end 105 | 106 | ---Set the current background colour 107 | --- 108 | ---This is used when writing text and clearing the terminal 109 | ---@param colour ccTweaked.colors.color The new background colour that should be used 110 | ------ 111 | ---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:setBackgroundColour) 112 | function Redirect.setBackgroundColour(colour) end 113 | 114 | ---Set the current background color 115 | --- 116 | ---This is used when writing text and clearing the terminal 117 | ---@param color ccTweaked.colors.color The new background color that should be used 118 | ------ 119 | ---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:setBackgroundColor) 120 | function Redirect.setBackgroundColor(color) end 121 | 122 | ---Get whether this terminal supports colour 123 | --- 124 | ---Terminals which don't support colour still allow writing coloured 125 | ---text/backgrounds, but it will be displayed in greyscale 126 | ---@return boolean isColour Whether this terminal supports colour or not 127 | ------ 128 | ---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:isColour) 129 | function Redirect.isColour() end 130 | 131 | ---Get whether this terminal supports color 132 | --- 133 | ---Terminals which don't support color still allow writing colored 134 | ---text/backgrounds, but it will be displayed in greyscale 135 | ---@return boolean isColor Whether this terminal supports color or not 136 | ------ 137 | ---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:isColor) 138 | function Redirect.isColor() end 139 | 140 | ---Writes `text` to the terminal with the specified text and background colors 141 | --- 142 | ---The cursor will be moved to the end of the text after writing 143 | --- 144 | ---`textColor` and `backgroundColor` must both be strings and the same length as 145 | ---`text`. Each of their characters represent a single hexadecimal digit, which 146 | ---is converted to a color 147 | ---@param text string The text to write 148 | ---@param textColor string A string of hexadecimal values that correspond to colors from the `colors` API 149 | ---@param backgroundColor string A string of hexadecimal values that correspond to colors from the `colors` API 150 | ---@throws If the inputs are not all of the same length 151 | ---## Example 152 | ---``` 153 | ---term.blit("Hello, world!","01234456789ab","0000000000000") 154 | ---``` 155 | ------ 156 | ---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:blit) 157 | function Redirect.blit(text, textColor, backgroundColor) end 158 | 159 | ---Set the value for a specific colour from CC's palette 160 | --- 161 | ---While you still can't have more than 16 colours, you can change what values 162 | ---are available. For example, you can change `colors.red` to `#FF0000` for it to 163 | ---be *more* red 164 | ---@param index ccTweaked.colors.color The colour that should be changed 165 | ---@param colour integer A 24 bit integer representing the RGB value of a colour 166 | ---## Example 167 | ---``` 168 | ---term.setPaletteColour(colors.red, 0xFF0000) 169 | ---``` 170 | ------ 171 | ---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:setPaletteColour) 172 | function Redirect.setPaletteColour(index, colour) end 173 | 174 | ---Set the value for a specific colour from CC's palette 175 | --- 176 | ---While you still can't have more than 16 colours, you can change what values 177 | ---are available. For example, you can change `colors.red` to `1, 0, 0` for it to 178 | ---be *more* red 179 | ---@param index ccTweaked.colors.color The colour that should be changed 180 | ---@param r number The red channel value 181 | ---@param g number The green channel value 182 | ---@param b number The blue channel value 183 | ---## Example 184 | ---``` 185 | ---term.setPaletteColour(colors.red, 1, 0, 0) 186 | ---``` 187 | ------ 188 | ---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:setPaletteColour) 189 | function Redirect.setPaletteColour(index, r, g, b) end 190 | 191 | ---Set the value for a specific color from CC's palette 192 | --- 193 | ---While you still can't have more than 16 colors, you can change what values 194 | ---are available. For example, you can change `colors.red` to `#FF0000` for it to 195 | ---be *more* red 196 | ---@param index ccTweaked.colors.color The color that should be changed 197 | ---@param color integer A 24 bit integer representing the RGB value of a color 198 | ---## Example 199 | ---``` 200 | ---term.setPaletteColor(colors.red, 0xFF0000) 201 | ---``` 202 | ------ 203 | ---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:setPaletteColor) 204 | function Redirect.setPaletteColor(index, color) end 205 | 206 | ---Set the value for a specific color from CC's palette 207 | --- 208 | ---While you still can't have more than 16 colors, you can change what values 209 | ---are available. For example, you can change `colors.red` to `1, 0, 0` for it to 210 | ---be *more* red 211 | ---@param index ccTweaked.colors.color The color that should be changed 212 | ---@param r number The red channel value 213 | ---@param g number The green channel value 214 | ---@param b number The blue channel value 215 | ---## Example 216 | ---``` 217 | ---term.setPaletteColor(colors.red, 1, 0, 0) 218 | ---``` 219 | ------ 220 | ---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:setPaletteColor) 221 | function Redirect.setPaletteColor(index, r, g, b) end 222 | 223 | ---Get the current colour value for a specific colour from the palette 224 | ---@param colour ccTweaked.colors.color The colour to get the value of 225 | ---@return number red The red channel (0 - 1) 226 | ---@return number green The green channel (0 - 1) 227 | ---@return number blue The blue channel (0 - 1) 228 | ------ 229 | ---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:getPaletteColour) 230 | function Redirect.getPaletteColour(colour) end 231 | 232 | ---Get the current color value for a specific color from the palette 233 | ---@param color ccTweaked.colors.color The color to get the value of 234 | ---@return number red The red channel (0 - 1) 235 | ---@return number green The green channel (0 - 1) 236 | ---@return number blue The blue channel (0 - 1) 237 | ------ 238 | ---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:getPaletteColor) 239 | function Redirect.getPaletteColor(color) end 240 | -------------------------------------------------------------------------------- /library/fs.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---Provides functions for interacting with a computer's files 📄 and directories 📁 4 | --- 5 | ---All functions use [absolute 6 | ---paths](https://en.wikipedia.org/wiki/Path_(computing)#Absolute_and_relative_paths), 7 | ---however, `shell.resolve()` can be used to convert a relative path into an 8 | ---absolute path 9 | --- 10 | ---Computers only have one storage device and filesystem but other filesystems 11 | ---can be [mounted](https://en.wikipedia.org/wiki/Mount_(computing)) using 12 | ---peripherals such as the drive peripheral. These drives mount their disk's 13 | ---content at locations like `disk/`, `disk1/`, etc. 14 | --- 15 | ---Most filesystems have a finite capacity and trying to perform an operation 16 | ---that could exceed it will fail 17 | --- 18 | ------ 19 | ---[Official Documentation](https://tweaked.cc/module/fs.html) 20 | fs = {} 21 | 22 | ---Get whether a path is mounted to the root of the parent filesystem 23 | --- 24 | ---✅ 25 | ---- `/` 26 | ---- `/rom` 27 | ---- `/disk` 28 | --- 29 | ---❌ 30 | ---- `/rom/apis` 31 | ---- `/disc/helloWorld.lua` 32 | ---@param path ccTweaked.fs.path The path to check 33 | ---@return boolean isRoot If the specified path is mounted to the root 34 | ---@throws If the path does not exist 35 | ------ 36 | ---[Official Documentation](https://tweaked.cc/module/fs.html#v:isDriveRoot) 37 | function fs.isDriveRoot(path) end 38 | 39 | ---Provides completion for files/directories 40 | --- 41 | ---When a directory is a candidate, two entries are provided - one with a 42 | ---trailing slash (hinting that there are files/directories that exist past this 43 | ---one) and one without (suggesting that this directory *is* the target). Setting 44 | ---`includeDirectories` to false will only suggest directories with a trailing 45 | ---slash (meaning only directories with content will be suggested but are not 46 | ---meant to be the final target) 47 | ---@param path ccTweaked.fs.path The path to complete 48 | ---@param source ccTweaked.fs.path The path where further paths should be resolved from 49 | ---@param includeFiles? boolean If filenames should be completed 50 | ---@param includeDirectories? boolean If empty directories should be completed 51 | ---@return string[]|table candidates 52 | ---## Examples 53 | ---``` 54 | ---fs.complete("doesNot", "/exist") 55 | -----> {} 56 | --- 57 | ---fs.complete("modules", "/rom") 58 | -----> {"/"} 59 | --- 60 | ---fs.complete("modules/", "/rom") 61 | -----> {"command/", "command", "main/", "main", "turtle/", "turtle"} 62 | --- 63 | ---fs.complete("modules/", "/rom", true, false) 64 | -----> {"command/", "main/", "turtle/"} 65 | ---``` 66 | ------ 67 | ---[Official Documentation](https://tweaked.cc/module/fs.html#v:complete) 68 | function fs.complete(path, source, includeFiles, includeDirectories) end 69 | 70 | ---Get a list of files in a directory 71 | ---@param path ccTweaked.fs.path The path to the directory to check 72 | ---@return string[]|table files 73 | ---@throws If the path doesn't exist 74 | ---@throws If the path is not a directory 75 | ------ 76 | ---[Official Documentation](https://tweaked.cc/module/fs.html#v:list) 77 | function fs.list(path) end 78 | 79 | ---Combine multiple components of a path into a single path 80 | ---@param start ccTweaked.fs.path The start of the path 81 | ---@vararg ccTweaked.fs.path|string Path components to combine 82 | ---@return string path The combined path 83 | ---@throws If arguments are invalid (e.g. are numbers) 84 | ---## Example 85 | ---``` 86 | ---fs.combine("/rom/programs", "../apis", "parallel.lua") 87 | -----> rom/apis/parallel.lua 88 | ---``` 89 | ------ 90 | ---[Official Documentation](https://tweaked.cc/module/fs.html#v:combine) 91 | function fs.combine(start, ...) end 92 | 93 | ---Get the filename component of a path 94 | ---@param path ccTweaked.fs.path The path to get the filename from 95 | ---@return string filename The last component of a path (name of the file if the path points to a file) 96 | ---## Examples 97 | ---``` 98 | ---fs.getName("/") 99 | -----> "root" 100 | --- 101 | ---fs.getName("/rom/programs/") 102 | -----> "programs" 103 | --- 104 | ---fs.getName("/rom/programs/reboot.lua") 105 | -----> "reboot.lua" 106 | ---``` 107 | ------ 108 | ---[Official Documentation](https://tweaked.cc/module/fs.html#v:getName) 109 | function fs.getName(path) end 110 | 111 | ---Get the parent directory component of a path 112 | ---@param path ccTweaked.fs.path The path to get the parent directory from 113 | ---@return ccTweaked.fs.path|string parentDirectory The parent directory component of the path (all parent directories) 114 | ---## Examples 115 | ---``` 116 | ---fs.getDir("/rom/startup.lua") 117 | -----> "rom" 118 | --- 119 | ---fs.getDir("/rom/programs/") 120 | -----> "rom" 121 | --- 122 | ---fs.getDir("/rom/apis/command/") 123 | -----> "rom/apis" 124 | ---``` 125 | ------ 126 | ---[Official Documentation](https://tweaked.cc/module/fs.html#v:getDir) 127 | function fs.getDir(path) end 128 | 129 | ---Get the size of a file 130 | ---@param path ccTweaked.fs.path The path to the file to get the size of 131 | ---@return number bytes The size of the file in bytes. 0 if the path points to a directory 132 | ---@throws If the path doesn't exist 133 | ---## Examples 134 | ---``` 135 | ---fs.getSize("/rom/apis/vector.lua") 136 | -----> 5826 137 | --- 138 | ---fs.getSize("/rom/apis/turtle/") 139 | -----> 0 140 | ---``` 141 | ------ 142 | ---[Official Documentation](https://tweaked.cc/module/fs.html#v:getSize) 143 | function fs.getSize(path) end 144 | 145 | ---Get whether a path exists 146 | ---@param path ccTweaked.fs.path The path to check the existence of 147 | ---@return boolean exists 148 | ------ 149 | ---[Official Documentation](https://tweaked.cc/module/fs.html#v:exists) 150 | function fs.exists(path) end 151 | 152 | ---Get whether a path is a directory 153 | ---@param path ccTweaked.fs.path The path to check 154 | ---@return boolean isDirectory If the path exists **and** is a directory 155 | ------ 156 | ---[Official Documentation](https://tweaked.cc/module/fs.html#v:isDir) 157 | function fs.isDir(path) end 158 | 159 | ---Get whether a path is read-only 160 | ---@param path ccTweaked.fs.path The path to check 161 | ---@return boolean isReadOnly If the path can only be read and not written to 162 | ---## Example 163 | ---``` 164 | ---fs.isReadOnly("/rom") 165 | -----> true 166 | ---``` 167 | ------ 168 | ---[Official Documentation](https://tweaked.cc/module/fs.html#v:isReadOnly) 169 | function fs.isReadOnly(path) end 170 | 171 | ---Create a directory, including any missing parents 172 | ---@param path ccTweaked.fs.path The path to (and including) the directory to create 173 | ---@throws If target path could not be written to 174 | ------ 175 | ---[Official Documentation](https://tweaked.cc/module/fs.html#v:makeDir) 176 | function fs.makeDir(path) end 177 | 178 | ---Move a file/directory to another path 179 | --- 180 | ---Any missing parent directories at the specified destination are created as 181 | ---needed 182 | ---@param origin ccTweaked.fs.path The origin path to move 183 | ---@param destination ccTweaked.fs.path The destination path 184 | ---@throws If destination could not be written to 185 | ---## Examples 186 | ---``` 187 | -----Rename file 188 | ---fs.move("/scripts/oldName.lua", "/scripts/newName.lua") 189 | --- 190 | -----Rename directory 191 | ---fs.move("/scripts/projectA/", "/scripts/projectB/") 192 | --- 193 | -----Move file to new directory 194 | ---fs.move("/scripts/oldLocation/test.lua", "/scripts/newLocation/test.lua") 195 | ---``` 196 | ------ 197 | ---[Official Documentation](https://tweaked.cc/module/fs.html#v:move) 198 | function fs.move(origin, destination) end 199 | 200 | ---Copy a file/directory to another path 201 | ---@param origin ccTweaked.fs.path The origin path to copy 202 | ---@param destination ccTweaked.fs.path The destination path to copy to 203 | ---@throws If destination could not be written to 204 | ---## Example 205 | ---``` 206 | ---fs.copy("/scripts/testing/main.lua", "scripts/trying/main.lua") 207 | ---``` 208 | ------ 209 | ---[Official Documentation](https://tweaked.cc/module/fs.html#v:copy) 210 | function fs.copy(origin, destination) end 211 | 212 | ---Deletes a file/directory 213 | --- 214 | ---Deleting a directory **deletes ALL children** (files and subdirectories) 215 | --- 216 | ---❗Be **VERY** careful when deleting directories as you could easily delete a 217 | ---**LOT** of files by accident 218 | ---@param path ccTweaked.fs.path The path to delete 219 | ---@throws If file/directory cannot be deleted 220 | ------ 221 | ---[Official Documentation](https://tweaked.cc/module/fs.html#v:delete) 222 | function fs.delete(path) end 223 | 224 | ---Opens a file for reading/writing 225 | ---@param path ccTweaked.fs.path The path to the file to open 226 | ---@param mode ccTweaked.fs.openMode The mode to open the file with 227 | ---@return ccTweaked.fs.ReadHandle|ccTweaked.fs.BinaryReadHandle|ccTweaked.fs.WriteHandle|ccTweaked.fs.BinaryWriteHandle|nil handler A file handler object or nil if the file does not exist or cannot be opened 228 | ---@return nil|string errorMessage Why the file cannot be opened 229 | ---@throws If an invalid mode was given 230 | ---## Example 231 | ---``` 232 | ---local file = fs.open("/rom/help/intro.txt", "r") 233 | ---local contents = file.readAll() 234 | ---file.close() 235 | ---``` 236 | ------ 237 | ---[Official Documentation](https://tweaked.cc/module/fs.html#v:open) 238 | function fs.open(path, mode) end 239 | 240 | ---Get the name of the mount that the path is located on 241 | ---@param path ccTweaked.fs.path The path to get the mount location of 242 | ---@return string mount The name of the mount location. `hdd` for local files and `rom` for files in the `/rom/` directory 243 | ---@throws If the path doesn't exist 244 | ------ 245 | ---[Official Documentation](https://tweaked.cc/module/fs.html#v:getDrive) 246 | function fs.getDrive(path) end 247 | 248 | ---Get the amount of free space on the mount that the specified path is located on 249 | ---@param path ccTweaked.fs.path A path that belongs to the desired mount 250 | ---@return number|"unlimited" free The free space in bytes, `unlimited`, or 0 if read-only 251 | ---@throws If the path doesn't exist 252 | ------ 253 | ---[Official Documentation](https://tweaked.cc/module/fs.html#v:getFreeSpace) 254 | function fs.getFreeSpace(path) end 255 | 256 | ---Search for files matching a wildcard pattern 257 | ---@param pattern string The path pattern to use 258 | ---@return string[] paths An array of matching paths 259 | ---@throws If the path doesn't exist 260 | ---## Example 261 | ---``` 262 | ------This would match one/two/three, one/A/three, etc. 263 | ---local results = fs.find("one/*/three") 264 | ---``` 265 | ------ 266 | ---[Official Documentation](https://tweaked.cc/module/fs.html#v:find) 267 | function fs.find(pattern) end 268 | 269 | ---Get the total capacity of the mount the path is located on, if available 270 | ---@param path ccTweaked.fs.path A path that is located on the desired mount 271 | ---@return number|nil capacity The capacity of the mount in bytes or `nil` if read-only 272 | ---@throws If the capacity could not be determined 273 | ------ 274 | ---[Official Documentation](https://tweaked.cc/module/fs.html#v:getCapacity) 275 | function fs.getCapacity(path) end 276 | 277 | ---Get attributes about a file/directory 278 | ---@param path ccTweaked.fs.path The path to the file/directory to get the attributes of 279 | ---@return ccTweaked.fs.fileAttributes attributes The attributes of the file/directory 280 | ---@throws If the path does not exist 281 | ------ 282 | ---[Official Documentation](https://tweaked.cc/module/fs.html#v:attributes) 283 | function fs.attributes(path) end 284 | --------------------------------------------------------------------------------