From 4749e1a01e989999eef9f4131cf2edf6e3211ebc Mon Sep 17 00:00:00 2001 From: sanine-a Date: Fri, 23 Oct 2020 21:52:10 -0500 Subject: add key binding input functions --- src/honey_lua.c | 184 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 165 insertions(+), 19 deletions(-) (limited to 'src/honey_lua.c') diff --git a/src/honey_lua.c b/src/honey_lua.c index 1cbd483..f397872 100644 --- a/src/honey_lua.c +++ b/src/honey_lua.c @@ -1,46 +1,192 @@ #include "common.h" +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +honey_result honey_format_string(char** string, + char* format_string, + ...) +{ + honey_result res; + va_list args, args_; + va_start(args, format_string); + va_copy(args_, args); + + int string_size = vsnprintf(NULL, 0, format_string, args_); + va_end(args_); + *string = malloc((string_size+1) * sizeof(char)); + if (*string == NULL) + res = HONEY_MEMORY_ALLOCATION_ERROR; + else { + vsnprintf(*string, string_size+1, format_string, args); + res = HONEY_OK; + } + + va_end(args); + + return res; +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +bool honey_lua_validate_types(lua_State* L, + unsigned int n_types, + ...) +{ + va_list args; + va_start(args, n_types); + + for (int i=0; i