forked from 26F-Studio/Zenitha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequire.lua
45 lines (41 loc) · 1.41 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
package.cpath=
package.cpath.. -- Windows, .\?.dll; .\loadall.dll
';'..love.filesystem.getSaveDirectory()..'/lib/lib?.so'.. -- Android, %save%/lib/lib?.so
';./?.so'.. -- Linux
';?.dylib' -- OS X
package.cpath=package.cpath:gsub('\\','/')
local _androidPlatform='armeabi-v7a'
if love.system.getOS()=='Android' then
local p=io.popen('uname -m')
if p then
local arch=p:read('*a'):lower()
p:close()
if arch:find('v8') or arch:find('64') then
_androidPlatform='arm64-v8a'
end
end
end
local loaded={}
---A more powerful require function, allow loading dynamic libraries
---@param libName string
return function(libName)
local _require=require
if love.system.getOS()=='OS X' then
_require=package.loadlib(libName..'.dylib','luaopen_'..libName)
elseif love.system.getOS()=='Android' then
if not loaded[libName] then
love.filesystem.write(
'lib/lib'..libName..'.so',
love.filesystem.read('data','libAndroid/'.._androidPlatform..'/lib'..libName..'.so')
)
loaded[libName]=true
end
end
-- arg #2: if system is OS X, it's nil, otherwise it's 'libName'
local success,res=pcall(_require,(not love.system.getOS()=='OS X' or nil) and libName)
if success and res then
return res
else
MSG.new('error',"Cannot load "..libName..": "..res)
end
end