-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
65 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 goImguiAssertHandler | ||
func goImguiAssertHandler(expression *C.char, file *C.char, line C.int) { | ||
if assertHandler != nil { | ||
assertHandler(C.GoString(expression), C.GoString(file), int(line)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters