BananaOS/test/boot/scripts/10_components.lua

49 lines
1.3 KiB
Lua
Raw Permalink Normal View History

2025-02-21 00:33:21 -05:00
local _, _, status, _ = ...
status(" *- Implementing component functions")
function package.loaded.component.isAvailable(componentType)
if component[componentType] then
return true
end
return false
end
function package.loaded.component.get(address, componentType)
local comp = package.loaded.component.list(componentType)
for a,_ in comp do
if a == address then
return a
else
local s,e = string.find(a,address)
if s == 1 then
return a
end
end
end
return nil, "no such component"
end
function package.loaded.component.getPrimary(componentType)
local prim = component[componentType]
if not prim then
error(string.format("no primary '%s' available", componentType))
end
return prim
end
function package.loaded.component.setPrimary(componentType, address)
if componentType == "filesystem" then
return
end
address = package.loaded.component.get(address:sub(1,5), componentType) -- don't sub
package.loaded.component[componentType] = package.loaded.component.proxy(address)
end
local components = package.loaded.component.list()
status(" *- Setting primary components")
for address, componentType in components do
package.loaded.component.setPrimary(componentType,address)
end