mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-08-18 14:29:04 +02:00
* After run parameter
This commit is contained in:
parent
a3a1ba5d28
commit
85ab0dc64d
@ -16,10 +16,17 @@ Type
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
{ TWASIHostApplication }
|
{ TWASIHostApplication }
|
||||||
TStartCallBack = Reference to Function (Sender : TObject; aDescriptor : TStartDescriptor) : Boolean;
|
TBeforeStartCallBack = Reference to Function (Sender : TObject; aDescriptor : TStartDescriptor) : Boolean;
|
||||||
|
TAfterStartCallBack = Reference to Procedure (Sender : TObject; aDescriptor : TStartDescriptor);
|
||||||
|
|
||||||
|
TBeforeStartEvent = Procedure (Sender : TObject; aDescriptor : TStartDescriptor; var aAllowRun : Boolean) of object;
|
||||||
|
TAfterStartEvent = Procedure (Sender : TObject; aDescriptor : TStartDescriptor) of object;
|
||||||
|
|
||||||
|
|
||||||
TWASIHostApplication = class(TBrowserApplication)
|
TWASIHostApplication = class(TBrowserApplication)
|
||||||
private
|
private
|
||||||
|
FAfterStart: TAfterStartEvent;
|
||||||
|
FBeforeStart: TBeforeStartEvent;
|
||||||
FEnv: TPas2JSWASIEnvironment;
|
FEnv: TPas2JSWASIEnvironment;
|
||||||
FExported: TWASIExports;
|
FExported: TWASIExports;
|
||||||
FMemoryDescriptor : TJSWebAssemblyMemoryDescriptor;
|
FMemoryDescriptor : TJSWebAssemblyMemoryDescriptor;
|
||||||
@ -36,8 +43,9 @@ Type
|
|||||||
Constructor Create(aOwner : TComponent); override;
|
Constructor Create(aOwner : TComponent); override;
|
||||||
Destructor Destroy; override;
|
Destructor Destroy; override;
|
||||||
// Load and start webassembly. If DoRun is true, then Webassembly entry point is called.
|
// Load and start webassembly. If DoRun is true, then Webassembly entry point is called.
|
||||||
// If aCallback is specified, then it is called prior to calling run.
|
// If aBeforeStart is specified, then it is called prior to calling run, and can disable running.
|
||||||
Procedure StartWebAssembly(aPath: string; DoRun : Boolean = True; aCallBack : TStartCallback = Nil);
|
// If aAfterStart is specified, then it is called after calling run. It is not called is running was disabled.
|
||||||
|
Procedure StartWebAssembly(aPath: string; DoRun : Boolean = True; aBeforeStart : TBeforeStartCallback = Nil; aAfterStart : TAfterStartCallback = Nil);
|
||||||
// Initial memory descriptor
|
// Initial memory descriptor
|
||||||
Property MemoryDescriptor : TJSWebAssemblyMemoryDescriptor Read FMemoryDescriptor Write FMemoryDescriptor;
|
Property MemoryDescriptor : TJSWebAssemblyMemoryDescriptor Read FMemoryDescriptor Write FMemoryDescriptor;
|
||||||
// Import/export table descriptor
|
// Import/export table descriptor
|
||||||
@ -47,6 +55,10 @@ Type
|
|||||||
// Exported functions. Also available in start descriptor.
|
// Exported functions. Also available in start descriptor.
|
||||||
Property Exported : TWASIExports Read FExported;
|
Property Exported : TWASIExports Read FExported;
|
||||||
Property RunEntryFunction : String Read FRunEntryFunction Write FRunEntryFunction;
|
Property RunEntryFunction : String Read FRunEntryFunction Write FRunEntryFunction;
|
||||||
|
// Called after webassembly start was run. Not called if webassembly was not run.
|
||||||
|
Property AfterStart : TAfterStartEvent Read FAfterStart Write FAfterStart;
|
||||||
|
// Called before running webassembly. If aAllowRun is false, running is disabled
|
||||||
|
Property BeforeStart : TBeforeStartEvent Read FBeforeStart Write FBeforeStart;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -91,7 +103,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TWASIHostApplication.StartWebAssembly(aPath: string; DoRun : Boolean = True; ACallBack: TStartCallback = Nil);
|
procedure TWASIHostApplication.StartWebAssembly(aPath: string; DoRun: Boolean;
|
||||||
|
aBeforeStart: TBeforeStartCallback = nil; aAfterStart: TAfterStartCallback = nil);
|
||||||
|
|
||||||
Var
|
Var
|
||||||
ImportObj : TJSObject;
|
ImportObj : TJSObject;
|
||||||
@ -109,13 +122,21 @@ Var
|
|||||||
// These 2 prevent running different instances simultaneously.
|
// These 2 prevent running different instances simultaneously.
|
||||||
FExported:=Res.Exported;
|
FExported:=Res.Exported;
|
||||||
WasiEnvironment.Instance:=Module.Instance;
|
WasiEnvironment.Instance:=Module.Instance;
|
||||||
if Assigned(aCallBack) then
|
if Assigned(aBeforeStart) then
|
||||||
DoRun:=aCallBack(Self,Res) and DoRun;
|
DoRun:=aBeforeStart(Self,Res) and DoRun;
|
||||||
|
if Assigned(FBeforeStart) then
|
||||||
|
FBeforeStart(Self,Res,DoRun);
|
||||||
if DoRun then
|
if DoRun then
|
||||||
|
begin
|
||||||
if FRunEntryFunction='' then
|
if FRunEntryFunction='' then
|
||||||
Res.Exported.Start
|
Res.Exported.Start
|
||||||
else
|
else
|
||||||
TProcedure(Res.Exported[RunEntryFunction])();
|
TProcedure(Res.Exported[RunEntryFunction])();
|
||||||
|
if Assigned(aAfterStart) then
|
||||||
|
aAfterStart(Self,Res);
|
||||||
|
if Assigned(FAfterStart) then
|
||||||
|
FAfterStart(Self,Res)
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user