love-loader/lib/chroot.lua

56 lines
1.2 KiB
Lua
Raw Normal View History

2022-05-30 07:33:56 +00:00
return function(ll)
ll.mdir = nil
ll.mgme = nil
2022-07-08 18:09:39 +00:00
if love.getVersion() >= 12 then
function ll._mntdir(dir)
return love.filesystem.mountFullPath(dir, '/')
end
function ll._umntdir(dir)
love.filesystem.unmountFullPath(dir)
end
else
local ffi = require 'ffi'
local liblove = ffi.os == 'Windows'
and ffi.load 'love'
or ffi.C -- thanks to slime73, Love2D developer :)
2022-07-08 18:09:39 +00:00
ffi.cdef [[
int PHYSFS_mount(const char *, const char *, int);
2022-07-08 18:09:39 +00:00
int PHYSFS_unmount(const char *);]]
-- FIXME: Bug may appear in Linux. Recompile Love2D or use official PPA.
function ll._mntdir(dir)
return liblove.PHYSFS_mount(dir, '/', 0) ~= 0
2022-07-08 18:09:39 +00:00
end
function ll._umntdir(dir)
liblove.PHYSFS_unmount(dir)
2022-07-08 18:09:39 +00:00
end
end
local baseReq = '?.lua;?/init.lua;'
2022-05-30 07:33:56 +00:00
function ll.mount(gme)
local mdir = gme.base .. gme.dir
2022-07-08 18:09:39 +00:00
love.filesystem.setRequirePath(
mdir .. '/?.lua;'
.. mdir .. '/?/init.lua;'
.. baseReq
)
2022-07-08 18:09:39 +00:00
if ll._mntdir(mdir)
then ll.mdir, ll.mgme = mdir, gme
else error('Cannot mount '..mdir)
love.filesystem.setRequirePath(baseReq)
end
2022-05-30 07:33:56 +00:00
end
function ll.umount()
if ll.mdir ~= nil then
2022-07-08 18:09:39 +00:00
ll._umntdir(ll.mdir)
2022-05-30 07:33:56 +00:00
ll.mdir = nil
end
end
end