1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-11-22 01:02:17 -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,11 +651,17 @@ begin
for i := fonts.count - 1 downto 0 do for i := fonts.count - 1 downto 0 do
Sender.Comp.AddConstantN(Fonts[i].Name,'string').SetString(Fonts[i].Name); 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 for ii := 0 to PluginsGlob.MPlugins[PluginsToLoad[i]].MethodLen - 1 do
Sender.AddFunctionEx(PluginsGlob.MPlugins[PluginsToLoad[i]].Methods[ii].FuncPtr, Sender.AddFunctionEx(PluginsGlob.MPlugins[PluginsToLoad[i]].Methods[ii].FuncPtr,
PluginsGlob.MPlugins[PluginsToLoad[i]].Methods[ii].FuncStr, PluginsGlob.MPlugins[PluginsToLoad[i]].Methods[ii].FuncStr,
Muf_Conv_to_PS_Conv(PluginsGlob.MPlugins[PluginsToLoad[i]].Methods[ii].FuncConv)); Muf_Conv_to_PS_Conv(PluginsGlob.MPlugins[PluginsToLoad[i]].Methods[ii].FuncConv));
end;
for i := 0 to high(VirtualKeys) do for i := 0 to high(VirtualKeys) do
Sender.Comp.AddConstantN(Format('VK_%S',[VirtualKeys[i].Str]),'Byte').SetInt(VirtualKeys[i].Key); Sender.Comp.AddConstantN(Format('VK_%S',[VirtualKeys[i].Str]),'Byte').SetInt(VirtualKeys[i].Key);

View File

@ -39,7 +39,12 @@ uses
const const
cv_StdCall = 0; //StdCall cv_StdCall = 0; //StdCall
cv_Register = 1; //Register cv_Register = 1; //Register
type type
TType = record
TypeName, TypeDef: string;
end;
TMPluginMethod = record TMPluginMethod = record
FuncPtr: pointer; FuncPtr: pointer;
FuncStr: string; FuncStr: string;
@ -47,8 +52,10 @@ type
end; end;
TMPlugin = record TMPlugin = record
Methods : Array of TMPluginMethod; Methods: array of TMPluginMethod;
MethodLen: integer; MethodLen: integer;
Types: array of TType;
TypesLen: integer;
end; end;
TMPluginArray = array of TMPlugin; TMPluginArray = array of TMPlugin;
@ -74,43 +81,79 @@ uses
{ TMPlugins } { TMPlugins }
function TMPlugins.InitPlugin(plugin: TLibHandle): boolean; function TMPlugins.InitPlugin(Plugin: TLibHandle): boolean;
var var
pntrArrc : function : integer; stdcall; GetFuncCount: function: integer; stdcall;
GetFuncInfo : function (x: Integer; var ProcAddr: Pointer; var ProcDef: PChar) : Integer; stdcall; GetFuncInfo: function(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): integer; stdcall;
GetFuncConv: function(x: integer): integer; stdcall; GetFuncConv: function(x: integer): integer; stdcall;
GetTypeCount : function : Integer; stdcall; GetTypeCount: function: integer; stdcall;
GetTypeInfo : function (x: Integer; var sType, sTypeDef: string): Integer; stdcall; GetTypeInfo: function(x: Integer; var sType, sTypeDef: string): integer; stdcall;
PD: PChar; PD: PChar;
pntr: Pointer; pntr: Pointer;
arrc, ii : integer; ArrC, I: integer;
begin begin
Pointer(pntrArrc) := GetProcAddress(plugin, PChar('GetFunctionCount')); Pointer(GetFuncCount) := GetProcAddress(Plugin, PChar('GetFunctionCount'));
if pntrArrc = nil then begin result:= false; exit; end; if (GetFuncCount = nil) then
Pointer(GetFuncInfo) := GetProcAddress(plugin, PChar('GetFunctionInfo')); begin
if GetFuncInfo = nil then begin result:= false; exit; end; Result := False;
Pointer(GetFuncConv) := GetProcAddress(plugin,pchar('GetFunctionCallingConv')); Exit;
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;
end; end;
StrDispose(pd);
inc(NumPlugins); Pointer(GetFuncInfo) := GetProcAddress(Plugin, PChar('GetFunctionInfo'));
result:= true; 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;
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;
end. end.