mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Allow for printf style assert and panic
This commit is contained in:
+10
-12
@@ -625,24 +625,22 @@ default_allocator :: proc() -> Allocator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
assert :: proc "contextless" (condition: bool, message := "", using loc := #caller_location) -> bool {
|
assert :: proc "contextless" (condition: bool, message := "", args: ...any, using loc := #caller_location) -> bool {
|
||||||
if !condition {
|
if !condition {
|
||||||
if len(message) > 0 {
|
fmt.fprintf(os.stderr, "%s(%d:%d) Runtime assertion", file_path, line, column);
|
||||||
fmt.fprintf(os.stderr, "%s(%d:%d) Runtime assertion: %s\n", file_path, line, column, message);
|
if len(message) > 0 do fmt.fprint(os.stderr, ": ");
|
||||||
} else {
|
fmt.fprintf(os.stderr, message, ...args);
|
||||||
fmt.fprintf(os.stderr, "%s(%d:%d) Runtime assertion\n", file_path, line, column);
|
fmt.fprintf(os.stderr, "\n");
|
||||||
}
|
|
||||||
__debug_trap();
|
__debug_trap();
|
||||||
}
|
}
|
||||||
return condition;
|
return condition;
|
||||||
}
|
}
|
||||||
|
|
||||||
panic :: proc "contextless" (message := "", using loc := #caller_location) {
|
panic :: proc "contextless" (message := "", args: ...any, using loc := #caller_location) {
|
||||||
if len(message) > 0 {
|
fmt.fprintf(os.stderr, "%s(%d:%d) Panic", file_path, line, column);
|
||||||
fmt.fprintf(os.stderr, "%s(%d:%d) Panic: %s\n", file_path, line, column, message);
|
if len(message) > 0 do fmt.fprint(os.stderr, ": ");
|
||||||
} else {
|
fmt.fprintf(os.stderr, message, ...args);
|
||||||
fmt.fprintf(os.stderr, "%s(%d:%d) Panic\n", file_path, line, column);
|
fmt.fprintf(os.stderr, "\n");
|
||||||
}
|
|
||||||
__debug_trap();
|
__debug_trap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user