Tweaked output callbacks to match 'puts' signature

This commit is contained in:
2026-05-08 11:12:27 +10:00
parent 185f3896c5
commit be84a8dfe2
5 changed files with 24 additions and 37 deletions
+6 -18
View File
@@ -2,21 +2,9 @@
#include <stdio.h>
static void outDefault(const char* msg) {
fprintf(stdout, "%s\n", msg);
}
static void errDefault(const char* msg) {
fprintf(stderr, "%s\n", msg);
}
static void assertDefault(const char* msg) {
fprintf(stderr, "%s\n", msg);
}
static Toy_callbackType printCallback = outDefault;
static Toy_callbackType errorCallback = errDefault;
static Toy_callbackType assertCallback = assertDefault;
static Toy_callbackType printCallback = puts;
static Toy_callbackType errorCallback = puts;
static Toy_callbackType assertCallback = puts;
void Toy_print(const char* msg) {
printCallback(msg);
@@ -43,13 +31,13 @@ void Toy_setAssertFailureCallback(Toy_callbackType cb) {
}
void Toy_resetPrintCallback(void) {
printCallback = outDefault;
printCallback = puts;
}
void Toy_resetErrorCallback(void) {
errorCallback = errDefault;
errorCallback = puts;
}
void Toy_resetAssertFailureCallback(void) {
assertCallback = assertDefault;
assertCallback = puts;
}
+2 -2
View File
@@ -2,8 +2,8 @@
#include "toy_common.h"
//handle callbacks for printing to the terminal, or elsewhere
typedef void (*Toy_callbackType)(const char*);
//handle callbacks for printing to the terminal, or elsewhere (signature matches 'puts')
typedef int (*Toy_callbackType)(const char*);
TOY_API void Toy_print(const char* msg); //print keyword
TOY_API void Toy_error(const char* msg); //runtime errors