1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-11-22 17:22:21 -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:
BenLand100 2010-01-21 16:45:58 +00:00
parent 5d4ee2baa1
commit 104b410220
6 changed files with 157 additions and 149 deletions

View File

@ -10,7 +10,7 @@
<TargetFileExt Value=""/> <TargetFileExt Value=""/>
<Title Value="Simba"/> <Title Value="Simba"/>
<UseXPManifest Value="True"/> <UseXPManifest Value="True"/>
<ActiveEditorIndexAtStart Value="0"/> <ActiveEditorIndexAtStart Value="11"/>
</General> </General>
<VersionInfo> <VersionInfo>
<ProjectVersion Value=""/> <ProjectVersion Value=""/>
@ -140,8 +140,8 @@
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
<UnitName Value="TestUnit"/> <UnitName Value="TestUnit"/>
<ComponentState Value="1"/> <ComponentState Value="1"/>
<CursorPos X="14" Y="1305"/> <CursorPos X="74" Y="536"/>
<TopLine Value="1288"/> <TopLine Value="515"/>
<EditorIndex Value="11"/> <EditorIndex Value="11"/>
<UsageCount Value="202"/> <UsageCount Value="202"/>
<Loaded Value="True"/> <Loaded Value="True"/>
@ -190,8 +190,8 @@
<Filename Value="../../Units/MMLCore/client.pas"/> <Filename Value="../../Units/MMLCore/client.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="Client"/> <UnitName Value="Client"/>
<CursorPos X="1" Y="64"/> <CursorPos X="46" Y="60"/>
<TopLine Value="47"/> <TopLine Value="43"/>
<EditorIndex Value="0"/> <EditorIndex Value="0"/>
<UsageCount Value="201"/> <UsageCount Value="201"/>
<Loaded Value="True"/> <Loaded Value="True"/>
@ -269,8 +269,8 @@
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/> <Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="mmlpsthread"/> <UnitName Value="mmlpsthread"/>
<CursorPos X="27" Y="328"/> <CursorPos X="95" Y="114"/>
<TopLine Value="228"/> <TopLine Value="97"/>
<EditorIndex Value="1"/> <EditorIndex Value="1"/>
<UsageCount Value="202"/> <UsageCount Value="202"/>
<Loaded Value="True"/> <Loaded Value="True"/>
@ -2057,123 +2057,123 @@
<JumpHistory Count="30" HistoryIndex="29"> <JumpHistory Count="30" HistoryIndex="29">
<Position1> <Position1>
<Filename Value="../../Units/MMLAddon/plugins.pas"/> <Filename Value="../../Units/MMLAddon/plugins.pas"/>
<Caret Line="106" Column="29" TopLine="82"/> <Caret Line="174" Column="24" TopLine="155"/>
</Position1> </Position1>
<Position2> <Position2>
<Filename Value="../../Units/MMLAddon/plugins.pas"/> <Filename Value="../../Units/MMLCore/iomanager.pas"/>
<Caret Line="102" Column="35" TopLine="85"/> <Caret Line="486" Column="36" TopLine="461"/>
</Position2> </Position2>
<Position3> <Position3>
<Filename Value="../../Units/MMLAddon/plugins.pas"/> <Filename Value="../../Units/MMLAddon/plugins.pas"/>
<Caret Line="106" Column="19" TopLine="89"/> <Caret Line="181" Column="48" TopLine="156"/>
</Position3> </Position3>
<Position4> <Position4>
<Filename Value="../../Units/MMLAddon/plugins.pas"/> <Filename Value="../../Units/MMLCore/iomanager.pas"/>
<Caret Line="229" Column="26" TopLine="199"/> <Caret Line="179" Column="68" TopLine="166"/>
</Position4> </Position4>
<Position5> <Position5>
<Filename Value="../../Units/MMLAddon/plugins.pas"/> <Filename Value="../../Units/MMLCore/iomanager.pas"/>
<Caret Line="174" Column="24" TopLine="155"/> <Caret Line="157" Column="30" TopLine="141"/>
</Position5> </Position5>
<Position6> <Position6>
<Filename Value="../../Units/MMLCore/iomanager.pas"/> <Filename Value="../../Units/MMLCore/iomanager.pas"/>
<Caret Line="486" Column="36" TopLine="461"/> <Caret Line="178" Column="47" TopLine="7"/>
</Position6> </Position6>
<Position7> <Position7>
<Filename Value="../../Units/MMLAddon/plugins.pas"/> <Filename Value="../../Units/MMLCore/iomanager.pas"/>
<Caret Line="181" Column="48" TopLine="156"/> <Caret Line="29" Column="90" TopLine="1"/>
</Position7> </Position7>
<Position8> <Position8>
<Filename Value="../../Units/MMLCore/iomanager.pas"/> <Filename Value="testunit.pas"/>
<Caret Line="179" Column="68" TopLine="166"/> <Caret Line="1792" Column="84" TopLine="1789"/>
</Position8> </Position8>
<Position9> <Position9>
<Filename Value="../../Units/MMLCore/iomanager.pas"/> <Filename Value="../../Units/MMLCore/iomanager.pas"/>
<Caret Line="157" Column="30" TopLine="141"/> <Caret Line="480" Column="16" TopLine="465"/>
</Position9> </Position9>
<Position10> <Position10>
<Filename Value="../../Units/MMLCore/iomanager.pas"/> <Filename Value="../../Units/MMLCore/iomanager.pas"/>
<Caret Line="178" Column="47" TopLine="7"/> <Caret Line="481" Column="19" TopLine="464"/>
</Position10> </Position10>
<Position11> <Position11>
<Filename Value="../../Units/MMLCore/iomanager.pas"/> <Filename Value="../../Units/MMLCore/iomanager.pas"/>
<Caret Line="29" Column="90" TopLine="1"/> <Caret Line="475" Column="15" TopLine="458"/>
</Position11> </Position11>
<Position12> <Position12>
<Filename Value="testunit.pas"/> <Filename Value="../../Units/MMLCore/iomanager.pas"/>
<Caret Line="1792" Column="84" TopLine="1789"/> <Caret Line="497" Column="48" TopLine="486"/>
</Position12> </Position12>
<Position13> <Position13>
<Filename Value="../../Units/MMLCore/iomanager.pas"/> <Filename Value="../../Units/MMLCore/iomanager.pas"/>
<Caret Line="480" Column="16" TopLine="465"/> <Caret Line="441" Column="22" TopLine="424"/>
</Position13> </Position13>
<Position14> <Position14>
<Filename Value="../../Units/MMLCore/iomanager.pas"/> <Filename Value="../../Units/MMLCore/iomanager.pas"/>
<Caret Line="481" Column="19" TopLine="464"/> <Caret Line="564" Column="7" TopLine="550"/>
</Position14> </Position14>
<Position15> <Position15>
<Filename Value="../../Units/MMLCore/iomanager.pas"/> <Filename Value="../../Units/MMLCore/iomanager.pas"/>
<Caret Line="475" Column="15" TopLine="458"/> <Caret Line="574" Column="76" TopLine="551"/>
</Position15> </Position15>
<Position16> <Position16>
<Filename Value="../../Units/MMLCore/iomanager.pas"/> <Filename Value="../../Units/MMLCore/iomanager.pas"/>
<Caret Line="497" Column="48" TopLine="486"/> <Caret Line="546" Column="17" TopLine="529"/>
</Position16> </Position16>
<Position17> <Position17>
<Filename Value="../../Units/MMLCore/iomanager.pas"/> <Filename Value="../../Units/MMLCore/iomanager.pas"/>
<Caret Line="441" Column="22" TopLine="424"/> <Caret Line="549" Column="16" TopLine="532"/>
</Position17> </Position17>
<Position18> <Position18>
<Filename Value="../../Units/MMLCore/iomanager.pas"/> <Filename Value="testunit.pas"/>
<Caret Line="564" Column="7" TopLine="550"/> <Caret Line="566" Column="18" TopLine="551"/>
</Position18> </Position18>
<Position19> <Position19>
<Filename Value="../../Units/MMLCore/iomanager.pas"/> <Filename Value="testunit.pas"/>
<Caret Line="574" Column="76" TopLine="551"/> <Caret Line="560" Column="69" TopLine="551"/>
</Position19> </Position19>
<Position20> <Position20>
<Filename Value="../../Units/MMLCore/iomanager.pas"/> <Filename Value="testunit.pas"/>
<Caret Line="546" Column="17" TopLine="529"/> <Caret Line="564" Column="41" TopLine="551"/>
</Position20> </Position20>
<Position21> <Position21>
<Filename Value="../../Units/MMLCore/iomanager.pas"/> <Filename Value="testunit.pas"/>
<Caret Line="549" Column="16" TopLine="532"/> <Caret Line="566" Column="18" TopLine="551"/>
</Position21> </Position21>
<Position22> <Position22>
<Filename Value="testunit.pas"/> <Filename Value="testunit.pas"/>
<Caret Line="566" Column="18" TopLine="551"/> <Caret Line="567" Column="18" TopLine="551"/>
</Position22> </Position22>
<Position23> <Position23>
<Filename Value="testunit.pas"/> <Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="560" Column="69" TopLine="551"/> <Caret Line="216" Column="18" TopLine="206"/>
</Position23> </Position23>
<Position24> <Position24>
<Filename Value="testunit.pas"/> <Filename Value="../../Units/MMLAddon/plugins.pas"/>
<Caret Line="564" Column="41" TopLine="551"/> <Caret Line="69" Column="31" TopLine="56"/>
</Position24> </Position24>
<Position25> <Position25>
<Filename Value="testunit.pas"/> <Filename Value="../../Units/MMLCore/iomanager.pas"/>
<Caret Line="566" Column="18" TopLine="551"/> <Caret Line="247" Column="52" TopLine="234"/>
</Position25> </Position25>
<Position26> <Position26>
<Filename Value="testunit.pas"/> <Filename Value="../../Units/MMLCore/client.pas"/>
<Caret Line="567" Column="18" TopLine="551"/> <Caret Line="64" Column="43" TopLine="45"/>
</Position26> </Position26>
<Position27> <Position27>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/> <Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="216" Column="18" TopLine="206"/> <Caret Line="328" Column="27" TopLine="96"/>
</Position27> </Position27>
<Position28> <Position28>
<Filename Value="../../Units/MMLAddon/plugins.pas"/> <Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="69" Column="31" TopLine="56"/> <Caret Line="217" Column="137" TopLine="200"/>
</Position28> </Position28>
<Position29> <Position29>
<Filename Value="../../Units/MMLCore/iomanager.pas"/> <Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="247" Column="52" TopLine="234"/> <Caret Line="213" Column="28" TopLine="185"/>
</Position29> </Position29>
<Position30> <Position30>
<Filename Value="../../Units/MMLCore/client.pas"/> <Filename Value="testunit.pas"/>
<Caret Line="33" Column="47" TopLine="45"/> <Caret Line="558" Column="20" TopLine="573"/>
</Position30> </Position30>
</JumpHistory> </JumpHistory>
</ProjectOptions> </ProjectOptions>
@ -2210,12 +2210,6 @@
</Other> </Other>
</CompilerOptions> </CompilerOptions>
<Debugging> <Debugging>
<BreakPoints Count="1">
<Item1>
<Source Value="../../Units/MMLCore/client.pas"/>
<Line Value="64"/>
</Item1>
</BreakPoints>
<Exceptions Count="3"> <Exceptions Count="3">
<Item1> <Item1>
<Name Value="EAbort"/> <Name Value="EAbort"/>

