Have trouble with printing UTF-8 stings or saving file with UTF-8 names on Windows?
lua-native is for you:
native.encode()
converts from UTF-8 string to system current encoding on Windows.
On other system (Mac/Linux...) it just return the 1st argument.
local native = require('native')
local mbcs = native.encode(utf8string)
print(mbcs) -- prints correctly in Windows/Mac/Linux... console...
native.decode()
converts from system default encoding to UTF-8 on Windows.
On other system (Mac/Linux...) it just return the 1st argument.
local native = require('native')
local lfs = require('lfs')
function attrdir(utf8_path)
local native_path = native.encode(utf8_path)
local utf8_filenames = {}
for file in lfs.dir(native_path) do
if file ~= "." and file ~= ".." then
utf8_filenames[#utf8_filenames+1] = native.decode(file)
end
end
return utf8_filenames
end
- You need Lua for Windows installed. It will set a
LUA_DEV
environment variable for you. - Setup a visual studio dll empty project named
nconv
, add header path$(LUA_DEV)\include
and lib path$(LUA_DEV)\lib
to options, and link withlua5.1.lib
. - Build the nconv.dll, and copy to
$(LUA_DEV)\clibs
. - Run the
test.lua
for test.
Yes, build is boring, just get a copy of prebuild binary from the download area.
- Add to rock repos?