ios: redirect prints to NSLog (printf is no longer an output of the simulator)
authorAlexis Laferrière <alexis.laf@xymus.net>
Fri, 23 Sep 2016 01:09:38 +0000 (21:09 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Fri, 30 Sep 2016 14:19:16 +0000 (10:19 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/ios/ios.nit
src/compiler/abstract_compiler.nit

index 98cb714..59778b4 100644 (file)
@@ -17,3 +17,16 @@ module ios
 
 import platform
 import app
+
+import cocoa::foundation
+
+redef fun print(msg) do msg.to_s.nslog
+redef fun print_error(msg) do msg.to_s.nslog
+
+redef class Text
+       private fun nslog do to_nsstring.nslog
+end
+
+redef class NSString
+       private fun nslog in "ObjC" `{ NSLog(@"%@", self); `}
+end
index 105b1fb..f310fe2 100644 (file)
@@ -662,6 +662,8 @@ abstract class AbstractCompiler
                self.header.add_decl("#include <inttypes.h>\n")
                self.header.add_decl("#include \"gc_chooser.h\"")
                self.header.add_decl("#ifdef __APPLE__")
+               self.header.add_decl("  #include <TargetConditionals.h>")
+               self.header.add_decl("  #include <syslog.h>")
                self.header.add_decl("  #include <libkern/OSByteOrder.h>")
                self.header.add_decl("  #define be32toh(x) OSSwapBigToHostInt32(x)")
                self.header.add_decl("#endif")
@@ -678,6 +680,8 @@ abstract class AbstractCompiler
                self.header.add_decl("  #endif")
                self.header.add_decl("  #include <android/log.h>")
                self.header.add_decl("  #define PRINT_ERROR(...) (void)__android_log_print(ANDROID_LOG_WARN, \"Nit\", __VA_ARGS__)")
+               self.header.add_decl("#elif TARGET_OS_IPHONE")
+               self.header.add_decl("  #define PRINT_ERROR(...) syslog(LOG_ERR, __VA_ARGS__)")
                self.header.add_decl("#else")
                self.header.add_decl("  #define PRINT_ERROR(...) fprintf(stderr, __VA_ARGS__)")
                self.header.add_decl("#endif")