Print to Console (log)
Posted: Thu Nov 07, 2019 2:18 pm
Any way to print to the macOS console output? (not terminal), Apple System Log?
NSLog
Thanks..
NSLog
Thanks..
http://www.purebasic.com
https://www.purebasic.fr/english/
I think using NSLog will be the easiest way.Rinzwind wrote:NSLog
I think the easiest way is just to log a normal PureBasic string and format that yourself.Rinzwind wrote:How to call that from PB? NSString and variable arguments.
Code: Select all
ImportC ""
NSLog2(Format, Arg) As "_NSLog"
EndImport
Procedure NSLog(Message.s)
Static Format.i
If Format = 0
CompilerIf #PB_Compiler_Unicode
Format = CocoaMessage(0, 0, "NSString stringWithString:$", @"%S")
CompilerElse
Format = CocoaMessage(0, 0, "NSString stringWithString:$", @"%s")
CompilerEndIf
CocoaMessage(0, Format, "retain")
EndIf
NSLog2(Format, @Message)
EndProcedure
NSLog("NSLog testing")
Code: Select all
; >> PB x64 unicode <<
; External constants
!extern ___CFConstantStringClassReference
; Imports
ImportC ""
NSLog2(Format, Arg) As "_NSLog"
EndImport
; Define CFString constant
DataSection
!CFSTRData_Format:
!db '%S',0
!align 4
CFSTR_Format:
!dq ___CFConstantStringClassReference, 0x7c8
!dq CFSTRData_Format, 2; Asciiz pointer and size
EndDataSection
Procedure NSLog(Message.s)
NSLog2(?CFSTR_Format, @Message)
EndProcedure
NSLog("NSLog testing")