Format parameters |
Fix format and styles |
||
Line 1: | Line 1: | ||
-- test in console: | -- test in console: | ||
-- =p.main(mw.getCurrentFrame():newChild{title="Template:Table ComponentMethods",args={" SetUpRenderer() *", " ", " Attaches components for a default [[PBS_Metallic]] material and [[Component:MeshRenderer|MeshRenderer]] referencing this mesh."}}:newChild{title="Module:Test",args={}}) | -- =p.main(mw.getCurrentFrame():newChild{title="Template:Table ComponentMethods",args={" SetUpRenderer() *", " ", " Attaches components for a default [[PBS_Metallic]] material and [[Component:MeshRenderer|MeshRenderer]] referencing this mesh."}}:newChild{title="Module:Test",args={}}) | ||
-- =p.main(mw.getCurrentFrame():newChild{title="Template:Table ComponentMethods",args={"Resize(size, filtering)", "size:int,int2:Scaling factor.;filtering:Filtering:Resampling method.", "Replaces the 2D texture with a scaled copy, resampled using the given filtering method. Scales separately in the X and Y axes when an int2 is passed."}}:newChild{title="Module:Test",args={}}) | -- =p.main(mw.getCurrentFrame():newChild{title="Template:Table ComponentMethods",args={"Resize(size, filtering)\n", "size:int,int2:Scaling factor.\n;filtering:Filtering:Resampling method.\n", "Replaces the 2D texture with a scaled copy, resampled using the given filtering method. Scales separately in the X and Y axes when an int2 is passed."}}:newChild{title="Module:Test",args={}}) | ||
-- =p.footnote(mw.getCurrentFrame():newChild{title="Template:Table ComponentMethods",args={" SetUpRenderer() *", " ", " Attaches components for a default [[PBS_Metallic]] material and [[Component:MeshRenderer|MeshRenderer]] referencing this mesh."}}:newChild{title="Module:Test",args={}}) | -- =p.footnote(mw.getCurrentFrame():newChild{title="Template:Table ComponentMethods",args={" SetUpRenderer() *", " ", " Attaches components for a default [[PBS_Metallic]] material and [[Component:MeshRenderer|MeshRenderer]] referencing this mesh."}}:newChild{title="Module:Test",args={}}) | ||
Line 29: | Line 29: | ||
local noParams = #params == 0 | local noParams = #params == 0 | ||
body = body .. " | body = body .. '|- style="vertical-align:top;"\n' | ||
body = body .. "|<code>" .. name .. "</code> " .. rest .. "\n" | body = body .. "|<code>" .. name .. "</code> " .. rest .. "\n" | ||
if noParams then | if noParams then | ||
Line 39: | Line 39: | ||
local _, paramEnd = params:find(";") | local _, paramEnd = params:find(";") | ||
paramEnd = paramEnd or #params + 1 | paramEnd = paramEnd or #params + 1 | ||
local param = params:sub(0, paramEnd - 1) | local param = mw.text.trim(params:sub(0, paramEnd - 1)) | ||
local name, types, desc = param:match("([^:]*):([^:]*):(.*)") | local name, types, desc = param:match("([^:]*):([^:]*):(.*)") | ||
body = body .. "<code>" .. name .. "</code> : " | body = body .. "\n<code>" .. name .. "</code> : " | ||
local first = true | local first = true | ||
for t in types:gmatch("([^,]+)") do | for t in types:gmatch("([^,]+)") do | ||
if not first then body = body .. | if not first then body = body .. " or " end | ||
-- use custom link if specified | -- use custom link if specified | ||
if t:match("^%[%[.+]]$") then | if t:match("^%[%[.+]]$") then | ||
Line 55: | Line 55: | ||
first = false | first = false | ||
end | end | ||
body = body .. "<br>" .. desc .. | body = body .. "<br>" .. desc .. "\n" | ||
params = params:sub(paramEnd + 1) | params = mw.text.trim(params:sub(paramEnd + 1)) | ||
until #params == 0 | until #params == 0 | ||
end | end |
Revision as of 04:54, 15 July 2024
Documentation for this module may be created at Module:ComponentMethods/doc
-- test in console:
-- =p.main(mw.getCurrentFrame():newChild{title="Template:Table ComponentMethods",args={" SetUpRenderer() *", " ", " Attaches components for a default [[PBS_Metallic]] material and [[Component:MeshRenderer|MeshRenderer]] referencing this mesh."}}:newChild{title="Module:Test",args={}})
-- =p.main(mw.getCurrentFrame():newChild{title="Template:Table ComponentMethods",args={"Resize(size, filtering)\n", "size:int,int2:Scaling factor.\n;filtering:Filtering:Resampling method.\n", "Replaces the 2D texture with a scaled copy, resampled using the given filtering method. Scales separately in the X and Y axes when an int2 is passed."}}:newChild{title="Module:Test",args={}})
-- =p.footnote(mw.getCurrentFrame():newChild{title="Template:Table ComponentMethods",args={" SetUpRenderer() *", " ", " Attaches components for a default [[PBS_Metallic]] material and [[Component:MeshRenderer|MeshRenderer]] referencing this mesh."}}:newChild{title="Module:Test",args={}})
local p = {}
function p.main(frame)
local templateFrame = frame:getParent()
local body = ""
local i = 0
while true do
local argI = i * 3 + 1
local method = templateFrame.args[argI]
local params = templateFrame.args[argI + 1]
local description = templateFrame.args[argI + 2]
if not description then
break
end
local _, nameEnd = method:find(")")
local name = mw.text.trim(method:sub(1, nameEnd)):gsub(" +", " ")
local rest = mw.text.trim(method:sub(nameEnd + 1))
params = mw.text.trim(params)
local noParams = #params == 0
body = body .. '|- style="vertical-align:top;"\n'
body = body .. "|<code>" .. name .. "</code> " .. rest .. "\n"
if noParams then
body = body .. "|''none''\n"
else
body = body .. "|"
local first = false
repeat
local _, paramEnd = params:find(";")
paramEnd = paramEnd or #params + 1
local param = mw.text.trim(params:sub(0, paramEnd - 1))
local name, types, desc = param:match("([^:]*):([^:]*):(.*)")
body = body .. "\n<code>" .. name .. "</code> : "
local first = true
for t in types:gmatch("([^,]+)") do
if not first then body = body .. " or " end
-- use custom link if specified
if t:match("^%[%[.+]]$") then
body = body .. t
else
body = body .. "[[Type:" .. t .. "|" .. t .. "]]"
end
first = false
end
body = body .. "<br>" .. desc .. "\n"
params = mw.text.trim(params:sub(paramEnd + 1))
until #params == 0
end
body = body .. "|" .. description .. "\n"
i = i + 1
end
return body
end
function p.footnote(frame)
local templateFrame = frame:getParent()
local body = ""
local anyHidden = false
local i = 0
while true do
local method = templateFrame.args[3 * i + 1]
if not method then
break
end
local _, j = method:find(")")
if method:sub(j + 1):find("*") then
anyHidden = true
break
end
i = i + 1
end
if anyHidden then
body = body .. "''* Methods marked with an asterisk are invisible in the inspector by default.''"
end
return body
end
return p