Push dictionary? How to achieve this in Lua?

Viewed 560

Say I have this dictionary in Lua

places = {dest1 = 10, dest2 = 20, dest3 = 30}

In my program I check if the dictionary has met my size limit in this case 3, how do I push the oldest key/value pair out of the dictionary and add a new one?

places["newdest"] = 50

--places should now look like this, dest3 pushed off and newdest added and dictionary has kept its size

places = {newdest = 50, dest1 = 10, dest2 = 20}
2 Answers
Related