4 ms·
I wish there were a statically typed language with Lua's stackful coroutines and the ability to manually yield. It seems that Lua and Ruby are the only two well
by nonbirithm 5y ago
I wish there were a statically typed language with Lua's stackful coroutines and the ability to manually yield. It seems that Lua and Ruby are the only two well-known languages with that kind of stackful coroutine. And also, LuaJIT has proven that they can be implemented in a performant way, so I'm not sure if performance is a valid obstacle to implementing them more often.
Even languages like Go and Java with proper fibers don't allow you to yield where you want to, and the yield points are inserted by the compiler/runtime instead.
A use case which I can't seem to reimplement without stackful coroutines is "inline" blocking input, as found in the source code of old roguelikes. It makes the game logic easier to follow since you don't have to rearchitect the entire engine to be event-based, and can instead yield between an "update" and "draw" coroutine each frame.
msg("Do you want your possessions identified?)
local yes = yes_or_no()
if yes then
identify_possessions()
end
I was honestly very surprised when I first realized that this is not how most graphical turn-based games are programmed.
- gpderetta 5y agoI'm a huge fan of lua-like coroutines. Even though I have never written a line of lua I read all their papers on the topic. Among the statically compiled languages, there are a few options in C++ for stackful coroutines, for example boost.context. There is still a chance that they might make it into the standard at some point.