Module:Sandbox/User:Ku
Jump to navigation
Jump to search
Module documentation
This documentation is transcluded from Template:Module sandbox/doc. [edit] [history] [purge]
Module:Sandbox/User:Ku requires Module:DPLlua.
| Function list |
|---|
| L 6 — get_ticks_for_item L 27 — p.ticks |
This module is a sandbox for Ku. It can be used to test changes to existing modules, prototype new modules, or just experiment with Lua features.
Invocations of this sandbox should be kept in userspace; if the module is intended for use in other namespaces, it should be moved out of the sandbox into a normal module and template.
This default documentation can be overridden by creating the /doc subpage of this module, as normal.
-- <nowiki>
local p = {}
local dpl = require('Module:DPLlua')
local function get_ticks_for_item(item)
-- Ask DPL for this exact page and include its Infobox Recipe params
local res = dpl.ask({
namespace = '',
ignorecase = true,
title = item,
uses = 'Template:Infobox Recipe',
count = 1,
include = '{Infobox Recipe}'
})
local page = res and res[1]
if not page or not page.include or not page.include['Infobox Recipe'] then
return nil
end
local recipe = page.include['Infobox Recipe']
-- This is where "ticks" lives
return recipe.ticks, recipe.ticksnote
end
function p.ticks(frame)
local args = frame.args
local parent = frame:getParent() and frame:getParent().args or {}
-- DEFAULT: Magic shieldbow, if nothing is passed in
local item = args.item
or args[1]
or parent.item
or parent[1]
or 'Bik arrow'
local ticks, note = get_ticks_for_item(item)
if not ticks then
return 'No ticks param on ' .. item
end
if note then
return ticks .. ' (' .. note .. ')'
end
mw.log(ticks)
return ticks
end
return p
-- </nowiki>