Template:FunctionDeclaration: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
<includeonly><kbd><b>{{User:Philmasterplus/Type|{{{return_type}}}}} [[{{{name}}}]]({{
<includeonly>{{
  #if: {{{param1.type|}}}
  #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|}}}|&nbsp;= {{{param1.default|}}}}}{{
    #if: {{data|{{{name}}}|function{{{func}}}.param1.type}}
  #if: {{{param1.optional|}}}|&nbsp;<nowiki>]</nowiki>}}
    |&nbsp;{{param2|name={{{name}}}|func={{{func}}}|param=1}}}}{{
}}{{
    #if: {{data|{{{name}}}|function{{{func}}}.param2.type}}
  #if: {{{param2.type|}}}
    |, {{param2|name={{{name}}}|func={{{func}}}|param=2}}}}{{
  |{{#if: {{{param2.optional|}}}|&nbsp;<nowiki>[</nowiki>}}, {{User:Philmasterplus/Param|{{{param2.type}}}|{{{param2|}}}}}{{
    #if: {{data|{{{name}}}|function{{{func}}}.param3.type}}
  #if: {{{param2.default|}}}|&nbsp;= {{{param2.default|}}}}}{{
    |, {{param2|name={{{name}}}|func={{{func}}}|param=3}}}}{{
  #if: {{{param2.optional|}}}|&nbsp;<nowiki>]</nowiki>}}
    #if: {{data|{{{name}}}|function{{{func}}}.param4.type}}
}}{{
    |, {{param2|name={{{name}}}|func={{{func}}}|param=4}}}}{{
  #if: {{{param3.type|}}}
    #if: {{data|{{{name}}}|function{{{func}}}.param5.type}}
  |{{#if: {{{param3.optional|}}}|&nbsp;<nowiki>[</nowiki>}}, {{User:Philmasterplus/Param|{{{param3.type}}}|{{{param3|}}}}}{{
    |, {{param2|name={{{name}}}|func={{{func}}}|param=5}}}}{{
  #if: {{{param3.default|}}}|&nbsp;= {{{param3.default|}}}}}{{
    #if: {{data|{{{name}}}|function{{{func}}}.param1.type}}
  #if: {{{param3.optional|}}}|&nbsp;<nowiki>]</nowiki>}}
    |&nbsp;}})</b></kbd>
}}{{
  | {{error|Invalid function number (func &#61; "{{{func|}}}") in Template:FunctionDeclaration}}}}</includeonly><noinclude>
  #if: {{{param4.type|}}}
  |{{#if: {{{param4.optional|}}}|&nbsp;<nowiki>[</nowiki>}}, {{User:Philmasterplus/Param|{{{param4.type}}}|{{{param4|}}}}}{{
  #if: {{{param4.default|}}}|&nbsp;= {{{param4.default|}}}}}{{
  #if: {{{param4.optional|}}}|&nbsp;<nowiki>]</nowiki>}}
}}{{
  #if: {{{param5.type|}}}
  |{{#if: {{{param5.optional|}}}|&nbsp;<nowiki>[</nowiki>}}, {{User:Philmasterplus/Param|{{{param5.type}}}|{{{param5|}}}}}{{
  #if: {{{param5.default|}}}|&nbsp;= {{{param5.default|}}}}}{{
  #if: {{{param5.optional|}}}|&nbsp;<nowiki>]</nowiki>}}
}}{{
  #if: {{{param1.type|}}}
  |&nbsp;
}})</b></kbd></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": {
     "name": {
     "name": {
       "label": "Function name",
       "label": "Function page name",
       "description": "Name of the function",
       "description": "Name of a function page. '''This must be a data page.'''",
      "type": "line"
       "type": "wiki-page-name",
    },
       "required": true
    "return_type": {
      "label": "Function return type",
      "description": "Return type of the function",
      "type": "line",
      "example": "void, int, string"
    },
    "param1": {
      "label": "Parameter 1 name",
      "description": "Name of parameter 1 (and so on for parameters 2 through 5). If omitted, only the parameter type will be shown.",
       "type": "line"
    },
    "param1.type": {
      "label": "Parameter 1 type",
      "description": "Parameter 1 data type",
       "type": "line",
      "example": "string"
     },
     },
     "param1.optional": {
     "func": {
       "label": "Parameter 1 is optional?",
       "label": "Overloaded function number",
       "description": "\"yes\" = optional. Any non-empty string will do, but please use \"yes\" to make standardization easier.",
       "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": "string",
       "type": "number",
       "example": "yes"
       "required": true
     },
     },
     "param1.default": {
     "format": {
       "label": "Parameter 1 default value",
       "label": "Rendering format",
       "description": "If this is specified, param1.optional must be \"yes\"",
       "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"
     }
     }
Line 71: Line 42:


==Examples==
==Examples==
===No arguments===
<pre>{{User:Philmasterplus/FunctionDeclaration|name=User:Philmasterplus/Sandbox|func=1}}</pre>
<pre>{{User:Philmasterplus/FunctionDeclaration
|name=my_id
|return_type=int
}}</pre>
 
{{User:Philmasterplus/FunctionDeclaration
|name=my_id
|return_type=int
}}
 
===Single argument===
<pre>{{User:Philmasterplus/FunctionDeclaration
|name=to_item
|return_type=int
|param1=it
|param1.type=item
}}</pre>
 
{{User:Philmasterplus/FunctionDeclaration
|name=to_item
|return_type=int
|param1=it
|param1.type=item
}}


===Multiple arguments===
{{User:Philmasterplus/FunctionDeclaration|name=User:Philmasterplus/Sandbox|func=1}}
<pre>{{User:Philmasterplus/FunctionDeclaration
|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
}}</pre>


{{User:Philmasterplus/FunctionDeclaration
<pre>{{User:Philmasterplus/FunctionDeclaration|name=User:Philmasterplus/Sandbox|func=2}}</pre>
|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===
{{User:Philmasterplus/FunctionDeclaration|name=User:Philmasterplus/Sandbox|func=2}}
<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
<pre>{{User:Philmasterplus/FunctionDeclaration|name=User:Philmasterplus/Sandbox|func=4}}</pre>
|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===
{{User:Philmasterplus/FunctionDeclaration|name=User:Philmasterplus/Sandbox|func=4}}
<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
<pre>{{User:Philmasterplus/FunctionDeclaration|name=User:Philmasterplus/Sandbox|func=0}}</pre>
|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
}}


===No parameter names (signature only)===
{{User:Philmasterplus/FunctionDeclaration|name=User:Philmasterplus/Sandbox|func=0}}
<pre>{{User:Philmasterplus/FunctionDeclaration
|name=maximize
|return_type=record [int]
|param1.type=string
|param2.type=int
|param3.type=int
|param4.type=boolean
|param5.type=boolean
}}</pre>


{{User:Philmasterplus/FunctionDeclaration
<pre>{{User:Philmasterplus/FunctionDeclaration|name=User:Philmasterplus/Sandbox}}</pre>
|name=maximize
|return_type=record [int]
|param1.type=string
|param2.type=int
|param3.type=int
|param4.type=boolean
|param5.type=boolean
}}


{{User:Philmasterplus/FunctionDeclaration|name=User:Philmasterplus/Sandbox}}
</noinclude>
</noinclude>

Revision as of 23:08, 18 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

Examples

{{User:Philmasterplus/FunctionDeclaration|name=User:Philmasterplus/Sandbox|func=1}}

Nothing to see here, move along. Nothing to see here, move along.( Nothing to see here, move along.? Nothing to see here, move along. = Nothing to see here, move along., Nothing to see here, move along.? Nothing to see here, move along. = Nothing to see here, move along., Nothing to see here, move along.? Nothing to see here, move along. = Nothing to see here, move along., Nothing to see here, move along.? Nothing to see here, move along. = Nothing to see here, move along., Nothing to see here, move along.? Nothing to see here, move along. = Nothing to see here, move along. )

{{User:Philmasterplus/FunctionDeclaration|name=User:Philmasterplus/Sandbox|func=2}}

Nothing to see here, move along. Nothing to see here, move along.( Nothing to see here, move along.? Nothing to see here, move along. = Nothing to see here, move along., Nothing to see here, move along.? Nothing to see here, move along. = Nothing to see here, move along., Nothing to see here, move along.? Nothing to see here, move along. = Nothing to see here, move along., Nothing to see here, move along.? Nothing to see here, move along. = Nothing to see here, move along., Nothing to see here, move along.? Nothing to see here, move along. = Nothing to see here, move along. )

{{User:Philmasterplus/FunctionDeclaration|name=User:Philmasterplus/Sandbox|func=4}}

Nothing to see here, move along. Nothing to see here, move along.( Nothing to see here, move along.? Nothing to see here, move along. = Nothing to see here, move along., Nothing to see here, move along.? Nothing to see here, move along. = Nothing to see here, move along., Nothing to see here, move along.? Nothing to see here, move along. = Nothing to see here, move along., Nothing to see here, move along.? Nothing to see here, move along. = Nothing to see here, move along., Nothing to see here, move along.? Nothing to see here, move along. = Nothing to see here, move along. )

{{User:Philmasterplus/FunctionDeclaration|name=User:Philmasterplus/Sandbox|func=0}}

Nothing to see here, move along. Nothing to see here, move along.( Nothing to see here, move along.? Nothing to see here, move along. = Nothing to see here, move along., Nothing to see here, move along.? Nothing to see here, move along. = Nothing to see here, move along., Nothing to see here, move along.? Nothing to see here, move along. = Nothing to see here, move along., Nothing to see here, move along.? Nothing to see here, move along. = Nothing to see here, move along., Nothing to see here, move along.? Nothing to see here, move along. = Nothing to see here, move along. )

{{User:Philmasterplus/FunctionDeclaration|name=User:Philmasterplus/Sandbox}}

Nothing to see here, move along. Nothing to see here, move along.( Nothing to see here, move along.? Nothing to see here, move along. = Nothing to see here, move along., Nothing to see here, move along.? Nothing to see here, move along. = Nothing to see here, move along., Nothing to see here, move along.? Nothing to see here, move along. = Nothing to see here, move along., Nothing to see here, move along.? Nothing to see here, move along. = Nothing to see here, move along., Nothing to see here, move along.? Nothing to see here, move along. = Nothing to see here, move along. )