Skip to content

Commit

Permalink
ASync http get/post
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Mar 13, 2024
1 parent e292e8b commit 959f99b
Show file tree
Hide file tree
Showing 11 changed files with 638 additions and 321 deletions.
14 changes: 13 additions & 1 deletion Source/Simba.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@
<PackageName Value="LCL"/>
</Item5>
</RequiredPackages>
<Units Count="127">
<Units Count="130">
<Unit0>
<Filename Value="Simba.lpr"/>
<IsPartOfProject Value="True"/>
Expand Down Expand Up @@ -979,6 +979,18 @@
<Filename Value="script/imports/simba.import_compress.pas"/>
<IsPartOfProject Value="True"/>
</Unit126>
<Unit127>
<Filename Value="simba.http_async.pas"/>
<IsPartOfProject Value="True"/>
</Unit127>
<Unit128>
<Filename Value="script/imports/simba.import_async.pas"/>
<IsPartOfProject Value="True"/>
</Unit128>
<Unit129>
<Filename Value="simba.input_async.pas"/>
<IsPartOfProject Value="True"/>
</Unit129>
</Units>
</ProjectOptions>
<CompilerOptions>
Expand Down
100 changes: 37 additions & 63 deletions Source/forms/simba.functionlistform.pas
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ TFunctionListState = record
procedure SetSimbaNodeShouldBeHidden(S: String; Hidden: Boolean);

procedure AddSimbaNodes;

procedure ArrangeBaseNodes;
procedure ArrangeSimbaNodes;

function CompareNodes(A, B: TTreeNode): Integer;
public
Expand Down Expand Up @@ -777,26 +776,27 @@ procedure TSimbaFunctionListForm.AddSimbaNodes;
ParentNode.Visible := False;
end;

FSimbaNode.AlphaSort();
//FSimbaNode.AlphaSort();
FSimbaNode.Expanded := True; // This needs to be on main thread it seems?

ArrangeSimbaNodes();

FTreeView.Loading := False;
FTreeView.EndUpdate();
end;

procedure TSimbaFunctionListForm.ArrangeBaseNodes;
procedure TSimbaFunctionListForm.ArrangeSimbaNodes;
var
BaseNode: TTreeNode;
Cur: Integer = 0;

procedure MoveToTop(const NodeText: String);
var
Node: TTreeNode;
begin
Node := BaseNode.FindNode(NodeText);
Node := FSimbaNode.FindNode(NodeText);
if not Assigned(Node) then
begin
DebugLn('ArrangeBaseNodes: Not found: ' + NodeText);
DebugLn('ArrangeSimbaNodes: Not found: ' + NodeText);
Exit;
end;

Expand All @@ -805,62 +805,36 @@ procedure TSimbaFunctionListForm.ArrangeBaseNodes;
end;

begin
BaseNode := FSimbaNode.FindNode('Base');
if (BaseNode = nil) then
Exit;

MoveToTop('Integer');
MoveToTop('Byte');
MoveToTop('Char');
MoveToTop('Boolean');

MoveToTop('Int8');
MoveToTop('Int16');
MoveToTop('Int32');
MoveToTop('Int64');
MoveToTop('UInt8');
MoveToTop('UInt16');
MoveToTop('UInt32');
MoveToTop('UInt64');

MoveToTop('NativeInt');
MoveToTop('NativeUInt');
MoveToTop('SizeInt');
MoveToTop('SizeUInt');
MoveToTop('PtrInt');
MoveToTop('PtrUInt');

MoveToTop('Single');
MoveToTop('Double');
MoveToTop('Currency');

MoveToTop('ByteBool');
MoveToTop('WordBool');
MoveToTop('LongBool');
MoveToTop('EvalBool');

MoveToTop('AnsiChar');
MoveToTop('WideChar');

MoveToTop('string');
MoveToTop('ShortString');
MoveToTop('AnsiString');
MoveToTop('WideString');
MoveToTop('UnicodeString');

MoveToTop('Pointer');
MoveToTop('ConstPointer');

MoveToTop('TByteArray');
MoveToTop('TBooleanArray');
MoveToTop('TSingleArray');
MoveToTop('TDoubleArray');
MoveToTop('TIntegerArray');
MoveToTop('TInt64Array');
MoveToTop('TStringArray');

MoveToTop('T2DIntegerArray');
MoveToTop('T2DStringArray');
MoveToTop('Base');
MoveToTop('Math');
MoveToTop('Color Math');
MoveToTop('File');
MoveToTop('String');
MoveToTop('Random');
MoveToTop('Timing');
MoveToTop('DateTime');
MoveToTop('TBox');
MoveToTop('TBoxArray');
MoveToTop('TPoint');
MoveToTop('TPointArray');
MoveToTop('T2DPointArray');
MoveToTop('TCircle');
MoveToTop('TQuad');
MoveToTop('Finder');
MoveToTop('Input');
MoveToTop('Target');
MoveToTop('Image');
MoveToTop('Debug Image');
MoveToTop('Match Template');
MoveToTop('Matrix');
MoveToTop('DTM');
MoveToTop('TWindowHandle');
MoveToTop('Process');
MoveToTop('JSON');
MoveToTop('Encoding');
MoveToTop('Web');
MoveToTop('ASync');
MoveToTop('Misc');
end;

