Development of Soldat scripts longer than a few hundreds lines may be problematic without aid of a proper IDE. In this topic I show how to develop Soldat scripts with Lazarus - freeware Pascal IDE coming with Free Pascal Compiler (FPC).
Why even bother? Firstly, you gain some basic refactorization and code navigation features offered by Lazarus. Secondly, you don't need to run SoldatServer billions of times to find all your errors in the code, the Pascal compiler will do that automatically. Yes, you actually can compile your script in Lazarus, which doesn't make much sense, except for parsing the script for syntactic correctness. The produced binary is rubbish, obviously.
Project structureUnder linked Github repository, the scriptcore.pas unit with example project are provided.
Your script must be compilable both by SoldatServer and FPC. This is done by maintaining structure of an actual Pascal program and using ScriptCore.pas unit, which consists of empty SC2/SC3 declarations.
In main project file (*.lpr) there must be the main script file included.
All script units must have scriptcore.pas included, so the FPC can recognize Scriptcore references.
{$ifdef FPC}
uses
Scriptcore;
{$endif}
In general, Pascal Script is more liberal than Delphi, although not everything compiled by Delphi will be compiled by Soldat Server. Your current scripts may require some minor changes. I haven't found anything that cannot be fixed by preprocessor.
Problems discovered so far- GetArrayLength, SetArrayLength - you may have to replace them with Length, SetLength, because of some variant issues in FPC. The latter version is known both to Delphi and Scriptcore.
- array of string - try replacing it with TStringArray.
- if string <> nil - Delphi doesn't take this well, change it to if string <> ''.
- case string of - This seems not to be allowed in Delphi, therefore you may need to use preprocessor
to hide it from FPC.
{$ifndef FPC}
code which FPC doesn't like.
{$endif}
If you come across any piece of code that FPC doesn't digest, just exclude it with the preprocessor. It only matters that Scriptcore compiles it after all.
Creating a new projectYou may modify the example project from the link. If for some reason you want to make the project from scratch, then go:
File -> New -> Simple program
Project -> Project Options
Parsing -> Syntax mode -> Delphi
(optional) Compilation and Linking -> Set optimization level to zero so it compiles faster.
(optional) Messages -> you may want to disable some warnings about unused parameters and such, otherwise the compilation log might get spammy;
Include the main script unit from the *.lpr file with "uses";
Save the project;
Build (Shift + F9).
DownloadThe Lazarus IDEscriptcore.pas with example project on GitHubFinal notesIt's still experimental. The scriptocre.pas is based on scriptcore source files, but it still may be lacking some declarations, or they might be incorrect. We will (probably) be updating it over time.