Module:ScriptItem2: Difference between revisions

no edit summary
No edit summary
No edit summary
 
(35 intermediate revisions by the same user not shown)
Line 38: Line 38:
-- Category Names. (String(s) to look for in an item name, case-INsensitive.)
-- Category Names. (String(s) to look for in an item name, case-INsensitive.)
'Blip', 'Building', 'Camera', 'Chatbox', 'Cheat', 'Client', 'Command', 'Cursor', 'Debug', 'Dodo',
'Blip', 'Building', 'Camera', 'Chatbox', 'Cheat', 'Client', 'Command', 'Cursor', 'Debug', 'Dodo',
'Element', 'Entity', 'Event', 'File', 'Font', 'Garage', 'HTTP', 'HUD', 'Key', 'Mission', 'Mouse', 'Network', 'Object',
'Element', 'Entity', 'Event', 'File', 'Font', 'Garage', 'HTTP', 'HUD', 'Key', 'Mission', 'Mouse', 'NetFlags', 'Network', 'Object',
'Pause', 'Ped', 'Pickup', 'Player', 'Process', 'Render', 'Resource', 'Screen', 'Socket', 'Sphere', 'Time', 'Vehicle', 'Weather', 'World'
'Pause', 'Ped', 'Pickup', 'Player', 'Process', 'Render', 'Resource', 'Screen', 'Socket', 'Sphere', 'Time', 'Vehicle', 'Weather', 'World'
}
}
Line 193: Line 193:
end
end
]]
]]
if args['return'] then
args.value = args['return']
end
if args.usage then
if args.usage then
Line 276: Line 280:
function p.gamesBox(frame)
function p.gamesBox(frame)
local args = p.getArgs(frame)
local args = p.getArgs(frame)
local gamesText = p.getGames(args.games)
local gamesText = p.getGames(args.games)
if gamesText == "All Games" then
 
local games2 = { 'iii', 'vc', 'sa', 'iv' }
local counter = 0
for i2,game2 in ipairs(games2) do
if gamesText:lower():find(game2) then
counter = counter + 1
end
end
 
