lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Patrick Rapin wrote:
> I think we can resolve the problem by changing a little bit the logic :
> - If the parameter has neither a path nor an extension, transform it
> to cygXXX.dll :
>   ffi.load "png"  => looks for cygpng.dll
> - If the filename has either an extension or a path, pass it verbatim
> to dlopen :
>   ffi,load "kernel32.dll" => finds kernel32.dll in c:\windows\system32
>   ffi.load "./my_lib" => looks for my_lib in current directory
> This makes sense IMHO since the first form is typical in a POSIX
> platform while the second would be expected on a Windows one.

Patrick, please test the attached patch. Thank you!
I'll push the fix as is, if everyone is happy with it.

--Mike
diff --git a/src/lj_clib.c b/src/lj_clib.c
--- a/src/lj_clib.c
+++ b/src/lj_clib.c
@@ -39,21 +39,38 @@ LJ_NORET LJ_NOINLINE static void clib_error_(lua_State *L)
 
 #define clib_error(L, fmt, name)	clib_error_(L)
 
+#if defined(__CYGWIN__)
+#define CLIB_SOPREFIX	"cyg"
+#else
+#define CLIB_SOPREFIX	"lib"
+#endif
+
 #if LJ_TARGET_OSX
 #define CLIB_SOEXT	"%s.dylib"
+#elif defined(__CYGWIN__)
+#define CLIB_SOEXT	"%s.dll"
 #else
 #define CLIB_SOEXT	"%s.so"
 #endif
 
 static const char *clib_extname(lua_State *L, const char *name)
 {
-  if (!strchr(name, '/')) {
+  if (!strchr(name, '/')
+#ifdef __CYGWIN__
+      && !strchr(name, '\\')
+#endif
+     ) {
     if (!strchr(name, '.')) {
       name = lj_str_pushf(L, CLIB_SOEXT, name);
       L->top--;
+#ifdef __CYGWIN__
+    } else {
+      return name;
+#endif
     }
-    if (!(name[0] == 'l' && name[1] == 'i' && name[2] == 'b')) {
-      name = lj_str_pushf(L, "lib%s", name);
+    if (!(name[0] == CLIB_SOPREFIX[0] && name[1] == CLIB_SOPREFIX[1] &&
+	  name[2] == CLIB_SOPREFIX[2])) {
+      name = lj_str_pushf(L, CLIB_SOPREFIX "%s", name);
       L->top--;
     }
   }