diff options
author | sanine-a <sanine.not@pm.me> | 2021-08-08 16:15:01 -0500 |
---|---|---|
committer | sanine-a <sanine.not@pm.me> | 2021-08-08 16:15:01 -0500 |
commit | 1459422a3dc158fa4c7222f7780d134261458b7c (patch) | |
tree | 5a86808284ce948d65fafc1bd4fcd4cfdc97202e /src/hs_throw_error.c | |
parent | e97f0a3b4e27a7c9539c0423e1363ba6f3faf0c1 (diff) |
add hs_throw_error() implementation and fix bug in tests
Diffstat (limited to 'src/hs_throw_error.c')
-rw-r--r-- | src/hs_throw_error.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/hs_throw_error.c b/src/hs_throw_error.c new file mode 100644 index 0000000..b2377dd --- /dev/null +++ b/src/hs_throw_error.c @@ -0,0 +1,23 @@ +#include <stdlib.h> + +#include "honeysuckle.h" + +void hs_throw_error(lua_State *L, const char *format_string, ...) +{ + 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_); + + char *string = malloc((string_size+1) * sizeof(char)); + if (string == NULL) + lua_pushstring(L, "there was an error allocating memory for an error message"); + else { + vsnprintf(string, string_size+1, format_string, args); + lua_pushstring(L, string); + free(string); + } + lua_error(L); +} |