summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2014-11-05 09:50:08 +0000
committerDaniel Kolesa <d.kolesa@samsung.com>2014-11-05 09:50:08 +0000
commit1ea00af7e9a0a7bb373c71d50c02f29868de9517 (patch)
tree4cce40f1b9089a123b95c0f04fa6939d00212a80 /src/bin
parenta5e3e0d0d44f51b2c28a89413fdddf552fe636f3 (diff)
elua: support foo.dll and libfoo.dll patterns on Windows in util + better errors
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/elua/core/util.lua50
1 files changed, 39 insertions, 11 deletions
diff --git a/src/bin/elua/core/util.lua b/src/bin/elua/core/util.lua
index 44a5042bea..d4175e1e22 100644
--- a/src/bin/elua/core/util.lua
+++ b/src/bin/elua/core/util.lua
@@ -66,24 +66,52 @@ end
66local loaded_libs = {} 66local loaded_libs = {}
67local loaded_libc = {} 67local loaded_libc = {}
68 68
69local load_lib_win = function(libname, ev)
70 local succ, v
71 if not ev or ev == "" then
72 succ, v = pcall(ffi.load, libname)
73 if not succ then
74 succ, v = pcall(ffi.load, "lib" .. libname)
75 end
76 else
77 succ, v = pcall(ffi.load, ev .. "\\" .. libname .. ".dll")
78 if not succ then
79 succ, v = pcall(ffi.load, ev .. "\\lib" .. libname .. ".dll")
80 end
81 end
82 if not succ then
83 return false, v
84 end
85 return true, v
86end
87
88local load_lib = function(libname, ev)
89 local succ, v
90 if ffi.os == "Windows" then
91 succ, v = load_lib_win(libname, ev)
92 elseif not ev or ev == "" then
93 succ, v = pcall(ffi.load, libname)
94 else
95 local ext = (ffi.os == "OSX") and ".dylib" or ".so"
96 succ, v = pcall(ffi.load, ev .. "/lib" .. libname .. ext)
97 end
98 if not succ then
99 return false, v
100 end
101 return true, v
102end
103
69-- makes sure we only keep one handle for each lib 104-- makes sure we only keep one handle for each lib
70-- reference counted 105-- reference counted
71M.lib_load = function(libname) 106M.lib_load = function(libname)
72 local lib = loaded_libs[libname] 107 local lib = loaded_libs[libname]
73 if not lib then 108 if not lib then
74 local ev = os.getenv("ELUA_" .. libname:upper() .. "_LIBRARY_PATH") 109 local ev = os.getenv("ELUA_" .. libname:upper() .. "_LIBRARY_PATH")
75 if not ev or ev == "" then 110 local succ, v = load_lib(libname, ev)
76 lib = ffi.load(libname) 111 if not succ then
77 else 112 error(v, 2)
78 if ffi.os == "Windows" then
79 lib = ffi.load(ev .. "\\" .. libname .. ".dll")
80 elseif ffi.os == "OSX" then
81 lib = ffi.load(ev .. "/lib" .. libname .. ".dylib")
82 else
83 lib = ffi.load(ev .. "/lib" .. libname .. ".so")
84 end
85 -- XXX: perhaps check here if it's loaded and fallback to default?
86 end 113 end
114 lib = v
87 loaded_libs[libname] = lib 115 loaded_libs[libname] = lib
88 loaded_libc[libname] = 0 116 loaded_libc[libname] = 0
89 end 117 end