This repository has been archived by the owner on Dec 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
require.lua
47 lines (47 loc) · 1.6 KB
/
require.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package.cpath=package.cpath..';'..love.filesystem.getSaveDirectory()..'/lib/?.so;'..'?.dylib'
local loaded={}
local errorCount={}
return function(libName)
local require=require
local arch='unknown'
local success,res
if SYSTEM=='Web' then
return
end
if SYSTEM=='macOS' then
require=package.loadlib(libName..'.dylib','luaopen_'..libName)
success,res=pcall(require)
else
if SYSTEM=='Android' and not loaded[libName] then
local platform=(function()
local p=io.popen('uname -m')
arch=p:read('*a'):lower()
p:close()
if arch:find('v8') and not arch:find('v8l') or arch:find('64') then
return 'arm64-v8a'
else
return 'armeabi-v7a'
end
end)()
local data=love.filesystem.read('data','libAndroid/'..platform..'/'..libName..'.so')
if data then
love.filesystem.write('lib/'..libName..'.so',data)
end
loaded[libName]=true
end
success,res=pcall(require,libName)
end
if success and res then
return res
else
if not next(errorCount) then
MES.new('info',"Architecture: "..arch)
end
errorCount[libName]=(errorCount[libName] or 0)+1
if errorCount[libName]==1 then
MES.new('error',"Cannot load "..libName..": "..tostring(res):gsub('[\128-\255]+','??'))
else
MES.new('error',("Cannot load %s (x%d)"):format(libName,errorCount[libName]))
end
end
end