layout | title |
---|---|
default |
Kernel API |
This page contains documentation for the public kernel module API.
This is a work-in-progress! Some parts may be broken or don't make sense.
Version number of Phoenix.
Small function to execute a syscall and error if it fails.
call
: The syscall to execute...
: The arguments to pass to the syscall
The values returned from the syscall
Copies a value. If the value is a table, copies all of its contents too.
tab
: The value to copy
The new copied value
Splits a string by a separator.
str
: The string to splitsep
: The separator pattern to split by (defaults to "%s")
A list of items in the string
executeThread(process: Process, thread: Thread, ev: table, dead: boolean, allWaiting: boolean): boolean, boolean
Resumes a thread's coroutine, handling different yield types.
process
: The process that owns the threadthread
: The thread to resumeev
: An event to pass to the thread, if presentdead
: Whether a thread in the current run cycle has diedallWaiting
: Whether all previous threads were waiting for an event
This function may return the following values:
- Whether this thread or a previous thread has died
- Whether all threads (including this one) are waiting for an event
Executes a function in user mode from kernel code.
process
: The process to execute asfunc
: The function to execute...
: Any parameters to pass to the function
This function may return the following values:
- Whether the function returned successfully
- The value that the function returned.
Creates a new _ENV shadow environment for a table. The resulting table can
have its environment set through t._ENV = val
.
env
: The environment table to use
A new _ENV-ized table
Stores all kernel arguments passed on the command line.
init
:root
:rootfstype
:preemptive
:quantum
:splitkernpath
:loglevel
:console
:traceback
:
Contains every syscall defined in the kernel.
Stores all currently running processes.
[0]
:id
:user
:dir
:dependents
:
Stores all currently loaded kernel modules.
Stores a list of hooks to call on certain CraftOS events. Each entry has the event name as a key, and a list of functions to call as the value. The functions are called with a single table parameter with the event parameters.
Process API
Filesystem API
Terminal API
User API
System logger API
Hardware API
Build string of Phoenix.
This function does not take any arguments.
Stores the start time of the kernel.
This function does not take any arguments.
Stores a quick reference to the kernel process object.
This function does not take any arguments.
Stores the current mounts as a key-value table of paths to filesystem objects.
This table contains all filesystem types. Use this to insert more filesystem types into the system.
A filesystem type has to implement one method for each function in the
filesystem API, with the exception of mounting-related functions and combine
,
as well as a new
method that is called with the process, the source device,
and the options table (if present). Paths passed to these methods (outside
new
) take a relative path to the mountpoint, NOT the absolute path.
craftos
:owner
:permissions
:write
:execute
:
Opens a file for reading or writing.
process
: The process to operate aspath
: The file path to open, which may be absolute or relative to the process's working directorymode
: The mode to open the file as
This function may return the following values:
- The new file handle
Or:
- If an error occurred
- An error message describing why the file couldn't be opened
Returns a list of file names in the directory.
process
: The process to operate aspath
: The file path to list, which may be absolute or relative to the process's working directory
A list of file names present in the directory
Returns a table with information about the selected path.
process
: The process to operate aspath
: The file path to stat, which may be absolute or relative to the process's working directory
This function may return the following values:
- A table with information about the path (see the docs for
the
stat
syscall for more info)
Or:
- If an error occurred
- An error message describing why the file couldn't be opened
Removes a file or directory.
process
: The process to operate aspath
: The file path to remove, which may be absolute or relative to the process's working directory
This function does not return anything.
Renames (moves) a file or directory.
process
: The process to operate aspath
: The file path to rename, which may be absolute or relative to the process's working directorynew
: path the file will be at, which may be in another directory but must be on the same mountpoint
This function does not return anything.
Creates a new directory and any parent directories.
process
: The process to operate aspath
: The directory to create, which may be absolute or relative to the process's working directory
This function does not return anything.
Changes the permissions (mode) of a file or directory for the specified user.
process
: The process to operate aspath
: The file path to modify, which may be absolute or relative to the process's working directoryuser
: The user to change the permissions for, ornil
for all usersboolean
: ?, write = boolean?, execute = boolean?} mode The new permissions for the user (see the docs for thechmod
syscall for more info)
This function does not return anything.
Changes the owner of a file or directory.
process
: The process to operate aspath
: The file path to modify, which may be absolute or relative to the process's working directoryuser
: The user that will own the file
This function does not return anything.
Mounts a disk device to a path using the specified filesystem and options.
process
: The process to operate astype
: The type of filesystem to mountsrc
: The source device to mountdest
: The destination mountpointoptions
: Any options to pass to the mounter (optional)
This function does not return anything.
Unmounts a filesystem at a mountpoint.
process
: The process to operate aspath
: The mountpoint to remove, which may be absolute or relative to the process's working directory
This function does not return anything.
Combines the specified path components into a single path.
first
: The first path component...
: Any additional path components to add
The final combined path
Creates a new global table with a Lua 5.2 standard library installed.
process
: The process to generate for
A new global table for the process
Returns a new TTY object.
term
: The CraftOS terminal object to render onwidth
: The width of the TTYheight
: The height of the TTY
The new TTY object
Stores all virtual TTYs for the main screen.
terminal
:terminal
:terminal
:terminal
:terminal
:terminal
:terminal
:terminal
:
Stores the TTY that is currently shown on screen.
This function does not take any arguments.
Stores all TTYs that have been created in user mode.
Stores what modifier keys are currently being held.
ctrl
:alt
:shift
:
Redraws the specified TTY if on-screen.
tty
: The TTY to redrawfull
: Whether to draw the full screen, or just the changed regions
This function does not return anything.
Resizes the TTY.
tty
: The TTY to resizewidth
: The new widthheight
: The new height
This function does not return anything.
Writes some text to a TTY's text buffer, allowing ANSI escapes.
tty
: The TTY to write totext
: The text to write
This function does not return anything.
Stores all open system logs.
default
: file = filesystem.open(KERNEL, "/var/log/default.log", "a"),
Immediately halts the system and shows an error message on screen. This function can be called either standalone or from within xpcall. This function never returns.
message
: A message to display on screen (optional)
This function does not return anything.
Creates a new package
and require
set in a global table for the specified process.
process
: The process to make the functions forG
: The global environment to install in
This function does not return anything.
Stores a list of used timers.
Stores a list of used alarms.
Finishes a process's resources so it can be removed cleanly.
process
: The process to reap
This function does not return anything.
Stores the root device for hardware.
id
:uuid
:parent
:displayName
:drivers
:
Returns all devices that match a path specifier.
path
: The path to query
The device objects that match
Returns all devices that match a type.
type
: The type to find
The device objects that match
Returns the absolute path to a device node.
node
: The node to lookup
The path to the node
Adds a new child to the specified node.
parent
: The parent of the new nodename
: The name of the new node
The newly added node
Removes a node from its parent and the device tree. The device node should no longer be used.
node
: The node to remove
This function may return the following values:
- Whether the operation succeeded
- An error message if it failed
Registers a device driver on a node.
node
: The node to modifydriver
: The driver to add
This function may return the following values:
- Whether the operation succeeded
- An error message if it failed
Returns a function that automatically attaches a driver to a node.
driver
: The driver to use
A function that takes a node and registers the driver on it
Deregisters a driver from a node.
node
: The node to modifydriver
: The driver to remove
This function may return the following values:
- Whether the operation succeeded
- An error message if it failed
Adds a function that is called when either a parent node or pattern matches on a new node.
callback
: A function that is called with a node when the pattern matchesparent
: A parent node to watch on (optional)pattern
: A Lua pattern to match on the device name (optional)
This function does not return anything.
Removes a listener callback from the listener list.
callback
: The function to remove
This function does not return anything.
Broadcasts an event to all processes listening to events on a node.
node
: The node to broadcast forevent
: The event to broadcastparam
: The parameters to pass for the event
This function does not return anything.
Calls a method on a device.
process
: The process to run asnode
: The node to call onmethod
: The method to call...
: Any arguments to pass
Any return values from the method
Stores all URI scheme handlers using Lua patterns as keys.
[https?]
:[wss?]
:[rednet]
:[rednet%+%a+]
:[psp]
: