Avoid some Lua stack leaks in the UI code.

(Closes #3000)
(Closes #3001)
(Closes #2999)
(Closes #2997)
(Closes #2996)

Yes, I've taken the liberty to assume that all of those crashes were caused by that leak.