Renamed some variables

This commit is contained in:
Shy 2024-08-29 17:47:28 +02:00
parent 682199716a
commit e2a9b8046d

18
c4mate
View file

@ -220,9 +220,9 @@ function MatePad:print_log(log)
end end
-- Get available items. -- Get available items.
function MatePad:get_roster() function MatePad:get_offerings()
local pipe, ok, exit, signal local pipe, ok, exit, signal
local roster = {} local offerings = {}
-- sed #1: Extract items section and insert newlines between entries. -- sed #1: Extract items section and insert newlines between entries.
-- sed #2: Extract and print id, name and price. If any extraction fails we -- sed #2: Extract and print id, name and price. If any extraction fails we
-- fail with exit code 1. -- fail with exit code 1.
@ -253,7 +253,7 @@ sed -n --sandbox '
if item.id == nil then break end if item.id == nil then break end
item.name = utf8_decode(pipe:read()) item.name = utf8_decode(pipe:read())
item.price = tonumber(pipe:read()) item.price = tonumber(pipe:read())
table.insert(roster, item) table.insert(offerings, item)
end end
ok, exit, signal = pipe:close() ok, exit, signal = pipe:close()
@ -261,11 +261,11 @@ sed -n --sandbox '
io.stderr:write("Sorry, there was an error while parsing the API response.\n") io.stderr:write("Sorry, there was an error while parsing the API response.\n")
-- Empty table will throw no exceptions. -- Empty table will throw no exceptions.
return {} return {}
elseif roster == nil then -- curl error elseif offerings == nil then -- curl error
io.stderr:write("Sorry, there was an error while connecting the API.\n") io.stderr:write("Sorry, there was an error while connecting the API.\n")
return {} return {}
end end
return roster return offerings
end end
-- Buy given item. -- Buy given item.
@ -419,13 +419,13 @@ elseif tonumber(arg[1]) ~= nil then
else else
-- Find and buy item. -- Find and buy item.
local roster, query, input, ok local offerings, query, input, ok
roster = pad:get_roster() offerings = pad:get_offerings()
query = table.concat(arg, " "):lower() query = table.concat(arg, " "):lower()
local menu = {} local menu = {}
for i = 1, #roster do for i = 1, #offerings do
local item = roster[i] local item = offerings[i]
if item.name:lower():match(query) then if item.name:lower():match(query) then
table.insert(menu, item) table.insert(menu, item)
end end