adding SetTraceLogCallback
This commit is contained in:
parent
7bdb60d758
commit
ca72d271e1
4 changed files with 101 additions and 0 deletions
18
raylib/utils_log.c
Normal file
18
raylib/utils_log.c
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include "raylib.h"
|
||||
#include "utils_log.h"
|
||||
#include <stdio.h> // Required for: vprintf()
|
||||
#include <string.h> // Required for: strcpy(), strcat()
|
||||
|
||||
#define MAX_TRACELOG_BUFFER_SIZE 128 // As defined in utils.c from raylib
|
||||
|
||||
void rayLogWrapperCallback(int logType, const char *text, va_list args) {
|
||||
char buffer[MAX_TRACELOG_BUFFER_SIZE] = { 0 };
|
||||
|
||||
vsprintf(buffer, text, args);
|
||||
|
||||
internalTraceLogCallbackGo(logType, buffer, strlen(buffer));
|
||||
}
|
||||
|
||||
void setLogCallbackWrapper(void) {
|
||||
SetTraceLogCallback(rayLogWrapperCallback);
|
||||
}
|
26
raylib/utils_log.go
Normal file
26
raylib/utils_log.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
package rl
|
||||
|
||||
/*
|
||||
#include "utils_log.h"
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import "unsafe"
|
||||
|
||||
// TraceLogCallbackFun - function that will recive the trace log messages
|
||||
type TraceLogCallbackFun func(int, string)
|
||||
|
||||
var internalTraceLogCallbackFun TraceLogCallbackFun = func(int, string) {}
|
||||
|
||||
// SetTraceLogCallback - set a call-back function for trace log
|
||||
func SetTraceLogCallback(fn TraceLogCallbackFun) {
|
||||
internalTraceLogCallbackFun = fn
|
||||
C.setLogCallbackWrapper()
|
||||
}
|
||||
|
||||
//export internalTraceLogCallbackGo
|
||||
func internalTraceLogCallbackGo(logType C.int, cstr unsafe.Pointer, len C.int) {
|
||||
str := string(C.GoBytes(cstr, len))
|
||||
lt := int(logType)
|
||||
internalTraceLogCallbackFun(lt, str)
|
||||
}
|
11
raylib/utils_log.h
Normal file
11
raylib/utils_log.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#if defined(__cplusplus)
|
||||
extern "C" { // Prevents name mangling of functions
|
||||
#endif
|
||||
|
||||
|
||||
void setLogCallbackWrapper(void); // enable the call-back
|
||||
void internalTraceLogCallbackGo(int, void*, int); // Go function that will get called
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue