summaryrefslogtreecommitdiff
path: root/src/honeysuckle.h
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2021-09-04 01:06:07 -0500
committersanine <sanine.not@pm.me>2021-09-04 01:06:07 -0500
commit22a39a8a55aaf6aa15cbaf82c2f26450335196e3 (patch)
tree6c136fc584c6608bc7900d9e853e4093f3cd40f0 /src/honeysuckle.h
parentbff77649543d2f43db4959b76f045a7a7f87c6a2 (diff)
add hs_process_table.c and remove honeysuckle.c
Diffstat (limited to 'src/honeysuckle.h')
-rw-r--r--src/honeysuckle.h37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/honeysuckle.h b/src/honeysuckle.h
index 378e0a1..871384c 100644
--- a/src/honeysuckle.h
+++ b/src/honeysuckle.h
@@ -365,7 +365,12 @@ int hs_create_table_(lua_State *L, int n_elements, struct hs_tbl_entry *elements
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
-void hs_process_table(lua_State *L, int table_index, void *data, ...);
+typedef void (*hs_pt_bool_callback)(bool, void *);
+typedef void (*hs_pt_int_callback)(lua_Integer, void *);
+typedef void (*hs_pt_num_callback)(lua_Number, void *);
+typedef void (*hs_pt_str_callback)(const char *, void *);
+
+
// default processors
void hs_pt_set_boolean(bool value, void *data);
void hs_pt_set_integer(lua_Integer value, void *data);
@@ -373,6 +378,36 @@ void hs_pt_set_number(lua_Number value, void *data);
void hs_pt_set_string(const char *value, void *data);
+struct hs_table_processor {
+ const char *key;
+ hs_type type;
+ union {
+ hs_pt_bool_callback boolean;
+ hs_pt_int_callback integer;
+ hs_pt_num_callback number;
+ hs_pt_str_callback string;
+ } func;
+ void *data;
+};
+
+#define hs_process_bool(str, f, d) \
+ { .key=(str), .type=HS_BOOL, .func.boolean=(f), .data=(d) }
+#define hs_process_int(str, f, d) \
+ { .key=(str), .type=HS_INT, .func.integer=(f), .data=(d) }
+#define hs_process_num(str, f, d) \
+ { .key=(str), .type=HS_NUM, .func.number=(f), .data=(d) }
+#define hs_process_str(str, f, d) \
+ { .key=(str), .type=HS_STR, .func.string=(f), .data=(d) }
+
+void hs_process_table_(lua_State *L,
+ int table_index,
+ int n_processors,
+ struct hs_table_processor *processors);
+
+#define hs_process_table(L, table_index, ...) \
+ hs_process_table(L, table_index, VA_NARGS(__VA_ARGS__)/4, {__VA_ARGS__})
+
+
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* hs_pushstring