Beef language bindings for WASM-4 — a fantasy game console for building small games in WebAssembly. Wasm4Beef provides a complete binding layer over the WASM-4 API and includes a build script to compile your Beef project into a .wasm cartridge.
- Full bindings to the WASM-4 API via the
Wasm4class - A simple
Game<T>base class withStart()andUpdate()lifecycle hooks - Pre-configured build scripts for compiling to WebAssembly
- Hot-reload support via the
w4CLI
[AlwaysInclude]
class MyGame : Game<MyGame>
{
protected override void Start()
{
Wasm4.Trace("Hello!");
}
protected override void Update()
{
Wasm4.Text("Hello world!", 35, 10);
}
}A complete working example is available in the Sample/ directory.
If you'd prefer to set up a project from scratch rather than using the sample, follow these steps.
Download and install the WASI SDK for your platform. Set variable WASI_SDK_PATH to your WASI SDK path.
In Beef IDE, add this library as a remote workspace dependency, or clone it alongside your project and add it as a local dependency.
Add the following Wasm32 configuration block to your workspace's BeefSpace.toml:
[Configs.Debug.Wasm32]
PreprocessorMacros = ["BF_CRT_DISABLE"]
TargetTriple = "wasm32-unknown-unknown"
BfSIMDSetting = "None"
BfOptimizationLevel = "Og"
AllocType = "CRT"
RuntimeKind = "Disabled"
ReflectKind = "Minimal"
EnableObjectDebugFlags = falseAdd the following to your project's BeefProj.toml. This wires up the post-build step that links your compiled object into a .wasm cartridge, and configures the w4 CLI as the debug runner:
[Configs.Debug.Wasm32]
PostBuildCmds = ["$(ProjectDir Wasm4)/build_debug.bat $(TargetPath) $(TargetDir)/$(ProjectName).wasm $(ProjectDir Wasm4)/imports.txt"]
DebugCommand = "w4"
DebugCommandArguments = "run --hot $(TargetDir)/$(ProjectName).wasm"In your project settings, change the Project Type from ConsoleApplication to Library.
Once built, the w4 CLI will launch your cartridge automatically if you run via the Beef debugger. You can also run it manually:
w4 run --hot path/to/YourGame.wasmThe --hot flag enables hot-reloading, so changes rebuild and reload without restarting.
- Beef Language (latest)
- WASI SDK
- WASM-4 CLI (
w4)