aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/template.h21
-rw-r--r--src/template.c11
2 files changed, 24 insertions, 8 deletions
diff --git a/include/template.h b/include/template.h
index ba62667..9a34c6a 100644
--- a/include/template.h
+++ b/include/template.h
@@ -40,9 +40,8 @@ char *tpl_render(char *str);
*/
int tpl_render_to_file(char *str, const char *filename);
-struct tplfunc_frame *tpl_getfunc(char *key);
-struct tplfunc_frame;
-typedef int tplfunc(struct tplfunc_frame *frame, void *result);
+typedef int tplfunc(void *frame, void *result);
+
struct tplfunc_frame {
char *key;
tplfunc *func;
@@ -62,6 +61,20 @@ struct tplfunc_frame {
double t_double;
} argv[10]; // accept up to 10 arguments
};
-void tpl_register_func(char *key, struct tplfunc_frame *frame);
+
+/**
+ * Register a template function
+ * @param key function name to expose to "func:" interface
+ * @param tplfunc_ptr pointer to function of type tplfunc
+ * @param argc number of function arguments to accept
+ */
+void tpl_register_func(char *key, void *tplfunc_ptr, int argc);
+
+/**
+ * Get the function frame associated with a template function
+ * @param key function name
+ * @return tplfunc_frame structure
+ */
+struct tplfunc_frame *tpl_getfunc(char *key);
#endif //STASIS_TEMPLATE_H
diff --git a/src/template.c b/src/template.c
index 819fe92..c30d6ae 100644
--- a/src/template.c
+++ b/src/template.c
@@ -25,10 +25,13 @@ extern void tpl_reset() {
tpl_pool_func_used = 0;
}
-void tpl_register_func(char *key, struct tplfunc_frame *frame) {
- (void) key; // TODO: placeholder
- tpl_pool_func[tpl_pool_func_used] = calloc(1, sizeof(*tpl_pool_func[tpl_pool_func_used]));
- memcpy(tpl_pool_func[tpl_pool_func_used], frame, sizeof(*frame));
+void tpl_register_func(char *key, void *tplfunc_ptr, int argc) {
+ struct tplfunc_frame *frame = calloc(1, sizeof(*frame));
+ frame->key = strdup(key);
+ frame->argc = argc;
+ frame->func = tplfunc_ptr;
+
+ tpl_pool_func[tpl_pool_func_used] = frame;
tpl_pool_func_used++;
}