Add a function to call a function by name.
This commit is contained in:
@@ -375,6 +375,33 @@ libab_result libab_run(libab* ab, const char* string, libab_ref* value) {
|
||||
return result;
|
||||
}
|
||||
|
||||
libab_result libab_run_function(libab* ab, const char* function,
|
||||
libab_ref* into,
|
||||
size_t param_count, ...) {
|
||||
libab_ref_vec params;
|
||||
va_list args;
|
||||
libab_result result = LIBAB_SUCCESS;
|
||||
|
||||
va_start(args, param_count);
|
||||
libab_ref_null(into);
|
||||
result = libab_ref_vec_init(¶ms);
|
||||
if(result == LIBAB_SUCCESS) {
|
||||
while(result == LIBAB_SUCCESS && param_count--) {
|
||||
result = libab_ref_vec_insert(¶ms, va_arg(args, libab_ref*));
|
||||
}
|
||||
|
||||
if(result == LIBAB_SUCCESS) {
|
||||
libab_ref_free(into);
|
||||
result = libab_interpreter_run_function(&ab->intr, function, ¶ms, into);
|
||||
}
|
||||
|
||||
libab_ref_vec_free(¶ms);
|
||||
}
|
||||
va_end(args);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
libab_result libab_free(libab* ab) {
|
||||
libab_table_free(libab_ref_get(&ab->table));
|
||||
libab_ref_free(&ab->table);
|
||||
|
||||
Reference in New Issue
Block a user