2 ms·
I don't think it does -- the receive function only takes a timeout[1]. If it did pattern matching, it'd probably take a table of potential patterns, or a table
by silentbicycle 17y ago
I don't think it does -- the receive function only takes a timeout[1]. If it did pattern matching, it'd probably take a table of potential patterns, or a table array of pattern->functions, or somesuch.
After wondering before, I just checked the source. In message.lua, receive just takes an optional timeout. It'd be easy to have it take an optional function argument that tests each message in turn (since it's just a list of messages, modified in place), and returns a true if that message should currently be used. I'll test and submit a patch for it later. Not as flexible as pattern matching, but PM would be better off in the base language. As for integrating Metalua's PM with selective receive, I'm not sure.
[1]: http://concurrentlua.luaforge.net/reference.html