Correctly handle UTF-8 in custom lua scripts. Closes #1189.