2023-03-15 21:52:13 +00:00
|
|
|
-- SPDX-FileCopyrightText: 2020 The CC: Tweaked Developers
|
|
|
|
--
|
Further licensing work
- Fix several inaccuracies with several files not marking Dan's
authorship. Most of these are new files, where the code was moved from
somewhere else:
- In the public API: IDynamicLuaObject, ILuaAPI, TaskCallbakc,
IDynamicPeripheral, UpgradeBase
- In the ROM: fs, http, require
- Do not mark Dan as an author for entirely new code. This affects
DetailHelpers, DropConsumer, FluidData, InventoryMethods, ItemDetails,
MonitorRenderState, NoTermComputerScreen, Palette, PlatformHelperImpl,
UploadFileMessage, the Terminal tests, and any speaker-related files.
- Relicence many files under the MPL where we have permission to do
so. See #1339 for further details.
Thank you to everyone who has contributed so far! Cannot overstate how
appreciated it is <3.
2023-03-29 21:48:57 +00:00
|
|
|
-- SPDX-License-Identifier: MPL-2.0
|
2020-10-11 21:38:18 +00:00
|
|
|
|
|
|
|
--[[- Loads the given API into the global environment.
|
|
|
|
|
|
|
|
This function loads and executes the file at the given path, and all global
|
|
|
|
variables and functions exported by it will by available through the use of
|
|
|
|
`myAPI.<function name>`, where `myAPI` is the base name of the API file.
|
|
|
|
|
|
|
|
@tparam string path The path of the API to load.
|
|
|
|
@treturn boolean Whether or not the API was successfully loaded.
|
2021-08-26 07:02:58 +00:00
|
|
|
@since 1.2
|
2020-10-11 21:38:18 +00:00
|
|
|
|
2021-07-30 21:44:11 +00:00
|
|
|
@deprecated When possible it's best to avoid using this function. It pollutes
|
|
|
|
the global table and can mask errors.
|
|
|
|
|
2023-08-24 09:48:30 +00:00
|
|
|
[`require`] should be used to load libraries instead.
|
2020-10-11 21:38:18 +00:00
|
|
|
]]
|
2020-04-28 08:42:34 +00:00
|
|
|
function loadAPI(path) end
|
2020-10-11 21:38:18 +00:00
|
|
|
|
2023-08-24 09:48:30 +00:00
|
|
|
--- Unloads an API which was loaded by [`os.loadAPI`].
|
2020-10-11 21:38:18 +00:00
|
|
|
--
|
|
|
|
-- This effectively removes the specified table from `_G`.
|
|
|
|
--
|
|
|
|
-- @tparam string name The name of the API to unload.
|
2021-08-26 07:02:58 +00:00
|
|
|
-- @since 1.2
|
2023-08-24 09:48:30 +00:00
|
|
|
-- @deprecated See [`os.loadAPI`] for why.
|
2020-10-11 21:38:18 +00:00
|
|
|
function unloadAPI(name) end
|
|
|
|
|
|
|
|
--[[- Pause execution of the current thread and waits for any events matching
|
|
|
|
`filter`.
|
|
|
|
|
2023-08-24 09:48:30 +00:00
|
|
|
This function [yields][`coroutine.yield`] the current process and waits for it
|
2020-10-11 21:38:18 +00:00
|
|
|
to be resumed with a vararg list where the first element matches `filter`.
|
|
|
|
If no `filter` is supplied, this will match all events.
|
|
|
|
|
2023-08-24 09:48:30 +00:00
|
|
|
Unlike [`os.pullEventRaw`], it will stop the application upon a "terminate"
|
2020-10-11 21:38:18 +00:00
|
|
|
event, printing the error "Terminated".
|
|
|
|
|
|
|
|
@tparam[opt] string filter Event to filter for.
|
|
|
|
@treturn string event The name of the event that fired.
|
|
|
|
@treturn any param... Optional additional parameters of the event.
|
|
|
|
@usage Listen for `mouse_click` events.
|
|
|
|
|
|
|
|
while true do
|
|
|
|
local event, button, x, y = os.pullEvent("mouse_click")
|
|
|
|
print("Button", button, "was clicked at", x, ",", y)
|
|
|
|
end
|
|
|
|
|
|
|
|
@usage Listen for multiple events.
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
@see os.pullEventRaw To pull the terminate event.
|
2021-08-26 07:02:58 +00:00
|
|
|
@changed 1.3 Added filter argument.
|
2020-10-11 21:38:18 +00:00
|
|
|
]]
|
2020-04-28 08:42:34 +00:00
|
|
|
function pullEvent(filter) end
|
2020-10-11 21:38:18 +00:00
|
|
|
|
|
|
|
--[[- Pause execution of the current thread and waits for events, including the
|
|
|
|
`terminate` event.
|
|
|
|
|
2023-08-24 09:48:30 +00:00
|
|
|
This behaves almost the same as [`os.pullEvent`], except it allows you to handle
|
2020-10-11 21:38:18 +00:00
|
|
|
the `terminate` event yourself - the program will not stop execution when
|
|
|
|
<kbd>Ctrl+T</kbd> is pressed.
|
|
|
|
|
|
|
|
@tparam[opt] string filter Event to filter for.
|
|
|
|
@treturn string event The name of the event that fired.
|
|
|
|
@treturn any param... Optional additional parameters of the event.
|
|
|
|
@usage Listen for `terminate` events.
|
|
|
|
|
|
|
|
while true do
|
|
|
|
local event = os.pullEventRaw()
|
|
|
|
if event == "terminate" then
|
|
|
|
print("Caught terminate event!")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@see os.pullEvent To pull events normally.
|
|
|
|
]]
|
2020-04-28 08:42:34 +00:00
|
|
|
function pullEventRaw(filter) end
|
2020-10-11 21:38:18 +00:00
|
|
|
|
2023-08-24 09:48:30 +00:00
|
|
|
--- Pauses execution for the specified number of seconds, alias of [`_G.sleep`].
|
2020-11-12 19:40:18 +00:00
|
|
|
--
|
|
|
|
-- @tparam number time The number of seconds to sleep for, rounded up to the
|
|
|
|
-- nearest multiple of 0.05.
|
2020-10-11 21:38:18 +00:00
|
|
|
function sleep(time) end
|
|
|
|
|
2023-11-08 19:37:30 +00:00
|
|
|
--- Get the current CraftOS version (for example, `CraftOS 1.9`).
|
2020-10-11 21:38:18 +00:00
|
|
|
--
|
|
|
|
-- This is defined by `bios.lua`. For the current version of CC:Tweaked, this
|
2023-11-08 19:37:30 +00:00
|
|
|
-- should return `CraftOS 1.9`.
|
2020-10-11 21:38:18 +00:00
|
|
|
--
|
|
|
|
-- @treturn string The current CraftOS version.
|
2020-11-12 19:40:18 +00:00
|
|
|
-- @usage os.version()
|
2020-04-28 08:42:34 +00:00
|
|
|
function version() end
|
2020-10-11 21:38:18 +00:00
|
|
|
|
|
|
|
--[[- Run the program at the given path with the specified environment and
|
|
|
|
arguments.
|
|
|
|
|
|
|
|
This function does not resolve program names like the shell does. This means
|
|
|
|
that, for example, `os.run("edit")` will not work. As well as this, it does not
|
2023-08-24 09:48:30 +00:00
|
|
|
provide access to the [`shell`] API in the environment. For this behaviour, use
|
|
|
|
[`shell.run`] instead.
|
2020-10-11 21:38:18 +00:00
|
|
|
|
|
|
|
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
|
2023-08-24 09:48:30 +00:00
|
|
|
such as [`loadfile`].
|
2020-10-11 21:38:18 +00:00
|
|
|
|
|
|
|
@tparam table env The environment to run the program with.
|
|
|
|
@tparam string path The exact path of the program to run.
|
|
|
|
@param ... The arguments to pass to the program.
|
|
|
|
@treturn boolean Whether or not the program ran successfully.
|
|
|
|
@usage Run the default shell from within your program:
|
|
|
|
|
2020-11-12 19:40:18 +00:00
|
|
|
os.run({}, "/rom/programs/shell.lua")
|
2020-10-11 21:38:18 +00:00
|
|
|
|
|
|
|
@see shell.run
|
|
|
|
@see loadfile
|
|
|
|
]]
|
2020-04-28 08:42:34 +00:00
|
|
|
function run(env, path, ...) end
|