Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add none-native calling for class methods/properties. #210

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions Source/uPSRuntime.pas
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,8 @@ TClassItem = record
5: (PointerInList2: Pointer);
6: (); {Property helper, like 3}
7: (); {Property helper that will pass it's name}
8: (ProcPtr: TPSProcPtr; Ext1, Ext2: Pointer);
9: (ReadProcPtr, WriteProcPtr: TPSProcPtr; ExtRead1, ExtRead2, ExtWrite1, ExtWrite2: Pointer); {Property Helper}
end;


Expand Down Expand Up @@ -1009,6 +1011,8 @@ TPSRuntimeClass = class

procedure RegisterMethod(ProcPtr: Pointer; const Name: tbtstring);

procedure RegisterMethodName(const Name: tbtstring; ProcPtr: TPSProcPtr; Ext1, Ext2: Pointer);

procedure RegisterVirtualMethod(ProcPtr: Pointer; const Name: tbtstring);

procedure RegisterVirtualAbstractMethod(ClassDef: TClass; ProcPtr: Pointer; const Name: tbtstring);
Expand All @@ -1017,6 +1021,12 @@ TPSRuntimeClass = class

procedure RegisterPropertyHelperName(ReadFunc, WriteFunc: Pointer; const Name: tbtstring);

procedure RegisterPropertyNameHelper(const Name: tbtstring; ProcPtr: TPSProcPtr;
ExtRead1, ExtRead2, ExtWrite1, ExtWrite2: Pointer); overload;

procedure RegisterPropertyNameHelper(const Name: tbtstring; ProcReadPtr, ProcWritePtr: TPSProcPtr;
ExtRead1, ExtRead2, ExtWrite1, ExtWrite2: Pointer); overload;

procedure RegisterEventPropertyHelper(ReadFunc, WriteFunc: Pointer; const Name: tbtstring);

constructor Create(aClass: TClass; const AName: tbtstring);
Expand Down Expand Up @@ -11118,6 +11128,26 @@ function SpecImport(Sender: TPSExec; p: TPSExternalProcRec; Tag: Pointer): Boole
if p.Ext2 = nil then begin result := false; exit; end;
end;
end;
8:
begin
p.ProcPtr := px^.ProcPtr;
p.Ext1 := px^.Ext1;
p.Ext2 := px^.Ext2;
end;
9:
begin
if IsRead then
begin
p.ProcPtr := px^.ReadProcPtr;
p.Ext1 := px^.ExtRead1;
p.Ext2 := px^.ExtRead2;
end else
begin
p.ProcPtr := px^.WriteProcPtr;
p.Ext1 := px^.ExtWrite1;
p.Ext2 := px^.ExtWrite2;
end;
end;
else
begin
result := false;
Expand Down Expand Up @@ -11413,6 +11443,20 @@ procedure TPSRuntimeClass.RegisterMethod(ProcPtr: Pointer; const Name: tbtString
FClassItems.Add(p);
end;

procedure TPSRuntimeClass.RegisterMethodName(const Name: tbtstring;
ProcPtr: TPSProcPtr; Ext1, Ext2: Pointer);
var
P: PClassItem;
begin
New(P);
p^.FName := FastUppercase(Name);
p^.FNameHash := MakeHash(p^.FName);
p^.b := 8;
p^.ProcPtr := ProcPtr;
p^.Ext1 := Ext1;
p^.Ext2 := Ext2;
FClassItems.Add(p);
end;

procedure TPSRuntimeClass.RegisterPropertyHelper(ReadFunc,
WriteFunc: Pointer; const Name: tbtString);
Expand Down Expand Up @@ -11482,6 +11526,43 @@ procedure TPSRuntimeClass.RegisterPropertyHelperName(ReadFunc,
FClassItems.Add(p);
end;

procedure TPSRuntimeClass.RegisterPropertyNameHelper(const Name: tbtstring;
ProcPtr: TPSProcPtr; ExtRead1, ExtRead2, ExtWrite1, ExtWrite2: Pointer);
var
P: PClassItem;
begin
New(P);
p^.FName := FastUppercase(Name);
p^.FNameHash := MakeHash(p^.FName);
p^.b := 9;
p^.ReadProcPtr := ProcPtr;
p^.WriteProcPtr := ProcPtr;
p^.ExtRead1 := ExtRead1;
p^.ExtRead2 := ExtRead2;
p^.ExtWrite1 := ExtWrite1;
p^.ExtWrite2 := ExtWrite2;
FClassItems.Add(p);
end;

procedure TPSRuntimeClass.RegisterPropertyNameHelper(const Name: tbtstring;
ProcReadPtr, ProcWritePtr: TPSProcPtr; ExtRead1, ExtRead2, ExtWrite1,
ExtWrite2: Pointer);
var
P: PClassItem;
begin
New(P);
p^.FName := FastUppercase(Name);
p^.FNameHash := MakeHash(p^.FName);
p^.b := 9;
p^.ReadProcPtr := ProcReadPtr;
p^.WriteProcPtr := ProcWritePtr;
p^.ExtRead1 := ExtRead1;
p^.ExtRead2 := ExtRead2;
p^.ExtWrite1 := ExtWrite1;
p^.ExtWrite2 := ExtWrite2;
FClassItems.Add(p);
end;

{ TPSRuntimeClassImporter }

function TPSRuntimeClassImporter.Add(aClass: TClass): TPSRuntimeClass;
Expand Down