Skip to content

Commit 242c349

Browse files
committed
LOADFFI模块用法换成类似xpcall的错误处理器并提供一个默认的函数
1 parent 942bffd commit 242c349

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

loadFFI.lua

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,27 @@ if SYSTEM=='Linux' then
1010
end
1111
end
1212

13-
---
13+
local function defaultErrorHandler(errInfo)
14+
for i=1,#errInfo do
15+
MSG.errorLog(errInfo[i])
16+
end
17+
end
18+
19+
---A wrapped ffi.load that will try to load FMOD library in different paths with an error handler receiving all error informations
1420
---@param name string name of the library, 'fmod' for 'fmod.dll'|'libfmod.so'
15-
---@return ffi.namespace*
16-
---@overload fun(name:string):result:false,errInfo:string[]
17-
return function(name)
21+
---@param handler? fun(errLog:string[]) will call this if loading failed
22+
---@return ffi.namespace*|false
23+
return function(name,handler)
1824
local errLog={}
1925
for i=1,#path do
2026
local suc,res
2127
suc,res=pcall(ffi.load,STRING.repD(path[i],name))
2228
if suc then
2329
return res
2430
else
25-
table.insert(errLog,"Loading FMOD lib:"..res)
31+
table.insert(errLog,STRING.repD("ffi.load('$1'): $2",name,res))
2632
end
2733
end
28-
return false,errLog
34+
(type(handler)=='function' and handler or defaultErrorHandler)(errLog)
35+
return false
2936
end

0 commit comments

Comments
 (0)