Avoid some Lua stack leaks in the UI code.

(Closes #3000)
(Closes #3001)
(Closes #2999)
(Closes #2997)
(Closes #2996)