OC-PsychOS/modules/base/component.lua

48 lines
979 B
Lua
Raw Normal View History

do
local oldcomp = component
_G.component = {}
for k,v in pairs(oldcomp) do
component[k] = v
end
for c,t in oldcomp.list() do
component[c:sub(1,8)] = oldcomp.proxy(c)
component[c] = oldcomp.proxy(c)
if not component[t] then
component[t] = oldcomp.proxy(c)
end
end
function component.list(filter,exact)
local ct = {}
for k,v in pairs(component) do
if type(v) == "table" then
if filter then
if exact then
if v.type == filter or v.address == filter then
ct[v.address] = v.type
end
else
if v.type:find(filter) or v.address:find(filter) then
ct[v.address] = v.type
end
end
else
ct[v.address] = v.type
end
end
end
return function(a,b)
return next(ct,b)
end
end
2017-08-01 14:42:12 +10:00
function component.proxy(k)
if type(component[k]) == "table" then
return component[k]
end
end
function component.type(k)
if type(component[k]) == "table" then
return component[k].type
end
2017-08-01 14:42:12 +10:00
end
end