summaryrefslogtreecommitdiff
path: root/src/hs_throw_error.c
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2021-08-21 23:06:27 -0500
committersanine <sanine.not@pm.me>2021-08-21 23:06:27 -0500
commitcd4a04ee73e50056f3d04e9f13b490dbf5ed800a (patch)
treec3f758f6b9eb1a052faec9976535d605249f41b8 /src/hs_throw_error.c
parent9899cea5784437667128e6335e4359dd47bc5d63 (diff)
begin refactoring tests to reflect struct-based API and implement hs_pushstring()
Diffstat (limited to 'src/hs_throw_error.c')
-rw-r--r--src/hs_throw_error.c21
1 files changed, 5 insertions, 16 deletions
diff --git a/src/hs_throw_error.c b/src/hs_throw_error.c
index b2377dd..20a4c6d 100644
--- a/src/hs_throw_error.c
+++ b/src/hs_throw_error.c
@@ -4,20 +4,9 @@
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);
+ va_list args;
+ va_start(args, format_string);
+ hs_vpushstring(L, format_string, args);
+ va_end(args);
+ lua_error(L);
}