* Wasm Timer host demo

This commit is contained in:
Michael Van Canneyt 2025-05-27 09:04:15 +02:00
parent 93a49d64d1
commit 8d87707e2d
3 changed files with 152 additions and 0 deletions

View File

@ -0,0 +1,17 @@
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Webassembly Timer Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="wasmtimerhost.js"></script>
</head>
<body>
<h3>Webassembly Timer Demo</h3>
<script>
rtl.showUncaughtExceptions=true;
window.addEventListener("load", rtl.run);
</script>
<div id="pasjsconsole"></div>
</body>
</html>

View File

@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="wasmtimerhost"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<CustomData Count="6">
<Item0 Name="BrowserConsole" Value="1"/>
<Item1 Name="MaintainHTML" Value="1"/>
<Item2 Name="Pas2JSProject" Value="1"/>
<Item3 Name="PasJSLocation" Value="$NameOnly($(ProjFile))"/>
<Item4 Name="PasJSWebBrowserProject" Value="1"/>
<Item5 Name="RunAtReady" Value="1"/>
</CustomData>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<Units>
<Unit>
<Filename Value="wasmtimerhost.lpr"/>
<IsPartOfProject Value="True"/>
</Unit>
<Unit>
<Filename Value="index.html"/>
<IsPartOfProject Value="True"/>
<CustomData Count="1">
<Item0 Name="PasJSIsProjectHTMLFile" Value="1"/>
</CustomData>
</Unit>
<Unit>
<Filename Value="../../../packages/wasm-utils/src/wasm.pas2js.timer.pas"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<Target FileExt=".js">
<Filename Value="wasmtimerhost"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<OtherUnitFiles Value="../../../packages/wasm-utils/src"/>
<UnitOutputDirectory Value="js"/>
</SearchPaths>
<Parsing>
<SyntaxOptions>
<AllowLabel Value="False"/>
<UseAnsiStrings Value="False"/>
<CPPInline Value="False"/>
</SyntaxOptions>
</Parsing>
<CodeGeneration>
<TargetOS Value="browser"/>
</CodeGeneration>
<Linking>
<Debugging>
<GenerateDebugInfo Value="False"/>
<UseLineInfoUnit Value="False"/>
</Debugging>
</Linking>
<Other>
<CustomOptions Value="-Jeutf-8 -Jirtl.js -Jc -Jminclude"/>
<CompilerPath Value="$(pas2js)"/>
</Other>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View File

@ -0,0 +1,39 @@
program wasmtimerhost;
{$mode objfpc}
uses
BrowserConsole, BrowserApp, WASIHostApp, JS, Classes, SysUtils, Web, wasm.pas2js.timer;
type
{ TMyApplication }
TMyApplication = class(TWASIHostApplication)
protected
FTimerAPI : TWasmTimerAPI;
procedure DoRun; override;
public
constructor Create(aOwner : TComponent); override;
end;
procedure TMyApplication.DoRun;
begin
StartWebAssembly('timerdemo.wasm');
end;
constructor TMyApplication.Create(aOwner: TComponent);
begin
inherited Create(aOwner);
FTimerAPI:=TWasmTimerAPI.Create(WasiEnvironment);
FTimerAPI.LogAPICalls:=True;
end;
var
Application : TMyApplication;
begin
Application:=TMyApplication.Create(nil);
Application.Initialize;
Application.Run;
end.