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

FunctionKindDescription
openFilefunctionOpens a file and transfers responsibility for closing it to the caller.
openProcessfunctionStarts a process and transfers responsibility for closing its pipe to the caller.
temporaryFilefunctionCreates 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.

function resources.openFile(path: string, mode: string?): LuaFile

Arguments

NameTypeDescription
pathstring

the path of the file to open

modestring?

the Lua file mode; omitted uses the Lua default

Returns

TypeDescription
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?): LuaFile

Arguments

NameTypeDescription
commandstring

the shell command to run

modestring?

the Lua pipe mode; omitted uses the Lua default

Returns

TypeDescription
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(): LuaFile

Returns

TypeDescription
LuaFile

the open temporary file handle, owned by the caller

Raises

  • when the temporary file cannot be created