Add TimeStampFunctionality

This commit is contained in:
Merlijn Wajer 2010-03-20 00:12:43 +01:00
parent d3801f0a45
commit 30093069c5
4 changed files with 66 additions and 1 deletions

View File

@ -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.

View File

@ -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

View File

@ -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;');

View File

@ -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;