summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2021-07-03 13:47:25 -0500
committersanine-a <sanine.not@pm.me>2021-07-03 13:47:25 -0500
commit392c95302d97b14d4a2bb89ebb49d8db0ae0420b (patch)
tree63e084040617eb6519f385e91f2cb3dac1de3d2e
parentf83e8d242b8a719733498181f4cad3fbb9c97ca7 (diff)
update README for table processing
-rw-r--r--README.md41
1 files changed, 30 insertions, 11 deletions
diff --git a/README.md b/README.md
index 5953056..7f53b36 100644
--- a/README.md
+++ b/README.md
@@ -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);
```