forked from alesan99/mari0_ae
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.lua
90 lines (77 loc) · 2.21 KB
/
utils.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
require("love.system")
---------------------
---- https stuff ----
---------------------
function hardpreload(module, path)
local full_path = module .. "/" .. path
-- read from .love
local data = love.filesystem.read("libs/" .. full_path)
-- write to save directory
love.filesystem.setIdentity("mari0_libs")
if not love.filesystem.getInfo(module) then
love.filesystem.createDirectory(module)
end
love.filesystem.write(full_path, data)
-- preload module
package.preload[module] = package.loadlib(love.filesystem.getSaveDirectory() .. "/" .. full_path, "luaopen_" .. module)
love.filesystem.setIdentity("mari0")
end
function softpreload(module, path)
love.filesystem.setIdentity("mari0_libs")
local full_path = module .. "/" .. path
package.preload[module] = package.loadlib(love.filesystem.getSaveDirectory() .. "/" .. full_path, "luaopen_" .. module)
love.filesystem.setIdentity("mari0")
end
local function loadhttps(loadfunc)
-- preload https module from bundled libs folder
-- to be removed in LÖVE 12.0
local system_os = love.system.getOS()
if system_os == "Windows" and jit.arch == "x64" then
loadfunc("https", "win64.dll")
elseif system_os == "Windows" and jit.arch == "x86" then
loadfunc("https", "win32.dll")
elseif system_os == "Linux" then
loadfunc("https", "linux.so")
elseif system_os == "OS X" then
loadfunc("https", "osx.so")
end
https_status, https = pcall(require, "https")
if not https_status then
https = nil
end
end
function hardloadhttps()
loadhttps(hardpreload)
end
function softloadhttps()
loadhttps(softpreload)
end
--------------
---- misc ----
--------------
function hasvalue(tab, val)
for i, value in pairs(tab) do
if value == val then
return true
end
end
return false
end
function kpairs(t, keys)
local i = 0
return function()
i = i + 1
if keys[i] then
return keys[i], t[keys[i]]
end
end
end
function isPaused(source)
return pausedaudio and hasvalue(pausedaudio, source)
end
function isStopped(source)
return not source:isPlaying() and not isPaused(source)
end
function isActive(source)
return source:isPlaying() or isPaused(source)
end