Compile scratch projects to WASM
- Rust (v1.65.0 or later)
- the
wasm32-unknown-unknown
target (rustup target add wasm32-unknown-unknown
) - wasm-bindgen-cli (
cargo install -f wasm-bindgen-cli
) - wasm-opt (install binaryen using whatever package manager you use)
./build.sh -pVW # use -dVW for a debug build without optimisation
You may need to run chmod +x build.sh
if it says it doesn't have permission.
The build script has additonal configuration options; run ./build.sh -h
for info on these.
If you experience runtime stack overflow errors in debug mode, try using the -O
option to enable wasm-opt.
name | number of bytes | optional? | description |
---|---|---|---|
redraw_requested | 4 | no | if a redraw has been requested or not |
thread_num | 4 | no | the number of currently running threads |
vars | 16 * number of global & local variables | yes | see variables |
sprite_info | 80 * number of sprites (i.e. target num - 1 ) |
yes | see sprite info |
threads | 4 * thread_num | no | imdices of the next step funcs of currently running threads |
byte | type | name | description |
---|---|---|---|
0-7 | f64 | x | x pos |
8-15 | f64 | y | y pos |
16-19 | f32 | pen_color | hue of pen (0-100) |
20-23 | f32 | pen_saturation | saturation of pen (0-100) |
24-27 | f32 | pen_brightness | value of pen (0-100) |
28-31 | f32 | pen_transparency | transparency of pen (0-100) |
32-47 | f32(x4) | pen_color4f | rgba color of pen [(0-1)x4] |
48-55 | f64 | pen_size | pen radius |
56 | i8 | pen_down | 1 if pen down else 0 |
57 | i8 | visible | 1 if sprite is visible else 0 |
58-59 | - | padding | reserved |
60-63 | i32 | costume | the current costume number, 0-indexed |
64-71 | f64 | size | sprite size |
72-79 | f64 | rotation | sprite rotation, in scratch angles (0 = up, 90 = right) |
byte | description |
---|---|
0-3 | identifies the type of the variable |
4-7 | padding |
8-15 | identifies the value of the variable |
value | type | variable value type | value description |
---|---|---|---|
0x00 | float64 | f64 |
a float |
0x01 | bool64 | i64 |
an integer - only the least significant bit is used |
0x02 | externref string (64 bit) | i64 |
wrapped to a 32 bit pointer to an externref value in the anyref table |
0x03 | int64 | i64 |
a 64-bit integer |
All values should be guaranteed to have the maximum possible alignment for that value type. Unused/padding bytes are not guaranteed to have any specific values and may be overwritten.
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.