Fix crashes from unchecked uses of lua_tostring. Closes #1588.