diff options
author | sanine <sanine.not@pm.me> | 2022-04-16 11:55:09 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2022-04-16 11:55:09 -0500 |
commit | db81b925d776103326128bf629cbdda576a223e7 (patch) | |
tree | 58bea8155c686733310009f6bed7363f91fbeb9d /libs/honeysuckle/src/hs_pushstring.c | |
parent | 55860037b14fb3893ba21cf2654c83d349cc1082 (diff) |
move 3rd-party librarys into libs/ and add built-in honeysuckle
Diffstat (limited to 'libs/honeysuckle/src/hs_pushstring.c')
-rw-r--r-- | libs/honeysuckle/src/hs_pushstring.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/libs/honeysuckle/src/hs_pushstring.c b/libs/honeysuckle/src/hs_pushstring.c new file mode 100644 index 0000000..f7da0d0 --- /dev/null +++ b/libs/honeysuckle/src/hs_pushstring.c @@ -0,0 +1,31 @@ +#include <stdlib.h> + +#include "honeysuckle.h" + +void hs_vpushstring(lua_State *L, const char *format_string, va_list args) +{ + va_list args_; + 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 a string"); + lua_error(L); + } + + vsnprintf(string, string_size+1, format_string, args); + lua_pushstring(L, string); + free(string); +} + + +void hs_pushstring(lua_State *L, const char *format_string, ...) +{ + va_list args; + va_start(args, format_string); + hs_vpushstring(L, format_string, args); + va_end(args); +} |