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
f64 s8_deserial_f64(s8_t 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
f64 s8_deserial_f64(s8_t string) { return strtod(string.str, NULL); }
#endif
void core_log_message(char *string) {
IF_PLATFORM_WINDOWS(if (IsDebuggerPresent()) OutputDebugStringA(string));
printf("%s", string);
fflush(stdout);
SWITCH_PLATFORM_WINDOWS_WASM_ELSE(
if (IsDebuggerPresent()) OutputDebugStringA(string),
write_to_console(string),
printf("%s", string); fflush(stdout)
);
}
void core_panic(void) {
if (core_desc.on_exit) core_desc.on_exit();
IF_PLATFORM_WINDOWS(ExitProcess(1));
IF_NOT_PLATFORM_WINDOWS(exit(1));
SWITCH_PLATFORM_WINDOWS_WASM_ELSE(
ExitProcess(1),
debug_break(),
exit(1)
);
}
#endif
void core_on_exit(void) {
debugf("program panicked! exiting...");

View File

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