aboutsummaryrefslogtreecommitdiffstats
path: root/gawkapi.h
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2012-07-11 21:41:54 +0300
committerArnold D. Robbins <arnold@skeeve.com>2012-07-11 21:41:54 +0300
commit73533707616e119778993fe18540098239ecbb2e (patch)
treec9a9f98f65cd2248e0110be526d555a446ea4b8a /gawkapi.h
parent6d1724214a95330b63a6a557f89fb9b40b4a521f (diff)
downloadegawk-73533707616e119778993fe18540098239ecbb2e.tar.gz
egawk-73533707616e119778993fe18540098239ecbb2e.tar.bz2
egawk-73533707616e119778993fe18540098239ecbb2e.zip
Add ability to call an initialization routine.
Diffstat (limited to 'gawkapi.h')
-rw-r--r--gawkapi.h26
1 files changed, 25 insertions, 1 deletions
diff --git a/gawkapi.h b/gawkapi.h
index 2bef258e..9f541cfc 100644
--- a/gawkapi.h
+++ b/gawkapi.h
@@ -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); \
}