How to create a multi-channel dynamic routing plugin based on simple events (Lua DSP Script?)

Suppose we have a 12 input and 12 output channels inside a track.
How can you handle dynamic channel re-routing inside the track with a plugin?

For example, if you want to dynamically re-route not NULL input channels to outputs sequentially: if only odd inputs are null then we will have the first 6 output channels dynamically connected to the even input channels.

You could write a LADSPA, LV2 plugin or even use Cabbage with Csound but maybe a Lua script (DSP Scripts) can be more effective and customizable on the fly?