function TSimbaFunctionListForm.CompareNodes(A, B: TTreeNode): Integer;
Expand Down
139 changes: 139 additions & 0 deletions Source/script/imports/simba.import_async.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
unit simba.import_async;

{$i simba.inc}

interface

uses
Classes, SysUtils,
simba.base, simba.script_compiler;

procedure ImportASync(Compiler: TSimbaScript_Compiler);

implementation

uses
lptypes, ffi,
simba.input, simba.http_async, simba.input_async;

procedure _LapeASyncHTTP_Get1(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
ASyncHTTP.Get(PString(Params^[0])^, TASyncHTTPFinishedEvent(Params^[1]^));
end;

procedure _LapeASyncHTTP_Get2(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
ASyncHTTP.Get(PString(Params^[0])^, PString(Params^[1])^, TASyncHTTPFinishedEvent(Params^[2]^));
end;

procedure _LapeASyncHTTP_Post1(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
ASyncHTTP.Post(PString(Params^[0])^, PString(Params^[1])^, TASyncHTTPFinishedEvent(Params^[2]^));
end;

procedure _LapeASyncHTTP_Post2(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
ASyncHTTP.Post(PString(Params^[0])^, PString(Params^[1])^, PStringArray(Params^[2])^, TASyncHTTPFinishedEvent(Params^[3]^));
end;

(*
ASyncMouse.Move
---------------
> procedure ASyncMouse.Move(Input: TSimbaInput; Dest: TPoint; Accuracy: Double = 1);
*)
procedure _LapeASyncMouse_Move(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
ASyncMouse.Move(PSimbaInput(Params^[0])^, PPoint(Params^[1])^, PDouble(Params^[2])^);
end;

(*
ASyncMouse.ChangeDest
---------------------
> procedure TASyncMouse.ChangeDest(Dest: TPoint);
*)
procedure _LapeASyncMouse_ChangeDest(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
ASyncMouse.ChangeDest(PPoint(Params^[0])^);
end;

(*
ASyncMouse.IsMoving
-------------------
> function TASyncMouse.IsMoving: Boolean;
*)
procedure _LapeASyncMouse_IsMoving(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PBoolean(Result)^ := ASyncMouse.IsMoving();
end;

(*
ASyncMouse.WaitMoving
---------------------
> procedure TASyncMouse.WaitMoving;
*)
procedure _LapeASyncMouse_WaitMoving(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
ASyncMouse.WaitMoving();
end;

(*
ASyncMouse.Stop
---------------
> procedure TASyncMouse.Stop;
*)
procedure _LapeASyncMouse_Stop(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
ASyncMouse.Stop();
end;

procedure ImportASync(Compiler: TSimbaScript_Compiler);
begin
with Compiler do
begin
// Empty "namespaces"
addGlobalType('record end;', 'ASyncMouse');
addGlobalType('record end;', 'ASyncHTTPClient');

ImportingSection := 'ASync';
addGlobalFunc('procedure ASyncMouse.Move(Input: TInput; Dest: TPoint; Accuracy: Double = 1); static;', @_LapeASyncMouse_Move);
addGlobalFunc('procedure ASyncMouse.ChangeDest(Dest: TPoint); static;', @_LapeASyncMouse_ChangeDest);
addGlobalFunc('function ASyncMouse.IsMoving: Boolean; static;', @_LapeASyncMouse_IsMoving);
addGlobalFunc('procedure ASyncMouse.WaitMoving; static;', @_LapeASyncMouse_WaitMoving);
addGlobalFunc('procedure ASyncMouse.Stop; static;', @_LapeASyncMouse_Stop);

addGlobalFunc(
'procedure ASyncMouse.Move(Input: TInput; Dest: TPoint; Accuracy: Double = 1); static; override;', [
'begin',
' if Input.Target.IsDefault() then',
' try',
' Input.Target := System.Target;',
' {$IFDECL Result}Result:={$ENDIF}inherited();',
' finally',
' Input.Target := [];',
' end else',
' {$IFDECL Result}Result:={$ENDIF}inherited();',
'end;'
]);

addGlobalType([
'record',
' URL: String;',
' Response: EHTTPStatus;',
' Data: String;',
' Headers: TStringArray;',
' Exception: String;',
' TimeUsed: Double;',
'end;'],
'TASyncHTTPResult');

addGlobalType('procedure(constref Result: TASyncHTTPResult) of object', 'TASyncHTTPFinishedEvent', FFI_DEFAULT_ABI);
addGlobalFunc('procedure ASyncHTTPClient.Get(URL: String; OnFetched: TASyncHTTPFinishedEvent); static; overload;', @_LapeASyncHTTP_Get1);
addGlobalFunc('procedure ASyncHTTPClient.Get(URL, DestFile: String; OnFetched: TASyncHTTPFinishedEvent); static; overload;', @_LapeASyncHTTP_Get2);
addGlobalFunc('procedure ASyncHTTPClient.Post(URL, PostData: String); static; overload;', @_LapeASyncHTTP_Post1);
addGlobalFunc('procedure ASyncHTTPClient.Post(URL, PostData: String; Headers: TStringArray); static; overload;', @_LapeASyncHTTP_Post2);

ImportingSection := '';
end;
end;

end.
Loading

0 comments on commit 959f99b

Please sign in to comment.