core.process
local process = require "core.process"
process.stream
(field) process.stream: process.stream
An abstraction over the standard input and outputs of a process that allows you to read and write data easily.
process.stream.__index
(field) process.stream.__index: process.stream
An abstraction over the standard input and outputs of a process that allows you to read and write data easily.
process.stream.buf
(field) process.stream.buf: string[]
process.stream.len
(field) process.stream.len: number
process.stream
An abstraction over the standard input and outputs of a process that allows you to read and write data easily.
__index
(field) __index: process.stream
An abstraction over the standard input and outputs of a process that allows you to read and write data easily.
buf
(field) buf: string[]
fd
(field) fd: process.streamtype
len
(field) len: number
process
(field) process: process
new
function process.stream.new(proc: process, fd: process.streamtype)
-> process.stream
Creates a stream from a process.
@param proc
— The process to wrap.
@param fd
— The standard stream of the process to wrap.
close
(method) process.stream:close()
Closes the stream and its underlying resources.
read
(method) process.stream:read(bytes: integer|`"L"`|`"all"`|`"line"`, options?: process.stream.readoption)
-> data: string|nil
Reads data from the stream.
When called inside a coroutine such as core.add_thread()
,
the function yields to the main thread occassionally to avoid blocking the editor.
If the function is not called inside the coroutine, the function returns immediately
without waiting for more data.
@param bytes
— The format or number of bytes to read.
@param options
— Options for reading from the stream.
@return data
— The string read from the stream, or nil if no data could be read.
bytes:
| `"line"` -- Reads a single line
| `"all"` -- Reads the entire stream
| `"L"` -- Reads a single line, keeping the trailing newline character.
write
(method) process.stream:write(bytes: string, options?: process.stream.writeoption)
-> num_bytes: integer
Writes data into the stream.
When called inside a coroutine such as core.add_thread()
,
the function yields to the main thread occassionally to avoid blocking the editor.
If the function is not called inside the coroutine,
the function writes as much data as possible before returning.
@param bytes
— The bytes to write into the stream.
@param options
— Options for writing to the stream.
@return num_bytes
— The number of bytes written to the stream.
process.stream.readoption
Options that can be passed to stream.read().
scan
(field) scan: number
The number of seconds to yield in a coroutine. Defaults to 1/config.fps
.
timeout
(field) timeout: number
The number of seconds to wait before the function throws an error. Reads do not time out by default.
process.stream.writeoption
Options that can be passed into stream.write().
scan
(field) scan: number
The number of seconds to yield in a coroutine. Defaults to 1/config.fps
.
process.__index
(method) process:__index(k: any)
-> function|unknown
process.start
function process.start(...any)
-> table
process.stream.close
(method) process.stream:close()
Closes the stream and its underlying resources.
process.stream.new
function process.stream.new(proc: process, fd: process.streamtype)
-> process.stream
Creates a stream from a process.
@param proc
— The process to wrap.
@param fd
— The standard stream of the process to wrap.
process.stream.read
(method) process.stream:read(bytes: integer|`"L"`|`"all"`|`"line"`, options?: process.stream.readoption)
-> data: string|nil
Reads data from the stream.
When called inside a coroutine such as core.add_thread()
,
the function yields to the main thread occassionally to avoid blocking the editor.
If the function is not called inside the coroutine, the function returns immediately
without waiting for more data.
@param bytes
— The format or number of bytes to read.
@param options
— Options for reading from the stream.
@return data
— The string read from the stream, or nil if no data could be read.
bytes:
| `"line"` -- Reads a single line
| `"all"` -- Reads the entire stream
| `"L"` -- Reads a single line, keeping the trailing newline character.
process.stream.write
(method) process.stream:write(bytes: string, options?: process.stream.writeoption)
-> num_bytes: integer
Writes data into the stream.
When called inside a coroutine such as core.add_thread()
,
the function yields to the main thread occassionally to avoid blocking the editor.
If the function is not called inside the coroutine,
the function writes as much data as possible before returning.
@param bytes
— The bytes to write into the stream.
@param options
— Options for writing to the stream.
@return num_bytes
— The number of bytes written to the stream.
process.wait
(method) process:wait(timeout?: number, scan?: number)
-> exit_code: integer|nil
Waits for the process to exit.
When called inside a coroutine such as core.add_thread()
,
the function yields to the main thread occassionally to avoid blocking the editor.
Otherwise, the function blocks the editor until the process exited or the timeout has expired.
@param timeout
— The amount of seconds to wait. If omitted, the function will wait indefinitely.
@param scan
— The amount of seconds to yield while scanning. If omittted, the scan rate will be the FPS.
@return exit_code
— The exit code for this process, or nil if the wait timed out.