-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use Zig idioms #605
Comments
Having used zig to develop for WASM4, one thing to keep in mind for the I mostly wanted to chime in and say this was a good idea! Good luck with the PR 🙂 |
In my opinion there are a couple important benefits to keeping the default bindings boring and unidiomatic.
Obviously this is kinda subjective, and we've made exceptions in the past (as in Odin where the author of the language contributed the bindings). In general though, I think I'd rather see users writing and distributing their own bindings that use advanced syntax. There are a couple different Rust crates for WASM-4 for example. |
I think one thing we could do though is lowercase the constants. So, |
From the perspective of someone familiar with Zig features, the wasm4 examples provide code that looks like it was directly translated from C rather than written with Zig's stdlib and features in mind.
std.PackedIntSlice
To use
DRAW_COLORS
as an example, instead of using a*u16
to represent what is actually 4 fields, you can usestd.PackedIntSlice
:Framebuffer could be similarly improved using
std.PackedIntSlice
.This REALLY simplifies things like the
pixel()
example in the basic drawing docs.int-backed enums
All of the prefixed constants could be represented much more nicely with
enum(u8)
orenum(u32)
. To use buttons as an example:slices
While
trace
wrapstraceUtf8
nicely, the same idiom is not extended todiskr
anddiskw
.tracef
std.fmt
and writers are to zig asprintf
andFILE
pointers are to c. Implementing a buffered writer wrapper overtrace
would be simple, idiomatic, and allow zig users a lot of convenience when interacting with the stdlib.Conclusion
I am happy to implement all of these features and submit a PR, as a new user of wasm4 and a first-time contributor I figured the responsible thing would be to post an issue for discussion first!
The text was updated successfully, but these errors were encountered: