Warning This project is still in its infancy. Interfaces are liable to change with each release until v1.0.
A Godot extension allowing for loading and interacting with WebAssembly (Wasm) modules from GDScript via the Wasmer WebAssembly runtime.
Please refer to the Godot Wasm wiki for guides, FAQs, class documentation, etc.
Godot Wasm can be used as a GDExtension/GDNative addon or Godot module. See the Installation wiki page for full instructions.
Using Godot Wasm involves the following.
- Create a WebAssembly (Wasm) module using a language of your choice. See FAQ for more information.
- Create a new Godot Wasm instance
var wasm = Wasm.new()
- Read your Wasm module bytecode
var bytecode = FileAccess.open("res://my_module.wasm", FileAccess.READ)
- Compile and instantiate your Wasm module using Godot Wasm via
wasm.load(bytecode)
- Call functions exported by the Wasm module
wasm.function("my_function", [])
See the Usage wiki page for full instructions.
- A small subset of WASI bindings are provided to the Wasm module by default. These can be overridden by the imports supplied on module instantiation. The guest Wasm module has no access to the host machines filesystem, etc. Pros for this are simplicity and increased security. Cons include not being able to generate truly random numbers (without a workaround) or run Wasm modules created in ways that require a larger set of WASI bindings e.g. TinyGo (see relevant issue).
- Only
int
andfloat
return values are supported. While workarounds could be used, this limitation is because the only concrete types supported by Wasm are integers and floating point. - A default empty
args
parameter forfunction(name, args)
can not be supplied. DefaultArray
parameters in GDNative seem to retain values between calls. Calling methods of this addon without expected arguments produces undefined behaviour. This is reliant on godotengine/godot-cpp#209. - Web/HTML5 export is not supported (see #15 and #18).
There have been numerous discussions around modding/sandboxing support for Godot. Some of those are included below.
- Proposal: Implement a sandbox mode
- Issue Add support for WebAssembly plugins and scripts
- Proposal Add WASM (WASI) host support (including, but not limited to, the HTML5 target)
- Proposal: Add a method to disallow using all global classes in a particular GDScript
- Pull Request: Added globals disabled feature to GDScript class