Module:MakeMWModule

From Fire Emblem Heroes Wiki
Jump to: navigation, search
Template-info.svg Documentation

Lua-only module which creates MediaWiki-compatible tables from other Lua modules.

makeMWModule(t, opts)[edit source]

Replaces all functions in a Lua module with ones that take MediaWiki frame arguments, aliasing the original functions.

Parameters[edit source]

  • t
Lua table with keys mapped to functions
  • opts
Table containing options to Module:Arguments.getArgs (optional)

Return values[edit source]

  • A new table mwt such that, for every function t.f present in the argument table:
    • mwt.f is a function that accepts a single MediaWiki frame argument, calls Module:Arguments.getArgs on it (using opts as the options table), then forwards the result and the frame itself to t.f
    • mwt._f == t.f
local getArgs = require('Module:Arguments').getArgs

local makeMWModule = function (base, opts)
  local p = {}
  for k, v in pairs(base) do
    p['_' .. k] = v
    p[k] = function (frame)
      return v(getArgs(frame, opts), frame)
    end
  end
  return p
end

return {
	makeMWModule = makeMWModule,
}