Template:FunctionDeclaration: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
No edit summary
Use question marks (?, a la TypeScript) instead of brackets for optional parameters. Brackets have a different meaning in ASH (maps), so using them for optional parameters was confusing.
 
(14 intermediate revisions by the same user not shown)
Line 1: Line 1:
<includeonly><kbd><b>{{{return_type}}} {{{name}}}({{
<includeonly>{{
  #if: {{{param1|}}}
  #if: {{data|{{{name}}}|function{{{func}}}.return_type}}
  |{{#if: {{{param1.optional|}}}|&nbsp;<nowiki>[</nowiki>}}&nbsp;{{User:Philmasterplus/Param|{{{param1.type}}}|{{{param1}}}}}{{
  | <kbd><b>{{type|{{data|{{{name}}}|function{{{func}}}.return_type}}}} [[{{data|{{{name}}}|name}}]]({{
  #if: {{{param1.default|}}}| = {{{param1.default|}}}&nbsp;}}{{
    #if: {{data|{{{name}}}|function{{{func}}}.param1.type}}
  #if: {{{param1.optional|}}}|<nowiki>]</nowiki>}}
    |&nbsp;{{param2|name={{{name}}}|func={{{func}}}|param=1|format={{{format}}}}}
}}{{
  }}{{
  #if: {{{param2|}}}
    #if: {{data|{{{name}}}|function{{{func}}}.param2.type}}
   |{{#if: {{{param2.optional|}}}|&nbsp;<nowiki>[</nowiki>}}, {{User:Philmasterplus/Param|{{{param2.type}}}|{{{param2}}}}}{{
    |, {{param2|name={{{name}}}|func={{{func}}}|param=2|format={{{format}}}}}
  #if: {{{param2.default|}}}| = {{{param2.default|}}}&nbsp;}}{{
  }}{{
  #if: {{{param2.optional|}}}|<nowiki>]</nowiki>}}
    #if: {{data|{{{name}}}|function{{{func}}}.param3.type}}
}}{{
    |, {{param2|name={{{name}}}|func={{{func}}}|param=3|format={{{format}}}}}
  #if: {{{param3|}}}
  }}{{
  |{{#if: {{{param3.optional|}}}|&nbsp;<nowiki>[</nowiki>}}, {{User:Philmasterplus/Param|{{{param3.type}}}|{{{param3}}}}}{{
    #if: {{data|{{{name}}}|function{{{func}}}.param4.type}}
  #if: {{{param3.default|}}}| = {{{param3.default|}}}&nbsp;}}{{
    |, {{param2|name={{{name}}}|func={{{func}}}|param=4|format={{{format}}}}}
  #if: {{{param3.optional|}}}|<nowiki>]</nowiki>}}
   }}{{
}}{{
    #if: {{data|{{{name}}}|function{{{func}}}.param5.type}}
  #if: {{{param4|}}}
    |, {{param2|name={{{name}}}|func={{{func}}}|param=5|format={{{format}}}}}
  |{{#if: {{{param4.optional|}}}|&nbsp;<nowiki>[</nowiki>}}, {{User:Philmasterplus/Param|{{{param4.type}}}|{{{param4}}}}}{{
  }}{{
  #if: {{{param4.default|}}}| = {{{param4.default|}}}&nbsp;}}{{
    #if: {{data|{{{name}}}|function{{{func}}}.param1.type}}
  #if: {{{param4.optional|}}}|<nowiki>]</nowiki>}}
    |&nbsp;}})</b></kbd>{{
}}{{
      #if: {{{desc|}}}
  #if: {{{param5|}}}
      | :{{data|{{{name}}}|function{{{func}}}.description}}}}{{
  |{{#if: {{{param5.optional|}}}|&nbsp;<nowiki>[</nowiki>}}, {{User:Philmasterplus/Param|{{{param5.type}}}|{{{param5}}}}}{{
      #if: {{{param_desc|}}}
  #if: {{{param5.default|}}}| = {{{param5.default|}}}&nbsp;}}{{
      |{{
  #if: {{{param5.optional|}}}|<nowiki>]</nowiki>}}
        #if: {{data|{{{name}}}|function{{{func}}}.param1.type}}
}}{{
        | :* {{pspan|{{data|{{{name}}}|function{{{func}}}.param1}}}}: {{data|{{{name}}}|function{{{func}}}.param1.description}}}}{{
  #if: {{{param1|}}}
        #if: {{data|{{{name}}}|function{{{func}}}.param2.type}}
   |&nbsp;
        | :* {{pspan|{{data|{{{name}}}|function{{{func}}}.param2}}}}: {{data|{{{name}}}|function{{{func}}}.param2.description}}}}{{
}})</b></kbd></includeonly><noinclude>
        #if: {{data|{{{name}}}|function{{{func}}}.param3.type}}
        | :* {{pspan|{{data|{{{name}}}|function{{{func}}}.param3}}}}: {{data|{{{name}}}|function{{{func}}}.param3.description}}}}{{
        #if: {{data|{{{name}}}|function{{{func}}}.param4.type}}
        | :* {{pspan|{{data|{{{name}}}|function{{{func}}}.param4}}}}: {{data|{{{name}}}|function{{{func}}}.param4.description}}}}{{
        #if: {{data|{{{name}}}|function{{{func}}}.param5.type}}
        | :* {{pspan|{{data|{{{name}}}|function{{{func}}}.param5}}}}: {{data|{{{name}}}|function{{{func}}}.param5.description}}}}
    }}
   | {{error|Invalid function number (func &#61; "{{{func|}}}") in Template:FunctionDeclaration}}}}</includeonly><noinclude>


<templatedata>
<templatedata>
{
{
   "description": "Displays an ASH function's declaration. This is meant to be transcluded by other templates, rather than function pages.",
   "description": "Displays an ASH function's declaration. This is meant to be transcluded by other templates, rather than regular pages.",
   "params": {
   "params": {
     "param1": {
     "name": {
       "label": "Parameter 1 name",
       "label": "Function page name",
       "description": "Name of parameter 1 (and so on for parameters 2 through 5)",
       "description": "Name of a function page. '''This must be a data page.'''",
      "type": "wiki-page-name",
      "required": true
    },
    "func": {
      "label": "Overloaded function number",
      "description": "A function page may describe multiple overloaded functions under the same name. This parameter allows you to select one. Allowed values are 1-5, inclusive.",
      "type": "number",
      "required": true
    },
    "format": {
      "label": "Rendering format",
      "description": "\"\" (empty string) = show everything, \"signature\" = only show parameter types (i.e. function signature). Default value is empty string (show everything).",
       "type": "line"
       "type": "line"
     },
     },
     "param1.type": {
     "desc": {
       "label": "Parameter 1 type",
       "label": "Show descriptions?",
       "description": "Parameter 1 data type",
       "description": "If set to \"yes\", also show the description of each function and its parameters below the declaration. Technically, any non-empty string works, but please use \"yes\" for ease of maintenance.",
      "type": "line",
       "type": "line"
       "example": "string"
     },
     },
     "param1.optional": {
     "param_desc": {
       "label": "Parameter 1 is optional?",
       "label": "Show parameter descriptions?",
       "description": "\"yes\" = optional. Any non-empty string will do, but please use \"yes\" to make standardization easier.",
       "description": "If set to \"yes\", also show the description of each function's parameters below the declaration. Technically, any non-empty string works, but please use \"yes\" for ease of maintenance.",
      "type": "string",
      "example": "yes"
    },
    "param1.default": {
      "label": "Parameter 1 default value",
      "description": "If this is specified, param1.optional must be \"yes\"",
       "type": "line"
       "type": "line"
     }
     }
Line 60: Line 72:


==Examples==
==Examples==
===No arguments===
{| class="wikitable"
<pre>{{User:Philmasterplus/FunctionDeclaration
! style="width: 50%" | Wiki markup
|name=my_id
! Result
|return_type=int
|-
}}</pre>
! colspan="2" | Normal format
 
|-
{{User:Philmasterplus/FunctionDeclaration
| <pre>{{FunctionDeclaration|name=visit_url|func=1}}</pre>
|name=my_id
| {{FunctionDeclaration|name=visit_url|func=1}}
|return_type=int
|-
}}
| <pre>{{FunctionDeclaration|name=visit_url|func=2}}</pre>
 
| {{FunctionDeclaration|name=visit_url|func=2}}
===Single argument===
|-
<pre>{{User:Philmasterplus/FunctionDeclaration
! colspan="2" | Normal format with description
|name=to_item
|-
|return_type=int
| <pre>{{FunctionDeclaration|name=visit_url|func=1|desc=yes}}</pre>
|param1=it
| {{FunctionDeclaration|name=visit_url|func=1|desc=yes}}
|param1.type=item
|-
}}</pre>
| <pre>{{FunctionDeclaration|name=visit_url|func=2|desc=yes}}</pre>
 
| {{FunctionDeclaration|name=visit_url|func=2|desc=yes}}
{{User:Philmasterplus/FunctionDeclaration
|-
|name=to_item
! colspan="2" | Normal format with description + parameter description
|return_type=int
|-
|param1=it
| <pre>{{FunctionDeclaration|name=visit_url|func=1|desc=yes|param_desc=yes}}</pre>
|param1.type=item
| {{FunctionDeclaration|name=visit_url|func=1|desc=yes|param_desc=yes}}
}}
|-
 
| <pre>{{FunctionDeclaration|name=visit_url|func=2|desc=yes|param_desc=yes}}</pre>
===Multiple arguments===
| {{FunctionDeclaration|name=visit_url|func=2|desc=yes|param_desc=yes}}
<pre>{{User:Philmasterplus/FunctionDeclaration
|-
|name=maximize
! colspan="2" | Signature format
|return_type=record [int]
|-
|param1=expression
|<pre>{{FunctionDeclaration|name=visit_url|func=2|format=signature}}</pre>
|param1.type=string
| {{FunctionDeclaration|name=visit_url|func=2|format=signature}}
|param2=max_price
|-
|param2.type=int
! colspan="2" | Invalid or missing function number
|param3=price_level
|-
|param3.type=int
| <pre>{{FunctionDeclaration|name=visit_url|func=4}}</pre>
|param4=simulate
| {{FunctionDeclaration|name=visit_url|func=4}}
|param4.type=boolean
|-
|param5=include_equip
| <pre>{{FunctionDeclaration|name=visit_url|func=0}}</pre>
|param5.type=boolean
| {{FunctionDeclaration|name=visit_url|func=0}}
}}</pre>
|-
 
| <pre>{{FunctionDeclaration|name=visit_url}}</pre>
{{User:Philmasterplus/FunctionDeclaration
| {{FunctionDeclaration|name=visit_url}}
|name=maximize
|}
|return_type=record [int]
|param1=expression
|param1.type=string
|param2=max_price
|param2.type=int
|param3=price_level
|param3.type=int
|param4=simulate
|param4.type=boolean
|param5=include_equip
|param5.type=boolean
}}
 
===Optional arguments===
<pre>{{User:Philmasterplus/FunctionDeclaration
|name=creatable_turns
|return_type=int
|param1=check_me
|param1.type=item
|param2=qty
|param2.type=int
|param2.optional=yes
|param3=free
|param3.type=boolean
|param3.optional=yes
}}</pre>
 
{{User:Philmasterplus/FunctionDeclaration
|name=creatable_turns
|return_type=int
|param1=check_me
|param1.type=item
|param2=qty
|param2.type=int
|param2.optional=yes
|param3=free
|param3.type=boolean
|param3.optional=yes
}}
 
===Default arguments===
<pre>{{User:Philmasterplus/FunctionDeclaration
|name=visit_url
|return_type=buffer
|param1=url
|param1.type=string
|param2=use_POST
|param2.type=boolean
|param2.optional=yes
|param2.default=true
|param3=encoded
|param3.type=boolean
|param3.optional=yes
|param3.default=false
}}</pre>
 
{{User:Philmasterplus/FunctionDeclaration
|name=visit_url
|return_type=buffer
|param1=url
|param1.type=string
|param1.optional=yes
|param2=use_POST
|param2.type=boolean
|param2.optional=yes
|param2.default=true
|param3=encoded
|param3.type=boolean
|param3.optional=yes
|param3.default=false
|param4=encoded
|param4.type=boolean
|param4.optional=yes
|param4.default=true
}}


[[Category:Basic Templates]]
</noinclude>
</noinclude>

Latest revision as of 14:22, 31 December 2020


Displays an ASH function's declaration. This is meant to be transcluded by other templates, rather than regular pages.

Template parameters[Edit template data]

ParameterDescriptionTypeStatus
Function page namename

Name of a function page. '''This must be a data page.'''

Page namerequired
Overloaded function numberfunc

A function page may describe multiple overloaded functions under the same name. This parameter allows you to select one. Allowed values are 1-5, inclusive.

Numberrequired
Rendering formatformat

"" (empty string) = show everything, "signature" = only show parameter types (i.e. function signature). Default value is empty string (show everything).

Lineoptional
Show descriptions?desc

If set to "yes", also show the description of each function and its parameters below the declaration. Technically, any non-empty string works, but please use "yes" for ease of maintenance.

Lineoptional
Show parameter descriptions?param_desc

If set to "yes", also show the description of each function's parameters below the declaration. Technically, any non-empty string works, but please use "yes" for ease of maintenance.

Lineoptional

Examples

Wiki markup Result
Normal format
{{FunctionDeclaration|name=visit_url|func=1}}
buffer visit_url()
{{FunctionDeclaration|name=visit_url|func=2}}
buffer visit_urlstring url, boolean? use_POST = true, boolean? encoded = false )
Normal format with description
{{FunctionDeclaration|name=visit_url|func=1|desc=yes}}
buffer visit_url()
Returns the original HTML source of the page being overridden inside a relay override script.
{{FunctionDeclaration|name=visit_url|func=2|desc=yes}}
buffer visit_urlstring url, boolean? use_POST = true, boolean? encoded = false )
Visits a web page and returns its HTML source.
Normal format with description + parameter description
{{FunctionDeclaration|name=visit_url|func=1|desc=yes|param_desc=yes}}
buffer visit_url()
Returns the original HTML source of the page being overridden inside a relay override script.
{{FunctionDeclaration|name=visit_url|func=2|desc=yes|param_desc=yes}}
buffer visit_urlstring url, boolean? use_POST = true, boolean? encoded = false )
Visits a web page and returns its HTML source.
  • url: URL of the page to visit. If a relative URL is provided, it is treated as an in-game page.
  • use_POST: If true, makes an HTTP POST request when visiting the URL. Otherwise, makes a GET request.
  • encoded: If true, KoLmafia assumes that url has already been URL-encoded and will not encode it.
Signature format
{{FunctionDeclaration|name=visit_url|func=2|format=signature}}
buffer visit_urlstring, boolean?, boolean? )
Invalid or missing function number
{{FunctionDeclaration|name=visit_url|func=4}}
Invalid function number (func = "4") in Template:FunctionDeclaration
{{FunctionDeclaration|name=visit_url|func=0}}
Invalid function number (func = "0") in Template:FunctionDeclaration
{{FunctionDeclaration|name=visit_url}}
Invalid function number (func = "") in Template:FunctionDeclaration