CompilerWarning

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
kenmo
Addict
Addict
Posts: 2033
Joined: Tue Dec 23, 2003 3:54 am

CompilerWarning

Post by kenmo »

PureBasic already has CompilerError, which allows us to force an error if the person compiling should be alerted of something. It would be nice if we could force a CompilerWarning too, which would not prevent compilation, but it would still present an obvious warning to the user that something is wrong or important.

It would be similar to the warnings that appear when a resource fails to load:

Code: Select all

If LoadImage(0, "doesNotExist.bmp")
  Debug "A warning should appear in the IDE."
EndIf
Also, this is a very minor punctuation request, but I wish the period "." was not automatically added to our CompilerError strings, such as:

Code: Select all

CompilerError "Fatal Error!"
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: CompilerWarning

Post by Shield »

+1, good points.
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: CompilerWarning

Post by ts-soft »

WorkAround (crossplattform)

Code: Select all

CompilerIf #PB_Compiler_Debugger
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Windows
      Import ""
         PB_DEBUGGER_SendWarning(Message.p-ascii)
       EndImport
    CompilerDefault
      ImportC ""
         PB_DEBUGGER_SendWarning(Message.p-ascii)
       EndImport
   CompilerEndSelect
CompilerEndIf

Macro CompilerWarning(error)
  CompilerIf #PB_Compiler_Debugger
    PB_DEBUGGER_SendWarning(error)
  CompilerEndIf
EndMacro

CompilerWarning("A warning should appear in the IDE.")
   
Last edited by ts-soft on Wed Aug 01, 2012 11:05 am, edited 1 time in total.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
kenmo
Addict
Addict
Posts: 2033
Joined: Tue Dec 23, 2003 3:54 am

Re: CompilerWarning

Post by kenmo »

That's a useful tip, thank you.

I always see people posting these Import "" tips and I don't know how they know about them! Are they documented somewhere?
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: CompilerWarning

Post by ts-soft »

To import a function from a lib, that is imported, no name for the lib required.

Code: Select all

CompilerIf #PB_Compiler_Debugger
make sure, the lib is imported!
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: CompilerWarning

Post by wilbert »

ts-soft wrote:WorkAround (crossplattform)
It's not entirely cross platform.
For OS X you need to use ImportC .
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: CompilerWarning

Post by ts-soft »

wilbert wrote:It's not entirely cross platform.
For OS X you need to use ImportC .
Thx, changed :D
(i can't make any test on macos)
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: CompilerWarning

Post by wilbert »

ts-soft wrote:Thx, changed :D
It's working fine now on OS X :)
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: CompilerWarning

Post by Little John »

Done. :-)

I just found out that this has been added in PB 5.40 LTS (tested with the Windows versions).

Code: Select all

CompilerWarning "Hi there"
I can't see where it is documented, though.
User avatar
StarBootics
Addict
Addict
Posts: 1006
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: CompilerWarning

Post by StarBootics »

Little John wrote:Done. :-)

I just found out that this has been added in PB 5.40 LTS (tested with the Windows versions).
Also work on Linux (Ubuntu Gnome).
Just nice !

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: CompilerWarning

Post by freak »

Please note that what was implemented here is a compiler warning. This means the warning is triggered at compile-time and you have to use things like CompilerIf if you want to show it conditionally. What ts-soft posted is code to trigger a debugger warning. This warning is issued by the debugger at run-time, and it will only show if the statement is actually executed (so you can show it conditionally using a regular if). There seems to be some confusion between the two at times.

For completeness, i just added two functions DebuggerError(Message$) and DebuggerWarning(Message$) to trigger debugger errors (in essence what ts-soft showed as an official function). This will be in v5.50.
quidquid Latine dictum sit altum videtur
User avatar
NicTheQuick
Addict
Addict
Posts: 1504
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: CompilerWarning

Post by NicTheQuick »

Nice!
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
Post Reply