love-loader/lib/chroot.lua

56 lines
1.2 KiB
Lua

return function(ll)
ll.mdir = nil
ll.mgme = nil
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 :)
ffi.cdef [[
int PHYSFS_mount(const char *, const char *, int);
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
end
function ll._umntdir(dir)
liblove.PHYSFS_unmount(dir)
end
end
local baseReq = '?.lua;?/init.lua;'
function ll.mount(gme)
local mdir = gme.base .. gme.dir
love.filesystem.setRequirePath(
mdir .. '/?.lua;'
.. mdir .. '/?/init.lua;'
.. baseReq
)
if ll._mntdir(mdir)
then ll.mdir, ll.mgme = mdir, gme
else error('Cannot mount '..mdir)
love.filesystem.setRequirePath(baseReq)
end
end
function ll.umount()
if ll.mdir ~= nil then
ll._umntdir(ll.mdir)
ll.mdir = nil
end
end
end