LUA and UTF-8 encoding
Hi, very grateful if anyone could help me with the following:
I'm using LUA, and want to load a script with Russian characters in the script file.
The file is saved in UTF-8 encoding, and will not load when I try to call luaL_loadbuffer on the file once it has been read into memory.
Currently I just read the entire script-file into a char[] array, then call luaL_loadbuffer on the array - which works perfectly for standard encoding.
I may just be being very dumb, but if anyone could tell me the correct procedure for reading a file in UTF-8 encoding and then running that file in memory I would be extremely grateful.
Many thanks
The Average Joe
cannot really help but providing a link: http://lua-users.org/wiki/LuaUnicode
hope it clarifies your problem.
hope it clarifies your problem.
Thank you for the response and the link.
I am really hoping that someone here has used a LUA script to hold foreign-language text strings (saved in UTF-8 encoding) and successfully read them in their code, and is willing to post a little bit of sample code on how they accomplished this.
I am really hoping that someone here has used a LUA script to hold foreign-language text strings (saved in UTF-8 encoding) and successfully read them in their code, and is willing to post a little bit of sample code on how they accomplished this.
The link above implies that it should work if all your non-ASCII values are within string literals, but not if they are in the code itself. Have you looked at the error code that luaL_loadbuffer returns?
Quote:Original post by Average_Joe
Thank you for the response and the link.
I am really hoping that someone here has used a LUA script to hold foreign-language text strings (saved in UTF-8 encoding) and successfully read them in their code, and is willing to post a little bit of sample code on how they accomplished this.
I can tell you that it works as you stated. I can use characters like ç ã ó inside LUA strings. And I'm not doing anything special. Just edit your file with something as ordinary as notepad.
Quote:Original post by Average_Joe
The file is saved in UTF-8 encoding, and will not load when I try to call luaL_loadbuffer on the file once it has been read into memory.
that's the problem I think.
Quote:The file is saved in UTF-8 encoding.
All non-ascii character codes must be within strings - make sure your utf-8 file doesn't have a BOM.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement