Official Soldat Forums

Server Talk => Scripting Releases => Topic started by: tk on July 24, 2016, 08:17:57 pm

Title: Soldat Scripts with Lazarus IDE
Post by: tk on July 24, 2016, 08:17:57 pm
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.

(http://i.imgur.com/zR1jQYT.png)

Project structure
Under 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.
Code: [Select]
{$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
Code: [Select]
{$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 project
You 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).

Download
The Lazarus IDE (http://www.getlazarus.org/)
scriptcore.pas with example project on GitHub (https://github.com/tk70/LazarusSC/tree/master/scripts/LazarusSC)

Final notes
It'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.
Title: Re: Soldat Scripts with Lazarus IDE
Post by: jrgp on July 24, 2016, 10:15:16 pm
Nice job. That scriptcore.pas clearly took a lot of work.