Last active
March 17, 2021 23:23
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__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