Add a function to call a function by name.
This commit is contained in:
@@ -820,4 +820,27 @@ libab_result libab_interpreter_run(libab_interpreter* intr, libab_tree* tree,
|
||||
return result;
|
||||
}
|
||||
|
||||
libab_result libab_interpreter_run_function(libab_interpreter* intr,
|
||||
const char* function,
|
||||
libab_ref_vec* params,
|
||||
libab_ref* into) {
|
||||
struct interpreter_state state;
|
||||
libab_ref function_value;
|
||||
libab_result result;
|
||||
|
||||
_interpreter_init(&state, intr);
|
||||
|
||||
libab_ref_null(into);
|
||||
result = _interpreter_require_value(&state.ab->table,
|
||||
function, &function_value);
|
||||
if(result == LIBAB_SUCCESS) {
|
||||
libab_ref_free(into);
|
||||
_interpreter_try_call(&state, &function_value, params, into);
|
||||
}
|
||||
|
||||
_interpreter_free(&state);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void libab_interpreter_free(libab_interpreter* intr) {}
|
||||
|
||||
@@ -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