View File

@ -527,9 +527,13 @@ begin
Writeln('The script hasn''t stopped yet, so we cannot start a new one.'); Writeln('The script hasn''t stopped yet, so we cannot start a new one.');
exit; exit;
end; 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; ScriptErrorLine:= -1;
CurrentSyncInfo.SyncMethod:= @Self.SafeCallThread; CurrentSyncInfo.SyncMethod:= @Self.SafeCallThread;
ScriptThread := TMMLPSThread.Create(True,@CurrentSyncInfo); ScriptThread := TMMLPSThread.Create(True,@CurrentSyncInfo,PluginsPath);
{$IFNDEF TERMINALWRITELN} {$IFNDEF TERMINALWRITELN}
ScriptThread.SetDebug(@formWriteln); ScriptThread.SetDebug(@formWriteln);
ScriptThread.DebugMemo := Self.Memo1; ScriptThread.DebugMemo := Self.Memo1;
@ -547,16 +551,6 @@ begin
if ScriptFile <> '' then if ScriptFile <> '' then
ScriptPath := ExtractFileDir(ScriptFile); 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 if not DirectoryExists(PluginsPath) and not assigned(PluginsGlob) then
begin begin
if FirstRun then if FirstRun then

View File

@ -111,7 +111,7 @@ type
procedure SetDebug( writelnProc : TWritelnProc ); procedure SetDebug( writelnProc : TWritelnProc );
procedure SetDbgImg( DebugImageInfo : TDbgImgInfo); procedure SetDbgImg( DebugImageInfo : TDbgImgInfo);
procedure SetPaths(ScriptP,AppP,IncludeP,PluginP,FontP : string); 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; destructor Destroy; override;
end; end;
threadvar threadvar
@ -210,11 +210,11 @@ end;
} }
constructor TMMLPSThread.Create(CreateSuspended : boolean; TheSyncInfo : PSyncInfo); constructor TMMLPSThread.Create(CreateSuspended : boolean; TheSyncInfo : PSyncInfo; plugin_dir: string);
begin begin
SyncInfo:= TheSyncInfo; SyncInfo:= TheSyncInfo;
SetLength(PluginsToLoad,0); SetLength(PluginsToLoad,0);
Client := TClient.Create; Client := TClient.Create(plugin_dir);
PSScript := TPSScript.Create(nil); PSScript := TPSScript.Create(nil);
PSScript.UsePreProcessor:= True; PSScript.UsePreProcessor:= True;
PSScript.OnNeedFile := @RequireFile; PSScript.OnNeedFile := @RequireFile;

View File

@ -41,7 +41,7 @@ It binds all the components together.
type type
TClient = class(TObject) TClient = class(TObject)
constructor Create; constructor Create(plugin_dir: string);
destructor Destroy; override; destructor Destroy; override;
public public
@ -57,11 +57,11 @@ type
implementation implementation
// Possibly pass arguments to a default window. // Possibly pass arguments to a default window.
constructor TClient.Create; constructor TClient.Create(plugin_dir: string);
begin begin
inherited Create; inherited Create;
IOManager:= TIOManager.Create('./Plugins'); IOManager:= TIOManager.Create(plugin_dir);
MFiles := TMFiles.Create; MFiles := TMFiles.Create;
MFinder := TMFinder.Create(Self); MFinder := TMFinder.Create(Self);
MBitmaps := TMBitmaps.Create(self); MBitmaps := TMBitmaps.Create(self);

View File

@ -2001,7 +2001,7 @@
<UsageCount Value="15"/> <UsageCount Value="15"/>
</Unit281> </Unit281>
</Units> </Units>
<JumpHistory Count="30" HistoryIndex="29"> <JumpHistory Count="29" HistoryIndex="28">
<Position1> <Position1>
<Filename Value="testunit.pas"/> <Filename Value="testunit.pas"/>
<Caret Line="205" Column="33" TopLine="28"/> <Caret Line="205" Column="33" TopLine="28"/>
@ -2104,24 +2104,20 @@
</Position25> </Position25>
<Position26> <Position26>
<Filename Value="testunit.pas"/> <Filename Value="testunit.pas"/>
<Caret Line="568" Column="40" TopLine="1101"/> <Caret Line="58" Column="21" TopLine="38"/>
</Position26> </Position26>
<Position27> <Position27>
<Filename Value="testunit.pas"/>
<Caret Line="58" Column="21" TopLine="38"/>
</Position27>
<Position28>
<Filename Value="../../Units/MMLCore/bitmaps.pas"/> <Filename Value="../../Units/MMLCore/bitmaps.pas"/>
<Caret Line="128" Column="27" TopLine="111"/> <Caret Line="128" Column="27" TopLine="111"/>
</Position27>
<Position28>
<Filename Value="testunit.pas"/>
<Caret Line="468" Column="17" TopLine="418"/>
</Position28> </Position28>
<Position29> <Position29>
<Filename Value="testunit.pas"/>
<Caret Line="468" Column="17" TopLine="418"/>
</Position29>
<Position30>
<Filename Value="testunit.pas"/> <Filename Value="testunit.pas"/>
<Caret Line="1017" Column="63" TopLine="1010"/> <Caret Line="1017" Column="63" TopLine="1010"/>
</Position30> </Position29>
</JumpHistory> </JumpHistory>
</ProjectOptions> </ProjectOptions>
<CompilerOptions> <CompilerOptions>
@ -2131,7 +2127,8 @@
</Target> </Target>
<SearchPaths> <SearchPaths>
<IncludeFiles Value="$(ProjOutDir)/;$(ProjPath)../../Units/MMLAddon/PSInc/"/> <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> </SearchPaths>
<CodeGeneration> <CodeGeneration>
<Optimizations> <Optimizations>

