--#region vfs --#endregion vfs --#region signals ---@class SignalHandle ---@field error string Error message if the handler fails ---@field active boolean Whether the signal handler is active ---Sends a signal to a process. ---@param pid number|string Process ID ---@param sig number Signal number (0–256) function syscall.sigsend(pid, sig) end ---Registers a signal handler for the current process. ---@param handler fun(sig: number) Signal callback ---@return SignalHandle handle Signal handler state function syscall.sigcatch(handler) end ---Removes the current process's signal handler and pending signals. function syscall.sigignore() end --#endregion signals --#region socket ---Creates a new socket file descriptor. ---@return number fd Socket file descriptor function syscall.socket() end ---Connects a socket to an address using a registered protocol handler. ---@param fd number Socket file descriptor ---@param address string Remote address ---@return boolean|nil success ---@return string|nil error Error code on failure function syscall.connect(fd, address) end ---Starts listening on a socket. ---@param fd number Socket file descriptor ---@param backlog? number Maximum pending connections ---@return any result ---@return string|nil error Error code on failure function syscall.listen(fd, backlog) end ---Sends data through a connected socket. ---@param fd number Socket file descriptor ---@param data string Data to send ---@return any result ---@return string|nil error Error code on failure function syscall.send(fd, data) end ---Receives data from a connected socket. ---May yield while waiting for data. ---@param fd number Socket file descriptor ---@param amount? number Maximum amount of data to receive ---@return string|nil data Received data ---@return string|nil error Error code on failure function syscall.recv(fd, amount) end ---Shuts down a socket connection. ---@param fd number Socket file descriptor ---@return boolean|nil success ---@return string|nil error Error code on failure function syscall.sockshutdown(fd) end ---Returns the registered socket protocol prefixes. ---@return string[] endpoints function syscall.socketendpoints() end --#endregion socket --#region auth ---@class PasswdEntry ---@field uid number User ID ---@field gid number Group ID ---@field username string Username ---@field homedir string Home directory ---@field shell string Login shell ---@class UserInfo: PasswdEntry ---@field locked boolean Whether the account is locked ---Authenticates a user and sets the current task's user and group IDs. ---@param uid number User ID ---@param password string Password ---@return boolean|nil success ---@return string|nil error function syscall.login(uid, password) end ---Changes a user's password. ---Root can change any user's password; users can change their own. ---@param uid number User ID ---@param newPassword string New password (minimum 6 characters) ---@return boolean|nil success ---@return string|nil error function syscall.setpassword(uid, newPassword) end ---Changes a user's username. Root only. ---@param uid number User ID ---@param newUsername string New username ---@return boolean|nil success ---@return string|nil error function syscall.setusername(uid, newUsername) end ---Creates a new user account. Root only. ---@param username string Username ---@param password string Password (minimum 6 characters) ---@param gid? number Group ID (defaults to the new UID) ---@param homedir? string Home directory (defaults to /home/username) ---@param shell? string Login shell (defaults to /bin/hysh) ---@return number|nil uid New user ID ---@return string|nil error function syscall.newuser(username, password, gid, homedir, shell) end ---Returns the current user's username. ---@return string|nil username ---@return string|nil error function syscall.whoami() end ---Gets a user's UID by username. ---@param username string Username ---@return number|nil uid function syscall.getuidbyname(username) end ---Gets a user's passwd information. ---@param uid number User ID ---@return PasswdEntry|nil entry function syscall.getpasswd(uid) end ---Elevates the current task to root after authenticating another account. ---@param targetUsername string Username to authenticate against ---@param password string Account password ---@return boolean|nil success ---@return number|string|nil previousUidOrError function syscall.elevate(targetUsername, password) end ---Deletes a user account. Root only. Cannot delete UID 0. ---@param uid number User ID ---@return boolean|nil success ---@return string|nil error function syscall.deleteuser(uid) end ---Locks a user account. Root only. Cannot lock UID 0. ---@param uid number User ID ---@return boolean|nil success ---@return string|nil error function syscall.lockuser(uid) end ---Unlocks a user account. Root only. ---@param uid number User ID ---@return boolean|nil success ---@return string|nil error function syscall.unlockuser(uid) end ---Lists all user accounts. ---@return UserInfo[] users function syscall.listusers() end ---Changes a user's login shell. ---Root or the account owner can change it. ---@param uid number User ID ---@param shell string Shell path ---@return boolean|nil success ---@return string|nil error function syscall.setshell(uid, shell) end ---Changes a user's home directory. Root only. ---@param uid number User ID ---@param homedir string Home directory path ---@return boolean|nil success ---@return string|nil error function syscall.sethomedir(uid, homedir) end ---Changes a user's primary group ID. Root only. ---@param uid number User ID ---@param gid number New group ID ---@return boolean|nil success ---@return string|nil error function syscall.setgid(uid, gid) end --#endregion auth --#region hpv ---@class TaskInfo ---@field name string Task name or executable path ---@field status string Current task state (R=running, S=sleeping, D=waiting for I/O, T=stopped, ST=stopped while sleeping, Z=exited) ---@field pid number Unique process/task identifier ---@field tgid number Thread group identifier ---@field username string|nil Username associated with the task's real UID ---@field uid number Real user ID ---@field euid number Effective user ID used for permission checks ---@field exit number|nil Exit code, if the task has exited ---@field sleep number Sleep deadline in milliseconds ---@field ivs number Internal virtual scheduling value ---@field vs number Virtual scheduling value ---@field children number[] PIDs of child tasks ---@field siblings number[] PIDs of tasks sharing the same parent ---@field parent number PID of the parent task ---@field cwd string Current working directory ---Create a new task running a Lua function. ---@param func fun(...: any): any Function executed by the new task ---@param name? string Task name; defaults to an automatically generated name ---@param envars? table Environment variables inherited by the task ---@param args? any[] Arguments passed to the function ---@param tgid? number Thread group ID; defaults to the current task's group ---@param clearFds? boolean If true, do not inherit the current task's file descriptors ---@return number pid PID of the newly created task function syscall.spawn(func, name, envars, args, tgid, clearFds) end ---Create a new task by loading and executing a Lua executable file. ---@param path string Path to the executable ---@param name? string Task name; defaults to the executable path ---@param envars? table Environment variables for the new task ---@param args? any[] Arguments passed to the executable ---@param tgid? number Thread group ID; defaults to the current task's group ---@param keepFds? boolean If true, inherit the current task's file descriptors ---@return number pid PID of the newly created task function syscall.execspawn(path, name, envars, args, tgid, keepFds) end ---Replace the current task's program with another executable. ---@param path string Path to the executable ---@param args? any[] Arguments passed to the executable ---@param envars? table Environment variables for the executable ---@param clearFds? boolean If true, close file descriptors greater than 2 before execution function syscall.exec(path, args, envars, clearFds) end ---Suspend the current task for the specified number of seconds. ---@param seconds number Duration to sleep function syscall.sleep(seconds) end ---Retrieve information about a task by its PID. ---@param pid number PID of the task to inspect ---@return TaskInfo|nil task Task information, or nil if the task does not exist function syscall.getTask(pid) end ---Collect the exit status of a child task that has finished. ---@param pid number PID of the child task ---@return boolean success Whether collection succeeded ---@return number|string|nil exitCodeOrError Exit code on success, or an error message on failure function syscall.collect(pid) end ---Terminate a task. ---@param pid number PID of the task to terminate ---@param force? boolean Allow termination of a task waiting for I/O ---@return boolean success Whether the task was terminated ---@return string|nil error Error message if termination failed function syscall.kill(pid, force) end ---Stop a running or sleeping task. ---@param pid number PID of the task to stop ---@return boolean success Whether the task was stopped ---@return string|nil error Error message if stopping failed function syscall.stop(pid) end ---Resume a previously stopped task. ---@param pid number PID of the task to resume ---@return boolean success Whether the task was resumed ---@return string|nil error Error message if resuming failed function syscall.continue(pid) end ---Get the PID of the currently running task. ---@return number pid Current task PID function syscall.getpid() end ---Get the PID of the current task's parent. ---@return number pid Parent task PID function syscall.getppid() end ---Get the PIDs of all currently tracked tasks. ---@return number[] pids List of task PIDs function syscall.getTasks() end ---Retrieve an environment variable from the current task. ---@param key string Environment variable name ---@return any value Environment variable value, or nil if unset function syscall.getEnviron(key) end ---Set an environment variable for the current task. ---@param key string Environment variable name ---@param value any Value to assign function syscall.setEnviron(key, value) end ---Exit the current task. ---@param code? number Optional numeric exit code function syscall.exit(code) end ---Set the real and effective user IDs of the current task. ---@param uid number User ID to assign; requires effective root privileges unless setting the real UID to its existing value function syscall.setuid(uid) end ---Get the real user ID of the current task. ---@return number uid Current task's real UID function syscall.getuid() end ---Get the effective user ID of the current task. ---@return number euid Current task's effective UID function syscall.geteuid() end --#endregion hpv --#region gpio ---@param pin number|string GPIO pin identifier ---@param data any Value to write ---@return any result function syscall.gpio_write(pin, data) end ---@param pin number|string GPIO pin identifier ---@param data number Analog value to write ---@return any result function syscall.gpio_writeAnalog(pin, data) end ---@param pin number|string GPIO pin identifier ---@return any value function syscall.gpio_read(pin) end ---@param pin number|string GPIO pin identifier ---@return number|nil value function syscall.gpio_readAnalog(pin) end --#endregion gpio --#endregion syscalls --#region globals ---@class DataList ---@field contents table ---@field push fun(self: DataList, ...: any) ---@field pop fun(self: DataList): any --- Rounds a number to the nearest integer. --- @param x number --- @return integer function math.round(x) end --- Checks whether a string ends with a suffix. --- @param str string --- @param suffix string --- @return boolean function string.hasSuffix(str, suffix) end --- Checks whether a string starts with a prefix. --- @param str string --- @param prefix string --- @return boolean function string.hasPrefix(str, prefix) end --- Returns the part of a string after the given prefix. --- @param str string --- @param prefix string --- @return string function string.getSuffix(str, prefix) end --- Returns the part of a string before the given suffix. --- @param str string --- @param suffix string --- @return string function string.getPrefix(str, suffix) end --- Joins multiple values into a string. --- @param str string First value --- @param ... any Additional values --- @return string function string.join(str, ...) end --- Joins multiple values using a delimiter. --- @param str string Delimiter --- @param ... any Values to join --- @return string function string.delim(str, ...) end --- Splits a string using a single-character delimiter. --- @param str string --- @param delim string Single-character delimiter --- @param maxResultCountOrNil? number Maximum number of results --- @return string[]|false function string.split(str, delim, maxResultCountOrNil) end --- Creates a deep copy of a value, preserving circular references. --- @generic T --- @param orig T --- @param copies? table --- @return T function table.deepcopy(orig, copies) end --- Returns the value stored at the matching key, or false. --- @param tabl table --- @param query any --- @return any|false function table.hasKey(tabl, query) end --- Returns the key associated with a matching value, or false. --- @param tabl table --- @param query any --- @return any|false function table.hasVal(tabl, query) end --- Creates a read-only proxy for a table. --- @param tabl table --- @param typ? string Custom type name --- @return table function table.readOnly(tabl, typ) end --- Serializes a table into a Lua-style table representation. --- @param tbl table --- @return string function table.serialize(tbl) end --- Returns the type of an object, optionally returning its original Lua type. --- @param object any --- @param trueType? boolean Use the original Lua type --- @return string function type(object, trueType) end --- Gets the metatable of an object, respecting custom user metatables. --- @param object any --- @return table|nil function getmetatable(object) end --- Checks whether a value equals any of the supplied values. --- @param a any --- @param ... any Values to compare --- @return boolean function isEqualToAny(a, ...) end --- Checks whether a value equals all of the supplied values. --- @param a any --- @param ... any Values to compare --- @return boolean function isEqualToAll(a, ...) end --- Returns all keys in a table. --- @param t table --- @return any[] function table.keys(t) end --- Returns all values in a table. --- @param t table --- @return any[] function table.values(t) end --- Returns the index of a value in an array, or -1 if not found. --- @param t table --- @param value any --- @return integer function table.indexOf(t, value) end --- Merges multiple tables into one table. --- @param ... table Tables to merge --- @return table function table.merge(...) end --- Replaces occurrences of a substring. --- @param s string --- @param target string --- @param repl string --- @return string function string.replace(s, target, repl) end --- Converts a number to a hexadecimal string. --- @param num number --- @return string function toHex(num) end --- Creates a stack. --- @return DataList function stack() end --- Creates a queue. --- @return DataList function queue() end ---Loads a module from the configured search paths. ---Modules are cached and returned through a read-only wrapper. ---@param module string Module name or path ---@vararg any Arguments passed to the module's loader ---@return table module Read-only module wrapper function require(module, ...) end ---Sleep the current task for a number of seconds. ---@param seconds number function sleep(seconds) end ---@param ... any Values to print, separated by tabs function print(...) end ---@param fmt string Format string ---@param ... any Format arguments function printf(fmt, ...) end ---@param ... any Values to print inline, separated by tabs function printInline(...) end ---@param fd? number Input file descriptor (defaults to 0) ---@param helpstr? string Prompt displayed before reading ---@param replacestr? string Replacement text echoed for each input ---@param fdo? number Output file descriptor used for echo (defaults to 1) ---@return string input function userinput(fd, helpstr, replacestr, fdo) end --#endregion globals