mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
android: provide more predictable logging, add comptime termux support (#14984)
This commit is contained in:
30
thirdparty/android/android.h
vendored
Normal file
30
thirdparty/android/android.h
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
#if defined(__ANDROID__)
|
||||
#include <android/log.h>
|
||||
|
||||
// Adapted from https://stackoverflow.com/a/196018/1904615
|
||||
#define V_ANDROID_LOG_STR_VALUE(arg) #arg
|
||||
#define V_ANDROID_LOG_NAME(tag_name) V_ANDROID_LOG_STR_VALUE(tag_name)
|
||||
|
||||
#ifndef V_ANDROID_LOG_TAG
|
||||
#if defined(APPNAME)
|
||||
#define V_ANDROID_LOG_TAG APPNAME
|
||||
#else
|
||||
#define V_ANDROID_LOG_TAG "V"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define V_ANDROID_LOG_TAG_NAME V_ANDROID_LOG_NAME(V_ANDROID_LOG_TAG)
|
||||
|
||||
int android_print(FILE *stream, const char *format, ...) {
|
||||
// int __android_log_vprint(int prio, const char *tag, const char *fmt, va_list ap)
|
||||
int res;
|
||||
va_list argptr;
|
||||
va_start(argptr, format);
|
||||
if (stream == stdout) {
|
||||
res = __android_log_vprint(ANDROID_LOG_INFO, V_ANDROID_LOG_TAG_NAME, format, argptr);
|
||||
} else {
|
||||
res = __android_log_vprint(ANDROID_LOG_ERROR, V_ANDROID_LOG_TAG_NAME, format, argptr);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
#endif
|
21
thirdparty/sokol/sokol_v.pre.h
vendored
21
thirdparty/sokol/sokol_v.pre.h
vendored
@ -1,21 +0,0 @@
|
||||
#if defined(V_ANDROID_LOG_PRINT)
|
||||
#if defined(__ANDROID__)
|
||||
// Adapted from https://stackoverflow.com/a/196018/1904615
|
||||
#define V_ANDROID_LOG_STR_VALUE(arg) #arg
|
||||
#define V_ANDROID_LOG_NAME(tag_name) V_ANDROID_LOG_STR_VALUE(tag_name)
|
||||
|
||||
#ifndef V_ANDROID_LOG_TAG
|
||||
#if defined(APPNAME)
|
||||
#define V_ANDROID_LOG_TAG APPNAME
|
||||
#else
|
||||
#define V_ANDROID_LOG_TAG "V_ANDROID"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define V_ANDROID_LOG_TAG_NAME V_ANDROID_LOG_NAME(V_ANDROID_LOG_TAG)
|
||||
|
||||
#include <android/log.h>
|
||||
#define printf(...) __android_log_print(ANDROID_LOG_INFO, V_ANDROID_LOG_TAG_NAME, __VA_ARGS__)
|
||||
#define fprintf(a, ...) __android_log_print(ANDROID_LOG_ERROR, V_ANDROID_LOG_TAG_NAME, __VA_ARGS__)
|
||||
#endif
|
||||
#endif
|
Reference in New Issue
Block a user