Module:Electowidget: Difference between revisions
Content added Content deleted
(very crude start on Lua version of electowidget (and really, it's not much...)) |
(Adding a function to parse the abif contents) |
||
Line 1: | Line 1: | ||
-- From: User:RobLa |
|||
-- 2019-12-09 - I might port electowidget to Lua. Maybe... |
|||
-- Date: ~~~~ |
|||
-- Comment: I think I'd like the new version of Electowidget to use ABIF |
|||
local p = {} |
local p = {} |
||
-- Function to parse the line and return a Lua native data structure |
|||
function p.parse_prefs_line(line) |
|||
local qty, prefs = line:match('(%d+):%s*(.*)') |
|||
local prefs_table = {} |
|||
if prefs == '' then |
|||
return { qty = qty, comment = nil, orderedlist = true } |
|||
end |
|||
local rank = 1 |
|||
for name, rating in prefs:gmatch('([^/]+)/([^ ]+)') do |
|||
prefs_table[rank] = { |
|||
name = name, |
|||
rating = tonumber(rating), |
|||
} |
|||
rank = rank + 1 |
|||
end |
|||
return { |
|||
qty = tonumber(qty), |
|||
prefs = prefs_table, |
|||
comment = nil, |
|||
orderedlist = true |
|||
} |
|||
end |
|||
function p.get_data() |
function p.get_data() |