1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-11-21 08:45:06 -05:00

Simba: Export types from plugins.

This commit is contained in:
John P (Dgby714) 2010-12-23 08:33:21 -05:00 committed by Merlijn Wajer
parent 285be4b6ed
commit 9778b2e6e6
2 changed files with 92 additions and 43 deletions

View File

@ -651,12 +651,18 @@ begin
for i := fonts.count - 1 downto 0 do
Sender.Comp.AddConstantN(Fonts[i].Name,'string').SetString(Fonts[i].Name);
for i := high(PluginsToLoad) downto 0 do
for i := High(PluginsToLoad) downto 0 do
begin
for ii := 0 to PluginsGlob.MPlugins[PluginsToLoad[i]].TypesLen - 1 do
Sender.Comp.AddTypeS(PluginsGlob.MPlugins[PluginsToLoad[i]].Types[ii].TypeName,
PluginsGlob.MPlugins[PluginsToLoad[i]].Types[ii].TypeDef);
for ii := 0 to PluginsGlob.MPlugins[PluginsToLoad[i]].MethodLen - 1 do
Sender.AddFunctionEx(PluginsGlob.MPlugins[PluginsToLoad[i]].Methods[ii].FuncPtr,
PluginsGlob.MPlugins[PluginsToLoad[i]].Methods[ii].FuncStr,
Muf_Conv_to_PS_Conv(PluginsGlob.MPlugins[PluginsToLoad[i]].Methods[ii].FuncConv));
end;
for i := 0 to high(VirtualKeys) do
Sender.Comp.AddConstantN(Format('VK_%S',[VirtualKeys[i].Str]),'Byte').SetInt(VirtualKeys[i].Key);
// Here we add all the Consts/Types to the engine.

View File

@ -39,16 +39,23 @@ uses
const
cv_StdCall = 0; //StdCall
cv_Register = 1; //Register
type
TType = record
TypeName, TypeDef: string;
end;
TMPluginMethod = record
FuncPtr : pointer;
FuncStr : string;
FuncPtr: pointer;
FuncStr: string;
FuncConv: integer;
end;
TMPlugin = record
Methods : Array of TMPluginMethod;
MethodLen : integer;
Methods: array of TMPluginMethod;
MethodLen: integer;
Types: array of TType;
TypesLen: integer;
end;
TMPluginArray = array of TMPlugin;
@ -58,13 +65,13 @@ type
TMPlugins = class (TGenericLoader)
private
Plugins : TMPluginArray;
NumPlugins : integer;
Plugins: TMPluginArray;
NumPlugins: integer;
protected
function InitPlugin(plugin: TLibHandle): boolean; override;
public
property MPlugins : TMPluginArray read Plugins;
property Count : integer read NumPlugins;
property MPlugins: TMPluginArray read Plugins;
property Count: integer read NumPlugins;
end;
implementation
@ -74,43 +81,79 @@ uses
{ TMPlugins }
function TMPlugins.InitPlugin(plugin: TLibHandle): boolean;
function TMPlugins.InitPlugin(Plugin: TLibHandle): boolean;
var
pntrArrc : function : integer; stdcall;
GetFuncInfo : function (x: Integer; var ProcAddr: Pointer; var ProcDef: PChar) : Integer; stdcall;
GetFuncConv : function (x: integer) : integer; stdcall;
GetTypeCount : function : Integer; stdcall;
GetTypeInfo : function (x: Integer; var sType, sTypeDef: string): Integer; stdcall;
PD : PChar;
pntr : Pointer;
arrc, ii : integer;
GetFuncCount: function: integer; stdcall;
GetFuncInfo: function(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): integer; stdcall;
GetFuncConv: function(x: integer): integer; stdcall;
GetTypeCount: function: integer; stdcall;
GetTypeInfo: function(x: Integer; var sType, sTypeDef: string): integer; stdcall;
PD: PChar;
pntr: Pointer;
ArrC, I: 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;
Pointer(GetFuncConv) := GetProcAddress(plugin,pchar('GetFunctionCallingConv'));
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;
if GetFuncConv <> nil then
Plugins[NumPlugins].Methods[ii].FuncConv := GetFuncConv(ii)
else
Plugins[NumPlugins].Methods[ii].FuncConv := cv_stdcall;
Pointer(GetFuncCount) := GetProcAddress(Plugin, PChar('GetFunctionCount'));
if (GetFuncCount = nil) then
begin
Result := False;
Exit;
end;
Pointer(GetFuncInfo) := GetProcAddress(Plugin, PChar('GetFunctionInfo'));
if (GetFuncInfo = nil) then
begin
Result := False;
Exit;
end;
Pointer(GetFuncConv) := GetProcAddress(Plugin, PChar('GetFunctionCallingConv'));
SetLength(Plugins, NumPlugins + 1);
Pointer(GetTypeCount) := GetProcAddress(Plugin, PChar('GetTypeCount'));
if (not (GetTypeCount = nil)) then
begin
Pointer(GetTypeInfo) := GetProcAddress(Plugin, PChar('GetTypeInfo'));
if (not (GetTypeInfo = nil)) then
begin
ArrC := GetTypeCount();
Plugins[NumPlugins].TypesLen := ArrC;
SetLength(Plugins[NumPlugins].Types, ArrC);
for I := 0 to ArrC - 1 do
begin
if (GetTypeInfo(I, Plugins[NumPlugins].Types[I].TypeName, Plugins[NumPlugins].Types[I].TypeDef) < 0) then
begin
WriteLn('Failed...');
Plugins[NumPlugins].Types[I].TypeName := '';
Plugins[NumPlugins].Types[I].TypeDef := '';
end;
WriteLn(Plugins[NumPlugins].Types[I].TypeName + ' = ' + Plugins[NumPlugins].Types[I].TypeDef);
end;
end;
end;
StrDispose(pd);
inc(NumPlugins);
result:= true;
ArrC := GetFuncCount();
WriteLn(ArrC);
Plugins[NumPlugins].MethodLen := ArrC;
SetLength(Plugins[NumPlugins].Methods, ArrC);
PD := StrAlloc(255);
for I := 0 to ArrC - 1 do
begin;
if (GetFuncInfo(I, pntr, PD) < 0) then
Continue;
WriteLn(PD);
Plugins[NumPlugins].Methods[I].FuncPtr := pntr;
Plugins[NumPlugins].Methods[I].FuncStr := PD;
if (GetFuncConv <> nil) then
Plugins[NumPlugins].Methods[I].FuncConv := GetFuncConv(I)
else
Plugins[NumPlugins].Methods[I].FuncConv := cv_stdcall;
end;
StrDispose(PD);
Inc(NumPlugins);
Result := True;
end;
end.