From b9faa51406da28c28e08e1dac17e4e3aa6a37938 Mon Sep 17 00:00:00 2001 From: osmarks Date: Sun, 29 Apr 2018 17:11:59 +0100 Subject: [PATCH] Refactor slightly --- server.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/server.lua b/server.lua index a7dba38..36900c2 100644 --- a/server.lua +++ b/server.lua @@ -71,6 +71,15 @@ function findSpace() end end +function search(msg) + return find(function(item) + return + (not msg.meta or item.damage == msg.meta) and + (not msg.name or item.name == msg.name) and + (not msg.dname or string.find(item.displayName:lower(), msg.dname:lower())) + end) +end + function processRequest(msg) print(textutils.serialise(msg)) @@ -78,12 +87,7 @@ function processRequest(msg) -- Applies a fuzzy search to display names -- Extracted items are either deposited in buffer or directly in target inventory. if msg.cmd == "extract" then - local inv, slot, item = find(function(item) - return - (not msg.meta or item.damage == msg.meta) and - (not msg.name or item.name == msg.name) and - (not msg.dname or string.find(item.displayName:lower(), msg.dname:lower())) - end) + local inv, slot, item = search(msg) index[inv][slot] = nil