Table macros?
How do you feel about a table macro? Something like:
macro_rules! insert_sequence {
(@replace_expr $_t:tt $sub:expr) => {$sub};
(@count $($tts:tt),*) => {0 $(+ insert_sequence!(@replace_expr $tts 1))*};
($table:ident => $head:tt $(,)? $($tail:expr),*) => {
$table.set(insert_sequence!(@count $($tail),*), $head)?;
insert_sequence!($table => $($tail),*)
};
($t:table =>) => {};
}
So obviously this is pretty rough, and I think procedural macros tend to be more readable, but what do you think about the idea in principle?
I've just been having an fiddly time making tables that have a bunch of different types together, and I think a macro would be a straightforward way to make it more ergonomic. There are two sticky points: you have to pass the lua state, and all the 'set' methods return result, so it's not obvious to me if something as ergonomic as vec![] would be possible.
Another possibly smarter way to do this might be to implement ToLua for all tuples.
Sorry, not yet in plans. I'll plan to add macros for userdata.