if counter == #games2 or gamesText == "All Games" then
return p.loadTemplate(frame, 'GreenInformationBox', {table.concat({
return p.loadTemplate(frame, 'GreenInformationBox', {table.concat({
p.loadTemplate(frame, 'icon-iii'),
p.loadTemplate(frame, 'icon-iii'),
Line 365: Line 379:


local args = p.getArgs(frame)
local args = p.getArgs(frame)
local isEvent = args.type == 'event'


local returnType
local returnType = 'void'
local argsText = {}
local argsText = {}


Line 383: Line 398:
do
do
local entries = p.getIndexedArgs(frame, 'arg')
local entries = p.getIndexedArgs(frame, 'arg')
local isEvent = args.type == 'event'
 
if isEvent then
table.insert(entries, 1, 'Event event')
end


if isEvent and args.syntax and args.syntax:lower() == 'event event' then
if isEvent and args.syntax and args.syntax:lower() == 'event event' then
elseif #entries == 0 then
elseif #entries == 0 or entries[1] == "void" then
elseif entries[1] == "void" then
table.insert(argsText, 'void')
else
else
for i,arg in ipairs(entries) do
for i,arg in ipairs(entries) do
local tokens = p.split(arg, ' ')
                table.insert(argsText, p.getArgSyntaxText(p.getArgParts(arg)))
local isOptional = tokens[1]:sub(1, 1) == '['
if isOptional then
tokens[1] = tokens[1]:sub(2, tokens[1]:len())
tokens[4] = tokens[4]:sub(1, tokens[4]:len() - 1)
end
local defaultValue = isOptional and "<span style='font-family: \"Source Code Pro\", monospace;'>"..tokens[4].."</span>" or "n/a"
if isOptional then
table.insert(argsText, '[ '..tokens[1]..' '..tokens[2]..' = '..defaultValue..' ]')
else
table.insert(argsText, tokens[1]..' '..tokens[2])
end
end
end
end
end
end
end


return returnType
if isEvent then
..' '..p.getDisplayedName(frame)
return p.loadTemplate(frame, 'CodeSyntax', {
..'('..(#argsText == 0 and 'void' or table.concat(argsText, ', ')..')')
p.getDisplayedName(frame)
..'('..(#argsText == 0 and 'void' or table.concat(argsText, ', '))..')'
})
elseif args.type == 'property' or args.type == 'variable' then
return p.loadTemplate(frame, 'CodeSyntax', {
returnType..' '..p.getDisplayedName(frame)
})
else
return p.loadTemplate(frame, 'CodeSyntax', {
returnType
..' '..p.getDisplayedName(frame)
..'('..(#argsText == 0 and 'void' or table.concat(argsText, ', '))..')'
})
end
end
 
function p.getArgParts(text)
--[[
        INPUT EXAMPLES (str)
        Vec3 pos The 3D position
        [Vec3 pos] The 3D position.
        [ Vec3 pos ] The 3D position
        [ Vec3 pos = new Vec3(0.0, 0.0, 0.0) ] The 3D position.
 
        OUTPUT (table)
        bool parts.optional
        bool parts.defaultValueIsSpecified
str parts.type
str parts.name
str parts.defaultValue
str parts.description
]]
 
local parts = {}
 
text = p.trim(text)
 
    parts.optional = false
local isProbablyOptional = text:sub(1, 1) == '['
if isProbablyOptional then
local optionalEndIndex = p.rfind(text, ']')
if optionalEndIndex then
            parts.optional = true
            local syntaxPart = p.trim(text:sub(2, optionalEndIndex - 1))
            parts.description = p.trim(text:sub(optionalEndIndex + 1, #text))
            local tokens = p.split(syntaxPart, ' ')
            parts.type = tokens[1]
            parts.name = tokens[2]
            parts.defaultValueIsSpecified = tokens[3] == '=' and #tokens >= 4
            parts.defaultValue = table.concat(tokens, ' ', 4, #tokens)
            return parts
        end
    end
 
    local tokens = p.split(text, ' ')
    parts.type = tokens[1]
    parts.name = tokens[2]
    parts.description = p.trim(table.concat(tokens, ' ', 3, #tokens))
    return parts
end
 
function p.getArgSyntaxText(parts)
    if parts.optional then
        if parts.defaultValueIsSpecified then
            return '[ '..parts.type..' '..parts.name..' = '..parts.defaultValue..' ]'
        else
            return '[ '..parts.type..' '..parts.name..' ]'
        end
    else
        return parts.type..' '..parts.name
    end
end
end


Line 418: Line 491:
local entries = p.getIndexedArgs(frame, 'desc')
local entries = p.getIndexedArgs(frame, 'desc')
local startTextFirstLine = "The <span style=\"font-family: 'Source Code Pro', monospace;\">"..p.getDisplayedNameColoured(frame).."</span> [[HowTo/Functions|"..args.type.."]] is "..(args.type == "event" and "invoked when" or "used to").." "
local startTextFirstLine = "The <span style=\"font-family: 'Source Code Pro', monospace;\">"..p.getDisplayedNameColoured(frame).."</span> "..args.type:lower().." is "..(args.type == "event" and "invoked when" or "used to").." "
for i,entry in ipairs(entries) do
for i,entry in ipairs(entries) do
Line 437: Line 510:
if isEvent and args.syntax and args.syntax:lower() == 'event event' then
if isEvent and args.syntax and args.syntax:lower() == 'event event' then
elseif #entries == 0 then
elseif #entries == 0 or entries[1] == "void" then
return p.documentationMissing(frame, "Parameters")
elseif entries[1] == "void" then
local headers = nil
local headers = nil
local rows = { { p.formatType("void", frame), "This "..args.type.." doesn't take any parameters." } }
local rows = { { p.formatType("void", frame), "This "..args.type.." doesn't take any parameters." } }
Line 447: Line 518:
for i,arg in ipairs(entries) do
for i,arg in ipairs(entries) do
local tokens = p.split(arg, ' ')
local tokens = p.split(arg, ' ')
 
local isOptional = tokens[1]:sub(1, 1) == '['
if isOptional then
tokens[1] = tokens[1]:sub(2, tokens[1]:len())
tokens[4] = tokens[4]:sub(1, tokens[4]:len() - 1)
end
local defaultValue = isOptional and "<span style='font-family: \"Source Code Pro\", monospace;'>"..tokens[4].."</span>" or "n/a"
local description = p.formatDescription(table.concat(tokens, ' ', isOptional and 5 or 3))
if isEvent then
if isEvent then
rows[i] = { (i + 1)..") ", p.formatType(tokens[1], frame), p.formatName(tokens[2], frame), description }
rows[i] = { (i + 1)..") ", p.formatType(tokens[1], frame), p.formatName(tokens[2], frame), p.formatDescription(table.concat(tokens, ' ', 3, #tokens)) }
else
else
rows[i] = { i..") ", p.formatType(tokens[1], frame), p.formatName(tokens[2], frame), (isOptional and ("Optional, defaults to "..defaultValue..". ") or "")..description }
local parts = p.getArgParts(arg)
 
if parts.optional then
if parts.defaultValueIsSpecified then
rows[i] = { i..") ", p.formatType(parts.type, frame), p.formatName(parts.name, frame), "Optional, defaults to "..p.formatDefaultValue(parts.defaultValue, frame)..". "..p.formatDescription(parts.description) }
else
rows[i] = { i..") ", p.formatType(parts.type, frame), p.formatName(parts.name, frame), "Optional, the default value has not been documented here yet. "..p.formatDescription(parts.description) }
end
else
rows[i] = { i..") ", p.formatType(parts.type, frame), p.formatName(parts.name, frame), p.formatDescription(parts.description) }
end
end
end
end
end
Line 568: Line 641:
local parameters = p.getIndexedArgs(frame, 'arg')
local parameters = p.getIndexedArgs(frame, 'arg')
for i=1, #parameters do
for i=1, #parameters do
local callbackSyntax = args['cb'..i..'Syntax'..suffix]
local callbackSyntax = {}
local callbackText = args['cb'..i..'Text'..suffix]
local callbackText = args['cb'..i..'Text'..suffix]
local callbackNParameters = p.getIndexedArgs(frame, 'cb'..i..'arg'..suffix)
local callbackNParameters = p.getIndexedArgs(frame, 'cb'..i..'arg'..suffix)
Line 579: Line 652:
local parameterTokens = p.split(parameters[i], ' ')
local parameterTokens = p.split(parameters[i], ' ')
local rows = {}
local rows = {}
if #parameterTokens > 0 then
local syntaxLine = parameterTokens[1]..' '..parameterTokens[2]..'('..callbackSyntax..')'
syntaxLine = p.loadTemplate(frame, 'CodeSyntax', {syntaxLine})
table.insert(html, syntaxLine)
end
if callbackText and #callbackText > 0 then
table.insert(html, callbackText)
end
for i2,callbackNParameter in ipairs(callbackNParameters) do
for i2,callbackNParameter in ipairs(callbackNParameters) do
Line 597: Line 660:
local description = p.formatDescription(table.concat(callbackTokens, ' ', 3))
local description = p.formatDescription(table.concat(callbackTokens, ' ', 3))
do
if parameterType == "void" then
table.insert(callbackSyntax, 'void')
else
table.insert(callbackSyntax, parameterType..' '..parameterName)
end
end
rows[i2] = { i2..') ', p.formatType(parameterType, frame), p.formatName(parameterName, frame), description }
rows[i2] = { i2..') ', p.formatType(parameterType, frame), p.formatName(parameterName, frame), description }
end
local callbackSyntax2 = #callbackSyntax == 0 and 'void' or table.concat(callbackSyntax, ', ')
if #parameterTokens > 0 then
local syntaxLine = parameterTokens[1]..' '..parameterTokens[2]..'('..callbackSyntax2..')'
syntaxLine = p.loadTemplate(frame, 'CodeSyntax', {syntaxLine})
table.insert(html, syntaxLine)
end
if callbackText and #callbackText > 0 then
table.insert(html, callbackText)
end
end
Line 723: Line 806:
local entries = p.getIndexedArgs(frame, data2[1])
local entries = p.getIndexedArgs(frame, data2[1])
for i2, entry in ipairs(entries) do
for i2, entry in ipairs(entries) do
local entry = "'''Example "..exampleIndex.." - "..data2[2]..":'''<br>"..p.loadTemplate(frame, 'CodeSyntax', {entry,id='example_'..exampleIndex})
local entry2 = "'''Example "..exampleIndex.." - "..data2[2]..":'''<br>"..p.loadTemplate(frame, 'CodeSyntax', {entry:gsub("\r\n", "\n"):gsub("\n", "<br>"):gsub("\t", "&nbsp;&nbsp;&nbsp;&nbsp;"),id='example_'..exampleIndex})
table.insert(examples, entry)
table.insert(examples, entry2)
exampleIndex = exampleIndex + 1
exampleIndex = exampleIndex + 1
end
end
Line 862: Line 945:
local args = p.getArgs(frame)
local args = p.getArgs(frame)
if p.isOOP(frame) then
if p.isOOP(frame) then
return args.class:lower().."."..args.name
return p.lowerFirstCharCase(args.class).."."..args.name
else
else
return args.name
return args.name
Line 881: Line 964:
local args = p.getArgs(frame)
local args = p.getArgs(frame)
if p.isOOP(frame) then
if p.isOOP(frame) then
return "<span style='color:"..typeRgb..";'>"..args.class:lower().."</span>.<span style='color:"..nameRgb.."';>"..args.name.."</span>"
return "<span style='color:"..typeRgb..";'>"..p.lowerFirstCharCase(args.class).."</span>.<span style='color:"..nameRgb.."';>"..args.name.."</span>"
else
else
return "<span style='color:"..nameRgb.."';>"..args.name.."</span>"
return "<span style='color:"..nameRgb.."';>"..args.name.."</span>"
Line 1,061: Line 1,144:
function p.isCancellable(frame)
function p.isCancellable(frame)
local args = p.getArgs(frame)
local args = p.getArgs(frame)
return (args.cancellable and args.cancellable == 'true') or (args.cancelable and args.cancelable == 'true')
return (args.cancel and args.cancel == 'true') or (args.cancel and args.cancel == 'true')
end
end


Line 1,070: Line 1,153:
function p.formatName(name, frame)
function p.formatName(name, frame)
return "<span style='font-family: \"Source Code Pro\", monospace; color: "..p.getNameRgb()..";\"'>"..name.."</span>"
return "<span style='font-family: \"Source Code Pro\", monospace; color: "..p.getNameRgb()..";\"'>"..name.."</span>"
end
function p.formatDefaultValue(value, frame)
return "<span style='font-family: \"Source Code Pro\", monospace; color: "..p.getNameRgb()..";\"'>"..value.."</span>"
end
end


function p.formatSource(type, frame)
function p.formatSource(type, frame)
return frame:preprocess('<source>'..type..'</source>')
return "<code>"..type.."</code>"
end
end


Line 1,087: Line 1,174:


function p.standardizeNullType(type)
function p.standardizeNullType(type)
type = type:lower()
local type2 = type:lower()
if type == 'void' or type == 'null' or type == 'undefined' or type == 'n/a' then
if type2 == 'void' or type2 == 'null' or type2 == 'undefined' or type2 == 'n/a' then
return 'void'
return 'void'
else
else
Line 1,137: Line 1,224:


   return r, n
   return r, n
end
function p.rfind(s, find)
local index = s:reverse():find(find)
if not index then return end
return #s - index + 1
end
function p.trim(s)
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end
end


Line 1,211: Line 1,308:
function p.properCase(text)
function p.properCase(text)
return text:sub(1,1):upper()..text:sub(2):lower()
return text:sub(1,1):upper()..text:sub(2):lower()
end
function p.lowerFirstCharCase(text)
return text:sub(1,1):lower()..text:sub(2)
end
end


6,834

edits