View File

@ -34,7 +34,7 @@ unit plugins;
interface interface
uses uses
Classes, SysUtils,dynlibs; Classes, SysUtils, dynlibs;
type type
TMPluginMethod = record TMPluginMethod = record
@ -44,31 +44,45 @@ type
TMPlugin = record TMPlugin = record
Methods : Array of TMPluginMethod; Methods : Array of TMPluginMethod;
dllHandle : TLibHandle;
filename : string;
MethodLen : integer; MethodLen : integer;
end; end;
TMPluginArray = array of TMPlugin; TMPluginArray = array of TMPlugin;
{ TMPlugins } TGenericLib = record
filename: string;
handle: TLibHandle;
end;
TGenericLibArray = array of TGenericLib;
TMPlugins = class (TObject) TGenericLoader = class(TObject)
private private
Plugins : TMPluginArray; PluginLen : integer;
PluginLen : integer; Loaded: TGenericLibArray;
procedure FreePlugins; procedure FreePlugins;
public protected
PluginDirs : TStringList; function InitPlugin(plugin: TLibHandle): boolean; virtual; abstract;
procedure ValidateDirs; public
procedure LoadPluginsDir( DirIndex : integer); PluginDirs : TStringList;
function LoadPlugin(PluginName : string) : integer; constructor Create;
property Count : integer read PluginLen; destructor Destroy; override;
property MPlugins : TMPluginArray read Plugins; procedure ValidateDirs;
constructor Create; procedure LoadPluginsDir(DirIndex : integer);
destructor Destroy;override; function LoadPlugin(PluginName : string) : integer;
end; 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 implementation
@ -77,24 +91,24 @@ uses
{ TMPlugins } { TMPlugins }
procedure TMPlugins.FreePlugins; procedure TGenericLoader.FreePlugins;
var var
I : integer; I : integer;
begin begin
for i := 0 to PluginLen - 1 do for i := 0 to PluginLen - 1 do
begin; begin;
if (Plugins[i].dllHandle > 0) then if (Loaded[i].handle > 0) then
try try
Writeln(inttostr(I)); Writeln(inttostr(I));
FreeLibrary(Plugins[i].dllHandle); FreeLibrary(Loaded[i].handle);
except except
end; end;
end; end;
SetLength(Plugins,0); SetLength(Loaded,0);
PluginLen:= 0; PluginLen:= 0;
end; end;
procedure TMPlugins.ValidateDirs; procedure TGenericLoader.ValidateDirs;
var var
i : integer; i : integer;
TempStr : string; TempStr : string;
@ -115,7 +129,7 @@ begin
end; end;
end; end;
procedure TMPlugins.LoadPluginsDir(DirIndex: integer); procedure TGenericLoader.LoadPluginsDir(DirIndex: integer);
var var
PlugExt: String = {$IFDEF LINUX}'*.so';{$ELSE}'*.dll';{$ENDIF} PlugExt: String = {$IFDEF LINUX}'*.so';{$ELSE}'*.dll';{$ENDIF}
FileSearcher : TSearchRec; FileSearcher : TSearchRec;
@ -133,16 +147,10 @@ begin
FindClose(FileSearcher); FindClose(FileSearcher);
end; end;
function TMPlugins.LoadPlugin(PluginName: string): Integer;
function TGenericLoader.LoadPlugin(PluginName: string): Integer;
var var
i, ii : integer; 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; Status : LongInt;
PlugExt: String = {$IFDEF LINUX}'.so';{$ELSE}'.dll';{$ENDIF} PlugExt: String = {$IFDEF LINUX}'.so';{$ELSE}'.dll';{$ENDIF}
begin begin
@ -162,51 +170,66 @@ begin
if ii = -1 then if ii = -1 then
raise Exception.CreateFMT('Plugins(%s) has not been found',[PluginName]); raise Exception.CreateFMT('Plugins(%s) has not been found',[PluginName]);
for i := 0 to PluginLen - 1 do 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); Exit(i);
pd := StrAlloc(255); SetLength(Loaded,PluginLen + 1);
SetLength(Plugins,PluginLen + 1);
Writeln(Format('Loading plugin %s at %s',[PluginName,PluginDirs.Strings[ii]])); Writeln(Format('Loading plugin %s at %s',[PluginName,PluginDirs.Strings[ii]]));
Plugins[PluginLen].filename:= PluginDirs.Strings[ii] + Pluginname + PlugExt; Loaded[PluginLen].filename:= PluginDirs.Strings[ii] + Pluginname + PlugExt;
Plugins[PluginLen].dllHandle:= LoadLibrary(PChar(Plugins[PluginLen].filename)); Loaded[PluginLen].handle:= LoadLibrary(PChar(Loaded[PluginLen].filename));
if Plugins[PluginLen].dllHandle = 0 then if Loaded[PluginLen].handle = 0 then
Raise Exception.CreateFMT('Error loading plugin %s',[Plugins[PluginLen].filename]); Raise Exception.CreateFMT('Error loading plugin %s',[Loaded[PluginLen].filename]);
Pointer(pntrArrc) := GetProcAddress(Plugins[PluginLen].dllHandle, PChar('GetFunctionCount')); if InitPlugin(Loaded[PluginLen].handle) then
if @pntrArrc = nil then inc(PluginLen)
Raise Exception.CreateFMT('Error loading plugin %s',[Plugins[PluginLen].filename]); else
arrc := pntrArrc(); FreeLibrary(Loaded[PluginLen].handle);
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;
Result := PluginLen; Result := PluginLen;
inc(PluginLen);
StrDispose(pd);
end; end;
constructor TMPlugins.Create; constructor TGenericLoader.Create;
begin begin
inherited Create; inherited Create;
PluginLen := 0; PluginLen := 0;
PluginDirs := TStringList.Create; PluginDirs := TStringList.Create;
end; end;
destructor TMPlugins.Destroy; destructor TGenericLoader.Destroy;
begin begin
FreePlugins; FreePlugins;
PluginDirs.Free; PluginDirs.Free;
inherited Destroy; inherited Destroy;
end; 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. end.