summaryrefslogtreecommitdiff
path: root/asl/base
diff options
context:
space:
mode:
Diffstat (limited to 'asl/base')
-rw-r--r--asl/base/assert.cpp18
-rw-r--r--asl/base/assert.hpp6
2 files changed, 18 insertions, 6 deletions
diff --git a/asl/base/assert.cpp b/asl/base/assert.cpp
index 2383e9e..c3e0c69 100644
--- a/asl/base/assert.cpp
+++ b/asl/base/assert.cpp
@@ -1,12 +1,18 @@
#include "asl/base/assert.hpp"
-// #include "asl/io/print.hpp"
+static asl::AssertFailureHandler* s_handler = nullptr;
+static void* s_user = nullptr;
+
+void asl::set_assert_failure_handler(AssertFailureHandler handler, void* user)
+{
+ s_handler = handler;
+ s_user = user;
+}
void asl::report_assert_failure(const char* msg, const source_location& sl)
{
- // @Todo(org)
- // eprint("------------------------------------------------------------\n");
- // eprint("Assertion failure at {}, line {}:\n", sl.file, sl.line);
- // eprint("{}\n", msg);
- // eprint("------------------------------------------------------------\n");
+ if (s_handler != nullptr)
+ {
+ s_handler(msg, sl, s_user);
+ }
}
diff --git a/asl/base/assert.hpp b/asl/base/assert.hpp
index 42e8635..d23e897 100644
--- a/asl/base/assert.hpp
+++ b/asl/base/assert.hpp
@@ -6,6 +6,10 @@
namespace asl
{
+using AssertFailureHandler = void (const char* msg, const source_location&, void* user);
+
+void set_assert_failure_handler(AssertFailureHandler handler, void* user);
+
void report_assert_failure(const char* msg, const source_location& sl = source_location{});
} // namespace asl
@@ -16,6 +20,8 @@ void report_assert_failure(const char* msg, const source_location& sl = source_l
#define ASL_DEBUG_BREAK() __builtin_debugtrap()
#endif
+// @Todo Configure asserts at build time
+
#define ASL_ASSERT(...) \
if (__VA_ARGS__) {} \
else \