forked from remobjects/pascalscript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: http://code.remobjects.com/svn/pascalscript@1 5c9d2617-0215-0410-a2ee-e80e04d1c6d8
- Loading branch information
carlokok
committed
May 30, 2006
0 parents
commit afe3fdf
Showing
237 changed files
with
83,622 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
program sample1; | ||
|
||
uses | ||
uPSCompiler, uPSRuntime; | ||
|
||
function ScriptOnUses(Sender: TPSPascalCompiler; const Name: string): Boolean; | ||
{ the OnUses callback function is called for each "uses" in the script. | ||
It's always called with the parameter 'SYSTEM' at the top of the script. | ||
For example: uses ii1, ii2; | ||
This will call this function 3 times. First with 'SYSTEM' then 'II1' and then 'II2'. | ||
} | ||
begin | ||
if Name = 'SYSTEM' then | ||
begin | ||
Result := True; | ||
end else | ||
Result := False; | ||
end; | ||
|
||
procedure ExecuteScript(const Script: string); | ||
var | ||
Compiler: TPSPascalCompiler; | ||
{ TPSPascalCompiler is the compiler part of the scriptengine. This will | ||
translate a Pascal script into a compiled form the executer understands. } | ||
Exec: TPSExec; | ||
{ TPSExec is the executer part of the scriptengine. It uses the output of | ||
the compiler to run a script. } | ||
Data: string; | ||
begin | ||
Compiler := TPSPascalCompiler.Create; // create an instance of the compiler. | ||
Compiler.OnUses := ScriptOnUses; // assign the OnUses event. | ||
if not Compiler.Compile(Script) then // Compile the Pascal script into bytecode. | ||
begin | ||
Compiler.Free; | ||
// You could raise an exception here. | ||
Exit; | ||
end; | ||
|
||
Compiler.GetOutput(Data); // Save the output of the compiler in the string Data. | ||
Compiler.Free; // After compiling the script, there is no need for the compiler anymore. | ||
|
||
Exec := TPSExec.Create; // Create an instance of the executer. | ||
if not Exec.LoadData(Data) then // Load the data from the Data string. | ||
begin | ||
{ For some reason the script could not be loaded. This is usually the case when a | ||
library that has been used at compile time isn't registered at runtime. } | ||
Exec.Free; | ||
// You could raise an exception here. | ||
Exit; | ||
end; | ||
|
||
Exec.RunScript; // Run the script. | ||
Exec.Free; // Free the executer. | ||
end; | ||
|
||
const | ||
Script = 'var s: string; begin s := ''Test''; S := s + ''ing;''; end.'; | ||
|
||
begin | ||
ExecuteScript(Script); | ||
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
program sample2; | ||
|
||
uses | ||
uPSCompiler, | ||
uPSRuntime, | ||
|
||
Dialogs | ||
|
||
; | ||
|
||
procedure MyOwnFunction(const Data: string); | ||
begin | ||
// Do something with Data | ||
ShowMessage(Data); | ||
end; | ||
|
||
function ScriptOnUses(Sender: TPSPascalCompiler; const Name: string): Boolean; | ||
{ the OnUses callback function is called for each "uses" in the script. | ||
It's always called with the parameter 'SYSTEM' at the top of the script. | ||
For example: uses ii1, ii2; | ||
This will call this function 3 times. First with 'SYSTEM' then 'II1' and then 'II2'. | ||
} | ||
begin | ||
if Name = 'SYSTEM' then | ||
begin | ||
Sender.AddDelphiFunction('procedure MyOwnFunction(Data: string)'); | ||
{ This will register the function to the script engine. Now it can be used from | ||
within the script.} | ||
|
||
Result := True; | ||
end else | ||
Result := False; | ||
end; | ||
|
||
procedure ExecuteScript(const Script: string); | ||
var | ||
Compiler: TPSPascalCompiler; | ||
{ TPSPascalCompiler is the compiler part of the scriptengine. This will | ||
translate a Pascal script into a compiled form the executer understands. } | ||
Exec: TPSExec; | ||
{ TPSExec is the executer part of the scriptengine. It uses the output of | ||
the compiler to run a script. } | ||
Data: string; | ||
begin | ||
Compiler := TPSPascalCompiler.Create; // create an instance of the compiler. | ||
Compiler.OnUses := ScriptOnUses; // assign the OnUses event. | ||
if not Compiler.Compile(Script) then // Compile the Pascal script into bytecode. | ||
begin | ||
Compiler.Free; | ||
// You could raise an exception here. | ||
Exit; | ||
end; | ||
|
||
Compiler.GetOutput(Data); // Save the output of the compiler in the string Data. | ||
Compiler.Free; // After compiling the script, there is no need for the compiler anymore. | ||
|
||
Exec := TPSExec.Create; // Create an instance of the executer. | ||
Exec.RegisterDelphiFunction(@MyOwnFunction, 'MYOWNFUNCTION', cdRegister); | ||
{ This will register the function to the executer. The first parameter is a | ||
pointer to the function. The second parameter is the name of the function (in uppercase). | ||
And the last parameter is the calling convention (usually Register). } | ||
|
||
if not Exec.LoadData(Data) then // Load the data from the Data string. | ||
begin | ||
{ For some reason the script could not be loaded. This is usually the case when a | ||
library that has been used at compile time isn't registered at runtime. } | ||
Exec.Free; | ||
// You could raise an exception here. | ||
Exit; | ||
end; | ||
|
||
Exec.RunScript; // Run the script. | ||
Exec.Free; // Free the executer. | ||
end; | ||
|
||
|
||
|
||
const | ||
Script = 'var s: string; begin s := ''Test''; S := s + ''ing;''; MyOwnFunction(s); end.'; | ||
|
||
begin | ||
ExecuteScript(Script); | ||
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
program sample3; | ||
|
||
uses | ||
uPSC_dll, | ||
uPSR_dll, | ||
uPSCompiler, | ||
uPSRuntime; | ||
|
||
function ScriptOnUses(Sender: TPSPascalCompiler; const Name: string): Boolean; | ||
{ the OnUses callback function is called for each "uses" in the script. | ||
It's always called with the parameter 'SYSTEM' at the top of the script. | ||
For example: uses ii1, ii2; | ||
This will call this function 3 times. First with 'SYSTEM' then 'II1' and then 'II2'. | ||
} | ||
begin | ||
if Name = 'SYSTEM' then | ||
begin | ||
Sender.OnExternalProc := @DllExternalProc; | ||
{ Assign the dll library to the script engine. This function can be found in the uPSC_dll.pas file. | ||
When you have assigned this, it's possible to do this in the script: | ||
Function FindWindow(c1, c2: PChar): Cardinal; external '[email protected] stdcall'; | ||
The syntax for the external string is 'functionname@dllname callingconvention'. | ||
} | ||
|
||
Result := True; | ||
end else | ||
Result := False; | ||
end; | ||
|
||
procedure ExecuteScript(const Script: string); | ||
var | ||
Compiler: TPSPascalCompiler; | ||
{ TPSPascalCompiler is the compiler part of the scriptengine. This will | ||
translate a Pascal script into a compiled form the executer understands. } | ||
Exec: TPSExec; | ||
{ TPSExec is the executer part of the scriptengine. It uses the output of | ||
the compiler to run a script. } | ||
Data: string; | ||
begin | ||
Compiler := TPSPascalCompiler.Create; // create an instance of the compiler. | ||
Compiler.OnUses := ScriptOnUses; // assign the OnUses event. | ||
if not Compiler.Compile(Script) then // Compile the Pascal script into bytecode. | ||
begin | ||
Compiler.Free; | ||
// You could raise an exception here. | ||
Exit; | ||
end; | ||
|
||
Compiler.GetOutput(Data); // Save the output of the compiler in the string Data. | ||
Compiler.Free; // After compiling the script, there is no need for the compiler anymore. | ||
|
||
Exec := TPSExec.Create; // Create an instance of the executer. | ||
|
||
RegisterDLLRuntime(Exec); | ||
{ Register the DLL runtime library. This can be found in the uPSR_dll.pas file.} | ||
|
||
if not Exec.LoadData(Data) then // Load the data from the Data string. | ||
begin | ||
{ For some reason the script could not be loaded. This is usually the case when a | ||
library that has been used at compile time isn't registered at runtime. } | ||
Exec.Free; | ||
// You could raise an exception here. | ||
Exit; | ||
end; | ||
|
||
Exec.RunScript; // Run the script. | ||
Exec.Free; // Free the executer. | ||
end; | ||
|
||
|
||
const | ||
Script = | ||
'function MessageBox(hWnd: Longint; lpText, lpCaption: PChar; uType: Longint): Longint; external ''[email protected] stdcall'';'#13#10 + | ||
'var s: string; begin s := ''Test''; MessageBox(0, s, ''Caption Here!'', 0);end.'; | ||
|
||
begin | ||
ExecuteScript(Script); | ||
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
program sample4; | ||
|
||
uses | ||
uPSCompiler, | ||
uPSRuntime, | ||
uPSC_std, | ||
uPSC_controls, | ||
uPSC_stdctrls, | ||
uPSC_forms, | ||
uPSR_std, | ||
uPSR_controls, | ||
uPSR_stdctrls, | ||
uPSR_forms, | ||
forms | ||
|
||
; | ||
|
||
function ScriptOnUses(Sender: TPSPascalCompiler; const Name: string): Boolean; | ||
{ the OnUses callback function is called for each "uses" in the script. | ||
It's always called with the parameter 'SYSTEM' at the top of the script. | ||
For example: uses ii1, ii2; | ||
This will call this function 3 times. First with 'SYSTEM' then 'II1' and then 'II2'. | ||
} | ||
begin | ||
if Name = 'SYSTEM' then | ||
begin | ||
SIRegister_Std(Sender); | ||
{ This will register the declarations of these classes: | ||
TObject, TPersistent, TComponent. This can be found | ||
in the uPSC_std.pas unit. } | ||
|
||
SIRegister_Controls(Sender); | ||
{ This will register the declarations of these classes: | ||
TControl, TWinControl, TFont, TStrings, TStringList, TCanvas, TGraphicControl. This can be found | ||
in the uPSC_controls.pas unit. } | ||
|
||
SIRegister_Forms(Sender); | ||
{ This will register: TScrollingWinControl, TCustomForm, TForm and TApplication. uPSC_forms.pas unit. } | ||
|
||
SIRegister_stdctrls(Sender); | ||
{ This will register: TButtonContol, TButton, TCustomCheckbox, TCheckBox, TCustomEdit, TEdit, TCustomMemo, TMemo, | ||
TCustomLabel and TLabel. Can be found in the uPSC_stdctrls.pas unit. } | ||
|
||
Result := True; | ||
end else | ||
Result := False; | ||
end; | ||
|
||
procedure ExecuteScript(const Script: string); | ||
var | ||
Compiler: TPSPascalCompiler; | ||
{ TPSPascalCompiler is the compiler part of the scriptengine. This will | ||
translate a Pascal script into a compiled form the executer understands. } | ||
Exec: TPSExec; | ||
{ TPSExec is the executer part of the scriptengine. It uses the output of | ||
the compiler to run a script. } | ||
Data: string; | ||
CI: TPSRuntimeClassImporter; | ||
begin | ||
Compiler := TPSPascalCompiler.Create; // create an instance of the compiler. | ||
Compiler.OnUses := ScriptOnUses; // assign the OnUses event. | ||
if not Compiler.Compile(Script) then // Compile the Pascal script into bytecode. | ||
begin | ||
Compiler.Free; | ||
// You could raise an exception here. | ||
Exit; | ||
end; | ||
|
||
Compiler.GetOutput(Data); // Save the output of the compiler in the string Data. | ||
Compiler.Free; // After compiling the script, there is no need for the compiler anymore. | ||
|
||
CI := TPSRuntimeClassImporter.Create; | ||
{ Create an instance of the runtime class importer.} | ||
|
||
RIRegister_Std(CI); // uPSR_std.pas unit. | ||
RIRegister_stdctrls(CI); // uPSR_stdctrls.pas unit. | ||
RIRegister_Controls(CI); // uPSR_controls.pas unit. | ||
RIRegister_Forms(CI); // uPSR_forms.pas unit. | ||
|
||
Exec := TPSExec.Create; // Create an instance of the executer. | ||
|
||
RegisterClassLibraryRuntime(Exec, CI); | ||
// Assign the runtime class importer to the executer. | ||
|
||
if not Exec.LoadData(Data) then // Load the data from the Data string. | ||
begin | ||
{ For some reason the script could not be loaded. This is usually the case when a | ||
library that has been used at compile time isn't registered at runtime. } | ||
Exec.Free; | ||
// You could raise an exception here. | ||
Exit; | ||
end; | ||
|
||
Exec.RunScript; // Run the script. | ||
Exec.Free; // Free the executer. | ||
CI.Free; // Free the runtime class importer. | ||
end; | ||
|
||
|
||
|
||
const | ||
Script = | ||
'var f: TForm; i: Longint; begin f := TForm.CreateNew(nil,0); f.Show; for i := 0 to 1000000 do; f.Hide; f.free; end.'; | ||
|
||
begin | ||
ExecuteScript(Script); | ||
end. |
Oops, something went wrong.