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