title: LuaLaTeX - string contains an invalid utf-8 sequence
body: <p>I am on Linux Debian and I am trying to print a PDF by extracting some information from my database <code>linux_krozki</code>. To do this I first created my database which has <code>utf8mb4</code> character set and <code>utf8mb4_slovenian_ci</code> collation. </p>
  
  <p>I didn't use <code>utf8</code> character set and <code>utf8_slovenian_ci</code> based on <a href="https://medium.com/@adamhooper/in-mysql-never-use-utf8-use-utf8mb4-11761243e434" rel="nofollow noreferrer">this topic</a>. </p>
  
  <pre><code>MariaDB [(none)]&gt; SHOW CREATE DATABASE linux_krozki;
  +--------------+-------------------------------------------------------------------------------------------------------+
  | Database     | Create Database                                                                                       |
  +--------------+-------------------------------------------------------------------------------------------------------+
  | linux_krozki | CREATE DATABASE `linux_krozki` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_slovenian_ci */ |
  +--------------+-------------------------------------------------------------------------------------------------------+
  </code></pre>
  
  <p>So now I fill the database table <code>skupine</code> with information like this - mind the letter <code>ž</code> in column <code>opombe</code>:</p>
  
  <p><a href="https://i.stack.imgur.com/wUSFD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wUSFD.png" alt="enter image description here"></a> </p>
  
  <p>When I want to compile a PDF document using LuaLaTeX in conjunction with LuaSQL I get an error because of that character <code>ž</code>:</p>
  
  <pre><code>! String contains an invalid utf-8 sequence.
  l.1 Mo
      en dostop za invalide, prepoved kajenja.
  l.39        Opombe: &amp; \luadirect{skupina_opombe(arg[3])}
  </code></pre>
  
  <p>This is weird, because my source files <code>predracun.lua</code> and <code>predracun.tex</code> are both UTF-8 encoded:</p>
  
  <p>Here is <code>predracun.tex</code> source file: </p>
  
  <pre><code>\documentclass[12pt]{article}
  
  % package for UTF-8 encoding 
  \usepackage[utf8]{luainputenc}
  
  % package for lua   
  \usepackage{luacode}
      \directlua{dofile('predracun.lua')}
  
  \begin{document}
      \begin{tabular}{rp{11cm}}
          ŽžĐđŠšĆćČč\\
          \luadirect{skupina_opombe()}\\
      \end{tabular}
  \end{document}   
  </code></pre>
  
  <p>And here is <code>predracun.lua</code> source file: </p>
  
  <pre><code>function skupina_opombe ()
      package.cpath = package.cpath .. ";/usr/lib/x86_64-linux-gnu/lua/5.3/luasql/mysql.so"
      luasql = require('luasql.mysql')
      env = assert (luasql.mysql())
      con = assert (env:connect("linux_krozki","ziga","Slovenija123"))
  
      cur = assert (con:execute("SELECT opombe FROM skupine WHERE id_skupine = (SELECT id_skupine FROM predracuni WHERE id_interesa =1);"))
  
      vnos = cur:fetch ({}, "a")
  
      tex.print(
          string.format([[%s]], vnos.opombe)
      )
  
  end 
  </code></pre>
  
  <p>I also explicitly specified <code>\usepackage[utf8]{luainputenc}</code> in the <code>predracun.tex</code>. So how come I still get the error? Mind that error isn't triggered by speciall characters <code>ŽžĐđŠšĆćČč</code> but by a <code>\luadirect{skupina_opombe()}</code> which reads from a database...</p>
  
  <p><strong>PS:</strong> I wasn't sure if I should publish this topic on TeX communitiy as it is a hybrid of TeX and programming language Lua.</p>