mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
builtin: use NSLog on iOS for print (#9665)
This commit is contained in:
parent
64391efa4d
commit
38c517c1a2
8
thirdparty/ios/ios.m
vendored
Normal file
8
thirdparty/ios/ios.m
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
void WrappedNSLog(const char *message,...) {
|
||||
va_list args;
|
||||
va_start(args, message);
|
||||
NSLog(@"%@",[[NSString alloc] initWithFormat:[NSString stringWithUTF8String:message] arguments:args]);
|
||||
va_end(args);
|
||||
}
|
@ -89,6 +89,12 @@ pub fn eprintln(s string) {
|
||||
} else {
|
||||
C.fprintf(C.stderr, c'%.*s\n', s.len, s.str)
|
||||
}
|
||||
} $else $if ios {
|
||||
if s.str == 0 {
|
||||
C.WrappedNSLog(c'eprintln(NIL)\n')
|
||||
} else {
|
||||
C.WrappedNSLog(s.str)
|
||||
}
|
||||
} $else {
|
||||
if s.str == 0 {
|
||||
C.write(2, c'eprintln(NIL)\n', 14)
|
||||
@ -110,6 +116,13 @@ pub fn eprint(s string) {
|
||||
} else {
|
||||
C.fprintf(C.stderr, c'%.*s', s.len, s.str)
|
||||
}
|
||||
} $else $if ios {
|
||||
// TODO: Implement a buffer as NSLog doesn't have a "print"
|
||||
if s.str == 0 {
|
||||
C.WrappedNSLog(c'eprint(NIL)')
|
||||
} else {
|
||||
C.WrappedNSLog(s.str)
|
||||
}
|
||||
} $else {
|
||||
if s.str == 0 {
|
||||
C.write(2, c'eprint(NIL)', 11)
|
||||
@ -125,6 +138,9 @@ pub fn eprint(s string) {
|
||||
pub fn print(s string) {
|
||||
$if android {
|
||||
C.fprintf(C.stdout, c'%.*s', s.len, s.str)
|
||||
} $else $if ios {
|
||||
// TODO: Implement a buffer as NSLog doesn't have a "print"
|
||||
C.WrappedNSLog(s.str)
|
||||
} $else {
|
||||
C.write(1, s.str, s.len)
|
||||
}
|
||||
@ -142,6 +158,8 @@ pub fn println(s string) {
|
||||
if s.str == 0 {
|
||||
$if android {
|
||||
C.fprintf(C.stdout, c'println(NIL)\n')
|
||||
} $else $if ios {
|
||||
C.WrappedNSLog(c'println(NIL)')
|
||||
} $else {
|
||||
C.write(1, c'println(NIL)\n', 13)
|
||||
}
|
||||
@ -149,6 +167,8 @@ pub fn println(s string) {
|
||||
}
|
||||
$if android {
|
||||
C.fprintf(C.stdout, c'%.*s\n', s.len, s.str)
|
||||
} $else $if ios {
|
||||
C.WrappedNSLog(s.str)
|
||||
} $else {
|
||||
C.write(1, s.str, s.len)
|
||||
C.write(1, c'\n', 1)
|
||||
|
6
vlib/builtin/builtin_ios.c.v
Normal file
6
vlib/builtin/builtin_ios.c.v
Normal file
@ -0,0 +1,6 @@
|
||||
module builtin
|
||||
|
||||
// TODO: Remove this later, added to make sure v self works
|
||||
$if ios {
|
||||
#include "@VROOT/thirdparty/ios/ios.m"
|
||||
}
|
@ -451,3 +451,6 @@ fn C.dup2(oldfd int, newfd int) int
|
||||
|
||||
// used by gl, stbi, freetype
|
||||
fn C.glTexImage2D()
|
||||
|
||||
// used by ios for println
|
||||
fn C.WrappedNSLog(str &byte)
|
||||
|
@ -141,6 +141,9 @@ pub fn (prefs &Preferences) should_compile_c(file string) bool {
|
||||
if (file.ends_with('_macos.c.v') || file.ends_with('_macos.v')) && prefs.os != .macos {
|
||||
return false
|
||||
}
|
||||
if (file.ends_with('_ios.c.v') || file.ends_with('_ios.v')) && prefs.os != .ios {
|
||||
return false
|
||||
}
|
||||
if file.ends_with('_nix.c.v') && prefs.os == .windows {
|
||||
return false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user