Je mets ce code avec son explication ici pour le retrouver facilement quand j'aurai le temps de l'ajouter à la FAQ.
Il s'agit d'un exemple simple par 'Freak' pour créer un préprocesseur.
Je ferai le reste de la traduction plus tard.
Créer un exécutable à partir de ce code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| ;
; Simple preprocessor example that replaces all "Hello" with "Yellow"
;
#FILE_Input = 0
#FILE_Output = 1
; Read the temporary filename used by the compiler (first argument)
File$ = ProgramParameter()
; Get a path for our temporary file
Temp$ = GetTemporaryDirectory() + "ToolTest.pb"
; Make a copy of the compiler used file, so it can be overwritten
If CopyFile(File$, Temp$)
; read the copy
If ReadFile(#FILE_Input, Temp$)
; re-create the compiler used file so it can be filled with the modified version
If CreateFile(#FILE_Output, File$)
While Not Eof(#FILE_Input)
; process the lines
Line$ = ReadString(#FILE_Input)
Line$ = ReplaceString(Line$, "Hello", "Yellow")
WriteStringN(#FILE_Output, Line$)
Wend
CloseFile(#FILE_Output)
EndIf
CloseFile(#FILE_Input)
EndIf
; Delete the copy
DeleteFile(Temp$)
EndIf |
Envoyé par
Freak
Then configure a new tool like this:
Commandline: your exe
Arguments: "%COMPILEFILE" (include the "s to be safe from paths with spaces in them)
Event to trigger the tool: Before Compile/Run
Wait unitil tool quits: checked
This will run your tool whenever you use Compile/Run from the compiler menu. You may want to add a second tool configuration with "Before Create Executable" to also have the tool run in that case.
Some other useful settings might be to run the tool hidden, to hide it from the tools menu and to enable it on a per-source basis. (so you can activate that preprocessor in each source's compiler options and it won't mess with all codes you compile).
Now just compile a code like this and see what happens:
MessageRequester("", "Hello World!")
Partager