summaryrefslogtreecommitdiff
path: root/libs/honeysuckle/examples/table_processing
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-04-16 11:55:09 -0500
committersanine <sanine.not@pm.me>2022-04-16 11:55:09 -0500
commitdb81b925d776103326128bf629cbdda576a223e7 (patch)
tree58bea8155c686733310009f6bed7363f91fbeb9d /libs/honeysuckle/examples/table_processing
parent55860037b14fb3893ba21cf2654c83d349cc1082 (diff)
move 3rd-party librarys into libs/ and add built-in honeysuckle
Diffstat (limited to 'libs/honeysuckle/examples/table_processing')
-rw-r--r--libs/honeysuckle/examples/table_processing/table_processing.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/libs/honeysuckle/examples/table_processing/table_processing.c b/libs/honeysuckle/examples/table_processing/table_processing.c
new file mode 100644
index 0000000..64c1f01
--- /dev/null
+++ b/libs/honeysuckle/examples/table_processing/table_processing.c
@@ -0,0 +1,60 @@
+#include <string.h>
+#include <stdlib.h>
+#include <honeysuckle.h>
+
+struct settings
+{
+ bool debug;
+ int debug_level;
+ char *logfile;
+} global_settings;
+
+void set_logfile(const char* filename, void *s)
+{
+ struct settings *settings = (struct settings *) s;
+ settings->logfile = malloc(sizeof(char) * strlen(filename));
+ strcpy(settings->logfile, filename);
+}
+
+int process(lua_State *L)
+{
+ int table_index;
+ hs_parse_args(L, hs_tbl(table_index));
+ hs_process_table(L, table_index,
+ hs_process_bool("debug",
+ hs_pt_set_boolean,
+ &(global_settings.debug)),
+ hs_process_int("level",
+ hs_pt_set_integer,
+ &(global_settings.debug_level)),
+ hs_process_str("logfile",
+ set_logfile,
+ &global_settings));
+ return 0;
+}
+
+int main()
+{
+ lua_State *L = luaL_newstate();
+ luaL_openlibs(L);
+
+ lua_pushcfunction(L, process);
+ lua_setglobal(L, "configure");
+
+ global_settings.debug = false;
+ global_settings.debug_level = 0;
+ global_settings.logfile = "nil";
+
+ printf("settings: [ %d, %d, '%s' ]\n",
+ global_settings.debug,
+ global_settings.debug_level,
+ global_settings.logfile);
+
+ luaL_dostring(L, "configure{debug=true, level=6, logfile='output.log'}");
+
+ printf("settings: [ %d, %d, '%s' ]\n",
+ global_settings.debug,
+ global_settings.debug_level,
+ global_settings.logfile);
+ return 0;
+}