Check the return value from lua_open()

It always fails when running under valgrind because valgrind does not
implement mmap functionality that LuaJIT requires.
Fix a use-after-free when a SubsEditCtrl is destroyed while the thesaurus is loading
Don't convert encoding names to lowercase when writing files

Not only is it unnecessary, but it actively breaks the mapping of
user-friendly encoding names in the Export dialog to the real encoding
names.

Closes #1789.
Fix memory leak in aegisub.text_extents on Windows

The old object returned by SelectObject has to be made active again
before the DC is destroyed or it doesn't get deleted.