1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-24 23:40:27 +00:00

Fix function handlers for :out and :err.

They were not properly handled for formatting functions.
This commit is contained in:
Calvin Rose 2022-07-02 21:11:05 -05:00
parent 221d71d07b
commit 8d0e6ed32f

View File

@ -545,6 +545,16 @@ static Janet cfun_io_printf_impl_x(int32_t argc, Janet *argv, int newline,
if (newline) janet_buffer_push_u8(buf, '\n'); if (newline) janet_buffer_push_u8(buf, '\n');
return janet_wrap_nil(); return janet_wrap_nil();
} }
case JANET_FUNCTION: {
/* Special case function */
JanetFunction *fun = janet_unwrap_function(x);
JanetBuffer *buf = janet_buffer(0);
janet_buffer_format(buf, fmt, offset, argc, argv);
if (newline) janet_buffer_push_u8(buf, '\n');
Janet args[1] = { janet_wrap_buffer(buf) };
janet_call(fun, 1, args);
return janet_wrap_nil();
}
case JANET_NIL: case JANET_NIL:
f = dflt_file; f = dflt_file;
if (f == NULL) janet_panic("cannot print to nil"); if (f == NULL) janet_panic("cannot print to nil");
@ -684,6 +694,16 @@ void janet_dynprintf(const char *name, FILE *dflt_file, const char *format, ...)
janet_buffer_deinit(&buffer); janet_buffer_deinit(&buffer);
break; break;
} }
case JANET_FUNCTION: {
JanetFunction *fun = janet_unwrap_function(x);
int32_t len = 0;
while (format[len]) len++;
JanetBuffer *buf = janet_buffer(len);
janet_formatbv(buf, format, args);
Janet args[1] = { janet_wrap_buffer(buf) };
janet_call(fun, 1, args);
break;
}
case JANET_BUFFER: case JANET_BUFFER:
janet_formatbv(janet_unwrap_buffer(x), format, args); janet_formatbv(janet_unwrap_buffer(x), format, args);
break; break;