Feature request: instrisic Defines for console / gui mode

General discussion for topics related to the FreeBASIC project or its community.
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Feature request: instrisic Defines for console / gui mode

Post by Josep Roca »

If the suggestion is implemented, additional features can be added like flagging as an error the use of SLEEP without parameters in an application compiled as a Windows GUI.
fxm
Moderator
Posts: 12082
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Feature request: instrisic Defines for console / gui mode

Post by fxm »

Josep Roca wrote:If the suggestion is implemented, additional features can be added like flagging as an error the use of SLEEP without parameters in an application compiled as a Windows GUI
and without any graphics windows defined by Screen[Res]().
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Feature request: instrisic Defines for console / gui mode

Post by jj2007 »

marpon wrote:i apologize if my formulation did hurt you, my intention was not to "insult" any people.
OK, no harm done.
paul doe wrote:
jj2007 wrote:Why do simple questions so often trigger subtle insults here?
I fail to see where the insult is (again). However, I do see that you're unable to grasp the difference between an intrinsic define and a #define provided by the application.
I am perfectly able to grasp that difference. I just don't believe that an intrinsic define console vs Gui provides a great added value. IMHO an application-defined switch is clearer, simple because it's explicit.
Intrinsic defines are a way for the compiler to expose internal state to the application being compiled, so that the app can branch differently depending on that state (to allow compiling to different platforms, say). A #define is something that the application defines; the preprocessor just replaces the definition with the appropriate text wherever the definition is referenced.
Right, I do that all the time.
So, allowing for redefinition of an intrinsic (what you propose) makes the definition very non-intrinsic, and thus, pointless.
Where did I propose that?
marpon
Posts: 342
Joined: Dec 28, 2012 13:31
Location: Paris - France

Re: Feature request: instrisic Defines for console / gui mode

Post by marpon »

fxm wrote:
Josep Roca wrote:If the suggestion is implemented, additional features can be added like flagging as an error the use of SLEEP without parameters in an application compiled as a Windows GUI
and without any graphics windows defined by Screen[Res]().
sleep interception not so easy

but work-arround is possible in code
for graphics windows defined by Screen[Res]()
If ScreenPtr = 0 Then ... can check it

for Windows GUI using the __FB_GUI__ do the job
fxm
Moderator
Posts: 12082
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Feature request: instrisic Defines for console / gui mode

Post by fxm »

marpon wrote:but work-arround is possible in code
for graphics windows defined by Screen[Res]()
If ScreenPtr = 0 Then ... can check it
Yes, of course, but it's a test at run-time while the test on "__FB_GUI__" will already be available at compile time.
marpon
Posts: 342
Joined: Dec 28, 2012 13:31
Location: Paris - France

Re: Feature request: instrisic Defines for console / gui mode

Post by marpon »

fxm wrote:
marpon wrote:but work-arround is possible in code
for graphics windows defined by Screen[Res]()
If ScreenPtr = 0 Then ... can check it
Yes, of course, but it's a test at run-time while the test on "__FB_GUI__" will already be available at compile time.
that's why i've said it's not easy (inside compiler)
i think we could use fb_GfxScreenPtr on the fb_sleep fonction

on the user code quite simple...
Last edited by marpon on Sep 13, 2018 19:09, edited 1 time in total.
fxm
Moderator
Posts: 12082
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Feature request: instrisic Defines for console / gui mode

Post by fxm »

Under Windows, we can test at run time the presence of :
- a graphics window with "ScreenPtr",
- a console window with "GetConsoleWindow()".
marpon
Posts: 342
Joined: Dec 28, 2012 13:31
Location: Paris - France

Re: Feature request: instrisic Defines for console / gui mode

Post by marpon »

sure
but it does not be what José is requesting , an error from the compiler on that wrong situation

for that we need to act at fb_sleep interception
i think we could use internally fb_GfxScreenPtr that is the source of ScreenPtr
and could have a function to get env.clopt.modeview (my added new var)

i will check this week end (if nobody has a solution of course)

it"s too late for me now.
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Feature request: instrisic Defines for console / gui mode

Post by coderJeff »

