From bc4af3b47260ee0f79343303b135d1ea32cde4d4 Mon Sep 17 00:00:00 2001 From: sanine Date: Fri, 17 Feb 2023 00:48:10 -0600 Subject: begin remove honeysuckle refactor --- src/util/util.c | 21 +++++++++++++++++++++ src/util/util.h | 17 +++++++++++++++++ 2 files changed, 38 insertions(+) (limited to 'src/util') diff --git a/src/util/util.c b/src/util/util.c index 89e9d38..52e2a16 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -1,6 +1,27 @@ #include #include #include +#include "util.h" + +void create_table(lua_State *L, struct honey_tbl_t *tbl) +{ + lua_createtable(L, 0, 0); + int t = lua_gettop(L); + + for (struct honey_tbl_t *pair = tbl; pair->key != NULL; pair += 1) { + if (pair->type == LUA_TNUMBER) { + lua_pushinteger(L, pair->value.integer); + lua_setfield(L, t, pair->key); + } + else if (pair->type == LUA_TFUNCTION) { + lua_pushcfunction(L, pair->value.function); + lua_setfield(L, t, pair->key); + } + else { + /* bad type, ignore */ + } + } +} void append_table(lua_State *L, int tbl_a, int tbl_b) { diff --git a/src/util/util.h b/src/util/util.h index 231bcc9..6092d11 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -3,7 +3,24 @@ #include + +struct honey_tbl_t { + const char *key; + int type; + union { + lua_Integer integer; + lua_CFunction function; + } value; +}; + +#define H_INT(k, v) { .key=k, .type=LUA_TNUMBER, .value.integer=v } +#define H_ENUM(v) { .key=#v, .type=LUA_TNUMBER, .value.integer=v } +#define H_FUNC(k, v) { .key=k, .type=LUA_TFUNCTION, .value.function=v } +#define H_END { .key=NULL, .type=LUA_TNIL, .value.integer=0 } + + void setup_util(lua_State *L, int honey_tbl); +void create_table(lua_State *L, struct honey_tbl_t *tbl); void append_table(lua_State *L, int tbl_a, int tbl_b); #endif -- cgit v1.2.1