Component Registry: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 24: | Line 24: | ||
end | end | ||
end | end | ||
</syntaxhighlight>{{Navbox content}} | </syntaxhighlight> | ||
{{Navbox content}} | |||
Revision as of 23:54, 1 August 2026
The Component Registry allows accessing all currently available Components and is the most convenient way of accessing components.
| Name | Type | Description |
|---|---|---|
:list() |
function() -> (string, userdata), table, nil |
Returns an iterator function that, in each invocation returns a string representing the type of the current component along with the actual userdata instance. |
:getFirst(componentType:string) |
userdata |
Returns the first component of the given componentType or nil if no matching component exists.
|
While :list() looks very intimidating, it can simply be used in a for-loop in place of ipairs(*). The built-in UEFI uses the following code to iterate over all components to find any bootable devices:
local bootables = {}
for compType, elem in components:list() do
print("- " .. compType)
if compType == "massStorage" then
if elem:fileExists("boot.lua") then
-- we found a bootable medium, use it as default if not already set
defaultBoot = defaultBoot == nil and idx or defaultBoot
bootables[idx] = elem
end
idx = idx + 1
end
end