diff options
Diffstat (limited to 'gawkapi.h')
-rw-r--r-- | gawkapi.h | 26 |
1 files changed, 25 insertions, 1 deletions
@@ -533,9 +533,13 @@ make_number(double num, awk_value_t *result) * * int dl_load(gawk_api_t *api_p, awk_ext_id_t id) * + * The return value should be zero on failure and non-zero on success. + * * For the macros to work, the function should save api_p in a global * variable named 'api' and save id in a global variable named 'ext_id'. - * The return value should be zero on failure and non-zero on success. + * In addition, a global function pointer named 'init_func' should be + * defined and set to either NULL or an initialization function that + * returns non-zero on success and zero upon failure. */ extern int dl_load(const gawk_api_t *const api_p, awk_ext_id_t id); @@ -549,6 +553,19 @@ static awk_ext_func_t func_table[] = { /* ... */ }; +/* EITHER: */ + +static awk_bool_t (*init_func)(void) = NULL; + +/* OR: */ + +static awk_bool_t init_my_module(void) +{ + ... +} + +static awk_bool_t (*init_func)(void) = init_my_module; + dl_load_func(func_table, some_name, "name_space_in_quotes") #endif @@ -579,6 +596,13 @@ int dl_load(const gawk_api_t *const api_p, awk_ext_id_t id) \ } \ } \ \ + if (init_func != NULL) { \ + if (! init_func()) { \ + warning(ext_id, #module ": initialization function failed\n"); \ + errors++; \ + } \ + } \ +\ return (errors == 0); \ } |