3 ms·
You're usually better off using coroutines for this sort of asynchronous programming in Lua. There's a larger overlap between coroutines and continuations than
by silentbicycle 17y ago
You're usually better off using coroutines for this sort of asynchronous programming in Lua. There's a larger overlap between coroutines and continuations than you'd think.
Also, Lua doesn't have macros, at least not in the sense that Lisp and Prolog do. It just has eval.
- scythe 17y ago>You're usually better off using coroutines for this sort of asynchronous programming in Lua. Macros and coroutines don't solve the same problem here. Macros provide wrappers that make "callbacks" implicit; coroutines provide scheduling. >Also, Lua doesn't have macros, at least not in the sense that Lisp and Prolog do. It just has eval. http://metalua.luaforge.net/ http://metalua.luaforge.net/ I object!
- silentbicycle 17y agoI wondered if you meant Metalua. That's a different dialect, like OCaml vs. SML different. Standard Lua doesn't have macros, and the packages I've seen that add them (such as Luma, http://luaforge.net/projects/luma/ http://luaforge.net/projects/luma/) do so via eval. I haven't done that much with Metalua - I don't really feel that Lua's lacking macros is a major problem, really, though I like the author's views on metaprogramming ("Make it obvious when something interesting happens", etc.). I remember looking at it a year or so ago, but didn't get into it. I just gave it a quick stab at porting, and I remember why - "Prerequisites - a 32 bits, little endian CPU" - I tend to switch back and forth between a couple OSs and hardware platforms, and Lua's portability is a big bonus for me. Adding a couple ML-ish features to Lua would be tempting, though.
- infinite8s 17y agoCoroutines are just one-off continuations (ie you can only run them once).
- silentbicycle 17y agoRight. They can be used as one-shot continuations. It doesn't cover all use cases, but a good subset of them. There's a patch by Mike Pall to add coroutine copying for simulating multi-shot continuations, though.