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>{{{return_type}}} {{{name}}}({{
<includeonly><kbd><b>{{{return_type}}} {{{name}}}({{
   #if: {{{param1|}}}
   #if: {{{param1.type|}}}
   |{{#if: {{{param1.optional|}}}|&nbsp;<nowiki>[</nowiki>}}&nbsp;{{User:Philmasterplus/Param|{{{param1.type}}}|{{{param1}}}}}{{
   |{{#if: {{{param1.optional|}}}|&nbsp;<nowiki>[</nowiki>}}&nbsp;{{User:Philmasterplus/Param|{{{param1.type}}}|{{{param1|}}}}}{{
   #if: {{{param1.default|}}}|&nbsp;= {{{param1.default|}}}&nbsp;}}{{
   #if: {{{param1.default|}}}|&nbsp;= {{{param1.default|}}}}}{{
   #if: {{{param1.optional|}}}|<nowiki>]</nowiki>}}
   #if: {{{param1.optional|}}}|&nbsp;<nowiki>]</nowiki>}}
}}{{
}}{{
   #if: {{{param2|}}}
   #if: {{{param2.type|}}}
   |{{#if: {{{param2.optional|}}}|&nbsp;<nowiki>[</nowiki>}}, {{User:Philmasterplus/Param|{{{param2.type}}}|{{{param2}}}}}{{
   |{{#if: {{{param2.optional|}}}|&nbsp;<nowiki>[</nowiki>}}, {{User:Philmasterplus/Param|{{{param2.type}}}|{{{param2|}}}}}{{
   #if: {{{param2.default|}}}|&nbsp;= {{{param2.default|}}}&nbsp;}}{{
   #if: {{{param2.default|}}}|&nbsp;= {{{param2.default|}}}}}{{
   #if: {{{param2.optional|}}}|<nowiki>]</nowiki>}}
   #if: {{{param2.optional|}}}|&nbsp;<nowiki>]</nowiki>}}
}}{{
}}{{
   #if: {{{param3|}}}
   #if: {{{param3.type|}}}
   |{{#if: {{{param3.optional|}}}|&nbsp;<nowiki>[</nowiki>}}, {{User:Philmasterplus/Param|{{{param3.type}}}|{{{param3}}}}}{{
   |{{#if: {{{param3.optional|}}}|&nbsp;<nowiki>[</nowiki>}}, {{User:Philmasterplus/Param|{{{param3.type}}}|{{{param3|}}}}}{{
   #if: {{{param3.default|}}}|&nbsp;= {{{param3.default|}}}&nbsp;}}{{
   #if: {{{param3.default|}}}|&nbsp;= {{{param3.default|}}}}}{{
   #if: {{{param3.optional|}}}|<nowiki>]</nowiki>}}
   #if: {{{param3.optional|}}}|&nbsp;<nowiki>]</nowiki>}}
}}{{
}}{{
   #if: {{{param4|}}}
   #if: {{{param4.type|}}}
   |{{#if: {{{param4.optional|}}}|&nbsp;<nowiki>[</nowiki>}}, {{User:Philmasterplus/Param|{{{param4.type}}}|{{{param4}}}}}{{
   |{{#if: {{{param4.optional|}}}|&nbsp;<nowiki>[</nowiki>}}, {{User:Philmasterplus/Param|{{{param4.type}}}|{{{param4|}}}}}{{
   #if: {{{param4.default|}}}|&nbsp;= {{{param4.default|}}}&nbsp;}}{{
   #if: {{{param4.default|}}}|&nbsp;= {{{param4.default|}}}}}{{
   #if: {{{param4.optional|}}}|<nowiki>]</nowiki>}}
   #if: {{{param4.optional|}}}|&nbsp;<nowiki>]</nowiki>}}
}}{{
}}{{
   #if: {{{param5|}}}
   #if: {{{param5.type|}}}
   |{{#if: {{{param5.optional|}}}|&nbsp;<nowiki>[</nowiki>}}, {{User:Philmasterplus/Param|{{{param5.type}}}|{{{param5}}}}}{{
   |{{#if: {{{param5.optional|}}}|&nbsp;<nowiki>[</nowiki>}}, {{User:Philmasterplus/Param|{{{param5.type}}}|{{{param5|}}}}}{{
   #if: {{{param5.default|}}}|&nbsp;= {{{param5.default|}}}&nbsp;}}{{
   #if: {{{param5.default|}}}|&nbsp;= {{{param5.default|}}}}}{{
   #if: {{{param5.optional|}}}|<nowiki>]</nowiki>}}
   #if: {{{param5.optional|}}}|&nbsp;<nowiki>]</nowiki>}}
}}{{
}}{{
   #if: {{{param1|}}}
   #if: {{{param1.type|}}}
   |&nbsp;
   |&nbsp;
}})</b></kbd></includeonly><noinclude>
}})</b></kbd></includeonly><noinclude>
Line 46: Line 46:
     "param1": {
     "param1": {
       "label": "Parameter 1 name",
       "label": "Parameter 1 name",
       "description": "Name of parameter 1 (and so on for parameters 2 through 5)",
       "description": "Name of parameter 1 (and so on for parameters 2 through 5). If omitted, only the parameter type will be shown.",
       "type": "line"
       "type": "line"
     },
     },
Line 189: Line 189:
|param4.optional=yes
|param4.optional=yes
|param4.default=true
|param4.default=true
}}
===No parameter names (signature only)===
<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
|name=maximize
|return_type=record [int]
|param1.type=string
|param2.type=int
|param3.type=int
|param4.type=boolean
|param5.type=boolean
}}
}}


</noinclude>
</noinclude>

Revision as of 20:22, 18 December 2020


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

Template parameters[Edit template data]

ParameterDescriptionTypeStatus
Function namename

Name of the function

Lineoptional
Function return typereturn_type

Return type of the function

Example
void, int, string
Lineoptional
Parameter 1 nameparam1

Name of parameter 1 (and so on for parameters 2 through 5). If omitted, only the parameter type will be shown.

Lineoptional
Parameter 1 typeparam1.type

Parameter 1 data type

Example
string
Lineoptional
Parameter 1 is optional?param1.optional

"yes" = optional. Any non-empty string will do, but please use "yes" to make standardization easier.

Example
yes
Stringoptional
Parameter 1 default valueparam1.default

If this is specified, param1.optional must be "yes"

Lineoptional

Examples

No arguments

{{User:Philmasterplus/FunctionDeclaration
|name=my_id
|return_type=int
}}

int my_id()

Single argument

{{User:Philmasterplus/FunctionDeclaration
|name=to_item
|return_type=int
|param1=it
|param1.type=item
}}

int to_item( Page '{{{name}}}' does not exist? Page '{{{name}}}' does not exist = Page '{{{name}}}' does not exist )

Multiple arguments

{{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
}}

record [int] maximize( Page '{{{name}}}' does not exist? Page '{{{name}}}' does not exist = Page '{{{name}}}' does not exist, Page '{{{name}}}' does not exist? Page '{{{name}}}' does not exist = Page '{{{name}}}' does not exist, Page '{{{name}}}' does not exist? Page '{{{name}}}' does not exist = Page '{{{name}}}' does not exist, Page '{{{name}}}' does not exist? Page '{{{name}}}' does not exist = Page '{{{name}}}' does not exist, Page '{{{name}}}' does not exist? Page '{{{name}}}' does not exist = Page '{{{name}}}' does not exist )

Optional arguments

{{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
}}

int creatable_turns( Page '{{{name}}}' does not exist? Page '{{{name}}}' does not exist = Page '{{{name}}}' does not exist [, Page '{{{name}}}' does not exist? Page '{{{name}}}' does not exist = Page '{{{name}}}' does not exist ] [, Page '{{{name}}}' does not exist? Page '{{{name}}}' does not exist = Page '{{{name}}}' does not exist ] )

Default arguments

{{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
}}

buffer visit_url( [ Page '{{{name}}}' does not exist? Page '{{{name}}}' does not exist = Page '{{{name}}}' does not exist ] [, Page '{{{name}}}' does not exist? Page '{{{name}}}' does not exist = Page '{{{name}}}' does not exist = true ] [, Page '{{{name}}}' does not exist? Page '{{{name}}}' does not exist = Page '{{{name}}}' does not exist = false ] [, Page '{{{name}}}' does not exist? Page '{{{name}}}' does not exist = Page '{{{name}}}' does not exist = true ] )

No parameter names (signature only)

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

record [int] maximize( Page '{{{name}}}' does not exist? Page '{{{name}}}' does not exist = Page '{{{name}}}' does not exist, Page '{{{name}}}' does not exist? Page '{{{name}}}' does not exist = Page '{{{name}}}' does not exist, Page '{{{name}}}' does not exist? Page '{{{name}}}' does not exist = Page '{{{name}}}' does not exist, Page '{{{name}}}' does not exist? Page '{{{name}}}' does not exist = Page '{{{name}}}' does not exist, Page '{{{name}}}' does not exist? Page '{{{name}}}' does not exist = Page '{{{name}}}' does not exist )