The non VCL components derive from TObject so it can work without the VCL. Note that you do need to mess around with the units to get them to compile under FPC as they haven't quite got the IFDEF's right.

Running scripts is in two stages, first you compile the script , then you execute it. The compile stage can be done as a pre process so you can distribute only compiled scripts with your application.

There is an example of running a compiled script, the script and thje compiler. It assumes that the Pascal Script units are in you library path.

Hope it helps

Dean


Testbed to run the code

[pascal]
program testbed;
{$APPTYPE CONSOLE}
uses
SysUtils,
Classes,
Dialogs,
uPSRuntime,
uPSUtils,
uPSCompiler;



var Exec: TPSExec;
s: TStringStream;
fs: TFileStream;


procedure Debug_LogMessage(const s: string);
begin
Writeln(s);
end;
function Debug_GetInput: string;
begin
Result := InputBox('Debug_GetInput','GetInput','test');
end;

begin
Exec := TPSExec.Create;
s := TStringStream.Create('');
try
Exec.RegisterDelphiFunction(@Debug_LogMessage, 'DEBUG_LOGMESSAGE', cdRegister);
Exec.RegisterDelphiFunction(@Debug_GetInput, 'DEBUG_GETINPUT', cdRegister);

fs := TFileStream.Create(ParamStr(1), fmOpenRead);
try
s.CopyFrom(fs, 0);
finally
fs.Free;
end;
if not Exec.LoadData(s.DataString) then
begin
Writeln(Exec.ExceptionString);
Exit;
end;
Exec.RunScript;
finally
s.Free;
Exec.Free;
Readln;
end;
end.
[/pascal]

Here is the test script

[pascal]
var t: string;
i: integer;
begin
t := Debug_GetInput;
for i := 0 to 100 do
begin
Debug_LogMessage(t);
end;
end.
[/pascal]

This is the compiler
[pascal]
program compiler;

uses
SysUtils, Dialogs, Classes,
uPSUtils,
uPSCompiler,
uPSPreProcessor,
uPSRuntime;

var Compiler: TPSPascalCompiler;
Data: string;
Script: TStringList;
CompiledScript: TStringStream;
idx: Integer;


function OnUses(Sender: TPSPascalCompiler; const Name: string): Boolean;
begin
Writeln('OnUses');
Result := False;
if Name = 'SYSTEM' then
begin
Sender.AddDelphiFunction('procedure Debug_LogMessage(const s: string)');
Sender.AddDelphiFunction('function Debug_GetInput: string');
Result := True;
end;
end;


function OnExportCheck(Sender: TPSPascalCompiler; Proc: TPSInternalProcedure; const ProcDecl: string): Boolean;
begin
Result := True;
end;

begin
Script := TStringList.Create;
Script.LoadFromFile(ParamStr(1));
Compiler := TPSPascalCompiler.Create;
try
Compiler.OnUses := OnUses;
Compiler.OnExportCheck := OnExportCheck;
Compiler.AllowNoBegin := True;
Compiler.AllowNoEnd := True; // AllowNoBegin and AllowNoEnd allows it that begin and end are not required in a script.
if not Compiler.Compile(Script.Text) then // Compile the Pascal script into bytecode.
begin
// You could raise an exception here.
for idx := 0 to Compiler.MsgCount-1 do
begin
Writeln(Compiler.Msg[idx].MessageToString);
end;
Exit;
end;
Compiler.GetOutput(Data); // Save the output of the compiler in the string Data.
CompiledScript := TStringStream.Create(Data);
try
with TFileStream.Create(ParamStr(2), fmCreate or fmOpenWrite) do
begin
try
CopyFrom(CompiledScript, 0);
finally
Free;
end;
end;
finally
CompiledScript.Free;
end;
finally
Compiler.Free;
Script.Free;
end;
end.
[/pascal]