diff options
Diffstat (limited to 'src/honeysuckle.h')
-rw-r--r-- | src/honeysuckle.h | 37 |
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 |