1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-12-22 23:38:50 -05:00

Some more files for #75.

git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@76 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
Wizzup? 2009-09-22 08:16:52 +00:00
parent f1a223473d
commit c49b1d84e9
3 changed files with 395 additions and 412 deletions

View File

@ -33,15 +33,15 @@
<PackageName Value="LCL"/>
</Item2>
</RequiredPackages>
<Units Count="114">
<Units Count="116">
<Unit0>
<Filename Value="project1.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="project1"/>
<CursorPos X="56" Y="11"/>
<CursorPos X="61" Y="11"/>
<TopLine Value="1"/>
<EditorIndex Value="0"/>
<UsageCount Value="119"/>
<UsageCount Value="121"/>
<Loaded Value="True"/>
</Unit0>
<Unit1>
@ -170,10 +170,10 @@
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="TestUnit"/>
<CursorPos X="30" Y="270"/>
<TopLine Value="255"/>
<EditorIndex Value="5"/>
<UsageCount Value="85"/>
<CursorPos X="68" Y="259"/>
<TopLine Value="228"/>
<EditorIndex Value="7"/>
<UsageCount Value="87"/>
<Loaded Value="True"/>
</Unit18>
<Unit19>
@ -302,10 +302,10 @@
<Filename Value="../../Units/MMLCore/client.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="Client"/>
<CursorPos X="25" Y="16"/>
<CursorPos X="35" Y="40"/>
<TopLine Value="1"/>
<EditorIndex Value="4"/>
<UsageCount Value="84"/>
<UsageCount Value="86"/>
<Loaded Value="True"/>
</Unit37>
<Unit38>
@ -315,7 +315,7 @@
<CursorPos X="3" Y="15"/>
<TopLine Value="1"/>
<EditorIndex Value="3"/>
<UsageCount Value="84"/>
<UsageCount Value="86"/>
<Loaded Value="True"/>
</Unit38>
<Unit39>
@ -331,16 +331,16 @@
<UnitName Value="files"/>
<CursorPos X="37" Y="42"/>
<TopLine Value="271"/>
<UsageCount Value="85"/>
<UsageCount Value="87"/>
</Unit40>
<Unit41>
<Filename Value="../../Units/MMLCore/window.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="Window"/>
<CursorPos X="3" Y="189"/>
<TopLine Value="187"/>
<EditorIndex Value="24"/>
<UsageCount Value="84"/>
<CursorPos X="33" Y="215"/>
<TopLine Value="206"/>
<EditorIndex Value="9"/>
<UsageCount Value="86"/>
<Loaded Value="True"/>
</Unit41>
<Unit42>
@ -375,10 +375,10 @@
<Filename Value="../../Units/MMLCore/finder.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="finder"/>
<CursorPos X="19" Y="152"/>
<TopLine Value="138"/>
<CursorPos X="63" Y="22"/>
<TopLine Value="11"/>
<EditorIndex Value="1"/>
<UsageCount Value="77"/>
<UsageCount Value="79"/>
<Loaded Value="True"/>
</Unit46>
<Unit47>
@ -394,7 +394,7 @@
<UnitName Value="MMLThread"/>
<CursorPos X="132" Y="5"/>
<TopLine Value="1"/>
<UsageCount Value="75"/>
<UsageCount Value="77"/>
</Unit48>
<Unit49>
<Filename Value="../../../Documents/fpc/rtl/objpas/classes/classesh.inc"/>
@ -406,10 +406,10 @@
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="mmlpsthread"/>
<CursorPos X="17" Y="34"/>
<TopLine Value="10"/>
<EditorIndex Value="13"/>
<UsageCount Value="73"/>
<CursorPos X="32" Y="268"/>
<TopLine Value="251"/>
<EditorIndex Value="8"/>
<UsageCount Value="75"/>
<Loaded Value="True"/>
</Unit50>
<Unit51>
@ -417,17 +417,13 @@
<UnitName Value="uPSComponent"/>
<CursorPos X="23" Y="510"/>
<TopLine Value="504"/>
<EditorIndex Value="18"/>
<UsageCount Value="23"/>
<Loaded Value="True"/>
</Unit51>
<Unit52>
<Filename Value="../../../FPC/FPCCheckout/rtl/objpas/classes/classesh.inc"/>
<CursorPos X="12" Y="116"/>
<TopLine Value="101"/>
<EditorIndex Value="7"/>
<UsageCount Value="13"/>
<Loaded Value="True"/>
</Unit52>
<Unit53>
<Filename Value="../../../FPC/FPCCheckout/rtl/objpas/types.pp"/>
@ -468,9 +464,7 @@
<UnitName Value="SynMemo"/>
<CursorPos X="19" Y="161"/>
<TopLine Value="146"/>
<EditorIndex Value="10"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit58>
<Unit59>
<Filename Value="../../../lazarus/components/synedit/syneditmiscclasses.pp"/>
@ -484,9 +478,7 @@
<UnitName Value="SynEdit"/>
<CursorPos X="3" Y="4078"/>
<TopLine Value="4064"/>
<EditorIndex Value="11"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit60>
<Unit61>
<Filename Value="../../../lazarus/components/synedit/syngutterchanges.pas"/>
@ -527,9 +519,7 @@
<Filename Value="../../Units/MMLAddon/PSInc/pscompile.inc"/>
<CursorPos X="23" Y="15"/>
<TopLine Value="1"/>
<EditorIndex Value="19"/>
<UsageCount Value="29"/>
<Loaded Value="True"/>
</Unit66>
<Unit67>
<Filename Value="../../../FPC/FPCCheckout/rtl/win/tthread.inc"/>
@ -541,18 +531,16 @@
<Filename Value="../../../FPC/FPCCheckout/rtl/inc/objpash.inc"/>
<CursorPos X="21" Y="184"/>
<TopLine Value="169"/>
<EditorIndex Value="17"/>
<UsageCount Value="18"/>
<Loaded Value="True"/>
</Unit68>
<Unit69>
<Filename Value="../../Units/MMLCore/bitmaps.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="bitmaps"/>
<CursorPos X="72" Y="420"/>
<TopLine Value="408"/>
<EditorIndex Value="25"/>
<UsageCount Value="63"/>
<CursorPos X="63" Y="428"/>
<TopLine Value="419"/>
<EditorIndex Value="10"/>
<UsageCount Value="65"/>
<Loaded Value="True"/>
</Unit69>
<Unit70>
@ -565,17 +553,15 @@
<Unit71>
<Filename Value="../../Units/MMLAddon/PSInc/Wrappers/colour.inc"/>
<CursorPos X="86" Y="33"/>
<TopLine Value="4"/>
<EditorIndex Value="23"/>
<TopLine Value="10"/>
<UsageCount Value="19"/>
<Loaded Value="True"/>
</Unit71>
<Unit72>
<Filename Value="../../Units/MMLAddon/PSInc/Wrappers/bitmap.inc"/>
<IsPartOfProject Value="True"/>
<CursorPos X="30" Y="34"/>
<TopLine Value="22"/>
<UsageCount Value="62"/>
<UsageCount Value="64"/>
</Unit72>
<Unit73>
<Filename Value="../../../FPC/FPCCheckout/packages/fcl-image/src/fpcanvas.inc"/>
@ -687,17 +673,13 @@
<UnitName Value="math"/>
<CursorPos X="10" Y="314"/>
<TopLine Value="299"/>
<EditorIndex Value="22"/>
<UsageCount Value="11"/>
<Loaded Value="True"/>
</Unit89>
<Unit90>
<Filename Value="../../../FPC/FPCCheckout/rtl/inc/systemh.inc"/>
<CursorPos X="5" Y="121"/>
<TopLine Value="106"/>
<EditorIndex Value="21"/>
<UsageCount Value="11"/>
<Loaded Value="True"/>
</Unit90>
<Unit91>
<Filename Value="../../../FPC/FPCCheckout/rtl/i386/fastmove.inc"/>
@ -712,14 +694,14 @@
<CursorPos X="49" Y="141"/>
<TopLine Value="141"/>
<EditorIndex Value="2"/>
<UsageCount Value="45"/>
<UsageCount Value="47"/>
<Loaded Value="True"/>
</Unit92>
<Unit93>
<Filename Value="../../../cogat/Units/CogatUnits/compcolors.pas"/>
<UnitName Value="CompColors"/>
<CursorPos X="19" Y="80"/>
<TopLine Value="75"/>
<CursorPos X="10" Y="35"/>
<TopLine Value="20"/>
<UsageCount Value="11"/>
</Unit93>
<Unit94>
@ -732,9 +714,7 @@
<Filename Value="../../Units/MMLAddon/PSInc/Wrappers/other.inc"/>
<CursorPos X="1" Y="1"/>
<TopLine Value="1"/>
<EditorIndex Value="16"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit95>
<Unit96>
<Filename Value="../../Units/PascalScript/uPSCompiler.pas"/>
@ -774,8 +754,8 @@
<UnitName Value="plugins"/>
<CursorPos X="86" Y="128"/>
<TopLine Value="128"/>
<EditorIndex Value="26"/>
<UsageCount Value="39"/>
<EditorIndex Value="11"/>
<UsageCount Value="41"/>
<Loaded Value="True"/>
</Unit101>
<Unit102>
@ -812,184 +792,189 @@
</Unit106>
<Unit107>
<Filename Value="../../Units/PascalScript/x86.inc"/>
<CursorPos X="1" Y="32"/>
<TopLine Value="17"/>
<EditorIndex Value="15"/>
<CursorPos X="41" Y="24"/>
<TopLine Value="241"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit107>
<Unit108>
<Filename Value="../../../FPC/FPCCheckout/rtl/inc/mathh.inc"/>
<CursorPos X="14" Y="71"/>
<TopLine Value="56"/>
<EditorIndex Value="20"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit108>
<Unit109>
<Filename Value="../../Units/MMLAddon/PSInc/Wrappers/math.inc"/>
<CursorPos X="20" Y="3"/>
<CursorPos X="10" Y="1"/>
<TopLine Value="1"/>
<EditorIndex Value="14"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit109>
<Unit110>
<Filename Value="../../../lazarus/lcl/controls.pp"/>
<UnitName Value="Controls"/>
<CursorPos X="14" Y="1371"/>
<TopLine Value="1356"/>
<EditorIndex Value="8"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit110>
<Unit111>
<Filename Value="../../../lazarus/lcl/include/control.inc"/>
<CursorPos X="28" Y="1022"/>
<TopLine Value="1010"/>
<EditorIndex Value="9"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit111>
<Unit112>
<Filename Value="../../../lazarus/lcl/stdctrls.pp"/>
<UnitName Value="StdCtrls"/>
<CursorPos X="3" Y="894"/>
<TopLine Value="879"/>
<EditorIndex Value="12"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit112>
<Unit113>
<Filename Value="../../../lazarus/lcl/menus.pp"/>
<UnitName Value="Menus"/>
<CursorPos X="50" Y="542"/>
<TopLine Value="522"/>
<EditorIndex Value="6"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit113>
<Unit114>
<Filename Value="../../../cogat/Units/CogatUnits/compdtm.pas"/>
<UnitName Value="compDTM"/>
<CursorPos X="1" Y="44"/>
<TopLine Value="41"/>
<EditorIndex Value="5"/>
<UsageCount Value="11"/>
<Loaded Value="True"/>
</Unit114>
<Unit115>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="dtm"/>
<CursorPos X="1" Y="32"/>
<TopLine Value="2"/>
<EditorIndex Value="6"/>
<UsageCount Value="22"/>
<Loaded Value="True"/>
</Unit115>
</Units>
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="testunit.pas"/>
<Caret Line="307" Column="24" TopLine="291"/>
</Position1>
<Position2>
<Filename Value="testunit.pas"/>
<Caret Line="18" Column="15" TopLine="9"/>
</Position2>
<Position3>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="8" Column="75" TopLine="4"/>
</Position3>
<Position4>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="20" Column="22" TopLine="5"/>
</Position4>
<Position5>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="63" Column="24" TopLine="51"/>
</Position5>
<Position6>
</Position1>
<Position2>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="268" Column="29" TopLine="253"/>
</Position2>
<Position3>
<Filename Value="testunit.pas"/>
<Caret Line="18" Column="26" TopLine="9"/>
</Position3>
<Position4>
<Filename Value="testunit.pas"/>
<Caret Line="20" Column="26" TopLine="9"/>
</Position4>
<Position5>
<Filename Value="testunit.pas"/>
<Caret Line="21" Column="26" TopLine="9"/>
</Position5>
<Position6>
<Filename Value="testunit.pas"/>
<Caret Line="20" Column="26" TopLine="9"/>
</Position6>
<Position7>
<Filename Value="testunit.pas"/>
<Caret Line="18" Column="26" TopLine="9"/>
<Caret Line="28" Column="47" TopLine="9"/>
</Position7>
<Position8>
<Filename Value="testunit.pas"/>
<Caret Line="20" Column="26" TopLine="9"/>
<Caret Line="21" Column="16" TopLine="20"/>
</Position8>
<Position9>
<Filename Value="testunit.pas"/>
<Caret Line="21" Column="26" TopLine="9"/>
<Caret Line="27" Column="49" TopLine="12"/>
</Position9>
<Position10>
<Filename Value="testunit.pas"/>
<Caret Line="20" Column="26" TopLine="9"/>
<Caret Line="20" Column="24" TopLine="4"/>
</Position10>
<Position11>
<Filename Value="testunit.pas"/>
<Caret Line="28" Column="47" TopLine="9"/>
<Caret Line="20" Column="26" TopLine="4"/>
</Position11>
<Position12>
<Filename Value="testunit.pas"/>
<Caret Line="21" Column="16" TopLine="20"/>
<Caret Line="27" Column="49" TopLine="4"/>
</Position12>
<Position13>
<Filename Value="testunit.pas"/>
<Caret Line="27" Column="49" TopLine="12"/>
<Caret Line="272" Column="1" TopLine="259"/>
</Position13>
<Position14>
<Filename Value="testunit.pas"/>
<Caret Line="20" Column="24" TopLine="4"/>
<Caret Line="269" Column="33" TopLine="254"/>
</Position14>
<Position15>
<Filename Value="../../../lazarus/lcl/menus.pp"/>
<Caret Line="106" Column="3" TopLine="91"/>
<Filename Value="../../Units/MMLCore/window.pas"/>
<Caret Line="189" Column="3" TopLine="187"/>
</Position15>
<Position16>
<Filename Value="../../../lazarus/lcl/menus.pp"/>
<Caret Line="125" Column="22" TopLine="110"/>
<Filename Value="../../Units/MMLCore/window.pas"/>
<Caret Line="127" Column="12" TopLine="106"/>
</Position16>
<Position17>
<Filename Value="testunit.pas"/>
<Caret Line="20" Column="26" TopLine="4"/>
<Filename Value="../../Units/MMLCore/window.pas"/>
<Caret Line="191" Column="23" TopLine="172"/>
</Position17>
<Position18>
<Filename Value="../../../lazarus/lcl/menus.pp"/>
<Caret Line="106" Column="3" TopLine="91"/>
<Filename Value="../../../cogat/Units/CogatUnits/compdtm.pas"/>
<Caret Line="46" Column="22" TopLine="35"/>
</Position18>
<Position19>
<Filename Value="../../../lazarus/lcl/menus.pp"/>
<Caret Line="125" Column="25" TopLine="110"/>
<Filename Value="../../../cogat/Units/CogatUnits/compdtm.pas"/>
<Caret Line="47" Column="22" TopLine="35"/>
</Position19>
<Position20>
<Filename Value="../../../lazarus/lcl/menus.pp"/>
<Caret Line="165" Column="64" TopLine="150"/>
<Filename Value="../../../cogat/Units/CogatUnits/compdtm.pas"/>
<Caret Line="48" Column="22" TopLine="35"/>
</Position20>
<Position21>
<Filename Value="../../../lazarus/lcl/menus.pp"/>
<Caret Line="193" Column="51" TopLine="178"/>
<Filename Value="../../../cogat/Units/CogatUnits/compdtm.pas"/>
<Caret Line="49" Column="22" TopLine="35"/>
</Position21>
<Position22>
<Filename Value="../../../lazarus/lcl/menus.pp"/>
<Caret Line="272" Column="66" TopLine="257"/>
<Filename Value="../../../cogat/Units/CogatUnits/compdtm.pas"/>
<Caret Line="507" Column="16" TopLine="496"/>
</Position22>
<Position23>
<Filename Value="../../../lazarus/lcl/menus.pp"/>
<Caret Line="394" Column="74" TopLine="379"/>
<Filename Value="../../Units/MMLCore/client.pas"/>
<Caret Line="34" Column="7" TopLine="21"/>
</Position23>
<Position24>
<Filename Value="../../../lazarus/lcl/menus.pp"/>
<Caret Line="395" Column="51" TopLine="379"/>
<Filename Value="../../Units/MMLCore/client.pas"/>
<Caret Line="19" Column="24" TopLine="4"/>
</Position24>
<Position25>
<Filename Value="../../../lazarus/lcl/menus.pp"/>
<Caret Line="411" Column="62" TopLine="396"/>
<Filename Value="../../Units/MMLCore/client.pas"/>
<Caret Line="20" Column="27" TopLine="1"/>
</Position25>
<Position26>
<Filename Value="../../../lazarus/lcl/menus.pp"/>
<Caret Line="503" Column="62" TopLine="488"/>
<Filename Value="../../Units/MMLCore/bitmaps.pas"/>
<Caret Line="37" Column="16" TopLine="11"/>
</Position26>
<Position27>
<Filename Value="../../../lazarus/lcl/menus.pp"/>
<Caret Line="537" Column="74" TopLine="522"/>
<Filename Value="../../Units/MMLCore/bitmaps.pas"/>
<Caret Line="57" Column="16" TopLine="42"/>
</Position27>
<Position28>
<Filename Value="testunit.pas"/>
<Caret Line="27" Column="49" TopLine="4"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="15" Column="28" TopLine="1"/>
</Position28>
<Position29>
<Filename Value="testunit.pas"/>
<Caret Line="272" Column="1" TopLine="259"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="17" Column="9" TopLine="3"/>
</Position29>
<Position30>
<Filename Value="testunit.pas"/>
<Caret Line="269" Column="33" TopLine="254"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="30" Column="17" TopLine="9"/>
</Position30>
</JumpHistory>
</ProjectOptions>

View File

@ -8,7 +8,7 @@ uses
{$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, LResources, Window, files, MufasaTypes, Client, TestUnit, finder,
MMLThread, mmlpsthread, bitmaps, colour_conv, plugins;
MMLThread, mmlpsthread, bitmaps, colour_conv, plugins, DTM;
{$IFDEF WINDOWS}{$R project1.rc}{$ENDIF}

View File

@ -1,282 +1,280 @@
unit mmlpsthread;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, client, uPSComponent,uPSCompiler,uPSRuntime,stdCtrls, Plugins,uPSPreProcessor;
type
{ TMMLPSThread }
TMMLPSThread = class(TThread)
procedure PSScriptProcessUnknowDirective(Sender: TPSPreProcessor;
Parser: TPSPascalPreProcessorParser; const Active: Boolean;
const DirectiveName, DirectiveParam: string; var Continue: Boolean);
protected
PSScript : TPSScript;
DebugTo : TMemo;
PluginsToload : Array of integer;
procedure OnCompile(Sender: TPSScript);
procedure AfterExecute(Sender : TPSScript);
function RequireFile(Sender: TObject; const OriginFileName: String;
var FileName, OutPut: string): Boolean;
procedure OnCompImport(Sender: TObject; x: TPSPascalCompiler);
procedure OnExecImport(Sender: TObject; se: TPSExec; x: TPSRuntimeClassImporter);
procedure OutputMessages;
procedure OnThreadTerminate(Sender: TObject);
procedure Execute; override;
public
Client : TClient;
procedure SetPSScript(Script : string);
procedure SetDebug( Strings : TMemo );
constructor Create(CreateSuspended: Boolean);
destructor Destroy; override;
end;
implementation
uses
MufasaTypes,
{$ifdef mswindows}windows,{$endif}
uPSC_std, uPSC_controls,uPSC_classes,uPSC_graphics,uPSC_stdctrls,uPSC_forms,
uPSC_extctrls, //Compile-libs
uPSR_std, uPSR_controls,uPSR_classes,uPSR_graphics,uPSR_stdctrls,uPSR_forms,
uPSR_extctrls, //Runtime-libs
Graphics, //For Graphics types
math, //Maths!
lclintf; // for GetTickCount and others.
threadvar
CurrThread : TMMLPSThread;
{Some General PS Functions here}
procedure psWriteln(str : string);
begin
{$IFNDEF MSWINDOWS}
writeln(str);
{$ELSE}
if CurrThread.DebugTo <> nil then
CurrThread.DebugTo.lines.add(str);
{$ENDIF}
//Just overwriting itz.. soz.
end;
function ThreadSafeCall(ProcName: string; var V: TVariantArray): Variant;
var
i : integer;
begin;
Writeln('We have a length of: ' + inttostr(length(v)));
Try
Result := CurrThread.PSScript.Exec.RunProcPVar(v,CurrThread.PSScript.Exec.GetProc(Procname));
Except
Writeln('We has some errors :-(');
end;
end;
{
Note to Raymond: For PascalScript, Create it on the .Create,
Execute it on the .Execute, and don't forget to Destroy it on .Destroy.
Furthermore, all the wrappers can be in the unit "implementation" section.
Better still to create an .inc for it, otherwise this unit will become huge.
(You can even split up the .inc's in stuff like color, bitmap, etc. )
Also, don't add PS to this unit, but make a seperate unit for it.
Unit "MMLPSThread", perhaps?
See the TestUnit for use of this thread, it's pretty straightforward.
It may also be wise to turn the "Importing of wrappers" into an include as
well, it will really make the unit more straightforward to use and read.
}
constructor TMMLPSThread.Create(CreateSuspended : boolean);
begin
SetLength(PluginsToLoad,0);
Client := TClient.Create;
PSScript := TPSScript.Create(nil);
PSScript.UsePreProcessor:= True;
PSScript.OnNeedFile := @RequireFile;
PSScript.OnProcessUnknowDirective:=@PSScriptProcessUnknowDirective;
PSScript.OnCompile:= @OnCompile;
PSScript.OnCompImport:= @OnCompImport;
PSScript.OnExecImport:= @OnExecImport;
PSScript.OnAfterExecute:= @AfterExecute;
// Set some defines
{$I PSInc/psdefines.inc}
FreeOnTerminate := True;
Self.OnTerminate := @Self.OnThreadTerminate;
inherited Create(CreateSuspended);
end;
procedure TMMLPSThread.OnThreadTerminate(Sender: TObject);
begin
// Writeln('Terminating the thread');
end;
destructor TMMLPSThread.Destroy;
begin
SetLength(PluginsToLoad,0);
Client.Free;
PSScript.Free;
inherited;
end;
// include PS wrappers
{$I PSInc/Wrappers/other.inc}
{$I PSInc/Wrappers/bitmap.inc}
{$I PSInc/Wrappers/colour.inc}
{$I PSInc/Wrappers/math.inc}
{$I PSInc/Wrappers/mouse.inc}
procedure TMMLPSThread.PSScriptProcessUnknowDirective(Sender: TPSPreProcessor;
Parser: TPSPascalPreProcessorParser; const Active: Boolean;
const DirectiveName, DirectiveParam: string; var Continue: Boolean);
var
TempNum : integer;
I,II : integer;
begin
if DirectiveName= 'LOADDLL' then
if DirectiveParam <> '' then
begin;
TempNum := PluginsGlob.LoadPlugin(DirectiveParam);
if TempNum < 0 then
Writeln(Format('Your DLL %s has not been found',[DirectiveParam]))
else
begin;
for i := High(PluginsToLoad) downto 0 do
if PluginsToLoad[i] = TempNum then
Exit;
SetLength(PluginsToLoad,Length(PluginsToLoad)+1);
PluginsToLoad[High(PluginsToLoad)] := TempNum;
end;
end;
Continue:= True;
end;
procedure TMMLPSThread.OnCompile(Sender: TPSScript);
var
i,ii : integer;
begin
for i := high(PluginsToLoad) downto 0 do
for ii := 0 to PluginsGlob.MPlugins[PluginsToLoad[i]].MethodLen - 1 do
PSScript.AddFunctionEx(PluginsGlob.MPlugins[PluginsToLoad[i]].Methods[i].FuncPtr,
PluginsGlob.MPlugins[PluginsToLoad[i]].Methods[i].FuncStr, cdStdCall);
// Here we add all the functions to the engine.
{$I PSInc/pscompile.inc}
end;
procedure TMMLPSThread.AfterExecute(Sender: TPSScript);
begin
//Here we add all the Script-freeing-leftovers (like BMParray etc)
// ^ This will all be done with Client.Destroy;
end;
function TMMLPSThread.RequireFile(Sender: TObject;
const OriginFileName: String; var FileName, OutPut: string): Boolean;
begin
end;
procedure TMMLPSThread.OnCompImport(Sender: TObject; x: TPSPascalCompiler);
begin
SIRegister_Std(x);
SIRegister_Controls(x);
SIRegister_Classes(x, true);
SIRegister_Graphics(x, true);
SIRegister_stdctrls(x);
SIRegister_Forms(x);
SIRegister_ExtCtrls(x);
end;
procedure TMMLPSThread.OnExecImport(Sender: TObject; se: TPSExec;
x: TPSRuntimeClassImporter);
begin
RIRegister_Std(x);
RIRegister_Classes(x, True);
RIRegister_Controls(x);
RIRegister_Graphics(x, True);
RIRegister_stdctrls(x);
RIRegister_Forms(x);
RIRegister_ExtCtrls(x);
end;
procedure TMMLPSThread.OutputMessages;
var
l: Longint;
b: Boolean;
begin
b := False;
for l := 0 to PSScript.CompilerMessageCount - 1 do
begin
psWriteln(PSScript.CompilerErrorToStr(l));
if (not b) and (PSScript.CompilerMessages[l] is TIFPSPascalCompilerError) then
begin
b := True;
// FormMain.CurrSynEdit.SelStart := PSScript.CompilerMessages[l].Pos;
end;
end;
end;
procedure TMMLPSThread.Execute;
var
time, i, ii: Integer;
begin;
CurrThread := Self;
time := lclintf.GetTickCount;
try
if PSScript.Compile then
begin
OutputMessages;
psWriteln('Compiled succesfully in ' + IntToStr(GetTickCount - time) + ' ms.');
// if not (ScriptState = SCompiling) then
if not PSScript.Execute then
begin
// FormMain.CurrSynEdit.SelStart := Script.PSScript.ExecErrorPosition;
psWriteln(PSScript.ExecErrorToString +' at '+Inttostr(PSScript.ExecErrorProcNo)+'.'
+Inttostr(PSScript.ExecErrorByteCodePosition));
end else psWriteln('Succesfully executed');
end else
begin
OutputMessages;
psWriteln('Compiling failed');
end;
except
on E : Exception do
psWriteln('Error: ' + E.Message);
end;
end;
procedure TMMLPSThread.SetPSScript(Script: string);
begin
PSScript.Script.Text:= Script;
end;
procedure TMMLPSThread.SetDebug(Strings: TMemo);
begin
DebugTo := Strings;
end;
{ Include stuff here? }
//{$I inc/colors.inc}
//{$I inc/bitmaps.inc}
end.
unit mmlpsthread;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, client, uPSComponent,uPSCompiler,uPSRuntime,stdCtrls, Plugins,uPSPreProcessor;
type
{ TMMLPSThread }
TMMLPSThread = class(TThread)
procedure PSScriptProcessUnknowDirective(Sender: TPSPreProcessor;
Parser: TPSPascalPreProcessorParser; const Active: Boolean;
const DirectiveName, DirectiveParam: string; var Continue: Boolean);
protected
PSScript : TPSScript;
DebugTo : TMemo;
PluginsToload : Array of integer;
procedure OnCompile(Sender: TPSScript);
procedure AfterExecute(Sender : TPSScript);
function RequireFile(Sender: TObject; const OriginFileName: String;
var FileName, OutPut: string): Boolean;
procedure OnCompImport(Sender: TObject; x: TPSPascalCompiler);
procedure OnExecImport(Sender: TObject; se: TPSExec; x: TPSRuntimeClassImporter);
procedure OutputMessages;
procedure OnThreadTerminate(Sender: TObject);
procedure Execute; override;
public
Client : TClient;
procedure SetPSScript(Script : string);
procedure SetDebug( Strings : TMemo );
constructor Create(CreateSuspended: Boolean);
destructor Destroy; override;
end;
implementation
uses
MufasaTypes,
{$ifdef mswindows}windows,{$endif}
uPSC_std, uPSC_controls,uPSC_classes,uPSC_graphics,uPSC_stdctrls,uPSC_forms,
uPSC_extctrls, //Compile-libs
uPSR_std, uPSR_controls,uPSR_classes,uPSR_graphics,uPSR_stdctrls,uPSR_forms,
uPSR_extctrls, //Runtime-libs
Graphics, //For Graphics types
math, //Maths!
lclintf; // for GetTickCount and others.
threadvar
CurrThread : TMMLPSThread;
{Some General PS Functions here}
procedure psWriteln(str : string);
begin
{$IFNDEF MSWINDOWS}
writeln(str);
{$ELSE}
if CurrThread.DebugTo <> nil then
CurrThread.DebugTo.lines.add(str);
{$ENDIF}
end;
function ThreadSafeCall(ProcName: string; var V: TVariantArray): Variant;
var
i : integer;
begin;
Writeln('We have a length of: ' + inttostr(length(v)));
Try
Result := CurrThread.PSScript.Exec.RunProcPVar(v,CurrThread.PSScript.Exec.GetProc(Procname));
Except
Writeln('We has some errors :-(');
end;
end;
{
Note to Raymond: For PascalScript, Create it on the .Create,
Execute it on the .Execute, and don't forget to Destroy it on .Destroy.
Furthermore, all the wrappers can be in the unit "implementation" section.
Better still to create an .inc for it, otherwise this unit will become huge.
(You can even split up the .inc's in stuff like color, bitmap, etc. )
Also, don't add PS to this unit, but make a seperate unit for it.
Unit "MMLPSThread", perhaps?
See the TestUnit for use of this thread, it's pretty straightforward.
It may also be wise to turn the "Importing of wrappers" into an include as
well, it will really make the unit more straightforward to use and read.
}
constructor TMMLPSThread.Create(CreateSuspended : boolean);
begin
SetLength(PluginsToLoad,0);
Client := TClient.Create;
PSScript := TPSScript.Create(nil);
PSScript.UsePreProcessor:= True;
PSScript.OnNeedFile := @RequireFile;
PSScript.OnProcessUnknowDirective:=@PSScriptProcessUnknowDirective;
PSScript.OnCompile:= @OnCompile;
PSScript.OnCompImport:= @OnCompImport;
PSScript.OnExecImport:= @OnExecImport;
PSScript.OnAfterExecute:= @AfterExecute;
// Set some defines
{$I PSInc/psdefines.inc}
FreeOnTerminate := True;
Self.OnTerminate := @Self.OnThreadTerminate;
inherited Create(CreateSuspended);
end;
procedure TMMLPSThread.OnThreadTerminate(Sender: TObject);
begin
// Writeln('Terminating the thread');
end;
destructor TMMLPSThread.Destroy;
begin
SetLength(PluginsToLoad,0);
Client.Free;
PSScript.Free;
inherited;
end;
// include PS wrappers
{$I PSInc/Wrappers/other.inc}
{$I PSInc/Wrappers/bitmap.inc}
{$I PSInc/Wrappers/colour.inc}
{$I PSInc/Wrappers/math.inc}
{$I PSInc/Wrappers/mouse.inc}
procedure TMMLPSThread.PSScriptProcessUnknowDirective(Sender: TPSPreProcessor;
Parser: TPSPascalPreProcessorParser; const Active: Boolean;
const DirectiveName, DirectiveParam: string; var Continue: Boolean);
var
TempNum : integer;
I,II : integer;
begin
if DirectiveName= 'LOADDLL' then
if DirectiveParam <> '' then
begin;
TempNum := PluginsGlob.LoadPlugin(DirectiveParam);
if TempNum < 0 then
Writeln(Format('Your DLL %s has not been found',[DirectiveParam]))
else
begin;
for i := High(PluginsToLoad) downto 0 do
if PluginsToLoad[i] = TempNum then
Exit;
SetLength(PluginsToLoad,Length(PluginsToLoad)+1);
PluginsToLoad[High(PluginsToLoad)] := TempNum;
end;
end;
Continue:= True;
end;
procedure TMMLPSThread.OnCompile(Sender: TPSScript);
var
i,ii : integer;
begin
for i := high(PluginsToLoad) downto 0 do
for ii := 0 to PluginsGlob.MPlugins[PluginsToLoad[i]].MethodLen - 1 do
PSScript.AddFunctionEx(PluginsGlob.MPlugins[PluginsToLoad[i]].Methods[i].FuncPtr,
PluginsGlob.MPlugins[PluginsToLoad[i]].Methods[i].FuncStr, cdStdCall);
// Here we add all the functions to the engine.
{$I PSInc/pscompile.inc}
end;
procedure TMMLPSThread.AfterExecute(Sender: TPSScript);
begin
//Here we add all the Script-freeing-leftovers (like BMParray etc)
// ^ This will all be done with Client.Destroy;
end;
function TMMLPSThread.RequireFile(Sender: TObject;
const OriginFileName: String; var FileName, OutPut: string): Boolean;
begin
end;
procedure TMMLPSThread.OnCompImport(Sender: TObject; x: TPSPascalCompiler);
begin
SIRegister_Std(x);
SIRegister_Controls(x);
SIRegister_Classes(x, true);
SIRegister_Graphics(x, true);
SIRegister_stdctrls(x);
SIRegister_Forms(x);
SIRegister_ExtCtrls(x);
end;
procedure TMMLPSThread.OnExecImport(Sender: TObject; se: TPSExec;
x: TPSRuntimeClassImporter);
begin
RIRegister_Std(x);
RIRegister_Classes(x, True);
RIRegister_Controls(x);
RIRegister_Graphics(x, True);
RIRegister_stdctrls(x);
RIRegister_Forms(x);
RIRegister_ExtCtrls(x);
end;
procedure TMMLPSThread.OutputMessages;
var
l: Longint;
b: Boolean;
begin
b := False;
for l := 0 to PSScript.CompilerMessageCount - 1 do
begin
psWriteln(PSScript.CompilerErrorToStr(l));
if (not b) and (PSScript.CompilerMessages[l] is TIFPSPascalCompilerError) then
begin
b := True;
// FormMain.CurrSynEdit.SelStart := PSScript.CompilerMessages[l].Pos;
end;
end;
end;
procedure TMMLPSThread.Execute;
var
time, i, ii: Integer;
begin;
CurrThread := Self;
time := lclintf.GetTickCount;
try
if PSScript.Compile then
begin
OutputMessages;
psWriteln('Compiled succesfully in ' + IntToStr(GetTickCount - time) + ' ms.');
// if not (ScriptState = SCompiling) then
if not PSScript.Execute then
begin
// FormMain.CurrSynEdit.SelStart := Script.PSScript.ExecErrorPosition;
psWriteln(PSScript.ExecErrorToString +' at '+Inttostr(PSScript.ExecErrorProcNo)+'.'
+Inttostr(PSScript.ExecErrorByteCodePosition));
end else psWriteln('Succesfully executed');
end else
begin
OutputMessages;
psWriteln('Compiling failed');
end;
except
on E : Exception do
psWriteln('Error: ' + E.Message);
end;
end;
procedure TMMLPSThread.SetPSScript(Script: string);
begin
PSScript.Script.Text:= Script;
end;
procedure TMMLPSThread.SetDebug(Strings: TMemo);
begin
DebugTo := Strings;
end;
{ Include stuff here? }
//{$I inc/colors.inc}
//{$I inc/bitmaps.inc}
end.