initial commit
This commit is contained in:
commit
faae37274c
|
|
@ -0,0 +1 @@
|
||||||
|
/startup.lua
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"diagnostics.libraryFiles": "Disable",
|
||||||
|
"workspace.library": ["./cclib"]
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
# luals
|
||||||
|
./cclib
|
||||||
|
./.luarc.json
|
||||||
|
|
||||||
|
# git
|
||||||
|
./.git
|
||||||
|
./.gitignore
|
||||||
|
|
||||||
|
# output
|
||||||
|
./startup.lua
|
||||||
|
|
@ -0,0 +1,69 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---This module converts between streams of DFPWM audio data and a list of
|
||||||
|
---amplitudes.
|
||||||
|
---
|
||||||
|
---[Dynamic Filter Pulse Width Modulation
|
||||||
|
---(DFPWM)](https://wiki.vexatos.com/dfpwm) is an audio codec designed by
|
||||||
|
---[GreaseMonkey](https://gist.github.com/iamgreaser/5890329) that is relatively
|
||||||
|
---compact compared to [pulse-code
|
||||||
|
---modulation](https://en.wikipedia.org/wiki/Pulse-code_modulation) (PCM). It
|
||||||
|
---uses only 1 bit per sample, any yet, is still simple enough to encode and
|
||||||
|
---decode in real time on CC:Tweaked computers. It is not a popular file format,
|
||||||
|
---and as a result, most audio processing tools do not have the option to export
|
||||||
|
---to it. However, the online tool [music.madefor.cc](https://music.madefor.cc/)
|
||||||
|
---can be used to convert from more standard audio formats to DFPWM.
|
||||||
|
---
|
||||||
|
---DFPWM can be read from the filesystem or a web request as a string, decoded
|
||||||
|
---to PCM, and played on a speaker peripheral.
|
||||||
|
---
|
||||||
|
---For an in-depth guide to playing audio in CC:Tweaked, see the [official
|
||||||
|
---guide](https://tweaked.cc/guide/speaker_audio.html).
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.audio.dfpwm.html)
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
---Create a new encoder for converting PCM audio data into DFPWM.
|
||||||
|
---
|
||||||
|
---The returned encode function accepts a table of amplitude data between -128
|
||||||
|
---and 127 and returns encoded DFPWM data.
|
||||||
|
---
|
||||||
|
---⚠️ **Warning**: Encoders contain lots of internal state. Reusing encoders for
|
||||||
|
---multiple streams can result in incorrect audio and is not recommended.
|
||||||
|
---@return fun(PCM: integer[]): string encoder
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.audio.dfpwm.html#v:make_encoder)
|
||||||
|
function M.make_encoder() end
|
||||||
|
|
||||||
|
---Helper function for encoding an entire file of audio at once.
|
||||||
|
---
|
||||||
|
---If writing many chunks to the same file, use an encoder from `make_encoder` instead.
|
||||||
|
---@param PCM integer[]
|
||||||
|
---@return string DFPWM
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.audio.dfpwm.html#v:encode)
|
||||||
|
function M.encode(PCM) end
|
||||||
|
|
||||||
|
---Create a new decoder for converting DFPWM into PCM audio data.
|
||||||
|
---
|
||||||
|
---The returned decoder function accepts a string of DFPWM data and returns a
|
||||||
|
---table of amplitudes between -128 and 127.
|
||||||
|
---
|
||||||
|
---⚠️ **Warning**: Decoders contain lots of internal state. Reusing decoders for
|
||||||
|
---multiple streams can result in incorrect audio and is not recommended.
|
||||||
|
---@return fun(DFPWM: string): integer[]
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.audio.dfpwm.html#v:make_decoder)
|
||||||
|
function M.make_decoder() end
|
||||||
|
|
||||||
|
---Helper function for decoding an entire file of audio at once.
|
||||||
|
---
|
||||||
|
---If processing large files, you should instead read the file in chunks and
|
||||||
|
---process it using `make_decoder`.
|
||||||
|
---@param DFPWM string DFPWM data to convert
|
||||||
|
---@return integer[] PCM
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.audio.dfpwm.html#v:decode)
|
||||||
|
function M.decode(DFPWM) end
|
||||||
|
|
||||||
|
return M
|
||||||
|
|
@ -0,0 +1,66 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---Helper functions for completing text. Useful for `_G.read()`
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.completion.html)
|
||||||
|
local completion = {}
|
||||||
|
|
||||||
|
---Get completions from a choice of strings
|
||||||
|
---@param text string The incomplete string
|
||||||
|
---@param choices string[] The choices to offer completions from
|
||||||
|
---@param trailingSpace? boolean Add a trailing space after the completed item
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---local completion = require "cc.completion"
|
||||||
|
---local animals = { "dog", "cat", "lion", "unicorn" }
|
||||||
|
---read(nil, nil, function(text) return completion.choice(text, animals) end)
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.completion.html#v:choice)
|
||||||
|
function completion.choice(text, choices, trailingSpace) end
|
||||||
|
|
||||||
|
---Get completions for the name of a connected peripheral
|
||||||
|
---@param text string The incomplete string
|
||||||
|
---@param trailingSpace? boolean Add a trailing space after the completed item
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---local completion = require "cc.completion"
|
||||||
|
---read(nil, nil, completion.peripheral)
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.completion.html#v:peripheral)
|
||||||
|
function completion.peripheral(text, trailingSpace) end
|
||||||
|
|
||||||
|
---Complete the side of a computer
|
||||||
|
---@param text string The incomplete string
|
||||||
|
---@param trailingSpace? boolean Add a trailing space after the completed item
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---local completion = require "cc.completion"
|
||||||
|
---read(nil, nil, completion.side)
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.completion.html#v:side)
|
||||||
|
function completion.side(text, trailingSpace) end
|
||||||
|
|
||||||
|
---Complete a setting name
|
||||||
|
---@param text string The incomplete string
|
||||||
|
---@param trailingSpace? boolean Add a trailing space after the completed item
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---local completion = require "cc.completion"
|
||||||
|
---read(nil, nil, completion.setting)
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.completion.html#v:setting)
|
||||||
|
function completion.setting(text, trailingSpace) end
|
||||||
|
|
||||||
|
---Complete the name of a Minecraft command
|
||||||
|
---@param text string The incomplete string
|
||||||
|
---@param trailingSpace? boolean Add a trailing space after the completed item
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.completion.html#v:command)
|
||||||
|
function completion.command(text, trailingSpace) end
|
||||||
|
|
||||||
|
return completion
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---Helper functions for validating certain values and types.
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.expect.html)
|
||||||
|
local expect = {}
|
||||||
|
|
||||||
|
---Expect an argument to be of a certain type
|
||||||
|
---@generic T
|
||||||
|
---@param argIndex integer The index of the argument (for error reporting)
|
||||||
|
---@param value T The value to check
|
||||||
|
---@param ... "number"|"string"|"boolean"|"nil" The type the value should be
|
||||||
|
---@return T value
|
||||||
|
---@throws If the value is not of one of the specified types
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.expect.html#v:expect)
|
||||||
|
function expect.expect(argIndex, value, ...) end
|
||||||
|
|
||||||
|
---Expect a field to be of a certain type
|
||||||
|
---@param tbl table The table the field belongs to
|
||||||
|
---@param key string The name of the field to check
|
||||||
|
---@param ... "number"|"string"|"boolean"|"nil" The type the value should be
|
||||||
|
---@return any value The value of the field
|
||||||
|
---@throws If the value is not of one of the specified types
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.expect.html#v:field)
|
||||||
|
function expect.field(tbl, key, ...) end
|
||||||
|
|
||||||
|
---Expect a number to be within a specific range (inclusive)
|
||||||
|
---@param num number The number to confirm is in the specified range
|
||||||
|
---@param min number The minimum value, if omitted `-math.huge` is used
|
||||||
|
---@param max number The maximum value, if omitted `math.huge` is used
|
||||||
|
---@return number value The given number
|
||||||
|
---@throws If the value is outside the given range
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.expect.html#v:range)
|
||||||
|
function expect.range(num, min, max) end
|
||||||
|
|
||||||
|
return expect
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---Module for reading and drawing "Nitrogen Fingers Text" (NFT) images.
|
||||||
|
---
|
||||||
|
---NFT images support coloured text and pixels, unlike `paintutils.parseImage`
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.image.nft.html)
|
||||||
|
local nft = {}
|
||||||
|
|
||||||
|
---Parse an NFT from a string
|
||||||
|
---@param image string The image content as a string
|
||||||
|
---@return table image The parsed image data
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.image.nft.html#v:parse)
|
||||||
|
function nft.parse(image) end
|
||||||
|
|
||||||
|
---Load an NFT from a file
|
||||||
|
---@param path string The filesystem path to the image file
|
||||||
|
---@return table|nil image The parsed image data or `nil` if the file could not be loaded
|
||||||
|
---@return nil|string error A message explaining why the file could not load
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.image.nft.html#v:load)
|
||||||
|
function nft.load(path) end
|
||||||
|
|
||||||
|
---Draw an NFT image on the screen
|
||||||
|
---@param image table An image data table, as returned from `nft.parse()` or `nft.load()`
|
||||||
|
---@param xPos integer The x position to begin the drawing at
|
||||||
|
---@param yPos integer The y position to begin the drawing at
|
||||||
|
---@param target? ccTweaked.term.Redirect The terminal to draw to. Defaults to the current terminal
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.image.nft.html#v:draw)
|
||||||
|
function nft.draw(image, xPos, yPos, target) end
|
||||||
|
|
||||||
|
return nft
|
||||||
|
|
@ -0,0 +1,136 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---A pretty printer for formatting text in a stylized manner.
|
||||||
|
---
|
||||||
|
---Printing uses document objects to structure the text. These documents will be
|
||||||
|
---used to print the most compact layout possible
|
||||||
|
---
|
||||||
|
---Based on [*A Prettier Printer*](https://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf)
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.pretty.html)
|
||||||
|
local pretty = {}
|
||||||
|
|
||||||
|
---A document contains formatted text with multiple possible layouts.
|
||||||
|
---@class ccTweaked.cc.pretty.Doc
|
||||||
|
|
||||||
|
---An empty document
|
||||||
|
---@type ccTweaked.cc.pretty.Doc
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.pretty.html#v:empty)
|
||||||
|
pretty.empty = nil
|
||||||
|
|
||||||
|
---A document with a single space in it
|
||||||
|
---@type ccTweaked.cc.pretty.Doc
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.pretty.html#v:space)
|
||||||
|
pretty.space = nil
|
||||||
|
|
||||||
|
---A line break, however when in a group and everything can fit on one line, is
|
||||||
|
---replaced with `empty`
|
||||||
|
---@type ccTweaked.cc.pretty.Doc
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.pretty.html#v:line)
|
||||||
|
pretty.line = nil
|
||||||
|
|
||||||
|
---A line break, however when in a group and everything can fit on one line, is
|
||||||
|
---replaced with `space`
|
||||||
|
---@type ccTweaked.cc.pretty.Doc
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.pretty.html#v:space_line)
|
||||||
|
pretty.space_line = nil
|
||||||
|
|
||||||
|
---Create a new `Doc` from a string
|
||||||
|
---@param text string The string to construct a document from
|
||||||
|
---@param color? ccTweaked.colors.color The color to print the text in. Defaults to the current color
|
||||||
|
---@return ccTweaked.cc.pretty.Doc doc The document containing the provided text
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.pretty.html#v:text)
|
||||||
|
function pretty.text(text, color) end
|
||||||
|
|
||||||
|
---Concatenate multiple documents into one
|
||||||
|
---@param ... ccTweaked.cc.pretty.Doc|string The documents to concat
|
||||||
|
---@return ccTweaked.cc.pretty.Doc doc The concatenated document
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.pretty.html#v:concat)
|
||||||
|
function pretty.concat(...) end
|
||||||
|
|
||||||
|
---Indents the following lines in the provided document using spaces
|
||||||
|
---@param depth integer The number of spaces to indent to
|
||||||
|
---@param doc ccTweaked.cc.pretty.Doc The document to indent
|
||||||
|
---@return ccTweaked.cc.pretty.Doc doc The nested document
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.pretty.html#v:nest)
|
||||||
|
function pretty.nest(depth, doc) end
|
||||||
|
|
||||||
|
---Build a document that is displayed on a single line if there is enough room
|
||||||
|
---or as normal if not
|
||||||
|
---@param doc ccTweaked.cc.pretty.Doc The document to make a group
|
||||||
|
---@return ccTweaked.cc.pretty.Doc doc The grouped document
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---local pretty = require("cc.pretty")
|
||||||
|
---
|
||||||
|
---pretty.print(
|
||||||
|
--- pretty.group(
|
||||||
|
--- pretty.concat("Hello", pretty.space_line, "World!")
|
||||||
|
--- )
|
||||||
|
---)
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.pretty.html#v:group)
|
||||||
|
function pretty.group(doc) end
|
||||||
|
|
||||||
|
---Write a doc to the terminal
|
||||||
|
---@param doc ccTweaked.cc.pretty.Doc The document to write
|
||||||
|
---@param maxWidth? number The maximum fraction of the screen width that can be written to before wrapping. Defaults to 0.6
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.pretty.html#v:write)
|
||||||
|
function pretty.write(doc, maxWidth) end
|
||||||
|
|
||||||
|
---Print a doc to the terminal with a trailing new line
|
||||||
|
---@param doc ccTweaked.cc.pretty.Doc The document to write
|
||||||
|
---@param maxWidth? number The maximum fraction of the screen width that can be written to before wrapping. Defaults to 0.6
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.pretty.html#v:print)
|
||||||
|
function pretty.print(doc, maxWidth) end
|
||||||
|
|
||||||
|
---Render a document into a string
|
||||||
|
---@param doc ccTweaked.cc.pretty.Doc The document to render
|
||||||
|
---@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
|
||||||
|
---@param maxWidth? number The maximum fraction of the screen width that can be written to before wrapping. Defaults to 0.6
|
||||||
|
---@return string rendered The rendered string
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.pretty.html#v:render)
|
||||||
|
function pretty.render(doc, width, maxWidth) end
|
||||||
|
|
||||||
|
---@class prettyOptions
|
||||||
|
---@field function_args boolean Show the arguments to a function if known, defaults to false
|
||||||
|
---@field function_source boolean Show where a function was defined, defaults to false
|
||||||
|
|
||||||
|
---Convert an object into a document that can then be displayed with `write` or `print`
|
||||||
|
---@param obj any The object to convert to a document
|
||||||
|
---@param options? prettyOptions Options for how certain things are displayed
|
||||||
|
---@return ccTweaked.cc.pretty.Doc doc The formatted document
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---local pretty = require "cc.pretty"
|
||||||
|
---pretty.print(pretty.pretty({ 1, 2, 3 }))
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.pretty.html#v:pretty)
|
||||||
|
function pretty.pretty(obj, options) end
|
||||||
|
|
||||||
|
---A shorthand that calls `pretty` and `print`
|
||||||
|
---@param obj any The object to print
|
||||||
|
---@param options? prettyOptions Options for how certain things are displayed
|
||||||
|
---@param maxWidth? number The maximum fraction of the screen width that can be written to before wrapping. Defaults to 0.6
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---local pretty = require "cc.pretty"
|
||||||
|
---pretty.pretty_print({ 1, 2, 3 })
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.pretty.html#v:pretty_print)
|
||||||
|
function pretty.pretty_print(obj, options, maxWidth) end
|
||||||
|
|
||||||
|
return pretty
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---A pure Lua implementation of the built-in
|
||||||
|
---[require](https://www.lua.org/manual/5.1/manual.html#pdf-require) function and
|
||||||
|
---[package](https://www.lua.org/manual/5.1/manual.html#5.3) library. This is
|
||||||
|
---usually not needed as it is already injected into every program environment,
|
||||||
|
---but it may be useful when building a custom shell or when executing programs
|
||||||
|
---yourself.
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.require.html)
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
---Create a new `require` function to load packages in a new `package` library.
|
||||||
|
---Can be used when creating a custom shell or when running programs outside the
|
||||||
|
---shell.
|
||||||
|
---@param env table Environment to load packages into
|
||||||
|
---@param dir string Directory that relative packages are loaded from
|
||||||
|
---@return fun(moduleName: string): unknown, unknown
|
||||||
|
---@return packagelib
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.require.html#v:make)
|
||||||
|
function M.make(env, dir) end
|
||||||
|
|
||||||
|
return M
|
||||||
|
|
@ -0,0 +1,118 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---@alias ccTweaked.cc.shell.completion.function fun(shell: ccTweaked.shell, text: string, previousArguments: string[]): string[]
|
||||||
|
|
||||||
|
---Helper functions for use with shell completion. Most programs can have
|
||||||
|
---completion support added using `build` rather than manually creating a
|
||||||
|
---function for `shell.setCompletionFunction`.
|
||||||
|
---
|
||||||
|
---Note that the helper functions in this module do not accept an argument
|
||||||
|
---index, and thus are not directly usable with `shell.setCompletionFunction`.
|
||||||
|
---You can wrap them using `build`, or a custom function.
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.shell.completion.html)
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
---Complete the name of a file relative to the current working directory
|
||||||
|
---@param shell ccTweaked.shell Shell to perform completion in
|
||||||
|
---@param text string Text to complete
|
||||||
|
---@return string[] suffixes Remaining text of matching files
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.shell.completion.html#v:file)
|
||||||
|
function M.file(shell, text) end
|
||||||
|
|
||||||
|
---Complete the name of a directory relative to the current working directory
|
||||||
|
---@param shell ccTweaked.shell Shell to perform completion in
|
||||||
|
---@param text string Text to complete
|
||||||
|
---@return string[] suffixes Remaining text of matching directories
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.shell.completion.html#v:dir)
|
||||||
|
function M.dir(shell, text) end
|
||||||
|
|
||||||
|
---Complete the name of a file or directory relative to the current working directory
|
||||||
|
---@param shell ccTweaked.shell Shell to perform completion in
|
||||||
|
---@param text string Text to complete
|
||||||
|
---@param previous string[] Shell arguments before this one
|
||||||
|
---@param addSpace boolean Whether to add a space after the completed item
|
||||||
|
---@return string[] suffixes Remaining text of matching directories/files
|
||||||
|
--------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.shell.completion.html#v:dirOrFile)
|
||||||
|
function M.dirOrFile(shell, text, previous, addSpace) end
|
||||||
|
|
||||||
|
---Complete the name of a program
|
||||||
|
---@param shell ccTweaked.shell Shell to perform completion in
|
||||||
|
---@param text string Text to complete
|
||||||
|
---@return string[] suffixes Remaining text of matching programs
|
||||||
|
-------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.shell.completion.html#v:program)
|
||||||
|
function M.program(shell, text) end
|
||||||
|
|
||||||
|
---Complete arguments of a program
|
||||||
|
---@param shell ccTweaked.shell Shell to perform completion in
|
||||||
|
---@param text string Text to complete
|
||||||
|
---@param previous string[] Shell arguments before this one
|
||||||
|
---@param starting integer The argument index this program and args start at
|
||||||
|
---@return string[] suffixes Remaining text of matching programs or arguments
|
||||||
|
-------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.shell.completion.html#v:programWithArgs)
|
||||||
|
function M.programWithArgs(shell, text, previous, starting) end
|
||||||
|
|
||||||
|
---A wrapped version of `help.completeTopic` for use with `build`
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.shell.completion.html#v:help)
|
||||||
|
function M.help(text) end
|
||||||
|
|
||||||
|
---A wrapped version of `cc.completion.choice` for use with `build`
|
||||||
|
---
|
||||||
|
-------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.shell.completion.html#v:choice)
|
||||||
|
function M.choice() end
|
||||||
|
|
||||||
|
---A wrapped version of `cc.completion.peripheral` for use with `build`
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.shell.completion.html#v:peripheral)
|
||||||
|
function M.peripheral() end
|
||||||
|
|
||||||
|
---A wrapped version of `cc.completion.side` for use with `build`
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.shell.completion.html#v:side)
|
||||||
|
function M.side() end
|
||||||
|
|
||||||
|
---A wrapped version of `cc.completion.setting` for use with `build`
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.shell.completion.html#v:setting)
|
||||||
|
function M.setting() end
|
||||||
|
|
||||||
|
---A wrapped version of `cc.completion.command` for use with `build`
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.shell.completion.html#v:command)
|
||||||
|
function M.command() end
|
||||||
|
|
||||||
|
---Helper function for building shell completion arguments.
|
||||||
|
---
|
||||||
|
---Accepts a series of single-argument completion functions and combines them
|
||||||
|
---into a function suitable for use with `shell.setCompletionFunction`. Every
|
||||||
|
---argument given represents an argument to the target program to be completed.
|
||||||
|
---Each argument can be:
|
||||||
|
---
|
||||||
|
---1. `nil`: will not be completed
|
||||||
|
---2. `function`: receives the `shell` object, string to complete, and array of
|
||||||
|
---arguments before this one
|
||||||
|
---3. `table`: Must have a `function`, like the above one, as the first item.
|
||||||
|
---Can also be followed by additional values that will be passed to the function
|
||||||
|
---from the start of the table. If this table is the last argument, it can set
|
||||||
|
---the `many` key to `true`, indicating that the function should be used to
|
||||||
|
---complete any remaining arguments.
|
||||||
|
---@param ... nil | ccTweaked.cc.shell.completion.function | {[1]: ccTweaked.cc.shell.completion.function, [integer]: any}
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.shell.completion.html#v:build)
|
||||||
|
function M.build(...) end
|
||||||
|
|
||||||
|
M.build({ false, true })
|
||||||
|
|
||||||
|
return M
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---Utilities for strings and text
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.strings.html)
|
||||||
|
local strings = {}
|
||||||
|
|
||||||
|
---Wraps a block of text so that each line fits within the specified width
|
||||||
|
---
|
||||||
|
---Useful for wrapping text if not using `print`
|
||||||
|
---@param text string The string to wrap
|
||||||
|
---@param width? number The width to constrain to. Defaults to the width of the terminal
|
||||||
|
---@return string[] lines A table that contains each line as a string
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/library/cc.strings.html#v:wrap)
|
||||||
|
function strings.wrap(text, width) end
|
||||||
|
|
||||||
|
---Make a string a fixed width through either truncating it or padding it with spaces
|
||||||
|
---@param line string The string to normalize
|
||||||
|
---@param width? number The width to constrain to. Defaults to the width of the terminal
|
||||||
|
---@return string normalizedString The string with the specified width
|
||||||
|
function strings.ensure_width(line, width) end
|
||||||
|
|
||||||
|
return strings
|
||||||
|
|
@ -0,0 +1,215 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---Contains constants and functions for colour values. Useful in conjunction
|
||||||
|
---with Bundled Cables from mods like [Project
|
||||||
|
---Red](https://projectredwiki.com/wiki/Main_Page), and colors on Advanced
|
||||||
|
---Computers and Advanced Monitors.
|
||||||
|
---
|
||||||
|
---For a British English version, replace colors with colours. This alternative
|
||||||
|
---API is exactly the same except the colours use British English (e.g.
|
||||||
|
---colors.gray is spelt colours.grey).
|
||||||
|
---
|
||||||
|
---On basic non-color terminals, all the colors are converted to grayscale. This
|
||||||
|
---means you can still use all 16 colors on the screen, but they will appear as
|
||||||
|
---the nearest tint of gray. You can check if a terminal supports color by using
|
||||||
|
---the function `term.isColor`. Grayscale colors are calculated by taking the
|
||||||
|
---average of the three components, i.e. `(red + green + blue) / 3`.
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/colors.html)
|
||||||
|
colors = {}
|
||||||
|
|
||||||
|
---**Hex**: `#F0F0F0`\
|
||||||
|
---**RGB**: `240, 240, 240`
|
||||||
|
---@type ccTweaked.colors.color
|
||||||
|
colors.white = 1
|
||||||
|
|
||||||
|
---**Hex**: `#F2B233`\
|
||||||
|
---**RGB**: `242, 178, 51`
|
||||||
|
---@type ccTweaked.colors.color
|
||||||
|
colors.orange = 2
|
||||||
|
|
||||||
|
---**Hex**: `#E57FD8`\
|
||||||
|
---**RGB**: `229, 127, 216`
|
||||||
|
---@type ccTweaked.colors.color
|
||||||
|
colors.magenta = 4
|
||||||
|
|
||||||
|
---**Hex**: `#99B2F2`\
|
||||||
|
---**RGB**: `153, 178, 242`
|
||||||
|
---@type ccTweaked.colors.color
|
||||||
|
colors.lightBlue = 8
|
||||||
|
|
||||||
|
---**Hex**: `#DEDE6C`\
|
||||||
|
---**RGB**: `222, 222, 108`
|
||||||
|
---@type ccTweaked.colors.color
|
||||||
|
colors.yellow = 16
|
||||||
|
|
||||||
|
---**Hex**: `#7FCC19`\
|
||||||
|
---**RGB**: `127, 204, 25`
|
||||||
|
---@type ccTweaked.colors.color
|
||||||
|
colors.lime = 32
|
||||||
|
|
||||||
|
---**Hex**: `#F2B2CC`\
|
||||||
|
---**RGB**: `242, 178, 204`
|
||||||
|
---@type ccTweaked.colors.color
|
||||||
|
colors.pink = 64
|
||||||
|
|
||||||
|
---**Hex**: `#4C4C4C`\
|
||||||
|
---**RGB**: `76, 76, 76`
|
||||||
|
---@type ccTweaked.colors.color
|
||||||
|
colors.gray = 128
|
||||||
|
|
||||||
|
---**Hex**: `#999999`\
|
||||||
|
---**RGB**: `153, 153, 153`
|
||||||
|
---@type ccTweaked.colors.color
|
||||||
|
colors.lightGray = 256
|
||||||
|
|
||||||
|
---**Hex**: `#4C99B2`\
|
||||||
|
---**RGB**: `76, 153, 178`
|
||||||
|
---@type ccTweaked.colors.color
|
||||||
|
colors.cyan = 512
|
||||||
|
|
||||||
|
---**Hex**: `#B266E5`\
|
||||||
|
---**RGB**: `178, 102, 229`
|
||||||
|
---@type ccTweaked.colors.color
|
||||||
|
colors.purple = 1024
|
||||||
|
|
||||||
|
---**Hex**: `#3366CC`\
|
||||||
|
---**RGB**: `51, 102, 204`
|
||||||
|
---@type ccTweaked.colors.color
|
||||||
|
colors.blue = 2048
|
||||||
|
|
||||||
|
---**Hex**: `#7F664C`\
|
||||||
|
---**RGB**: `127, 102, 76`
|
||||||
|
---@type ccTweaked.colors.color
|
||||||
|
colors.brown = 4096
|
||||||
|
|
||||||
|
---**Hex**: `#57A64E`\
|
||||||
|
---**RGB**: `87, 166, 78`
|
||||||
|
---@type ccTweaked.colors.color
|
||||||
|
colors.green = 8192
|
||||||
|
|
||||||
|
---**Hex**: `#CC4C4C`\
|
||||||
|
---**RGB**: `204, 76, 76`
|
||||||
|
---@type ccTweaked.colors.color
|
||||||
|
colors.red = 16384
|
||||||
|
|
||||||
|
---**Hex**: `#111111`\
|
||||||
|
---**RGB**: `17, 17, 17`
|
||||||
|
---@type ccTweaked.colors.color
|
||||||
|
colors.black = 32768
|
||||||
|
|
||||||
|
---Combines colors into a set. Useful for Bundled Cables
|
||||||
|
---@vararg ccTweaked.colors.color
|
||||||
|
---@return ccTweaked.colors.colorSet set The result of combining the provided colors
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---colors.combine(colors.white, colors.magenta, colours.lightBlue)
|
||||||
|
-----> 13
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/colors.html#v:combine)
|
||||||
|
function colors.combine(...) end
|
||||||
|
|
||||||
|
---Removes one or more colors from a set. Useful for Bundled Cables.
|
||||||
|
---@param color ccTweaked.colors.color The color to subtract from
|
||||||
|
---@vararg ccTweaked.colors.color
|
||||||
|
---@return ccTweaked.colors.colorSet set The result of subtracting the provided colors
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---colors.subtract(colours.lime, colours.orange, colours.white)
|
||||||
|
-----> 32
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/colors.html#v:subtract)
|
||||||
|
function colors.subtract(color, ...) end
|
||||||
|
|
||||||
|
---Test whether a color is contained within a color set
|
||||||
|
---@param set ccTweaked.colors.colorSet
|
||||||
|
---@param color ccTweaked.colors.color
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---colors.test(colors.combine(colors.white, colors.magenta, colours.lightBlue), colors.lightBlue)
|
||||||
|
-----> true
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/colors.html#v:test)
|
||||||
|
function colors.test(set, color) end
|
||||||
|
|
||||||
|
---Combine an RGB value into one hexadecimal representation
|
||||||
|
---@param r number The red channel (0 - 1)
|
||||||
|
---@param g number The green channel (0 - 1)
|
||||||
|
---@param b number The blue channel (0 - 1)
|
||||||
|
---@return number hex The hexadecimal representation of the RGB value
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---colors.packRGB(0.7, 0.2, 0.6)
|
||||||
|
-----> 0xb23399
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/colors.html#v:packRGB)
|
||||||
|
function colors.packRGB(r, g, b) end
|
||||||
|
|
||||||
|
---Convert a hex value into separate r, g, b, values
|
||||||
|
---@param hex number
|
||||||
|
---@return number r Red component (0 - 1)
|
||||||
|
---@return number g Green component (0 - 1)
|
||||||
|
---@return number b Blue component (0 - 1)
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---colors.unpackRGB(0xb23399)
|
||||||
|
-----> 0.7, 0.2, 0.6
|
||||||
|
---```
|
||||||
|
function colors.unpackRGB(hex) end
|
||||||
|
|
||||||
|
---Calls either `colors.packRGB` or `colors.unpackRGB` depending on how many
|
||||||
|
---arguments it receives.
|
||||||
|
---@deprecated
|
||||||
|
---@param r number The red channel (0 - 1)
|
||||||
|
---@param g number The green channel (0 - 1)
|
||||||
|
---@param b number The blue channel (0 - 1)
|
||||||
|
---@return number hex The hexadecimal representation of the RGB value
|
||||||
|
---🚮 **Deprecated in `v1.81.0`**, use `colors.packRGB()`
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---colors.rgb8(0.7, 0.2, 0.6)
|
||||||
|
-----> 0xb23399
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/colors.html#v:rgb8)
|
||||||
|
function colors.rgb8(r, g, b) end
|
||||||
|
|
||||||
|
---Calls either `colors.packRGB` or `colors.unpackRGB` depending on how many
|
||||||
|
---arguments it receives.
|
||||||
|
---@deprecated
|
||||||
|
---@param hex number
|
||||||
|
---@return number r Red component (0 - 1)
|
||||||
|
---@return number g Green component (0 - 1)
|
||||||
|
---@return number b Blue component (0 - 1)
|
||||||
|
---🚮 **Deprecated in `v1.81.0`**, use `colors.unpackRGB()`
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---colors.rgb8(0xb23399)
|
||||||
|
-----> 0.7, 0.2, 0.6
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/colors.html#v:rgb8)
|
||||||
|
function colors.rgb8(hex) end
|
||||||
|
|
||||||
|
---Converts a color into a blit hex character for use with `term.blit()`
|
||||||
|
---@param color ccTweaked.colors.color The color to convert
|
||||||
|
---@return string blit The blit hex character that represents the given color
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---colors.toBlit(colors.magenta)
|
||||||
|
-----> "2"
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/colors.html#v:toBlit)
|
||||||
|
function colors.toBlit(color) end
|
||||||
|
|
||||||
|
---Convert a paint/blit hex character (0-9,a-f) to a color
|
||||||
|
---@param hex string
|
||||||
|
---@return ccTweaked.colors.color color
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/colors.html#v:fromBlit)
|
||||||
|
function colors.fromBlit(hex) end
|
||||||
|
|
@ -0,0 +1,85 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---Execute [Minecraft Commands](https://minecraft.gamepedia.com/Commands) using
|
||||||
|
---a command computer
|
||||||
|
---
|
||||||
|
---This API is only available on command computers and is not accessible by
|
||||||
|
---normal players
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/commands.html)
|
||||||
|
commands = {}
|
||||||
|
|
||||||
|
---The builtin commands API, without any generated command helper functions
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/commands.html#v:native)
|
||||||
|
commands.native = {}
|
||||||
|
|
||||||
|
---A table of asynchronous wrappers for all commands
|
||||||
|
---
|
||||||
|
---These functions return a "task ID"
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/commands.html#v:async)
|
||||||
|
commands.async = {}
|
||||||
|
|
||||||
|
---Execute a command
|
||||||
|
---@param command string The command to execute
|
||||||
|
---@return boolean success If the command executed successfully
|
||||||
|
---@return string[] output The output of this command as an array of lines
|
||||||
|
---@return number|nil affected The number of "affected" objects or `nil` if the command failed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/commands.html#v:exec)
|
||||||
|
function commands.exec(command) end
|
||||||
|
|
||||||
|
---Execute a command asynchronously
|
||||||
|
---
|
||||||
|
---This will return immediately and fire a `task_complete` event when it completes
|
||||||
|
---@param command string The command to execute
|
||||||
|
---@return integer taskID The ID of this task, useful for checking that the `task_complete` event is meant for this task
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/commands.html#v:execAsync)
|
||||||
|
function commands.execAsync(command) end
|
||||||
|
|
||||||
|
---List all commands this computer has permission to execute
|
||||||
|
---@param command? string The command to complete
|
||||||
|
---@return string[] commands An array of available commands
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/commands.html#v:list)
|
||||||
|
function commands.list(command) end
|
||||||
|
|
||||||
|
---Get the position of the current computer
|
||||||
|
---@return number x The current x position
|
||||||
|
---@return number y The current y position
|
||||||
|
---@return number z The current z position
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/commands.html#v:getBlockPosition)
|
||||||
|
function commands.getBlockPosition() end
|
||||||
|
|
||||||
|
---Get information about a range of blocks
|
||||||
|
---
|
||||||
|
---Blocks are traversed by ascending y level, followed by z and x - the returned
|
||||||
|
--table may be indexed using `x + z * width + y * depth * depth`.
|
||||||
|
---@param minX number The x coordinate to start querying at
|
||||||
|
---@param minY number The y coordinate to start querying at
|
||||||
|
---@param minZ number The z coordinate to start querying at
|
||||||
|
---@param maxX number The x coordinate to stop querying at
|
||||||
|
---@param maxY number the y coordinate to stop querying at
|
||||||
|
---@param maxZ number The z coordinate to stop querying at
|
||||||
|
---@param dimension? string The dimension to query (defaults to current)
|
||||||
|
---@return ccTweaked.turtle.slotInfo[] details An array of details on each block
|
||||||
|
---@throws If the coordinates are not within the world
|
||||||
|
---@throws If trying to get info about more than 4096 blocks
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/commands.html#v:getBlockInfos)
|
||||||
|
function commands.getBlockInfos(minX, minY, minZ, maxX, maxY, maxZ, dimension) end
|
||||||
|
|
||||||
|
---Get some basic info on a block
|
||||||
|
---@param x number The x position to query
|
||||||
|
---@param y number The y position to query
|
||||||
|
---@param z number The z position to query
|
||||||
|
---@param dimension? string The dimension to query (defaults to current)
|
||||||
|
---@return ccTweaked.turtle.slotInfo
|
||||||
|
---@throws If the coordinates are not within the world or are not currently loaded
|
||||||
|
function commands.getBlockInfo(x, y, z, dimension) end
|
||||||
|
|
@ -0,0 +1,131 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---Functions for interacting with disk drives
|
||||||
|
---
|
||||||
|
---The disk functions can be used on a locally attached or remote disk drive
|
||||||
|
---peripheral. If the drive is attached locally, you can use the side it is
|
||||||
|
---attached to, if it is remote, you have to use the name printed when enabling
|
||||||
|
---its modem (e.g. `drive_0`).
|
||||||
|
---
|
||||||
|
---💬 A disk drive can contain a floppy disk 💾, record 💿, or a computer 🖥️
|
||||||
|
---(including pocket computer or turtle)
|
||||||
|
---
|
||||||
|
---💬 Computers, turtles, and pocket computers can be placed in a disk drive to
|
||||||
|
---access their internal drives.
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/disk.html)
|
||||||
|
disk = {}
|
||||||
|
|
||||||
|
---Checks that an item is in a disk drive
|
||||||
|
---@param name ccTweaked.peripherals.computerSide|string The name of the disk drive or the side of the computer that the drive is on
|
||||||
|
---@return boolean present
|
||||||
|
---Supports: 💾💿🖥️
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---disk.isPresent("top")
|
||||||
|
---disk.isPresent("drive_3")
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/disk.html#v:isPresent)
|
||||||
|
function disk.isPresent(name) end
|
||||||
|
|
||||||
|
---Get the label of the inserted item. If the inserted item is a computer,
|
||||||
|
---this returns the label of the computer as read by `os.getComputerLabel()`
|
||||||
|
---@param name ccTweaked.peripherals.computerSide|string The name of the disk drive or the side of the computer that the drive is on
|
||||||
|
---Supports: 💾💿🖥️
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/disk.html#v:getLabel)
|
||||||
|
function disk.getLabel(name) end
|
||||||
|
|
||||||
|
---Set the label of an inserted item.
|
||||||
|
---@param name ccTweaked.peripherals.computerSide|string The name of the disk drive or the side of the computer that the drive is on
|
||||||
|
---@param label string The new value for the label
|
||||||
|
---Supports: 💾💿🖥️
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/disk.html#v:setLabel)
|
||||||
|
function disk.setLabel(name, label) end
|
||||||
|
|
||||||
|
---Check if an item is present and provides a mount. For records, returns false
|
||||||
|
---@param name ccTweaked.peripherals.computerSide|string The name of the disk drive or the side of the computer that the drive is on
|
||||||
|
---@return boolean hasMount
|
||||||
|
---Supports: 💾💿🖥️
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/disk.html#v:hasData)
|
||||||
|
function disk.hasData(name) end
|
||||||
|
|
||||||
|
---Gets the path on this computer where the contents of the inserted item can be
|
||||||
|
---found
|
||||||
|
---@param name ccTweaked.peripherals.computerSide|string The name of the disk drive or the side of the computer that the drive is on
|
||||||
|
---@return string? path The path to the mount location or `nil` if the drive is empty or the inserted item cannot be mounted
|
||||||
|
---Supports: 💾💿🖥️
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---disk.getMountPath("left")
|
||||||
|
----->"/disk0"
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/disk.html#v:getMountPath)
|
||||||
|
function disk.getMountPath(name) end
|
||||||
|
|
||||||
|
---Checks that the inserted item is a music disk
|
||||||
|
---@param name ccTweaked.peripherals.computerSide|string The name of the disk drive or the side of the computer that the drive is on
|
||||||
|
---@return boolean hasAudio If an item is present and is a record
|
||||||
|
---Supports: 💾💿🖥️
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/disk.html#v:hasAudio)
|
||||||
|
function disk.hasAudio(name) end
|
||||||
|
|
||||||
|
---Get the title of the music track from the record in the drive. This usually
|
||||||
|
---results in the same as `disk.getLabel()` for records.
|
||||||
|
---@param name ccTweaked.peripherals.computerSide|string The name of the disk drive or the side of the computer that the drive is on
|
||||||
|
---@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
|
||||||
|
---Supports: 💾💿🖥️
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/disk.html#v:getAudioTitle)
|
||||||
|
function disk.getAudioTitle(name) end
|
||||||
|
|
||||||
|
---Plays the record in the drive
|
||||||
|
---
|
||||||
|
---Make sure to check that there is an item in the drive and that it is a record with `disk.hasData()`
|
||||||
|
---
|
||||||
|
---Stops any already playing records. The record will stop playing when it
|
||||||
|
---reaches the end of its runtime, is removed from the drive, or when stopped
|
||||||
|
---manually by `disk.stopAudio()`
|
||||||
|
---@param name ccTweaked.peripherals.computerSide|string The name of the disk drive or the side of the computer that the drive is on
|
||||||
|
---Supports: 💿
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/disk.html#v:playAudio)
|
||||||
|
function disk.playAudio(name) end
|
||||||
|
|
||||||
|
---Stops the currently playing record that was started with `disk.playAudio()`
|
||||||
|
---@param name ccTweaked.peripherals.computerSide|string The name of the disk drive or the side of the computer that the drive is on
|
||||||
|
---Supports: 💿
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/disk.html#v:stopAudio)
|
||||||
|
function disk.stopAudio(name) end
|
||||||
|
|
||||||
|
---Ejects any item that is in the drive, dropping it into the world
|
||||||
|
---@param name ccTweaked.peripherals.computerSide|string The name of the disk drive or the side of the computer that the drive is on
|
||||||
|
---Supports: 💾💿🖥️
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/disk.html#v:eject)
|
||||||
|
function disk.eject(name) end
|
||||||
|
|
||||||
|
---Get the unique identifier of the disk in the drive. Only floppy disks have an
|
||||||
|
---ID
|
||||||
|
---@param name ccTweaked.peripherals.computerSide|string The name of the disk drive or the side of the computer that the drive is on
|
||||||
|
---@return number|nil ID The ID of the floppy disk or nil if the drive is empty or does not contain a floppy disk
|
||||||
|
---Supports: 💾
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/disk.html#v:getID)
|
||||||
|
function disk.getID(name) end
|
||||||
|
|
@ -0,0 +1,282 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---Provides functions for interacting with a computer's files 📄 and directories 📁
|
||||||
|
---
|
||||||
|
---All functions use [absolute
|
||||||
|
---paths](https://en.wikipedia.org/wiki/Path_(computing)#Absolute_and_relative_paths),
|
||||||
|
---however, `shell.resolve()` can be used to convert a relative path into an
|
||||||
|
---absolute path
|
||||||
|
---
|
||||||
|
---Computers only have one storage device and filesystem but other filesystems
|
||||||
|
---can be [mounted](https://en.wikipedia.org/wiki/Mount_(computing)) using
|
||||||
|
---peripherals such as the drive peripheral. These drives mount their disk's
|
||||||
|
---content at locations like `disk/`, `disk1/`, etc.
|
||||||
|
---
|
||||||
|
---Most filesystems have a finite capacity and trying to perform an operation
|
||||||
|
---that could exceed it will fail
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html)
|
||||||
|
fs = {}
|
||||||
|
|
||||||
|
---Get whether a path is mounted to the root of the parent filesystem
|
||||||
|
---
|
||||||
|
---✅
|
||||||
|
---- `/`
|
||||||
|
---- `/rom`
|
||||||
|
---- `/disk`
|
||||||
|
---
|
||||||
|
---❌
|
||||||
|
---- `/rom/apis`
|
||||||
|
---- `/disc/helloWorld.lua`
|
||||||
|
---@param path string The path to check
|
||||||
|
---@return boolean isRoot If the specified path is mounted to the root
|
||||||
|
---@throws If the path does not exist
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#v:isDriveRoot)
|
||||||
|
function fs.isDriveRoot(path) end
|
||||||
|
|
||||||
|
---Provides completion for files/directories
|
||||||
|
---
|
||||||
|
---When a directory is a candidate, two entries are provided - one with a
|
||||||
|
---trailing slash (hinting that there are files/directories that exist past this
|
||||||
|
---one) and one without (suggesting that this directory *is* the target). Setting
|
||||||
|
---`includeDirectories` to false will only suggest directories with a trailing
|
||||||
|
---slash (meaning only directories with content will be suggested but are not
|
||||||
|
---meant to be the final target)
|
||||||
|
---@param path string The path to complete
|
||||||
|
---@param source string The path where further paths should be resolved from
|
||||||
|
---@param includeFiles? boolean If filenames should be completed
|
||||||
|
---@param includeDirectories? boolean If empty directories should be completed
|
||||||
|
---@return string[]|table candidates
|
||||||
|
---## Examples
|
||||||
|
---```
|
||||||
|
---fs.complete("doesNot", "/exist")
|
||||||
|
-----> {}
|
||||||
|
---
|
||||||
|
---fs.complete("modules", "/rom")
|
||||||
|
-----> {"/"}
|
||||||
|
---
|
||||||
|
---fs.complete("modules/", "/rom")
|
||||||
|
-----> {"command/", "command", "main/", "main", "turtle/", "turtle"}
|
||||||
|
---
|
||||||
|
---fs.complete("modules/", "/rom", true, false)
|
||||||
|
-----> {"command/", "main/", "turtle/"}
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#v:complete)
|
||||||
|
function fs.complete(path, source, includeFiles, includeDirectories) end
|
||||||
|
|
||||||
|
---Get a list of files in a directory
|
||||||
|
---@param path string The path to the directory to check
|
||||||
|
---@return string[] files
|
||||||
|
---@throws If the path doesn't exist
|
||||||
|
---@throws If the path is not a directory
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#v:list)
|
||||||
|
function fs.list(path) end
|
||||||
|
|
||||||
|
---Combine multiple components of a path into a single path
|
||||||
|
---@param start string The start of the path
|
||||||
|
---@vararg string|string Path components to combine
|
||||||
|
---@return string path The combined path
|
||||||
|
---@throws If arguments are invalid (e.g. are numbers)
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---fs.combine("/rom/programs", "../apis", "parallel.lua")
|
||||||
|
-----> rom/apis/parallel.lua
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#v:combine)
|
||||||
|
function fs.combine(start, ...) end
|
||||||
|
|
||||||
|
---Get the filename component of a path
|
||||||
|
---@param path string The path to get the filename from
|
||||||
|
---@return string filename The last component of a path (name of the file if the path points to a file)
|
||||||
|
---## Examples
|
||||||
|
---```
|
||||||
|
---fs.getName("/")
|
||||||
|
-----> "root"
|
||||||
|
---
|
||||||
|
---fs.getName("/rom/programs/")
|
||||||
|
-----> "programs"
|
||||||
|
---
|
||||||
|
---fs.getName("/rom/programs/reboot.lua")
|
||||||
|
-----> "reboot.lua"
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#v:getName)
|
||||||
|
function fs.getName(path) end
|
||||||
|
|
||||||
|
---Get the parent directory component of a path
|
||||||
|
---@param path string The path to get the parent directory from
|
||||||
|
---@return string|string parentDirectory The parent directory component of the path (all parent directories)
|
||||||
|
---## Examples
|
||||||
|
---```
|
||||||
|
---fs.getDir("/rom/startup.lua")
|
||||||
|
-----> "rom"
|
||||||
|
---
|
||||||
|
---fs.getDir("/rom/programs/")
|
||||||
|
-----> "rom"
|
||||||
|
---
|
||||||
|
---fs.getDir("/rom/apis/command/")
|
||||||
|
-----> "rom/apis"
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#v:getDir)
|
||||||
|
function fs.getDir(path) end
|
||||||
|
|
||||||
|
---Get the size of a file
|
||||||
|
---@param path string The path to the file to get the size of
|
||||||
|
---@return integer bytes The size of the file in bytes. 0 if the path points to a directory
|
||||||
|
---@throws If the path doesn't exist
|
||||||
|
---## Examples
|
||||||
|
---```
|
||||||
|
---fs.getSize("/rom/apis/vector.lua")
|
||||||
|
-----> 5826
|
||||||
|
---
|
||||||
|
---fs.getSize("/rom/apis/turtle/")
|
||||||
|
-----> 0
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#v:getSize)
|
||||||
|
function fs.getSize(path) end
|
||||||
|
|
||||||
|
---Get whether a path exists
|
||||||
|
---@param path string The path to check the existence of
|
||||||
|
---@return boolean exists
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#v:exists)
|
||||||
|
function fs.exists(path) end
|
||||||
|
|
||||||
|
---Get whether a path is a directory
|
||||||
|
---@param path string The path to check
|
||||||
|
---@return boolean isDirectory If the path exists **and** is a directory
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#v:isDir)
|
||||||
|
function fs.isDir(path) end
|
||||||
|
|
||||||
|
---Get whether a path is read-only
|
||||||
|
---@param path string The path to check
|
||||||
|
---@return boolean isReadOnly If the path can only be read and not written to
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---fs.isReadOnly("/rom")
|
||||||
|
-----> true
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#v:isReadOnly)
|
||||||
|
function fs.isReadOnly(path) end
|
||||||
|
|
||||||
|
---Create a directory, including any missing parents
|
||||||
|
---@param path string The path to (and including) the directory to create
|
||||||
|
---@throws If target path could not be written to
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#v:makeDir)
|
||||||
|
function fs.makeDir(path) end
|
||||||
|
|
||||||
|
---Move a file/directory to another path
|
||||||
|
---
|
||||||
|
---Any missing parent directories at the specified destination are created as
|
||||||
|
---needed
|
||||||
|
---@param origin string The origin path to move
|
||||||
|
---@param destination string The destination path
|
||||||
|
---@throws If destination could not be written to
|
||||||
|
---## Examples
|
||||||
|
---```
|
||||||
|
-----Rename file
|
||||||
|
---fs.move("/scripts/oldName.lua", "/scripts/newName.lua")
|
||||||
|
---
|
||||||
|
-----Rename directory
|
||||||
|
---fs.move("/scripts/projectA/", "/scripts/projectB/")
|
||||||
|
---
|
||||||
|
-----Move file to new directory
|
||||||
|
---fs.move("/scripts/oldLocation/test.lua", "/scripts/newLocation/test.lua")
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#v:move)
|
||||||
|
function fs.move(origin, destination) end
|
||||||
|
|
||||||
|
---Copy a file/directory to another path
|
||||||
|
---@param origin string The origin path to copy
|
||||||
|
---@param destination string The destination path to copy to
|
||||||
|
---@throws If destination could not be written to
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---fs.copy("/scripts/testing/main.lua", "scripts/trying/main.lua")
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#v:copy)
|
||||||
|
function fs.copy(origin, destination) end
|
||||||
|
|
||||||
|
---Deletes a file/directory
|
||||||
|
---
|
||||||
|
---Deleting a directory **deletes ALL children** (files and subdirectories)
|
||||||
|
---
|
||||||
|
---❗Be **VERY** careful when deleting directories as you could easily delete a
|
||||||
|
---**LOT** of files by accident
|
||||||
|
---@param path string The path to delete
|
||||||
|
---@throws If file/directory cannot be deleted
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#v:delete)
|
||||||
|
function fs.delete(path) end
|
||||||
|
|
||||||
|
---Opens a file for reading/writing
|
||||||
|
---@param path string The path to the file to open
|
||||||
|
---@param mode ccTweaked.fs.openMode The mode to open the file with
|
||||||
|
---@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
|
||||||
|
---@return nil|string errorMessage Why the file cannot be opened
|
||||||
|
---@throws If an invalid mode was given
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---local file = fs.open("/rom/help/intro.txt", "r")
|
||||||
|
---local contents = file.readAll()
|
||||||
|
---file.close()
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#v:open)
|
||||||
|
function fs.open(path, mode) end
|
||||||
|
|
||||||
|
---Get the name of the mount that the path is located on
|
||||||
|
---@param path string The path to get the mount location of
|
||||||
|
---@return string mount The name of the mount location. `hdd` for local files and `rom` for files in the `/rom/` directory
|
||||||
|
---@throws If the path doesn't exist
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#v:getDrive)
|
||||||
|
function fs.getDrive(path) end
|
||||||
|
|
||||||
|
---Get the amount of free space on the mount that the specified path is located on
|
||||||
|
---@param path string A path that belongs to the desired mount
|
||||||
|
---@return integer|"unlimited" free The free space in bytes, `unlimited`, or 0 if read-only
|
||||||
|
---@throws If the path doesn't exist
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#v:getFreeSpace)
|
||||||
|
function fs.getFreeSpace(path) end
|
||||||
|
|
||||||
|
---Search for files matching a wildcard pattern
|
||||||
|
---@param pattern string The path pattern to use
|
||||||
|
---@return string[] paths An array of matching paths
|
||||||
|
---@throws If the path doesn't exist
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
------This would match one/two/three, one/A/three, etc.
|
||||||
|
---local results = fs.find("one/*/three")
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#v:find)
|
||||||
|
function fs.find(pattern) end
|
||||||
|
|
||||||
|
---Get the total capacity of the mount the path is located on, if available
|
||||||
|
---@param path string A path that is located on the desired mount
|
||||||
|
---@return integer? capacity The capacity of the mount in bytes or `nil` if read-only
|
||||||
|
---@throws If the capacity could not be determined
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#v:getCapacity)
|
||||||
|
function fs.getCapacity(path) end
|
||||||
|
|
||||||
|
---Get attributes about a file/directory
|
||||||
|
---@param path string The path to the file/directory to get the attributes of
|
||||||
|
---@return ccTweaked.fs.fileAttributes attributes The attributes of the file/directory
|
||||||
|
---@throws If the path does not exist
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#v:attributes)
|
||||||
|
function fs.attributes(path) end
|
||||||
|
|
@ -0,0 +1,95 @@
|
||||||
|
---@meta
|
||||||
|
---Functions defined in `bios.lua` that are in the global (_G) environment.
|
||||||
|
|
||||||
|
---Stores the current ComputerCraft and Minecraft versions, for example:
|
||||||
|
---`ComputerCraft 1.93.0 (Minecraft 1.15.2)`
|
||||||
|
---@type string
|
||||||
|
_HOST = nil
|
||||||
|
|
||||||
|
---Stores the default settings as a comma-separated string as defined in the
|
||||||
|
---ComputerCraft configuration file. By default, is an empty string.
|
||||||
|
---@type string
|
||||||
|
_CC_DEFAULT_SETTINGS = nil
|
||||||
|
|
||||||
|
---Pauses execution for the specified number of seconds.
|
||||||
|
---@param time number The number of seconds to sleep for, rounded up to the nearest multiple of 0.05
|
||||||
|
---As it waits for a fixed amount of world ticks, time will automatically be
|
||||||
|
---rounded up to the nearest multiple of 0.05 seconds. If you are using
|
||||||
|
---coroutines or the parallel API, it will only pause execution of the current
|
||||||
|
---thread, not the whole program.
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---print("Going to sleep for 2 seconds!")
|
||||||
|
---sleep(2)
|
||||||
|
---print("Slept for 2 seconds!")
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/_G.html#v:sleep)
|
||||||
|
function sleep(time) end
|
||||||
|
|
||||||
|
---Writes text to the screen with no trailing newline. Wraps text when needed.
|
||||||
|
---@param text string
|
||||||
|
---@return number lines The number of lines written
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---write("Hello World!")
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/_G.html#v:write)
|
||||||
|
function write(text) end
|
||||||
|
|
||||||
|
---Prints the specified values to the screen, separated by spaces, wrapping when
|
||||||
|
---necessary. After printing the cursor is moved to the next line.
|
||||||
|
---@vararg any
|
||||||
|
---@return number lines The number of lines written
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---print("Hello", "World!")
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/_G.html#v:print)
|
||||||
|
function print(...) end
|
||||||
|
|
||||||
|
---Prints the specified values to the screen in red, separated by spaces,
|
||||||
|
--wrapping when necessary. After printing, the cursor is moved to the next line.
|
||||||
|
---@param ... unknown
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---printError("Something has gone terribly wrong!")
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/_G.html#v:printError)
|
||||||
|
function printError(...) end
|
||||||
|
|
||||||
|
---Reads user input from the terminal. This automatically handles arrow keys,
|
||||||
|
--pasting, character replacement, history scrollback, auto-completion, and
|
||||||
|
--default values.
|
||||||
|
---@param replaceCharacter? string A character to replace each typed character. Useful for hiding passwords.
|
||||||
|
---@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.
|
||||||
|
---@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.
|
||||||
|
---@param default? string Text that should already be entered by default
|
||||||
|
---@return string text The text entered by the user
|
||||||
|
---## Example
|
||||||
|
---Prompt user for a password
|
||||||
|
---```
|
||||||
|
---while true do
|
||||||
|
--- write("Password> ")
|
||||||
|
--- local pwd = read("*")
|
||||||
|
--- if pwd == "let me in" then break end
|
||||||
|
--- print("Incorrect password, try again.")
|
||||||
|
---end
|
||||||
|
---print("Logged in!")
|
||||||
|
---```
|
||||||
|
---## Example 2
|
||||||
|
---Offer history, completion, and a default value
|
||||||
|
---```
|
||||||
|
---local completion = require "cc.completion"
|
||||||
|
---local history = { "potato", "orange", "apple" }
|
||||||
|
---local choices = { "apple", "orange", "banana", "strawberry" }
|
||||||
|
---write("> ")
|
||||||
|
---local msg = read(nil, history, function(text) return completion.choice(text, choices) end, "app")
|
||||||
|
---print(msg)
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/_G.html#v:read)
|
||||||
|
function read(replaceCharacter, history, completeFunction, default) end
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---Using modems and computers, you can find the GPS coordinates of other computers/turtles in the world.
|
||||||
|
---
|
||||||
|
---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.
|
||||||
|
---
|
||||||
|
---You can set up a GPS host using the `gps` program. The program requires the `x`, `y`, `z` of the host **computer** not modem.
|
||||||
|
---
|
||||||
|
---You can choose which axes `x`, `y`, `z` refer to, just make sure that you are consistent with your usage.
|
||||||
|
---
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/gps.html)
|
||||||
|
gps = {}
|
||||||
|
|
||||||
|
---The channel that GPS requests and responses are broadcast on
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/gps.html#v:CHANNEL_GPS)
|
||||||
|
gps.CHANNEL_GPS = 65534
|
||||||
|
|
||||||
|
---Attempt to retrieve the location of this computer
|
||||||
|
---@param timeout number The maximum time in seconds permitted to try and retrieve location
|
||||||
|
---@param debug boolean If debugging messages should be displayed
|
||||||
|
---@return number x This computer's `x` position
|
||||||
|
---@return number y This computer's `y` position
|
||||||
|
---@return number z This computer's `z` position
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/gps.html#v:locate)
|
||||||
|
function gps.locate(timeout, debug) end
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---Tools for finding and specifying where help files are on this computer
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/help.html)
|
||||||
|
help = {}
|
||||||
|
|
||||||
|
---Get a list of index directories where help files are searched for
|
||||||
|
---@return string indexList A colon-separated list of index directories. Paths are absolute
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---local helpPaths = {}
|
||||||
|
---
|
||||||
|
-----Separate colon-separated list into table
|
||||||
|
---for match in string.gmatch(help.path(), "([^:]+)") do
|
||||||
|
--- table.insert(helpPaths, match)
|
||||||
|
---end
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/help.html#v:path)
|
||||||
|
function help.path() end
|
||||||
|
|
||||||
|
---Set where help files will be searched for
|
||||||
|
---@param indexList string A colon-separated list of index directories. Paths are absolute
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---help.setPath(help.path() .. ":/myProgram/help/")
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/help.html#v:setPath)
|
||||||
|
function help.setPath(indexList) end
|
||||||
|
|
||||||
|
---Get the location of the help file for a topic
|
||||||
|
---@param topic string The topic to find
|
||||||
|
---@return string|nil path The path to the help file or `nil` if it cannot be found
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---help.lookup("disk")
|
||||||
|
-----> "rom/help/disk.txt"
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/help.html#v:lookup)
|
||||||
|
function help.lookup(topic) end
|
||||||
|
|
||||||
|
---Get a list of help topics
|
||||||
|
---@return string[] topics An array of help topics sorted A→Z
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/help.html#v:topics)
|
||||||
|
function help.topics() end
|
||||||
|
|
||||||
|
---Get completion suggestions for help topics
|
||||||
|
---@param partial string A partially completed help topic name to complete
|
||||||
|
---@return string[] completions An array of possible completions
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/help.html#v:completeTopic)
|
||||||
|
function help.completeTopic(partial) end
|
||||||
|
|
@ -0,0 +1,144 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---An API for making [HTTP
|
||||||
|
---requests](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods). Allows
|
||||||
|
---sending/receiving data to/from a web server.
|
||||||
|
---
|
||||||
|
---[Making requests to local IPs](https://tweaked.cc/guide/local_ips.html) is
|
||||||
|
---blocked by default but can be enabled in the configuration file.
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html)
|
||||||
|
http = {}
|
||||||
|
|
||||||
|
---Asynchronously make a
|
||||||
|
---[GET](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET) or
|
||||||
|
---[POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST) request
|
||||||
|
---
|
||||||
|
---When the request is completed, the `http_success` or `http_failure` event will be fired.
|
||||||
|
---@param url string The URL to make the request to
|
||||||
|
---@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
|
||||||
|
---@param headers? table<string, string> The [request headers](https://developer.mozilla.org/en-US/docs/Glossary/Request_header)
|
||||||
|
---@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
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#v:request)
|
||||||
|
function http.request(url, body, headers, binary) end
|
||||||
|
|
||||||
|
---Asynchronously make a [HTTP request](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods)
|
||||||
|
---
|
||||||
|
---When the request is completed, the `http_success` or `http_failure` event will be fired.
|
||||||
|
---@param request ccTweaked.http.Request
|
||||||
|
---## Request Parameter Shape
|
||||||
|
---```
|
||||||
|
---request = {
|
||||||
|
--- url: string, -- The URL to make the request to
|
||||||
|
--- body?: string, -- The body of the request, if it has one
|
||||||
|
--- headers?: {[string] = string}, -- The request headers
|
||||||
|
--- 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
|
||||||
|
--- method?: string, -- The HTTP method to use
|
||||||
|
--- redirect?: boolean -- Whether HTTP redirects should be followed. Defaults to true
|
||||||
|
---}
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#v:request)
|
||||||
|
function http.request(request) end
|
||||||
|
|
||||||
|
---Make a [GET](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET) request
|
||||||
|
---@param url string The URL to make the request to
|
||||||
|
---@param headers? table<string, string> The [request headers](https://developer.mozilla.org/en-US/docs/Glossary/Request_header)
|
||||||
|
---@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
|
||||||
|
---@return ccTweaked.http.Response|ccTweaked.http.BinaryResponse|nil response The HTTP response object. `nil` when the request fails
|
||||||
|
---@return string message Why the request failed
|
||||||
|
---@return nil|ccTweaked.http.Response|ccTweaked.http.BinaryResponse failedResponse The response object for the failed request, if available
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#v:get)
|
||||||
|
function http.get(url, headers, binary) end
|
||||||
|
|
||||||
|
---Make a HTTP request
|
||||||
|
---@param request ccTweaked.http.Request
|
||||||
|
---@return ccTweaked.http.Response|ccTweaked.http.BinaryResponse|nil response The HTTP response object. `nil` when the request fails
|
||||||
|
---@return string message Why the request failed
|
||||||
|
---@return nil|ccTweaked.http.Response|ccTweaked.http.BinaryResponse failedResponse The response object for the failed request, if available
|
||||||
|
---## Request Parameter Shape
|
||||||
|
---```
|
||||||
|
---request = {
|
||||||
|
--- url: string, -- The URL to make the request to
|
||||||
|
--- body?: string, -- The body of the request, if it has one
|
||||||
|
--- headers?: {[string] = string}, -- The request headers
|
||||||
|
--- 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
|
||||||
|
--- method?: string, -- The HTTP method to use
|
||||||
|
--- redirect?: boolean -- Whether HTTP redirects should be followed. Defaults to true
|
||||||
|
---}
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#v:get)
|
||||||
|
function http.get(request) end
|
||||||
|
|
||||||
|
---Make a [POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST) request
|
||||||
|
---@param url string The URL to make the request to
|
||||||
|
---@param body string The body of the [POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST) request
|
||||||
|
---@param headers? table<string, string> The [request headers](https://developer.mozilla.org/en-US/docs/Glossary/Request_header)
|
||||||
|
---@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
|
||||||
|
---@return ccTweaked.http.Response|ccTweaked.http.BinaryResponse|nil response The HTTP response object. `nil` when the request fails
|
||||||
|
---@return string message Why the request failed
|
||||||
|
---@return nil|ccTweaked.http.Response|ccTweaked.http.BinaryResponse failedResponse The response object for the failed request, if available
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#v:post)
|
||||||
|
function http.post(url, body, headers, binary) end
|
||||||
|
|
||||||
|
---Make a HTTP request
|
||||||
|
---@param request ccTweaked.http.Request
|
||||||
|
---@return ccTweaked.http.Response|ccTweaked.http.BinaryResponse|nil response The HTTP response object. `nil` when the request fails
|
||||||
|
---@return string message Why the request failed
|
||||||
|
---@return nil|ccTweaked.http.Response|ccTweaked.http.BinaryResponse failedResponse The response object for the failed request, if available
|
||||||
|
---## Request Parameter Shape
|
||||||
|
---```
|
||||||
|
---request = {
|
||||||
|
--- url: string, -- The URL to make the request to
|
||||||
|
--- body?: string, -- The body of the request, if it has one
|
||||||
|
--- headers?: {[string] = string}, -- The request headers
|
||||||
|
--- 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
|
||||||
|
--- method?: string, -- The HTTP method to use
|
||||||
|
--- redirect?: boolean -- Whether HTTP requests should be followed. Defaults to true
|
||||||
|
---}
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#v:post)
|
||||||
|
function http.post(request) end
|
||||||
|
|
||||||
|
---Asynchronously determine if a URL can be requested
|
||||||
|
---
|
||||||
|
---This will immediately return if the URL entered is itself invalid. You will
|
||||||
|
---then want to listen to the `http_check` event which will contain more info on
|
||||||
|
---if the URL can be requested.
|
||||||
|
---@param url string The URL to check
|
||||||
|
---@return boolean valid If the URL is valid. It could still 404, this is just confirming the URL is valid (read above)
|
||||||
|
---@return nil|string message Why the URL is invalid (e.g. blocked, malformed, etc.)
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#v:checkURLAsync)
|
||||||
|
function http.checkURLAsync(url) end
|
||||||
|
|
||||||
|
---Determine if a URL can be requested
|
||||||
|
---@param url string The URL to check
|
||||||
|
---@return boolean valid If the URL can be requested
|
||||||
|
---@return nil|string message Why the URL cannot be requested (e.g. blocked, malformed, etc.)
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#v:checkURL)
|
||||||
|
function http.checkURL(url) end
|
||||||
|
|
||||||
|
---Open a websocket
|
||||||
|
---@param url string The URL of the websocket to connect to. Should use the `ws://` or `wss://` protocol
|
||||||
|
---@param headers? table<string, string> Headers to send for the handshake
|
||||||
|
---@return ccTweaked.http.Websocket|false websocket The websocket connection object or false if it failed to connect
|
||||||
|
---@return string message Why the websocket failed to connect
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#v:websocket)
|
||||||
|
function http.websocket(url, headers) end
|
||||||
|
|
||||||
|
---Asynchronously open a websocket
|
||||||
|
---
|
||||||
|
---Returns immediately and a `websocket_success` or `websocket_failure` event will be fired when the request is completed
|
||||||
|
---@param url string The URL of the websocket to connect to. Should use the `ws://` or `wss://` protocol
|
||||||
|
---@param headers? table<string, string> Headers to send for the handshake
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#v:websocketAsync)
|
||||||
|
function http.websocketAsync(url, headers) end
|
||||||
|
|
@ -0,0 +1,119 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---Emulates Lua's [io library](https://www.lua.org/manual/5.1/manual.html#5.7)
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/io.html)
|
||||||
|
io = {}
|
||||||
|
|
||||||
|
---A file handle representing the "standard input". Reading from this file will
|
||||||
|
---prompt the user for input.
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/io.html#v:stdin)
|
||||||
|
---@type ccTweaked.fs.Handle
|
||||||
|
io.stdin = nil
|
||||||
|
|
||||||
|
---A file handle representing the "standard output". Writing to this file will
|
||||||
|
---display the written text to the screen.
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/io.html#v:stdout)
|
||||||
|
---@type ccTweaked.fs.Handle
|
||||||
|
io.stdout = nil
|
||||||
|
|
||||||
|
---A file handle representing the "standard error" stream.
|
||||||
|
---One may use this to display error messages, writing to it will display them on the terminal.
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/io.html#v:stderr)
|
||||||
|
---@type ccTweaked.fs.Handle
|
||||||
|
io.stderr = nil
|
||||||
|
|
||||||
|
---Close a file handle
|
||||||
|
---@param handle ccTweaked.fs.Handle The file handle to close. Defaults to the current output file
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/io.html#v:close)
|
||||||
|
function io.close(handle) end
|
||||||
|
|
||||||
|
---Flushes the current output file, saving it without closing it
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/io.html#v:flush)
|
||||||
|
function io.flush() end
|
||||||
|
|
||||||
|
---Get or set the current input file
|
||||||
|
---@param file (ccTweaked.fs.Handle|string)? The new input file, either as a file path or a handle
|
||||||
|
---@return ccTweaked.fs.Handle handle The current input file handle
|
||||||
|
---@throws If the provided path cannot be opened for reading
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/io.html#v:input)
|
||||||
|
function io.input(file) end
|
||||||
|
|
||||||
|
---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
|
||||||
|
---
|
||||||
|
---Once the end of the file has been reached, nil will be returned and the file is automatically closed.
|
||||||
|
---
|
||||||
|
---If no file name is given, the current input will be used instead. In this case, the handle is not used.
|
||||||
|
---@param path? string The path to the file to read lines from
|
||||||
|
---@param readMode? ccTweaked.io.readMode How the lines should be read
|
||||||
|
---@return fun(): string iterator The line iterator
|
||||||
|
---@throws If the file cannot be opened for reading
|
||||||
|
---
|
||||||
|
---❗Passing `"a"` as a format will result in an infinite loop and will crash your script after timing out
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
-----Iterate over and print all lines in a file
|
||||||
|
---for line in io.lines("/rom/help/intro.txt") do
|
||||||
|
--- print(line)
|
||||||
|
---end
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/io.html#v:lines)
|
||||||
|
function io.lines(path, readMode) end
|
||||||
|
|
||||||
|
---Open a file in the mode provided
|
||||||
|
---@param path string The path to the file to open
|
||||||
|
---@param mode? ccTweaked.fs.openMode The mode to open the file in. Defaults to `rb` (binary read)
|
||||||
|
---@return ccTweaked.fs.Handle|nil handle The opened file or nil if an error occurred
|
||||||
|
---@return nil|string errorMessage Why the file could not be opened
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/io.html#v:open)
|
||||||
|
function io.open(path, mode) end
|
||||||
|
|
||||||
|
---Get or set the current output file
|
||||||
|
---@param file (ccTweaked.fs.Handle|string)? The new output file, either as a file path or a handle
|
||||||
|
---@return ccTweaked.fs.Handle handle The current output file handle
|
||||||
|
---@throws If the provided path cannot be opened for writing
|
||||||
|
---------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/io.html#v:output)
|
||||||
|
function io.output(file) end
|
||||||
|
|
||||||
|
---Read from the currently opened file
|
||||||
|
---
|
||||||
|
---This is equivalent to:
|
||||||
|
---```
|
||||||
|
---local handle = io.open('/testFile.txt')
|
||||||
|
---handle:read()
|
||||||
|
---```
|
||||||
|
---@param ... ccTweaked.io.readMode The formats to use for reading. Defaults to `l`
|
||||||
|
---@return string ... The data (as a string) read from the file or nil if no data could be read.
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/io.html#v:read)
|
||||||
|
function io.read(...) end
|
||||||
|
|
||||||
|
---Checks whether the provided value is a `Handle` and if it is open
|
||||||
|
---@param obj any The value to check
|
||||||
|
---@return "file"|"closed file"|nil type If the file is open (`"file"`), closed (`"closed file"`), or is not even a file `Handle` (`nil`)
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/io.html#v:type)
|
||||||
|
function io.type(obj) end
|
||||||
|
|
||||||
|
---Write to the currently opened file
|
||||||
|
---
|
||||||
|
---This is equivalent to:
|
||||||
|
---```
|
||||||
|
---local handle = io.open('/testFile.txt')
|
||||||
|
---handle:write()
|
||||||
|
---```
|
||||||
|
---@param ... string The strings to write to the file
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/io.html#v:write)
|
||||||
|
function io.write(...) end
|
||||||
|
|
@ -0,0 +1,135 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---@type integer
|
||||||
|
local int
|
||||||
|
|
||||||
|
---It is recommended that you use the constant values defined here rather than
|
||||||
|
---any numerical values as they may change between versions
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/keys.html)
|
||||||
|
keys = {
|
||||||
|
["space"] = int,
|
||||||
|
["apostrophe"] = int,
|
||||||
|
["comma"] = int,
|
||||||
|
["minus"] = int,
|
||||||
|
["period"] = int,
|
||||||
|
["slash"] = int,
|
||||||
|
["zero"] = int,
|
||||||
|
["one"] = int,
|
||||||
|
["two"] = int,
|
||||||
|
["three"] = int,
|
||||||
|
["four"] = int,
|
||||||
|
["five"] = int,
|
||||||
|
["six"] = int,
|
||||||
|
["seven"] = int,
|
||||||
|
["eight"] = int,
|
||||||
|
["nine"] = int,
|
||||||
|
["semicolon"] = int,
|
||||||
|
["equals"] = int,
|
||||||
|
["a"] = int,
|
||||||
|
["b"] = int,
|
||||||
|
["c"] = int,
|
||||||
|
["d"] = int,
|
||||||
|
["e"] = int,
|
||||||
|
["f"] = int,
|
||||||
|
["g"] = int,
|
||||||
|
["h"] = int,
|
||||||
|
["i"] = int,
|
||||||
|
["j"] = int,
|
||||||
|
["k"] = int,
|
||||||
|
["l"] = int,
|
||||||
|
["m"] = int,
|
||||||
|
["n"] = int,
|
||||||
|
["o"] = int,
|
||||||
|
["p"] = int,
|
||||||
|
["q"] = int,
|
||||||
|
["r"] = int,
|
||||||
|
["s"] = int,
|
||||||
|
["t"] = int,
|
||||||
|
["u"] = int,
|
||||||
|
["v"] = int,
|
||||||
|
["w"] = int,
|
||||||
|
["x"] = int,
|
||||||
|
["y"] = int,
|
||||||
|
["z"] = int,
|
||||||
|
["leftBracket"] = int,
|
||||||
|
["backslash"] = int,
|
||||||
|
["rightBracket"] = int,
|
||||||
|
["grave"] = int,
|
||||||
|
["enter"] = int,
|
||||||
|
["tab"] = int,
|
||||||
|
["backspace"] = int,
|
||||||
|
["insert"] = int,
|
||||||
|
["delete"] = int,
|
||||||
|
["right"] = int,
|
||||||
|
["left"] = int,
|
||||||
|
["down"] = int,
|
||||||
|
["up"] = int,
|
||||||
|
["pageUp"] = int,
|
||||||
|
["pageDown"] = int,
|
||||||
|
["home"] = int,
|
||||||
|
["end"] = int,
|
||||||
|
["capsLock"] = int,
|
||||||
|
["scrollLock"] = int,
|
||||||
|
["numLock"] = int,
|
||||||
|
["printScreen"] = int,
|
||||||
|
["pause"] = int,
|
||||||
|
["f1"] = int,
|
||||||
|
["f2"] = int,
|
||||||
|
["f3"] = int,
|
||||||
|
["f4"] = int,
|
||||||
|
["f5"] = int,
|
||||||
|
["f6"] = int,
|
||||||
|
["f7"] = int,
|
||||||
|
["f8"] = int,
|
||||||
|
["f9"] = int,
|
||||||
|
["f10"] = int,
|
||||||
|
["f11"] = int,
|
||||||
|
["f12"] = int,
|
||||||
|
["f13"] = int,
|
||||||
|
["f14"] = int,
|
||||||
|
["f15"] = int,
|
||||||
|
["f16"] = int,
|
||||||
|
["f17"] = int,
|
||||||
|
["f18"] = int,
|
||||||
|
["f19"] = int,
|
||||||
|
["f20"] = int,
|
||||||
|
["f21"] = int,
|
||||||
|
["f22"] = int,
|
||||||
|
["f23"] = int,
|
||||||
|
["f24"] = int,
|
||||||
|
["f25"] = int,
|
||||||
|
["numPad0"] = int,
|
||||||
|
["numPad1"] = int,
|
||||||
|
["numPad2"] = int,
|
||||||
|
["numPad3"] = int,
|
||||||
|
["numPad4"] = int,
|
||||||
|
["numPad5"] = int,
|
||||||
|
["numPad6"] = int,
|
||||||
|
["numPad7"] = int,
|
||||||
|
["numPad8"] = int,
|
||||||
|
["numPad9"] = int,
|
||||||
|
["numPadDecimal"] = int,
|
||||||
|
["numPadDivide"] = int,
|
||||||
|
["numPadMultiply"] = int,
|
||||||
|
["numPadSubtract"] = int,
|
||||||
|
["numPadAdd"] = int,
|
||||||
|
["numPadEnter"] = int,
|
||||||
|
["numPadEqual"] = int,
|
||||||
|
["leftShift"] = int,
|
||||||
|
["leftCtrl"] = int,
|
||||||
|
["leftAlt"] = int,
|
||||||
|
["leftSuper"] = int,
|
||||||
|
["rightShift"] = int,
|
||||||
|
["rightCtrl"] = int,
|
||||||
|
["rightAlt"] = int,
|
||||||
|
["menu"] = int,
|
||||||
|
}
|
||||||
|
|
||||||
|
---Translates a key code to a written name from the `keys` API
|
||||||
|
---@param code integer
|
||||||
|
---@return string|nil name The name of the key or nil if the code was invalid
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/keys.html#v:getName)
|
||||||
|
function keys.getName(code) end
|
||||||
|
|
@ -0,0 +1,73 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---Multishell can be used to run multiple programs at the same time
|
||||||
|
---
|
||||||
|
---Multishell is a program that injects its API into the shell's environment and
|
||||||
|
---it is only available on advance computers
|
||||||
|
---
|
||||||
|
---When multiple programs are running, a tab bar at the top of the screen
|
||||||
|
---appears, allow you to switch between programs. New shells can be launched
|
||||||
|
---using the `bg` or `fg` programs, by using `shell.openTab()` or
|
||||||
|
---`multishell.launch()`.
|
||||||
|
---
|
||||||
|
---Each process is identified by its PID (process ID), which corresponds to its position in
|
||||||
|
---the tab list. As these positions can change, the **PID is not constant**.
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/multishell.html)
|
||||||
|
multishell = {}
|
||||||
|
|
||||||
|
---Get the currently opened/visible process. This is the currently selected
|
||||||
|
---process from the tab bar.
|
||||||
|
---@return ccTweaked.multishell.PID PID The ID of the focused process
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/multishell.html#v:getFocus)
|
||||||
|
function multishell.getFocus() end
|
||||||
|
|
||||||
|
---Set the currently opened/visible process
|
||||||
|
---@param PID ccTweaked.multishell.PID The ID of the process to focus
|
||||||
|
---@return boolean success If the process was successfully changed. This will be `false` if there is no process with the given `PID`
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/multishell.html#v:setFocus)
|
||||||
|
function multishell.setFocus(PID) end
|
||||||
|
|
||||||
|
---Get the title of the tab for the given process
|
||||||
|
---@param PID ccTweaked.multishell.PID The ID of the process to get the title of
|
||||||
|
---@return string|nil title The title of the process or `nil` if the process doesn't exist
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/multishell.html#v:getTitle)
|
||||||
|
function multishell.getTitle(PID) end
|
||||||
|
|
||||||
|
---Set the title of the tab for the given process
|
||||||
|
---@param PID ccTweaked.multishell.PID The ID of the process that will have its title set
|
||||||
|
---@param title string The new title to set for the process
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/multishell.html#v:setTitle)
|
||||||
|
function multishell.setTitle(PID, title) end
|
||||||
|
|
||||||
|
---Get the `PID` of the currently running process
|
||||||
|
---@return ccTweaked.multishell.PID PID The ID of the currently running process
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/multishell.html#v:getCurrent)
|
||||||
|
function multishell.getCurrent() end
|
||||||
|
|
||||||
|
---Launch a new process in multishell mode
|
||||||
|
---@param env table The environment to load the path under. For example, passing `_E` will pass the environment you are currently using.
|
||||||
|
---@param path string The path to the program to launch
|
||||||
|
---@param ... any Additional arguments to pass to the program
|
||||||
|
---@return ccTweaked.multishell.PID PID The ID of the created process
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---local pENV = {}
|
||||||
|
---local path = "/add.lua"
|
||||||
|
---local PID = multishell.launch(pENV, path, 2, 2)
|
||||||
|
---multishell.setTitle(PID, "2+2=4")
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/multishell.html#v:launch)
|
||||||
|
function multishell.launch(env, path, ...) end
|
||||||
|
|
||||||
|
---Get the number of concurrent processes within this multishell
|
||||||
|
---@return number count The number of processes running
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/multishell.html#v:getCount)
|
||||||
|
function multishell.getCount() end
|
||||||
|
|
@ -0,0 +1,312 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---For interacting with CraftOS on the current computer
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/os.html)
|
||||||
|
os = {}
|
||||||
|
|
||||||
|
---Loads an API/library into the global environment
|
||||||
|
---
|
||||||
|
---This will load and execute the given file and all exported variables and
|
||||||
|
---functions will be available under the namespace of the filename
|
||||||
|
---(e.g.`fileName.functionName`)
|
||||||
|
---
|
||||||
|
---🚮 **Deprecated** due to it polluting the global namespace\
|
||||||
|
---You should instead use `require()` to load libraries/APIs
|
||||||
|
---@param path string Path to the file to load
|
||||||
|
---@return boolean success If the API was successfully loaded
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/os.html#v:loadAPI)
|
||||||
|
function os.loadAPI(path) end
|
||||||
|
|
||||||
|
---Unloads an API that was loaded with `os.loadAPI()`
|
||||||
|
---
|
||||||
|
---🚮 **Deprecated**, see `os.loadAPI()` for more info
|
||||||
|
---@param name string The name of the API to unload
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/os.html#v:unloadAPI)
|
||||||
|
function os.unloadAPI(name) end
|
||||||
|
|
||||||
|
---Pause execution of the current thread and wait for an event to fire
|
||||||
|
---
|
||||||
|
---If no event name is provided, it will resume when any event fires
|
||||||
|
---
|
||||||
|
---Unlike `os.pullEventRaw()`, this function will stop when it receives a
|
||||||
|
---`terminate` event and it will print the error "Terminated"
|
||||||
|
---
|
||||||
|
---This works by yielding until it receives a vararg list where the first
|
||||||
|
---element matches the name of the event provided
|
||||||
|
---@generic T : ccTweaked.os.event
|
||||||
|
---@async
|
||||||
|
---@param event? `T` The event to listen for
|
||||||
|
---@return `T` event The name of the event that fired
|
||||||
|
---@return any ... Any values returned by the event
|
||||||
|
---@overload fun(): ccTweaked.os.event, ...
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---while true do
|
||||||
|
--- local eventData = { os.pullEvent() }
|
||||||
|
--- local event = eventData[1]
|
||||||
|
---
|
||||||
|
--- if event == "mouse_click" then
|
||||||
|
--- print("Button", eventData[2], "was clicked at", eventData[3], ",", eventData[4])
|
||||||
|
--- elseif event == "key" then
|
||||||
|
--- print("Key code", eventData[2], "was pressed")
|
||||||
|
--- end
|
||||||
|
---end
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/os.html#v:pullEvent)
|
||||||
|
function os.pullEvent(event) end
|
||||||
|
|
||||||
|
---Pause execution of the current thread and wait for an event to fire,
|
||||||
|
---including the terminate event
|
||||||
|
---
|
||||||
|
---This behaves nearly the exact same as `os.pullEvent()` except this also
|
||||||
|
---allows you to handle the `terminate` event, rather than stopping
|
||||||
|
---
|
||||||
|
---If no event name is provided, it will resume when any event fires
|
||||||
|
---
|
||||||
|
---This works by yielding until it receives a vararg list where the first
|
||||||
|
---element matches the name of the event provided
|
||||||
|
---@generic T : ccTweaked.os.event
|
||||||
|
---@async
|
||||||
|
---@param event? `T` The event to listen for
|
||||||
|
---@return `T` event The name of the event that fired
|
||||||
|
---@return any ... Any values returned by the event
|
||||||
|
---@overload fun(): ccTweaked.os.event, ...
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---while true do
|
||||||
|
--- local event = os.pullEventRaw()
|
||||||
|
--- if event == "terminate" then
|
||||||
|
--- print("Caught terminate event!")
|
||||||
|
--- end
|
||||||
|
---end
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/os.html#v:pullEventRaw)
|
||||||
|
function os.pullEventRaw(event) end
|
||||||
|
|
||||||
|
---Pauses execution for the specified number of seconds. An alias for `_G.sleep()`
|
||||||
|
---@param time number The number of seconds to sleep for, rounded up to the nearest multiple of 0.05
|
||||||
|
---As it waits for a fixed amount of world ticks, time will automatically be
|
||||||
|
---rounded up to the nearest multiple of 0.05 seconds. If you are using
|
||||||
|
---coroutines or the parallel API, it will only pause execution of the current
|
||||||
|
---thread, not the whole program.
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---print("Going to sleep for 2 seconds!")
|
||||||
|
---sleep(2)
|
||||||
|
---print("Slept for 2 seconds!")
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/os.html#v:sleep)
|
||||||
|
function os.sleep(time) end
|
||||||
|
|
||||||
|
---Get the current CraftOS version. Defined by `bios.lua`
|
||||||
|
---@return string version CraftOS version (e.g. `CraftOS 1.8`)
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/os.html#v:version)
|
||||||
|
function os.version() end
|
||||||
|
|
||||||
|
---Run a new process
|
||||||
|
---
|
||||||
|
---This does not provide access to the `shell` API, for this, you should instead
|
||||||
|
---use `shell.run()`
|
||||||
|
---
|
||||||
|
---If the program cannot be found, or failed to run, it will print the error and
|
||||||
|
---return false. If you want to handle this more gracefully, use an alternative
|
||||||
|
---such as `loadfile()`.
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---local pENV = {}
|
||||||
|
---local path = "/add.lua"
|
||||||
|
---local PID = os.run(pENV, path, 2, 2)
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/os.html#v:run)
|
||||||
|
---@param env table The environment to load the path under. For example, passing `_E` will pass the environment you are currently using.
|
||||||
|
---@param path string The path to the program to launch
|
||||||
|
---@param ... any Additional arguments to pass to the program
|
||||||
|
function os.run(env, path, ...) end
|
||||||
|
|
||||||
|
---Adds an event to the event queue that can later be listened to with `os.pullEvent()`
|
||||||
|
---@param name ccTweaked.os.event The name of the event to queue
|
||||||
|
---@param ... any The parameters of the event that can be read later
|
||||||
|
---@triggers `any`
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/os.html#v:queueEvent)
|
||||||
|
function os.queueEvent(name, ...) end
|
||||||
|
|
||||||
|
---Start a timer that will fire a `timer` event when it reaches the specified
|
||||||
|
---number of seconds.
|
||||||
|
---
|
||||||
|
---As this waits for a fixed amount of world ticks, `seconds` will be rounded up
|
||||||
|
---to the nearest multiple of 0.05 seconds
|
||||||
|
---@param seconds number The number of seconds until the timer fires
|
||||||
|
---@return integer ID The ID of the new timer
|
||||||
|
---@throws If `seconds` is below zero
|
||||||
|
---@triggers `timer`
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/os.html#v:startTimer)
|
||||||
|
function os.startTimer(seconds) end
|
||||||
|
|
||||||
|
---Cancels a timer that was started with `os.startTimer()`
|
||||||
|
---@param ID integer The ID of the timer to cancel
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/os.html#v:cancelTimer)
|
||||||
|
function os.cancelTimer(ID) end
|
||||||
|
|
||||||
|
---Set an alarm that will fire an `alarm` event at the requested game-time.
|
||||||
|
---@param time number The game-time to fire the event at (0.0 - 24.0)
|
||||||
|
---@return integer ID The ID of the new alarm
|
||||||
|
---@throws if the `time` is out of range
|
||||||
|
---@triggers `alarm`
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/os.html#v:setAlarm)
|
||||||
|
function os.setAlarm(time) end
|
||||||
|
|
||||||
|
---Cancels an alarm that was started with `os.setAlarm()`
|
||||||
|
---@param ID integer The ID of the alarm to cancel
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/os.html#v:cancelAlarm)
|
||||||
|
function os.cancelAlarm(ID) end
|
||||||
|
|
||||||
|
---Shut down this computer immediately
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/os.html#v:shutdown)
|
||||||
|
function os.shutdown() end
|
||||||
|
|
||||||
|
---Reboot this computer immediately
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/os.html#v:reboot)
|
||||||
|
function os.reboot() end
|
||||||
|
|
||||||
|
---Get the ID of this computer
|
||||||
|
---@return integer ID The ID of this computer
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/os.html#v:getComputerID)
|
||||||
|
function os.getComputerID() end
|
||||||
|
|
||||||
|
---Get the ID of this computer
|
||||||
|
---@return integer ID The ID of this computer
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/os.html#v:computerID)
|
||||||
|
function os.computerID() end
|
||||||
|
|
||||||
|
---Get the label of this computer
|
||||||
|
---@return string|nil label The label of this computer or `nil` if none is set
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/os.html#v:getComputerLabel)
|
||||||
|
function os.getComputerLabel() end
|
||||||
|
|
||||||
|
---Get the label of this computer
|
||||||
|
---@return string|nil label The label of this computer or `nil` if none is set
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/os.html#v:computerLabel)
|
||||||
|
function os.computerLabel() end
|
||||||
|
|
||||||
|
---Set the label of this computer
|
||||||
|
---@param label string? The new label for this computer or `nil` to clear it
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/os.html#v:setComputerLabel)
|
||||||
|
function os.setComputerLabel(label) end
|
||||||
|
|
||||||
|
---Get the number of seconds that this computer has been running for
|
||||||
|
---@return number uptime This computer's uptime in seconds
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/os.html#v:clock)
|
||||||
|
function os.clock() end
|
||||||
|
|
||||||
|
---Get the current time in one of the below formats
|
||||||
|
---
|
||||||
|
---- `ingame` - The current world time (default)
|
||||||
|
---- `utc` - Get the hour of the day in UTC time
|
||||||
|
---- `local` - Get the hour of the day in the timezone that the server is located in
|
||||||
|
---
|
||||||
|
---This function can also be given the table from calling `os.date("*t")` in
|
||||||
|
---which case, this function returns a [UNIX
|
||||||
|
---timestamp](https://www.unixtimestamp.com/)
|
||||||
|
---@param locale? ccTweaked.os.locale|ccTweaked.os.dateTable The locale to get the time in
|
||||||
|
---@return number time The hour of the selected locale or a UNIX timestamp depending on the value passed in
|
||||||
|
---@throws If an invald locale is passed in
|
||||||
|
---## Examples
|
||||||
|
---### Get game time
|
||||||
|
---```
|
||||||
|
---textutils.formatTime(os.time())
|
||||||
|
-----> "12:29 PM"
|
||||||
|
---```
|
||||||
|
---### Get UNIX timestamp
|
||||||
|
---```
|
||||||
|
---os.time(os.date("*t"))
|
||||||
|
-----> 1658310967
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/os.html#v:time)
|
||||||
|
function os.time(locale) end
|
||||||
|
|
||||||
|
---Get the amount of days since UNIX epoch in one of the below formats
|
||||||
|
---
|
||||||
|
---- `ingame` - The number of days since the save was created (default)
|
||||||
|
---- `utc` - Get the number of days since 1 January 1970 in UTC time
|
||||||
|
---- `local` - Get the number of days since 1 January 1970 in the server's local timezone
|
||||||
|
---
|
||||||
|
---@param locale? ccTweaked.os.locale
|
||||||
|
---@return number days Value depends on `locale` passed in
|
||||||
|
---@throws If an invalid locale is passed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/os.html#v:day)
|
||||||
|
function os.day(locale) end
|
||||||
|
|
||||||
|
---Get the number of milliseconds since an epoch
|
||||||
|
---@param locale ccTweaked.os.locale The locale to get the epoch from
|
||||||
|
---@return number milliseconds Number of milliseconds since the selected epoch
|
||||||
|
---@throws If an invalid locale is passed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/os.html#v:epoch)
|
||||||
|
function os.epoch(locale) end
|
||||||
|
|
||||||
|
---Get a date string (or table)
|
||||||
|
---
|
||||||
|
---The format string takes the same formats as [C's strftime
|
||||||
|
---function](http://www.cplusplus.com/reference/ctime/strftime/). It can be
|
||||||
|
---prefixed with an exclamation mark (!) to use UTC time instead of the server's
|
||||||
|
---local timezone.
|
||||||
|
---
|
||||||
|
---If the format is exactly `*t` (optionally prefixed with !), a table will be
|
||||||
|
---returned instead. This table has fields for the year, month, day, hour,
|
||||||
|
---minute, second, day of the week, day of the year, and whether Daylight Savings
|
||||||
|
---Time is in effect. This table can be converted to a UNIX timestamp (days since
|
||||||
|
---1 January 1970) with date.
|
||||||
|
---@param format? string The format of the string to return. Defaults to `%c`
|
||||||
|
---@param time? number The time (in seconds) to convert to a string. Defaults to the current time
|
||||||
|
---@return string|ccTweaked.os.dateTable
|
||||||
|
---@throws If an invalid format is passed
|
||||||
|
---## Examples
|
||||||
|
---### Get Date String
|
||||||
|
---```
|
||||||
|
---os.date("%d %b, %Y")
|
||||||
|
-----> "20 Jun, 2022"
|
||||||
|
---```
|
||||||
|
---### Get Date Table
|
||||||
|
---```
|
||||||
|
---os.date("*t")
|
||||||
|
----->
|
||||||
|
---{
|
||||||
|
--- year = 2022,
|
||||||
|
--- yday = 171,
|
||||||
|
--- month = 6,
|
||||||
|
--- day = 20,
|
||||||
|
--- wday = 2,
|
||||||
|
--- hour = 14,
|
||||||
|
--- min = 30,
|
||||||
|
--- sec = 14,
|
||||||
|
--- isdst = false
|
||||||
|
---
|
||||||
|
---}
|
||||||
|
---```
|
||||||
|
function os.date(format, time) end
|
||||||
|
|
@ -0,0 +1,90 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---Contains utilities for drawing graphics such as pixels, lines, and images
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/paintutils.html)
|
||||||
|
paintutils = {}
|
||||||
|
|
||||||
|
---Parse an image from a multi-line string
|
||||||
|
---@param image string A string containing the raw image data
|
||||||
|
---@return table imageData The parsed image data, for use with `paintutils.drawImage()`
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/paintutils.html#v:parseImage)
|
||||||
|
function paintutils.parseImage(image) end
|
||||||
|
|
||||||
|
---Loads an image from a file
|
||||||
|
---
|
||||||
|
---These image files can be created using the `paint` program
|
||||||
|
---@param path string The file to load
|
||||||
|
---@return table|nil imageData The parsed image data, for use with `paintutils.drawImage()`, or `nil` if the file does not exist
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---local image = paintutils.loadImage("data/example.nfp")
|
||||||
|
---paintutils.drawImage(image, term.getCursorPos())
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/paintutils.html#v:loadImage)
|
||||||
|
function paintutils.loadImage(path) end
|
||||||
|
|
||||||
|
---Draws a single pixel to the current terminal
|
||||||
|
---
|
||||||
|
---`1, 1` is the top left of the terminal screen
|
||||||
|
---
|
||||||
|
---⚠️ This may change the position of the cursor and the background color. Neither may be preserved
|
||||||
|
---@param x number The x position to draw at
|
||||||
|
---@param y number The y position to draw at
|
||||||
|
---@param color? ccTweaked.colors.color The color to use for this pixel. If omitted, the color will default to the current background color
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/paintutils.html#v:drawPixel)
|
||||||
|
function paintutils.drawPixel(x, y, color) end
|
||||||
|
|
||||||
|
---Draws a straight line between the two coordinates to the current terminal
|
||||||
|
---
|
||||||
|
---`1, 1` is the top left of the terminal screen
|
||||||
|
---
|
||||||
|
---⚠️ This may change the position of the cursor and the background color. Neither may be preserved
|
||||||
|
---@param x number The x position to start drawing at
|
||||||
|
---@param y number The y position to start drawing at
|
||||||
|
---@param x2 number The x position to stop drawing at
|
||||||
|
---@param y2 number The y position to stop drawing at
|
||||||
|
---@param color? ccTweaked.colors.color The color to use for this line. If omitted, the color will default to the current background color
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/paintutils.html#v:drawLine)
|
||||||
|
function paintutils.drawLine(x, y, x2, y2, color) end
|
||||||
|
|
||||||
|
---Draws the outline if a box to the current terminal
|
||||||
|
---
|
||||||
|
---`1, 1` is the top left of the terminal screen
|
||||||
|
---
|
||||||
|
---⚠️ This may change the position of the cursor and the background color. Neither may be preserved
|
||||||
|
---@param x number The x position to start drawing at
|
||||||
|
---@param y number The y position to start drawing at
|
||||||
|
---@param x2 number The x position to stop drawing at
|
||||||
|
---@param y2 number The y position to stop drawing at
|
||||||
|
---@param color? ccTweaked.colors.color The color to use for this box. If omitted, the color will default to the current background color
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/paintutils.html#v:drawBox)
|
||||||
|
function paintutils.drawBox(x, y, x2, y2, color) end
|
||||||
|
|
||||||
|
---Draws a filled box to the current terminal
|
||||||
|
---
|
||||||
|
---`1, 1` is the top left of the terminal screen
|
||||||
|
---
|
||||||
|
---⚠️ This may change the position of the cursor and the background color. Neither may be preserved
|
||||||
|
---@param x number The x position to start drawing at
|
||||||
|
---@param y number The y position to start drawing at
|
||||||
|
---@param x2 number The x position to stop drawing at
|
||||||
|
---@param y2 number The y position to stop drawing at
|
||||||
|
---@param color? ccTweaked.colors.color The color to use for this box. If omitted, the color will default to the current background color
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/paintutils.html#v:drawFilledBox)
|
||||||
|
function paintutils.drawFilledBox(x, y, x2, y2, color) end
|
||||||
|
|
||||||
|
---Draw an image that was loaded by `paintutils.parseImage()` or `paintutils.loadImage()`
|
||||||
|
---@param image table The parsed image data
|
||||||
|
---@param x number The x position to start drawing at
|
||||||
|
---@param y number The y position to start drawing at
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/paintutils.html#v:drawImage)
|
||||||
|
function paintutils.drawImage(image, x, y) end
|
||||||
|
|
@ -0,0 +1,72 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---Offers a simple way to run multiple functions at once
|
||||||
|
---
|
||||||
|
---Functions are not actually run simultaneously, however, this API will
|
||||||
|
---automatically switch between them whenever they yield (whether that be through
|
||||||
|
---`coroutine.yield()`, or functions that call that, such as `os.pullEvent()`)
|
||||||
|
---
|
||||||
|
---Each function executed in "parallel" gets its own copy of the event queue,
|
||||||
|
---and so "event consuming" functions (again, mostly anything that causes the
|
||||||
|
---script to pause - e.g. `os.sleep`, `rednet.receive`, most of the turtle API, etc)
|
||||||
|
---can safely be used in one without affecting the event queue accessed by the
|
||||||
|
---other.
|
||||||
|
---
|
||||||
|
---⚠️ Be careful to pass in the function you want to execute in parallel and not
|
||||||
|
---the result of that function (don't *call* the function)
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/parallel.html)
|
||||||
|
parallel = {}
|
||||||
|
|
||||||
|
---Switches between the execution of the functions until any one of them finishes
|
||||||
|
---
|
||||||
|
---Should one of the functions error, it will be propgated up to this
|
||||||
|
---`parallel.waitForAny()` call
|
||||||
|
---@param ... function The functions to be run in "parallel"
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---local function tick()
|
||||||
|
--- while true do
|
||||||
|
--- os.sleep(1)
|
||||||
|
--- print("Tick")
|
||||||
|
--- end
|
||||||
|
---end
|
||||||
|
---local function wait_for_q()
|
||||||
|
--- repeat
|
||||||
|
--- local _, key = os.pullEvent("key")
|
||||||
|
--- until key == keys.q
|
||||||
|
--- print("Q was pressed!")
|
||||||
|
---end
|
||||||
|
---
|
||||||
|
-----Print a message every second until the q key is pressed
|
||||||
|
---parallel.waitForAny(tick, wait_for_q)
|
||||||
|
---print("Everything done!")
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/parallel.html#v:waitForAny)
|
||||||
|
function parallel.waitForAny(...) end
|
||||||
|
|
||||||
|
---Switches between the execution of the functions until they all finish
|
||||||
|
---
|
||||||
|
---Should one of the functions error, it will be propgated up to this
|
||||||
|
---`parallel.waitForAll()` call
|
||||||
|
---@param ... function
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---local function a()
|
||||||
|
--- os.sleep(1)
|
||||||
|
--- print("A is done")
|
||||||
|
---end
|
||||||
|
---local function b()
|
||||||
|
--- os.sleep(3)
|
||||||
|
--- print("B is done")
|
||||||
|
---end
|
||||||
|
---
|
||||||
|
-----Start two timers and wait for both to finish
|
||||||
|
---parallel.waitForAll(a, b)
|
||||||
|
---print("Everything done!")
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/parallel.html#v:waitForAll)
|
||||||
|
function parallel.waitForAll(...) end
|
||||||
|
|
@ -0,0 +1,117 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---Functions for finding and controlling peripherals (such as a drive, monitor,
|
||||||
|
---or turtle) attached to this computer
|
||||||
|
---
|
||||||
|
---### Referencing Peripherals
|
||||||
|
---Computers can interact with adjacent peripherals. Each peripheral is given a
|
||||||
|
---name based on which direction it is in:\
|
||||||
|
---`"bottom"`, `"top"`, `"left"`, `"right"`, `"front"`, `"back"`
|
||||||
|
---
|
||||||
|
---It's also possible to use peripherals which are further away using modems.
|
||||||
|
---Place one modem against your computer and another modem against your
|
||||||
|
---peripheral. You can then right click the modem to use (or attach) the
|
||||||
|
---peripheral. This will print a peripheral name to chat, which can then be used
|
||||||
|
---just like a direction name to access the peripheral. You can click on the
|
||||||
|
---message to copy the name to your clipboard.
|
||||||
|
---
|
||||||
|
---### Using Peripherals
|
||||||
|
---Once you have the name of a peripheral, you can call functions on it using
|
||||||
|
---`peripheral.call()`. Once you start making a couple of peripheral
|
||||||
|
---calls this can get very repetitive, and so we can wrap a peripheral. This
|
||||||
|
---builds a table of all the peripheral's functions so you can use it like an API
|
||||||
|
---or module.
|
||||||
|
---
|
||||||
|
---### Finding Peripherals
|
||||||
|
---Sometimes you just need to know a peripheral exists. Thankfully there's
|
||||||
|
---`peripheral.find()`. This takes a peripheral type and returns all the attached
|
||||||
|
---peripherals which are of this type.
|
||||||
|
---
|
||||||
|
---What is a peripheral type though? This is a string which describes what a
|
||||||
|
---peripheral is, and so what functions are available on it. For instance,
|
||||||
|
---speakers are just called `speaker`, and monitors `monitor`. Some peripherals
|
||||||
|
---might have more than one type - a Minecraft chest is both a `minecraft:chest`
|
||||||
|
---and `inventory`. You can get all the types a peripheral has with
|
||||||
|
---`peripheral.getType()`, and check a peripheral is a specific type with
|
||||||
|
---`peripheral.hasType()`.
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/peripheral.html)
|
||||||
|
peripheral = {}
|
||||||
|
|
||||||
|
---Get a list of all available peripherals
|
||||||
|
---
|
||||||
|
---If a peripheral is attached to a side, its name will be listed as the side it
|
||||||
|
---is attached to, if it is attached remotely, it will have a unique name from
|
||||||
|
---the network it is on
|
||||||
|
---@return string[] peripherals A list of the names of all of connected peripherals
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/peripheral.html#v:getNames)
|
||||||
|
function peripheral.getNames() end
|
||||||
|
|
||||||
|
---Determines if a peripheral is present
|
||||||
|
---@param name string|ccTweaked.peripherals.computerSide The name of the device or side of the computer to check
|
||||||
|
---@return boolean isPresent If *some* peripheral is present on the specified side or with the specified name
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/peripheral.html#v:isPresent)
|
||||||
|
function peripheral.isPresent(name) end
|
||||||
|
|
||||||
|
---Get the type(s) of a peripheral
|
||||||
|
---@param peripheral string|ccTweaked.peripherals.computerSide|ccTweaked.peripherals.wrappedPeripheral The name/side or wrapped instance of a peripheral to get the type(s) of
|
||||||
|
---@return ccTweaked.peripherals.type ... The peripheral's types or `nil` if one is not present
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/peripheral.html#v:getType)
|
||||||
|
function peripheral.getType(peripheral) end
|
||||||
|
|
||||||
|
---Check that a peripheral has a given type
|
||||||
|
---@param peripheral string|ccTweaked.peripherals.computerSide|ccTweaked.peripherals.wrappedPeripheral The name/side or wrapped instance of a peripheral to check the type of
|
||||||
|
---@param peripheralType ccTweaked.peripherals.type The type to check
|
||||||
|
---@return boolean|nil hasType If the peripheral has the given type or `nil` if it is not present
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/peripheral.html#v:hasType)
|
||||||
|
function peripheral.hasType(peripheral, peripheralType) end
|
||||||
|
|
||||||
|
---Get the methods for the peripheral with a given name
|
||||||
|
---@param name string|ccTweaked.peripherals.computerSide The name/side of the peripheral to get the methods of
|
||||||
|
---@return string[]|nil methods An array of method names that are provided by the peripheral or `nil` if it is not present
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/peripheral.html#v:getMethods)
|
||||||
|
function peripheral.getMethods(name) end
|
||||||
|
|
||||||
|
---Get the name of a wrapped peripheral
|
||||||
|
---@param peripheral ccTweaked.peripherals.wrappedPeripheral The peripheral to get the name of
|
||||||
|
---@return string name The name of the peripheral
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/peripheral.html#v:getName)
|
||||||
|
function peripheral.getName(peripheral) end
|
||||||
|
|
||||||
|
---Call a method on the peripheral with the provided name
|
||||||
|
---@param name string|ccTweaked.peripherals.computerSide The peripheral to invoke the method on
|
||||||
|
---@param method string The name of the method to call
|
||||||
|
---@param ... any Args to pass to the method
|
||||||
|
---@return any ... Return values from the method
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/peripheral.html#v:call)
|
||||||
|
function peripheral.call(name, method, ...) end
|
||||||
|
|
||||||
|
---Get a table containing all methods available on a peripheral
|
||||||
|
---@param name string|ccTweaked.peripherals.computerSide The name of the peripheral to wrap
|
||||||
|
---@return ccTweaked.peripherals.wrappedPeripheral|nil wrappedPeripheral The table containing the peripheral's methods or `nil` if the peripheral does not exist
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/peripheral.html#v:wrap)
|
||||||
|
function peripheral.wrap(name) end
|
||||||
|
|
||||||
|
---Find all peripherals of a given type and return them wrapped
|
||||||
|
---@param peripheralType ccTweaked.peripherals.type The type of peripheral to find
|
||||||
|
---@param filter? fun(name: string, wrapped: ccTweaked.peripherals.wrappedPeripheral): boolean A filter function that should return if the peripheral should be included in the result
|
||||||
|
---@return ccTweaked.peripherals.wrappedPeripheral? ... The wrapped peripherals that were found, if any
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---local monitors = { peripheral.find("monitor") }
|
||||||
|
---for _, monitor in pairs(monitors) do
|
||||||
|
--- monitor.write("Hello")
|
||||||
|
---end
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/peripheral.html#v:find)
|
||||||
|
function peripheral.find(peripheralType, filter) end
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---Functions for pocket computers
|
||||||
|
---
|
||||||
|
---This API is only available on pocket computers. This allows you to check if
|
||||||
|
---the current computer is a pocket computer
|
||||||
|
---
|
||||||
|
---```
|
||||||
|
---if pocket then print("This is a pocket computer") end
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/pocket.html)
|
||||||
|
pocket = {}
|
||||||
|
|
||||||
|
---Equip an upgrade from the player's inventory, prioritizing the currently
|
||||||
|
---selected slot
|
||||||
|
---@return boolean success If an item was equipped
|
||||||
|
---@return string|nil errorMessage The reason an item was not equipped
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/pocket.html#v:equipBack)
|
||||||
|
function pocket.equipBack() end
|
||||||
|
|
||||||
|
---Remove the currently equipped upgrade
|
||||||
|
---@return boolean success If an upgrade was unequipped
|
||||||
|
---@return string errorMessage The reason why an upgrade was not unequipped
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/pocket.html#v:unequipBack)
|
||||||
|
function pocket.unequipBack() end
|
||||||
|
|
@ -0,0 +1,131 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---The rednet API provides a layer of abstraction on top of the modem peripheral
|
||||||
|
---in order to make communicating between computers easier
|
||||||
|
---
|
||||||
|
---### Basic Usage
|
||||||
|
---In order to send and receive message between two computers, they must have a
|
||||||
|
---modem attached. They can then use `rednet.open()` to start sending and
|
||||||
|
---receiving messages
|
||||||
|
---
|
||||||
|
---⚠️ Unintended computers could be listening in to messages or pretending to be
|
||||||
|
---other computers. Encrypting/signing your messages would help increase the
|
||||||
|
---security of your messages
|
||||||
|
---
|
||||||
|
---### Protocols
|
||||||
|
---Protocols provide a basic means to filter messages being sent over rednet and
|
||||||
|
---offer a basic sort of DNS that allows you to discover other computers by
|
||||||
|
---their friendly hostname
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/rednet.html)
|
||||||
|
rednet = {}
|
||||||
|
|
||||||
|
---The channel that messages will be sent on by `rednet.broadcast()`
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/rednet.html#v:CHANNEL_BROADCAST)
|
||||||
|
rednet.CHANNEL_BROADCAST = 65535
|
||||||
|
|
||||||
|
---The channel used to repeat messages
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/rednet.html#v:CHANNEL_REPEAT)
|
||||||
|
rednet.CHANNEL_REPEAT = 65535
|
||||||
|
|
||||||
|
---The highest channel reserved by rednet for computer IDs. Computers with IDs
|
||||||
|
---greater or equal to this limit will wrap back around to 0
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/rednet.html#v:MAX_ID_CHANNELS)
|
||||||
|
rednet.MAX_ID_CHANNELS = 65500
|
||||||
|
|
||||||
|
---Open a modem, allowing it to send and receive on rednet
|
||||||
|
---
|
||||||
|
---This opens two channels on the modem, one matching the ID of this computer,
|
||||||
|
---and another matching the value of `rednet.CHANNEL_BROADCAST`
|
||||||
|
---@param modem string|ccTweaked.peripherals.computerSide The name/side of the modem to open
|
||||||
|
---@throws If there is no modem with the given name
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/rednet.html#v:open)
|
||||||
|
function rednet.open(modem) end
|
||||||
|
|
||||||
|
---Close a modem, preventing it from sending or receiving on rednet
|
||||||
|
---@param modem? string|ccTweaked.peripherals.computerSide The name/side of the modem to close. If omitted, all modems will be closed
|
||||||
|
---@throws If there is no modem with the given name
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/rednet.html#v:close)
|
||||||
|
function rednet.close(modem) end
|
||||||
|
|
||||||
|
---Get whether a modem is currently open on rednet
|
||||||
|
---@param modem string|ccTweaked.peripherals.computerSide|nil The name of the modem or side of computer to check. If omitted, all connected modems will be checked (if any)
|
||||||
|
---@return boolean isOpen If the modem is open
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/rednet.html#v:isOpen)
|
||||||
|
function rednet.isOpen(modem) end
|
||||||
|
|
||||||
|
---Send a message to a target computer
|
||||||
|
---@param recipient integer The ID of the computer to send the message to
|
||||||
|
---@param message number|boolean|string|table The message to send
|
||||||
|
---@param protocol? string The protocol to send the message under
|
||||||
|
---@return boolean success If the message was sent (does not guarantee that the message was received)
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/rednet.html#v:send)
|
||||||
|
function rednet.send(recipient, message, protocol) end
|
||||||
|
|
||||||
|
---Broadcast a message over the channel defined by `rednet.CHANNEL_BROADCAST`
|
||||||
|
---
|
||||||
|
---Every device listening on rednet can receive broadcasted messages
|
||||||
|
---@param message number|boolean|string|table The message to broadcast
|
||||||
|
---@param protocol string The protocol to broadcast the message under
|
||||||
|
-------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/rednet.html#v:broadcast)
|
||||||
|
function rednet.broadcast(message, protocol) end
|
||||||
|
|
||||||
|
---Receive a message over rednet
|
||||||
|
---@param protocol? string The protocol to exclusively receive messages under
|
||||||
|
---@param timeout? number The number of seconds to wait if no message is received
|
||||||
|
---@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
|
||||||
|
---@return nil|number|boolean|string|table message The received message
|
||||||
|
---@return nil|string protocol The protocol the message was sent under
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/rednet.html#v:receive)
|
||||||
|
function rednet.receive(protocol, timeout) end
|
||||||
|
|
||||||
|
---Register this computer as hosting a specific protocol under the provided
|
||||||
|
---hostname. This allows other computers to find this one by using
|
||||||
|
---`rednet.lookup()`
|
||||||
|
---
|
||||||
|
---No two computers can share the same hostname and the hostname `localhost` is reserved. They can only share hostnames in the following scenarios:
|
||||||
|
---- They are hosting different protocols
|
||||||
|
---- They join the same network after registering
|
||||||
|
---@param protocol string The protocol this computer provides
|
||||||
|
---@param hostname string The name this computer exposes for this protocol
|
||||||
|
---@throws If the requested hostname is reserved or already in use
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/rednet.html#v:host)
|
||||||
|
function rednet.host(protocol, hostname) end
|
||||||
|
|
||||||
|
---Stop hosting a certain protocol, preventing this computer from responding to
|
||||||
|
---`rednet.lookup()` requests
|
||||||
|
---@param protocol string The protocol to unregister from
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/rednet.html#v:unhost)
|
||||||
|
function rednet.unhost(protocol) end
|
||||||
|
|
||||||
|
---Search the network for computers hosting a specific protocol
|
||||||
|
---@param protocol string The protocol to perform a lookup on
|
||||||
|
---@param hostname? string The hostname to search for
|
||||||
|
---@return number|nil ... The IDs of any computers that match the search critera
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/rednet.html#v:lookup)
|
||||||
|
function rednet.lookup(protocol, hostname) end
|
||||||
|
|
||||||
|
---Listen for modem messages and convert them into rednet messages, ready for
|
||||||
|
---receiving through `rednet.receive()`
|
||||||
|
---
|
||||||
|
---⚠️ This is called on startup and should not be called manually
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/rednet.html#v:run)
|
||||||
|
function rednet.run() end
|
||||||
|
|
@ -0,0 +1,108 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---The redstone API allows you to interact with redstone I/O in binary,
|
||||||
|
---analogue, and "bundled" mode
|
||||||
|
---
|
||||||
|
---When a redstone input changes, a `redstone` event will be fired
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/redstone.html)
|
||||||
|
redstone = {}
|
||||||
|
|
||||||
|
---Get the valid sides of this computer
|
||||||
|
---@return ccTweaked.peripherals.computerSide[] sides The sides of the computer
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/redstone.html#v:getSides)
|
||||||
|
function redstone.getSides() end
|
||||||
|
|
||||||
|
---Set the binary state of a redstone signal on a specific side of this computer
|
||||||
|
---@param side ccTweaked.peripherals.computerSide The side of the computer to set the state of
|
||||||
|
---@param state boolean If the redstone should be on, with a signal strength of 15
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/redstone.html#v:setOutput)
|
||||||
|
function redstone.setOutput(side, state) end
|
||||||
|
|
||||||
|
---Get the current redstone output state at the side of a computer
|
||||||
|
---@param side ccTweaked.peripherals.computerSide The side of the computer to check
|
||||||
|
---@return boolean state If the redstone output is on or off
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/redstone.html#v:getOutput)
|
||||||
|
function redstone.getOutput(side) end
|
||||||
|
|
||||||
|
---Get the current redstone input of a given side
|
||||||
|
---@param side ccTweaked.peripherals.computerSide The side of the computer to check
|
||||||
|
---@return boolean state Whether the redstone input is on or off
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/redstone.html#v:getInput)
|
||||||
|
function redstone.getInput(side) end
|
||||||
|
|
||||||
|
---Set the redstone signal strength for a given side
|
||||||
|
---@param side ccTweaked.peripherals.computerSide The side of the computer to set the signal strength for
|
||||||
|
---@param strength ccTweaked.redstone.signalStrength The strength of the analog output signal
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/redstone.html#v:setAnalogOutput)
|
||||||
|
function redstone.setAnalogOutput(side, strength) end
|
||||||
|
|
||||||
|
---Set the redstone signal strength for a given side
|
||||||
|
---@param side ccTweaked.peripherals.computerSide The side of the computer to set the signal strength for
|
||||||
|
---@param strength ccTweaked.redstone.signalStrength The strength of the analogue output signal
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/redstone.html#v:setAnalogueOutput)
|
||||||
|
function redstone.setAnalogueOutput(side, strength) end
|
||||||
|
|
||||||
|
---Get the redstone analog output signal strength for a given side
|
||||||
|
---@param side ccTweaked.peripherals.computerSide The side of the computer to check
|
||||||
|
---@return ccTweaked.redstone.signalStrength strength The strength of the analog output signal (0 - 15)
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/redstone.html#v:getAnalogOutput)
|
||||||
|
function redstone.getAnalogOutput(side) end
|
||||||
|
|
||||||
|
---Get the redstone analogue output signal strength for a given side
|
||||||
|
---@param side ccTweaked.peripherals.computerSide The side of the computer to check
|
||||||
|
---@return ccTweaked.redstone.signalStrength strength The strength of the analogue output signal (0 - 15)
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/redstone.html#v:getAnalogueOutput)
|
||||||
|
function redstone.getAnalogueOutput(side) end
|
||||||
|
|
||||||
|
---Get the current analog input strength for a given side
|
||||||
|
---@param side ccTweaked.peripherals.computerSide The side of the computer to check
|
||||||
|
---@return ccTweaked.redstone.signalStrength strength The strength of the analog input signal
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/redstone.html#v:getAnalogInput)
|
||||||
|
function redstone.getAnalogInput(side) end
|
||||||
|
|
||||||
|
---Get the current analogue input strength for a given side
|
||||||
|
---@param side ccTweaked.peripherals.computerSide The side of the computer to check
|
||||||
|
---@return ccTweaked.redstone.signalStrength strength The strength of the analogue input signal
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/redstone.html#v:getAnalogueInput)
|
||||||
|
function redstone.getAnalogueInput(side) end
|
||||||
|
|
||||||
|
---Set the bundled cable output for a given side
|
||||||
|
---
|
||||||
|
---🗒️ Use `colors.subtract()` and `colors.combine()` to make a color set
|
||||||
|
---@param side ccTweaked.peripherals.computerSide The side to set
|
||||||
|
---@param colorSet ccTweaked.colors.colorSet The colorSet to set for the output
|
||||||
|
function redstone.setBundledOutput(side, colorSet) end
|
||||||
|
|
||||||
|
---Get the bundled cable output for a given side
|
||||||
|
---@param side ccTweaked.peripherals.computerSide The side of the computer to check
|
||||||
|
---@return ccTweaked.colors.colorSet colorSet The bundled cable output
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/redstone.html#v:getBundledOutput)
|
||||||
|
function redstone.getBundledOutput(side) end
|
||||||
|
|
||||||
|
---Get the bundled cable input for a given side
|
||||||
|
---@param side ccTweaked.peripherals.computerSide The side of the computer to check
|
||||||
|
---@return ccTweaked.colors.colorSet colorSet The bundled cable input
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/redstone.html#v:getBundledInput)
|
||||||
|
function redstone.getBundledInput(side) end
|
||||||
|
|
||||||
|
---Test whether a bundled input is as expected
|
||||||
|
---@param side ccTweaked.peripherals.computerSide The side of the computer to check
|
||||||
|
---@param colorSet ccTweaked.colors.colorSet The input that is expected
|
||||||
|
---@return boolean success If the test is true
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/redstone.html#v:testBundledInput)
|
||||||
|
function redstone.testBundledInput(side, colorSet) end
|
||||||
|
|
@ -0,0 +1,87 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---The settings API provides a way for you to read and write settings for
|
||||||
|
---CraftOS and your programs
|
||||||
|
---
|
||||||
|
---By default, the settings API will load its configuration from the `/.settings`
|
||||||
|
---file. One can then use settings.save to update the file
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/settings.html)
|
||||||
|
settings = {}
|
||||||
|
|
||||||
|
---Define a new setting
|
||||||
|
---@param name string The name of this option
|
||||||
|
---@param options? ccTweaked.settings.settingOptions The options of this setting
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/settings.html#v:define)
|
||||||
|
function settings.define(name, options) end
|
||||||
|
|
||||||
|
---Remove a setting definition
|
||||||
|
---
|
||||||
|
---This does not remove the value of a set setting, `settings.unset()` can be
|
||||||
|
---used for that
|
||||||
|
---@param name string The name of the setting to delete
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/settings.html#v:undefine)
|
||||||
|
function settings.undefine(name) end
|
||||||
|
|
||||||
|
---Set the value of a setting
|
||||||
|
---@param name string The name of the setting to set
|
||||||
|
---@param value string|boolean|number|table The new value for the setting, cannot be nil
|
||||||
|
---@throws If the value cannot be serialized by `textutils.serialize()`
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/settings.html#v:set)
|
||||||
|
function settings.set(name, value) end
|
||||||
|
|
||||||
|
---Get the value of a setting
|
||||||
|
---@param name string The name of the setting to get
|
||||||
|
---@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
|
||||||
|
---@return any value The setting's value or the default value
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/settings.html#v:get)
|
||||||
|
function settings.get(name, default) end
|
||||||
|
|
||||||
|
---Get details on a specific setting
|
||||||
|
---@param name string The name of the setting to get
|
||||||
|
---@return ccTweaked.settings.settingDetails details The details of this setting
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/settings.html#v:getDetails)
|
||||||
|
function settings.getDetails(name) end
|
||||||
|
|
||||||
|
---Remove the value of a setting, setting it to it's default value
|
||||||
|
---
|
||||||
|
---`settings.get()` will return the default value until the setting's value is set or the computer is rebooted
|
||||||
|
---@param name string The name of the setting to unset
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/settings.html#v:unset)
|
||||||
|
function settings.unset(name) end
|
||||||
|
|
||||||
|
---Reset the value of all settings to their defaults
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/settings.html#v:clear)
|
||||||
|
function settings.clear() end
|
||||||
|
|
||||||
|
---Get the names of all currently defined settings
|
||||||
|
---@return string[] settings An alphabetically sorted array of all currently defined settings
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/settings.html#v:getNames)
|
||||||
|
function settings.getNames() end
|
||||||
|
|
||||||
|
---Load settings from a file
|
||||||
|
---
|
||||||
|
---The two configurations will be merged where conflicting entries will be
|
||||||
|
---overwritten by this new file
|
||||||
|
---@param path? string The path to load the settings from (defaults to `.settings`)
|
||||||
|
---@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
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/settings.html#v:load)
|
||||||
|
function settings.load(path) end
|
||||||
|
|
||||||
|
---Save settings to a file
|
||||||
|
---
|
||||||
|
---This will completely overwrite the target file
|
||||||
|
---@param path? string The path to save the file to (defaults to `.settings`)
|
||||||
|
---@return boolean success If the settings were successfully saved
|
||||||
|
function settings.save(path) end
|
||||||
|
|
@ -0,0 +1,200 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---The shell API provides access to CraftOS's command line interface (CLI)
|
||||||
|
---
|
||||||
|
---The shell is not a "true" API. It is actually a program which injects it's
|
||||||
|
---API into the programs that it launches. This allows multiple shells to run at
|
||||||
|
---the same time but means that it isn't available in the global environment,
|
||||||
|
---meaning it is unavailable to other APIs
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/shell.html)
|
||||||
|
---@class ccTweaked.shell
|
||||||
|
shell = {}
|
||||||
|
|
||||||
|
---Run a program with the provided arguments
|
||||||
|
---
|
||||||
|
---Unlike `shell.run()`, each argument is passed to the program as-is.
|
||||||
|
---
|
||||||
|
---`shell.run("echo", "a b c")` will run echo with the arguments `a`, `b`, and
|
||||||
|
---`c`. `shell.execute("echo", "a b c")` will run echo with the argument "a b c"
|
||||||
|
---@param command string The program to execute
|
||||||
|
---@param ... string Arguments to this program
|
||||||
|
---@return boolean success Whether the program exited successfully
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/shell.html#v:execute)
|
||||||
|
function shell.execute(command, ...) end
|
||||||
|
|
||||||
|
---Run a command with the provided arguments as if it were called from the command line
|
||||||
|
---@param command string The program to execute
|
||||||
|
---@param ... string Arguments to concatenate and pass to the program as a command line input
|
||||||
|
---@return boolean success Whether the program exited successfully
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/shell.html#v:run)
|
||||||
|
function shell.run(command, ...) end
|
||||||
|
|
||||||
|
---Exit the current shell
|
||||||
|
---
|
||||||
|
---This will not terminate your running program, however, it will terminate the shell when the program exits
|
||||||
|
---
|
||||||
|
---If this is called on the top-level shell, the computer will shutdown
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/shell.html#v:exit)
|
||||||
|
function shell.exit() end
|
||||||
|
|
||||||
|
---Get the current working directory
|
||||||
|
---@return string path The current working directory
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/shell.html#v:dir)
|
||||||
|
function shell.dir() end
|
||||||
|
|
||||||
|
---Set the current working directory
|
||||||
|
---@param dir string The path to the current working directory
|
||||||
|
---@throws If the path does not exist
|
||||||
|
---@throws If the path is not a directory
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/shell.html#v:setDir)
|
||||||
|
function shell.setDir(dir) end
|
||||||
|
|
||||||
|
---Get the path where programs are located
|
||||||
|
---
|
||||||
|
---The path is a list of diretories separated by a colon (`:`)
|
||||||
|
---
|
||||||
|
---For example, turtles will look in:
|
||||||
|
---- `/rom/programs`
|
||||||
|
---- `/rom/programs/turtle/`
|
||||||
|
---@return string path The current path to programs
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/shell.html#v:path)
|
||||||
|
function shell.path() end
|
||||||
|
|
||||||
|
---Set the path where programs are located
|
||||||
|
---
|
||||||
|
---The path is a list of diretories separated by a colon (`:`)
|
||||||
|
---
|
||||||
|
---Make sure paths start with a `/` otherwise they will be searched for from the
|
||||||
|
---current working directory rather than the root of this computer
|
||||||
|
---@param path string The path where programs are located
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/shell.html#v:setPath)
|
||||||
|
function shell.setPath(path) end
|
||||||
|
|
||||||
|
---Resolve a relative path to an absolute path
|
||||||
|
---
|
||||||
|
---Many APIs only take absolute paths so this function will help convert to them
|
||||||
|
---
|
||||||
|
---This does nothing if the path starts with `/`
|
||||||
|
---@param path string The relative path to resolve
|
||||||
|
---@return string absolutePath The path converted to an absolute path
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/shell.html#v:resolve)
|
||||||
|
function shell.resolve(path) end
|
||||||
|
|
||||||
|
---Resolve a program, searching through the program `path` and list of `aliases`
|
||||||
|
---@param command string The name of the program
|
||||||
|
---@return string|nil absolutePath The absolute path to the program or `nil` if it could not be found
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---shell.resolveProgram("hello")
|
||||||
|
----- => rom/programs/fun/hello.lua
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/shell.html#v:resolveProgram)
|
||||||
|
function shell.resolveProgram(command) end
|
||||||
|
|
||||||
|
---Get a list of all programs at `path`
|
||||||
|
---@param includeHidden? boolean If hidden files should be included (those that start with `.`)
|
||||||
|
---@return string[] programs A list of available programs
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/shell.html#v:programs)
|
||||||
|
function shell.programs(includeHidden) end
|
||||||
|
|
||||||
|
---Complete an incomplete shell command line
|
||||||
|
---
|
||||||
|
---Completion handlers for your program can be registered with `shell.setCompletionFunction()`
|
||||||
|
---@param command string The input to complete
|
||||||
|
---@return string[]|nil completions An array of possible completions or `nil` if there are none
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/shell.html#v:complete)
|
||||||
|
function shell.complete(command) end
|
||||||
|
|
||||||
|
---Complete the name of a program
|
||||||
|
---@param program string The name of the program to complete
|
||||||
|
---@return string[] completions An array of possible completions
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/shell.html#v:completeProgram)
|
||||||
|
function shell.completeProgram(program) end
|
||||||
|
|
||||||
|
---Set the completion function for a specific program
|
||||||
|
---
|
||||||
|
---When the given program is entered on the command line, the provided function
|
||||||
|
---will be called to provide completions
|
||||||
|
---
|
||||||
|
---For instance, when completing `pastebin put rom/st` our pastebin completion
|
||||||
|
---function will receive the shell API, an index of `2`, `rom/st` as the current
|
||||||
|
---argument, and a "previous" table of `{ "put" }`. This function may then wish to
|
||||||
|
---return a table containing `artup.lua`, indicating the entire command should be
|
||||||
|
---completed to `pastebin put rom/startup.lua`.
|
||||||
|
---
|
||||||
|
---You can also return a space at the end of an argument to help indicate that
|
||||||
|
---another argument is desired
|
||||||
|
---@param program string The absolute path to the program without a leading `/`
|
||||||
|
---@param complete ccTweaked.shell.completionFunction The function to use for completions
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/shell.html#v:setCompletionFunction)
|
||||||
|
function shell.setCompletionFunction(program, complete) end
|
||||||
|
|
||||||
|
---Get a list of all completion functions
|
||||||
|
---
|
||||||
|
---This should only be needed when creating a custom shell
|
||||||
|
---
|
||||||
|
---@return ccTweaked.shell.completionInfo
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/shell.html#v:getCompletionInfo)
|
||||||
|
function shell.getCompletionInfo() end
|
||||||
|
|
||||||
|
---Get the path of the currently running program
|
||||||
|
---@return string path The path to the currently running program
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/shell.html#v:getRunningProgram)
|
||||||
|
function shell.getRunningProgram() end
|
||||||
|
|
||||||
|
---Add an alias for a program
|
||||||
|
---@param alias string The alias to add
|
||||||
|
---@param program string|string The name/path of the program to alias
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/shell.html#v:setAlias)
|
||||||
|
function shell.setAlias(alias, program) end
|
||||||
|
|
||||||
|
---Remove an alias for a program
|
||||||
|
---@param alias string The alias to remove
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/shell.html#v:clearAlias)
|
||||||
|
function shell.clearAlias(alias) end
|
||||||
|
|
||||||
|
---Get a list of all aliases for this shell
|
||||||
|
---@return table<string, string> aliases A table where the keys are the aliases and the values are the paths to the program being aliased
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/shell.html#v:aliases)
|
||||||
|
function shell.aliases() end
|
||||||
|
|
||||||
|
---Open a new multishell tab
|
||||||
|
---
|
||||||
|
---This function is only available if the `multishell` API is
|
||||||
|
---@param ... string The command line to run
|
||||||
|
---@return ccTweaked.multishell.PID PID The ID of the process that was started
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---local id = shell.openTab("lua")
|
||||||
|
---shell.switchTab(id)
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/shell.html#v:openTab)
|
||||||
|
function shell.openTab(...) end
|
||||||
|
|
||||||
|
---Switch to a different `multishell` tab
|
||||||
|
---@param PID ccTweaked.multishell.PID The ID of the process to switch to
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/shell.html#v:switchTab)
|
||||||
|
function shell.switchTab(PID) end
|
||||||
|
|
@ -0,0 +1,56 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---Interact with a computer's terminal or monitors
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html)
|
||||||
|
---@class term: ccTweaked.term.Redirect
|
||||||
|
term = {}
|
||||||
|
|
||||||
|
---Get the default colour value for a colour from the palette
|
||||||
|
---@param colour ccTweaked.colors.color The colour to get the default value for
|
||||||
|
---@return number r The red channel (0 - 1)
|
||||||
|
---@return number g The green channel (0 - 1)
|
||||||
|
---@return number b The blue channel (0 - 1)
|
||||||
|
---@throws If an invalid colour is given
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html#v:nativePaletteColour)
|
||||||
|
function term.nativePaletteColour(colour) end
|
||||||
|
|
||||||
|
---Get the default color value for a color from the palette
|
||||||
|
---@param color ccTweaked.colors.color The color to get the default value for
|
||||||
|
---@return number r The red channel (0 - 1)
|
||||||
|
---@return number g The green channel (0 - 1)
|
||||||
|
---@return number b The blue channel (0 - 1)
|
||||||
|
---@throws If an invalid color is given
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html#v:nativePaletteColor)
|
||||||
|
function term.nativePaletteColor(color) end
|
||||||
|
|
||||||
|
---Redirect the terminal output to a monitor, window, or any other custom
|
||||||
|
---terminal object. Once called, any calls to the `term` API will instead operate
|
||||||
|
---on the new terminal object
|
||||||
|
---@param target ccTweaked.term.Redirect The terminal object the `term` API will draw to
|
||||||
|
---@return ccTweaked.term.Redirect previous The previous terminal object that was being drawn to
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---term.redirect(peripheral.find("monitor"))
|
||||||
|
---print("Hello monitor!")
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html#v:redirect)
|
||||||
|
function term.redirect(target) end
|
||||||
|
|
||||||
|
---Get the current terminal object that the `term` API is drawing to
|
||||||
|
---@return ccTweaked.term.Redirect current The current terminal object
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html#v:current)
|
||||||
|
function term.current() end
|
||||||
|
|
||||||
|
---Get the native terminal object
|
||||||
|
---
|
||||||
|
---⚠️ It is recommended that you don't use this function unless you absolutely
|
||||||
|
---have to. In a multitask environment, `term.native()` will not be the current
|
||||||
|
---terminal object and so drawing may interfere with other programs
|
||||||
|
---@return ccTweaked.term.Redirect native The native terminal redirect
|
||||||
|
function term.native() end
|
||||||
|
|
@ -0,0 +1,196 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---Utilities for formatting and manipulating strings
|
||||||
|
textutils = {}
|
||||||
|
|
||||||
|
---Write text character-by-character at the cursor position
|
||||||
|
---
|
||||||
|
---Like `_G.write()`, this function does not append a newline
|
||||||
|
---@param text string The text to write to the screen
|
||||||
|
---@param rate? number The number of characters to write per second (defaults to 20)
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/textutils.html#v:slowWrite)
|
||||||
|
function textutils.slowWrite(text, rate) end
|
||||||
|
|
||||||
|
---Print text character-by-character at the cursor position
|
||||||
|
---
|
||||||
|
---Like `_G.print()`, this function appends a newline
|
||||||
|
---@param text string The text to print to the screen
|
||||||
|
---@param rate? number The number of characters to write per second (defaults to 20)
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/textutils.html#v:slowPrint)
|
||||||
|
function textutils.slowPrint(text, rate) end
|
||||||
|
|
||||||
|
---Formats a time value into a readable string
|
||||||
|
---@param time number The time to format, as provided by `os.time()`
|
||||||
|
---@param twentyFourHr boolean Whether to use 24 hour time or 12 hour time
|
||||||
|
---@return string formattedTime The time formatted as a string
|
||||||
|
function textutils.formatTime(time, twentyFourHr) end
|
||||||
|
|
||||||
|
---Print text to the screen
|
||||||
|
---
|
||||||
|
---Should the text not all fit on the screen, a "Press any key to continue"
|
||||||
|
---prompt will appear. Each keypress will scroll one line
|
||||||
|
---@param text string The text to print to the screen
|
||||||
|
---@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
|
||||||
|
---@return integer linesPrinted The number of lines that were printed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/textutils.html#v:pagedPrint)
|
||||||
|
function textutils.pagedPrint(text, leadingLines) end
|
||||||
|
|
||||||
|
---Print tables in a structured form
|
||||||
|
---
|
||||||
|
---This accepts multiple arguments. When encountering a table, it is treated as
|
||||||
|
---a row with column widths being auto adjusted. When encountering a number, this
|
||||||
|
---sets the text color for subsequent rows
|
||||||
|
---@param ... table|number The rows and text colors to display
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---textutils.tabulate(
|
||||||
|
--- colors.orange, { "1", "2", "3" },
|
||||||
|
--- colors.lightBlue, { "A", "B", "C" }
|
||||||
|
---)
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/textutils.html#v:tabulate)
|
||||||
|
function textutils.tabulate(...) end
|
||||||
|
|
||||||
|
---Print tables in a structured form, stopping and prompting for input should
|
||||||
|
---the result not fit on the screen
|
||||||
|
---
|
||||||
|
---This accepts multiple arguments. When encountering a table, it is treated as
|
||||||
|
---a row with column widths being auto adjusted. When encountering a number, this
|
||||||
|
---sets the text color for subsequent rows
|
||||||
|
---@param ... table|number The rows and text colors to display
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/textutils.html#v:pagedTabulate)
|
||||||
|
function textutils.pagedTabulate(...) end
|
||||||
|
|
||||||
|
---A table representing an empty JSON array
|
||||||
|
---
|
||||||
|
---Useful to help distinguish it from an empty JSON object
|
||||||
|
---
|
||||||
|
---⚠️ This should not be modified
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/textutils.html#v:empty_json_array)
|
||||||
|
textutils.empty_json_array = {
|
||||||
|
__tostring = function()
|
||||||
|
return "[]"
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
|
||||||
|
---A table representing the JSON null value
|
||||||
|
---
|
||||||
|
---⚠️ This should not be modified
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/textutils.html#v:json_null)
|
||||||
|
textutils.json_null = {
|
||||||
|
__tostring = function()
|
||||||
|
return "null"
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
|
||||||
|
---Get a textual representation of a Lua table, suitable for saving to a file or
|
||||||
|
---printing
|
||||||
|
---@param tbl table The table to convert
|
||||||
|
---@param options? ccTweaked.textutils.serializationOptions
|
||||||
|
---@return string serialized The serialized representation
|
||||||
|
---@throws If the table contains a function
|
||||||
|
---@throws If the table contains tables that appear multiple times
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/textutils.html#v:serialize)
|
||||||
|
function textutils.serialize(tbl, options) end
|
||||||
|
|
||||||
|
---Get a textual representation of a Lua table, suitable for saving to a file or
|
||||||
|
---printing
|
||||||
|
---@param t table The table to convert
|
||||||
|
---@param options? ccTweaked.textutils.serializationOptions
|
||||||
|
---@return string serialised The serialised representation
|
||||||
|
---@throws If the table contains a function
|
||||||
|
---@throws If the table contains tables that appear multiple times
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/textutils.html#v:serialise)
|
||||||
|
function textutils.serialise(t, options) end
|
||||||
|
|
||||||
|
---Convert a serialized string back into a Lua table
|
||||||
|
---@param str string The text to turn back into a table
|
||||||
|
---@return table|nil tbl The unserialized table or `nil` if the table couldn't be unserialized
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/textutils.html#v:unserialize)
|
||||||
|
function textutils.unserialize(str) end
|
||||||
|
|
||||||
|
---Convert a serialised string back into a Lua table
|
||||||
|
---@param str string The text to turn back into a table
|
||||||
|
---@return table|nil tbl The unserialised table or `nil` if the table couldn't be unserialised
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/textutils.html#v:unserialise)
|
||||||
|
function textutils.unserialise(str) end
|
||||||
|
|
||||||
|
---Get a JSON representation of the given value
|
||||||
|
---
|
||||||
|
---This function attempts to guess whether a table is a JSON array or object.
|
||||||
|
---However, empty tables are assumed to be empty objects - use
|
||||||
|
---`textutils.empty_json_array` to mark an empty array.
|
||||||
|
---
|
||||||
|
---This is largely intended for interacting with various functions from the
|
||||||
|
---commands API, though may also be used in making http requests.
|
||||||
|
---@param tbl string|boolean|number|table The value to serialize
|
||||||
|
---@param NBTstyle? boolean If [NBT style](https://minecraft.fandom.com/wiki/NBT_format) JSON (non-quoted keys) should be output
|
||||||
|
---@return string JSON The JSON output
|
||||||
|
---@throws If the `value` contains a function
|
||||||
|
---@throws If the `value` contains tables that appear multiple times
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/textutils.html#v:serializeJSON)
|
||||||
|
function textutils.serializeJSON(tbl, NBTstyle) end
|
||||||
|
|
||||||
|
---Get a JSON representation of the given value
|
||||||
|
---
|
||||||
|
---This function attempts to guess whether a table is a JSON array or object.
|
||||||
|
---However, empty tables are assumed to be empty objects - use
|
||||||
|
---`textutils.empty_json_array` to mark an empty array.
|
||||||
|
---
|
||||||
|
---This is largely intended for interacting with various functions from the
|
||||||
|
---commands API, though may also be used in making http requests.
|
||||||
|
---@param tbl table The value to serialise
|
||||||
|
---@param NBTstyle? boolean If [NBT style](https://minecraft.fandom.com/wiki/NBT_format) JSON (non-quoted keys) should be output
|
||||||
|
---@return string JSON The JSON output
|
||||||
|
---@throws If `t` contains a function
|
||||||
|
---@throws If `t` contains tables that appear multiple times
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/textutils.html#v:serialiseJSON)
|
||||||
|
function textutils.serialiseJSON(tbl, NBTstyle) end
|
||||||
|
|
||||||
|
---Convert a serialized JSON string back into a Lua table
|
||||||
|
---@param str string The string to unserialize
|
||||||
|
---@param options? ccTweaked.textutils.unserializeJSONOptions Options for unserializing
|
||||||
|
---@return table|nil unserialized The unserialized object or `nil` if the object couldn't be unserialized
|
||||||
|
---@return string|nil errorMessage Why the object couldn't be unserialized
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/textutils.html#v:unserializeJSON)
|
||||||
|
function textutils.unserializeJSON(str, options) end
|
||||||
|
|
||||||
|
---Convert a serialised JSON string back into a Lua table
|
||||||
|
---@param str string The string to unserialise
|
||||||
|
---@param options? ccTweaked.textutils.unserializeJSONOptions Options for unserialising
|
||||||
|
---@return table|nil unserialised The unserialised object or `nil` if the object couldn't be unserialised
|
||||||
|
---@return string|nil errorMessage Why the object couldn't be unserialised
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/textutils.html#v:unserialiseJSON)
|
||||||
|
function textutils.unserialiseJSON(str, options) end
|
||||||
|
|
||||||
|
---Encode a string to make it safe to use as a URL
|
||||||
|
---@param str string The string to encode
|
||||||
|
---@return string url The encoded url
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/textutils.html#v:urlEncode)
|
||||||
|
function textutils.urlEncode(str) end
|
||||||
|
|
||||||
|
---Get completions for Lua expressions
|
||||||
|
---@param searchText string The text to complete
|
||||||
|
---@param searchTable? table A table to find variables in, defaulting to `_G`. It will also search through a parent metatable using the `__index` metamethod
|
||||||
|
---@return string[] completions A possibly empty array of completions
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/textutils.html#v:complete)
|
||||||
|
function textutils.complete(searchText, searchTable) end
|
||||||
|
|
@ -0,0 +1,414 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---Turtles are a robot that can break/place blocks, attack mobs, and move around
|
||||||
|
---the world. They have an inventory of 16 slots, allowing them to store blocks
|
||||||
|
---they have broken or would like to place.
|
||||||
|
---
|
||||||
|
---### Moving a turtle
|
||||||
|
---Turtles are blocks and can therefor move around the world on Minecraft's
|
||||||
|
---grid, one block at a time. Moving a turtle (but not turning it) consumes fuel.
|
||||||
|
---If a turtle does not have fuel, it will refuse to move and the movement
|
||||||
|
---functions will return `false`. To prevent a runaway turtle, it is recommended
|
||||||
|
---to wrap your movement functions with `assert()` to throw a fatal error, if
|
||||||
|
---you don't want to handle errors in a different way, like so:
|
||||||
|
---
|
||||||
|
---```
|
||||||
|
---assert(turtle.forward())
|
||||||
|
---```
|
||||||
|
---
|
||||||
|
---### Upgrades
|
||||||
|
---A base turtle can move around and place blocks, however, through upgrades,
|
||||||
|
---they can do even more such as mine, dig, till, attack, and more. Turtles have
|
||||||
|
---a slot on their left and right sides where you can equip tools (sword,
|
||||||
|
---pickaxe, hoe, etc.) or peripherals (modem, speaker)
|
||||||
|
turtle = {}
|
||||||
|
|
||||||
|
---Move the turtle forward one block
|
||||||
|
---@return boolean success If the turtle could move
|
||||||
|
---@return string|nil errorMessage Why the turtle couldn't move
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:forward)
|
||||||
|
function turtle.forward() end
|
||||||
|
|
||||||
|
---Move the turtle back one block
|
||||||
|
---@return boolean success If the turtle could move
|
||||||
|
---@return string|nil errorMessage Why the turtle couldn't move
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:back)
|
||||||
|
function turtle.back() end
|
||||||
|
|
||||||
|
---Move the turtle up one block
|
||||||
|
---@return boolean success If the turtle could move
|
||||||
|
---@return string|nil errorMessage Why the turtle couldn't move
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:up)
|
||||||
|
function turtle.up() end
|
||||||
|
|
||||||
|
---Move the turtle down one block
|
||||||
|
---@return boolean success If the turtle could move
|
||||||
|
---@return string|nil errorMessage Why the turtle couldn't move
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:down)
|
||||||
|
function turtle.down() end
|
||||||
|
|
||||||
|
---Rotate the turtle 90 degrees to the left
|
||||||
|
---@return boolean success If the turtle could turn
|
||||||
|
---@return string|nil errorMessage Why the turtle couldn't turn
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:turnLeft)
|
||||||
|
function turtle.turnLeft() end
|
||||||
|
|
||||||
|
---Rotate the turtle 90 degrees to the right
|
||||||
|
---@return boolean success If the turtle could turn
|
||||||
|
---@return string|nil errorMessage Why the turtle couldn't turn
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:turnRight)
|
||||||
|
function turtle.turnRight() end
|
||||||
|
|
||||||
|
---Attempt to break the block in front of the turtle
|
||||||
|
---
|
||||||
|
---This requires a tool capable of breaking the block. Diamond pickaxes can
|
||||||
|
---break any block but other tools are more limited
|
||||||
|
---@param side? ccTweaked.turtle.side The specific tool to use
|
||||||
|
---@return boolean success If a block was broken
|
||||||
|
---@return string|nil errorMessage The reason no block was broken
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:dig)
|
||||||
|
function turtle.dig(side) end
|
||||||
|
|
||||||
|
---Attempt to break the block above the turtle
|
||||||
|
---
|
||||||
|
---This requires a tool capable of breaking the block. Diamond pickaxes can
|
||||||
|
---break any block but other tools are more limited
|
||||||
|
---@param side? ccTweaked.turtle.side The specific tool to use
|
||||||
|
---@return boolean success If a block was broken
|
||||||
|
---@return string|nil errorMessage The reason no block was broken
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:digUp)
|
||||||
|
function turtle.digUp(side) end
|
||||||
|
|
||||||
|
---Attempt to break the block below the turtle
|
||||||
|
---
|
||||||
|
---This requires a tool capable of breaking the block. Diamond pickaxes can
|
||||||
|
---break any block but other tools are more limited
|
||||||
|
---@param side? ccTweaked.turtle.side The specific tool to use
|
||||||
|
---@return boolean success If a block was broken
|
||||||
|
---@return string|nil errorMessage The reason no block was broken
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:digDown)
|
||||||
|
function turtle.digDown(side) end
|
||||||
|
|
||||||
|
---Place a block or item in front of the turtle
|
||||||
|
---
|
||||||
|
---This also allows buckets to pick up or place liquids and wheat to breed cows.
|
||||||
|
---It cannot, however, be used to trigger buttons or levers
|
||||||
|
---@param text? string When placing a sign, set it's contents to this text
|
||||||
|
---@return boolean success If a block was placed
|
||||||
|
---@return string|nil errorMessage The reason the block could not be placed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:place)
|
||||||
|
function turtle.place(text) end
|
||||||
|
|
||||||
|
---Place a block or item above the turtle
|
||||||
|
---
|
||||||
|
---This also allows buckets to pick up or place liquids and wheat to breed cows.
|
||||||
|
---It cannot, however, be used to trigger buttons or levers
|
||||||
|
---@param text? string When placing a sign, set it's contents to this text
|
||||||
|
---@return boolean success If a block was placed
|
||||||
|
---@return string|nil errorMessage The reason the block could not be placed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:placeUp)
|
||||||
|
function turtle.placeUp(text) end
|
||||||
|
|
||||||
|
---Place a block or item below the turtle
|
||||||
|
---
|
||||||
|
---This also allows buckets to pick up or place liquids and wheat to breed cows.
|
||||||
|
---It cannot, however, be used to trigger buttons or levers
|
||||||
|
---@param text? string When placing a sign, set it's contents to this text
|
||||||
|
---@return boolean success If a block was placed
|
||||||
|
---@return string|nil errorMessage The reason the block could not be placed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:placeDown)
|
||||||
|
function turtle.placeDown(text) end
|
||||||
|
|
||||||
|
---Drop the contents of the currently selected slot into the inventory in front
|
||||||
|
---of the turtle or into the world if there is no inventory
|
||||||
|
---@param count? integer The number of items to drop. If omitted, the entire stack will be dropped
|
||||||
|
---@return boolean success If items were dropped
|
||||||
|
---@return string errorMessage The reason items weren't dropped
|
||||||
|
---@throws If dropping an invalid number of items
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:drop)
|
||||||
|
function turtle.drop(count) end
|
||||||
|
|
||||||
|
---Drop the contents of the currently selected slot into the inventory above
|
||||||
|
---the turtle or into the world if there is no inventory
|
||||||
|
---@param count? integer The number of items to drop. If omitted, the entire stack will be dropped
|
||||||
|
---@return boolean success If items were dropped
|
||||||
|
---@return string errorMessage The reason items weren't dropped
|
||||||
|
---@throws If dropping an invalid number of items
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:dropUp)
|
||||||
|
function turtle.dropUp(count) end
|
||||||
|
|
||||||
|
---Drop the contents of the currently selected slot into the inventory below
|
||||||
|
---the turtle or into the world if there is no inventory
|
||||||
|
---@param count? integer The number of items to drop. If omitted, the entire stack will be dropped
|
||||||
|
---@return boolean success If items were dropped
|
||||||
|
---@return string errorMessage The reason items weren't dropped
|
||||||
|
---@throws If dropping an invalid number of items
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:dropDown)
|
||||||
|
function turtle.dropDown(count) end
|
||||||
|
|
||||||
|
---Change the currently selected inventory slot
|
||||||
|
---
|
||||||
|
---This determines what slot `turtle.drop()`, `turtle.place()`, and others act
|
||||||
|
---on
|
||||||
|
---@param slot ccTweaked.turtle.slot The inventory slot to select
|
||||||
|
---@return boolean success If the slot has been selected (1 - 16)
|
||||||
|
---@throws If `slot` is out of range
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:select)
|
||||||
|
function turtle.select(slot) end
|
||||||
|
|
||||||
|
---Get the number of items in the given slot
|
||||||
|
---@param slot? ccTweaked.turtle.slot The slot to check (1 - 16, default is the selected slot)
|
||||||
|
---@return integer count The number of items in the slot
|
||||||
|
---@throws If `slot` is out of range
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:getItemCount)
|
||||||
|
function turtle.getItemCount(slot) end
|
||||||
|
|
||||||
|
---Get the remaining space in a stack in a slot
|
||||||
|
---@param slot? ccTweaked.turtle.slot The slot to check (1 - 16, default is the selected slot)
|
||||||
|
---@return integer count The number of items that can fit in this stack
|
||||||
|
---@throws If `slot` is out of range
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:getItemSpace)
|
||||||
|
function turtle.getItemSpace(slot) end
|
||||||
|
|
||||||
|
---Check if there is a solid (non-air, non-liquid) block in front of the turtle
|
||||||
|
---@return boolean detected If there is a block in front
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:detect)
|
||||||
|
function turtle.detect() end
|
||||||
|
|
||||||
|
---Check if there is a solid (non-air, non-liquid) block above the turtle
|
||||||
|
---@return boolean detected If there is a block above
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:detectUp)
|
||||||
|
function turtle.detectUp() end
|
||||||
|
|
||||||
|
---Check if there is a solid (non-air, non-liquid) block below the turtle
|
||||||
|
---@return boolean detected If there is a block below
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:detectDown)
|
||||||
|
function turtle.detectDown() end
|
||||||
|
|
||||||
|
---Check if the block in front of the turtle is the same as the item in the
|
||||||
|
---currently selected slot
|
||||||
|
---@return boolean areSame If the block and the item are the same
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:compare)
|
||||||
|
function turtle.compare() end
|
||||||
|
|
||||||
|
---Check if the block above the turtle is the same as the item in the
|
||||||
|
---currently selected slot
|
||||||
|
---@return boolean areSame If the block and the item are the same
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:compareUp)
|
||||||
|
function turtle.compareUp() end
|
||||||
|
|
||||||
|
---Check if the block below the turtle is the same as the item in the
|
||||||
|
---currently selected slot
|
||||||
|
---@return boolean areSame If the block and the item are the same
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:compareDown)
|
||||||
|
function turtle.compareDown() end
|
||||||
|
|
||||||
|
---Attack the entity in front of the turtle
|
||||||
|
---@param side? ccTweaked.turtle.side The specific tool to use to attack
|
||||||
|
---@return boolean attacked Whether an entity was attacked
|
||||||
|
---@return string|nil errorMessage The reason nothing was attacked
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:attack)
|
||||||
|
function turtle.attack(side) end
|
||||||
|
|
||||||
|
---Attack the entity above the turtle
|
||||||
|
---@param side? ccTweaked.turtle.side The specific tool to use to attack
|
||||||
|
---@return boolean attacked Whether an entity was attacked
|
||||||
|
---@return string|nil errorMessage The reason nothing was attacked
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:attackUp)
|
||||||
|
function turtle.attackUp(side) end
|
||||||
|
|
||||||
|
---Attack the entity below the turtle
|
||||||
|
---@param side? ccTweaked.turtle.side The specific tool to use to attack
|
||||||
|
---@return boolean attacked Whether an entity was attacked
|
||||||
|
---@return string|nil errorMessage The reason nothing was attacked
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:attackDown)
|
||||||
|
function turtle.attackDown(side) end
|
||||||
|
|
||||||
|
---Suck an item from the inventory in front of the turtle or from the world if there is no inventory
|
||||||
|
---
|
||||||
|
---This will pull the item into the first acceptable slot, starting with the currently selected one
|
||||||
|
---@param count? integer The number of items to suck up (default is up to a stack of items)
|
||||||
|
---@return boolean success If any items were picked up
|
||||||
|
---@return string|nil errorMessage The reason why nothing was picked up
|
||||||
|
---@throws If given an invalid `count`
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:suck)
|
||||||
|
function turtle.suck(count) end
|
||||||
|
|
||||||
|
---Suck an item from the inventory above the turtle or from the world if there is no inventory
|
||||||
|
---
|
||||||
|
---This will pull the item into the first acceptable slot, starting with the currently selected one
|
||||||
|
---@param count? integer The number of items to suck up (default is up to a stack of items)
|
||||||
|
---@return boolean success If any items were picked up
|
||||||
|
---@return string|nil errorMessage The reason why nothing was picked up
|
||||||
|
---@throws If given an invalid `count`
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:suckUp)
|
||||||
|
function turtle.suckUp(count) end
|
||||||
|
|
||||||
|
---Suck an item from the inventory below the turtle or from the world if there is no inventory
|
||||||
|
---
|
||||||
|
---This will pull the item into the first acceptable slot, starting with the currently selected one
|
||||||
|
---@param count? integer The number of items to suck up (default is up to a stack of items)
|
||||||
|
---@return boolean success If any items were picked up
|
||||||
|
---@return string|nil errorMessage The reason why nothing was picked up
|
||||||
|
---@throws If given an invalid `count`
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:suckDown)
|
||||||
|
function turtle.suckDown(count) end
|
||||||
|
|
||||||
|
---Get the amount of fuel this turtle has
|
||||||
|
---@return number|"unlimited" amount The current fuel level or `"unlimited"` if the config has disabled turtle fuel consumption when moving
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:getFuelLevel)
|
||||||
|
function turtle.getFuelLevel() end
|
||||||
|
|
||||||
|
---Refuel this turtle using the item in the currently selected slot
|
||||||
|
---
|
||||||
|
---Refueling will continue until the turtle is full or all items have been
|
||||||
|
---consumed
|
||||||
|
---
|
||||||
|
---Passing `0` can be used to test if the currently selected item is combustable as it will return `false`
|
||||||
|
---@param count? integer The maximum number of items to consume
|
||||||
|
---@return boolean success If the turtle was refuelled
|
||||||
|
---@return string|nil errorMessage The reason the turtle was not refuelled
|
||||||
|
---@throws If `count` is out of range
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:refuel)
|
||||||
|
function turtle.refuel(count) end
|
||||||
|
|
||||||
|
---Compare the item in the currently selected slot to an item in another slot
|
||||||
|
---@param slot ccTweaked.turtle.slot The slot to compare to
|
||||||
|
---@return boolean areSame If the two items are the same
|
||||||
|
---@throws If the slot is out of range
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:compareTo)
|
||||||
|
function turtle.compareTo(slot) end
|
||||||
|
|
||||||
|
---Move an item from the selected slot to another one
|
||||||
|
---@param slot ccTweaked.turtle.slot The slot to move the item to
|
||||||
|
---@param count? integer The maximum number of items in the stack to move
|
||||||
|
---@return boolean success If an item was successfully moved
|
||||||
|
---@throws If the slot is out of range
|
||||||
|
---@throws If `count` is out of range
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:transferTo)
|
||||||
|
function turtle.transferTo(slot, count) end
|
||||||
|
|
||||||
|
---Get the currently selected slot
|
||||||
|
---@return integer slot The currently selected slot
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:getSelectedSlot)
|
||||||
|
function turtle.getSelectedSlot() end
|
||||||
|
|
||||||
|
---Get the maximum amount of fuel that this turtle can hold
|
||||||
|
---
|
||||||
|
---By default normal turtles have a limit of 20,000 and
|
||||||
|
---advanced turtles have a limit of 100,000
|
||||||
|
---@return integer|"unlimited" limit The maximum amount of fuel this turtle can hold or `"unlimited"` if the config has disabled turtle fuel consumption
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:getFuelLimit)
|
||||||
|
function turtle.getFuelLimit() end
|
||||||
|
|
||||||
|
---Equip/Unequip an item on the left side of this turtle
|
||||||
|
---
|
||||||
|
---This attempts to equip the item in currently selected slot. The current
|
||||||
|
---equipment is removed and placed in the turtle's inventory. If there is no item
|
||||||
|
---in the currently selected slot, the current upgrade is removed but no new one
|
||||||
|
---is equipped, effectively unequipping the turtle
|
||||||
|
---@return boolean success If the item was equipped
|
||||||
|
---@return string|nil errorMessage The reason equipping failed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:equipLeft)
|
||||||
|
function turtle.equipLeft() end
|
||||||
|
|
||||||
|
---Equip/Unequip an item on the right side of this turtle
|
||||||
|
---
|
||||||
|
---This attempts to equip the item in currently selected slot. The current
|
||||||
|
---equipment is removed and placed in the turtle's inventory. If there is no item
|
||||||
|
---in the currently selected slot, the current upgrade is removed but no new one
|
||||||
|
---is equipped, effectively unequipping the turtle
|
||||||
|
---@return boolean success If the item was equipped
|
||||||
|
---@return string|nil errorMessage The reason equipping failed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:equipRight)
|
||||||
|
function turtle.equipRight() end
|
||||||
|
|
||||||
|
---Get information about the block in front of the turtle
|
||||||
|
---@return boolean blockPresent If there is a block in front of the turtle
|
||||||
|
---@return ccTweaked.turtle.inspectInfo|string info Info about the block or a message explaining that there is no block
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:inspect)
|
||||||
|
function turtle.inspect() end
|
||||||
|
|
||||||
|
---Get information about the block above the turtle
|
||||||
|
---@return boolean blockPresent If there is a block above the turtle
|
||||||
|
---@return ccTweaked.turtle.inspectInfo|string info Info about the block or a message explaining that there is no block
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:inspectUp)
|
||||||
|
function turtle.inspectUp() end
|
||||||
|
|
||||||
|
---Get information about the block below the turtle
|
||||||
|
---@return boolean blockPresent If there is a block below the turtle
|
||||||
|
---@return ccTweaked.turtle.inspectInfo|string info Info about the block or a message explaining that there is no block
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:inspectDown)
|
||||||
|
function turtle.inspectDown() end
|
||||||
|
|
||||||
|
---Get information about the items in the given slot
|
||||||
|
---@param slot? ccTweaked.turtle.slot The slot to get information about (defaults to the currently selected slot)
|
||||||
|
---@param detailed? boolean Whether to get more info on the block. This results in much more info at the cost of execution time
|
||||||
|
---@return nil|ccTweaked.turtle.slotInfo|ccTweaked.turtle.slotInfoDetailed info Information about `slot` or `nil` if it is empty
|
||||||
|
---@throws If the slot is out of range
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:getItemDetail)
|
||||||
|
function turtle.getItemDetail(slot, detailed) end
|
||||||
|
|
||||||
|
---Craft a recipe based on the turtle's inventory
|
||||||
|
---
|
||||||
|
---This requires the items to craft the item to be laid out as if the turtle's
|
||||||
|
---inventory is a crafting table. **ALL other slots must be empty**
|
||||||
|
---@param limit? integer The maximum number of items to craft (default is 64)
|
||||||
|
---@return boolean success If crafting succeeded
|
||||||
|
---@return string|nil errorMessage Why crafting failed
|
||||||
|
---@throws If limit is less than 1
|
||||||
|
---@throws If limit is greater than 64
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:craft)
|
||||||
|
function turtle.craft(limit) end
|
||||||
|
|
||||||
|
---The builtin turtle API with no generate helper functions
|
||||||
|
---
|
||||||
|
---🚮 **Deprecated** This used to behave differently than the `turtle` API. This
|
||||||
|
---should never be needed now
|
||||||
|
---@deprecated
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/turtle.html#v:native)
|
||||||
|
turtle.native = {}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---@alias ccTweaked.colors.color integer An integer represeting a color value. Colors can be found in the `colors` namespace, such as `colors.orange`
|
||||||
|
|
||||||
|
---@alias ccTweaked.colors.colorSet integer A set of colors (an integer representing multiple color values)
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---@alias ccTweaked.fs.openMode
|
||||||
|
---| '"r"' # read mode
|
||||||
|
---| '"w"' # write mode
|
||||||
|
---| '"a"' # append mode
|
||||||
|
---| '"r+"' # read/write, data preserved
|
||||||
|
---| '"w+"' # read/write, data truncated (erased) on open
|
||||||
|
---| '"rb"' # binary read mode
|
||||||
|
---| '"wb"' # binary write mode
|
||||||
|
---| '"ab"' # binary append mode
|
||||||
|
|
||||||
|
---@alias ccTweaked.fs.seekWhence
|
||||||
|
---| '"set"' # relative to the start of the file
|
||||||
|
---| '"cur"' # relative to the current position
|
||||||
|
---| '"end"' # relative to the end of the file
|
||||||
|
|
||||||
|
---@class ccTweaked.fs.fileAttributes
|
||||||
|
---@field size integer
|
||||||
|
---@field isDir boolean
|
||||||
|
---@field isReadOnly boolean
|
||||||
|
---@field created ccTweaked.epoch
|
||||||
|
---@field modified ccTweaked.epoch
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---@alias ccTweaked.epoch integer A number of milliseconds since the [UNIX epoch](https://en.wikipedia.org/wiki/Unix_time). Useful for timestamping.
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
---@alias ccTweaked.http.Request.method
|
||||||
|
---| '"GET"'
|
||||||
|
---| '"HEAD"'
|
||||||
|
---| '"POST"'
|
||||||
|
---| '"PUT"'
|
||||||
|
---| '"DELETE"'
|
||||||
|
---| '"CONNECT"'
|
||||||
|
---| '"OPTIONS"'
|
||||||
|
---| '"TRACE"'
|
||||||
|
---| '"PATCH"'
|
||||||
|
|
||||||
|
---@class ccTweaked.http.Request
|
||||||
|
---@field url string
|
||||||
|
---@field method ccTweaked.http.Request.method? Defaults to GET
|
||||||
|
---@field headers table<string, string>?
|
||||||
|
---@field body string?
|
||||||
|
---@field binary boolean?
|
||||||
|
---@field redirect boolean? Whether redirects should be followed
|
||||||
|
---@field timeout integer? Connection timeout in seconds
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---@alias ccTweaked.io.seekMode
|
||||||
|
---| '"set"' # Relative to the start of the file
|
||||||
|
---| '"cur"' # Relative to the current position (default)
|
||||||
|
---| '"end"' # Relative to the end of the file
|
||||||
|
|
||||||
|
---@alias ccTweaked.io.readMode
|
||||||
|
---| '"l"' # Read the next line (no trailing newline)
|
||||||
|
---| '"L"' # Read the next line (with trailing newline)
|
||||||
|
---| '"a"' # Read the remainder of the file
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---@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.
|
||||||
|
|
@ -0,0 +1,238 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---A base class for all objects that interact with a terminal (e.g. `term` and monitors)
|
||||||
|
---@class ccTweaked.term.Redirect
|
||||||
|
Redirect = {}
|
||||||
|
|
||||||
|
---Write `text` at the current cursor position, moving the cursor to the end of the text
|
||||||
|
---
|
||||||
|
---🗒️Unlike `_G.write()` and `_G.print()`, this function does not wrap text
|
||||||
|
---@param text string The text to write
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:write)
|
||||||
|
function Redirect.write(text) end
|
||||||
|
|
||||||
|
---Move all positions up or down
|
||||||
|
---@param y number The number of lines to move by (can be negative)
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:scroll)
|
||||||
|
function Redirect.scroll(y) end
|
||||||
|
|
||||||
|
---Get the current position of the cursor
|
||||||
|
---@return integer x The current x position
|
||||||
|
---@return integer y The current y position
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:getCursorPos)
|
||||||
|
function Redirect.getCursorPos() end
|
||||||
|
|
||||||
|
---Set the position of the cursor
|
||||||
|
---@param x number The new x position
|
||||||
|
---@param y number The new y position
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:setCursorPos)
|
||||||
|
function Redirect.setCursorPos(x, y) end
|
||||||
|
|
||||||
|
---Check if the cursor is currently blinking
|
||||||
|
---@return boolean isBlinking If the cursor is currently blinking
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:getCursorBlink)
|
||||||
|
function Redirect.getCursorBlink() end
|
||||||
|
|
||||||
|
---Set whether the cursor should be visible and blinking at the current cursor position
|
||||||
|
---@param blink boolean If the cursor should be blinking
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:setCursorBlink)
|
||||||
|
function Redirect.setCursorBlink(blink) end
|
||||||
|
|
||||||
|
---Get the size of the terminal
|
||||||
|
---@return integer width The terminal's width
|
||||||
|
---@return integer height The terminal's height
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:getSize)
|
||||||
|
function Redirect.getSize() end
|
||||||
|
|
||||||
|
---Clears the terminal, filling it with the current background color
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:clear)
|
||||||
|
function Redirect.clear() end
|
||||||
|
|
||||||
|
---Clears the line the cursor is on, filling it with the current background color
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:clearLine)
|
||||||
|
function Redirect.clearLine() end
|
||||||
|
|
||||||
|
---Get the current text color that text would be drawn in
|
||||||
|
---@return ccTweaked.colors.color textColor The current text color
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:getTextColor)
|
||||||
|
function Redirect.getTextColor() end
|
||||||
|
|
||||||
|
---Get the current text colour that text would be drawn in
|
||||||
|
---@return ccTweaked.colors.color textColour The current text colour
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:getTextColour)
|
||||||
|
function Redirect.getTextColour() end
|
||||||
|
|
||||||
|
---Set the colour that text should be drawn in
|
||||||
|
---@param colour ccTweaked.colors.color The new colour text should be drawn in
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:setTextColour)
|
||||||
|
function Redirect.setTextColour(colour) end
|
||||||
|
|
||||||
|
---Set the color that text should be drawn in
|
||||||
|
---@param color ccTweaked.colors.color The new color text should be drawn in
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:setTextColor)
|
||||||
|
function Redirect.setTextColor(color) end
|
||||||
|
|
||||||
|
---Get the current background colour
|
||||||
|
---
|
||||||
|
---This is used when writing text and clearing the terminal
|
||||||
|
---@return ccTweaked.colors.color backgroundColour The current background colour
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:getBackgroundColour)
|
||||||
|
function Redirect.getBackgroundColour() end
|
||||||
|
|
||||||
|
---Get the current background color
|
||||||
|
---
|
||||||
|
---This is used when writing text and clearing the terminal
|
||||||
|
---@return ccTweaked.colors.color backgroundColor The current background color
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:getBackgroundColor)
|
||||||
|
function Redirect.getBackgroundColor() end
|
||||||
|
|
||||||
|
---Set the current background colour
|
||||||
|
---
|
||||||
|
---This is used when writing text and clearing the terminal
|
||||||
|
---@param colour ccTweaked.colors.color The new background colour that should be used
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:setBackgroundColour)
|
||||||
|
function Redirect.setBackgroundColour(colour) end
|
||||||
|
|
||||||
|
---Set the current background color
|
||||||
|
---
|
||||||
|
---This is used when writing text and clearing the terminal
|
||||||
|
---@param color ccTweaked.colors.color The new background color that should be used
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:setBackgroundColor)
|
||||||
|
function Redirect.setBackgroundColor(color) end
|
||||||
|
|
||||||
|
---Get whether this terminal supports colour
|
||||||
|
---
|
||||||
|
---Terminals which don't support colour still allow writing coloured
|
||||||
|
---text/backgrounds, but it will be displayed in greyscale
|
||||||
|
---@return boolean isColour Whether this terminal supports colour or not
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:isColour)
|
||||||
|
function Redirect.isColour() end
|
||||||
|
|
||||||
|
---Get whether this terminal supports color
|
||||||
|
---
|
||||||
|
---Terminals which don't support color still allow writing colored
|
||||||
|
---text/backgrounds, but it will be displayed in greyscale
|
||||||
|
---@return boolean isColor Whether this terminal supports color or not
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:isColor)
|
||||||
|
function Redirect.isColor() end
|
||||||
|
|
||||||
|
---Writes `text` to the terminal with the specified text and background colors
|
||||||
|
---
|
||||||
|
---The cursor will be moved to the end of the text after writing
|
||||||
|
---
|
||||||
|
---`textColor` and `backgroundColor` must both be strings and the same length as
|
||||||
|
---`text`. Each of their characters represent a single hexadecimal digit, which
|
||||||
|
---is converted to a color
|
||||||
|
---@param text string The text to write
|
||||||
|
---@param textColor string A string of hexadecimal values that correspond to colors from the `colors` API
|
||||||
|
---@param backgroundColor string A string of hexadecimal values that correspond to colors from the `colors` API
|
||||||
|
---@throws If the inputs are not all of the same length
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---term.blit("Hello, world!","01234456789ab","0000000000000")
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:blit)
|
||||||
|
function Redirect.blit(text, textColor, backgroundColor) end
|
||||||
|
|
||||||
|
---Set the value for a specific colour from CC's palette
|
||||||
|
---
|
||||||
|
---While you still can't have more than 16 colours, you can change what values
|
||||||
|
---are available. For example, you can change `colors.red` to `#FF0000` for it to
|
||||||
|
---be *more* red
|
||||||
|
---@param index ccTweaked.colors.color The colour that should be changed
|
||||||
|
---@param colour integer A 24 bit integer representing the RGB value of a colour
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---term.setPaletteColour(colors.red, 0xFF0000)
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:setPaletteColour)
|
||||||
|
function Redirect.setPaletteColour(index, colour) end
|
||||||
|
|
||||||
|
---Set the value for a specific colour from CC's palette
|
||||||
|
---
|
||||||
|
---While you still can't have more than 16 colours, you can change what values
|
||||||
|
---are available. For example, you can change `colors.red` to `1, 0, 0` for it to
|
||||||
|
---be *more* red
|
||||||
|
---@param index ccTweaked.colors.color The colour that should be changed
|
||||||
|
---@param r number The red channel value
|
||||||
|
---@param g number The green channel value
|
||||||
|
---@param b number The blue channel value
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---term.setPaletteColour(colors.red, 1, 0, 0)
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:setPaletteColour)
|
||||||
|
function Redirect.setPaletteColour(index, r, g, b) end
|
||||||
|
|
||||||
|
---Set the value for a specific color from CC's palette
|
||||||
|
---
|
||||||
|
---While you still can't have more than 16 colors, you can change what values
|
||||||
|
---are available. For example, you can change `colors.red` to `#FF0000` for it to
|
||||||
|
---be *more* red
|
||||||
|
---@param index ccTweaked.colors.color The color that should be changed
|
||||||
|
---@param color integer A 24 bit integer representing the RGB value of a color
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---term.setPaletteColor(colors.red, 0xFF0000)
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:setPaletteColor)
|
||||||
|
function Redirect.setPaletteColor(index, color) end
|
||||||
|
|
||||||
|
---Set the value for a specific color from CC's palette
|
||||||
|
---
|
||||||
|
---While you still can't have more than 16 colors, you can change what values
|
||||||
|
---are available. For example, you can change `colors.red` to `1, 0, 0` for it to
|
||||||
|
---be *more* red
|
||||||
|
---@param index ccTweaked.colors.color The color that should be changed
|
||||||
|
---@param r number The red channel value
|
||||||
|
---@param g number The green channel value
|
||||||
|
---@param b number The blue channel value
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---term.setPaletteColor(colors.red, 1, 0, 0)
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:setPaletteColor)
|
||||||
|
function Redirect.setPaletteColor(index, r, g, b) end
|
||||||
|
|
||||||
|
---Get the current colour value for a specific colour from the palette
|
||||||
|
---@param colour ccTweaked.colors.color The colour to get the value of
|
||||||
|
---@return number red The red channel (0 - 1)
|
||||||
|
---@return number green The green channel (0 - 1)
|
||||||
|
---@return number blue The blue channel (0 - 1)
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:getPaletteColour)
|
||||||
|
function Redirect.getPaletteColour(colour) end
|
||||||
|
|
||||||
|
---Get the current color value for a specific color from the palette
|
||||||
|
---@param color ccTweaked.colors.color The color to get the value of
|
||||||
|
---@return number red The red channel (0 - 1)
|
||||||
|
---@return number green The green channel (0 - 1)
|
||||||
|
---@return number blue The blue channel (0 - 1)
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/term.html#ty:Redirect:getPaletteColor)
|
||||||
|
function Redirect.getPaletteColor(color) end
|
||||||
|
|
@ -0,0 +1,133 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---A 3 dimensional vector with an `x`, `y`, and `z` value
|
||||||
|
---
|
||||||
|
---These are suitable for positions or directions
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/vector.html#ty:Vector)
|
||||||
|
---@class ccTweaked.Vector
|
||||||
|
---@field x number
|
||||||
|
---@field y number
|
||||||
|
---@field z number
|
||||||
|
Vector = {}
|
||||||
|
|
||||||
|
---Add two `Vector` objects together
|
||||||
|
---
|
||||||
|
---You can also take advantage of the `__add` metamethod:
|
||||||
|
---```
|
||||||
|
---result = vector1 + vector2
|
||||||
|
---```
|
||||||
|
---@param v ccTweaked.Vector The second `Vector` to add
|
||||||
|
---@return ccTweaked.Vector result The resulting `Vector`
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/vector.html#ty:Vector:add)
|
||||||
|
function Vector:add(v) end
|
||||||
|
|
||||||
|
---Subtract one `Vector` from another
|
||||||
|
---
|
||||||
|
---You can also take advantage of the `__sub` metamethod:
|
||||||
|
---```
|
||||||
|
---result = vector1 - vector2
|
||||||
|
---```
|
||||||
|
---@param v ccTweaked.Vector The second `Vector` to subtract
|
||||||
|
---@return ccTweaked.Vector result The resulting `Vector`
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/vector.html#ty:Vector:sub)
|
||||||
|
function Vector:sub(v) end
|
||||||
|
|
||||||
|
---Multiply a `Vector` by a scalar value, scaling it
|
||||||
|
---
|
||||||
|
---You can also take advantage of the `__mul` metamethod:
|
||||||
|
---```
|
||||||
|
---result = vector1 * 2
|
||||||
|
---```
|
||||||
|
---@param scalar number The scalar value to multiply with
|
||||||
|
---@return ccTweaked.Vector result The resulting `Vector`
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/vector.html#ty:Vector:mul)
|
||||||
|
function Vector:mul(scalar) end
|
||||||
|
|
||||||
|
---Divide a `Vector` by a scalar value, scaling it
|
||||||
|
---
|
||||||
|
---You can also take advantage of the `__div` metamethod:
|
||||||
|
---```
|
||||||
|
---result = vector1 / 2
|
||||||
|
---```
|
||||||
|
---@param scalar number The scalar value to divide with
|
||||||
|
---@return ccTweaked.Vector result The resulting `Vector`
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/vector.html#ty:Vector:div)
|
||||||
|
function Vector:div(scalar) end
|
||||||
|
|
||||||
|
---Negate a vector
|
||||||
|
---
|
||||||
|
---You can also take advantage of the `__unm` metamethod:
|
||||||
|
---```
|
||||||
|
---negated = -vector1
|
||||||
|
---```
|
||||||
|
---@return ccTweaked.Vector negated The negated `Vector`
|
||||||
|
function Vector:unm() end
|
||||||
|
|
||||||
|
---Compute the dot product of two vectors
|
||||||
|
---@param v ccTweaked.Vector The second vector to use for the calculation
|
||||||
|
---@return number dot The dot product of the two vectors
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/vector.html#ty:Vector:dot)
|
||||||
|
function Vector:dot(v) end
|
||||||
|
|
||||||
|
---Compute the cross product of two vectors
|
||||||
|
---@param v ccTweaked.Vector The second vector to use for the calculation
|
||||||
|
---@return ccTweaked.Vector cross The cross products of the two vectors
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/vector.html#ty:Vector:cross)
|
||||||
|
function Vector:cross(v) end
|
||||||
|
|
||||||
|
---Get the length/magnitude of this vector
|
||||||
|
---@return number length The length of this vector
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/vector.html#ty:Vector:length)
|
||||||
|
function Vector:length() end
|
||||||
|
|
||||||
|
---Divide this vector by its length, normalizing it
|
||||||
|
---@return ccTweaked.Vector normalized The normalized vector
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/vector.html#ty:Vector:normalize)
|
||||||
|
function Vector:normalize() end
|
||||||
|
|
||||||
|
---Create a new `Vector` with each dimension rounded
|
||||||
|
---@param tolerance? number The tolerance that rounding should take place to (defaults to 1)
|
||||||
|
---@return ccTweaked.Vector rounded The rounded vector
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---local rounded = vector1:round(0.05)
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/vector.html#ty:Vector:round)
|
||||||
|
function Vector:round(tolerance) end
|
||||||
|
|
||||||
|
---Convert this vector to a string for printing
|
||||||
|
---
|
||||||
|
---You can also take advantage of the `__tostring` metamethod:
|
||||||
|
---```
|
||||||
|
---asString = tostring(vector1)
|
||||||
|
---```
|
||||||
|
---@return string str The string representation of this vector
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/vector.html#ty:Vector:tostring)
|
||||||
|
function Vector:toString() end
|
||||||
|
|
||||||
|
---Check if two vectors are equal
|
||||||
|
---@param v ccTweaked.Vector The vector to compare to
|
||||||
|
---@return boolean equal If the two vectors are equal
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---local v1 = vector.new(12.00439, 0, 0)
|
||||||
|
---local v2 = vector.new(12.00441, 0, 0)
|
||||||
|
---
|
||||||
|
---local areSimilar = v1:round(0.001):equals(v2:round(0.001))
|
||||||
|
----->true
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/vector.html#ty:Vector:tostring)
|
||||||
|
function Vector:equals(v) end
|
||||||
|
|
@ -0,0 +1,62 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---@class ccTweaked.Window: ccTweaked.term.Redirect
|
||||||
|
Window = {}
|
||||||
|
|
||||||
|
---Get the buffered contents of a given line in this window
|
||||||
|
---@param y integer The y position of the line to get
|
||||||
|
---@return string content The text content of this line
|
||||||
|
---@return string textBlit The text colors of this line, suitable for use with `term.blit()`
|
||||||
|
---@return string backgroundBlit The background colors of this line, suitable for use with `term.blit()`
|
||||||
|
---@throws If `y` is not between 1 and this window's height
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/window.html#ty:Window:getLine)
|
||||||
|
function Window.getLine(y) end
|
||||||
|
|
||||||
|
---Set whether this window is visible
|
||||||
|
---@param visible boolean If this window should be visible
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/window.html#ty:Window:setVisible)
|
||||||
|
function Window.setVisible(visible) end
|
||||||
|
|
||||||
|
---Get whether this window is visible
|
||||||
|
---@return boolean visible If this window is visible
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/window.html#ty:Window:isVisible)
|
||||||
|
function Window.isVisible() end
|
||||||
|
|
||||||
|
---Draw this window
|
||||||
|
---
|
||||||
|
---⚠️ This does nothing if the window is set to be invisible
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/window.html#ty:Window:redraw)
|
||||||
|
function Window.redraw() end
|
||||||
|
|
||||||
|
---Set the current terminal's cursor to where this window's cursor is
|
||||||
|
---
|
||||||
|
---⚠️ This does nothing if the window is set to be invisible
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/window.html#ty:Window:restoreCursor)
|
||||||
|
function Window.restoreCursor() end
|
||||||
|
|
||||||
|
---Get the position of the top left corner of this window
|
||||||
|
---@return number x The x position of this window
|
||||||
|
---@return number y The y position of this window
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/window.html#ty:Window:getPosition)
|
||||||
|
function Window.getPosition() end
|
||||||
|
|
||||||
|
---Reposition, resize, or change the inheritance of this window
|
||||||
|
---
|
||||||
|
---🗒️ If you are changing the size of this window, it is recommended to fire a
|
||||||
|
---`term_resize` event to allow programs to adjust their scaling
|
||||||
|
---@param x number The new x position of this window
|
||||||
|
---@param y number The new y position of this window
|
||||||
|
---@param w? number The new width of this window
|
||||||
|
---@param h? number The new height of this window
|
||||||
|
---@param parent? ccTweaked.term.Redirect|ccTweaked.peripherals.Monitor The new `Redirect` that this window should be drawn to
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/window.html#ty:Window:reposition)
|
||||||
|
function Window.reposition(x, y, w, h, parent) end
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---A file handle created with `fs.open()` using `rb` mode
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#ty:BinaryReadHandle)
|
||||||
|
---@class ccTweaked.fs.BinaryReadHandle
|
||||||
|
BinaryReadHandle = {}
|
||||||
|
|
||||||
|
---Read a number of bytes from the file
|
||||||
|
---@param count number The number of bytes to read
|
||||||
|
---@return string|nil byte The byte as a string or nil when the end of the file is reached
|
||||||
|
---@throws When trying to read a negative number of bytes
|
||||||
|
---@throws If the file has been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#ty:BinaryReadHandle:read)
|
||||||
|
function BinaryReadHandle.read(count) end
|
||||||
|
|
||||||
|
---Read a byte from the file
|
||||||
|
---@return ccTweaked.os.ASCII|nil byte The byte as an [ASCII code](https://www.rapidtables.com/code/text/ascii-table.html)
|
||||||
|
---@throws If the file has been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#ty:BinaryReadHandle:read)
|
||||||
|
function BinaryReadHandle.read() end
|
||||||
|
|
||||||
|
---Read the remainder of the file
|
||||||
|
---@return string|nil contents The remaining content of the file or nil if the end of the file is reached
|
||||||
|
---@throws If the file has been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#ty:BinaryReadHandle:readAll)
|
||||||
|
function BinaryReadHandle.readAll() end
|
||||||
|
|
||||||
|
---Read a line from the file
|
||||||
|
---@param includeNewline? boolean If any trailing newline characters should be included. Defaults to false
|
||||||
|
---@return string|nil line The read line or nil if the end of the file has been reached
|
||||||
|
---@throws If the file has been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#ty:BinaryReadHandle:readLine)
|
||||||
|
function BinaryReadHandle.readLine(includeNewline) end
|
||||||
|
|
||||||
|
---Close the file, freeing it
|
||||||
|
---
|
||||||
|
---Once closed, it can no longer be read unless it is reopened
|
||||||
|
---@throws If the file has already been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#ty:BinaryReadHandle:close)
|
||||||
|
function BinaryReadHandle.close() end
|
||||||
|
|
||||||
|
---Seek to a new position in the file. The new position is an offset relative to `whence`
|
||||||
|
---@param whence? ccTweaked.fs.seekWhence What `offset` is relative to. Defaults to `cur`
|
||||||
|
---@param offset? number The offset to seek to. Defaults to 0
|
||||||
|
---@return number|nil newPosition The new file read position relative to the start of the file or nil if seeking failed
|
||||||
|
---@return string|nil errorMessage The reason seeking failed
|
||||||
|
---@throws If the file has been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#ty:BinaryReadHandle:seek)
|
||||||
|
function BinaryReadHandle.seek(whence, offset) end
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---A file handle created with `fs.open()` using `wb` or `ab` mode
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#ty:BinaryWriteHandle)
|
||||||
|
---@class ccTweaked.fs.BinaryWriteHandle
|
||||||
|
BinaryWriteHandle = {}
|
||||||
|
|
||||||
|
---Write a string or byte to the file
|
||||||
|
---@param value ccTweaked.os.ASCII|string The string to write or an ASCII code to write
|
||||||
|
---@throws If the file has been closed
|
||||||
|
---## Examples
|
||||||
|
---```
|
||||||
|
---local file = fs.open("myFile.txt", "wb")
|
||||||
|
---file.write("Hello World!\n")
|
||||||
|
---
|
||||||
|
-----Write "Hi"
|
||||||
|
---file.write(48)
|
||||||
|
---file.write(69)
|
||||||
|
---
|
||||||
|
---file.close()
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#ty:BinaryWriteHandle:write)
|
||||||
|
function BinaryWriteHandle.write(value) end
|
||||||
|
|
||||||
|
---Save the current file without closing it
|
||||||
|
---@throws If the file has been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#ty:BinaryWriteHandle:flush)
|
||||||
|
function BinaryWriteHandle.flush() end
|
||||||
|
|
||||||
|
---Close the file, freeing it
|
||||||
|
---
|
||||||
|
---Once closed, it can no longer be written to unless it is reopened
|
||||||
|
---@throws If the file has already been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#ty:BinaryWriteHandle:close)
|
||||||
|
function BinaryWriteHandle.close() end
|
||||||
|
|
||||||
|
---Change where the "cursor" is, changing where bytes will be written to. The
|
||||||
|
---new position is an offset relative to `whence`
|
||||||
|
---@param whence? ccTweaked.fs.seekWhence What `offset` is relative to. Defaults to `cur`
|
||||||
|
---@param offset? number The offset to seek to. Defaults to 0
|
||||||
|
---@return number|nil newPosition The new file write position relative to the start of the file or nil if seeking failed
|
||||||
|
---@return string|nil errorMessage The reason seeking failed
|
||||||
|
---@throws If the file has been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#ty:BinaryWriteHandle:seek)
|
||||||
|
function BinaryWriteHandle.seek(whence, offset) end
|
||||||
|
|
@ -0,0 +1,94 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---A file handle which can be read from and written to. Contains
|
||||||
|
---[methods](https://www.lua.org/pil/16.html#:~:text=This%20use%20of,method%20call%20as)
|
||||||
|
---for editing files.
|
||||||
|
---
|
||||||
|
---Make sure you are calling these methods like so: `myHandle:read()`
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/io.html#ty:Handle)
|
||||||
|
---@class ccTweaked.fs.Handle
|
||||||
|
Handle = {}
|
||||||
|
|
||||||
|
---Close the file, freeing it
|
||||||
|
---@return true|nil success If the file was closed
|
||||||
|
---@return nil|string reason The reason it couldn't be closed
|
||||||
|
---@throws If the handle is already closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/io.html#ty:Handle:close)
|
||||||
|
function Handle:close() end
|
||||||
|
|
||||||
|
---Flush any buffered output, forcing it to be written to the file
|
||||||
|
---@throws If the file has been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/io.html#ty:Handle:flush)
|
||||||
|
function Handle:flush() end
|
||||||
|
|
||||||
|
---Returns an iterator that returns a new line from the file each time it is
|
||||||
|
---called. When the end of the file has been reached, returns `nil`
|
||||||
|
---
|
||||||
|
---Useful for looping over all lines in a file
|
||||||
|
---@param format ccTweaked.io.readMode The format each line should be read with
|
||||||
|
---@return fun(): string|nil iterator The line iterator
|
||||||
|
---@throws If the file cannot be opened for reading
|
||||||
|
---⚠️ The file is not automatically closed when the end of the file is reached
|
||||||
|
---
|
||||||
|
---❗Passing `"a"` as a format will result in an infinite loop and will crash your script after timing out
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---local file = io.open("/rom/help/intro.txt")
|
||||||
|
---
|
||||||
|
-----Iterate over all lines in a file
|
||||||
|
-----Read each line with a trailing newline
|
||||||
|
---for line in file:lines("L") do
|
||||||
|
--- print(line)
|
||||||
|
---end
|
||||||
|
---
|
||||||
|
---file:close()
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/io.html#ty:Handle:lines)
|
||||||
|
function Handle:lines(format) end
|
||||||
|
|
||||||
|
---Read data from the file using the specified format. For each format provided,
|
||||||
|
---returns either the data read or `nil` if no data could be read.
|
||||||
|
---@param ... ccTweaked.io.readMode The formats to use for reading. Defaults to `l`
|
||||||
|
---@return string content The data (as a string) read from the file or nil if no data could be read.
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/io.html#ty:Handle:read)
|
||||||
|
function Handle:read(...) end
|
||||||
|
|
||||||
|
---Seek to a new position in the file. The new position is an offset relative to `whence`
|
||||||
|
---
|
||||||
|
---Only available if the handle was opened in binary mode
|
||||||
|
---@param whence? ccTweaked.fs.seekWhence What `offset` is relative to. Defaults to `cur`
|
||||||
|
---@param offset? number The offset to seek to. Defaults to 0
|
||||||
|
---@return number|nil newPosition The new file read position relative to the start of the file or nil if seeking failed
|
||||||
|
---@return string|nil errorMessage The reason seeking failed
|
||||||
|
---@throws If the file has been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/io.html#ty:Handle:seek)
|
||||||
|
function Handle:seek(whence, offset) end
|
||||||
|
|
||||||
|
---Set the buffering mode
|
||||||
|
---@param mode "no"|"full"|"line" The buffering mode to use
|
||||||
|
---@param size number The buffer size in bytes
|
||||||
|
---@deprecated
|
||||||
|
---[See Lua Documentation](https://www.lua.org/manual/5.1/manual.html#pdf-file:setvbuf)
|
||||||
|
---
|
||||||
|
---🚮 Deprecated, has no effect in ComputerCraft
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/io.html#ty:Handle:setvbuf)
|
||||||
|
function Handle:setvbuf(mode, size) end
|
||||||
|
|
||||||
|
---Write one or more values to the file
|
||||||
|
---@param ... string|number The values to write
|
||||||
|
---@return ccTweaked.fs.Handle|nil self Returns this handler so you can chain calls. Possibly nil if file could not be written to
|
||||||
|
---@return nil|string errorMessage The reason the file couldn't be written to
|
||||||
|
---@throws If the file has been closed
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/io.html#ty:Handle:write)
|
||||||
|
function Handle:write(...) end
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---A file handle created with `fs.open()` using `r` mode
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#ty:ReadHandle)
|
||||||
|
---@class ccTweaked.fs.ReadHandle
|
||||||
|
ReadHandle = {}
|
||||||
|
|
||||||
|
---Read a single line from the file
|
||||||
|
---@param includeNewline? boolean If any trailing newline characters should be included. Defaults to false
|
||||||
|
---@return string|nil line The read line or nil if the end of the file has been reached
|
||||||
|
---@throws If the file has been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#ty:ReadHandle:readLine)
|
||||||
|
function ReadHandle.readLine(includeNewline) end
|
||||||
|
|
||||||
|
---Read the remainder of the file
|
||||||
|
---@return string|nil contents The remaining contents of the file or nil if at the end of the file
|
||||||
|
---@throws If the file has been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#ty:ReadHandle:readAll)
|
||||||
|
function ReadHandle.readAll() end
|
||||||
|
|
||||||
|
---Read characters from the file
|
||||||
|
---@param count? number The number of characters to read. Defaults to 1
|
||||||
|
---@return string|nil characters The read character(s) or nil if at the end of the file
|
||||||
|
---@throws When trying to read a negative number of characters
|
||||||
|
---@throws If the file has been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#ty:ReadHandle:read)
|
||||||
|
function ReadHandle.read(count) end
|
||||||
|
|
||||||
|
---Move the cursor to a new position in the file. Sets the cursor to a new position offset by `offset`, relative to `whence`.
|
||||||
|
---@param whence ccTweaked.io.seekMode?
|
||||||
|
---@param offset integer?
|
||||||
|
---@return integer | nil position The new cursor position or nil if failed
|
||||||
|
---@return string? err The reason that seeking failed
|
||||||
|
---@throws If the file has been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#ty:ReadHandle:seek)
|
||||||
|
function ReadHandle.seek(whence, offset) end
|
||||||
|
|
||||||
|
---Close the file, freeing it
|
||||||
|
---
|
||||||
|
---Once closed, it can no longer be read unless it is reopened
|
||||||
|
---@throws If the file has already been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#ty:ReadHandle:close)
|
||||||
|
function ReadHandle.close() end
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---A file handle created with `fs.open()` using the `w` or `a` mode
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#ty:WriteHandle)
|
||||||
|
---@class ccTweaked.fs.WriteHandle
|
||||||
|
WriteHandle = {}
|
||||||
|
|
||||||
|
---Write a value to a file
|
||||||
|
---@param value any The value to write to the file
|
||||||
|
---@throws If the file has been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#ty:WriteHandle:write)
|
||||||
|
function WriteHandle.write(value) end
|
||||||
|
|
||||||
|
---Write a value to a file with a trailing newline character
|
||||||
|
---@param value any The value to write to the file
|
||||||
|
---@throws If the file has been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#ty:WriteHandle:writeLine)
|
||||||
|
function WriteHandle.writeLine(value) end
|
||||||
|
|
||||||
|
---Save the current file without closing it
|
||||||
|
---@throws If the file has been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#ty:WriteHandle:flush)
|
||||||
|
function WriteHandle.flush() end
|
||||||
|
|
||||||
|
---Close the file, freeing it
|
||||||
|
---
|
||||||
|
---Once closed, it can no longer be written to unless it is reopened
|
||||||
|
---@throws If the file has already been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/fs.html#ty:WriteHandle:close)
|
||||||
|
function WriteHandle.close() end
|
||||||
|
|
@ -0,0 +1,73 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---A HTTP response. This provides the same methods as a file as well as some response-specific methods
|
||||||
|
---
|
||||||
|
---@class ccTweaked.http.BinaryResponse : ccTweaked.fs.BinaryReadHandle
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response)
|
||||||
|
BinaryResponse = {}
|
||||||
|
|
||||||
|
---Get the response code and message returned by the server
|
||||||
|
---@return number code The response code (e.g. 200)
|
||||||
|
---@return string message The response message (e.g. "OK")
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response:getResponseCode)
|
||||||
|
function BinaryResponse.getResponseCode() end
|
||||||
|
|
||||||
|
---Get the [response headers](https://developer.mozilla.org/en-US/docs/Glossary/Response_header)
|
||||||
|
---
|
||||||
|
---If multiple headers are sent with the same name, they will be combined with a
|
||||||
|
---comma
|
||||||
|
---@return table<string, string>
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response:getResponseHeaders)
|
||||||
|
function BinaryResponse.getResponseHeaders() end
|
||||||
|
|
||||||
|
---Read a single line from the response
|
||||||
|
---@param includeNewline? boolean If any trailing newline characters should be included. Defaults to false
|
||||||
|
---@return string|nil line The read line or nil if the end of the response has been reached
|
||||||
|
---@throws If the response has been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response)
|
||||||
|
function BinaryResponse.readLine(includeNewline) end
|
||||||
|
|
||||||
|
---Read the remainder of the response
|
||||||
|
---@return string|nil contents The remaining contents of the response or nil if at the end of the response
|
||||||
|
---@throws If the response has been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response)
|
||||||
|
function BinaryResponse.readAll() end
|
||||||
|
|
||||||
|
---Read a number of bytes from the response
|
||||||
|
---@param count number The number of bytes to read
|
||||||
|
---@return string|nil byte The byte as a string or nil when the end of the response is reached
|
||||||
|
---@throws When trying to read a negative number of bytes
|
||||||
|
---@throws If the response has been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response)
|
||||||
|
function BinaryResponse.read(count) end
|
||||||
|
|
||||||
|
---Read a byte from the response
|
||||||
|
---@return ccTweaked.os.ASCII|nil byte The byte as an [ASCII code](https://www.rapidtables.com/code/text/ascii-table.html)
|
||||||
|
---@throws If the response has been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response)
|
||||||
|
function BinaryResponse.read() end
|
||||||
|
|
||||||
|
---Close the response
|
||||||
|
---
|
||||||
|
---Once closed, it can no longer be read unless it is re-requested
|
||||||
|
---@throws If the response has already been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response)
|
||||||
|
function BinaryResponse.close() end
|
||||||
|
|
||||||
|
---Seek to a new position in the response. The new position is an offset relative to `whence`
|
||||||
|
---@param whence ccTweaked.fs.seekWhence What `offset` is relative to
|
||||||
|
---@param offset number The offset to seek to
|
||||||
|
---@return number|nil newPosition The new response read position relative to the start of the response or nil if seeking failed
|
||||||
|
---@return string|nil errorMessage The reason seeking failed
|
||||||
|
---@throws If the response has been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response)
|
||||||
|
function BinaryResponse.seek(whence, offset) end
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---A HTTP response. This provides the same methods as a file as well as some response-specific methods
|
||||||
|
---
|
||||||
|
---@class ccTweaked.http.Response : ccTweaked.fs.ReadHandle
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response)
|
||||||
|
Response = {}
|
||||||
|
|
||||||
|
---Get the response code and message returned by the server
|
||||||
|
---@return number code The response code (e.g. 200)
|
||||||
|
---@return string message The response message (e.g. "OK")
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response:getResponseCode)
|
||||||
|
function Response.getResponseCode() end
|
||||||
|
|
||||||
|
---Get the [response headers](https://developer.mozilla.org/en-US/docs/Glossary/Response_header)
|
||||||
|
---
|
||||||
|
---If multiple headers are sent with the same name, they will be combined with a
|
||||||
|
---comma
|
||||||
|
---@return table<string, string>
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response:getResponseHeaders)
|
||||||
|
function Response.getResponseHeaders() end
|
||||||
|
|
||||||
|
---Read a single line from the response
|
||||||
|
---@param includeNewline? boolean If any trailing newline characters should be included. Defaults to false
|
||||||
|
---@return string|nil line The read line or nil if the end of the response has been reached
|
||||||
|
---@throws If the response has been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response)
|
||||||
|
function Response.readLine(includeNewline) end
|
||||||
|
|
||||||
|
---Read the remainder of the response
|
||||||
|
---@return string|nil contents The remaining contents of the response or nil if at the end of the response
|
||||||
|
---@throws If the response has been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response)
|
||||||
|
function Response.readAll() end
|
||||||
|
|
||||||
|
---Read characters from the response
|
||||||
|
---@param count? number The number of characters to read. Defaults to 1
|
||||||
|
---@return string|nil characters The read character(s) or nil if at the end of the response
|
||||||
|
---@throws When trying to read a negative number of characters
|
||||||
|
---@throws If the response has been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response)
|
||||||
|
function Response.read(count) end
|
||||||
|
|
||||||
|
---Close the response
|
||||||
|
---
|
||||||
|
---Once closed, it can no longer be read unless it is re-requested
|
||||||
|
---
|
||||||
|
---@throws If the response has already been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#ty:Response)
|
||||||
|
function Response.close() end
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---A [websocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API)
|
||||||
|
---that can be used to send/receive messages to/from a web server
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#ty:Websocket)
|
||||||
|
---@class ccTweaked.http.Websocket
|
||||||
|
Websocket = {}
|
||||||
|
|
||||||
|
---Wait for a message from the server
|
||||||
|
---@param timeout? number The number of seconds to wait for a message. Default to never timing out
|
||||||
|
---@return string|nil response The received message or `nil` if the websocket was closed while waiting or the timeout was reached
|
||||||
|
---@return boolean isBinary If this is a binary message
|
||||||
|
---@throws If the websocket has been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#ty:Websocket:receive)
|
||||||
|
function Websocket.receive(timeout) end
|
||||||
|
|
||||||
|
---Send a message to the server
|
||||||
|
---@param message any The message to send
|
||||||
|
---@param binary boolean If this message is binary or not
|
||||||
|
---@throws If the message is too large
|
||||||
|
---@throws If the websocket has been closed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#ty:Websocket:send)
|
||||||
|
function Websocket.send(message, binary) end
|
||||||
|
|
||||||
|
---Close the websocket connection meaning you can no longer send or receive on it
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#ty:Websocket:close)
|
||||||
|
function Websocket.close() end
|
||||||
|
|
||||||
|
---Get the response headers from the initial handshake. Headers that were sent
|
||||||
|
---with the same name will have their values concatenated with a comma separator.
|
||||||
|
---@return table<string, string>
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/http.html#ty:Websocket:getResponseHeaders)
|
||||||
|
function Websocket.getResponseHeaders() end
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---The Chat Box is able to read and write messages to the in-game chat.
|
||||||
|
---You can send messages to just one player or to everyone.
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://docs.advanced-peripherals.de/0.7/peripherals/chat_box/)
|
||||||
|
---@class ccTweaked.peripherals.ChatBox
|
||||||
|
ChatBox = {}
|
||||||
|
|
||||||
|
---Send a message to chat.
|
||||||
|
---@param message string
|
||||||
|
---@param prefix? string
|
||||||
|
---@param brackets? string
|
||||||
|
---@param bracketColor? string
|
||||||
|
---@param utf8Support? boolean
|
||||||
|
---@return true | nil, string
|
||||||
|
function ChatBox.sendMessage(message, prefix, brackets, bracketColor, range, utf8Support) end
|
||||||
|
|
||||||
|
---Send a formatted message to chat.
|
||||||
|
---@param json string
|
||||||
|
---@param prefix? string
|
||||||
|
---@param brackets? string
|
||||||
|
---@param bracketColor? string
|
||||||
|
---@param range? number
|
||||||
|
---@param utf8Support? boolean
|
||||||
|
---@return true | nil, string
|
||||||
|
function ChatBox.sendFormattedMessage(json, prefix, brackets, bracketColor, range, utf8Support) end
|
||||||
|
|
||||||
|
---Send a formatter message to a specific player.
|
||||||
|
---@param json string
|
||||||
|
---@param username string
|
||||||
|
---@param prefix? string
|
||||||
|
---@param brackets? string
|
||||||
|
---@param bracketColor? string
|
||||||
|
---@param range? number
|
||||||
|
---@param utf8Support? boolean
|
||||||
|
---@return true | nil, string
|
||||||
|
function ChatBox.sendFormattedMessageToPlayer(json, username, prefix, brackets, bracketColor, range, utf8Support) end
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---Command blocks can be used as a peripheral to allow their commands to be
|
||||||
|
---executed using a computer
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/command.html)
|
||||||
|
---@class ccTweaked.peripherals.Command
|
||||||
|
Command = {}
|
||||||
|
|
||||||
|
---Get the command that this command block will run
|
||||||
|
---@return string command The current command
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/command.html#v:getCommand)
|
||||||
|
function Command.getCommand() end
|
||||||
|
|
||||||
|
---Set the command block's command
|
||||||
|
---@param command string The new command
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/command.html#v:setCommand)
|
||||||
|
function Command.setCommand(command) end
|
||||||
|
|
||||||
|
---Execute the command block once
|
||||||
|
---@return boolean success If the command was executed successfully
|
||||||
|
---@return string|nil errorMessage Why the command failed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/command.html#v:runCommand)
|
||||||
|
function Command.runCommand() end
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---A computer or turtle wrapped as a peripheral
|
||||||
|
---
|
||||||
|
---A computer will have the type `computer` while a turtle will have the type
|
||||||
|
---`turtle`
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/computer.html)
|
||||||
|
---@class ccTweaked.peripherals.Computer
|
||||||
|
Computer = {}
|
||||||
|
|
||||||
|
---Turn the computer on
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/computer.html#v:turnOn)
|
||||||
|
function Computer.turnOn() end
|
||||||
|
|
||||||
|
---Shutdown the computer
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/computer.html#v:shutdown)
|
||||||
|
function Computer.shutdown() end
|
||||||
|
|
||||||
|
---Reboot or turn on the computer
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/computer.html#v:reboot)
|
||||||
|
function Computer.reboot() end
|
||||||
|
|
||||||
|
---Get the ID of the computer
|
||||||
|
---@return integer ID The ID of the computer
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/computer.html#v:getID)
|
||||||
|
function Computer.getID() end
|
||||||
|
|
||||||
|
---Get whether the computer is on or not
|
||||||
|
---@return boolean isOn If the computer is on
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/computer.html#v:isOn)
|
||||||
|
function Computer.isOn() end
|
||||||
|
|
||||||
|
---Get the label of the computer
|
||||||
|
---@return string|nil label The computer's label or `nil` if it does not have one
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/computer.html#v:getLabel)
|
||||||
|
function Computer.getLabel() end
|
||||||
|
|
@ -0,0 +1,115 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---Disk drives are a peripheral which allow you to read and write to floppy
|
||||||
|
---disks and other "mountable media" (such as computers or turtles). They also
|
||||||
|
---allow you to play records.
|
||||||
|
---
|
||||||
|
---When a disk drive attaches some mount (such as a floppy disk or computer), it
|
||||||
|
---attaches a folder called disk, disk2, etc... to the root directory of the
|
||||||
|
---computer. This folder can be used to interact with the files on that disk.
|
||||||
|
---
|
||||||
|
---When a disk is inserted, a `disk` event is fired, with the side peripheral is
|
||||||
|
---on. Likewise, when the disk is detached, a `disk_eject` event is fired.
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/drive.html)
|
||||||
|
---@class ccTweaked.peripherals.Drive
|
||||||
|
Drive = {}
|
||||||
|
|
||||||
|
---Checks that an item is in the drive
|
||||||
|
---@return boolean present If an item is in the drive
|
||||||
|
---Supports: 💾💿🖥️
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/drive.html#v:isDiskPresent)
|
||||||
|
function Drive.isDiskPresent() end
|
||||||
|
|
||||||
|
---Get the label of the inserted item. If the inserted item is a computer,
|
||||||
|
---this returns the label of the computer as read by `os.getComputerLabel()`
|
||||||
|
---@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
|
||||||
|
---Supports: 💾💿🖥️
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/drive.html#v:getDiskLabel)
|
||||||
|
function Drive.getDiskLabel() end
|
||||||
|
|
||||||
|
---Set the label of an inserted item.
|
||||||
|
---@param label string The new value for the label
|
||||||
|
---Supports: 💾💿🖥️
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/drive.html#v:setDiskLabel)
|
||||||
|
function Drive.setDiskLabel(label) end
|
||||||
|
|
||||||
|
---Check if an item is present and provides a mount. For records, returns false
|
||||||
|
---@return boolean hasMount
|
||||||
|
---
|
||||||
|
---Supports: 💾💿🖥️
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/drive.html#v:hasData)
|
||||||
|
function Drive.hasData() end
|
||||||
|
|
||||||
|
---Gets the path on this computer where the contents of the inserted item can be
|
||||||
|
---found
|
||||||
|
---@return string|nil path The path to the mount location or `nil` if the drive is empty or the inserted item cannot be mounted
|
||||||
|
---Supports: 💾💿🖥️
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/drive.html#v:getMountPath)
|
||||||
|
function Drive.getMountPath() end
|
||||||
|
|
||||||
|
---Checks that the inserted item is a music disk
|
||||||
|
---@return boolean hasAudio If an item is present and is a record
|
||||||
|
---Supports: 💾💿🖥️
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/drive.html#v:hasAudio)
|
||||||
|
function Drive.hasAudio() end
|
||||||
|
|
||||||
|
---Get the title of the music track from the record in the drive. This usually
|
||||||
|
---results in the same as `getLabel()` for records.
|
||||||
|
---@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
|
||||||
|
---Supports: 💾💿🖥️
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/drive.html#v:getAudioTitle)
|
||||||
|
function Drive.getAudioTitle() end
|
||||||
|
|
||||||
|
---Plays the record in the drive
|
||||||
|
---
|
||||||
|
---Make sure to check that there is an item in the drive and that it is a record with `hasData()`
|
||||||
|
---
|
||||||
|
---Stops any already playing records. The record will stop playing when it
|
||||||
|
---reaches the end of its runtime, is removed from the drive, or when stopped
|
||||||
|
---manually by `stopAudio()`
|
||||||
|
---
|
||||||
|
---Supports: 💿
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/drive.html#v:playAudio)
|
||||||
|
function Drive.playAudio() end
|
||||||
|
|
||||||
|
---Stops the currently playing record that was started with `disk.playAudio()`
|
||||||
|
---
|
||||||
|
---Supports: 💿
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/drive.html#v:stopAudio)
|
||||||
|
function Drive.stopAudio() end
|
||||||
|
|
||||||
|
---Ejects any item that is in the drive, dropping it into the world
|
||||||
|
---
|
||||||
|
---Supports: 💾💿🖥️
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/drive.html#v:ejectDisk)
|
||||||
|
function Drive.ejectDisk() end
|
||||||
|
|
||||||
|
---Get the unique identifier of the disk in the drive. Only floppy disks have an
|
||||||
|
---ID
|
||||||
|
---@return number|nil ID The ID of the floppy disk or nil if the drive is empty or does not contain a floppy disk
|
||||||
|
---Supports: 💾
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/drive.html#v:getDiskID)
|
||||||
|
function Drive.getID() end
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---Offers methods for interacting with blocks that use Forge's energy system
|
||||||
|
---
|
||||||
|
---This works with storage blocks as well as generators and machines that consume energy
|
||||||
|
---
|
||||||
|
---🗒️ Due to limitations with Forge's energy API, you cannot measure throughput (RF used/generated per tick)
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/generic_peripheral/energy_storage.html)
|
||||||
|
---@class ccTweaked.peripherals.EnergyStorage
|
||||||
|
EnergyStorage = {}
|
||||||
|
|
||||||
|
---Get the energy of this block
|
||||||
|
---@return number RF The energy stored in this block
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/generic_peripheral/energy_storage.html#v:getEnergy)
|
||||||
|
function EnergyStorage.getEnergy() end
|
||||||
|
|
||||||
|
---Get the maximum amount of energy that this block can store
|
||||||
|
---@return number RF The capacity of this block
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/generic_peripheral/energy_storage.html#v:getEnergyCapacity)
|
||||||
|
function EnergyStorage.getEnergyCapacity() end
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---Offers methods for interacting with tanks and other fluid storage blocks
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/generic_peripheral/fluid_storage.html)
|
||||||
|
---@class ccTweaked.peripherals.FluidStorage
|
||||||
|
FluidStorage = {}
|
||||||
|
|
||||||
|
---Get all "tanks" in this fluid storage
|
||||||
|
---
|
||||||
|
---Each tank either contains some amount of fluid or is empty. Tanks with fluids
|
||||||
|
---inside will return some basic information about the fluid, including its name
|
||||||
|
---and amount.
|
||||||
|
---
|
||||||
|
---The returned table is sparse, and so empty tanks will be nil - it is
|
||||||
|
---recommended to loop over using pairs rather than ipairs.
|
||||||
|
---@return table|nil[]
|
||||||
|
function FluidStorage.tanks() end
|
||||||
|
|
||||||
|
---Move a fluid from one container to another connected one
|
||||||
|
---@param toName string The name of the peripheral/container to
|
||||||
|
---@param limit? number The maximum amount of fluid to move
|
||||||
|
---@param fluidName? string The name of the fluid to move. If not given, a random fluid will be moved
|
||||||
|
---@return number fluidMoved The amount of fluid moved
|
||||||
|
---@throws If the target container doesn't exist
|
||||||
|
---@throws If the target container isn't for fluids
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/generic_peripheral/fluid_storage.html#v:pushFluid)
|
||||||
|
function FluidStorage.pushFluid(toName, limit, fluidName) end
|
||||||
|
|
||||||
|
---Move a fluid from a connected contained into this one
|
||||||
|
---
|
||||||
|
---Both containers must be attached through wired modems
|
||||||
|
---@param fromName string The name of the container to pull from
|
||||||
|
---@param limit? number The maximum amount of fluid to move
|
||||||
|
---@param fluidName? string The name of the fluid to move. If not given, a random fluid will be moved
|
||||||
|
---@return number fluidMoved The amount of fluid moved
|
||||||
|
---@throws If the source container doesn't exist
|
||||||
|
---@throws If the source container isn't for fluids
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/generic_peripheral/fluid_storage.html#v:pullFluid)
|
||||||
|
function FluidStorage.pullFluid(fromName, limit, fluidName) end
|
||||||
|
|
@ -0,0 +1,81 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---Methods for interacting with inventories
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/generic_peripheral/inventory.html)
|
||||||
|
---@class ccTweaked.peripherals.Inventory
|
||||||
|
Inventory = {}
|
||||||
|
|
||||||
|
---Get the size of this inventory
|
||||||
|
---@return number slots The number of slots in this inventory
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/generic_peripheral/inventory.html#v:size)
|
||||||
|
function Inventory.size() end
|
||||||
|
|
||||||
|
---List all items in this inventory
|
||||||
|
---
|
||||||
|
---Each item in the inventory is represented by a table containing some basic
|
||||||
|
---information, much like turtle.getItemDetail includes. More information can be
|
||||||
|
---fetched with getItemDetail. The table contains the item name, the count and an
|
||||||
|
---a (potentially nil) hash of the item's nbt. This NBT data doesn't contain
|
||||||
|
---anything useful, but allows you to distinguish identical items.
|
||||||
|
---
|
||||||
|
---The returned table is sparse, and so empty slots will be nil - it is
|
||||||
|
---recommended to loop over using pairs rather than ipairs.
|
||||||
|
---@return ccTweaked.peripherals.inventory.itemList list The list of items in this inventory
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---local chest = peripheral.find("minecraft:chest")
|
||||||
|
-----print all items in the adjacent chest
|
||||||
|
---for slot, item in pairs(chest.list()) do
|
||||||
|
--- print(("%d x %s in slot %d"):format(item.count, item.name, slot))
|
||||||
|
---end
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/generic_peripheral/inventory.html#v:list)
|
||||||
|
function Inventory.list() end
|
||||||
|
|
||||||
|
---Get detailed information about an item in this inventory
|
||||||
|
---@param slot integer The slot to get more info about
|
||||||
|
---@return table|nil info Information about the item in the slot or `nil` if no item is present
|
||||||
|
---@throws If the slot is out of range
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/generic_peripheral/inventory.html#v:getItemDetail)
|
||||||
|
function Inventory.getItemDetail(slot) end
|
||||||
|
|
||||||
|
---Get the maximum quantity of items that can be stored in this stack
|
||||||
|
---@param slot integer The slot to check
|
||||||
|
---@return integer limit The maximum number of items that can be in this stack
|
||||||
|
---@throws If the slot is out of range
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/generic_peripheral/inventory.html#v:getItemLimit)
|
||||||
|
function Inventory.getItemLimit(slot) end
|
||||||
|
|
||||||
|
---Push items from this inventory to another
|
||||||
|
---@param toName string The name of the inventory to push to
|
||||||
|
---@param sourceSlot integer The slot from this inventory to push from
|
||||||
|
---@param limit? integer The maximum number of items to move (default is the stack limit)
|
||||||
|
---@param targetSlot? integer The slot in the target inventory to push the items into (by default will insert into any slot)
|
||||||
|
---@return integer quantity The number of items transferred
|
||||||
|
---@throws If the target inventory doesn't exist
|
||||||
|
---@throws If the target inventory isn't an inventory
|
||||||
|
---@throws If the `sourceSlot` is out of range
|
||||||
|
---@throws If the `targetSlot` is out of range
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/generic_peripheral/inventory.html#v:pushItems)
|
||||||
|
function Inventory.pushItems(toName, sourceSlot, limit, targetSlot) end
|
||||||
|
|
||||||
|
---Pull items from another inventory into this one
|
||||||
|
---@param sourceName string The name of the inventory to pull from
|
||||||
|
---@param sourceSlot integer The slot of the source inventory to pull from
|
||||||
|
---@param limit? integer The maximum number of items to move (default is the stack limit)
|
||||||
|
---@param targetSlot? integer The slot in this inventory to push the items into (by default will insert into any slot)
|
||||||
|
---@return integer quantity The number of items transferred
|
||||||
|
---@throws If the source inventory doesn't exist
|
||||||
|
---@throws If the source inventory isn't an inventory
|
||||||
|
---@throws If the `sourceSlot` is out of range
|
||||||
|
---@throws If the `targetSlot` is out of range
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/generic_peripheral/inventory.html#v:pullItems)
|
||||||
|
function Inventory.pullItems(sourceName, sourceSlot, limit, targetSlot) end
|
||||||
|
|
@ -0,0 +1,74 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---Modems allow you to send messages between computers over large distances
|
||||||
|
---
|
||||||
|
---🗒️The `rednet` API builds on top of modems and is more user-friendly
|
||||||
|
---
|
||||||
|
---Modems operate on channels. Any modem can send a message on a channel, but
|
||||||
|
---only those that have opened the channel are able to receive messages.
|
||||||
|
---
|
||||||
|
---Channels are an integer between 0 and 65535 (inclusive). While these channels
|
||||||
|
---have no initial significance, certain APIs or programs can make use of
|
||||||
|
---specififc channels. For example, the `gps` module sends all of its messages on
|
||||||
|
---`gps.CHANNEL_GPS` (default is 65534), while `rednet` uses the channel equal to
|
||||||
|
---the computer's ID
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/modem.html)
|
||||||
|
---@class ccTweaked.peripherals.Modem
|
||||||
|
Modem = {}
|
||||||
|
|
||||||
|
---Open a channel on a modem
|
||||||
|
---
|
||||||
|
---A channel must be open in order to receive messages on it
|
||||||
|
---
|
||||||
|
---Modem can have 128 channels open at one time
|
||||||
|
---@param channel ccTweaked.peripherals.modem.channel The channel to open (0 - 65535)
|
||||||
|
---@throws If the `channel` is out of range
|
||||||
|
---@throws If there are too many open channels
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/modem.html#v:open)
|
||||||
|
function Modem.open(channel) end
|
||||||
|
|
||||||
|
---Check if a channel is open or not
|
||||||
|
---@param channel ccTweaked.peripherals.modem.channel The channel to check (0 - 65535)
|
||||||
|
---@return boolean isOpen If the channel is open
|
||||||
|
---@throws If the `channel` is out of range
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/modem.html#v:isOpen)
|
||||||
|
function Modem.isOpen(channel) end
|
||||||
|
|
||||||
|
---Close an open channel so that it no longer receives messages
|
||||||
|
---@param channel ccTweaked.peripherals.modem.channel The channel to close (0 - 65535)
|
||||||
|
---@throws If the `channel` is out of range
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/modem.html#v:close)
|
||||||
|
function Modem.close(channel) end
|
||||||
|
|
||||||
|
---Close all open channels
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/modem.html#v:closeAll)
|
||||||
|
function Modem.closeAll() end
|
||||||
|
|
||||||
|
---Sends a message on the specified channel over the modem
|
||||||
|
---
|
||||||
|
---Modems listening on the specified channel will queue a `modem_message` event
|
||||||
|
---on any parent computers
|
||||||
|
---@param channel ccTweaked.peripherals.modem.channel The channel to send the message on (does not need to be open)
|
||||||
|
---@param replyChannel ccTweaked.peripherals.modem.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
|
||||||
|
---@param payload boolean|string|number|table The payload of the message to send
|
||||||
|
---@throws If the channel is out of range
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---local modem = peripheral.find("modem") or error("No modem attached", 0)
|
||||||
|
---modem.transmit(15, 43, "Hello, world!")
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/modem.html#v:transmit)
|
||||||
|
function Modem.transmit(channel, replyChannel, payload) end
|
||||||
|
|
||||||
|
---Get whether this modem is wireless or wired
|
||||||
|
---@return boolean isWireless If this modem is wireless
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/modem.html#v:isWireless)
|
||||||
|
function Modem.isWireless() end
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---Monitors are a block that can display the terminal on one side. This allows
|
||||||
|
---them to be viewed and interacted with without opening a GUI
|
||||||
|
---
|
||||||
|
---Monitors act as terminal redirects and share the same methods, as well as some additional ones
|
||||||
|
---
|
||||||
|
---Like computers, monitors come in both normal (no color) and advanced (color) varieties
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/monitor.html)
|
||||||
|
---@class ccTweaked.peripherals.Monitor: ccTweaked.term.Redirect
|
||||||
|
Monitor = {}
|
||||||
|
|
||||||
|
---Set the scale of text on this monitor. A larger scale will have a lower resolution but larger text
|
||||||
|
---@param scale number The scale of the monitor. Must be a multiple of 0.5 between 0.5 and 5
|
||||||
|
---@throws If the `scale` is out of range
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/monitor.html#v:setTextScale)
|
||||||
|
function Monitor.setTextScale(scale) end
|
||||||
|
|
||||||
|
---Get the current text scale
|
||||||
|
---@return number scale The current text scale for this monitor
|
||||||
|
---@throws If the monitor cannot be found
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/monitor.html#v:getTextScale)
|
||||||
|
function Monitor.getTextScale() end
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---The Player Detector is a useful peripheral that allows you to detect players within a certain range, position and area.
|
||||||
|
---You can get a list of all online players and detect when a player clicks on the block.
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://docs.advanced-peripherals.de/0.7/peripherals/player_detector/)
|
||||||
|
---@class ccTweaked.peripherals.PlayerDetector
|
||||||
|
PlayerDetector = {}
|
||||||
|
|
||||||
|
---Get the position of a player.
|
||||||
|
---@param username string
|
||||||
|
---@return table | nil
|
||||||
|
function PlayerDetector.getPlayerPos(username) end
|
||||||
|
|
||||||
|
---Get a list of online players.
|
||||||
|
---@return table
|
||||||
|
function PlayerDetector.getOnlinePlayers() end
|
||||||
|
|
||||||
|
---Get a list of players within a range.
|
||||||
|
---@param range number
|
||||||
|
---@return table
|
||||||
|
function PlayerDetector.getPlayersInRange(range) end
|
||||||
|
|
@ -0,0 +1,72 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---The printer peripheral allows you to print pages and books
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/printer.html)
|
||||||
|
---@class ccTweaked.peripherals.Printer
|
||||||
|
Printer = {}
|
||||||
|
|
||||||
|
---Writes text to the currently active page
|
||||||
|
---@param ... string|number The values to write to the current page
|
||||||
|
---@throws If no page is started
|
||||||
|
---@throws If any values couldn't be converted to a string
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/printer.html#v:write)
|
||||||
|
function Printer.write(...) end
|
||||||
|
|
||||||
|
---Get the current position of the cursor on the page
|
||||||
|
---@return number x The x position of the cursor
|
||||||
|
---@return number y The y position of the cursor
|
||||||
|
---@throws If a page isn't being printed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/printer.html#v:getCursorPos)
|
||||||
|
function Printer.getCursorPos() end
|
||||||
|
|
||||||
|
---Set the current position of the cursor on the page
|
||||||
|
---@param x number The new x coordinate of the cursor
|
||||||
|
---@param y number The new y coordinate of the cursor
|
||||||
|
---@throws If a page isn't being printed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/printer.html#v:setCursorPos)
|
||||||
|
function Printer.setCursorPos(x, y) end
|
||||||
|
|
||||||
|
---Get the size of the current page
|
||||||
|
---@return number width The width of the current page
|
||||||
|
---@return number height The height of the current page
|
||||||
|
---@throws If a page isn't being printed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/printer.html#v:getPageSize)
|
||||||
|
function Printer.getPageSize() end
|
||||||
|
|
||||||
|
---Starts printing a new page
|
||||||
|
---@return boolean success Whether a new page could be started or not
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/printer.html#v:newPage)
|
||||||
|
function Printer.newPage() end
|
||||||
|
|
||||||
|
---Finish printing the current page and feed it into the output tray
|
||||||
|
---@return boolean success Whether the page could be finalized or not
|
||||||
|
---@throws If a page isn't being printed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/printer.html#v:endPage)
|
||||||
|
function Printer.endPage() end
|
||||||
|
|
||||||
|
---Set the title of the current page
|
||||||
|
---@param title? string The title to set for the current page
|
||||||
|
---@throws If a page isn't being printed
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/printer.html#v:setPageTitle)
|
||||||
|
function Printer.setPageTitle(title) end
|
||||||
|
|
||||||
|
---Get the amount of ink remaining in the printer
|
||||||
|
---@return number ink The amount of ink left in the printer
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/printer.html#v:getInkLevel)
|
||||||
|
function Printer.getInkLevel() end
|
||||||
|
|
||||||
|
---Get the amount of paper left in the printer
|
||||||
|
---@return number pages The amount of paper left in the printer
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/printer.html#v:getPaperLevel)
|
||||||
|
function Printer.getPaperLevel() end
|
||||||
|
|
@ -0,0 +1,81 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---The speaker peripheral allows you to play music discs, notes, Minecraft
|
||||||
|
---sounds, and custom audio
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/speaker.html)
|
||||||
|
---@class ccTweaked.peripherals.Speaker
|
||||||
|
Speaker = {}
|
||||||
|
|
||||||
|
---Plays a note through the speaker
|
||||||
|
---
|
||||||
|
---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.
|
||||||
|
---
|
||||||
|
---A maximum of 8 notes can be played in a single tick. If this limit is hit, this function will return false.
|
||||||
|
---@param instrument ccTweaked.peripherals.speaker.instrument The instrument to play on
|
||||||
|
---@param volume? number The volume to play at (0.0 - 3.0, defaults to 1.0)
|
||||||
|
---@param pitch? number The pitch to play at in semitones from 0 to 24 (defaults to 12)
|
||||||
|
---@return boolean success If the note could be played or if the limit was reached
|
||||||
|
---@throws If the `instrument` does not exist
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/speaker.html#v:playNote)
|
||||||
|
function Speaker.playNote(instrument, volume, pitch) end
|
||||||
|
|
||||||
|
---Play a Minecraft sound through the speaker
|
||||||
|
---
|
||||||
|
---Only one sound can be played at once. This function will return false if
|
||||||
|
---another sound was started this tick, or if some audio is still playing.
|
||||||
|
---@param name ccTweaked.peripherals.speaker.soundEffect The name of the sound to play
|
||||||
|
---@param volume? number The volume to play at (0.0 - 3.0, defaults to 1.0)
|
||||||
|
---@param pitch? number The speed to play at (0.5 - 2.0, defaults to 12)
|
||||||
|
---@return boolean success If the sound could be played
|
||||||
|
---@throws If the sound name was invalid
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---local speaker = peripheral.find("speaker")
|
||||||
|
---speaker.playSound("entity.creeper.primed")
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/speaker.html#v:playSound)
|
||||||
|
function Speaker.playSound(name, volume, pitch) end
|
||||||
|
|
||||||
|
---Attempt to stream audio to the speaker
|
||||||
|
---
|
||||||
|
---This accepts a list of audio samples as amplitudes between -128 and 127.
|
||||||
|
---These are stored in an internal buffer and played back at 48kHz. If this
|
||||||
|
---buffer is full, this function will return false. You should wait for a
|
||||||
|
---`speaker_audio_empty` event before trying again.
|
||||||
|
---
|
||||||
|
---🗒️ The speaker only buffers a single call to `playAudio()` at once. This means
|
||||||
|
---if you try to play a small number of samples, you'll have a lot of stutter.
|
||||||
|
---You should try to play as many samples in one call as possible (up to
|
||||||
|
---128×1024), as this reduces the chances of audio stuttering or halting,
|
||||||
|
---especially when the server or computer is lagging.
|
||||||
|
---@param audio number[] An array of amplitudes
|
||||||
|
---@param volume? number The volume to play the audio at. Defaults to the previous value given
|
||||||
|
---@return boolean success If there was room to accept the audio data
|
||||||
|
---@throws If the audio data is malformed
|
||||||
|
---## Example
|
||||||
|
---```
|
||||||
|
---local dfpwm = require("cc.audio.dfpwm")
|
||||||
|
---local speaker = peripheral.find("speaker")
|
||||||
|
---
|
||||||
|
---local decoder = dfpwm.make_decoder()
|
||||||
|
---for chunk in io.lines("data/example.dfpwm", 16 * 1024) do
|
||||||
|
--- local buffer = decoder(chunk)
|
||||||
|
---
|
||||||
|
--- while not speaker.playAudio(buffer) do
|
||||||
|
--- os.pullEvent("speaker_audio_empty")
|
||||||
|
--- end
|
||||||
|
---end
|
||||||
|
---```
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/speaker.html#v:playAudio)
|
||||||
|
function Speaker.playAudio(audio, volume) end
|
||||||
|
|
||||||
|
---Stop all audio being played by this speaker
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/speaker.html#v:stop)
|
||||||
|
function Speaker.stop() end
|
||||||
|
|
@ -0,0 +1,70 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---Modems allow you to send messages between computers over large distances
|
||||||
|
---
|
||||||
|
---🗒️The `rednet` API builds on top of modems and is more user-friendly
|
||||||
|
---
|
||||||
|
---Modems operate on channels. Any modem can send a message on a channel, but
|
||||||
|
---only those that have opened the channel are able to receive messages.
|
||||||
|
---
|
||||||
|
---Channels are an integer between 0 and 65535 (inclusive). While these channels
|
||||||
|
---have no initial significance, certain APIs or programs can make use of
|
||||||
|
---specififc channels. For example, the `gps` module sends all of its messages on
|
||||||
|
---`gps.CHANNEL_GPS` (default is 65534), while `rednet` uses the channel equal to
|
||||||
|
---the computer's ID
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/modem.html)
|
||||||
|
---@class ccTweaked.peripherals.WiredModem: ccTweaked.peripherals.Modem
|
||||||
|
WiredModem = {}
|
||||||
|
|
||||||
|
---List all peripherals on the wired network
|
||||||
|
---
|
||||||
|
---If this computer is attached to the network, it **will not** be included in this list
|
||||||
|
---@return string[] peripherals Remote peripheral names on the network
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/modem.html#v:getNamesRemote)
|
||||||
|
function WiredModem.getNamesRemote() end
|
||||||
|
|
||||||
|
---Get if a peripheral is available on this wired network
|
||||||
|
---@param name string The peripheral's name
|
||||||
|
---@return boolean isPresent If a peripheral with the given name is present
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/modem.html#v:isPresentRemote)
|
||||||
|
function WiredModem.isPresentRemote(name) end
|
||||||
|
|
||||||
|
---Get the type of a peripheral on this wired network
|
||||||
|
---@param name string The peripheral's name
|
||||||
|
---@return ccTweaked.peripherals.type|nil type The peripheral's type or `nil` if it is not present
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/modem.html#v:getTypeRemote)
|
||||||
|
function WiredModem.getTypeRemote(name) end
|
||||||
|
|
||||||
|
---Check that a peripheral is of a given type
|
||||||
|
---@param name string The peripheral's name
|
||||||
|
---@param type ccTweaked.peripherals.type The type to check
|
||||||
|
---@return boolean|nil isType If a peripheral has a given type or `nil` if it is not present
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/modem.html#v:hasTypeRemote)
|
||||||
|
function WiredModem.hasTypeRemote(name, type) end
|
||||||
|
|
||||||
|
---Get the names of the methods for a peripheral with the provided name
|
||||||
|
---@param name string The peripheral's name
|
||||||
|
---@return string[]|nil methods An array of method names or `nil` if it is not present
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/modem.html#v:getMethodsRemote)
|
||||||
|
function WiredModem.getMethodsRemote(name) end
|
||||||
|
|
||||||
|
---Call a method on a peripheral on this wired network
|
||||||
|
---@param name string The name of the peripheral to invoke the method on
|
||||||
|
---@param method string The name of the method to call
|
||||||
|
---@param ... any Args to pass to the method
|
||||||
|
---@return any ... The return values of the method
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/modem.html#v:callRemote)
|
||||||
|
function WiredModem.callRemote(name, method, ...) end
|
||||||
|
|
||||||
|
---Get the network name of the current computer, if the modem is on
|
||||||
|
---@return string|nil name The current computer's name on the wired network on `nil` if the modem is off
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/peripheral/modem.html#v:getNameLocal)
|
||||||
|
function WiredModem.getNameLocal() end
|
||||||
|
|
@ -0,0 +1,55 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---@alias ccTweaked.os.locale
|
||||||
|
---| '"ingame"' # The current world time
|
||||||
|
---| '"utc"' # Get the hour of the day in UTC time
|
||||||
|
---| '"local"' # Get the hour of the day in the timezone that the server is located in
|
||||||
|
|
||||||
|
---@class ccTweaked.os.dateTable
|
||||||
|
---@field year integer year number
|
||||||
|
---@field yday integer day of the year
|
||||||
|
---@field wday integer day of the week
|
||||||
|
---@field month integer month of the year
|
||||||
|
---@field day integer day of the month
|
||||||
|
---@field hour integer hour of the day
|
||||||
|
---@field min integer Minute of the hour
|
||||||
|
---@field sec integer Seconds of the minute
|
||||||
|
---@field isdst boolean If Daylight Saving Time is in effect
|
||||||
|
|
||||||
|
---@alias ccTweaked.os.ASCII number An [ASCII code](https://www.rapidtables.com/code/text/ascii-table.html) that corresponds to a character
|
||||||
|
|
||||||
|
---@alias ccTweaked.os.event
|
||||||
|
---| '"alarm"' # Fired when an alarm started with `os.setAlarm()` completes.<hr/>[Official Documentation](https://tweaked.cc/event/alarm.html)
|
||||||
|
---| '"char"' # Fired when a key is typed on the keyboard. Only captures characters, not control keys.<hr/>[Official Documentation](https://tweaked.cc/event/char.html)
|
||||||
|
---| '"computer_command"' # Fired when the `/computercraft queue` command is run for the current computer.<hr/>[Official Documentation](https://tweaked.cc/event/computer_command.html)
|
||||||
|
---| '"disk"' # Fired when a disk is inserted into an adjacent or networked disk drive.<hr/>[Official Documentation](https://tweaked.cc/event/disk.html)
|
||||||
|
---| '"disk_eject"' # Fired when a disk is removed from an adjacent or networked disk drive.<hr/>[Official Documentation](https://tweaked.cc/event/disk_eject.html)
|
||||||
|
---| '"http_check"' # Fired when a URL check completes.<hr/>[Official Documentation](https://tweaked.cc/event/http_check.html)
|
||||||
|
---| '"http_failure"' # Fired when an HTTP request fails.<hr/>[Official Documentation](https://tweaked.cc/event/http_failure.html)
|
||||||
|
---| '"http_success"' # Fired when an HTTP request succeeds.<hr/>[Official Documentation](https://tweaked.cc/event/http_success.html)
|
||||||
|
---| '"key"' # Fired when any key is pressed while the terminal is focused. For text input, use a `char` event.<hr/>[Official Documentation](https://tweaked.cc/event/key.html)
|
||||||
|
---| '"key_up"' # Fired when a key is released (or the terminal is closed while a key was pressed).<hr/>[Official Documentation](https://tweaked.cc/event/key_up.html)
|
||||||
|
---| '"modem_message"' # Fired when a message is received on an open channel on any modem.<hr/>[Official Documentation](https://tweaked.cc/event/modem_message.html)
|
||||||
|
---| '"monitor_resize"' # Fired when an adjacent or networked monitor is resized.<hr/>[Official Documentation](https://tweaked.cc/event/monitor_resize.html)
|
||||||
|
---| '"monitor_touch"' # Fired when an adjacent or networked **advanced** monitor is right-clicked.<hr/>[Official Documentation](https://tweaked.cc/event/monitor_touch.html)
|
||||||
|
---| '"mouse_click"' # Fired when an advanced/pocket computer is clicked with a mouse.<hr/>[Official Documentation](https://tweaked.cc/event/mouse_click.html)
|
||||||
|
---| '"mouse_drag"' # Fired when the mouse is moved while a mouse button is being held.<hr/>[Official Documentation](https://tweaked.cc/event/mouse_drag.html)
|
||||||
|
---| '"mouse_scroll"' # Fired when a mouse wheel is scrolled in the terminal.<hr/>[Official Documentation](https://tweaked.cc/event/mouse_scroll.html)
|
||||||
|
---| '"mouse_up"' # Fired when a mouse button is released or leaves the terminal.<hr/>[Official Documentation](https://tweaked.cc/event/mouse_up.html)
|
||||||
|
---| '"paste"' # Fired when text is pasted into the computer.<hr/>[Official Documentation](https://tweaked.cc/event/paste.html)
|
||||||
|
---| '"peripheral"' # Fired when a peripheral is attached to a side or a modem.<hr/>[Official Documentation](https://tweaked.cc/event/peripheral.html)
|
||||||
|
---| '"peripheral_detach"' # Fired when a peripheral is removed from a side or modem.<hr/>[Official Documentation](https://tweaked.cc/event/peripheral_detach.html)
|
||||||
|
---| '"rednet_message"' # Fired when a message is received over rednet.<hr/>[Official Documentation](https://tweaked.cc/event/rednet_message.html)
|
||||||
|
---| '"redstone"' # Fired when a redstone input on a side is changed.<hr/>[Official Documentation](https://tweaked.cc/event/redstone.html)
|
||||||
|
---| '"speaker_audio_empty"' # Fired when a speaker's audio has ended.<hr/>[Official Documentation](https://tweaked.cc/event/speaker_audio_empty.html)
|
||||||
|
---| '"task_complete"' # Fired when an asynchronous completes.<hr/>[Official Documentation](https://tweaked.cc/event/task_complete.html)
|
||||||
|
---| '"term_resize"' # Fired when the main terminal is resized.<hr/>[Official Documentation](https://tweaked.cc/event/term_resize.html)
|
||||||
|
---| '"terminate"' # Fired when `CTRL + T` is held down.<hr/>[Official Documentation](https://tweaked.cc/event/terminate.html)
|
||||||
|
---| '"timer"' # Fired when a timer started with `os.startTimer()` completes.<hr/>[Official Documentation](https://tweaked.cc/event/timer.html)
|
||||||
|
---| '"turtle_inventory"' # Fired when a turtle's inventory changes.<hr/>[Official Documentation](https://tweaked.cc/event/turtle_inventory.html)
|
||||||
|
---| '"websocket_closed"' # Fired when a websocket connection is closed.<hr/>[Official Documentation](https://tweaked.cc/event/websocket_closed.html)
|
||||||
|
---| '"websocket_failure"' # Fired when a websocket connection fails.<hr/>[Official Documentation](https://tweaked.cc/event/websocket_failure.html)
|
||||||
|
---| '"websocket_message"' # Fired when a websocket message is received.<hr/>[Official Documentation](https://tweaked.cc/event/websocket_message.html)
|
||||||
|
---| '"websocket_success"' # Fired when a websocket connection succeeds.<hr/>[Official Documentation](https://tweaked.cc/event/websocket_success.html)
|
||||||
|
---| '"file_transfer"' # Fired when a file is dragged and dropped on an open computer.<hr/>[Official Documentation](https://tweaked.cc/event/file_transfer.html)
|
||||||
|
---| string
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,19 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---@alias ccTweaked.redstone.signalStrength
|
||||||
|
---| 0
|
||||||
|
---| 1
|
||||||
|
---| 2
|
||||||
|
---| 3
|
||||||
|
---| 4
|
||||||
|
---| 5
|
||||||
|
---| 6
|
||||||
|
---| 7
|
||||||
|
---| 8
|
||||||
|
---| 9
|
||||||
|
---| 10
|
||||||
|
---| 11
|
||||||
|
---| 12
|
||||||
|
---| 13
|
||||||
|
---| 14
|
||||||
|
---| 15
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---@class ccTweaked.settings.settingOptions
|
||||||
|
---@field description string A description of the setting
|
||||||
|
---@field default any The default value of the setting
|
||||||
|
---@field type type Require values to be of this type. Setting to another value will raise an error
|
||||||
|
|
||||||
|
---@class ccTweaked.settings.settingDetails: ccTweaked.settings.settingOptions
|
||||||
|
---@field value any The value of this setting
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---@alias ccTweaked.shell.completionFunction fun(shell: ccTweaked.shell, index: integer, argument: string, previous: string[]): string[]? The completion function to use for completion
|
||||||
|
|
||||||
|
---@alias ccTweaked.shell.completionInfo table<string, completionInfo>
|
||||||
|
---@class completionInfo
|
||||||
|
---@field fnComplete ccTweaked.shell.completionFunction
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---@class ccTweaked.textutils.serializationOptions
|
||||||
|
---@field compact? boolean Do not emit whitespace characters
|
||||||
|
---@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
|
||||||
|
|
||||||
|
---@class ccTweaked.textutils.unserializeJSONOptions
|
||||||
|
---@field nbt_style? boolean When true, this will accept stringified NBT strings, as produced by many commands.
|
||||||
|
---@field parse_null? boolean When true, `null` will be parsed as `textutils.json_null` instead of `nil`
|
||||||
|
---@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`
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---@alias ccTweaked.turtle.side
|
||||||
|
---| '"left"'
|
||||||
|
---| '"right"'
|
||||||
|
|
||||||
|
---@alias ccTweaked.turtle.slot
|
||||||
|
---| 1
|
||||||
|
---| 2
|
||||||
|
---| 3
|
||||||
|
---| 4
|
||||||
|
---| 5
|
||||||
|
---| 6
|
||||||
|
---| 7
|
||||||
|
---| 8
|
||||||
|
---| 9
|
||||||
|
---| 10
|
||||||
|
---| 11
|
||||||
|
---| 12
|
||||||
|
---| 13
|
||||||
|
---| 14
|
||||||
|
---| 15
|
||||||
|
---| 16
|
||||||
|
|
||||||
|
---@class ccTweaked.turtle.inspectInfo
|
||||||
|
---@field name string The name of the block
|
||||||
|
---@field state table<string, any> The state of the block
|
||||||
|
---@field tags table<string, boolean> The tags of the block
|
||||||
|
|
||||||
|
---@class ccTweaked.turtle.slotInfo
|
||||||
|
---@field name string The name of the item
|
||||||
|
---@field count integer The number of items in this slot
|
||||||
|
|
||||||
|
---@class ccTweaked.turtle.slotInfoDetailed
|
||||||
|
---@field name string The name of the item
|
||||||
|
---@field count integer The number of items in this slot
|
||||||
|
---@field maxCount integer The max number of items that can be in this stack
|
||||||
|
---@field displayName string The display name of this item
|
||||||
|
---@field tags table<string, boolean> The tags of this item
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---The vector API allows you to create a `Vector` object
|
||||||
|
---
|
||||||
|
---[Vectors on Wikipedia](http://en.wikipedia.org/wiki/Euclidean_vector)
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/vector.html)
|
||||||
|
vector = {}
|
||||||
|
|
||||||
|
---Create a new `Vector` object with the given coordinates
|
||||||
|
---@param x number The x coordinate or direction
|
||||||
|
---@param y number The y coordinate or direction
|
||||||
|
---@param z number The z coordinate or direction
|
||||||
|
---@return ccTweaked.Vector vector A new `Vector` object
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/vector.html#v:new)
|
||||||
|
function vector.new(x, y, z) end
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---The window API lets you create `Window` objects for redirecting the terminal
|
||||||
|
---to smaller windows
|
||||||
|
---
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/window.html)
|
||||||
|
window = {}
|
||||||
|
|
||||||
|
---Create a `Window` object that can be used as a terminal redirect
|
||||||
|
---@param parent ccTweaked.term.Redirect|ccTweaked.peripherals.Monitor The parent terminal to draw to
|
||||||
|
---@param x number The x position of this window within the parent
|
||||||
|
---@param y number The y position of this window within the parent
|
||||||
|
---@param width number The width of this window
|
||||||
|
---@param height number The height of this window
|
||||||
|
---@param visible? boolean If this window should immediately be visible (defaults to true)
|
||||||
|
---@return ccTweaked.Window window The window object
|
||||||
|
------
|
||||||
|
---[Official Documentation](https://tweaked.cc/module/window.html#v:create)
|
||||||
|
function window.create(parent, x, y, width, height, visible) end
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
return {
|
||||||
|
prefix = "!",
|
||||||
|
|
||||||
|
users = {
|
||||||
|
["MinishCaps"] = {
|
||||||
|
subscribeLog = true,
|
||||||
|
admin = true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,150 @@
|
||||||
|
local cfg = require("cfg")
|
||||||
|
|
||||||
|
local boxes = { peripheral.find("chat_box") }
|
||||||
|
|
||||||
|
local function ssleep(seconds)
|
||||||
|
local fireAt = os.time() + (seconds / 50)
|
||||||
|
local enqueued = {}
|
||||||
|
|
||||||
|
os.setAlarm(fireAt)
|
||||||
|
|
||||||
|
while true do
|
||||||
|
local ev = { os.pullEventRaw() }
|
||||||
|
if ev[1] == "alarm" then
|
||||||
|
break
|
||||||
|
else
|
||||||
|
table.insert(enqueued, ev)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, ev in next, enqueued do
|
||||||
|
os.queueEvent(table.unpack(ev))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local curBox = 1
|
||||||
|
local lastResetAt = 0
|
||||||
|
|
||||||
|
local function dispatch(callback)
|
||||||
|
local bx = boxes[curBox]
|
||||||
|
if bx ~= nil then
|
||||||
|
callback(bx)
|
||||||
|
end
|
||||||
|
|
||||||
|
if curBox >= #boxes then
|
||||||
|
local sinceReset = os.clock() - lastResetAt
|
||||||
|
if sinceReset < 1 then
|
||||||
|
ssleep(1 - sinceReset)
|
||||||
|
end
|
||||||
|
|
||||||
|
curBox = 1
|
||||||
|
lastResetAt = os.clock()
|
||||||
|
else
|
||||||
|
curBox = curBox + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function send(unm, msg, chan)
|
||||||
|
local prefix = "&bSky"
|
||||||
|
|
||||||
|
if chan then
|
||||||
|
prefix = prefix .. "&7/&3" .. chan
|
||||||
|
end
|
||||||
|
|
||||||
|
prefix = prefix .. "&r"
|
||||||
|
|
||||||
|
if type(msg) ~= "table" then
|
||||||
|
msg = { { text = msg } }
|
||||||
|
end
|
||||||
|
|
||||||
|
dispatch(function(bx)
|
||||||
|
bx.sendFormattedMessageToPlayer(
|
||||||
|
textutils.serialiseJSON(msg),
|
||||||
|
unm,
|
||||||
|
prefix, "[]"
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function userBc(msg, cat, logChan)
|
||||||
|
for i, v in pairs(cfg.users) do
|
||||||
|
if logChan then
|
||||||
|
if v.subscribeLog == true then
|
||||||
|
send(i, msg, cat or "log")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
send(i, msg, cat)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function reportLog(msg, cat)
|
||||||
|
userBc(msg, cat, true)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function say(msg)
|
||||||
|
dispatch(function(bx)
|
||||||
|
bx.sendMessage(msg, ":", "<>")
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function faketpa(tgtplr, sender, fakeplr, fakemsg)
|
||||||
|
dispatch(function(bx)
|
||||||
|
local clickEvent = {
|
||||||
|
action = "open_url",
|
||||||
|
value = "https://picture.wtf/p/27wzu9.png",
|
||||||
|
}
|
||||||
|
|
||||||
|
local msg = {
|
||||||
|
{ text = fakemsg },
|
||||||
|
{ text = "\nTPA request! [ " },
|
||||||
|
{ text = sender, color = "yellow" },
|
||||||
|
{ text = " !ARROWEMJ! " },
|
||||||
|
{ text = tgtplr, color = "yellow" },
|
||||||
|
{ text = " ]" },
|
||||||
|
{ text = "\nClick one of these: " },
|
||||||
|
{
|
||||||
|
text = "Accept !ACCEPTEMJ!",
|
||||||
|
color = "green",
|
||||||
|
bold = true,
|
||||||
|
hoverEvent = {
|
||||||
|
action = "show_text",
|
||||||
|
contents = "Click to Accept",
|
||||||
|
},
|
||||||
|
clickEvent = clickEvent,
|
||||||
|
},
|
||||||
|
{ text = " | " },
|
||||||
|
{
|
||||||
|
text = "Deny !DENYEMJ!",
|
||||||
|
color = "red",
|
||||||
|
bold = true,
|
||||||
|
hoverEvent = {
|
||||||
|
action = "show_text",
|
||||||
|
contents = "Click to Deny",
|
||||||
|
},
|
||||||
|
clickEvent = clickEvent,
|
||||||
|
},
|
||||||
|
{ text = " |" },
|
||||||
|
}
|
||||||
|
local jsonMsg = textutils.serialiseJSON(msg)
|
||||||
|
jsonMsg = jsonMsg:gsub("!ARROWEMJ!", "\\u27A1")
|
||||||
|
jsonMsg = jsonMsg:gsub("!ACCEPTEMJ!", "\\u2714")
|
||||||
|
jsonMsg = jsonMsg:gsub("!DENYEMJ!", "\\u274C")
|
||||||
|
|
||||||
|
bx.sendFormattedMessageToPlayer(
|
||||||
|
jsonMsg,
|
||||||
|
tgtplr,
|
||||||
|
fakeplr, "<>",
|
||||||
|
nil, nil,
|
||||||
|
true
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
send = send,
|
||||||
|
userBc = userBc,
|
||||||
|
reportLog = reportLog,
|
||||||
|
say = say,
|
||||||
|
faketpa = faketpa,
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,269 @@
|
||||||
|
-- Skynet v1.2 // server
|
||||||
|
-- orig. written by minish - 2023-10
|
||||||
|
-- revived 2025-01
|
||||||
|
|
||||||
|
--#region Imports
|
||||||
|
local cfg = require("cfg")
|
||||||
|
local ch = require("chat")
|
||||||
|
local tk = require("tracking")
|
||||||
|
--#endregion
|
||||||
|
|
||||||
|
--#region Machine Preparation
|
||||||
|
settings.set("shell.allow_disk_startup", false)
|
||||||
|
--#endregion
|
||||||
|
|
||||||
|
local function q(v)
|
||||||
|
return tostring(v or "??")
|
||||||
|
end
|
||||||
|
|
||||||
|
local cmds = {
|
||||||
|
loc = function(unm, args)
|
||||||
|
local tg = tk:resTg(args[1])
|
||||||
|
if not tg then
|
||||||
|
ch.send(unm, "missing target!", "loc")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
tk:refreshOne(tg)
|
||||||
|
local p = tk.plrs[tg]
|
||||||
|
if not p then
|
||||||
|
ch.send(unm, "couldn't locate target", "loc")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
ch.send(unm, string.format("user: %s xyz:[%s, %s, %s] dim=%s", tg, q(p.x), q(p.y), q(p.z), q(p.dimension)))
|
||||||
|
end,
|
||||||
|
rpt = function(unm, args)
|
||||||
|
tk:refresh()
|
||||||
|
|
||||||
|
local ins = table.insert
|
||||||
|
|
||||||
|
local mparts = {}
|
||||||
|
ins(mparts, { text = "finished generating report!\n" })
|
||||||
|
|
||||||
|
local n, nplrs = 0, 0
|
||||||
|
for _, _ in next, tk.plrs do nplrs = nplrs + 1 end
|
||||||
|
for i, v in pairs(tk.plrs) do
|
||||||
|
local line = string.format("user: %s xyz:[%s, %s, %s] dim=%s", i, q(v.x), q(v.y), q(v.z), q(v.dimension))
|
||||||
|
n = n + 1
|
||||||
|
if n ~= nplrs then
|
||||||
|
line = line .. "\n"
|
||||||
|
end
|
||||||
|
|
||||||
|
ins(mparts, { text = "[" })
|
||||||
|
ins(mparts, { text = "s", color = "aqua" })
|
||||||
|
ins(mparts, { text = "] " .. line })
|
||||||
|
end
|
||||||
|
|
||||||
|
ch.send(unm, mparts, "rpt")
|
||||||
|
end,
|
||||||
|
unsublog = function(unm, args)
|
||||||
|
if not cfg.users[unm].subscribeLog then
|
||||||
|
ch.send(unm, "you're already aren't subscribed!", "users")
|
||||||
|
ch.reportLog("user " .. unm .. " tries log unsub, but they weren't there")
|
||||||
|
else
|
||||||
|
cfg.users[unm].subscribeLog = false
|
||||||
|
ch.reportLog("user " .. unm .. " unsubscribes from log")
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
sublog = function(unm, args)
|
||||||
|
if cfg.users[unm].subscribeLog then
|
||||||
|
ch.send(unm, "you're already subscribed!", "users")
|
||||||
|
ch.reportLog("user " .. unm .. " tries log sub, but already there")
|
||||||
|
else
|
||||||
|
cfg.users[unm].subscribeLog = true
|
||||||
|
ch.reportLog("user " .. unm .. " subscribes to log")
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
allow = function(unm, args)
|
||||||
|
local tg = tk:resTg(args[1])
|
||||||
|
if not tg then
|
||||||
|
ch.send(unm, "No user was specified!", "users")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if cfg.users[tg] ~= nil then
|
||||||
|
ch.send(unm, "They're already allowed!!", "users")
|
||||||
|
ch.reportLog("user " .. unm .. " tries to allow " .. tg .. ", but they already are")
|
||||||
|
else
|
||||||
|
cfg.users[tg] = {}
|
||||||
|
ch.reportLog("user " .. unm .. " allows " .. tg)
|
||||||
|
ch.send(tg, "You were added to skynet, welcome!! // try $help for list of commands", "users")
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
disallow = function(unm, args)
|
||||||
|
local tg = tk:resTg(args[1])
|
||||||
|
if not tg then
|
||||||
|
ch.send(unm, "No user was specified!", "users")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if cfg.users[tg] == nil then
|
||||||
|
ch.send(unm, "That person is already disallowed", "users")
|
||||||
|
ch.reportLog("user " .. unm .. " tries to disallow " .. tg .. ", but they already are")
|
||||||
|
else
|
||||||
|
cfg.users[tg] = nil
|
||||||
|
ch.reportLog("user " .. unm .. " disallows " .. tg)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
ping = function(unm, args)
|
||||||
|
ch.send(unm, "Alive!!!!")
|
||||||
|
end,
|
||||||
|
shutdown = function(unm, args)
|
||||||
|
if cfg.users[unm].admin then
|
||||||
|
ch.reportLog("system shutdown requested by " .. unm)
|
||||||
|
ch.userBc("Shutting down..")
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
ch.reportLog("non-admin user " .. unm .. " attempted to shutdown")
|
||||||
|
ch.send(unm, "no permission to do that..", "cmd")
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
say = function(unm, args)
|
||||||
|
local msg = table.concat(args, " ")
|
||||||
|
|
||||||
|
ch.say(msg)
|
||||||
|
end,
|
||||||
|
faketpa = function(unm, args)
|
||||||
|
local tgtplr = table.remove(args, 1)
|
||||||
|
local sender = table.remove(args, 1)
|
||||||
|
local fakeplr = table.remove(args, 1)
|
||||||
|
local fakemsg = table.concat(args, " ")
|
||||||
|
|
||||||
|
if not tgtplr then
|
||||||
|
ch.send(unm, "no target player specified", "cmd")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if not sender then
|
||||||
|
ch.send(unm, "no sender name specified", "cmd")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if not fakeplr then
|
||||||
|
ch.send(unm, "no fake player specified", "cmd")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
tgtplr = tk:resTg(tgtplr)
|
||||||
|
if not tgtplr then
|
||||||
|
ch.send(unm, "target player specified not found", "cmd")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
ch.faketpa(tgtplr, sender, fakeplr, fakemsg)
|
||||||
|
end,
|
||||||
|
help = function(unm, args)
|
||||||
|
ch.send(unm, "not added yet sry")
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
|
||||||
|
local function processMessage(unm, msg, hidden)
|
||||||
|
if not hidden and msg:sub(1, #cfg.prefix) ~= cfg.prefix then return end
|
||||||
|
|
||||||
|
if not hidden then
|
||||||
|
msg = msg:sub(#cfg.prefix + 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
local args = {}
|
||||||
|
|
||||||
|
for arg in msg:gmatch("%S+") do
|
||||||
|
table.insert(args, arg)
|
||||||
|
end
|
||||||
|
|
||||||
|
local cmd = table.remove(args, 1)
|
||||||
|
|
||||||
|
if cfg.users[unm] == nil then
|
||||||
|
ch.reportLog("foreign user " .. unm .. " tries: " .. cmd)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local handler = cmds[cmd]
|
||||||
|
if handler then
|
||||||
|
ch.reportLog("user " .. unm .. " runs: " .. cmd)
|
||||||
|
local res = handler(unm, args)
|
||||||
|
|
||||||
|
if res then
|
||||||
|
-- command requested shutdown
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
else
|
||||||
|
ch.reportLog("user " .. unm .. " tries invalid cmd: " .. cmd)
|
||||||
|
ch.send(unm, "not a valid command", "cmd")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function scheduleScan()
|
||||||
|
os.startTimer(2)
|
||||||
|
end
|
||||||
|
|
||||||
|
local termStreak = 0
|
||||||
|
local termStreakAt = 0
|
||||||
|
local lastPlrList
|
||||||
|
local listeners = {
|
||||||
|
["chat"] = function(username, message, uuid, isHidden)
|
||||||
|
return processMessage(username, message, isHidden)
|
||||||
|
end,
|
||||||
|
["playerChangedDimension"] = function(username, fromDim, toDim)
|
||||||
|
ch.reportLog(username .. " goes from " .. fromDim .. " to " .. toDim, "dims")
|
||||||
|
end,
|
||||||
|
["playerJoin"] = function(username, dimension)
|
||||||
|
tk.plrs[username] = { dimension = dimension }
|
||||||
|
end,
|
||||||
|
["playerLeave"] = function(username, dimension)
|
||||||
|
tk.plrs[username] = nil
|
||||||
|
end,
|
||||||
|
["timer"] = function()
|
||||||
|
local plrs = tk:scanRange(16)
|
||||||
|
table.sort(plrs)
|
||||||
|
|
||||||
|
local plrList = table.concat(plrs, ", ")
|
||||||
|
if plrList ~= lastPlrList then
|
||||||
|
if #plrs > 0 then
|
||||||
|
ch.reportLog("players in range: " .. plrList, "scan")
|
||||||
|
elseif lastPlrList ~= nil then
|
||||||
|
ch.reportLog("players left range", "scan")
|
||||||
|
end
|
||||||
|
|
||||||
|
lastPlrList = plrList
|
||||||
|
end
|
||||||
|
|
||||||
|
scheduleScan()
|
||||||
|
end,
|
||||||
|
["terminate"] = function()
|
||||||
|
-- should we reset term streak
|
||||||
|
if os.clock() - termStreakAt > 1 then
|
||||||
|
-- yes
|
||||||
|
termStreak = 1
|
||||||
|
termStreakAt = os.clock()
|
||||||
|
else
|
||||||
|
-- no so increase streak
|
||||||
|
termStreak = termStreak + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
-- check if streak is too much
|
||||||
|
if termStreak >= 2 then
|
||||||
|
ch.reportLog("restarting to prevent sys access..")
|
||||||
|
os.reboot()
|
||||||
|
end
|
||||||
|
|
||||||
|
print("?")
|
||||||
|
ch.reportLog("ALERT!! somebody tried to terminate skynet runner")
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
|
||||||
|
local function evDispatcher()
|
||||||
|
while true do
|
||||||
|
local params = { os.pullEventRaw() }
|
||||||
|
local event = table.remove(params, 1)
|
||||||
|
local listener = listeners[event]
|
||||||
|
|
||||||
|
if listener and listener(table.unpack(params)) then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
ch.userBc("Loaded!")
|
||||||
|
ch.reportLog("you are auto subbed to log, welcome!")
|
||||||
|
|
||||||
|
tk:refresh()
|
||||||
|
scheduleScan()
|
||||||
|
evDispatcher()
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
local function levenshtein(str1, str2)
|
||||||
|
local len1 = string.len(str1)
|
||||||
|
local len2 = string.len(str2)
|
||||||
|
local matrix = {}
|
||||||
|
local cost = 0
|
||||||
|
|
||||||
|
-- quick cut-offs to save time
|
||||||
|
if (len1 == 0) then
|
||||||
|
return len2
|
||||||
|
elseif (len2 == 0) then
|
||||||
|
return len1
|
||||||
|
elseif (str1 == str2) then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
-- initialise the base matrix values
|
||||||
|
for i = 0, len1, 1 do
|
||||||
|
matrix[i] = {}
|
||||||
|
matrix[i][0] = i
|
||||||
|
end
|
||||||
|
for j = 0, len2, 1 do
|
||||||
|
matrix[0][j] = j
|
||||||
|
end
|
||||||
|
|
||||||
|
-- actual Levenshtein algorithm
|
||||||
|
for i = 1, len1, 1 do
|
||||||
|
for j = 1, len2, 1 do
|
||||||
|
if (str1:byte(i) == str2:byte(j)) then
|
||||||
|
cost = 0
|
||||||
|
else
|
||||||
|
cost = 1
|
||||||
|
end
|
||||||
|
|
||||||
|
matrix[i][j] = math.min(matrix[i - 1][j] + 1, matrix[i][j - 1] + 1, matrix[i - 1][j - 1] + cost)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- return the last value - this is the Levenshtein distance
|
||||||
|
return matrix[len1][len2]
|
||||||
|
end
|
||||||
|
|
||||||
|
return levenshtein
|
||||||
|
|
@ -0,0 +1,60 @@
|
||||||
|
local levenshtein = require("levenshtein")
|
||||||
|
|
||||||
|
local pd = peripheral.find("player_detector")
|
||||||
|
|
||||||
|
if not pd then
|
||||||
|
print("no player detector :(")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local tk = {}
|
||||||
|
|
||||||
|
tk.plrs = {}
|
||||||
|
|
||||||
|
function tk:refreshOne(unm)
|
||||||
|
local p = pd.getPlayerPos(unm)
|
||||||
|
self.plrs[unm] = p or {}
|
||||||
|
end
|
||||||
|
|
||||||
|
function tk:refresh()
|
||||||
|
self.plrs = {}
|
||||||
|
|
||||||
|
for _, x in next, pd.getOnlinePlayers() do
|
||||||
|
self:refreshOne(x)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function tk:scanRange(range)
|
||||||
|
return pd.getPlayersInRange(range)
|
||||||
|
end
|
||||||
|
|
||||||
|
function tk:resTg(tgr)
|
||||||
|
if not tgr then return nil end
|
||||||
|
|
||||||
|
tgr = string.lower(tgr)
|
||||||
|
|
||||||
|
local lst, lstv = math.huge, nil
|
||||||
|
|
||||||
|
for x, _ in next, self.plrs do
|
||||||
|
local xl = x:lower():sub(1, #tgr)
|
||||||
|
if xl == tgr then
|
||||||
|
return x
|
||||||
|
end
|
||||||
|
-- compare if first letter matches
|
||||||
|
if xl:sub(1, 1) == tgr:sub(1, 1) then
|
||||||
|
local dis = levenshtein(tgr, xl)
|
||||||
|
if dis < lst then
|
||||||
|
lst = dis
|
||||||
|
lstv = x
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if lst >= 2 then
|
||||||
|
return nil --too far
|
||||||
|
end
|
||||||
|
|
||||||
|
return lstv
|
||||||
|
end
|
||||||
|
|
||||||
|
return tk
|
||||||
Loading…
Reference in New Issue