Skip to content

ContextManager

Inherits: LibTSMModule

Functions

Create

lua
function BaseType.ContextManager.Create(enterFunc, exitFunc)
  -> ContextManagerObject

Creates a context manager.

Parameters:

NameTypeDescription
enterFuncfun(arg: A): EThe enter function which is called when the managed code block starts
exitFuncfun(arg: A, enterValue: E)The exit function which is called when the managed code block completes

Returns:

TypeDescription
ContextManagerObject

Methods

With

lua
function ContextManagerObject:With(arg, func, obj, key)
  -> function, any, any

Returns an iterator which executes to completion with the context manager. NOTE: The iterator must not be interrupted (i.e. with a break or return).

Parameters:

NameTypeDescription
arganyA value to pass as the first argument to the enter and exit functions (must be non-nil)
funcfun(obj: any, key?: any): ...anyThe iterator function or nil to iterate exactly once
objanyThe object to pass to the iterator function
keyanyThe initial key to pass to the iterator function

Returns:

TypeDescription
function
any
any