craftos2-lua
libxev
craftos2-lua | libxev | |
---|---|---|
1 | 6 | |
5 | 1,618 | |
- | - | |
7.0 | 8.1 | |
about 1 month ago | 11 days ago | |
C | Zig | |
GNU General Public License v3.0 or later | MIT License |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
craftos2-lua
-
Show HN: Async tasks in 350 lines of C
> Do you have examples of any async code returning values without “objects” or compiler magic?
Lua coroutines represent a yieldable computation, but given a coroutine object, you can't await it or retrieve a return value from it. The only things you can do with a coroutine are check its status and resume it. So how do asynchronous computations return values in Lua?
It's simple: don't create an extra coroutine around it. If you're already in a yieldable coroutine, then you can call the yielding function directly. Nested yields will bubble up, and from the caller's perspective you just call a function and it returns a value.
Doing this from Lua is a bit of compiler/interpreter magic, but some modified Lua interpreters support yieldable C functions that can also perform yieldable calls [0]. This requires some due diligence on the part of the caller, making sure to bubble up yields from the inner function and also pass down resumes until it completes (you need to add a state for "this function call yielded"). But it uses no promises, futures or channels.
[0]: https://github.com/MCJack123/craftos2-lua/blob/89dcba94c28be... (lua_getctx returns whether you're being resumed from a yield, and expects you to have pushed your own state to the Lua stack if you need any.)
libxev
-
libxev: A cross-platform, high-performance event loop
io_uring support is obviously great & excellent, fulfills the "high performance" part well.
i was not expecting "Wasm + WASI" support at all. that's very cool. implementation is wasi_poll.zig (https://github.com/mitchellh/libxev/blob/main/src/backend/wa...). not to be unkind, but this makes me wonder very much if WASI is already missing the mark, if polling is the solution offered.
gotta say, this is some very understandable clean code. further enhancing my sense that i really ought be playing with zig.
- Show HN: Async tasks in 350 lines of C
-
Epoll: The API that powers the modern internet (2022)
You might be interested in a pure Zig implementation of these primitives by Mitchell in his libxev library: https://github.com/mitchellh/libxev
-
Zig: The Modern Alternative to C
https://github.com/mitchellh/libxev
- one from the Tigerbeetle DB
- Libxev: A cross-platform, high-performance event loop
What are some alternatives?
zigcoro - A Zig coroutine library
unzig - Zig with Unused Variables
async_io_uring - An event loop in Zig using io_uring and coroutines
sokol-tools - Command line tools for use with sokol headers
http.zig - An HTTP/1.1 server for zig
zig-pico - Not so scuffed Zig project for using the Raspberry Pi Pico SDK
mach - zig game engine & graphics toolkit
aviary.sh - Minimal distributed configuration management in bash
bash2048 - Bash implementation of 2048 game
bashttpd - A web server written in bash
bitcoin-bash-tools - Set of bitcoin-related bash functions
otp - Erlang/OTP