Assert.go 874 B

123456789101112131415161718192021222324252627282930313233
  1. package imgui
  2. import "C"
  3. import (
  4. "errors"
  5. "fmt"
  6. )
  7. // AssertHandler is a handler for an assertion that happened in the native part of ImGui.
  8. type AssertHandler func(expression string, file string, line int)
  9. var assertHandler AssertHandler = func(expression string, file string, line int) {
  10. message := fmt.Sprintf(`Assertion failed!
  11. File: %s, Line %d
  12. Expression: %s
  13. `, file, line, expression)
  14. panic(errors.New(message))
  15. }
  16. // SetAssertHandler registers a handler function for all future assertions.
  17. // Setting nil will disable special handling.
  18. // The default handler panics.
  19. func SetAssertHandler(handler AssertHandler) {
  20. assertHandler = handler
  21. }
  22. //export iggAssert
  23. func iggAssert(result C.int, expression *C.char, file *C.char, line C.int) {
  24. if (result == 0) && (assertHandler != nil) {
  25. assertHandler(C.GoString(expression), C.GoString(file), int(line))
  26. }
  27. }