From eedb9a17c548ae006d8d3df67c8c771b9dcc8b42 Mon Sep 17 00:00:00 2001 From: sanine Date: Sat, 28 Aug 2021 17:04:23 -0500 Subject: create hs_create_table.c and add to build --- src/honeysuckle.h | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) (limited to 'src/honeysuckle.h') diff --git a/src/honeysuckle.h b/src/honeysuckle.h index db26562..f54a261 100644 --- a/src/honeysuckle.h +++ b/src/honeysuckle.h @@ -60,8 +60,10 @@ struct hs_arg { void hs_parse_args_(lua_State *L, int n_args, struct hs_arg *arguments); -#define hs_parse_args(L, ...) \ - hs_parse_args_(L, VA_NARGS(__VA_ARGS__)/2, (struct hs_arg[]) { __VA_ARGS__ }) +#define hs_parse_args(L, ...) \ + hs_parse_args_(L, \ + VA_NARGS(__VA_ARGS__)/2, \ + (struct hs_arg[]) { __VA_ARGS__ }) #define hs_overload(...) VA_NARGS(__VA_ARGS__)/2, (struct hs_arg[]) { __VA_ARGS__ } @@ -99,7 +101,7 @@ struct hs_tbl_entry { lua_CFunction function; void *userdata; } value; -} +}; #define hs_bool_bool(key, value) \ { HS_BOOL, .key.boolean=key, HS_BOOL, .value.boolean=value } @@ -253,8 +255,20 @@ struct hs_tbl_entry { #define hs_light_light(key, value) \ { HS_LIGHT, .key.userdata=key, HS_LIGHT, .value.userdata=value } +int hs_create_table_(lua_State *L, int n_elements, struct hs_tbl_entry *elements); + +#define hs_create_table(L, ...) \ + hs_create_table_(L, \ + VA_NARGS(__VA_ARGS__)/4, \ + (struct hs_tbl_entry[]) { __VA_ARGS__ }) -int hs_create_table(lua_State *L, ...); + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * + * hs_process_table + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ void hs_process_table(lua_State *L, int table_index, void *data, ...); // default processors @@ -263,16 +277,37 @@ void hs_pt_set_integer(lua_Integer value, void *data); void hs_pt_set_number(lua_Number value, void *data); void hs_pt_set_string(const char *value, void *data); + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * + * hs_pushstring + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + void hs_vpushstring(lua_State *L, const char *format_string, va_list args); void hs_pushstring(lua_State *L, const char *format_string, ...); -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * + * error creation and handling + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ void hs_throw_error(lua_State *L, const char *format_string, ...); int hs_traceback(lua_State *L); int hs_call(lua_State *L, int nargs, int nret); + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * + * registry operations + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + #define hs_rstore(L) luaL_ref(L, LUA_REGISTRYINDEX); #define hs_rload(L, ref) lua_rawgeti(L, LUA_REGISTRYINDEX, ref) #define hs_rdel(L, ref) luaL_unref(L, LUA_REGISTRYINDEX, ref) -- cgit v1.2.1