Not sure where this topic is going on SLEEP or what all the ultimate needs are, but for the "__FB_GUI__" addition, it will tell the programmer, at compile time, if '-s gui' was passed on the command line, that's it. What programmers use it for, I leave up to them.
marpon wrote:sleep interception not so easy
Yea, SLEEP is a bit of an oddball, both a sub and a function, something not allowed in normal user code, but the compiler does it anyway.
Hacking on SLEEP:

Code: Select all

'' hack, undefine both versions of SLEEP, one is a function, other is a sub
#undef sleep
#undef sleep

'' declare the rtlib functions
declare sub fb_Sleep alias "fb_Sleep" ( byval amount as long = -1 )
declare function fb_SleepEx alias "fb_SleepEx" ( byval amount as long, byval keyflag as long ) as long

'' SLEEP interceptors
function Sleep overload ( byval amount as long = -1 ) as long
	print "  - SLEEP(1) intercepted!"
	fb_Sleep( amount ) '' call original sleep command
	return 0
end function  

function Sleep overload ( byval amount as long, byval keyflag as long ) as long
	print "  - SLEEP(2) intercepted!"
	return fb_SleepEx( amount, keyflag ) '' call original sleep command
end function  

'' DEMO
print "Wait for keypress";
sleep

print "Wait for keypress, or 5 sec";
sleep 5000

print "Wait for keypress, or 5 sec";
sleep 5000, 0

print "Wait 5 sec";
sleep 5000, 1
marpon, you can do whatever you want with your pull request while it exists as a pull request, including completely rewriting what is in the commits. It takes some practice to find out what you can do with git. In this case I would do a 'soft reset' to an early version and re-commit the changes. When you push (again) to the pull request, you will need to --force it.
St_W wrote:You may also consider changing the "subsystem" member in FBCCTX type (in fbc.bas) to use your enum type instead of a string. The implementation of the "-gen" option may act as an implementation help for that too.
marpon, as St_W points out, ENUM's are a good practice for this sort of thing, but I don't think there should be both fbc.subsystem and "modeview" options, tracking the same info. They can be combined.

Good stuff, keep at it. :)
speedfixer
Posts: 606
Joined: Nov 28, 2012 1:27
Location: CA, USA moving to WA, USA
Contact:

Re: Feature request: instrisic Defines for console / gui mode

Post by speedfixer »

I program in Linux only, but ...

I simply ask SCREENINFO about the driver.

If it is an empty string, I am in console.
(Some of the other info also confirns NOT graphics, but this is the easiest.)

Does that work in Windows, also?


David
fxm
Moderator
Posts: 12082
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Feature request: instrisic Defines for console / gui mode

Post by fxm »

Yes but the '(ScreenPtr = 0)' test must also work in Linux.
marpon
Posts: 342
Joined: Dec 28, 2012 13:31
Location: Paris - France

Re: Feature request: instrisic Defines for console / gui mode

Post by marpon »

@coderJeff

thank"s for my quick request implementation, now we have __FB_GUI__ on the rolling v1.06.0
fxm
Moderator
Posts: 12082
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Feature request: instrisic Defines for console / gui mode

Post by fxm »

@coderJeff,

I propose that I take into account the corresponding update of the documentation, if it is okay?
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Feature request: instrisic Defines for console / gui mode

Post by coderJeff »

@marpon, you are welcome. I learned some new things too. In future I will try to give better guidance/instruction. The quality of pull request could be improved. But we all have to start somewhere.

@St_W, yea, having a merge from marpon:master to fbc:master was a little different than what I usually see. After merging, the source reference just disappeared, gone; that was unexpected. I think having a separate branch for the pull request would work a little cleaner.

@fxm, yes, thank-you. Please do.
fxm
Moderator
Posts: 12082
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Feature request: instrisic Defines for console / gui mode

Post by fxm »

Done:
- KeyPgDdfbgui → fxm [Added new page]
- CatPgDddefines → fxm [Updated after '__FB_GUI__' page creation]
- CatPgFunctIndex → fxm [Updated after '__FB_GUI__' page creation]
- CatPgFullIndex → fxm [Updated after '__FB_GUI__' page creation]
- CompilerOpts → fxm [Updated after '__FB_GUI__' page creation]
Post Reply