🐛 fix bug of incorrectly searching paths of lib.nas and dynamic libs.

`dylib.dlopen` now only needs file name of dynamic lib, not the real path.
This commit is contained in:
ValKmjolnir
2022-07-29 22:49:50 +08:00
parent fb37283be0
commit ca6cb5daae
12 changed files with 44 additions and 46 deletions
+10 -8
View File
@@ -427,16 +427,18 @@ var dylib=
{
# open dynamic lib.
dlopen: func(libname){
# find dynamic lib from local dir first
if(io.exists(libname))
return __dlopen(libname);
# find dynamic lib through PATH
var envpath=split(os.platform()=="windows"?";":":",unix.getenv("PATH"));
var path=os.platform()=="windows"?["\\","\\module\\"]:["/","/module/"];
# first find ./module
append(envpath,".");
var path=os.platform()=="windows"?"\\module\\":"/module/";
foreach(var p;envpath){
p=[p~path[0]~libname,p~path[1]~libname];
if(io.exists(p[0])){
libname=p[0];
break;
}
if(io.exists(p[1])){
libname=p[1];
p~=path~libname;
if(io.exists(p)){
libname=p;
break;
}
}