DETLEF C SDK
Native embedding and package authoring
Loading...
Searching...
No Matches
Callbacks and Registration

Functions

DetlefStatus detlef_register_binding (DetlefAccess *a, DetlefSlice input, DetlefHandle handle)
 
DetlefStatus detlef_stdlib_install (DetlefAccess *a, DetlefOutput output_callback, void *output_data, DetlefLineInput input_callback, void *input_data)
 
DetlefStatus detlef_argument_count (DetlefAccess *a, size_t *out)
 
DetlefStatus detlef_argument_evaluate (DetlefAccess *a, size_t index, DetlefHandle *out)
 
DetlefStatus detlef_argument_value (DetlefAccess *a, size_t index, DetlefHandle *out)
 
DetlefStatus detlef_argument_boolean (DetlefAccess *a, size_t index, DetlefBool *out)
 
DetlefStatus detlef_argument_expression (DetlefAccess *a, size_t index, DetlefHandle *out)
 
DetlefStatus detlef_argument_identifier (DetlefAccess *a, size_t index, DetlefText *out)
 
DetlefStatus detlef_argument_span (DetlefAccess *a, size_t index, DetlefSpan *out)
 
DetlefStatus detlef_call_span (DetlefAccess *a, DetlefSpan *out)
 
DetlefStatus detlef_callback_error (DetlefAccess *a, DetlefSlice message, DetlefSpan span, DetlefBool has_span)
 
DetlefStatus detlef_access_error (DetlefAccess *a, DetlefText *out, DetlefSpan *span, DetlefBool *has_span)
 
DetlefStatus detlef_register_function (DetlefAccess *a, DetlefSlice input, const DetlefNamed *params, size_t count, const DetlefNamed *vararg, DetlefFunctionCallback callback, void *data)
 
DetlefStatus detlef_register_control (DetlefAccess *a, DetlefSlice input, DetlefCallback callback, void *data)
 
DetlefStatus detlef_register_script_function (DetlefAccess *a, DetlefSlice input, const DetlefNamed *params, size_t count, const DetlefNamed *vararg, DetlefHandle body, DetlefHandle env)
 

Detailed Description

Function Documentation

◆ detlef_access_error()

DetlefStatus detlef_access_error ( DetlefAccess *  a,
DetlefText *  out,
DetlefSpan *  span,
DetlefBool *  has_span 
)

Copy the last diagnostic associated with this access, including an optional source span. Reading it does not clear the error.

Parameters
aBorrowed callback access. Must not be freed, saved, or used outside its current callback.
[out]outReceives owned UTF-8 text without a trailing NUL. Must be freed once with detlef_text_free().
[out]spanReceives a half-open source range in UTF-8 byte offsets. No cleanup is required.
[out]has_spanReceives one when a diagnostic includes a span, otherwise zero. No cleanup is required.
Returns
DETLEF_OK on success; otherwise a DetlefStatus error code.

◆ detlef_argument_boolean()

DetlefStatus detlef_argument_boolean ( DetlefAccess *  a,
size_t  index,
DetlefBool *  out 
)

Read an argument as a boolean, evaluating it in a Control. Non-boolean values are rejected.

Parameters
aBorrowed callback access. Must not be freed, saved, or used outside its current callback.
indexZero-based argument index.
[out]outReceives DETLEF_FALSE or DETLEF_TRUE.
Returns
DETLEF_OK on success; otherwise a DetlefStatus error code.

◆ detlef_argument_count()

DetlefStatus detlef_argument_count ( DetlefAccess *  a,
size_t *  out 
)

Read the number of arguments supplied to the current callable. A setup access has no callable arguments.

Parameters
aBorrowed callback access. Must not be freed, saved, or used outside its current callback.
[out]outReceives the number of arguments in the current callback.
Returns
DETLEF_OK on success; otherwise a DetlefStatus error code.

◆ detlef_argument_evaluate()

DetlefStatus detlef_argument_evaluate ( DetlefAccess *  a,
size_t  index,
DetlefHandle *  out 
)

Evaluate a Control argument by zero-based index. Repeated calls repeat evaluation and its side effects. Functions return their already evaluated argument.

Parameters
aBorrowed callback access. Must not be freed, saved, or used outside its current callback.
indexZero-based argument index.
[out]outOn success, receives an owned evaluation handle for the argument, including descriptors or void. Release with detlef_handle_release() unless transferred as a callback result.
Returns
DETLEF_OK on success; otherwise a DetlefStatus error code.

◆ detlef_argument_expression()

DetlefStatus detlef_argument_expression ( DetlefAccess *  a,
size_t  index,
DetlefHandle *  out 
)

Obtain the unevaluated expression for a Control argument. Eager Function arguments do not have expressions.

Parameters
aBorrowed callback access. Must not be freed, saved, or used outside its current callback.
indexZero-based argument index.
[out]outOn success, receives an owned argument expression handle. Release with detlef_handle_release().
Returns
DETLEF_OK on success; otherwise a DetlefStatus error code.

◆ detlef_argument_identifier()

DetlefStatus detlef_argument_identifier ( DetlefAccess *  a,
size_t  index,
DetlefText *  out 
)

Copy the identifier in a Control argument without evaluating it. Non-identifier expressions are rejected.

Parameters
aBorrowed callback access. Must not be freed, saved, or used outside its current callback.
indexZero-based argument index.
[out]outReceives owned UTF-8 text without a trailing NUL. Must be freed once with detlef_text_free().
Returns
DETLEF_OK on success; otherwise a DetlefStatus error code.

◆ detlef_argument_span()

DetlefStatus detlef_argument_span ( DetlefAccess *  a,
size_t  index,
DetlefSpan *  out 
)

Read a Control argument's source span in UTF-8 byte offsets.

Parameters
aBorrowed callback access. Must not be freed, saved, or used outside its current callback.
indexZero-based argument index.
[out]outReceives the argument's half-open source range in UTF-8 byte offsets.
Returns
DETLEF_OK on success; otherwise a DetlefStatus error code.

◆ detlef_argument_value()

DetlefStatus detlef_argument_value ( DetlefAccess *  a,
size_t  index,
DetlefHandle *  out 
)

Obtain a runtime value from an argument, evaluating it in a Control. Void and descriptor results are rejected.

Parameters
aBorrowed callback access. Must not be freed, saved, or used outside its current callback.
indexZero-based argument index.
[out]outOn success, receives an owned runtime value handle for the argument. Release with detlef_handle_release() unless transferred as a callback result.
Returns
DETLEF_OK on success; otherwise a DetlefStatus error code.

◆ detlef_call_span()

DetlefStatus detlef_call_span ( DetlefAccess *  a,
DetlefSpan *  out 
)

Read the current Control call's source span. The operation requires an expression- backed callback.

Parameters
aBorrowed callback access. Must not be freed, saved, or used outside its current callback.
[out]outReceives the current call's half-open source range in UTF-8 byte offsets.
Returns
DETLEF_OK on success; otherwise a DetlefStatus error code.

◆ detlef_callback_error()

DetlefStatus detlef_callback_error ( DetlefAccess *  a,
DetlefSlice  message,
DetlefSpan  span,
DetlefBool  has_span 
)

Set a callback diagnostic and return DETLEF_ERROR. The message is copied. Set has_span to one to attach a source range.

Parameters
aBorrowed callback access. Must not be freed, saved, or used outside its current callback.
messageBorrowed UTF-8 diagnostic text, copied during this call.
spanHalf-open source range in UTF-8 byte offsets.
has_spanOne attaches a source span; zero omits it.
Returns
DETLEF_ERROR after copying the callback diagnostic.

◆ detlef_register_binding()

DetlefStatus detlef_register_binding ( DetlefAccess *  a,
DetlefSlice  input,
DetlefHandle  handle 
)

Register a named value binding by copying its value. The supplied handle remains owned by its caller; this is separate from declaring a mutable variable.

