From 512f62b7a1f7d425f55559c7263fa16105855c59 Mon Sep 17 00:00:00 2001 From: Larpon Date: Sun, 17 Jan 2021 05:32:59 +0100 Subject: [PATCH] android: enable custom (e)println output via android log system (#8135) --- examples/2048/2048.v | 7 ------- thirdparty/sokol/sokol_v.h | 20 ++++++++++++++++++++ vlib/sokol/c/declaration.c.v | 2 ++ 3 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 thirdparty/sokol/sokol_v.h diff --git a/examples/2048/2048.v b/examples/2048/2048.v index 9f674e4aaf..094428be19 100644 --- a/examples/2048/2048.v +++ b/examples/2048/2048.v @@ -936,13 +936,6 @@ fn (mut app App) showfps() { } } -// TODO: Move this somewhere else (vlib?) once Android support is merged -$if android { - #include - #define LOG_TAG "v_logcat_test" - #define printf(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) - #define fprintf(a, ...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) -} fn main() { mut app := &App{} app.new_game() diff --git a/thirdparty/sokol/sokol_v.h b/thirdparty/sokol/sokol_v.h new file mode 100644 index 0000000000..cc08678928 --- /dev/null +++ b/thirdparty/sokol/sokol_v.h @@ -0,0 +1,20 @@ +#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 + #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 + diff --git a/vlib/sokol/c/declaration.c.v b/vlib/sokol/c/declaration.c.v index 73d00f5f5c..34777bc332 100644 --- a/vlib/sokol/c/declaration.c.v +++ b/vlib/sokol/c/declaration.c.v @@ -41,6 +41,8 @@ pub const ( #flag solaris -DSOKOL_NO_ENTRY // TODO end +#include "sokol_v.h" + #include "sokol_app.h" #define SOKOL_IMPL