2010-03-15 18:42:39 -04:00
|
|
|
unit virtualextension;
|
|
|
|
|
|
|
|
{$mode objfpc}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
Classes, SysUtils;
|
|
|
|
|
|
|
|
type
|
2010-03-22 17:21:08 -04:00
|
|
|
{ TVirtualSimbaExtension }
|
|
|
|
|
2010-03-15 18:42:39 -04:00
|
|
|
TVirtualSimbaExtension = class(TObject)
|
2010-03-22 17:21:08 -04:00
|
|
|
protected
|
|
|
|
FName: String;
|
|
|
|
FVersion : string;
|
|
|
|
FFilename : string;
|
|
|
|
FEnabled : boolean;
|
|
|
|
procedure SetEnabled(bool : boolean); virtual;
|
2010-03-15 18:42:39 -04:00
|
|
|
public
|
2010-03-22 17:21:08 -04:00
|
|
|
OnChange : TNotifyEvent;
|
2010-03-15 18:42:39 -04:00
|
|
|
{ Must be implemented }
|
|
|
|
function HookExists(HookName: String): Boolean; virtual; abstract;
|
|
|
|
|
|
|
|
{ No Custom Arguments just yet... }
|
2010-03-22 17:21:08 -04:00
|
|
|
function ExecuteHook(HookName: String; fArgs: Array of Variant; out OutVariant : variant): Integer; virtual; abstract;
|
2010-03-15 18:42:39 -04:00
|
|
|
|
2010-03-22 17:21:08 -04:00
|
|
|
function GetName : string;
|
|
|
|
function GetVersion : String;
|
|
|
|
property Filename : string read FFilename write FFilename;
|
|
|
|
property Enabled : boolean read FEnabled write SetEnabled;
|
2010-03-15 18:42:39 -04:00
|
|
|
end;
|
|
|
|
|
2010-03-18 19:31:39 -04:00
|
|
|
|
|
|
|
{ Each hook has a HookName which the extension uses to identify the hook.
|
|
|
|
Additionally, variables are exported. Currently we will use an Array of Variant.
|
|
|
|
Therefore, we will have to specify what amount Arguments we will pass.
|
|
|
|
( So it is not type safe... Not like Variants are type safe... )
|
|
|
|
}
|
|
|
|
type TEventHook = record
|
|
|
|
HookName: String;
|
|
|
|
ArgumentCount: Integer;
|
|
|
|
end;
|
|
|
|
|
2010-03-22 17:21:08 -04:00
|
|
|
const
|
|
|
|
SExt_ok = 0;
|
|
|
|
SExt_error = 1;
|
2010-03-18 19:31:39 -04:00
|
|
|
EventHooks: Array [0..7] of TEventHook =
|
|
|
|
( (HookName : 'onScriptCompile' ; ArgumentCount : 1),
|
|
|
|
(HookName : 'onScriptStart' ; ArgumentCount : 1),
|
|
|
|
(HookName : 'onScriptPause' ; ArgumentCount : 1),
|
|
|
|
(HookName : 'onScriptStop' ; ArgumentCount : 1),
|
|
|
|
(HookName : 'onColourPick' ; ArgumentCount : 3),
|
|
|
|
(HookName : 'onOpenFile' ; ArgumentCount : 1),
|
|
|
|
(HookName : 'onOpenSocket' ; ArgumentCount : 1),
|
|
|
|
(HookName : 'onWriteFile' ; ArgumentCount : 1));
|
|
|
|
|
2010-03-15 18:42:39 -04:00
|
|
|
implementation
|
|
|
|
|
2010-03-22 17:21:08 -04:00
|
|
|
{ TVirtualSimbaExtension }
|
|
|
|
|
|
|
|
procedure TVirtualSimbaExtension.SetEnabled(bool: boolean);
|
|
|
|
begin
|
|
|
|
if assigned(OnChange) then
|
|
|
|
OnChange(self);
|
|
|
|
FEnabled:= bool;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TVirtualSimbaExtension.GetName: string;
|
|
|
|
var
|
|
|
|
OutPut : Variant;
|
|
|
|
begin
|
|
|
|
Result := '';
|
|
|
|
if FName <> '' then
|
|
|
|
Result := FName
|
|
|
|
else if self.HookExists('GetName') then
|
|
|
|
begin;
|
|
|
|
if ExecuteHook('GetName',[],OutPut) <> SExt_ok then
|
|
|
|
FName := ''
|
|
|
|
else
|
|
|
|
FName := OutPut;
|
|
|
|
result := FName;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TVirtualSimbaExtension.GetVersion: String;
|
|
|
|
var
|
|
|
|
OutPut : Variant;
|
|
|
|
begin
|
|
|
|
Result := '';
|
|
|
|
if FVersion <> '' then
|
|
|
|
Result := FVersion
|
|
|
|
else if self.HookExists('GetVersion') then
|
|
|
|
begin;
|
|
|
|
if ExecuteHook('GetVersion',[],OutPut) <> SExt_ok then
|
|
|
|
FVersion := ''
|
|
|
|
else
|
|
|
|
FVersion := Output;
|
|
|
|
result := FVersion;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2010-03-15 18:42:39 -04:00
|
|
|
end.
|
|
|
|
|