lots and LOTS of stuff

i lost track sorry
This commit is contained in:
Ponali
2025-09-14 13:37:41 +02:00
parent ef0ffa1886
commit d3d5f21ab1
14 changed files with 272 additions and 124 deletions
+19 -10
View File
@@ -1,21 +1,24 @@
local log = require("log")
local fs = require("filesystem")
local modulePath = "/halyde/kernel/modules"
local modules = assert(fs.list(modulePath))
local moduleList = assert(fs.list(modulePath))
local modules = {}
local moduleTypes = {}
local function loadModule(modName)
local moduleData = assert(require(fs.concat(modulePath, modName)), "Module did not return anything!") -- TODO: Make this not actually throw an error, rather put something in the log and move on
table.remove(modules, table.find(modules, modName))
local moduleData = modules[modName]
table.remove(moduleList, table.find(moduleList, modName))
if not moduleData then return end
if not moduleData.check() then
return
end
if moduleData.dependencies then
for _, dependency in pairs(moduleData.dependencies) do
if table.find(modules, dependency) then
if table.find(moduleList, dependency) then
loadModule(dependency)
elseif table.find(modules, dependency .. ".lua") then
elseif table.find(moduleList, dependency .. ".lua") then
loadModule(dependency .. ".lua")
else
for typeLookupDrvName, typeLookupDrvType in pairs(moduleTypes) do
@@ -33,16 +36,22 @@ local function loadModule(modName)
end
end
for _, modName in pairs(modules) do -- Get all the module types
local moduleData = assert(require(fs.concat(modulePath, modName)), "Module did not return anything!") -- TODO: Make this not actually throw an error, rather put something in the log and move on
for _, modName in pairs(moduleList) do -- Get all the module types
local moduleData = require(fs.concat(modulePath, modName)) -- TODO: Make this not actually throw an error, rather put something in the log and move on
if type(moduleData)~="table" then
log.add(string.format("[modload: %s] Module returned invalid type (%s) - skipping",modName,type(moduleData)),"error")
goto continue
end
modules[modName]=moduleData
if moduleData.type then
--print(moduleData.type)
moduleTypes[modName] = moduleData.type -- Not the other way around because there can be multiple modules of the same type, but there can't be multiple entries with the same key
end
::continue::
end
while modules[1] do
if modules[1]:sub(-1, -1) ~= "/" then -- Check if it's not a directory. If it is, it might be module config
loadModule(modules[1])
while moduleList[1] do
if moduleList[1]:sub(-1, -1) ~= "/" then -- Check if it's not a directory. If it is, it might be module config
loadModule(moduleList[1])
end
end