Create a new creation function for new initialization type.
This commit is contained in:
parent
cbd57f2585
commit
9b575916ff
|
@ -115,6 +115,18 @@ libab_result libab_create_function_tree(libab_ref* into,
|
||||||
void (*free_function)(void*),
|
void (*free_function)(void*),
|
||||||
libab_tree* tree,
|
libab_tree* tree,
|
||||||
libab_ref* scope);
|
libab_ref* scope);
|
||||||
|
/**
|
||||||
|
* Allocates a function that uses a given behavior to run.
|
||||||
|
* @param into the reference into which to store the new function.
|
||||||
|
* @param free_function the free function used to free function instances.
|
||||||
|
* @param behavior the behavior that dictates what the function does.
|
||||||
|
* @param scope the scope in which this function was declared.
|
||||||
|
* @return libab_result the result of any necessary allocations.
|
||||||
|
*/
|
||||||
|
libab_result libab_create_function_behavior(libab_ref* into,
|
||||||
|
void (*free_function)(void*),
|
||||||
|
libab_behavior* behavior,
|
||||||
|
libab_ref* scope);
|
||||||
/**
|
/**
|
||||||
* Creates a function list object, storing it in to the given reference.
|
* Creates a function list object, storing it in to the given reference.
|
||||||
* @param into the reference to store into.
|
* @param into the reference to store into.
|
||||||
|
|
28
src/util.c
28
src/util.c
|
@ -264,6 +264,34 @@ libab_result libab_create_function_tree(libab_ref* into,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
libab_result libab_create_function_behavior(libab_ref* into,
|
||||||
|
void (*free_function)(void*),
|
||||||
|
libab_behavior* behavior,
|
||||||
|
libab_ref* scope) {
|
||||||
|
libab_function* new_function;
|
||||||
|
libab_result result = LIBAB_SUCCESS;
|
||||||
|
|
||||||
|
if((new_function = malloc(sizeof(*new_function)))) {
|
||||||
|
result = libab_function_init_behavior(new_function, behavior, scope);
|
||||||
|
} else {
|
||||||
|
result = LIBAB_MALLOC;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(result == LIBAB_SUCCESS) {
|
||||||
|
result = libab_ref_new(into, new_function, free_function);
|
||||||
|
if(result != LIBAB_SUCCESS) {
|
||||||
|
libab_function_free(new_function);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(result != LIBAB_SUCCESS) {
|
||||||
|
libab_ref_null(into);
|
||||||
|
free(new_function);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
libab_result libab_create_function_list(libab_ref* into, libab_ref* type) {
|
libab_result libab_create_function_list(libab_ref* into, libab_ref* type) {
|
||||||
libab_function_list* list;
|
libab_function_list* list;
|
||||||
libab_result result = LIBAB_SUCCESS;
|
libab_result result = LIBAB_SUCCESS;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user