summaryrefslogtreecommitdiff
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
parenta5e3e0d0d44f51b2c28a89413fdddf552fe636f3 (diff)
downloadefl-1ea00af7e9a0a7bb373c71d50c02f29868de9517.tar.gz
elua: support foo.dll and libfoo.dll patterns on Windows in util + better errors
-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
local loaded_libs = {}
local loaded_libc = {}
+local load_lib_win = function(libname, ev)
+ local succ, v
+ if not ev or ev == "" then
+ succ, v = pcall(ffi.load, libname)
+ if not succ then
+ succ, v = pcall(ffi.load, "lib" .. libname)
+ end
+ else
+ succ, v = pcall(ffi.load, ev .. "\\" .. libname .. ".dll")
+ if not succ then
+ succ, v = pcall(ffi.load, ev .. "\\lib" .. libname .. ".dll")
+ end
+ end
+ if not succ then
+ return false, v
+ end
+ return true, v
+end
+
+local load_lib = function(libname, ev)
+ local succ, v
+ if ffi.os == "Windows" then
+ succ, v = load_lib_win(libname, ev)
+ elseif not ev or ev == "" then
+ succ, v = pcall(ffi.load, libname)
+ else
+ local ext = (ffi.os == "OSX") and ".dylib" or ".so"
+ succ, v = pcall(ffi.load, ev .. "/lib" .. libname .. ext)
+ end
+ if not succ then
+ return false, v
+ end
+ return true, v
+end
+
-- makes sure we only keep one handle for each lib
-- reference counted
M.lib_load = function(libname)
local lib = loaded_libs[libname]
if not lib then
local ev = os.getenv("ELUA_" .. libname:upper() .. "_LIBRARY_PATH")
- if not ev or ev == "" then
- lib = ffi.load(libname)
- else
- if ffi.os == "Windows" then
- lib = ffi.load(ev .. "\\" .. libname .. ".dll")
- elseif ffi.os == "OSX" then
- lib = ffi.load(ev .. "/lib" .. libname .. ".dylib")
- else
- lib = ffi.load(ev .. "/lib" .. libname .. ".so")
- end
- -- XXX: perhaps check here if it's loaded and fallback to default?
+ local succ, v = load_lib(libname, ev)
+ if not succ then
+ error(v, 2)
end
+ lib = v
loaded_libs[libname] = lib
loaded_libc[libname] = 0
end