diff options
author | sanine <sanine.not@pm.me> | 2023-02-17 00:48:10 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-02-17 00:48:10 -0600 |
commit | bc4af3b47260ee0f79343303b135d1ea32cde4d4 (patch) | |
tree | 8be0e99b99f3ed70e8514737da0babad0a27a84e /src/util | |
parent | 71af5331b108d6407c791e3859af41ef2b379483 (diff) |
begin remove honeysuckle refactor
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/util.c | 21 | ||||
-rw-r--r-- | src/util/util.h | 17 |
2 files changed, 38 insertions, 0 deletions
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 <lua.h> #include <lauxlib.h> #include <honeysuckle.h> +#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 <lua.h> + +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 |