forked from inkyblackness/imgui-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Assert.go
47 lines (39 loc) · 1.13 KB
/
Assert.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package imgui
import "C"
import (
"fmt"
)
// AssertHandler is a handler for an assertion that happened in the native part of ImGui.
type AssertHandler func(expression string, file string, line int)
// AssertionError is the standard error being thrown by the default handler.
type AssertionError struct {
Expression string
File string
Line int
}
// Error returns the string representation.
func (err AssertionError) Error() string {
return fmt.Sprintf(`Assertion failed!
File: %s, Line %d
Expression: %s
`, err.File, err.Line, err.Expression)
}
var assertHandler AssertHandler = func(expression string, file string, line int) {
panic(AssertionError{
Expression: expression,
File: file,
Line: line,
})
}
// SetAssertHandler registers a handler function for all future assertions.
// Setting nil will disable special handling.
// The default handler panics.
func SetAssertHandler(handler AssertHandler) {
assertHandler = handler
}
//export iggAssert
func iggAssert(expression *C.char, file *C.char, line C.int) {
if assertHandler != nil {
assertHandler(C.GoString(expression), C.GoString(file), int(line))
}
}