Any way to print to the macOS console output? (not terminal), Apple System Log?
NSLog
Thanks..
Print to Console (log)
Re: Print to Console (log)
I think using NSLog will be the easiest way.Rinzwind wrote:NSLog
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
Re: Print to Console (log)
How to call that from PB? NSString and variable arguments.
Re: Print to Console (log)
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")
Here's also an example with a CFString constant in the DataSection.
It might be a bit more difficult but I'm posting it also as a reference for myself on how to create a CFString constant at compile time.
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")
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)