Clingo
Loading...
Searching...
No Matches
clingo_ground_event_handler Struct Reference

The ground event handler interface. More...

#include <ground.h>

Public Attributes

bool(* callable )(char const *name, size_t name_size, size_t arguments_size, void *data, bool *result)
 Check if the function with the given name and number of arguments is callable.
 
bool(* call )(clingo_lib_t *lib, clingo_location_t const *location, char const *name, size_t name_size, clingo_symbol_t const *arguments, size_t arguments_size, void *data, clingo_symbol_callback_t symbol_callback, void *symbol_callback_data)
 Callback function to implement external functions.
 
void(* finish )(clingo_ground_result_t result, void *data)
 Callback to notify that the grounding has finished.
 
void(* free )(void *data)
 Callback to free the userdata of the handler.
 

Detailed Description

The ground event handler interface.

Member Data Documentation

◆ call

bool(* clingo_ground_event_handler::call) (clingo_lib_t *lib, clingo_location_t const *location, char const *name, size_t name_size, clingo_symbol_t const *arguments, size_t arguments_size, void *data, clingo_symbol_callback_t symbol_callback, void *symbol_callback_data)

Callback function to implement external functions.

If an external function of form @name(parameters) occurs in a logic program, then this function is called with its location, name, parameters, and a callback to inject symbols as arguments. The callback can be called multiple times; all symbols passed are injected.

If a (non-recoverable) clingo API function fails in this callback, for example, the symbol callback, the callback must return its return code. In case of errors not related to clingo, this function can use clingo_set_error().

Parameters
[in]libthe library object
[in]locationlocation from which the external function was called
[in]namename of the called external function
[in]argumentsarguments of the called external function
[in]arguments_sizenumber of arguments
[in]datauser data of the callback
[in]symbol_callbackfunction to inject symbols
[in]symbol_callback_datauser data for the symbol callback (must be passed untouched)
Returns
whether the call was successful
See also
clingo_control_ground()

The following example implements the external function @f() returning 42.

bool
clingo_location_t const *location,
char const *name,
size_t name_size,
clingo_symbol_t const *arguments,
void *data,
if (size == 1 && strncmp(name, "f", 1) == 0 && arguments_size == 0) {
}
return clingo_set_error(lib, clingo_result_runtime, "function not found", 18);
}
CLINGO_VISIBILITY_DEFAULT bool clingo_set_error(clingo_result_t code, char const *message, size_t size)
Set an error in the current thread.
struct clingo_lib clingo_lib_t
A library object storing global information.
Definition core.h:171
struct clingo_location clingo_location_t
Represents a source code location marking its beginning and end.
Definition core.h:354
@ clingo_result_runtime
errors only detectable at runtime like invalid input
Definition core.h:99
bool(* clingo_symbol_callback_t)(clingo_symbol_t const *symbols, size_t symbols_size, void *data)
Callback function to inject symbols.
Definition symbol.h:60
uint64_t clingo_symbol_t
Type to represent a symbol.
Definition symbol.h:51
CLINGO_VISIBILITY_DEFAULT clingo_symbol_t clingo_symbol_create_number(int32_t number)
Construct a symbol representing a number.
bool(* call)(clingo_lib_t *lib, clingo_location_t const *location, char const *name, size_t name_size, clingo_symbol_t const *arguments, size_t arguments_size, void *data, clingo_symbol_callback_t symbol_callback, void *symbol_callback_data)
Callback function to implement external functions.
Definition ground.h:116

◆ callable

bool(* clingo_ground_event_handler::callable) (char const *name, size_t name_size, size_t arguments_size, void *data, bool *result)

Check if the function with the given name and number of arguments is callable.

Parameters
[in]namename of the called external function
[in]name_sizesize of the name
[in]arguments_sizenumber of arguments
[in]datauser data of the callback
[out]resultwhether the function is callable
Returns
whether the call was successful

◆ finish

void(* clingo_ground_event_handler::finish) (clingo_ground_result_t result, void *data)

Callback to notify that the grounding has finished.

This can be used for thread synchronization as the function is not called in the main thread when grounding asynchronously.

Parameters
resultthe ground result
datathe user data

◆ free

void(* clingo_ground_event_handler::free) (void *data)

Callback to free the userdata of the handler.

Parameters
datathe user data

The documentation for this struct was generated from the following file: