From 30093069c5d7aae45dc6d3adc4ac4774b4579def Mon Sep 17 00:00:00 2001 From: Merlijn Wajer Date: Sat, 20 Mar 2010 00:12:43 +0100 Subject: [PATCH] Add TimeStampFunctionality --- Projects/SAMufasaGUI/scriptproperties.pas | 53 ++++++++++++++++++++++ Units/MMLAddon/PSInc/Wrappers/other.inc | 5 ++ Units/MMLAddon/PSInc/psexportedmethods.inc | 1 + Units/MMLAddon/mmlpsthread.pas | 8 +++- 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 Projects/SAMufasaGUI/scriptproperties.pas diff --git a/Projects/SAMufasaGUI/scriptproperties.pas b/Projects/SAMufasaGUI/scriptproperties.pas new file mode 100644 index 0000000..9acadbe --- /dev/null +++ b/Projects/SAMufasaGUI/scriptproperties.pas @@ -0,0 +1,53 @@ +unit scriptproperties; + +{$mode objfpc} + +interface + +uses + Classes, SysUtils; +type + TScriptProperties = class(TObject) + public + constructor Create; + destructor Destroy; override; + function SetProp(Name: String; Value: String): Boolean; + public + WriteTimeStamp: Boolean; + end; + +implementation + +constructor TScriptProperties.Create; +begin + inherited; + + WriteTimeStamp := False; + + { set default values } +end; + +destructor TScriptProperties.Destroy; +begin + inherited Destroy; +end; + +function TScriptProperties.SetProp(Name: String; Value: String): Boolean; + +begin + { + Fucking hell. We can't use a String in case statement, and we cannot define + hash maps as constants, and we also cannot use variables in case statements. + } + Name := LowerCase(Name); + if Name = 'writetimestamp' then + begin + WriteTimeStamp := LowerCase(Value) = 'true'; + Exit(True); + end; + {more if bla } + Result := False; +end; + +end. + diff --git a/Units/MMLAddon/PSInc/Wrappers/other.inc b/Units/MMLAddon/PSInc/Wrappers/other.inc index ff767a2..f6d41e3 100644 --- a/Units/MMLAddon/PSInc/Wrappers/other.inc +++ b/Units/MMLAddon/PSInc/Wrappers/other.inc @@ -21,6 +21,11 @@ Other.inc for the Mufasa Macro Library } +function psSetScriptProp(Name: String; Value: String): boolean; +begin + Exit(CurrThread.Prop.SetProp(Name, Value)); +end; + procedure psWait(t: Integer); extdecl; {$ifdef MSWINDOWS} begin diff --git a/Units/MMLAddon/PSInc/psexportedmethods.inc b/Units/MMLAddon/PSInc/psexportedmethods.inc index f374023..b4dca9b 100644 --- a/Units/MMLAddon/PSInc/psexportedmethods.inc +++ b/Units/MMLAddon/PSInc/psexportedmethods.inc @@ -130,6 +130,7 @@ AddFunction(@ps_Random,'function Random(Int: integer): integer;'); AddFunction(@ClearDebug,'procedure ClearDebug;'); AddFunction(@PlaySound,'procedure PlaySound( Sound : string);'); AddFunction(@StopSound,'Procedure StopSound;'); +AddFunction(@psSetScriptProp, 'function psSetScriptProp(Name: String; Value: String): boolean;'); diff --git a/Units/MMLAddon/mmlpsthread.pas b/Units/MMLAddon/mmlpsthread.pas index cdef7a1..b52fe29 100644 --- a/Units/MMLAddon/mmlpsthread.pas +++ b/Units/MMLAddon/mmlpsthread.pas @@ -32,7 +32,7 @@ interface uses Classes, SysUtils, client, uPSComponent,uPSCompiler, uPSRuntime,stdCtrls, uPSPreProcessor,MufasaTypes,MufasaBase, web, - bitmaps, plugins, libloader, dynlibs,internets; + bitmaps, plugins, libloader, dynlibs,internets,scriptproperties; type @@ -82,6 +82,7 @@ type DebugImg : TDbgImgInfo; ExportedMethods : TExpMethodArr; Includes : TStringList; + Prop: TScriptProperties; procedure LoadPlugin(plugidx: integer); virtual; abstract; public @@ -209,6 +210,8 @@ uses {Some General PS Functions here} procedure psWriteln(str : string); extdecl; begin + if CurrThread.Prop.WriteTimeStamp then + str := format('[%s]: %s', [TimeToStr(TimeStampToDateTime(MSecsToTimeStamp(GetTickCount - CurrThread.StartTime))), str]); if Assigned(CurrThread.DebugTo) then CurrThread.DebugTo(str) else @@ -277,6 +280,9 @@ begin OnError:= nil; Includes := TStringList.Create; Includes.CaseSensitive:= {$ifdef linux}true{$else}false{$endif}; + + Prop := TScriptProperties.Create; + inherited Create(CreateSuspended); end;