Jump to content

Module:Inventory slot: Difference between revisions

m
p.parseString() should now correctly handle nameless items.
imported>Ttv pedro270707
mNo edit summary
imported>Ttv pedro270707
m (p.parseString() should now correctly handle nameless items.)
Line 128: Line 128:


function p.parseString(input)
function p.parseString(input)
local strings = {}
    local strings = {}
for str in input:gmatch("[^;]+") do
    for str in input:gmatch("[^;]+") do
    table.insert(strings, str:match("^%s*(.-)%s*$"))
        table.insert(strings, str:match("^%s*(.-)%s*$"))
end
    end
 
   
local result = {}
    local result = {}
 
   
for _, str in ipairs(strings) do
    for _, str in ipairs(strings) do
local name, item, count = str:match("^%[(.-)%](.-),(%d+)$")
        local name, item, count = str:match("^%[(.-)%](.-),?(%d*)$")
if not name then
        if name then
name, item = str:match("^%[(.-)%](.-)$")
            table.insert(result, { name = name:gsub("^%s*(.-)%s*$", "%1"), item = item:gsub("^%s*(.-)%s*$", "%1"), count = tonumber(count) })
end
        else
if name then
            item, count = str:match("(.-),?(%d*)$")
if count == nil then
            table.insert(result, { name = nil, item = item:gsub("^%s*(.-)%s*$", "%1"), count = tonumber(count) })
table.insert(result, { name = name:gsub("^%s*(.-)%s*$", "%1"), item = item:gsub("^%s*(.-)%s*$", "%1"), count = nil })
        end
else
    end
table.insert(result, { name = name:gsub("^%s*(.-)%s*$", "%1"), item = item:gsub("^%s*(.-)%s*$", "%1"), count = tonumber(count) })
   
end
    return result
else
if count == nil then
table.insert(result, { name = nil, item = str:gsub("^%s*(.-)%s*$", "%1"), count = nil })
else
table.insert(result, { name = nil, item = str:gsub("^%s*(.-)%s*$", "%1"), count = tonumber(count) })
end
end
end
 
return result
end
end


return p
return p