Module ammcore.defer¶
Type-safe utilities for working with errors in Lua.
Index¶
Function¶
-
ammcore.defer.defer(fn: fun(...
any), ...:any) defer:ammcore.defer._Defer¶ Defer code execution till the end of the current block.
Assign result of this function to a local
closevariable:do local _<close> = defer.defer(function() print("I run at the end of the `do` block!") end) -- Do something else, maybe even throw an error. end -- When `_` goes out of scope, the function above is executed.
- Parameters:
fn (fun(...
any)) – a function that will be called upon closing the returned value.... (
any) – function parameters.
- Returns:
defer (
ammcore.defer._Defer) – an opaque object that should be placed to aclosevariable.
-
ammcore.defer.xpcall(fn: fun(...
any), ...:any) ok:boolean, err: {message:any, trace:string}¶ Version of FIN xpcall for proper type checking.
Calls the given function with the given parameters. Returns
trueif function call was successful,falseif function call raised an error.- Parameters:
fn (fun(...
any)) – a function that will be called in protected environment.... (
any) – function parameters.
- Returns:
ok (
boolean) –trueif function call was successful.err ({message:
any, trace:string}) – an object describing an error; only returned whenokisfalse.