Skip to content

Instantly share code, notes, and snippets.

@ceifa
Last active March 17, 2021 23:23
Show Gist options
  • Save ceifa/71721b30cd81fe40a56d0ac6207cd34f to your computer and use it in GitHub Desktop.
Save ceifa/71721b30cd81fe40a56d0ac6207cd34f to your computer and use it in GitHub Desktop.
a poor coded and not tested virtual filesystem made by me, but can be useful in future
__DANGER_filesystem = {}
file = {}
function file.exists(path)
for filek, filev in ipairs(__DANGER_filesystem) do
if string.find(filev.path, path, 0, true) then return true end
end
return false
end
function file.findPairs(pattern, path)
local k = 0
local iter = function(t, last)
for filek = k + 1, #__DANGER_filesystem do
if not path or string.find(__DANGER_filesystem[filek].path, path, 0, true) and string.find(__DANGER_filesystem[filek].path, pattern) then
return (last or 0) + 1, __DANGER_filesystem[filek].path
end
end
end
return iter, nil, 0
end
function file.find(pattern, path)
local fnext = file.findPairs(pattern, path)
local _, v = fnext()
return v
end
function file.read(path)
for filek, filev in ipairs(__DANGER_filesystem) do
if string.find(filev.path, path, 0, true) then return filev.content end
end
end
function file.isFile(path)
for filek, filev in ipairs(__DANGER_filesystem) do
if string.find(filev.path, path, 0, true) and filev.path == path then return true end
end
return false
end
package.searchers = {
package.searchers[1],
function(moduleName)
local content = file.read(moduleName) or file.read(moduleName .. "/init.lua")
if content then return load(content) end
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment