Difference between revisions of "Pascal Script"

From Free Pascal wiki
Jump to navigationJump to search
(Linked OS portals; fixed typos; removed dead link; added history section; fixed syntax highlighting)
 
(34 intermediate revisions by 14 users not shown)
Line 1: Line 1:
===About===
+
{{Pascal Script}}
Pascal Script is an ObjectPascal/Delphi/Lazarus compatible interpreter with bytecode compiler.
+
 
It currently works in Windows and Linux on a 32-bit Intel processor.
+
'''Pascal Script''' is an [[Object Pascal]]/[[Delphi]]/[[Lazarus]]-compatible interpreter with bytecode compiler that delivers a [[PascalScript|scripting]] environment for application programs.
 +
 
 +
It currently works in [[Portal:Mac|macOS]], [[Portal:Windows|Windows]] and [[Portal:Linux|Linux on 32-bit and 64-bit]] [[:Category:x86|x86]], [[PowerPC]] and [[ARM]] processors.
 +
 
 
It was created and is maintained by Carlo Kok and is copyrighted by [http://www.remobjects.com RemObjects software] as freeware with full source available.
 
It was created and is maintained by Carlo Kok and is copyrighted by [http://www.remobjects.com RemObjects software] as freeware with full source available.
The fix of few incompatibilities between ROPS (RemObjects Pascal Script) and FreePascal 2.0.1 was made by Bogusław Brandys with a great help of many developers from #fpc and #lazarus-ide IRC channels . Thank You.
 
  
 +
The fixing of a few incompatibilities between ROPS (RemObjects Pascal Script) and Free Pascal 2.0.1 was made by Bogusław Brandys with a great help of many developers from #fpc and #lazarus-ide IRC channels. Thank You.
  
Its main caracteristics are :
+
Its main characteristics are :
 
 
 
* almost all Object Pascal syntax supported  
 
* almost all Object Pascal syntax supported  
 
* Delphi/Lazarus classes supported (however cannot be declared inside of script)
 
* Delphi/Lazarus classes supported (however cannot be declared inside of script)
Line 13: Line 15:
 
* easily import new classes into script engine
 
* easily import new classes into script engine
  
 +
The download contains the components package for Delphi (various versions) and Lazarus + a few samples for Delphi (which may or may not work under Free Pascal+ Lazarus). It is work in progress...
  
The download contains the components package for Delphi (various versions) and Lazarus + a few samples for Delphi (which may or may not work under FreePascal+ Lazarus)
+
This component is now designed for cross-platform applications, however limited to 32-bit Intel platform only. I'd like to make it work on PowerPC and 64-bit architectures someday. (Note: The current version seems to support 64-bit machines, according to RemObjects.)
It is a work in progress.
 
 
 
This component is now designed for cross-platform applications, however limited to 32-bit Intel platform only. I'd like to make it work on PowerPC and 64-bit architectures someday.
 
 
 
===Screenshot===
 
  
 +
==Screenshots==
 
Here are some screenshots how it looks under Lazarus:
 
Here are some screenshots how it looks under Lazarus:
  
 +
<gallery>
 +
Image:Rops_linux.png|under Linux
 +
Image:Rops_windows.png|under Windows
 +
Image:maXbox_mini_LAZARUS.png|under Windows
 +
Image:Pascal Script for Lazarus 2 on Mac.png|macOS Mojave
 +
</gallery>
  
[http://wiki.lazarus.freepascal.org/index.php/Image:Rops_linux.png  under Linux]
+
==License==
[http://wiki.lazarus.freepascal.org/index.php/Image:Rops_windows.png under Windows]
 
 
 
===License===
 
 
BSD like, see [[Pascal Script/License | full text]].
 
BSD like, see [[Pascal Script/License | full text]].
  
===Download===
+
==Download==
You can download beta releases for testing here: [http://sourceforge.net/project/showfiles.php?group_id=92177 Lazarus CCR Files page].
+
* From RemObjects (FPC + Lazarus is supported)
 +
: This is the main page of RemObjects [http://www.remobjects.com/ps.aspx Pascal Script distribution]. There are download links for binary packages.
 +
* New repository: https://github.com/remobjects/pascalscript git://github.com/remobjects/pascalscript.git
 +
* '''In newer Lazarus versions Pascal Script is included as a standard component.'''
  
===Change Log===
+
==Change Log==
 
* Version 1.0 2005/10/21
 
* Version 1.0 2005/10/21
 
+
* ("Official" support of FPC, as seen on 2006/07/21)
  
 
===Dependencies / System Requirements===
 
===Dependencies / System Requirements===
 
* None
 
* None
 
+
* Status: Beta (ToDo: update info)
Status: Beta
+
* Issues: (ToDo: update info)
 
+
* Needs testing on Windows.
Issues:  
+
* Needs testing on Linux.
Needs testing on Windows.
+
* Almost working ;-)
Needs testing on Linux.
 
Almost working ;-)
 
  
 
===Installation===
 
===Installation===
Line 55: Line 58:
 
* Click on Install
 
* Click on Install
  
===Usage===
+
===Compilation errors===
Drop the PascalScript component on a form and a few plugins. (TODO:finish)
+
When compiling to install the package, the compiler will stumble on two lines in uPSR_forms.pas:
  
See the example projects.
+
<syntaxhighlight lang="pascal">
 +
RegisterMethod(@TAPPLICATION.HELPCOMMAND, 'HELPCOMMAND'); // <-- this one
 +
RegisterMethod(@TAPPLICATION.HELPCONTEXT, 'HELPCONTEXT');
 +
RegisterMethod(@TAPPLICATION.HELPJUMP, 'HELPJUMP');      // <-- and that one
 +
</syntaxhighlight>
  
See also this [http://www.remobjects.com/articles/?id={2FFC1EE9-F18D-4B11-9DE4-1BA0A79D0D04} article] from RemObjects.
+
Simply comment out the lines. These methods are not yet implemented in the LCL.
  
 +
==Usage==
 +
Drop the PascalScript component on a form and a few plugins. (TODO:finish)
  
===Example aplication===
+
If you get the error "Fatal: Can't find unit uPSCompiler used by ...", open up the pascalscript package, and under the "more" options, select "add to project".
  
Below is source code for small console mode interpreter application:
+
See the example projects.
 
 
<code>
 
program psce;
 
{$APPTYPE CONSOLE}
 
 
 
{$IFDEF FPC}
 
{$mode delphi}{$H+}
 
{$ENDIF}
 
 
 
uses
 
  SysUtils,interfaces,Classes,Forms,uPSCompiler, uPSR_std, uPSC_std, uPSR_classes, uPSC_classes, uPSRuntime, uPSComponent,uPSDisassembly,
 
  uPSR_dateutils,uPSC_dateutils,uPSC_forms,uPSR_forms,uPSC_controls,uPSR_controls,uPSR_dll,uPSC_dll;
 
 
 
type
 
  TPSCE = class
 
  protected
 
    FScr: TPSScript;
 
    procedure SaveCompiled(var Data : String);
 
    procedure SaveDissasembly(var Data : String);
 
    procedure OnCompile(Sender: TPSScript);
 
    procedure OnExecImport(Sender: TObject; se: TPSExec; x: TPSRuntimeClassImporter);
 
  public
 
    constructor Create;
 
    destructor Destroy; override;
 
    function Compile(const FileName: string): Boolean;
 
    function Execute: Boolean;
 
  end;
 
 
 
 
 
var
 
  aPSCE: TPSCE;
 
  SFile,Data : String;
 
 
 
 
 
procedure MWritedt(d : TDateTime);
 
var
 
s : String;
 
begin
 
  s := DateToStr(d) + ' ' + TimeToStr(d);
 
  Write(s);
 
end;
 
 
 
 
 
procedure MWrites(const s: string);
 
begin
 
  Write(s);
 
end;
 
 
 
 
 
 
 
procedure MWritei(const i: Integer);
 
begin
 
  Write(i);
 
end;
 
 
 
procedure MWrited(const d: Double);
 
begin
 
  Write(d:0:1);
 
end;
 
 
 
procedure MWriteln;
 
begin
 
  Writeln;
 
end;
 
 
 
procedure MVal(const s: string; var n, z: Integer);
 
begin
 
  Val(s, n, z);
 
end;
 
 
 
constructor TPSCE.Create;
 
begin
 
  FScr:=TPSScript.Create(nil);
 
  FScr.OnCompile:= OnCompile;
 
  FScr.OnExecImport := OnExecImport;
 
end;
 
 
 
destructor TPSCE.Destroy;
 
begin
 
  FScr.Free;
 
end;
 
 
 
procedure TPSCE.SaveCompiled(var Data : String);
 
var
 
  OutFile: string;
 
  Fx : Longint ;
 
begin
 
  OutFile := ExtractFilePath(ParamStr(0)) + ChangeFileExt(SFile,'.out');
 
  Fx:= FileCreate(OutFile) ;
 
  FileWrite(Fx,Data[1],Length(Data));
 
  FileClose (Fx) ;
 
end;
 
 
 
procedure TPSCE.SaveDissasembly(var Data : String);
 
var
 
  OutFile: string;
 
  Fx : Longint ;
 
begin
 
  OutFile := ExtractFilePath(ParamStr(0)) + ChangeFileExt(SFile,'.dis');
 
  Fx:= FileCreate(OutFile) ;
 
  FileWrite(Fx,Data[1],Length(Data));
 
  FileClose (Fx) ;
 
end;
 
 
 
 
 
 
 
procedure TPSCE.OnExecImport(Sender: TObject; se: TPSExec; x: TPSRuntimeClassImporter);
 
begin
 
RIRegister_Std(x);
 
RIRegister_Classes(x,true);
 
RIRegister_Forms(x);
 
RIRegister_Controls(x);
 
RegisterDateTimeLibrary_R(se);
 
RegisterDLLRuntime(se);
 
end;
 
 
 
procedure TPSCE.OnCompile(Sender: TPSScript);
 
begin
 
  RegisterDateTimeLibrary_C(Sender.Comp);
 
  Sender.AddFunction(@MWrites, 'procedure Writes(const s: string)');
 
  Sender.AddFunction(@MWritedt,'procedure WriteDT(d : TDateTime)');
 
  Sender.AddFunction(@MWritei, 'procedure Writei(const i: Integer)');
 
  Sender.AddFunction(@MWrited, 'procedure Writed(const f: Double)');
 
  Sender.AddFunction(@MWriteln, 'procedure Writeln');
 
  Sender.AddFunction(@MVal, 'procedure Val(const s: string; var n, z: Integer)');
 
  SIRegister_Std(Sender.Comp);
 
  SIRegister_Classes(Sender.Comp,true);
 
  SIRegister_Forms(Sender.Comp);
 
  SIRegister_Controls(Sender.Comp);
 
end;
 
 
 
function TPSCE.Compile(const FileName: string): Boolean;
 
var
 
  S: TStringList;
 
  i: Integer;
 
begin
 
  Result:=False;
 
  if FileExists(FileName) then begin
 
    S:=TStringList.Create;
 
    S.LoadFromFile(FileName);
 
    FScr.Script:=S;
 
    Result:=FScr.Compile;
 
    S.Free;
 
    if not Result then
 
      if FScr.CompilerMessageCount > 0 then
 
        for i:=0 to FScr.CompilerMessageCount-1 do
 
          Writeln(FScr.CompilerErrorToStr(i));
 
  end else Writeln('File not found: ', FileName);
 
end;
 
 
 
function TPSCE.Execute: Boolean;
 
begin
 
  Result:=FScr.Execute;
 
  if not Result then
 
    Writeln('Run-time error:' + FScr.ExecErrorToString);
 
end;
 
  
 +
See also these [https://github.com/remobjects/pascalscript/wiki articles] from RemObjects.
  
 +
==Example application==
 +
Sample small console mode interpreter application:
 +
[[Pascal Script Examples|Pascal Script Examples (psce)]]
  
 +
Sample components Demo with Lazarus GUI:
 +
[[http://sourceforge.net/projects/maxbox/files/Lazarus/PASCALSCRIPT_LAZARUS.zip/download]]
  
begin
+
== History ==
  Application.Initialize;
 
  aPSCE:=TPSCE.Create;
 
  if ParamCount = 0 then
 
  begin
 
    Writeln('Usage: ', ExtractFileName(ParamStr(0)), ' [--compile|--dissasembly] <script.pss>');
 
    Writeln('');
 
    Writeln('--compile : Save compiled script bytecode');
 
    Writeln('--dissasembly: Save dissasembly of script');
 
    Exit;
 
  end;
 
 
 
SFile := ParamStr(1);
 
if (ParamStr(1)='--compile') or (ParamStr(1)='--dissasembly') then
 
begin
 
  SFile := ParamStr(2);
 
  aPSCE.Compile(SFile);
 
  aPSCE.FScr.GetCompiled(Data);
 
  if Paramstr(1)='--compile' then aPSCE.SaveCompiled(Data);
 
  if Paramstr(1)='--dissasembly' then
 
  begin
 
    if not IFPS3DataToText(Data,Data) then Writeln('Cannot create dissasembly!')
 
    else
 
    aPSCE.SaveDissasembly(Data);
 
  end;
 
Exit;
 
end;
 
 
  
aPSCE.Compile(SFile);
+
Pascal Script started out in 2001 with CajScript 1.0, which was soon superseded by CajScript 2.0 (later called Innerfuse Pascal Script 2.0). Version 2.0 interpreted scripts while it ran them, which had the disadvantage that every piece of code had to be reparsed every time the script engine went over it. With Pascal Script 3.0, this was changed to a new model, where the compiler and runtime were completely separated from each other and used a custom byte code format to represent the compiled script. This compiled script only contained the bare minimum that was required to execute the code. Later, when Carlo Kok joined RemObjects, it was renamed RemObjects Pascal Script and is now being maintained by RemObjects Software.
aPSCE.Execute;
 
aPSCE.Free;
 
end.
 
  
 +
One prominent use of Pascal Script is the Open Source InnoSetup project. InnoSetup is a widely used setup engine that uses Pascal Script as scripting engine to provide advanced scripting abilities during installation and uninstallation. Using Pascal Script, users can customize almost all parts of the setup, add new wizard pages, call into dlls to add advanced features and provide custom behavior and install conditions.
  
 +
== See also ==
 +
* [https://www.remobjects.com/ps.aspx RemObjects Pascal Script page]
 +
* [[Pascal Script tab]]
  
</code>
+
[[Category: Pascal Script]]

Latest revision as of 13:54, 10 December 2019

Deutsch (de) English (en) español (es) 日本語 (ja) русский (ru)

Pascal Script is an Object Pascal/Delphi/Lazarus-compatible interpreter with bytecode compiler that delivers a scripting environment for application programs.

It currently works in macOS, Windows and Linux on 32-bit and 64-bit x86, PowerPC and ARM processors.

It was created and is maintained by Carlo Kok and is copyrighted by RemObjects software as freeware with full source available.

The fixing of a few incompatibilities between ROPS (RemObjects Pascal Script) and Free Pascal 2.0.1 was made by Bogusław Brandys with a great help of many developers from #fpc and #lazarus-ide IRC channels. Thank You.

Its main characteristics are :

  • almost all Object Pascal syntax supported
  • Delphi/Lazarus classes supported (however cannot be declared inside of script)
  • can create fully workable GUI forms with components
  • easily import new classes into script engine

The download contains the components package for Delphi (various versions) and Lazarus + a few samples for Delphi (which may or may not work under Free Pascal+ Lazarus). It is work in progress...

This component is now designed for cross-platform applications, however limited to 32-bit Intel platform only. I'd like to make it work on PowerPC and 64-bit architectures someday. (Note: The current version seems to support 64-bit machines, according to RemObjects.)

Screenshots

Here are some screenshots how it looks under Lazarus:

License

BSD like, see full text.

Download

  • From RemObjects (FPC + Lazarus is supported)
This is the main page of RemObjects Pascal Script distribution. There are download links for binary packages.

Change Log

  • Version 1.0 2005/10/21
  • ("Official" support of FPC, as seen on 2006/07/21)

Dependencies / System Requirements

  • None
  • Status: Beta (ToDo: update info)
  • Issues: (ToDo: update info)
  • Needs testing on Windows.
  • Needs testing on Linux.
  • Almost working ;-)

Installation

  • Create the directory lazarus\components\pascalscript
  • Unzip files into the directory
  • Open lazarus
  • Open the package pascalscript.lpk with Component/Open package file (.lpk)
  • Click on Compile
  • Click on Install

Compilation errors

When compiling to install the package, the compiler will stumble on two lines in uPSR_forms.pas:

RegisterMethod(@TAPPLICATION.HELPCOMMAND, 'HELPCOMMAND'); // <-- this one
RegisterMethod(@TAPPLICATION.HELPCONTEXT, 'HELPCONTEXT');
RegisterMethod(@TAPPLICATION.HELPJUMP, 'HELPJUMP');       // <-- and that one

Simply comment out the lines. These methods are not yet implemented in the LCL.

Usage

Drop the PascalScript component on a form and a few plugins. (TODO:finish)

If you get the error "Fatal: Can't find unit uPSCompiler used by ...", open up the pascalscript package, and under the "more" options, select "add to project".

See the example projects.

See also these articles from RemObjects.

Example application

Sample small console mode interpreter application: Pascal Script Examples (psce)

Sample components Demo with Lazarus GUI: [[1]]

History

Pascal Script started out in 2001 with CajScript 1.0, which was soon superseded by CajScript 2.0 (later called Innerfuse Pascal Script 2.0). Version 2.0 interpreted scripts while it ran them, which had the disadvantage that every piece of code had to be reparsed every time the script engine went over it. With Pascal Script 3.0, this was changed to a new model, where the compiler and runtime were completely separated from each other and used a custom byte code format to represent the compiled script. This compiled script only contained the bare minimum that was required to execute the code. Later, when Carlo Kok joined RemObjects, it was renamed RemObjects Pascal Script and is now being maintained by RemObjects Software.

One prominent use of Pascal Script is the Open Source InnoSetup project. InnoSetup is a widely used setup engine that uses Pascal Script as scripting engine to provide advanced scripting abilities during installation and uninstallation. Using Pascal Script, users can customize almost all parts of the setup, add new wizard pages, call into dlls to add advanced features and provide custom behavior and install conditions.

See also