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:
@@ -159,8 +159,8 @@ pub fn eprintln(s string) {
|
||||
C.fflush(C.stdout)
|
||||
C.fflush(C.stderr)
|
||||
// eprintln is used in panics, so it should not fail at all
|
||||
$if android {
|
||||
C.fprintf(C.stderr, c'%.*s\n', s.len, s.str)
|
||||
$if android && !termux {
|
||||
C.android_print(C.stderr, c'%.*s\n', s.len, s.str)
|
||||
}
|
||||
_writeln_to_fd(2, s)
|
||||
C.fflush(C.stderr)
|
||||
@@ -182,8 +182,8 @@ pub fn eprint(s string) {
|
||||
} $else {
|
||||
C.fflush(C.stdout)
|
||||
C.fflush(C.stderr)
|
||||
$if android {
|
||||
C.fprintf(C.stderr, c'%.*s', s.len, s.str)
|
||||
$if android && !termux {
|
||||
C.android_print(C.stderr, c'%.*s', s.len, s.str)
|
||||
}
|
||||
_write_buf_to_fd(2, s.str, s.len)
|
||||
C.fflush(C.stderr)
|
||||
@@ -211,11 +211,9 @@ pub fn flush_stderr() {
|
||||
// print prints a message to stdout. Unlike `println` stdout is not automatically flushed.
|
||||
[manualfree]
|
||||
pub fn print(s string) {
|
||||
$if android {
|
||||
C.fprintf(C.stdout, c'%.*s', s.len, s.str) // logcat
|
||||
}
|
||||
// no else if for android termux support
|
||||
$if ios {
|
||||
$if android && !termux {
|
||||
C.android_print(C.stdout, c'%.*s\n', s.len, s.str)
|
||||
} $else $if ios {
|
||||
// TODO: Implement a buffer as NSLog doesn't have a "print"
|
||||
C.WrappedNSLog(s.str)
|
||||
} $else $if freestanding {
|
||||
@@ -232,12 +230,10 @@ pub fn println(s string) {
|
||||
println('println(NIL)')
|
||||
return
|
||||
}
|
||||
$if android {
|
||||
C.fprintf(C.stdout, c'%.*s\n', s.len, s.str) // logcat
|
||||
$if android && !termux {
|
||||
C.android_print(C.stdout, c'%.*s\n', s.len, s.str)
|
||||
return
|
||||
}
|
||||
// no else if for android termux support
|
||||
$if ios {
|
||||
} $else $if ios {
|
||||
C.WrappedNSLog(s.str)
|
||||
return
|
||||
} $else $if freestanding {
|
||||
|
3
vlib/builtin/builtin_android_outside_termux.c.v
Normal file
3
vlib/builtin/builtin_android_outside_termux.c.v
Normal file
@@ -0,0 +1,3 @@
|
||||
module builtin
|
||||
|
||||
#include "@VEXEROOT/thirdparty/android/android.h"
|
@@ -487,5 +487,8 @@ fn C.glTexImage2D()
|
||||
// used by ios for println
|
||||
fn C.WrappedNSLog(str &u8)
|
||||
|
||||
// used by Android for (e)println to output to the Android log system / logcat
|
||||
pub fn C.android_print(voidptr, &char, ...voidptr)
|
||||
|
||||
// absolute value
|
||||
fn C.abs(number int) int
|
||||
|
Reference in New Issue
Block a user