Lua will be 30 this year
lua.org
lua.org
Lua is an embedded language and I think most users who want compatibility run or forked Lua 5.1, which is from 2006
It’s not clear to me that Lua in 1995 was better than JavaScript in 1995
Back in time when I messed with Lua [1], I needed a version of `pairs` that returns keys in the sorted order. Lua-users has a page for that [2], so I looked it up, and found that it has a subtle but important enough bug---it relies on `__orderedIndex` stored in the original table, which never gets updated nor GCed. I'm sure many enough people had been and will be tripped up by this snippet.
[1] So much that I had written a type checker for Lua: https://github.com/devcat-studio/kailua/
The correct way to do this is as follows. First you collect all keys and sort them as usual, and then return an iterator function that contains those keys as an upvalue. Essentially you need to create a single-use `pairs` function that holds all necessary states.
[1] You can't insert a key during the iteration, but removing an existing key is guaranteed to work correctly, no matter if you've already past the deleted key or not: https://www.lua.org/manual/5.4/manual.html#pdf-next
Then again its just syntax..