Skip to content

use module unicode flag for using unicode on dir and attributes#1

Open
sonoro1234 wants to merge 32 commits intospacewander:masterfrom
sonoro1234:unicode
Open

use module unicode flag for using unicode on dir and attributes#1
sonoro1234 wants to merge 32 commits intospacewander:masterfrom
sonoro1234:unicode

Conversation

@sonoro1234
Copy link
Copy Markdown
Contributor

@sonoro1234 sonoro1234 commented Feb 16, 2017

local lfs = require"lfs_ffi"
lfs.unicode = true
for file in lfs.dir([[c:/luaGL/frames_anima/luajit_test/]]) do print(file);print(file:byte(1,#file)) end

things left mkdir, chdir ,set correct MAX_PATH and do winx64 also

Also corrected a problem when compiling with mingw64 (32 bits) where _findfirst32 is exported as _findfirst
Solution was trying with pcall

Appveyor test is failing for x64 but I only changed x32

@spacewander
Copy link
Copy Markdown
Owner

First of all, thanks for your pull request.

Unfortunately, the Windows support of this luafilesystem is far from perfect. To be honest, I consider this luafilesystem is just a toy project.

The root cause is, Windows (and other OS) deeply use macros to hide the platform difference, and LuaJIT FFI can't detect these macros.

Take _stat as an example. Here is a piece of sys/stat.h from Windows:

/*
 * We have to have same name for structure and the fuction so as to do the
 * macro magic.we need the structure name and function name the same.
 */
#define __stat64    _stat64

#ifdef _USE_32BIT_TIME_T
#define _fstat      _fstat32
#define _fstati64   _fstat32i64
#define _stat       _stat32
#define _stati64    _stat32i64
#define _wstat      _wstat32
#define _wstati64   _wstat32i64

#else
#define _fstat      _fstat64i32
#define _fstati64   _fstat64
#define _stat       _stat64i32
#define _stati64    _stat64
#define _wstat      _wstat64i32
#define _wstati64   _wstat64

#endif

The _stat is either _stat32 or _stat64i32, depended on the value of _USE_32BIT_TIME_T. However, _USE_32BIT_TIME_T is a macro, which is invisible in LuaJIT FFI.

We could make a guess. With pcall, we cound guess again and again. But the solution is far from perfect. Admittedly, the vanilla luafilesystem works better in such situation.

@sonoro1234
Copy link
Copy Markdown
Contributor Author

Yes but vanilla luafilesystem is not using unicode in windows. There is a pull request for this but it seems unattended!!

@sonoro1234
Copy link
Copy Markdown
Contributor Author

also according to https://msdn.microsoft.com/es-es/library/14h5k7ff.aspx
_stat64 is not dependent on _USE_32BIT_TIME_T

@spacewander
Copy link
Copy Markdown
Owner

@sonoro1234
I just replace _stat64i32 to _stat64, thanks for your advice!

@sonoro1234
Copy link
Copy Markdown
Contributor Author

In case you use windows: How are you dealing with chinese caracters in file names or paths with lfs?

@spacewander
Copy link
Copy Markdown
Owner

Actually I am a server-side programmer. I use LuaJIT within OpenResty. If I have to handle unicode characters, I perfer to write scripts in Python 3 or Ruby, which have good unicode support.
Sorry for no useful information given.

Comment thread lfs_ffi.lua Outdated
Comment thread lfs_ffi.lua Outdated
Comment thread lfs_ffi.lua
Comment thread lfs_ffi.lua Outdated
@spacewander
Copy link
Copy Markdown
Owner

@sonoro1234
I have applied your fix as commit 1a99db2 and updated the fix to support LuaJIT 2.0 in 9c519dc

Comment thread lfs_ffi.lua Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants