How would you go about making a bidirectional map in Lua? I am new to Lua, and the only way that I can think of is to put every key-value pair in a table, iterate over each pair to add them (key-value swapped) to the original table.
Is there a better way to do this?
I don't think there is a better way (assuming you can handle key/value conflicts). A slightly better way may be to store swapped values when you add a new values to the table (or update/remove an existing value), but the overall idea is the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With