Page 1 of 2

Extend the compiler with resident Macros

Posted: Fri Jan 02, 2009 10:23 pm
by Blue
Sorry for the so-so topic title, but i'm not quite sure how to word what i want.

To make it simple, let me break it down in steps:
(1) i have a macro MsgBox() that i just can't live without... (yes, yes, i know; just take it as an example!)
(2) I use it in all my PB source code files and I would like to be able to call upon it without having to include it specifically in all source files.
(3) at present, I have the macro spelled out as as a template, which I can easily import in the source file when I remember to click on it.

Surely there is a way to call upon it as any other PB function or constant, without having to explicitly (and manually!) include it in all source files.

I'm under the impression that something like this is possible by using the \RESIDENTS folder in the PB setup, but i have no clue how to go about doing it practically. I remember coming acrosss a posting by NetMaestro alluding to such a possibility, but I haven't been able to find it again. Plus i didn't want to hijack the topic with my unrelated question.

Any suggestion, anyone ?

BTW: is there any documentation anywhere that explains in details the purpose of the many subfolders in the PB setup ? I've come across many tidbits here and there, but not any centralized explanation. I think that could be very useful to many PB users.

Posted: Fri Jan 02, 2009 10:55 pm
by srod
Yes, create a PB source file with just the macro in it and save it. Then use the command line to invoke the PB compiler with the RESIDENT switch to create a resident file (alternatively Tailbite can create a resident file for you). Place this resident file in the \Residents subfolder of your PB installation and then restart the IDE / compiler. At this point you can use your macro without any additional work.

Posted: Sat Jan 03, 2009 7:51 am
by Blue
srod wrote:Yes [...] you can use your macro without any additional work.
WOW!!! So cool and so very easy to do. :shock:
Thanks, Srod.
I followed your suggestion and it works really well
:lol:

I'm extremely impresssed by how easy PB makes it for the user to customize and extend the development environment.
It's amazingly smart and simple.

Too bad the documentation isn't more explicit on this and some other good things.
i think that such rich features should be easier to discover, understand and apply.
Clearly, the present documentation's one-liner on /RESIDENT is a bit short on the purpose and fabulous usefulness of this parameter and its name-sake subfolder... :roll:

Posted: Sat Jan 03, 2009 8:56 am
by Rings
just a example,

Code: Select all

Macro MsgBox(a)
  MessageRequester("Info",a,0)
EndMacro
save the file in yourdirectory(named "Msgbox_Macro.pb" )
open a shell,
type in:
pbcompiler yourdirectory/msgbox_macro.pb /resident ../Residents/msgbox.res
the restart the compiler from the IDE.

if you want to overwrite the Resident file, delete it first from the Residents directory

Posted: Sat Jan 03, 2009 9:16 am
by Blue
Thanks for the input, Rings.
That's pretty close to what I actually did following srod's instructions and, indeed, it works perfectly.

But since you seem in the know as to the raison d'ĂȘtre of the [Residents] sub-folder, maybe you know of other good but lesser known purposes for this folder or for the similarly named switch ?

--------------------------------------------------
BTW:
I just noticed the Moderator title following your name.
So, maybe you have the ability to make the information in this thread stand out as a sticky subject at the top of the section (Sorry: I just can't remember the word for this action... :oops:).
I'm convinced many users would greatly benefit from learning and making use of what is being offered here by you and Srod.

Posted: Sun Jan 04, 2009 1:37 am
by SFSxOI
I never knew how to do this, or that I even wanted to do this, until now. I've just been including a utilities.pbi with my favorite things in it in my stuff. Now i'll do some residents.

Thanks all for about the best tip I got today. :)

Posted: Sun Jan 04, 2009 6:20 am
by Blue
SFSxOI wrote:I never knew [...] that I even wanted to do this [...]
:lol: :lol: :lol:

Posted: Sun Jan 04, 2009 1:12 pm
by Seldon
Me too. :D Maybe it's a silly question, but which is the difference between a RES and a LIB file ? Can a LIB be made only in C or assembly ? And can I put just constants and macros in a RES file or functions too ? Thanks.

Posted: Sun Jan 04, 2009 2:04 pm
by srod
A residents file holds constants, structure definitions, prototypes,... only, i.e. no code.

Must admit that I no longer use these or user-libs; sticking firmly with source code includes only.

Posted: Sun Jan 04, 2009 2:50 pm
by Blue
srod wrote:[...]Must admit that I no longer use these or user-libs; sticking firmly with source code includes only.
Yeah. Now that I've played with my new toy, I can see at least one reason to abstain from using it: if you want to share your code, you MUST remember to translate all your clever obscure hacks :!: back into regular universal PB.

Is there a smart(er) way to automate the inclusion of a piece of code into new source files?
I've been using a one-line template (which works OK), but i'm thinking there must be a better way.

I'm beginning to think i should have opened this topic in the "PB Editor" section.

Posted: Sun Jan 04, 2009 3:36 pm
by Trond
Maybe it's possible to create a tool that creates a new file with some predefined contents (instead of the default empty one)?

Posted: Mon Jan 05, 2009 10:23 am
by Blue
Trond wrote:Maybe it's possible to create a tool that creates a new file with some predefined contents (instead of the default empty one)?
Right on, just as in MS Visual Basic (where you can even choose among a number of different template types!).
I have made, for myself, a tool that does what you suggest (creates a skeleton file, in a related folder, then opens the file in the IDE) ; it works, but its value is limited by the fact that it's not tied to the "New" command in the IDE.

Being able to do that would make the tool as practical (at least i think...) as the process used in VB. But i have not the slightest idea how to make the connection to that IDE command :cry:

Any idea on that ?

Posted: Wed Jan 07, 2009 3:33 pm
by graves
Hi,
I've found a trick to include procedures on a Resident file, and use it along all your programs.
The trick: include it on a macro.

1. Create a source file with this macro:

Code: Select all

macro TestProc
Procedure Test_Proc()
  pintn("Hello from proc")
EndProcedure
endmacro
2. Compile it as Resident file:

Code: Select all

pbcompiler path\file.pb /RESIDENT .\Residents\testproc.res
3. Create a new source with this little program, compile and execute:

Code: Select all

TestProc   ; to include the procedure in your program
OpenConsole()
Test_Proc()       ; to execute the procedure
input()
CloseConsole()
END

Posted: Wed Jan 07, 2009 4:38 pm
by Hurga
In jaPBe there is an possibility to include some file (more or less) automaically.

I suggested gnozal to make this option a bit more flexible so that I can just add a file to the specific folder and jaPBe registrate it so I can use it.
This would make it a bit easier and an lot more easy to change the "include"-files or add some code to them.

Posted: Wed Jan 07, 2009 10:48 pm
by akj
Following from what Blue says, for external tools, I would also very much welcome an additional trigger: 'New sourcecode created'.

After all, there is already a trigger for the opposite action of 'Sourcecode closed'.