I wrote a blog post about making a generic method dispatch helper for 'foreach'.
It's more of a novelty than something really worth adding to code. It's better to just use 'for x in all(XS)' instead.
Here's the mini summary:
function callm(method, ...) local params={...} return function(o) if type(o)=="table" then local m=o[method] if type(m)=="function" then m(o,unpack(params)) end end end end function _draw() cls() foreach(drawable, callm("draw", 11)) end |
Check it out: https://kallanreed.com/2021/10/17/pico-8-generic-dispatch-with-parameters/
[Please log in to post a comment]