-
-
Notifications
You must be signed in to change notification settings - Fork 247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Characters with accents in profile path break Lua's require
on Windows
#5425
Comments
To confirm, you're making use of this feature to load your scripts? |
@vadi2 |
I got two reports about this, first one was early this year, so this applies to earlier versions of Mudlet as well. |
The package installed then is called |
The code that enables this feature is here, and we have a lot of functions already for working around Windows & i18n issues. Since we're passing this to the Lua VM - try using the same solution I developed already for hunspell which is also a C library: https://github.com/Mudlet/Mudlet/pull/2758/files#diff-a4fc43e16d0ada6ab826b586dbc8c8600ac838f7558a4fd7c7434db135f384e1R5213 |
Ok, I see how this works now. Mudlet populates additional paths to Lua (in utf8 already). Then once I call the I will try out what happens if I provide an absolute path to lua file instead. The other thing you provided doesn't look like something I could use, or I'm not sure how I could use that. I don't control where the files are located, the non-ascii character in path comes from windows user folder name. |
Try 'manging' the path using that function - it could be that Lua passes the utf8 path to Windows C API which then does not understand it. |
Ah, I get the point now, you say to copy the files somewhere with no non-ascii characters. But that's weird, I'd have to copy them outside even the windows user folder, don't think that's OK, firstly that may trigger some permissions problem, secondly I don't want to modify content of someone's hard drive. And copying to windows temp folder may not be wise too as it may be periodically cleared by some software |
Ok, didn't notice your previous comment, I'm writing from my mobile. That function you made creates a windiws "short path" right? But I have to do this from a lua script, can I do all that from there? Or i may prepare a version of mudlet that mangles these path and give it to that useless that has that issue |
Yeah the latter, try making a PR with that change - and the bots will generate links which you can test with the the users in question :) |
I just found out that you can add custom module loaders to Lua, from a Lua script. I made one that simply loads a file using io.open, using absolute path, and loading this as module. Basically bypassing any built in path search. Couldn't test it yet, but I should have access to Windows 10 machine later today, so I'll try to replicate and see if that custom loader works. If it does then that is an issue of Lua C code. The default Lua loader is a small C function that uses *char and there's some magic going on in there on these strings, maybe that's where it breaks |
Aaah, sorry, I misunderstood what |
Just tested on Windows 10 codepage I am able to |
@Delwing did you test with production or development version of mudlet? |
Just as stated - 4.12.0. So latest release. |
That's exactly the version Sławek tested it with as well... damn, so that issue probably depends on not only the system version but something else as well... may be hard to fix :-/ |
My user directory is without accents, but again... tried to put accents in directory name as well, still working. |
IIRC The problem boils down to the fact that I think(!) the Windows API has two methods to works with filenames and paths, a (narrow) 8-bit encoding one - which varies depending on where in the world the PC is set up for and a (wide) 16-bit (UTF-16) one which Windows calls "Unicode". Unless things are carefully done the default method used is the narrow one and I think that is what the Lua library / external install of Lua will use on Windows - and that does not work well for non-ASCII characters (including those in a user's home directory) on that OS. I think somewhere in our C++ code we load our own Lua script files using Lua's C (binary library) function |
Ah, this also helps a little to explain it - it is talking about : http://lua-users.org/wiki/LoadLibrary and starts off:
Of course, we are using Lua 5.1 so we are indeed using the narrow (this calls it "ANSI") Windows API function |
@SlySven Yes, some stuff is loaded different, it uses short paths translated from normal paths, it was a workaround for this exact issue. And I think you are right about 8-bit and Unicode paths in windows api. The problem is that we do have a proxy layer for all file-handling Lua functions (utf8_filenames.lua) that is supposed to translate the internally used utf8 strings into encoding that is currently used in Windows. Apparently, this is not always working properly. As @Delwing said - it works fine for him on wibdows 10, but I know two guys for whom it doesn't. So there must be some additional unknown variable into this problem. |
Let's try. See solution in #5425 (comment). |
We have https://wiki.mudlet.org/w/Manual:Miscellaneous_Functions#getWindowsCodepage - can you test with people who have the issue vs who don't to see if there's a difference? |
Kind of workaround popped into my head, while someone asked me question about this of one of Discords. You can add something like: package.path = package.path .. ";C:\\scripts\\?.lua" and then you will be able to require files from that directory |
This happens when
require()
is used in Lua, like this for example:In the screenshot you see Lua throwing that error multiple times, failing in multiple
require
commands while trying to load other parts of the script.Got that issue reported from two people, one named Sławek and other named Łukasz (obviously, both naming their Windows uer like this). Creating a new Windows user without the accent character fixed the issue.
This happens with latest version, but I got it first reported in the beginning of this year, so the problem is there for longer.
I searched the issues tab and the only similar thing I found was this:
#1616
The text was updated successfully, but these errors were encountered: