1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-12-24 00:08:52 -05:00

Writeln() now goes to debug box on Linux too. ;-)

git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@191 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
Wizzup? 2009-11-04 22:41:06 +00:00
parent eeb04eecfb
commit 366764d910
3 changed files with 78 additions and 24 deletions

View File

@ -95,6 +95,7 @@ type
ScriptPanel: TPanel; ScriptPanel: TPanel;
TabPopup: TPopupMenu; TabPopup: TPopupMenu;
TB_SaveAll: TToolButton; TB_SaveAll: TToolButton;
DebugTimer: TTimer;
TrayDivider: TMenuItem; TrayDivider: TMenuItem;
TrayPlay: TMenuItem; TrayPlay: TMenuItem;
TrayStop: TMenuItem; TrayStop: TMenuItem;
@ -187,12 +188,15 @@ type
State: TDragState; var Accept: Boolean); State: TDragState; var Accept: Boolean);
procedure PageControl1MouseDown(Sender: TObject; Button: TMouseButton; procedure PageControl1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer); Shift: TShiftState; X, Y: Integer);
procedure ProcessDebugStream(Sender: TObject);
private private
PopupTab : integer; PopupTab : integer;
SearchStart : TPoint; SearchStart : TPoint;
function GetScriptState: TScriptState; function GetScriptState: TScriptState;
procedure SetScriptState(const State: TScriptState); procedure SetScriptState(const State: TScriptState);
public public
DebugStream: String;
CurrScript : TScriptFrame; //The current scriptframe CurrScript : TScriptFrame; //The current scriptframe
CurrTab : TMufasaTab; //The current TMufasaTab CurrTab : TMufasaTab; //The current TMufasaTab
Tabs : TList; Tabs : TList;
@ -220,9 +224,9 @@ type
procedure DoSearch(Next : boolean); procedure DoSearch(Next : boolean);
procedure RefreshTab;//Refreshes all the form items that depend on the Script (Panels, title etc.) procedure RefreshTab;//Refreshes all the form items that depend on the Script (Panels, title etc.)
end; end;
{$ifdef mswindows}
procedure Writeln( S : String); procedure formWriteln( S : String);
{$endif}
const const
WindowTitle = 'Mufasa v2 - %s';//Title, where %s = the place of the filename. WindowTitle = 'Mufasa v2 - %s';//Title, where %s = the place of the filename.
Panel_State = 0; Panel_State = 0;
@ -237,14 +241,50 @@ var
implementation implementation
uses uses
lclintf,plugins; lclintf,plugins,
syncobjs; // for the critical sections
{$ifdef mswindows} //{$ifdef mswindows}
procedure Writeln( S : String);
begin; var
Form1.Memo1.Lines.Add(s); DebugCriticalSection: syncobjs.TCriticalSection;
procedure TForm1.ProcessDebugStream(Sender: TObject);
begin
if length(DebugStream) = 0 then
Exit;
// cut off 1 newline char
DebugCriticalSection.Enter;
try
setlength(DebugStream, length(DebugStream) - 1);
Memo1.Lines.Add(DebugStream);
SetLength(DebugStream, 0);
finally
DebugCriticalSection.Leave;
end; end;
{$ENDIF} end;
procedure formWriteln( S : String);
begin
s := s + #10;
DebugCriticalSection.Enter;
try
Form1.DebugStream:= Form1.DebugStream + s;
finally
DebugCriticalSection.Leave;
end;
writeln('formWriteln: ' + s);
//Form1.Memo1.Lines.Add(s);
end;
//{$ENDIF}
procedure TForm1.RunScript; procedure TForm1.RunScript;
begin begin
@ -265,7 +305,8 @@ begin
CurrentSyncInfo.SyncMethod:= @Self.SafeCallThread; CurrentSyncInfo.SyncMethod:= @Self.SafeCallThread;
ScriptThread := TMMLPSThread.Create(True,@CurrentSyncInfo); ScriptThread := TMMLPSThread.Create(True,@CurrentSyncInfo);
ScriptThread.SetPSScript(CurrScript.SynEdit.Lines.Text); ScriptThread.SetPSScript(CurrScript.SynEdit.Lines.Text);
ScriptThread.SetDebug(Self.Memo1); // ScriptThread.SetDebug(Self.Memo1);
ScriptThread.SetDebug(@formWriteln);
ScriptThread.OnError:=@ErrorThread; ScriptThread.OnError:=@ErrorThread;
if ScriptFile <> '' then if ScriptFile <> '' then
ScriptThread.SetPaths( ExtractFileDir(ScriptFile) + DS,IncludeTrailingPathDelimiter(ExpandFileName(MainDir +DS + '..' + DS + '..' + ds))) ScriptThread.SetPaths( ExtractFileDir(ScriptFile) + DS,IncludeTrailingPathDelimiter(ExpandFileName(MainDir +DS + '..' + DS + '..' + ds)))
@ -635,6 +676,10 @@ begin
MainDir:= ExtractFileDir(Application.ExeName); MainDir:= ExtractFileDir(Application.ExeName);
PluginsGlob := TMPlugins.Create; PluginsGlob := TMPlugins.Create;
PluginsGlob.PluginDirs.Add(ExpandFileName(MainDir + DS + '..' + DS + '..'+ DS + 'Plugins'+ DS)); PluginsGlob.PluginDirs.Add(ExpandFileName(MainDir + DS + '..' + DS + '..'+ DS + 'Plugins'+ DS));
{ For writeln }
SetLength(DebugStream, 0);
DebugCriticalSection := syncobjs.TCriticalSection.Create;
end; end;
procedure TForm1.FormDestroy(Sender: TObject); procedure TForm1.FormDestroy(Sender: TObject);
@ -648,6 +693,9 @@ begin
Picker.Free; Picker.Free;
Window.Free; Window.Free;
PluginsGlob.Free; PluginsGlob.Free;
SetLength(DebugStream, 0);
DebugCriticalSection.Free;
end; end;
procedure TForm1.FormShortCuts(var Msg: TLMKey; var Handled: Boolean); procedure TForm1.FormShortCuts(var Msg: TLMKey; var Handled: Boolean);

View File

@ -60,7 +60,7 @@ begin;
result := TForm.Create(nil); result := TForm.Create(nil);
end; end;
function CreateButton(Owner : TComponent) : TButton; function CreateButton(Owner : TComponent) : TButton;
begin; begin
Result := TButton.Create(Owner); Result := TButton.Create(Owner);
end; end;

View File

@ -40,6 +40,9 @@ type
OldThread : TThread; OldThread : TThread;
PSScript : TPSScript; PSScript : TPSScript;
end; end;
TWritelnProc = procedure(s: string);
PSyncInfo = ^TSyncInfo; PSyncInfo = ^TSyncInfo;
TErrorType = (errRuntime,errCompile); TErrorType = (errRuntime,errCompile);
TOnError = procedure (ErrorAtLine,ErrorPosition : integer; ErrorStr : string; ErrorType : TErrorType) of object; TOnError = procedure (ErrorAtLine,ErrorPosition : integer; ErrorStr : string; ErrorType : TErrorType) of object;
@ -53,7 +56,8 @@ type
private private
ScriptPath, AppPath : string; ScriptPath, AppPath : string;
protected protected
DebugTo : TMemo; //DebugTo : TMemo;
DebugTo: TWritelnProc;
PluginsToload : Array of integer; PluginsToload : Array of integer;
FOnError : TOnError; FOnError : TOnError;
procedure OnCompile(Sender: TPSScript); procedure OnCompile(Sender: TPSScript);
@ -70,7 +74,7 @@ type
SyncInfo : PSyncInfo; //We need this for callthreadsafe SyncInfo : PSyncInfo; //We need this for callthreadsafe
property OnError : TOnError read FOnError write FOnError; property OnError : TOnError read FOnError write FOnError;
procedure SetPSScript(Script : string); procedure SetPSScript(Script : string);
procedure SetDebug( Strings : TMemo ); procedure SetDebug( writelnProc : TWritelnProc );
procedure SetPaths(ScriptP,AppP : string); procedure SetPaths(ScriptP,AppP : string);
constructor Create(CreateSuspended: Boolean; TheSyncInfo : PSyncInfo); constructor Create(CreateSuspended: Boolean; TheSyncInfo : PSyncInfo);
destructor Destroy; override; destructor Destroy; override;
@ -95,19 +99,21 @@ uses
{Some General PS Functions here} {Some General PS Functions here}
procedure psWriteln(str : string); procedure psWriteln(str : string);
{$IFDEF WINDOWS} //{$IFDEF WINDOWS}
begin begin
if CurrThread.DebugTo <> nil then if Assigned(CurrThread.DebugTo) then
CurrThread.DebugTo(str);
{if CurrThread.DebugTo <> nil then
begin; begin;
CurrThread.DebugTo.lines.add(str); CurrThread.DebugTo.lines.add(str);
CurrThread.DebugTo.Refresh; CurrThread.DebugTo.Refresh;
end; }
end; end;
end; //{$ELSE}
{$ELSE} //begin
begin //writeln(str);
writeln(str); //end;
end; //{$ENDIF}
{$ENDIF}
function ThreadSafeCall(ProcName: string; var V: TVariantArray): Variant; function ThreadSafeCall(ProcName: string; var V: TVariantArray): Variant;
begin; begin;
@ -340,9 +346,9 @@ begin
PSScript.Script.Text:= Script; PSScript.Script.Text:= Script;
end; end;
procedure TMMLPSThread.SetDebug(Strings: TMemo); procedure TMMLPSThread.SetDebug(writelnProc: TWritelnProc);
begin begin
DebugTo := Strings; DebugTo := writelnProc;
end; end;
procedure TMMLPSThread.SetPaths(ScriptP, AppP: string); procedure TMMLPSThread.SetPaths(ScriptP, AppP: string);