2020-10-11 21:38:18 +00:00
|
|
|
--[[-
|
2020-11-29 11:24:18 +00:00
|
|
|
Functions in the global environment, defined in `bios.lua`. This does not
|
|
|
|
include standard Lua functions.
|
2020-10-11 21:38:18 +00:00
|
|
|
|
|
|
|
@module _G
|
|
|
|
]]
|
|
|
|
|
|
|
|
--[[- Pauses execution for the specified number of seconds.
|
|
|
|
|
|
|
|
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|parallel API}, it will only pause execution of the current
|
|
|
|
thread, not the whole program.
|
|
|
|
|
2021-12-21 00:22:16 +00:00
|
|
|
:::tip
|
|
|
|
Because sleep internally uses timers, it is a function that yields. This means
|
2022-09-29 21:21:38 +00:00
|
|
|
that you can use it to prevent "Too long without yielding" errors. However, as
|
2021-12-21 00:22:16 +00:00
|
|
|
the minimum sleep time is 0.05 seconds, it will slow your program down.
|
|
|
|
:::
|
|
|
|
|
|
|
|
:::caution
|
|
|
|
Internally, this function queues and waits for a timer event (using
|
2020-10-11 21:38:18 +00:00
|
|
|
@{os.startTimer}), however it does not listen for any other events. This means
|
|
|
|
that any event that occurs while sleeping will be entirely discarded. If you
|
|
|
|
need to receive events while sleeping, consider using @{os.startTimer|timers},
|
|
|
|
or the @{parallel|parallel API}.
|
2021-12-21 00:22:16 +00:00
|
|
|
:::
|
2020-10-11 21:38:18 +00:00
|
|
|
|
|
|
|
@tparam number time The number of seconds to sleep for, rounded up to the
|
|
|
|
nearest multiple of 0.05.
|
|
|
|
|
|
|
|
@see os.startTimer
|
2020-11-29 11:24:18 +00:00
|
|
|
@usage Sleep for three seconds.
|
|
|
|
|
|
|
|
print("Sleeping for three seconds")
|
|
|
|
sleep(3)
|
|
|
|
print("Done!")
|
2020-10-11 21:38:18 +00:00
|
|
|
]]
|
|
|
|
function sleep(time) end
|
|
|
|
|
2020-11-29 11:24:18 +00:00
|
|
|
--- Writes a line of text to the screen without a newline at the end, wrapping
|
|
|
|
-- text if necessary.
|
|
|
|
--
|
|
|
|
-- @tparam string text The text to write to the string
|
|
|
|
-- @treturn number The number of lines written
|
|
|
|
-- @see print A wrapper around write that adds a newline and accepts multiple arguments
|
|
|
|
-- @usage write("Hello, world")
|
2020-10-11 21:38:18 +00:00
|
|
|
function write(text) end
|
2020-11-29 11:24:18 +00:00
|
|
|
|
|
|
|
--- Prints the specified values to the screen separated by spaces, wrapping if
|
|
|
|
-- necessary. After printing, the cursor is moved to the next line.
|
|
|
|
--
|
|
|
|
-- @param ... The values to print on the screen
|
|
|
|
-- @treturn number The number of lines written
|
|
|
|
-- @usage print("Hello, world!")
|
2020-10-11 21:38:18 +00:00
|
|
|
function print(...) end
|
2020-11-29 11:24:18 +00:00
|
|
|
|
|
|
|
--- Prints the specified values to the screen in red, separated by spaces,
|
|
|
|
-- wrapping if necessary. After printing, the cursor is moved to the next line.
|
|
|
|
--
|
|
|
|
-- @param ... The values to print on the screen
|
|
|
|
-- @usage printError("Something went wrong!")
|
2020-10-11 21:38:18 +00:00
|
|
|
function printError(...) end
|
|
|
|
|
2022-05-02 16:49:32 +00:00
|
|
|
--[[- Reads user input from the terminal. This automatically handles arrow keys,
|
2020-11-29 11:24:18 +00:00
|
|
|
pasting, character replacement, history scrollback, auto-completion, and
|
|
|
|
default values.
|
|
|
|
|
|
|
|
@tparam[opt] string replaceChar A character to replace each typed character with.
|
|
|
|
This can be used for hiding passwords, for example.
|
|
|
|
@tparam[opt] table history A table holding history items that can be scrolled
|
|
|
|
back to with the up/down arrow keys. The oldest item is at index 1, while the
|
|
|
|
newest item is at the highest index.
|
|
|
|
@tparam[opt] function(partial: string):({ string... }|nil) completeFn A function
|
|
|
|
to be used for completion. This function should take the partial text typed so
|
|
|
|
far, and returns a list of possible completion options.
|
|
|
|
@tparam[opt] string default Default text which should already be entered into
|
|
|
|
the prompt.
|
|
|
|
|
|
|
|
@treturn string The text typed in.
|
|
|
|
|
|
|
|
@see cc.completion For functions to help with completion.
|
2021-07-18 16:36:09 +00:00
|
|
|
@usage Read a string and echo it back to the user
|
2020-11-29 11:24:18 +00:00
|
|
|
|
|
|
|
write("> ")
|
|
|
|
local msg = read()
|
|
|
|
print(msg)
|
|
|
|
|
|
|
|
@usage Prompt a 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!")
|
|
|
|
|
|
|
|
@usage A complete example with completion, history 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)
|
2021-07-30 21:44:11 +00:00
|
|
|
|
|
|
|
@changed 1.74 Added `completeFn` parameter.
|
|
|
|
@changed 1.80pr1 Added `default` parameter.
|
2020-11-29 11:24:18 +00:00
|
|
|
]]
|
2020-10-11 21:38:18 +00:00
|
|
|
function read(replaceChar, history, completeFn, default) end
|
|
|
|
|
2022-05-02 16:49:32 +00:00
|
|
|
--- Stores the current ComputerCraft and Minecraft versions.
|
|
|
|
--
|
|
|
|
-- Outside of Minecraft (for instance, in an emulator) @{_HOST} will contain the
|
|
|
|
-- emulator's version instead.
|
2020-10-11 21:38:18 +00:00
|
|
|
--
|
|
|
|
-- For example, `ComputerCraft 1.93.0 (Minecraft 1.15.2)`.
|
2022-05-02 16:49:32 +00:00
|
|
|
-- @usage Print the current computer's environment.
|
|
|
|
--
|
|
|
|
-- print(_HOST)
|
2021-07-30 21:44:11 +00:00
|
|
|
-- @since 1.76
|
2020-10-11 21:38:18 +00:00
|
|
|
_HOST = _HOST
|
|
|
|
|
|
|
|
--[[- The default computer settings as defined in the ComputerCraft
|
|
|
|
configuration.
|
|
|
|
|
|
|
|
This is a comma-separated list of settings pairs defined by the mod
|
|
|
|
configuration or server owner. By default, it is empty.
|
|
|
|
|
|
|
|
An example value to disable autocompletion:
|
|
|
|
|
|
|
|
shell.autocomplete=false,lua.autocomplete=false,edit.autocomplete=false
|
|
|
|
|
2020-11-29 11:24:18 +00:00
|
|
|
@usage _CC_DEFAULT_SETTINGS
|
2021-07-30 21:44:11 +00:00
|
|
|
@since 1.77
|
2020-10-11 21:38:18 +00:00
|
|
|
]]
|
|
|
|
_CC_DEFAULT_SETTINGS = _CC_DEFAULT_SETTINGS
|