forked from Hyperion/HyperionOS
finished vfs for a while
This commit is contained in:
@@ -1,37 +1,33 @@
|
||||
--:Minify:--
|
||||
-- :Minify:--
|
||||
local kernel = ...
|
||||
local cache = {}
|
||||
kernel.searchpaths = {
|
||||
"/lib/?.lua",
|
||||
"/lib/?",
|
||||
"/usr/lib/?.lua",
|
||||
"/usr/lib/?",
|
||||
"/usr/local/lib/?.lua",
|
||||
"/usr/local/lib/?",
|
||||
"?.lua",
|
||||
"?"
|
||||
"/lib/?.lua", "/lib/?", "/usr/lib/?.lua", "/usr/lib/?",
|
||||
"/usr/local/lib/?.lua", "/usr/local/lib/?", "?.lua", "?"
|
||||
}
|
||||
|
||||
function require(module,...)
|
||||
if cache[module] then
|
||||
return cache[module]
|
||||
end
|
||||
function require(module, ...)
|
||||
if cache[module] then return cache[module] end
|
||||
local modpath = module:gsub("%.", "/")
|
||||
local failed = {}
|
||||
for _, path in ipairs(kernel.searchpaths) do
|
||||
local full_path = string.gsub(path, "%?", modpath)
|
||||
if full_path:sub(1,1)~="/" then
|
||||
full_path=kernel.currentTask.cwd..full_path
|
||||
local full_path = string.replace(path, "?", modpath)
|
||||
if full_path:sub(1, 1) ~= "/" then
|
||||
full_path = kernel.currentTask.cwd .. full_path
|
||||
end
|
||||
|
||||
if kernel.vfs.exists(full_path) then
|
||||
if kernel.vfs.type(full_path)=="directory" then
|
||||
if kernel.vfs.type(full_path) == "directory" then
|
||||
full_path = full_path .. "/init"
|
||||
end
|
||||
|
||||
if kernel.vfs.exists(full_path) then
|
||||
local handle = kernel.vfs.open(full_path, "r")
|
||||
local file_content = kernel.vfs.read(handle, 1024 * 1024 * 4)
|
||||
kernel.vfs.close(handle)
|
||||
return assert(load(file_content, full_path, "t", kernel._U))(...)
|
||||
|
||||
return
|
||||
assert(load(file_content, full_path, "t", kernel._U))(...)
|
||||
else
|
||||
table.insert(failed, full_path)
|
||||
end
|
||||
@@ -39,5 +35,6 @@ function require(module,...)
|
||||
table.insert(failed, full_path)
|
||||
end
|
||||
end
|
||||
|
||||
error("Module not found: " .. module .. " (searched paths: " .. table.concat(failed, ", ") .. ")")
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user