English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. Blitz Basic

 
 
Thread Tools
Old 22 October 2021, 00:04   #1
zooperdan
Registered User

 
Join Date: Sep 2021
Location: Norway
Posts: 13
Possible to detect if program is run in editor?

Hi

I wonder if there is any way to detect if the program is running in the editor or started from WB or CLI?

Cheers.
zooperdan is offline  
Old 22 October 2021, 08:50   #2
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 1,488
Huh? What do you mean "running in the editor"? What is "the editor", and how can an editor run a program?

AmigaOs "only" has two execution environments, the shell and the workbench.
Thomas Richter is offline  
Old 22 October 2021, 09:41   #3
aros-sg
Registered User

 
Join Date: Nov 2015
Location: Italy
Posts: 93
Guess: This is Blitz Basic Forum, so he means running/starting it from/in Blitz Basic editor, similiar to how you can run/start Amiga Basic programs from the editor or Pascal programs from Hispeed Pascal editor.
aros-sg is offline  
Old 22 October 2021, 09:49   #4
zooperdan
Registered User

 
Join Date: Sep 2021
Location: Norway
Posts: 13
Quote:
Originally Posted by Thomas Richter View Post
Huh? What do you mean "running in the editor"? What is "the editor", and how can an editor run a program?

AmigaOs "only" has two execution environments, the shell and the workbench.
Well, by editor I of course mean the Blitz Basic editor. The one you do the coding in and then compile and run.

I want to be able to detect in code whether the program was run from the editor or if it's a compiled program started from either WB or CLI. This way I can i.e show some debug info, allow certain keypresses/cheats etc. while developing.

The ideal would be a preprocessor directive which only includes and executes a code segment if it's compiled/ran from within the Blitz Basic editor. When you compile those segments are not included in the build. This is a common feature of most development environments.

Example

#IF EDITOR
; some code which is only compiled and executed while in the editor
#ENDIF

Last edited by zooperdan; 22 October 2021 at 09:58.
zooperdan is offline  
Old 22 October 2021, 11:14   #5
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 5,418
Blitz and its variants allow you to compile code directly from the IDE into RAM and run it there with various debugging and monitoring options. There's no executable file involved in this process, and effectively it's running "from the editor" instead of from Workbench or the shell. This is typically done to test a program during development, with compiling to an executable file done later once it's nearly ready.

To answer the OP, yes there is. It's a function called FromBlitz and will return true if run from the Blitz IDE and false otherwise. It's not a core Blitz function however, it's in the RIMiscLib command library. This is included with most distributions of Blitz however, so chances are you already have it installed. If Blitz doesn't recognise the keyword FromBlitz, have a look at updating the installation to a more complete version.

Edit: I can't think of any way to do automatic conditional compiling based on whether it has been run from the editor or not. You could manually control it using a constant:

Code:
#debug = True

CNIF #debug
  NPrint "This is a debug build"
CEND
and then change the #debug to False when you build your final executable. AmiBlitz 3 has a compile-time constant #__debug (two underscores), which tells you if the debugger is running, though you can still run the code from the editor with the debugger turned off, in which case the compiler will also skip your debug code. That constant isn't available in Blitz 2 however...

Last edited by Daedalus; 22 October 2021 at 11:27.
Daedalus is offline  
Old 22 October 2021, 11:30   #6
zooperdan
Registered User

 
Join Date: Sep 2021
Location: Norway
Posts: 13
Quote:
Originally Posted by Daedalus View Post
Blitz and its variants allow you to compile code directly from the IDE into RAM and run it there with various debugging and monitoring options. There's no executable file involved in this process, and effectively it's running "from the editor" instead of from Workbench or the shell. This is typically done to test a program during development, with compiling to an executable file done later once it's nearly ready.

To answer the OP, yes there is. It's a function called FromBlitz and will return true if run from the Blitz IDE and false otherwise. It's not a core Blitz function however, it's in the RIMiscLib command library. This is included with most distributions of Blitz however, so chances are you already have it installed. If Blitz doesn't recognise the keyword FromBlitz, have a look at updating the installation to a more complete version.
Perfect. Thank you! I used to do a lot of programming in Blitz Basic but that's 3 decades ago. It feels like I have to learn it all over again.
zooperdan is offline  
Old 22 October 2021, 11:33   #7
zooperdan
Registered User

 
Join Date: Sep 2021
Location: Norway
Posts: 13
Quote:
Originally Posted by Daedalus View Post
Edit: I can't think of any way to do automatic conditional compiling based on whether it has been run from the editor or not. You could manually control it using a constant:

Code:
#debug = True

CNIF #debug
  NPrint "This is a debug build"
CEND
and then change the #debug to False when you build your final executable. AmiBlitz 3 has a compile-time constant #__debug (two underscores), which tells you if the debugger is running, though you can still run the code from the editor with the debugger turned off, in which case the compiler will also skip your debug code. That constant isn't available in Blitz 2 however...
Thanks again. Yeah that CNIF/CEND is something I can work with.
zooperdan is offline  
Old 22 October 2021, 11:40   #8
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 5,418
Cool, that's the method I use and it works well for me. Enjoy
Daedalus is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
run a program from within another meynaf Coders. System 22 13 August 2018 09:59
ClassicWB: How to run a program at startup? Foebane support.Apps 20 05 March 2018 10:54
Run AREXX program from PC side? MickGyver support.WinUAE 5 15 March 2017 11:05
Possible to run a program from CLI in background? VoltureX support.Apps 17 14 January 2012 04:16
Cant run AnimatED....anyone every used this great program? mrbob2 support.Apps 2 20 June 2009 14:13

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 08:01.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Page generated in 0.08051 seconds with 13 queries