SWITCH_PLATFORM_WINDOWS_WASM_ELSE

This commit is contained in:
krzosa
2024-12-29 11:12:23 +01:00
parent 061c59c865
commit 6cfd5bd784
2 changed files with 18 additions and 25 deletions

View File

@@ -79,28 +79,26 @@ b32 vmem_decommit(void *p, usize size) { return true; }
#if PLATFORM_WASM #if PLATFORM_WASM
f64 s8_deserial_f64(s8_t string); f64 s8_deserial_f64(s8_t string);
void write_to_console(char *string); void write_to_console(char *string);
void core_log_message(char *string) {
write_to_console(string);
}
void core_panic(void) {
if (core_desc.on_exit) core_desc.on_exit();
debug_break();
}
#else #else
f64 s8_deserial_f64(s8_t string) { return strtod(string.str, NULL); } f64 s8_deserial_f64(s8_t string) { return strtod(string.str, NULL); }
#endif
void core_log_message(char *string) { void core_log_message(char *string) {
IF_PLATFORM_WINDOWS(if (IsDebuggerPresent()) OutputDebugStringA(string)); SWITCH_PLATFORM_WINDOWS_WASM_ELSE(
printf("%s", string); if (IsDebuggerPresent()) OutputDebugStringA(string),
fflush(stdout); write_to_console(string),
printf("%s", string); fflush(stdout)
);
} }
void core_panic(void) { void core_panic(void) {
if (core_desc.on_exit) core_desc.on_exit(); if (core_desc.on_exit) core_desc.on_exit();
IF_PLATFORM_WINDOWS(ExitProcess(1)); SWITCH_PLATFORM_WINDOWS_WASM_ELSE(
IF_NOT_PLATFORM_WINDOWS(exit(1)); ExitProcess(1),
debug_break(),
exit(1)
);
} }
#endif
void core_on_exit(void) { void core_on_exit(void) {
debugf("program panicked! exiting..."); debugf("program panicked! exiting...");

View File

@@ -69,17 +69,12 @@
#endif #endif
#if PLATFORM_WINDOWS #if PLATFORM_WINDOWS
#define IF_PLATFORM_WINDOWS(x) x #define SWITCH_PLATFORM_WINDOWS_WASM_ELSE(WINDOWS, WASM, ELSE) WINDOWS
#define IF_NOT_PLATFORM_WINDOWS(x) #elif PLATFORM_WASM
#define SWITCH_PLATFORM_WINDOWS_WASM_ELSE(WINDOWS, WASM, ELSE) WASM
#else #else
#define IF_PLATFORM_WINDOWS(x) #define SWITCH_PLATFORM_WINDOWS_WASM_ELSE(WINDOWS, WASM, ELSE) ELSE
#define IF_NOT_PLATFORM_WINDOWS(x) x
#endif #endif
#if PLATFORM_WASM #define IF_PLATFORM_WINDOWS(x) SWITCH_PLATFORM_WINDOWS_WASM_ELSE(x, ((void)0), ((void)0))
#define IF_PLATFORM_WASM(x) x #define IF_PLATFORM_NOT_WINDOWS(x) SWITCH_PLATFORM_WINDOWS_WASM_ELSE(((void)0), x, x)
#define IF_NOT_PLATFORM_WASM(x)
#else
#define IF_PLATFORM_WASM(x)
#define IF_NOT_PLATFORM_WASM(x) x
#endif