v50 Steam/Premium information for editors
  • v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
  • Use this page to report any issues related to the migration.
This notice may be cached—the current version can be found here.

Difference between revisions of "Module:Versions"

From Dwarf Fortress Wiki
Jump to navigation Jump to search
(create)
 
(parser-function-friendly wrapper)
Line 39: Line 39:
 
end
 
end
 
error('Unknown version: ' .. version)
 
error('Unknown version: ' .. version)
 +
end
 +
 +
env.parserFuncs = {}
 +
for k, v in pairs(env) do
 +
if type(v) == 'function' then
 +
env.parserFuncs[k] = function(frame)
 +
return v(unpack(frame.args))
 +
end
 +
end
 
end
 
end
  
 
return env
 
return env

Revision as of 06:40, 26 November 2022

Version/namespace helpers.

For use in templates, see module:versions/parserFunctions


local env = {}

local namespaces = {
	-- keys are the canonical namespace name (not aliases)
	['23a'] = {
		-- versions are sorted in ascending order 
		versions = {'0.21', '0.22', '0.23'},
	},
	['40d'] = {
		versions = {'0.27', '0.28'},
	},
	['v0.31'] = {
		versions = {'0.31'},
	},
	['v0.34'] = {
		versions = {'0.34'},
	},
	['DF2014'] = {
		versions = {'0.40', '0.42', '0.43', '0.44', '0.47'},
	},
}
local version_to_namespace = {}
for name, data in pairs(namespaces) do 
	data.canonical_version = data.versions[#data.versions]
	if not data.category_prefix then
		data.category_prefix = name
	end
	for _, version in pairs(data.versions) do
		version_to_namespace[version] = name
	end
end

function env.versionToNamespace(version)
	local parts = mw.text.split(version:gsub('^v', ''), '.', true)
	for _, key in pairs{parts[1], parts[1] .. '.' .. parts[2]} do
		if version_to_namespace[key] then
			return version_to_namespace[key]
		end
	end
	error('Unknown version: ' .. version)
end

env.parserFuncs = {}
for k, v in pairs(env) do
	if type(v) == 'function' then
		env.parserFuncs[k] = function(frame)
			return v(unpack(frame.args))
		end
	end
end

return env