saman9074
saman9074

Reputation: 45

How do I create a file with utf-8 format in lua?

I've created a file with the following code in lua:

local f = io.open("./data/myfile.html", "w") 
f:write(text) 
f:close()

String is stored in the file is Persian. When the file is opened letters are illegible. Like the screenshot below:

image

How I fix it?

Upvotes: 1

Views: 1537

Answers (1)

Vlad
Vlad

Reputation: 5847

Lua doesn't care about encoding. If your Lua source texts are already in utf-8, then you should just add "meta" tag in html "head" section.

<head>
  <meta charset="UTF-8">
</head>

If your html version is earlier than html5, then use older construct:

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>

Upvotes: 2

Related Questions