µEvLoop
A fast and lightweight event loop aimed at embedded platforms in C99.
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Data Structures | Typedefs | Functions
closure.h File Reference

Defines closures, objects that bind functions to creating and calling contexts. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  uel_closure_t
 Defines a closure, a tuple <function, context, destructor> More...
 

Typedefs

typedef void *(* uel_closure_function_t) (void *context, void *params)
 Defines a closure function, suitable for being bound at a closure. More...
 

Functions

uel_closure_t uel_closure_create (uel_closure_function_t function, void *context)
 Creates a new closure. More...
 
void * uel_closure_invoke (uel_closure_t *closure, void *params)
 Invokes a closure and returns whatever value it returned. More...
 
uel_closure_t uel_nop ()
 Returns a closure that does nothing. More...
 

Detailed Description

Defines closures, objects that bind functions to creating and calling contexts.

Typedef Documentation

◆ uel_closure_function_t

typedef void*(* uel_closure_function_t) (void *context, void *params)

Defines a closure function, suitable for being bound at a closure.

Must take two pointers ar arguments, one for the context and one for closure parameters. Must return a void pointer.

Function Documentation

◆ uel_closure_create()

uel_closure_t uel_closure_create ( uel_closure_function_t  function,
void *  context 
)

Creates a new closure.

Binds the tuple <function, context> and populates a new closure object with it. The object is returned by value.

Parameters
functionThe function to be run on closure invokation.
contextThe creation context of the closure.
Returns
The closure object, by value.

◆ uel_closure_invoke()

void* uel_closure_invoke ( uel_closure_t *  closure,
void *  params 
)

Invokes a closure and returns whatever value it returned.

Parameters
closureThe closure reference to be invoked.
paramsThe parameters to be passed along during closure invokation.
Returns
This function returns whatever the closure function returned.

◆ uel_nop()

uel_closure_t uel_nop ( )

Returns a closure that does nothing.

The returned closure can be passed as parameters to functions that take closures as callbacks when the caller does not need to callback.