UsageEdit

DON'T USE THIS, OR ANYTHING LIKE IT. EVER. SERIOUSLY.
*Setting somekey to somevalue (shouldn't see anything): {{#invoke:Sandbox/Jackmcbarn/variables|set|somekey|somevalue}}
*Setting otherk to otherv (shouldn't see anything): {{#invoke:Sandbox/Jackmcbarn/variables|set|otherk|otherv}}
*Getting somekey: {{#invoke:Sandbox/Jackmcbarn/variables|get|somekey}}
*Getting otherk: {{#invoke:Sandbox/Jackmcbarn/variables|get|otherk}}
*Getting somekey: {{#invoke:Sandbox/Jackmcbarn/variables|get|somekey}}
*Getting otherk: {{#invoke:Sandbox/Jackmcbarn/variables|get|otherk}}
*Clearing all variables (shouldn't see anything): {{#invoke:Sandbox/Jackmcbarn/variables|done}}

Produces:

  • Setting somekey to somevalue (shouldn't see anything):
  • Setting otherk to otherv (shouldn't see anything):
  • Getting somekey:
  • Getting otherk:
  • Getting somekey:
  • Getting otherk:
  • Clearing all variables (shouldn't see anything):
{{#invoke:Sandbox/Jackmcbarn|function_name}}



local p = {}

function p.set(frame)
	frame:extensionTag{name = 'ref', content = frame.args[2], args = { group = 'lower-greek', name = frame.args[1] }}
	return ''
end

function p.get(frame)
	local refText = mw.text.unstrip(frame:extensionTag{name = 'references', args = { group='lower-greek' }})
	local keyMatch = mw.ustring.gmatch(refText, '<li id="cite_note%-([^-]*)%-%d+">')
	local valMatch = mw.ustring.gmatch(refText, '<span class="reference%-text">([^<]*)')
	local variables = {}
	for key in keyMatch do
		variables[key] = valMatch()
		frame:extensionTag{name = 'ref', content = variables[key], args = { group = 'lower-greek', name = key }}
	end
	return variables[frame.args[1]]
end

function p.done(frame)
	frame:extensionTag{name = 'references', args = { group='lower-greek' }}
	return ''
end

return p