[rcore] Add non-va_list custom logging callback #5318
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a version of
TraceLogCallback, calledTraceLogCallback2(pending a better name), which is like the original but instead of receiving a format string and ava_listof arguments, receives a pre-formatted string of the arguments only.Why?
The default logger logs to standard output, but can be redirected using
SetTraceLogCallback(). This works for users of Raylib interfacing using C, but cannot be used with some other programming languages' bindings (e.g. Racket) because the foreign function interface (FFI) used to call Raylib does not supportva_list. This is unfortunate, because redirecting Raylib logging to the language's own logging facilities seems like an excellent use-case forTraceLogCallback, but one for which it cannot be used.This PR solves the problem by formatting the log message ahead of time, before it is passed to the callback, where it is then much easier for non-C languages to use. I considered other designs, such as using a
unionto pass out all the arguments in an FFI-compatible way, but this seems the simplest.What is this PR?
I am mainly just throwing this PR out here as a possible implementation to fix the issue, but I'm not sure if I will have the time to see it through.