NSLog problem with PB6

Mac OSX specific forum
mrbungle
Enthusiast
Enthusiast
Posts: 143
Joined: Wed Dec 30, 2020 3:18 am

Re: NSLog problem with PB6

Post by mrbungle »

I can test it though which log would I be looking at?
User avatar
deseven
Enthusiast
Enthusiast
Posts: 367
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: NSLog problem with PB6

Post by deseven »

To see system logs, open Console app, press "Start" on top, input "PureBasic" in the search field, then pick any code example in this topic that works for other people (like the last one from mk-soft), then run it.
mrbungle
Enthusiast
Enthusiast
Posts: 143
Joined: Wed Dec 30, 2020 3:18 am

Re: NSLog problem with PB6

Post by mrbungle »

If I'm looking at the expected output, I see the following (M2 Macbook Air):

Output: (null)

I used the following code:

Code: Select all

 Macro CocoaString(NSString)
  PeekS(CocoaMessage(0, NSString, "UTF8String"), -1, #PB_UTF8)
EndMacro

Macro CocoaCString(NSString)
  PeekS(CocoaMessage(0, NSString, "cStringUsingEncoding:", #NSUTF16LittleEndianStringEncoding))
EndMacro

Macro CocoaAllocString(String)
  CocoaMessage(0, 0, "NSString stringWithBytes:", @String, "length:", StringByteLength(String), "encoding:", #NSUTF16LittleEndianStringEncoding)
EndMacro

ImportC ""
  NSLog(format, message)
EndImport

Define format = CocoaAllocString("Output: %S")
Define message.s = "Test: " + FormatDate("%HH:%II:%SS", Date())

NSLog(format, @message)
User avatar
deseven
Enthusiast
Enthusiast
Posts: 367
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: NSLog problem with PB6

Post by deseven »

Thanks! Then this should be a bug in arm compiler, I'll create a bug report later.
mrbungle
Enthusiast
Enthusiast
Posts: 143
Joined: Wed Dec 30, 2020 3:18 am

Re: NSLog problem with PB6

Post by mrbungle »

No problem!
User avatar
mk-soft
Always Here
Always Here
Posts: 6204
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: NSLog problem with PB6

Post by mk-soft »

Try the delay ...
If the programme ends too quickly, the log does not arrive.

For format string: https://developer.apple.com/library/arc ... fiers.html

Code: Select all

Macro CocoaString(NSString)
  PeekS(CocoaMessage(0, NSString, "UTF8String"), -1, #PB_UTF8)
EndMacro

Macro CocoaCString(NSString)
  PeekS(CocoaMessage(0, NSString, "cStringUsingEncoding:", #NSUTF16LittleEndianStringEncoding))
EndMacro

Macro CocoaAllocString(String)
  CocoaMessage(0, 0, "NSString stringWithBytes:", @String, "length:", StringByteLength(String), "encoding:", #NSUTF16LittleEndianStringEncoding)
EndMacro

ImportC ""
  NSLog(format, message)
EndImport

Define format = CocoaAllocString("Output: %S")
Define message.s = "Time: " + FormatDate("%HH:%II:%SS", Date())

NSLog(format, @message)

Delay(1000)

My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
deseven
Enthusiast
Enthusiast
Posts: 367
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: NSLog problem with PB6

Post by deseven »

mk-soft wrote: Mon Oct 31, 2022 3:49 pm Try the delay ...
No luck with that either (with ARM application).
mrbungle
Enthusiast
Enthusiast
Posts: 143
Joined: Wed Dec 30, 2020 3:18 am

Re: NSLog problem with PB6

Post by mrbungle »

Same issue: Output: (null) even with the delay on an ARM CPU
mrbungle
Enthusiast
Enthusiast
Posts: 143
Joined: Wed Dec 30, 2020 3:18 am

Re: NSLog problem with PB6

Post by mrbungle »

Not sure if it matters but by default I set the PB6 compiler to optimize code.
User avatar
deseven
Enthusiast
Enthusiast
Posts: 367
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: NSLog problem with PB6

Post by deseven »

Nope, I have "Optimize generated code" unchecked and it doesn't work anyway.
I created a bug here.
Post Reply