mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-16 02:39:48 -04:00
Fixed primaries being determined using the fuzzy component.list getter by adding a second parameter to list, exact
, which will suppress fuzzy search.
This prevents the inventory controller upgrade to be returned for `component.inventory`, for example, and will only return it for `component.inventory_controller` now, as was originally intended.
This commit is contained in:
parent
64bf4d67e4
commit
bc8c29812f
@ -17,7 +17,7 @@ setmetatable(component, { __index = function(_, key)
|
||||
function component.get(address, componentType)
|
||||
checkArg(1, address, "string")
|
||||
checkArg(2, componentType, "string", "nil")
|
||||
for c in component.list(componentType) do
|
||||
for c in component.list(componentType, true) do
|
||||
if c:sub(1, address:len()) == address then
|
||||
return c
|
||||
end
|
||||
@ -31,7 +31,7 @@ function component.isAvailable(componentType)
|
||||
-- This is mostly to avoid out of memory errors preventing proxy
|
||||
-- creation cause confusion by trying to create the proxy again,
|
||||
-- causing the oom error to be thrown again.
|
||||
component.setPrimary(componentType, component.list(componentType)())
|
||||
component.setPrimary(componentType, component.list(componentType, true)())
|
||||
end
|
||||
return primaries[componentType] ~= nil
|
||||
end
|
||||
@ -108,7 +108,7 @@ local function onComponentRemoved(_, address, componentType)
|
||||
if primaries[componentType] and primaries[componentType].address == address or
|
||||
adding[componentType] and adding[componentType].address == address
|
||||
then
|
||||
component.setPrimary(componentType, component.list(componentType)())
|
||||
component.setPrimary(componentType, component.list(componentType, true)())
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -464,9 +464,9 @@ libcomponent = {
|
||||
end
|
||||
error("no such method", 1)
|
||||
end,
|
||||
list = function(filter)
|
||||
list = function(filter, exact)
|
||||
checkArg(1, filter, "string", "nil")
|
||||
local list = spcall(component.list, filter)
|
||||
local list = spcall(component.list, filter, not not exact)
|
||||
local key = nil
|
||||
return function()
|
||||
key = next(list, key)
|
||||
|
@ -12,9 +12,11 @@ class ComponentAPI(owner: NativeLuaArchitecture) extends NativeLuaAPI(owner) {
|
||||
|
||||
lua.pushScalaFunction(lua => components.synchronized {
|
||||
val filter = if (lua.isString(1)) Option(lua.toString(1)) else None
|
||||
val exact = if (lua.isBoolean(2)) lua.toBoolean(2) else true
|
||||
lua.newTable(0, components.size)
|
||||
def matches(name: String) = if (exact) name == filter.get else name.contains(filter.get)
|
||||
for ((address, name) <- components) {
|
||||
if (filter.isEmpty || name.contains(filter.get)) {
|
||||
if (filter.isEmpty || matches(name)) {
|
||||
lua.pushString(address)
|
||||
lua.pushString(name)
|
||||
lua.rawSet(-3)
|
||||
|
@ -14,9 +14,11 @@ class ComponentAPI(owner: LuaJLuaArchitecture) extends LuaJAPI(owner) {
|
||||
|
||||
component.set("list", (args: Varargs) => components.synchronized {
|
||||
val filter = if (args.isstring(1)) Option(args.tojstring(1)) else None
|
||||
val exact = args.optboolean(2, false)
|
||||
val table = LuaValue.tableOf(0, components.size)
|
||||
def matches(name: String) = if (exact) name == filter.get else name.contains(filter.get)
|
||||
for ((address, name) <- components) {
|
||||
if (filter.isEmpty || name.contains(filter.get)) {
|
||||
if (filter.isEmpty || matches(name)) {
|
||||
table.set(address, name)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user