Parameters
aBorrowed callback access. Must not be freed, saved, or used outside its current callback.
inputBorrowed UTF-8 name, without a trailing NUL requirement. Storage may be released after the call.
handleBorrowed runtime value handle to bind. Not consumed.
Returns
DETLEF_OK on success; otherwise a DetlefStatus error code.

◆ detlef_register_control()

DetlefStatus detlef_register_control ( DetlefAccess *  a,
DetlefSlice  input,
DetlefCallback  callback,
void *  data 
)

Register a lazy Control with full context access. Callback code and data must remain valid while the registration can be invoked.

Parameters
aBorrowed callback access. Must not be freed, saved, or used outside its current callback.
inputBorrowed UTF-8 name, without a trailing NUL requirement. Storage may be released after the call.
callbackSynchronous callback. Its code and associated data must remain valid while registered; DETLEF does not free them.
dataHost-owned callback data. Must remain valid while its callback can run; DETLEF never frees it.
Returns
DETLEF_OK on success; otherwise a DetlefStatus error code.

◆ detlef_register_function()

DetlefStatus detlef_register_function ( DetlefAccess *  a,
DetlefSlice  input,
const DetlefNamed *  params,
size_t  count,
const DetlefNamed *  vararg,
DetlefFunctionCallback  callback,
void *  data 
)

Register an eager native Function using resolved parameter types and an optional variadic parameter. Callback code and data must remain valid while the registration can be invoked.

Parameters
aBorrowed callback access. Must not be freed, saved, or used outside its current callback.
inputBorrowed UTF-8 name, without a trailing NUL requirement. Storage may be released after the call.
paramsBorrowed parameter names paired with resolved type descriptors. Names are copied; handles are not consumed.
countNumber of entries in the supplied array.
varargOptional borrowed variadic parameter with a resolved element type descriptor; NULL means no variadic parameter.
callbackSynchronous callback. Its code and associated data must remain valid while registered; DETLEF does not free them.
dataHost-owned callback data. Must remain valid while its callback can run; DETLEF never frees it.
Returns
DETLEF_OK on success; otherwise a DetlefStatus error code.

◆ detlef_register_script_function()

DetlefStatus detlef_register_script_function ( DetlefAccess *  a,
DetlefSlice  input,
const DetlefNamed *  params,
size_t  count,
const DetlefNamed *  vararg,
DetlefHandle  body,
DetlefHandle  env 
)

Register a script Function using resolved parameter types and a body expression. A zero environment handle captures the current environment.

Parameters
aBorrowed callback access. Must not be freed, saved, or used outside its current callback.
inputBorrowed UTF-8 name, without a trailing NUL requirement. Storage may be released after the call.
paramsBorrowed parameter names paired with resolved type descriptors. Names are copied; handles are not consumed.
countNumber of entries in the supplied array.
varargOptional borrowed variadic parameter with a resolved element type descriptor; NULL means no variadic parameter.
bodyBorrowed body expression handle, copied into the registration. Not consumed.
envBorrowed captured-environment handle; zero captures the current environment. Not consumed.
Returns
DETLEF_OK on success; otherwise a DetlefStatus error code.

◆ detlef_stdlib_install()

DetlefStatus detlef_stdlib_install ( DetlefAccess *  a,
DetlefOutput  output_callback,
void *  output_data,
DetlefLineInput  input_callback,
void *  input_data 
)

Install the standard library with synchronous output and optional input callbacks. Output bytes are borrowed; input bytes remain host-owned and are copied immediately after the input callback returns. A null input callback means EOF.

Parameters
aBorrowed callback access. Must not be freed, saved, or used outside its current callback.
output_callbackSynchronous callback. Its code and associated data must remain valid while registered; DETLEF does not free them.
output_dataHost-owned callback data. Must remain valid while its callback can run; DETLEF never frees it.
input_callbackSynchronous callback. Its access and borrowed buffers must not escape the callback. Input may be NULL to provide EOF.
input_dataHost-owned callback data. Must remain valid while its callback can run; DETLEF never frees it.
Returns
DETLEF_OK on success; otherwise a DetlefStatus error code.