Page 2 of 2

Re: NSLog problem with PB6

Posted: Mon Oct 31, 2022 12:40 pm
by mrbungle
I can test it though which log would I be looking at?

Re: NSLog problem with PB6

Posted: Mon Oct 31, 2022 12:49 pm
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.

Re: NSLog problem with PB6

Posted: Mon Oct 31, 2022 1:06 pm
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)

Re: NSLog problem with PB6

Posted: Mon Oct 31, 2022 1:23 pm
by deseven
Thanks! Then this should be a bug in arm compiler, I'll create a bug report later.

Re: NSLog problem with PB6

Posted: Mon Oct 31, 2022 1:39 pm
by mrbungle
No problem!

Re: NSLog problem with PB6

Posted: Mon Oct 31, 2022 3:49 pm
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)


Re: NSLog problem with PB6

Posted: Mon Oct 31, 2022 3:53 pm
by deseven
mk-soft wrote: Mon Oct 31, 2022 3:49 pm Try the delay ...
No luck with that either (with ARM application).

Re: NSLog problem with PB6

Posted: Mon Oct 31, 2022 4:48 pm
by mrbungle
Same issue: Output: (null) even with the delay on an ARM CPU

Re: NSLog problem with PB6

Posted: Mon Oct 31, 2022 6:30 pm
by mrbungle
Not sure if it matters but by default I set the PB6 compiler to optimize code.

Re: NSLog problem with PB6

Posted: Mon Oct 31, 2022 8:12 pm
by deseven
Nope, I have "Optimize generated code" unchecked and it doesn't work anyway.
I created a bug here.