Module:Type

local utils = require('Module:Utils') local links = require('Module:Links')

local primitive_types = utils.array_to_set {'int', 'double', 'float', 'boolean', 'string', 'number', 'userdata', 'function', 'void', 'nil', 'table'}

local p = {}

function p.link(type_name) if mw.ustring.sub(type_name, -2, -1) == "[]" then -- The type is an array. return p.link(mw.ustring.sub(type_name, 1, -3)) .. "[]"   elseif primitive_types[type_name] then return mw.text.tag('span', {class = 'value-type primitive-type'}, type_name) else local title = mw.title.new(type_name, 'Class') -- If there exists a class with the same name as the type, link to its page. if title.exists then return mw.text.tag('span', {class = 'value-type class-link'}, links.wikilink(title, type_name)) else title = mw.title.new(type_name) -- If there exists a page with the same name as the type, link to it. if title.exists then return mw.text.tag('span', {class = 'value-type'}, links.wikilink(title, type_name)) else return mw.text.tag('span', {class = 'value-type'}, type_name) end end end end

function p._link_type(args) return p.link(args.type) end

p.link_type = utils.make_wrapper_function(p._link_type)

return p