mirror of
https://github.com/moparisthebest/Simba
synced 2024-11-22 09:12:19 -05:00
Merged oop changes to plugin loading into trunk. Also removed some missing paths from the project file and set laz to build in a build/$(TargetOS) folder instead of building where the sorces are... its cleaner imo. In the IOManager branch I coded for passing the plugin path down to the mufasa library so it can load components (e.g. eios and a system i'm planning for multiple script components). I'll probably be quite for a while as I work on SMART.
git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@441 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
parent
5d4ee2baa1
commit
104b410220
@ -10,7 +10,7 @@
|
||||
<TargetFileExt Value=""/>
|
||||
<Title Value="Simba"/>
|
||||
<UseXPManifest Value="True"/>
|
||||
<ActiveEditorIndexAtStart Value="0"/>
|
||||
<ActiveEditorIndexAtStart Value="11"/>
|
||||
</General>
|
||||
<VersionInfo>
|
||||
<ProjectVersion Value=""/>
|
||||
@ -140,8 +140,8 @@
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
<UnitName Value="TestUnit"/>
|
||||
<ComponentState Value="1"/>
|
||||
<CursorPos X="14" Y="1305"/>
|
||||
<TopLine Value="1288"/>
|
||||
<CursorPos X="74" Y="536"/>
|
||||
<TopLine Value="515"/>
|
||||
<EditorIndex Value="11"/>
|
||||
<UsageCount Value="202"/>
|
||||
<Loaded Value="True"/>
|
||||
@ -190,8 +190,8 @@
|
||||
<Filename Value="../../Units/MMLCore/client.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="Client"/>
|
||||
<CursorPos X="1" Y="64"/>
|
||||
<TopLine Value="47"/>
|
||||
<CursorPos X="46" Y="60"/>
|
||||
<TopLine Value="43"/>
|
||||
<EditorIndex Value="0"/>
|
||||
<UsageCount Value="201"/>
|
||||
<Loaded Value="True"/>
|
||||
@ -269,8 +269,8 @@
|
||||
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="mmlpsthread"/>
|
||||
<CursorPos X="27" Y="328"/>
|
||||
<TopLine Value="228"/>
|
||||
<CursorPos X="95" Y="114"/>
|
||||
<TopLine Value="97"/>
|
||||
<EditorIndex Value="1"/>
|
||||
<UsageCount Value="202"/>
|
||||
<Loaded Value="True"/>
|
||||
@ -2057,123 +2057,123 @@
|
||||
<JumpHistory Count="30" HistoryIndex="29">
|
||||
<Position1>
|
||||
<Filename Value="../../Units/MMLAddon/plugins.pas"/>
|
||||
<Caret Line="106" Column="29" TopLine="82"/>
|
||||
<Caret Line="174" Column="24" TopLine="155"/>
|
||||
</Position1>
|
||||
<Position2>
|
||||
<Filename Value="../../Units/MMLAddon/plugins.pas"/>
|
||||
<Caret Line="102" Column="35" TopLine="85"/>
|
||||
<Filename Value="../../Units/MMLCore/iomanager.pas"/>
|
||||
<Caret Line="486" Column="36" TopLine="461"/>
|
||||
</Position2>
|
||||
<Position3>
|
||||
<Filename Value="../../Units/MMLAddon/plugins.pas"/>
|
||||
<Caret Line="106" Column="19" TopLine="89"/>
|
||||
<Caret Line="181" Column="48" TopLine="156"/>
|
||||
</Position3>
|
||||
<Position4>
|
||||
<Filename Value="../../Units/MMLAddon/plugins.pas"/>
|
||||
<Caret Line="229" Column="26" TopLine="199"/>
|
||||
<Filename Value="../../Units/MMLCore/iomanager.pas"/>
|
||||
<Caret Line="179" Column="68" TopLine="166"/>
|
||||
</Position4>
|
||||
<Position5>
|
||||
<Filename Value="../../Units/MMLAddon/plugins.pas"/>
|
||||
<Caret Line="174" Column="24" TopLine="155"/>
|
||||
<Filename Value="../../Units/MMLCore/iomanager.pas"/>
|
||||
<Caret Line="157" Column="30" TopLine="141"/>
|
||||
</Position5>
|
||||
<Position6>
|
||||
<Filename Value="../../Units/MMLCore/iomanager.pas"/>
|
||||
<Caret Line="486" Column="36" TopLine="461"/>
|
||||
<Caret Line="178" Column="47" TopLine="7"/>
|
||||
</Position6>
|
||||
<Position7>
|
||||
<Filename Value="../../Units/MMLAddon/plugins.pas"/>
|
||||
<Caret Line="181" Column="48" TopLine="156"/>
|
||||
<Filename Value="../../Units/MMLCore/iomanager.pas"/>
|
||||
<Caret Line="29" Column="90" TopLine="1"/>
|
||||
</Position7>
|
||||
<Position8>
|
||||
<Filename Value="../../Units/MMLCore/iomanager.pas"/>
|
||||
<Caret Line="179" Column="68" TopLine="166"/>
|
||||
<Filename Value="testunit.pas"/>
|
||||
<Caret Line="1792" Column="84" TopLine="1789"/>
|
||||
</Position8>
|
||||
<Position9>
|
||||
<Filename Value="../../Units/MMLCore/iomanager.pas"/>
|
||||
<Caret Line="157" Column="30" TopLine="141"/>
|
||||
<Caret Line="480" Column="16" TopLine="465"/>
|
||||
</Position9>
|
||||
<Position10>
|
||||
<Filename Value="../../Units/MMLCore/iomanager.pas"/>
|
||||
<Caret Line="178" Column="47" TopLine="7"/>
|
||||
<Caret Line="481" Column="19" TopLine="464"/>
|
||||
</Position10>
|
||||
<Position11>
|
||||
<Filename Value="../../Units/MMLCore/iomanager.pas"/>
|
||||
<Caret Line="29" Column="90" TopLine="1"/>
|
||||
<Caret Line="475" Column="15" TopLine="458"/>
|
||||
</Position11>
|
||||
<Position12>
|
||||
<Filename Value="testunit.pas"/>
|
||||
<Caret Line="1792" Column="84" TopLine="1789"/>
|
||||
<Filename Value="../../Units/MMLCore/iomanager.pas"/>
|
||||
<Caret Line="497" Column="48" TopLine="486"/>
|
||||
</Position12>
|
||||
<Position13>
|
||||
<Filename Value="../../Units/MMLCore/iomanager.pas"/>
|
||||
<Caret Line="480" Column="16" TopLine="465"/>
|
||||
<Caret Line="441" Column="22" TopLine="424"/>
|
||||
</Position13>
|
||||
<Position14>
|
||||
<Filename Value="../../Units/MMLCore/iomanager.pas"/>
|
||||
<Caret Line="481" Column="19" TopLine="464"/>
|
||||
<Caret Line="564" Column="7" TopLine="550"/>
|
||||
</Position14>
|
||||
<Position15>
|
||||
<Filename Value="../../Units/MMLCore/iomanager.pas"/>
|
||||
<Caret Line="475" Column="15" TopLine="458"/>
|
||||
<Caret Line="574" Column="76" TopLine="551"/>
|
||||
</Position15>
|
||||
<Position16>
|
||||
<Filename Value="../../Units/MMLCore/iomanager.pas"/>
|
||||
<Caret Line="497" Column="48" TopLine="486"/>
|
||||
<Caret Line="546" Column="17" TopLine="529"/>
|
||||
</Position16>
|
||||
<Position17>
|
||||
<Filename Value="../../Units/MMLCore/iomanager.pas"/>
|
||||
<Caret Line="441" Column="22" TopLine="424"/>
|
||||
<Caret Line="549" Column="16" TopLine="532"/>
|
||||
</Position17>
|
||||
<Position18>
|
||||
<Filename Value="../../Units/MMLCore/iomanager.pas"/>
|
||||
<Caret Line="564" Column="7" TopLine="550"/>
|
||||
<Filename Value="testunit.pas"/>
|
||||
<Caret Line="566" Column="18" TopLine="551"/>
|
||||
</Position18>
|
||||
<Position19>
|
||||
<Filename Value="../../Units/MMLCore/iomanager.pas"/>
|
||||
<Caret Line="574" Column="76" TopLine="551"/>
|
||||
<Filename Value="testunit.pas"/>
|
||||
<Caret Line="560" Column="69" TopLine="551"/>
|
||||
</Position19>
|
||||
<Position20>
|
||||
<Filename Value="../../Units/MMLCore/iomanager.pas"/>
|
||||
<Caret Line="546" Column="17" TopLine="529"/>
|
||||
<Filename Value="testunit.pas"/>
|
||||
<Caret Line="564" Column="41" TopLine="551"/>
|
||||
</Position20>
|
||||
<Position21>
|
||||
<Filename Value="../../Units/MMLCore/iomanager.pas"/>
|
||||
<Caret Line="549" Column="16" TopLine="532"/>
|
||||
<Filename Value="testunit.pas"/>
|
||||
<Caret Line="566" Column="18" TopLine="551"/>
|
||||
</Position21>
|
||||
<Position22>
|
||||
<Filename Value="testunit.pas"/>
|
||||
<Caret Line="566" Column="18" TopLine="551"/>
|
||||
<Caret Line="567" Column="18" TopLine="551"/>
|
||||
</Position22>
|
||||
<Position23>
|
||||
<Filename Value="testunit.pas"/>
|
||||
<Caret Line="560" Column="69" TopLine="551"/>
|
||||
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
|
||||
<Caret Line="216" Column="18" TopLine="206"/>
|
||||
</Position23>
|
||||
<Position24>
|
||||
<Filename Value="testunit.pas"/>
|
||||
<Caret Line="564" Column="41" TopLine="551"/>
|
||||
<Filename Value="../../Units/MMLAddon/plugins.pas"/>
|
||||
<Caret Line="69" Column="31" TopLine="56"/>
|
||||
</Position24>
|
||||
<Position25>
|
||||
<Filename Value="testunit.pas"/>
|
||||
<Caret Line="566" Column="18" TopLine="551"/>
|
||||
<Filename Value="../../Units/MMLCore/iomanager.pas"/>
|
||||
<Caret Line="247" Column="52" TopLine="234"/>
|
||||
</Position25>
|
||||
<Position26>
|
||||
<Filename Value="testunit.pas"/>
|
||||
<Caret Line="567" Column="18" TopLine="551"/>
|
||||
<Filename Value="../../Units/MMLCore/client.pas"/>
|
||||
<Caret Line="64" Column="43" TopLine="45"/>
|
||||
</Position26>
|
||||
<Position27>
|
||||
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
|
||||
<Caret Line="216" Column="18" TopLine="206"/>
|
||||
<Caret Line="328" Column="27" TopLine="96"/>
|
||||
</Position27>
|
||||
<Position28>
|
||||
<Filename Value="../../Units/MMLAddon/plugins.pas"/>
|
||||
<Caret Line="69" Column="31" TopLine="56"/>
|
||||
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
|
||||
<Caret Line="217" Column="137" TopLine="200"/>
|
||||
</Position28>
|
||||
<Position29>
|
||||
<Filename Value="../../Units/MMLCore/iomanager.pas"/>
|
||||
<Caret Line="247" Column="52" TopLine="234"/>
|
||||
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
|
||||
<Caret Line="213" Column="28" TopLine="185"/>
|
||||
</Position29>
|
||||
<Position30>
|
||||
<Filename Value="../../Units/MMLCore/client.pas"/>
|
||||
<Caret Line="33" Column="47" TopLine="45"/>
|
||||
<Filename Value="testunit.pas"/>
|
||||
<Caret Line="558" Column="20" TopLine="573"/>
|
||||
</Position30>
|
||||
</JumpHistory>
|
||||
</ProjectOptions>
|
||||
@ -2210,12 +2210,6 @@
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<BreakPoints Count="1">
|
||||
<Item1>
|
||||
<Source Value="../../Units/MMLCore/client.pas"/>
|
||||
<Line Value="64"/>
|
||||
</Item1>
|
||||
</BreakPoints>
|
||||
<Exceptions Count="3">
|
||||
<Item1>
|
||||
<Name Value="EAbort"/>
|
||||
|
@ -527,9 +527,13 @@ begin
|
||||
Writeln('The script hasn''t stopped yet, so we cannot start a new one.');
|
||||
exit;
|
||||
end;
|
||||
AppPath:= MainDir + DS;
|
||||
includePath:= LoadSettingDef('Settings/Includes/Path', IncludeTrailingPathDelimiter(ExpandFileName(MainDir+ DS + '..' + DS + '..' + ds)) + 'Includes' + DS);
|
||||
fontPath := LoadSettingDef('Settings/Fonts/Path', IncludeTrailingPathDelimiter(ExpandFileName(MainDir+ DS + '..' + DS + '..' + ds)) + 'Fonts' + DS);
|
||||
PluginsPath := LoadSettingDef('Settings/Plugins/Path', ExpandFileName(MainDir + DS + '..' + DS + '..'+ DS + 'Plugins'+ DS));
|
||||
ScriptErrorLine:= -1;
|
||||
CurrentSyncInfo.SyncMethod:= @Self.SafeCallThread;
|
||||
ScriptThread := TMMLPSThread.Create(True,@CurrentSyncInfo);
|
||||
ScriptThread := TMMLPSThread.Create(True,@CurrentSyncInfo,PluginsPath);
|
||||
{$IFNDEF TERMINALWRITELN}
|
||||
ScriptThread.SetDebug(@formWriteln);
|
||||
ScriptThread.DebugMemo := Self.Memo1;
|
||||
@ -547,16 +551,6 @@ begin
|
||||
|
||||
if ScriptFile <> '' then
|
||||
ScriptPath := ExtractFileDir(ScriptFile);
|
||||
AppPath:= MainDir + DS;
|
||||
includePath:= LoadSettingDef('Settings/Includes/Path',
|
||||
IncludeTrailingPathDelimiter(ExpandFileName(MainDir+
|
||||
DS + '..' + DS + '..' + ds)) + 'Includes' + DS);
|
||||
fontPath := LoadSettingDef('Settings/Fonts/Path',
|
||||
IncludeTrailingPathDelimiter(ExpandFileName(MainDir+
|
||||
DS + '..' + DS + '..' + ds)) + 'Fonts' + DS);
|
||||
|
||||
PluginsPath := LoadSettingDef('Settings/Plugins/Path',
|
||||
ExpandFileName(MainDir + DS + '..' + DS + '..'+ DS + 'Plugins'+ DS));
|
||||
if not DirectoryExists(PluginsPath) and not assigned(PluginsGlob) then
|
||||
begin
|
||||
if FirstRun then
|
||||
|
@ -111,7 +111,7 @@ type
|
||||
procedure SetDebug( writelnProc : TWritelnProc );
|
||||
procedure SetDbgImg( DebugImageInfo : TDbgImgInfo);
|
||||
procedure SetPaths(ScriptP,AppP,IncludeP,PluginP,FontP : string);
|
||||
constructor Create(CreateSuspended: Boolean; TheSyncInfo : PSyncInfo);
|
||||
constructor Create(CreateSuspended: Boolean; TheSyncInfo : PSyncInfo; plugin_dir: string);
|
||||
destructor Destroy; override;
|
||||
end;
|
||||
threadvar
|
||||
@ -210,11 +210,11 @@ end;
|
||||
}
|
||||
|
||||
|
||||
constructor TMMLPSThread.Create(CreateSuspended : boolean; TheSyncInfo : PSyncInfo);
|
||||
constructor TMMLPSThread.Create(CreateSuspended : boolean; TheSyncInfo : PSyncInfo; plugin_dir: string);
|
||||
begin
|
||||
SyncInfo:= TheSyncInfo;
|
||||
SetLength(PluginsToLoad,0);
|
||||
Client := TClient.Create;
|
||||
Client := TClient.Create(plugin_dir);
|
||||
PSScript := TPSScript.Create(nil);
|
||||
PSScript.UsePreProcessor:= True;
|
||||
PSScript.OnNeedFile := @RequireFile;
|
||||
|
@ -41,7 +41,7 @@ It binds all the components together.
|
||||
|
||||
type
|
||||
TClient = class(TObject)
|
||||
constructor Create;
|
||||
constructor Create(plugin_dir: string);
|
||||
destructor Destroy; override;
|
||||
|
||||
public
|
||||
@ -57,11 +57,11 @@ type
|
||||
implementation
|
||||
|
||||
// Possibly pass arguments to a default window.
|
||||
constructor TClient.Create;
|
||||
constructor TClient.Create(plugin_dir: string);
|
||||
begin
|
||||
inherited Create;
|
||||
|
||||
IOManager:= TIOManager.Create('./Plugins');
|
||||
IOManager:= TIOManager.Create(plugin_dir);
|
||||
MFiles := TMFiles.Create;
|
||||
MFinder := TMFinder.Create(Self);
|
||||
MBitmaps := TMBitmaps.Create(self);
|
||||
|
@ -2001,7 +2001,7 @@
|
||||
<UsageCount Value="15"/>
|
||||
</Unit281>
|
||||
</Units>
|
||||
<JumpHistory Count="30" HistoryIndex="29">
|
||||
<JumpHistory Count="29" HistoryIndex="28">
|
||||
<Position1>
|
||||
<Filename Value="testunit.pas"/>
|
||||
<Caret Line="205" Column="33" TopLine="28"/>
|
||||
@ -2104,24 +2104,20 @@
|
||||
</Position25>
|
||||
<Position26>
|
||||
<Filename Value="testunit.pas"/>
|
||||
<Caret Line="568" Column="40" TopLine="1101"/>
|
||||
<Caret Line="58" Column="21" TopLine="38"/>
|
||||
</Position26>
|
||||
<Position27>
|
||||
<Filename Value="testunit.pas"/>
|
||||
<Caret Line="58" Column="21" TopLine="38"/>
|
||||
</Position27>
|
||||
<Position28>
|
||||
<Filename Value="../../Units/MMLCore/bitmaps.pas"/>
|
||||
<Caret Line="128" Column="27" TopLine="111"/>
|
||||
</Position27>
|
||||
<Position28>
|
||||
<Filename Value="testunit.pas"/>
|
||||
<Caret Line="468" Column="17" TopLine="418"/>
|
||||
</Position28>
|
||||
<Position29>
|
||||
<Filename Value="testunit.pas"/>
|
||||
<Caret Line="468" Column="17" TopLine="418"/>
|
||||
</Position29>
|
||||
<Position30>
|
||||
<Filename Value="testunit.pas"/>
|
||||
<Caret Line="1017" Column="63" TopLine="1010"/>
|
||||
</Position30>
|
||||
</Position29>
|
||||
</JumpHistory>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
@ -2131,7 +2127,8 @@
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)/;$(ProjPath)../../Units/MMLAddon/PSInc/"/>
|
||||
<OtherUnitFiles Value="$(ProjPath)../../Units/MMLCore/;../../../fpc/packages/unixutil/src/;$(ProjPath)../../Units/MMLAddon/;$(ProjPath)../../Units/PascalScript/;$(ProjPath)../../Units/Misc/;$(ProjPath)../../Units/MMLAddon/PSInc/;$(ProjPath)../../Units/Linux/;$(ProjPath)../../Units/Synapse/;$(LazarusDir)/components/mouseandkeyinput/;../../../fpc/packages/libc/src/"/>
|
||||
<OtherUnitFiles Value="$(ProjPath)../../Units/MMLCore/;$(ProjPath)../../Units/MMLAddon/;$(ProjPath)../../Units/PascalScript/;$(ProjPath)../../Units/Misc/;$(ProjPath)../../Units/MMLAddon/PSInc/;$(ProjPath)../../Units/Linux/;$(ProjPath)../../Units/Synapse/;$(LazarusDir)/components/mouseandkeyinput/"/>
|
||||
<UnitOutputDirectory Value="../../build/$(TargetOS)/"/>
|
||||
</SearchPaths>
|
||||
<CodeGeneration>
|
||||
<Optimizations>
|
||||
|
@ -34,7 +34,7 @@ unit plugins;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils,dynlibs;
|
||||
Classes, SysUtils, dynlibs;
|
||||
|
||||
type
|
||||
TMPluginMethod = record
|
||||
@ -44,31 +44,45 @@ type
|
||||
|
||||
TMPlugin = record
|
||||
Methods : Array of TMPluginMethod;
|
||||
dllHandle : TLibHandle;
|
||||
filename : string;
|
||||
MethodLen : integer;
|
||||
end;
|
||||
TMPluginArray = array of TMPlugin;
|
||||
|
||||
{ TMPlugins }
|
||||
TGenericLib = record
|
||||
filename: string;
|
||||
handle: TLibHandle;
|
||||
end;
|
||||
TGenericLibArray = array of TGenericLib;
|
||||
|
||||
TMPlugins = class (TObject)
|
||||
private
|
||||
Plugins : TMPluginArray;
|
||||
PluginLen : integer;
|
||||
procedure FreePlugins;
|
||||
public
|
||||
PluginDirs : TStringList;
|
||||
procedure ValidateDirs;
|
||||
procedure LoadPluginsDir( DirIndex : integer);
|
||||
function LoadPlugin(PluginName : string) : integer;
|
||||
property Count : integer read PluginLen;
|
||||
property MPlugins : TMPluginArray read Plugins;
|
||||
constructor Create;
|
||||
destructor Destroy;override;
|
||||
TGenericLoader = class(TObject)
|
||||
private
|
||||
PluginLen : integer;
|
||||
Loaded: TGenericLibArray;
|
||||
procedure FreePlugins;
|
||||
protected
|
||||
function InitPlugin(plugin: TLibHandle): boolean; virtual; abstract;
|
||||
public
|
||||
PluginDirs : TStringList;
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
procedure ValidateDirs;
|
||||
procedure LoadPluginsDir(DirIndex : integer);
|
||||
function LoadPlugin(PluginName : string) : integer;
|
||||
end;
|
||||
|
||||
|
||||
{ TMPlugins }
|
||||
|
||||
TMPlugins = class (TGenericLoader)
|
||||
private
|
||||
Plugins : TMPluginArray;
|
||||
NumPlugins : integer;
|
||||
protected
|
||||
function InitPlugin(plugin: TLibHandle): boolean; override;
|
||||
public
|
||||
property MPlugins : TMPluginArray read Plugins;
|
||||
property Count : integer read NumPlugins;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
@ -77,24 +91,24 @@ uses
|
||||
|
||||
{ TMPlugins }
|
||||
|
||||
procedure TMPlugins.FreePlugins;
|
||||
procedure TGenericLoader.FreePlugins;
|
||||
var
|
||||
I : integer;
|
||||
begin
|
||||
for i := 0 to PluginLen - 1 do
|
||||
begin;
|
||||
if (Plugins[i].dllHandle > 0) then
|
||||
if (Loaded[i].handle > 0) then
|
||||
try
|
||||
Writeln(inttostr(I));
|
||||
FreeLibrary(Plugins[i].dllHandle);
|
||||
FreeLibrary(Loaded[i].handle);
|
||||
except
|
||||
end;
|
||||
end;
|
||||
SetLength(Plugins,0);
|
||||
SetLength(Loaded,0);
|
||||
PluginLen:= 0;
|
||||
end;
|
||||
|
||||
procedure TMPlugins.ValidateDirs;
|
||||
procedure TGenericLoader.ValidateDirs;
|
||||
var
|
||||
i : integer;
|
||||
TempStr : string;
|
||||
@ -115,7 +129,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMPlugins.LoadPluginsDir(DirIndex: integer);
|
||||
procedure TGenericLoader.LoadPluginsDir(DirIndex: integer);
|
||||
var
|
||||
PlugExt: String = {$IFDEF LINUX}'*.so';{$ELSE}'*.dll';{$ENDIF}
|
||||
FileSearcher : TSearchRec;
|
||||
@ -133,16 +147,10 @@ begin
|
||||
FindClose(FileSearcher);
|
||||
end;
|
||||
|
||||
function TMPlugins.LoadPlugin(PluginName: string): Integer;
|
||||
|
||||
function TGenericLoader.LoadPlugin(PluginName: string): Integer;
|
||||
var
|
||||
i, ii : integer;
|
||||
pntrArrc : function : integer; stdcall;
|
||||
GetFuncInfo : function (x: Integer; var ProcAddr: Pointer; var ProcDef: PChar) : Integer; stdcall;
|
||||
GetTypeCount : function : Integer; stdcall;
|
||||
GetTypeInfo : function (x: Integer; var sType, sTypeDef: string): Integer; stdcall;
|
||||
PD : PChar;
|
||||
pntr : Pointer;
|
||||
arrc : integer;
|
||||
Status : LongInt;
|
||||
PlugExt: String = {$IFDEF LINUX}'.so';{$ELSE}'.dll';{$ENDIF}
|
||||
begin
|
||||
@ -162,51 +170,66 @@ begin
|
||||
if ii = -1 then
|
||||
raise Exception.CreateFMT('Plugins(%s) has not been found',[PluginName]);
|
||||
for i := 0 to PluginLen - 1 do
|
||||
if Plugins[i].filename = (PluginDirs.Strings[ii] + PluginName + PlugExt) then
|
||||
if Loaded[i].filename = (PluginDirs.Strings[ii] + PluginName + PlugExt) then
|
||||
Exit(i);
|
||||
pd := StrAlloc(255);
|
||||
SetLength(Plugins,PluginLen + 1);
|
||||
SetLength(Loaded,PluginLen + 1);
|
||||
Writeln(Format('Loading plugin %s at %s',[PluginName,PluginDirs.Strings[ii]]));
|
||||
Plugins[PluginLen].filename:= PluginDirs.Strings[ii] + Pluginname + PlugExt;
|
||||
Plugins[PluginLen].dllHandle:= LoadLibrary(PChar(Plugins[PluginLen].filename));
|
||||
if Plugins[PluginLen].dllHandle = 0 then
|
||||
Raise Exception.CreateFMT('Error loading plugin %s',[Plugins[PluginLen].filename]);
|
||||
Pointer(pntrArrc) := GetProcAddress(Plugins[PluginLen].dllHandle, PChar('GetFunctionCount'));
|
||||
if @pntrArrc = nil then
|
||||
Raise Exception.CreateFMT('Error loading plugin %s',[Plugins[PluginLen].filename]);
|
||||
arrc := pntrArrc();
|
||||
SetLength(Plugins[PluginLen].Methods, ArrC);
|
||||
Pointer(GetFuncInfo) := GetProcAddress(Plugins[PluginLen].dllHandle, PChar('GetFunctionInfo'));
|
||||
if @GetFuncInfo = nil then
|
||||
Raise Exception.CreateFMT('Error loading plugin %s',[Plugins[PluginLen].filename]);
|
||||
Plugins[PluginLen].MethodLen := Arrc;
|
||||
for ii := 0 to ArrC-1 do
|
||||
begin;
|
||||
if (GetFuncInfo(ii, pntr, pd) < 0) then
|
||||
Continue;
|
||||
Plugins[Pluginlen].Methods[ii].FuncPtr := pntr;
|
||||
Plugins[Pluginlen].Methods[ii].FuncStr := pd;
|
||||
end;
|
||||
Loaded[PluginLen].filename:= PluginDirs.Strings[ii] + Pluginname + PlugExt;
|
||||
Loaded[PluginLen].handle:= LoadLibrary(PChar(Loaded[PluginLen].filename));
|
||||
if Loaded[PluginLen].handle = 0 then
|
||||
Raise Exception.CreateFMT('Error loading plugin %s',[Loaded[PluginLen].filename]);
|
||||
if InitPlugin(Loaded[PluginLen].handle) then
|
||||
inc(PluginLen)
|
||||
else
|
||||
FreeLibrary(Loaded[PluginLen].handle);
|
||||
Result := PluginLen;
|
||||
inc(PluginLen);
|
||||
StrDispose(pd);
|
||||
|
||||
end;
|
||||
|
||||
|
||||
constructor TMPlugins.Create;
|
||||
constructor TGenericLoader.Create;
|
||||
begin
|
||||
inherited Create;
|
||||
PluginLen := 0;
|
||||
PluginDirs := TStringList.Create;
|
||||
end;
|
||||
|
||||
destructor TMPlugins.Destroy;
|
||||
destructor TGenericLoader.Destroy;
|
||||
begin
|
||||
FreePlugins;
|
||||
PluginDirs.Free;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
function TMPlugins.InitPlugin(plugin: TLibHandle): boolean;
|
||||
var
|
||||
pntrArrc : function : integer; stdcall;
|
||||
GetFuncInfo : function (x: Integer; var ProcAddr: Pointer; var ProcDef: PChar) : Integer; stdcall;
|
||||
GetTypeCount : function : Integer; stdcall;
|
||||
GetTypeInfo : function (x: Integer; var sType, sTypeDef: string): Integer; stdcall;
|
||||
PD : PChar;
|
||||
pntr : Pointer;
|
||||
arrc, ii : integer;
|
||||
begin
|
||||
Pointer(pntrArrc) := GetProcAddress(plugin, PChar('GetFunctionCount'));
|
||||
if @pntrArrc = nil then begin result:= false; exit; end;
|
||||
Pointer(GetFuncInfo) := GetProcAddress(plugin, PChar('GetFunctionInfo'));
|
||||
if @GetFuncInfo = nil then begin result:= false; exit; end;
|
||||
arrc := pntrArrc();
|
||||
SetLength(Plugins,NumPlugins+1);
|
||||
Plugins[NumPlugins].MethodLen := Arrc;
|
||||
SetLength(Plugins[NumPlugins].Methods, ArrC);
|
||||
pd := StrAlloc(255);
|
||||
for ii := 0 to ArrC-1 do
|
||||
begin;
|
||||
if (GetFuncInfo(ii, pntr, pd) < 0) then
|
||||
Continue;
|
||||
Plugins[NumPlugins].Methods[ii].FuncPtr := pntr;
|
||||
Plugins[NumPlugins].Methods[ii].FuncStr := pd;
|
||||
end;
|
||||
StrDispose(pd);
|
||||
inc(NumPlugins);
|
||||
result:= true;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user