| Line 3: |
Line 3: |
| | local Formatting = require("Module:Formatting") | | local Formatting = require("Module:Formatting") |
| | local Ship = require("Module:Ship") | | local Ship = require("Module:Ship") |
| | + | local ShipIndex = require("Module:ShipIndex") |
| | | | |
| | local args = nil | | local args = nil |
| | local ship = nil | | local ship = nil |
| | + | |
| | + | local enumerating_functions = { |
| | + | |
| | + | base_names = function() |
| | + | return ShipIndex.base_names |
| | + | end, |
| | + | |
| | + | } |
| | | | |
| | local formatting_functions = { | | local formatting_functions = { |
| Line 17: |
Line 26: |
| | implementation_date = function(ship) | | implementation_date = function(ship) |
| | local date = ship:implementation_date() | | local date = ship:implementation_date() |
| − | return format{ | + | return not date and "??" or format{ |
| | "${year}/${month}/${day}", | | "${year}/${month}/${day}", |
| | year = date[1], | | year = date[1], |
| Line 48: |
Line 57: |
| | end | | end |
| | end | | end |
| | + | |
| | + | local sequence = nil |
| | + | local sequence_position = nil |
| | | | |
| | function interpret_arg(arg) | | function interpret_arg(arg) |
| | local prefix = string.sub(arg, 1, 1) | | local prefix = string.sub(arg, 1, 1) |
| − | if prefix == "!" then | + | if prefix == "@" then |
| | + | local enumerator = string.sub(arg, 2) |
| | + | local enumerating_function = enumerating_functions[enumerator] |
| | + | if enumerating_function and not sequence then |
| | + | sequence = enumerating_function() |
| | + | sequence_position = 1 |
| | + | end |
| | + | elseif arg == "!@" then |
| | + | local ship_key = sequence[sequence_position] |
| | + | sequence_position = sequence_position + 1 |
| | + | ship = Ship(ship_key) |
| | + | elseif prefix == "!" then |
| | local ship_key = string.sub(arg, 2) | | local ship_key = string.sub(arg, 2) |
| | ship = Ship(ship_key) | | ship = Ship(ship_key) |
| Line 72: |
Line 95: |
| | args = args_ | | args = args_ |
| | local values = {} | | local values = {} |
| − | for _, arg in ipairs(args) do | + | repeat |
| − | local value = interpret_arg(arg)
| + | for _, arg in ipairs(args_) do |
| − | if value then
| + | local value = interpret_arg(arg) |
| − | table.insert(values, value)
| + | if value then |
| | + | table.insert(values, value) |
| | + | end |
| | end | | end |
| − | end | + | until not sequence or sequence_position > #sequence |
| | return table.concat(values, args.concat or "") | | return table.concat(values, args.concat or "") |
| | end | | end |
| Line 83: |
Line 108: |
| | local Calc = {} | | local Calc = {} |
| | | | |
| − | function Calc.format(frame, args) | + | function Calc.format(frame, args_) |
| − | return interpret_args(args or Utils.getTemplateArgs(frame).explicit) | + | return interpret_args(args_ or Utils.getTemplateArgs(frame).explicit) |
| | + | end |
| | + | |
| | + | function Calc.test() |
| | + | mw.log(Calc.format(nil, { |
| | + | format = "table", |
| | + | "@base_names", |
| | + | "#", "!@", "?id", "?link", "?implementation_date" |
| | + | })) |
| | end | | end |
| | | | |
| | return Calc | | return Calc |