-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsimbaplugin.inc
112 lines (90 loc) · 2.23 KB
/
simbaplugin.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Helpers
type
PParamArray = ^TParamArray;
TParamArray = array[Word] of Pointer;
var
SimbaImports: record
Functions: array of record Header: String; Method: Pointer; end;
Types: array of record Str: String; Name: String; end;
Code: String;
end;
OldMemoryManager: TMemoryManager;
procedure addGlobalFunc(Header: String; Method: Pointer);
begin
with SimbaImports do
begin
SetLength(Functions, Length(Functions) + 1);
Functions[High(Functions)].Header := Header;
Functions[High(Functions)].Method := Method;
end;
end;
procedure addGlobalType(Str: String; Name: String);
begin
with SimbaImports do
begin
SetLength(Types, Length(Types) + 1);
Types[High(Types)].Str := Str;
Types[High(Types)].Name := Name;
end;
end;
procedure addCode(Code: TStringArray);
begin
SimbaImports.Code := SimbaImports.Code + String.Join(LineEnding, Code);
end;
// Exports
function GetTypeCount(): Int32; cdecl;
begin
Result := Length(SimbaImports.Types);
end;
function GetTypeInfo(Index: Int32; var Name, Str: PChar): Int32; cdecl;
begin
with SimbaImports do
begin
StrPCopy(Name, Types[Index].Name);
StrPCopy(Str, Types[Index].Str);
end;
Result := Index;
end;
function GetFunctionCount: Int32; cdecl;
begin
Result := Length(SimbaImports.Functions);
end;
function GetFunctionInfo(Index: Int32; var Method: Pointer; var Header: PChar): Int32; cdecl;
begin
with SimbaImports do
begin
StrPCopy(Header, Functions[Index].Header);
Method := Functions[Index].Method;
end;
Result := Index;
end;
function GetCodeLength: Int32; cdecl;
begin
Result := Length(SimbaImports.Code);
end;
procedure GetCode(var Code: PChar); cdecl;
begin
StrPCopy(Code, SimbaImports.Code);
end;
function GetPluginABIVersion: Int32; cdecl;
begin
Result := 2;
end;
procedure SetPluginMemManager(MemoryManager: TMemoryManager); cdecl;
begin
GetMemoryManager(OldMemoryManager);
SetMemoryManager(MemoryManager);
end;
procedure OnDetach(Data: Pointer); cdecl;
begin
SetMemoryManager(OldMemoryManager);
end;
exports GetTypeCount;
exports GetTypeInfo;
exports GetFunctionCount;
exports GetFunctionInfo;
exports GetCodeLength;
exports GetCode;
exports GetPluginABIVersion;
exports SetPluginMemManager;
exports OnDetach;