So - the world is a weird place, and lua wraps back around to itself.
I was working on my game, server side, and have been thinking that I really need to do that in lua as well, because the combat routines want to be portable, so they can be used server-side to decide combats, and client-side to show them like a movie.
And if I’m doing server-side lua to host the turns, I may as well go full-bore and do the webserver in lua as well (it was/is in ruby using sinatra right now - highly recommended) so that I can share even more code (in this case, the redis I/O and procedures). So I start digging into lua stuff, and come across:
http://luvit.io/
That is, in a nutshell, node.js (which I like, except I’m not keen on javascript) using lua instead of javascript (neat!). Problem is, there are no redis bindings for it, yet. And I’m thinking of doing my own, but we’re starting to get into yak-shaving territory, not game building.
But - as I was researching things, I came across this thread:
http://lua-list.2524044.n2.nabble.com/ANN-Luvit-Lua-UV-Jit-NodeJS-re-implemented-in-Lua-td7048032.html
That suggests, among other things, that the old callbacks stuff I did, for example in the code above, is sub-optimal - that lua coroutines are the way to go, giving you the power of async callbacks, without the callback confusions/complexity (and I’m getting that big-time).
Problem is - I don’t understand coroutines well enough to actually understand how that would work, and can’t find good examples.
I’d like, very much, for there to be good example code if/when http.get is approved - and if coroutines are the way to go, I’d like to try to get my head wrapped around it and “do it right”.
So - is anyone here lua-savvy enough that you say “oh, yeah - coroutines would do that easy! Look, here’s how…” and be able to post a small example? I think I just need a gentle push. I’ll keep reading, and maybe going back to “normal” coroutine stuff rather than callback related - but if this is easy/trivial for someone already, a good example would be much appreciated.