Module: nupp.resources
Owning wrappers for Lua's file handles.
io.open hands back a borrowed handle, which means nothing has to close it and nothing complains when nobody does. These are the same calls annotated as owners, so the checker knows a handle must be discharged and lexical cleanup can do it — on fallthrough, on error, and on structured control flow alike.
See docs/ownership.md.
Module contents
Functions
| Function | Kind | Description |
|---|---|---|
openFile | function | Opens a file and transfers responsibility for closing it to the caller. |
openProcess | function | Starts a process and transfers responsibility for closing its pipe to the caller. |
temporaryFile | function | Creates a temporary file owned by the caller. |
Functions#
resources.openFilefunction#
Opens a file and transfers responsibility for closing it to the caller.
The returned handle closes automatically at its lexical boundary.
Arguments
| Name | Type | Description |
|---|---|---|
path | string | the path of the file to open |
mode | string? | the Lua file mode; omitted uses the Lua default |
Returns
| Type | Description |
|---|---|
LuaFile | the open file handle, owned by the caller |
Raises
when the file cannot be opened
resources.openProcessfunction#
Starts a process and transfers responsibility for closing its pipe to the caller.
The returned handle closes automatically at its lexical boundary.
function resources.openProcess(command: string, mode: string?): LuaFileArguments
| Name | Type | Description |
|---|---|---|
command | string | the shell command to run |
mode | string? | the Lua pipe mode; omitted uses the Lua default |
Returns
| Type | Description |
|---|---|
LuaFile | the process pipe, owned by the caller |
Raises
when the process pipe cannot be opened
resources.temporaryFilefunction#
Creates a temporary file owned by the caller.
The returned handle closes automatically at its lexical boundary.
function resources.temporaryFile(): LuaFileReturns
| Type | Description |
|---|---|
LuaFile | the open temporary file handle, owned by the caller |
Raises
when the temporary file cannot be created