Added component.isAvailable()
The function checks if a component of a specified type exists.
This commit is contained in:
+16
-5
@@ -63,7 +63,7 @@ function compLib.list(componentType)
|
|||||||
__call = function(self)
|
__call = function(self)
|
||||||
i, value = next(self, i)
|
i, value = next(self, i)
|
||||||
return i, value
|
return i, value
|
||||||
end
|
end,
|
||||||
})
|
})
|
||||||
return componentList
|
return componentList
|
||||||
end
|
end
|
||||||
@@ -81,7 +81,9 @@ function compLib.invoke(address, funcName, ...)
|
|||||||
--ocelot.log("Invoking " .. funcName .. " from " .. address)
|
--ocelot.log("Invoking " .. funcName .. " from " .. address)
|
||||||
if componentlib.additions[address] then
|
if componentlib.additions[address] then
|
||||||
--ocelot.log("vcomponent")
|
--ocelot.log("vcomponent")
|
||||||
if not componentlib.additions[address].proxy[funcName] then error("no such method") end
|
if not componentlib.additions[address].proxy[funcName] then
|
||||||
|
error("no such method")
|
||||||
|
end
|
||||||
return componentlib.additions[address].proxy[funcName](...)
|
return componentlib.additions[address].proxy[funcName](...)
|
||||||
else
|
else
|
||||||
return LLcomponent.invoke(address, funcName, ...)
|
return LLcomponent.invoke(address, funcName, ...)
|
||||||
@@ -95,21 +97,30 @@ function compLib.get(address)
|
|||||||
end
|
end
|
||||||
for currentAddress, name in compLib.list() do
|
for currentAddress, name in compLib.list() do
|
||||||
if currentAddress:find("^" .. address) then
|
if currentAddress:find("^" .. address) then
|
||||||
return (currentAddress)
|
return currentAddress
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return nil, "full address not found"
|
return nil, "full address not found"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function compLib.isAvailable(componentType)
|
||||||
|
checkArg(1, componentType, "string")
|
||||||
|
if LLcomponent.list(componentType)() then
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Add main component proxies to the library
|
-- Add main component proxies to the library
|
||||||
setmetatable(compLib, {
|
setmetatable(compLib, {
|
||||||
["__index"] = function(_, item)
|
["__index"] = function(_, item)
|
||||||
if compLib.list(item)() then
|
if LLcomponent.list(item)() then
|
||||||
return compLib.proxy(compLib.list(item)())
|
return compLib.proxy(compLib.list(item)())
|
||||||
else
|
else
|
||||||
return compLib[item]
|
return compLib[item]
|
||||||
end
|
end
|
||||||
end
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
return compLib
|
return compLib
|
||||||
|
|||||||
Reference in New Issue
Block a user