diff options
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 41 |
1 files changed, 30 insertions, 11 deletions
@@ -191,22 +191,41 @@ char *str = hs_enum_to_string(L, index, VALUE_3); // "three" [(Back to top)](#table-of-contents) `hs_process_table()` is intended for creating lua bindings that can be called -like `set_config{ debug=true, verbosity=2, logfile='run.log' }`. It can -only operate on stringly-keyed values. +like `set_config{ debug=true, verbosity=2, logfile='run.log' }`. It operates +only on values with string keys and boolean, number, or string types. +`hs_process_table()` accepts a lua_State pointer, a stack index for the table to +operate on, and then a series of string key/data type/function/user data void +pointer quadruplets, finished off by `HS_END`. This function does not pop the +table from the stack. + +honeysuckle provides the functions `hs_pt_set_bool`, `hs_pt_set_int`, +`hs_pt_set_num`, and `hs_pt_set_string` for the very common operations of "set +a variable to the provided value". User-defined functions should have signature +`void (function)([type], void *)`, where [type] is either `lua_Boolean`, +`lua_Integer`, `lua_Number`, or `const char *`, depending on the expected +value type. + ```c -void set_verbosity(int value, void *data) { // set verbosity level } -void set_debug(bool value, void *data) { // set debug } -void set_logfile(char *value, void *data) { // set log filename } -void process_any_key(int stack_index, void *data) { // do something } +void open_logfile(const char *logfile, void *settings) { + // do something to open and configure the logfile +} // tbl_index comes from somewhere... + +struct settings { + bool debug; + int verbosity; + float epsilon; +}; + +struct settings s; -hs_process_table(L, tbl_index, NULL, - "verbosity", HS_INT, set_verbosity, - "debug", HS_BOOL, set_debug, - "logfile", HS_STR, set_logfile, - "extraData", HS_ANY, process_any_key, +hs_process_table(L, tbl_index, + "verbosity", HS_INT, hs_pt_set_int, &(s.verbosity), + "debug", HS_BOOL, hs_pt_set_bool, &(s.debug), + "logfile", HS_STR, set_logfile, &s + "epsilon", HS_NUM, hs_pt_set_num, &(s.epsilon), HS_END); ``` |