CINXE.COM

Extension:Scribunto/Lua reference manual - MediaWiki

<!DOCTYPE html> <html class="client-nojs vector-feature-language-in-header-disabled vector-feature-language-in-main-page-header-disabled vector-feature-sticky-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-feature-night-mode-disabled skin-theme-clientpref-day vector-toc-available" lang="en" dir="ltr"> <head> <meta charset="UTF-8"> <title>Extension:Scribunto/Lua reference manual - MediaWiki</title> <script>(function(){var className="client-js vector-feature-language-in-header-disabled vector-feature-language-in-main-page-header-disabled vector-feature-sticky-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-feature-night-mode-disabled skin-theme-clientpref-day vector-toc-available";var cookie=document.cookie.match(/(?:^|; )mediawikiwikimwclientpreferences=([^;]+)/);if(cookie){cookie[1].split('%2C').forEach(function(pref){className=className.replace(new RegExp('(^| )'+pref.replace(/-clientpref-\w+$|[^\w-]+/g,'')+'-clientpref-\\w+( |$)'),'$1'+pref+'$2');});}document.documentElement.className=className;}());RLCONF={"wgBreakFrames":false,"wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""], "wgDefaultDateFormat":"dmy","wgMonthNames":["","January","February","March","April","May","June","July","August","September","October","November","December"],"wgRequestId":"22a2d53f-4097-4948-88a5-69d40fffef7b","wgCanonicalNamespace":"Extension","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":102,"wgPageName":"Extension:Scribunto/Lua_reference_manual","wgTitle":"Scribunto/Lua reference manual","wgCurRevisionId":6855937,"wgRevisionId":6855937,"wgArticleId":94994,"wgIsArticle":true,"wgIsRedirect":false,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":["Lua"],"wgPageViewLanguage":"en","wgPageContentLanguage":"en","wgPageContentModel":"wikitext","wgRelevantPageName":"Extension:Scribunto/Lua_reference_manual","wgRelevantArticleId":94994,"wgIsProbablyEditable":false,"wgRelevantPageIsProbablyEditable":false,"wgRestrictionEdit":["autoconfirmed"],"wgRestrictionMove":["autoconfirmed"],"wgNoticeProject":"mediawiki","wgCiteReferencePreviewsActive":true, "wgMediaViewerOnClick":true,"wgMediaViewerEnabledByDefault":true,"wgVisualEditor":{"pageLanguageCode":"en","pageLanguageDir":"ltr","pageVariantFallbacks":"en"},"wgMFDisplayWikibaseDescriptions":{"search":true,"watchlist":true,"tagline":false,"nearby":true},"wgWMESchemaEditAttemptStepOversample":false,"wgWMEPageLength":300000,"wgTranslatePageTranslation":"source","wgCentralAuthMobileDomain":false,"wgEditSubmitButtonLabelPublish":true,"wgULSPosition":"personal","wgULSisCompactLinksEnabled":true,"wgVector2022LanguageInHeader":false,"wgULSisLanguageSelectorEmpty":false,"wgWikibaseItemId":"Q26134952","wgCheckUserClientHintsHeadersJsApi":["brands","architecture","bitness","fullVersionList","mobile","model","platform","platformVersion"]};RLSTATE={"ext.globalCssJs.user.styles":"ready","site.styles":"ready","user.styles":"ready","ext.globalCssJs.user":"ready","user":"ready","user.options":"loading","ext.translate.tag.languages":"ready","ext.pygments":"ready","ext.math.styles":"ready", "skins.vector.search.codex.styles":"ready","skins.vector.styles":"ready","skins.vector.icons":"ready","ext.translate.edit.documentation.styles":"ready","ext.translate":"ready","ext.wikimediamessages.styles":"ready","ext.visualEditor.desktopArticleTarget.noscript":"ready","ext.uls.pt":"ready","wikibase.client.init":"ready","ext.wikimediaBadges":"ready"};RLPAGEMODULES=["ext.pygments.view","mediawiki.page.media","site","mediawiki.page.ready","mediawiki.toc","skins.vector.js","ext.centralNotice.geoIP","ext.centralNotice.startUp","ext.translate.pagetranslation.uls","ext.urlShortener.toolbar","ext.centralauth.centralautologin","mmv.bootstrap","ext.visualEditor.desktopArticleTarget.init","ext.visualEditor.targetLoader","ext.echo.centralauth","ext.eventLogging","ext.wikimediaEvents","ext.navigationTiming","ext.uls.compactlinks","ext.uls.interface","wikibase.client.vector-2022","ext.checkUser.clientHints","wikibase.sidebar.tracking"];</script> <script>(RLQ=window.RLQ||[]).push(function(){mw.loader.impl(function(){return["user.options@12s5i",function($,jQuery,require,module){mw.user.tokens.set({"patrolToken":"+\\","watchToken":"+\\","csrfToken":"+\\"}); }];});});</script> <link rel="stylesheet" href="/w/load.php?lang=en&amp;modules=ext.math.styles%7Cext.pygments%2Ctranslate%2CwikimediaBadges%7Cext.translate.edit.documentation.styles%7Cext.translate.tag.languages%7Cext.uls.pt%7Cext.visualEditor.desktopArticleTarget.noscript%7Cext.wikimediamessages.styles%7Cskins.vector.icons%2Cstyles%7Cskins.vector.search.codex.styles%7Cwikibase.client.init&amp;only=styles&amp;skin=vector-2022"> <script async="" src="/w/load.php?lang=en&amp;modules=startup&amp;only=scripts&amp;raw=1&amp;skin=vector-2022"></script> <meta name="ResourceLoaderDynamicStyles" content=""> <link rel="stylesheet" href="/w/load.php?lang=en&amp;modules=site.styles&amp;only=styles&amp;skin=vector-2022"> <meta name="generator" content="MediaWiki 1.44.0-wmf.4"> <meta name="referrer" content="origin"> <meta name="referrer" content="origin-when-cross-origin"> <meta name="robots" content="max-image-preview:standard"> <meta name="format-detection" content="telephone=no"> <meta property="og:image" content="https://upload.wikimedia.org/wikipedia/commons/thumb/2/26/MediaWiki_fallback_chains.svg/1200px-MediaWiki_fallback_chains.svg.png"> <meta property="og:image:width" content="1200"> <meta property="og:image:height" content="1371"> <meta property="og:image" content="https://upload.wikimedia.org/wikipedia/commons/thumb/2/26/MediaWiki_fallback_chains.svg/800px-MediaWiki_fallback_chains.svg.png"> <meta property="og:image:width" content="800"> <meta property="og:image:height" content="914"> <meta property="og:image" content="https://upload.wikimedia.org/wikipedia/commons/thumb/2/26/MediaWiki_fallback_chains.svg/640px-MediaWiki_fallback_chains.svg.png"> <meta property="og:image:width" content="640"> <meta property="og:image:height" content="731"> <meta name="viewport" content="width=1120"> <meta property="og:site_name" content="MediaWiki"> <meta property="og:title" content="Extension:Scribunto/Lua reference manual - MediaWiki"> <meta property="og:type" content="website"> <link rel="preconnect" href="//upload.wikimedia.org"> <link rel="alternate" media="only screen and (max-width: 640px)" href="//m.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual"> <link rel="apple-touch-icon" href="/static/apple-touch/mediawiki.png"> <link rel="icon" href="/static/favicon/mediawiki.ico"> <link rel="search" type="application/opensearchdescription+xml" href="/w/rest.php/v1/search" title="MediaWiki (en)"> <link rel="EditURI" type="application/rsd+xml" href="//www.mediawiki.org/w/api.php?action=rsd"> <link rel="canonical" href="https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual"> <link rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/"> <link rel="alternate" type="application/atom+xml" title="MediaWiki Atom feed" href="/w/index.php?title=Special:RecentChanges&amp;feed=atom"> <link rel="dns-prefetch" href="//meta.wikimedia.org" /> <link rel="dns-prefetch" href="//login.wikimedia.org"> </head> <body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-102 ns-subject page-Extension_Scribunto_Lua_reference_manual rootpage-Extension_Scribunto skin-vector-2022 action-view"><a class="mw-jump-link" href="#bodyContent">Jump to content</a> <div class="vector-header-container"> <header class="vector-header mw-header"> <div class="vector-header-start"> <nav class="vector-main-menu-landmark" aria-label="Site"> <div id="vector-main-menu-dropdown" class="vector-dropdown vector-main-menu-dropdown vector-button-flush-left vector-button-flush-right" > <input type="checkbox" id="vector-main-menu-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-main-menu-dropdown" class="vector-dropdown-checkbox " aria-label="Main menu" > <label id="vector-main-menu-dropdown-label" for="vector-main-menu-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-menu mw-ui-icon-wikimedia-menu"></span> <span class="vector-dropdown-label-text">Main menu</span> </label> <div class="vector-dropdown-content"> <div id="vector-main-menu-unpinned-container" class="vector-unpinned-container"> <div id="vector-main-menu" class="vector-main-menu vector-pinnable-element"> <div class="vector-pinnable-header vector-main-menu-pinnable-header vector-pinnable-header-unpinned" data-feature-name="main-menu-pinned" data-pinnable-element-id="vector-main-menu" data-pinned-container-id="vector-main-menu-pinned-container" data-unpinned-container-id="vector-main-menu-unpinned-container" > <div class="vector-pinnable-header-label">Main menu</div> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-main-menu.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-main-menu.unpin">hide</button> </div> <div id="p-navigation" class="vector-menu mw-portlet mw-portlet-navigation" > <div class="vector-menu-heading"> Navigation </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="n-mainpage-description" class="mw-list-item"><a href="/wiki/MediaWiki" title="Visit the main page [z]" accesskey="z"><span>Main page</span></a></li><li id="n-mw-download" class="mw-list-item"><a href="/wiki/Download"><span>Get MediaWiki</span></a></li><li id="n-mw-extensions" class="mw-list-item"><a href="/wiki/Special:MyLanguage/Category:Extensions"><span>Get extensions</span></a></li><li id="n-blog-text" class="mw-list-item"><a href="https://techblog.wikimedia.org/"><span>Tech blog</span></a></li><li id="n-mw-contribute" class="mw-list-item"><a href="/wiki/Special:MyLanguage/How_to_contribute"><span>Contribute</span></a></li> </ul> </div> </div> <div id="p-support" class="vector-menu mw-portlet mw-portlet-support" > <div class="vector-menu-heading"> Support </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="n-help" class="mw-list-item"><a href="/wiki/Special:MyLanguage/Help:Contents" title="The place to find out"><span>User help</span></a></li><li id="n-mw-faq" class="mw-list-item"><a href="/wiki/Special:MyLanguage/Manual:FAQ"><span>FAQ</span></a></li><li id="n-mw-manual" class="mw-list-item"><a href="/wiki/Special:MyLanguage/Manual:Contents"><span>Technical manual</span></a></li><li id="n-mw-supportdesk" class="mw-list-item"><a href="/wiki/Project:Support_desk"><span>Support desk</span></a></li><li id="n-mw-communication" class="mw-list-item"><a href="/wiki/Special:MyLanguage/Communication"><span>Communication</span></a></li> </ul> </div> </div> <div id="p-development" class="vector-menu mw-portlet mw-portlet-development" > <div class="vector-menu-heading"> Development </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="n-mw-developerportal" class="mw-list-item"><a href="https://developer.wikimedia.org/"><span>Developer portal</span></a></li><li id="n-svn-statistics" class="mw-list-item"><a href="/wiki/Development_statistics"><span>Code statistics</span></a></li> </ul> </div> </div> <div id="p-mediawiki.org" class="vector-menu mw-portlet mw-portlet-mediawiki_org" > <div class="vector-menu-heading"> mediawiki.org </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="n-portal" class="mw-list-item"><a href="/wiki/Project:Help" title="About the project, what you can do, where to find things"><span>Community portal</span></a></li><li id="n-recentchanges" class="mw-list-item"><a href="/wiki/Special:RecentChanges" title="A list of recent changes in the wiki [r]" accesskey="r"><span>Recent changes</span></a></li><li id="n-mw-translate" class="mw-list-item"><a href="/wiki/Special:LanguageStats"><span>Translate content</span></a></li><li id="n-randompage" class="mw-list-item"><a href="/wiki/Special:Random" title="Load a random page [x]" accesskey="x"><span>Random page</span></a></li><li id="n-mw-discussion" class="mw-list-item"><a href="/wiki/Project:Village_Pump"><span>Village pump</span></a></li><li id="n-Sandboxlink-portlet-label" class="mw-list-item"><a href="/wiki/Project:Sandbox"><span>Sandbox</span></a></li> </ul> </div> </div> <div id="p-lang" class="vector-menu mw-portlet mw-portlet-lang" > <div class="vector-menu-heading"> In other languages </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> <div class="after-portlet after-portlet-lang"><span class="wb-langlinks-add wb-langlinks-link"><a href="https://www.wikidata.org/wiki/Special:EntityPage/Q26134952#sitelinks-wikipedia" title="Add interlanguage links" class="wbc-editpage">Add links</a></span></div> </div> </div> </div> </div> </div> </div> </nav> <a href="/wiki/MediaWiki" class="mw-logo"> <img class="mw-logo-icon" src="/static/images/icons/mediawikiwiki.svg" alt="" aria-hidden="true" height="50" width="50"> <span class="mw-logo-container skin-invert"> <img class="mw-logo-wordmark" alt="MediaWiki" src="/static/images/mobile/copyright/mediawikiwiki-wordmark.svg" style="width: 7.5em; height: 1.125em;"> </span> </a> </div> <div class="vector-header-end"> <div id="p-search" role="search" class="vector-search-box-vue vector-search-box-collapses vector-search-box-show-thumbnail vector-search-box-auto-expand-width vector-search-box"> <a href="/wiki/Special:Search" class="cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only search-toggle" title="Search MediaWiki [f]" accesskey="f"><span class="vector-icon mw-ui-icon-search mw-ui-icon-wikimedia-search"></span> <span>Search</span> </a> <div class="vector-typeahead-search-container"> <div class="cdx-typeahead-search cdx-typeahead-search--show-thumbnail cdx-typeahead-search--auto-expand-width"> <form action="/w/index.php" id="searchform" class="cdx-search-input cdx-search-input--has-end-button"> <div id="simpleSearch" class="cdx-search-input__input-wrapper" data-search-loc="header-moved"> <div class="cdx-text-input cdx-text-input--has-start-icon"> <input class="cdx-text-input__input" type="search" name="search" placeholder="Search MediaWiki" aria-label="Search MediaWiki" autocapitalize="sentences" title="Search MediaWiki [f]" accesskey="f" id="searchInput" > <span class="cdx-text-input__icon cdx-text-input__start-icon"></span> </div> <input type="hidden" name="title" value="Special:Search"> </div> <button class="cdx-button cdx-search-input__end-button">Search</button> </form> </div> </div> </div> <nav class="vector-user-links vector-user-links-wide" aria-label="Personal tools"> <div class="vector-user-links-main"> <div id="p-vector-user-menu-preferences" class="vector-menu mw-portlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-uls" class="mw-list-item active user-links-collapsible-item"><a data-mw="interface" href="#" class="uls-trigger cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet"><span class="vector-icon mw-ui-icon-wikimedia-language mw-ui-icon-wikimedia-wikimedia-language"></span> <span>English</span></a> </li> </ul> </div> </div> <div id="p-vector-user-menu-userpage" class="vector-menu mw-portlet emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> <nav class="vector-appearance-landmark" aria-label="Appearance"> <div id="vector-appearance-dropdown" class="vector-dropdown " title="Change the appearance of the page&#039;s font size, width, and color" > <input type="checkbox" id="vector-appearance-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-appearance-dropdown" class="vector-dropdown-checkbox " aria-label="Appearance" > <label id="vector-appearance-dropdown-label" for="vector-appearance-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-appearance mw-ui-icon-wikimedia-appearance"></span> <span class="vector-dropdown-label-text">Appearance</span> </label> <div class="vector-dropdown-content"> <div id="vector-appearance-unpinned-container" class="vector-unpinned-container"> </div> </div> </div> </nav> <div id="p-vector-user-menu-notifications" class="vector-menu mw-portlet emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> <div id="p-vector-user-menu-overflow" class="vector-menu mw-portlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="pt-sitesupport-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="https://donate.wikimedia.org/?utm_source=donate&amp;utm_medium=sidebar&amp;utm_campaign=spontaneous&amp;uselang=en" class=""><span>Donate</span></a> </li> <li id="pt-createaccount-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="/w/index.php?title=Special:CreateAccount&amp;returnto=Extension%3AScribunto%2FLua+reference+manual" title="You are encouraged to create an account and log in; however, it is not mandatory" class=""><span>Create account</span></a> </li> <li id="pt-login-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="/w/index.php?title=Special:UserLogin&amp;returnto=Extension%3AScribunto%2FLua+reference+manual" title="You are encouraged to log in; however, it is not mandatory [o]" accesskey="o" class=""><span>Log in</span></a> </li> </ul> </div> </div> </div> <div id="vector-user-links-dropdown" class="vector-dropdown vector-user-menu vector-button-flush-right vector-user-menu-logged-out" title="More options" > <input type="checkbox" id="vector-user-links-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-user-links-dropdown" class="vector-dropdown-checkbox " aria-label="Personal tools" > <label id="vector-user-links-dropdown-label" for="vector-user-links-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-ellipsis mw-ui-icon-wikimedia-ellipsis"></span> <span class="vector-dropdown-label-text">Personal tools</span> </label> <div class="vector-dropdown-content"> <div id="p-personal" class="vector-menu mw-portlet mw-portlet-personal user-links-collapsible-item" title="User menu" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="pt-sitesupport" class="user-links-collapsible-item mw-list-item"><a href="https://donate.wikimedia.org/?utm_source=donate&amp;utm_medium=sidebar&amp;utm_campaign=spontaneous&amp;uselang=en"><span>Donate</span></a></li><li id="pt-createaccount" class="user-links-collapsible-item mw-list-item"><a href="/w/index.php?title=Special:CreateAccount&amp;returnto=Extension%3AScribunto%2FLua+reference+manual" title="You are encouraged to create an account and log in; however, it is not mandatory"><span class="vector-icon mw-ui-icon-userAdd mw-ui-icon-wikimedia-userAdd"></span> <span>Create account</span></a></li><li id="pt-login" class="user-links-collapsible-item mw-list-item"><a href="/w/index.php?title=Special:UserLogin&amp;returnto=Extension%3AScribunto%2FLua+reference+manual" title="You are encouraged to log in; however, it is not mandatory [o]" accesskey="o"><span class="vector-icon mw-ui-icon-logIn mw-ui-icon-wikimedia-logIn"></span> <span>Log in</span></a></li> </ul> </div> </div> <div id="p-user-menu-anon-editor" class="vector-menu mw-portlet mw-portlet-user-menu-anon-editor" > <div class="vector-menu-heading"> Pages for logged out editors <a href="/wiki/Help:Introduction" aria-label="Learn more about editing"><span>learn more</span></a> </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="pt-anoncontribs" class="mw-list-item"><a href="/wiki/Special:MyContributions" title="A list of edits made from this IP address [y]" accesskey="y"><span>Contributions</span></a></li><li id="pt-anontalk" class="mw-list-item"><a href="/wiki/Special:MyTalk" title="Discussion about edits from this IP address [n]" accesskey="n"><span>Talk</span></a></li> </ul> </div> </div> </div> </div> </nav> </div> </header> </div> <div class="mw-page-container"> <div class="mw-page-container-inner"> <div class="vector-sitenotice-container"> <div id="siteNotice"><!-- CentralNotice --></div> </div> <div class="vector-column-start"> <div class="vector-main-menu-container"> <div id="mw-navigation"> <nav id="mw-panel" class="vector-main-menu-landmark" aria-label="Site"> <div id="vector-main-menu-pinned-container" class="vector-pinned-container"> </div> </nav> </div> </div> <div class="vector-sticky-pinned-container"> <nav id="mw-panel-toc" aria-label="Contents" data-event-name="ui.sidebar-toc" class="mw-table-of-contents-container vector-toc-landmark"> <div id="vector-toc-pinned-container" class="vector-pinned-container"> <div id="vector-toc" class="vector-toc vector-pinnable-element"> <div class="vector-pinnable-header vector-toc-pinnable-header vector-pinnable-header-pinned" data-feature-name="toc-pinned" data-pinnable-element-id="vector-toc" > <h2 class="vector-pinnable-header-label">Contents</h2> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-toc.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-toc.unpin">hide</button> </div> <ul class="vector-toc-contents" id="mw-panel-toc-list"> <li id="toc-mw-content-text" class="vector-toc-list-item vector-toc-level-1"> <a href="#" class="vector-toc-link"> <div class="vector-toc-text">Beginning</div> </a> </li> <li id="toc-Introduction" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Introduction"> <div class="vector-toc-text"> <span class="vector-toc-numb">1</span> <span>Introduction</span> </div> </a> <button aria-controls="toc-Introduction-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Introduction subsection</span> </button> <ul id="toc-Introduction-sublist" class="vector-toc-list"> <li id="toc-Getting_started" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Getting_started"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.1</span> <span>Getting started</span> </div> </a> <ul id="toc-Getting_started-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Module_structure" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Module_structure"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.2</span> <span>Module structure</span> </div> </a> <ul id="toc-Module_structure-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Accessing_parameters_from_wikitext" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Accessing_parameters_from_wikitext"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.3</span> <span>Accessing parameters from wikitext</span> </div> </a> <ul id="toc-Accessing_parameters_from_wikitext-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Returning_text" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Returning_text"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.4</span> <span>Returning text</span> </div> </a> <ul id="toc-Returning_text-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Module_documentation" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Module_documentation"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.5</span> <span>Module documentation</span> </div> </a> <ul id="toc-Module_documentation-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Renaming_or_moving_modules" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Renaming_or_moving_modules"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.6</span> <span>Renaming or moving modules</span> </div> </a> <ul id="toc-Renaming_or_moving_modules-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Lua_language" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Lua_language"> <div class="vector-toc-text"> <span class="vector-toc-numb">2</span> <span>Lua language</span> </div> </a> <button aria-controls="toc-Lua_language-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Lua language subsection</span> </button> <ul id="toc-Lua_language-sublist" class="vector-toc-list"> <li id="toc-Tokens" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Tokens"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.1</span> <span>Tokens</span> </div> </a> <ul id="toc-Tokens-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Comments" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Comments"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.2</span> <span>Comments</span> </div> </a> <ul id="toc-Comments-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Data_types" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Data_types"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.3</span> <span>Data types</span> </div> </a> <ul id="toc-Data_types-sublist" class="vector-toc-list"> <li id="toc-nil" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#nil"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.3.1</span> <span>nil</span> </div> </a> <ul id="toc-nil-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-boolean" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#boolean"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.3.2</span> <span>boolean</span> </div> </a> <ul id="toc-boolean-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-string" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#string"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.3.3</span> <span>string</span> </div> </a> <ul id="toc-string-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-number" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#number"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.3.4</span> <span>number</span> </div> </a> <ul id="toc-number-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-table" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#table"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.3.5</span> <span>table</span> </div> </a> <ul id="toc-table-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-function" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#function"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.3.6</span> <span>function</span> </div> </a> <ul id="toc-function-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Unsupported_types" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Unsupported_types"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.3.7</span> <span>Unsupported types</span> </div> </a> <ul id="toc-Unsupported_types-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Upvalues" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Upvalues"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.4</span> <span>Upvalues</span> </div> </a> <ul id="toc-Upvalues-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Metatables" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Metatables"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.5</span> <span>Metatables</span> </div> </a> <ul id="toc-Metatables-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Variables" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Variables"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.6</span> <span>Variables</span> </div> </a> <ul id="toc-Variables-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Expressions" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Expressions"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.7</span> <span>Expressions</span> </div> </a> <ul id="toc-Expressions-sublist" class="vector-toc-list"> <li id="toc-Arithmetic_operators" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Arithmetic_operators"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.7.1</span> <span>Arithmetic operators</span> </div> </a> <ul id="toc-Arithmetic_operators-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Relational_operators" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Relational_operators"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.7.2</span> <span>Relational operators</span> </div> </a> <ul id="toc-Relational_operators-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Logical_operators" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Logical_operators"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.7.3</span> <span>Logical operators</span> </div> </a> <ul id="toc-Logical_operators-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Concatenation_operator" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Concatenation_operator"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.7.4</span> <span>Concatenation operator</span> </div> </a> <ul id="toc-Concatenation_operator-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Length_operator" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Length_operator"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.7.5</span> <span>Length operator</span> </div> </a> <ul id="toc-Length_operator-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Operator_precedence" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Operator_precedence"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.7.6</span> <span>Operator precedence</span> </div> </a> <ul id="toc-Operator_precedence-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Function_calls" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Function_calls"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.7.7</span> <span>Function calls</span> </div> </a> <ul id="toc-Function_calls-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Function_declarations" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Function_declarations"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.7.8</span> <span>Function declarations</span> </div> </a> <ul id="toc-Function_declarations-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Statements" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Statements"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.8</span> <span>Statements</span> </div> </a> <ul id="toc-Statements-sublist" class="vector-toc-list"> <li id="toc-Assignments" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Assignments"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.8.1</span> <span>Assignments</span> </div> </a> <ul id="toc-Assignments-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Local_variable_declarations" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Local_variable_declarations"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.8.2</span> <span>Local variable declarations</span> </div> </a> <ul id="toc-Local_variable_declarations-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Control_structures" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Control_structures"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.8.3</span> <span>Control structures</span> </div> </a> <ul id="toc-Control_structures-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Function_calls_as_statements" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Function_calls_as_statements"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.8.4</span> <span>Function calls as statements</span> </div> </a> <ul id="toc-Function_calls_as_statements-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Function_declaration_statements" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Function_declaration_statements"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.8.5</span> <span>Function declaration statements</span> </div> </a> <ul id="toc-Function_declaration_statements-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Error_handling" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Error_handling"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.9</span> <span>Error handling</span> </div> </a> <ul id="toc-Error_handling-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Garbage_collection" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Garbage_collection"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.10</span> <span>Garbage collection</span> </div> </a> <ul id="toc-Garbage_collection-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Standard_libraries" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Standard_libraries"> <div class="vector-toc-text"> <span class="vector-toc-numb">3</span> <span>Standard libraries</span> </div> </a> <button aria-controls="toc-Standard_libraries-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Standard libraries subsection</span> </button> <ul id="toc-Standard_libraries-sublist" class="vector-toc-list"> <li id="toc-Basic_functions" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Basic_functions"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.1</span> <span>Basic functions</span> </div> </a> <ul id="toc-Basic_functions-sublist" class="vector-toc-list"> <li id="toc-G" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#G"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.1.1</span> <span>_G</span> </div> </a> <ul id="toc-G-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-VERSION" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#VERSION"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.1.2</span> <span>_VERSION</span> </div> </a> <ul id="toc-VERSION-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-assert" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#assert"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.1.3</span> <span>assert</span> </div> </a> <ul id="toc-assert-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-error" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#error"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.1.4</span> <span>error</span> </div> </a> <ul id="toc-error-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-getfenv" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#getfenv"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.1.5</span> <span>getfenv</span> </div> </a> <ul id="toc-getfenv-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-getmetatable" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#getmetatable"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.1.6</span> <span>getmetatable</span> </div> </a> <ul id="toc-getmetatable-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-ipairs" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#ipairs"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.1.7</span> <span>ipairs</span> </div> </a> <ul id="toc-ipairs-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-next" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#next"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.1.8</span> <span>next</span> </div> </a> <ul id="toc-next-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-pairs" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#pairs"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.1.9</span> <span>pairs</span> </div> </a> <ul id="toc-pairs-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-pcall" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#pcall"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.1.10</span> <span>pcall</span> </div> </a> <ul id="toc-pcall-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-rawequal" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#rawequal"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.1.11</span> <span>rawequal</span> </div> </a> <ul id="toc-rawequal-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-rawget" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#rawget"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.1.12</span> <span>rawget</span> </div> </a> <ul id="toc-rawget-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-rawset" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#rawset"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.1.13</span> <span>rawset</span> </div> </a> <ul id="toc-rawset-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-select" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#select"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.1.14</span> <span>select</span> </div> </a> <ul id="toc-select-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-setmetatable" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#setmetatable"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.1.15</span> <span>setmetatable</span> </div> </a> <ul id="toc-setmetatable-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-tonumber" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#tonumber"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.1.16</span> <span>tonumber</span> </div> </a> <ul id="toc-tonumber-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-tostring" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#tostring"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.1.17</span> <span>tostring</span> </div> </a> <ul id="toc-tostring-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-type" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#type"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.1.18</span> <span>type</span> </div> </a> <ul id="toc-type-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-unpack" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#unpack"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.1.19</span> <span>unpack</span> </div> </a> <ul id="toc-unpack-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-xpcall" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#xpcall"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.1.20</span> <span>xpcall</span> </div> </a> <ul id="toc-xpcall-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Debug_library" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Debug_library"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.2</span> <span>Debug library</span> </div> </a> <ul id="toc-Debug_library-sublist" class="vector-toc-list"> <li id="toc-debug.traceback" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#debug.traceback"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.2.1</span> <span>debug.traceback</span> </div> </a> <ul id="toc-debug.traceback-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Math_library" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Math_library"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3</span> <span>Math library</span> </div> </a> <ul id="toc-Math_library-sublist" class="vector-toc-list"> <li id="toc-math.abs" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#math.abs"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3.1</span> <span>math.abs</span> </div> </a> <ul id="toc-math.abs-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-math.acos" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#math.acos"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3.2</span> <span>math.acos</span> </div> </a> <ul id="toc-math.acos-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-math.asin" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#math.asin"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3.3</span> <span>math.asin</span> </div> </a> <ul id="toc-math.asin-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-math.atan" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#math.atan"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3.4</span> <span>math.atan</span> </div> </a> <ul id="toc-math.atan-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-math.atan2" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#math.atan2"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3.5</span> <span>math.atan2</span> </div> </a> <ul id="toc-math.atan2-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-math.ceil" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#math.ceil"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3.6</span> <span>math.ceil</span> </div> </a> <ul id="toc-math.ceil-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-math.cos" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#math.cos"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3.7</span> <span>math.cos</span> </div> </a> <ul id="toc-math.cos-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-math.cosh" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#math.cosh"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3.8</span> <span>math.cosh</span> </div> </a> <ul id="toc-math.cosh-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-math.deg" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#math.deg"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3.9</span> <span>math.deg</span> </div> </a> <ul id="toc-math.deg-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-math.exp" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#math.exp"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3.10</span> <span>math.exp</span> </div> </a> <ul id="toc-math.exp-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-math.floor" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#math.floor"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3.11</span> <span>math.floor</span> </div> </a> <ul id="toc-math.floor-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-math.fmod" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#math.fmod"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3.12</span> <span>math.fmod</span> </div> </a> <ul id="toc-math.fmod-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-math.frexp" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#math.frexp"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3.13</span> <span>math.frexp</span> </div> </a> <ul id="toc-math.frexp-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-math.huge" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#math.huge"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3.14</span> <span>math.huge</span> </div> </a> <ul id="toc-math.huge-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-math.ldexp" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#math.ldexp"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3.15</span> <span>math.ldexp</span> </div> </a> <ul id="toc-math.ldexp-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-math.log" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#math.log"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3.16</span> <span>math.log</span> </div> </a> <ul id="toc-math.log-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-math.log10" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#math.log10"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3.17</span> <span>math.log10</span> </div> </a> <ul id="toc-math.log10-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-math.max" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#math.max"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3.18</span> <span>math.max</span> </div> </a> <ul id="toc-math.max-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-math.min" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#math.min"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3.19</span> <span>math.min</span> </div> </a> <ul id="toc-math.min-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-math.modf" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#math.modf"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3.20</span> <span>math.modf</span> </div> </a> <ul id="toc-math.modf-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-math.pi" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#math.pi"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3.21</span> <span>math.pi</span> </div> </a> <ul id="toc-math.pi-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-math.pow" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#math.pow"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3.22</span> <span>math.pow</span> </div> </a> <ul id="toc-math.pow-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-math.rad" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#math.rad"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3.23</span> <span>math.rad</span> </div> </a> <ul id="toc-math.rad-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-math.random" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#math.random"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3.24</span> <span>math.random</span> </div> </a> <ul id="toc-math.random-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-math.randomseed" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#math.randomseed"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3.25</span> <span>math.randomseed</span> </div> </a> <ul id="toc-math.randomseed-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-math.sin" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#math.sin"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3.26</span> <span>math.sin</span> </div> </a> <ul id="toc-math.sin-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-math.sinh" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#math.sinh"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3.27</span> <span>math.sinh</span> </div> </a> <ul id="toc-math.sinh-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-math.sqrt" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#math.sqrt"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3.28</span> <span>math.sqrt</span> </div> </a> <ul id="toc-math.sqrt-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-math.tan" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#math.tan"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3.29</span> <span>math.tan</span> </div> </a> <ul id="toc-math.tan-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-math.tanh" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#math.tanh"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3.30</span> <span>math.tanh</span> </div> </a> <ul id="toc-math.tanh-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Operating_system_library" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Operating_system_library"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.4</span> <span>Operating system library</span> </div> </a> <ul id="toc-Operating_system_library-sublist" class="vector-toc-list"> <li id="toc-os.clock" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#os.clock"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.4.1</span> <span>os.clock</span> </div> </a> <ul id="toc-os.clock-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-os.date" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#os.date"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.4.2</span> <span>os.date</span> </div> </a> <ul id="toc-os.date-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-os.difftime" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#os.difftime"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.4.3</span> <span>os.difftime</span> </div> </a> <ul id="toc-os.difftime-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-os.time" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#os.time"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.4.4</span> <span>os.time</span> </div> </a> <ul id="toc-os.time-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Package_library" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Package_library"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.5</span> <span>Package library</span> </div> </a> <ul id="toc-Package_library-sublist" class="vector-toc-list"> <li id="toc-require" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#require"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.5.1</span> <span>require</span> </div> </a> <ul id="toc-require-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-package.loaded" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#package.loaded"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.5.2</span> <span>package.loaded</span> </div> </a> <ul id="toc-package.loaded-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-package.loaders" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#package.loaders"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.5.3</span> <span>package.loaders</span> </div> </a> <ul id="toc-package.loaders-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-package.preload" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#package.preload"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.5.4</span> <span>package.preload</span> </div> </a> <ul id="toc-package.preload-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-package.seeall" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#package.seeall"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.5.5</span> <span>package.seeall</span> </div> </a> <ul id="toc-package.seeall-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-String_library" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#String_library"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.6</span> <span>String library</span> </div> </a> <ul id="toc-String_library-sublist" class="vector-toc-list"> <li id="toc-string.byte" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#string.byte"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.6.1</span> <span>string.byte</span> </div> </a> <ul id="toc-string.byte-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-string.char" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#string.char"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.6.2</span> <span>string.char</span> </div> </a> <ul id="toc-string.char-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-string.find" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#string.find"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.6.3</span> <span>string.find</span> </div> </a> <ul id="toc-string.find-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-string.format" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#string.format"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.6.4</span> <span>string.format</span> </div> </a> <ul id="toc-string.format-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-string.gmatch" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#string.gmatch"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.6.5</span> <span>string.gmatch</span> </div> </a> <ul id="toc-string.gmatch-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-string.gsub" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#string.gsub"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.6.6</span> <span>string.gsub</span> </div> </a> <ul id="toc-string.gsub-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-string.len" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#string.len"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.6.7</span> <span>string.len</span> </div> </a> <ul id="toc-string.len-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-string.lower" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#string.lower"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.6.8</span> <span>string.lower</span> </div> </a> <ul id="toc-string.lower-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-string.match" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#string.match"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.6.9</span> <span>string.match</span> </div> </a> <ul id="toc-string.match-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-string.rep" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#string.rep"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.6.10</span> <span>string.rep</span> </div> </a> <ul id="toc-string.rep-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-string.reverse" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#string.reverse"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.6.11</span> <span>string.reverse</span> </div> </a> <ul id="toc-string.reverse-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-string.sub" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#string.sub"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.6.12</span> <span>string.sub</span> </div> </a> <ul id="toc-string.sub-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-string.ulower" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#string.ulower"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.6.13</span> <span>string.ulower</span> </div> </a> <ul id="toc-string.ulower-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-string.upper" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#string.upper"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.6.14</span> <span>string.upper</span> </div> </a> <ul id="toc-string.upper-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-string.uupper" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#string.uupper"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.6.15</span> <span>string.uupper</span> </div> </a> <ul id="toc-string.uupper-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Patterns" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Patterns"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.6.16</span> <span>Patterns</span> </div> </a> <ul id="toc-Patterns-sublist" class="vector-toc-list"> <li id="toc-Character_class" class="vector-toc-list-item vector-toc-level-4"> <a class="vector-toc-link" href="#Character_class"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.6.16.1</span> <span>Character class</span> </div> </a> <ul id="toc-Character_class-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Pattern_items" class="vector-toc-list-item vector-toc-level-4"> <a class="vector-toc-link" href="#Pattern_items"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.6.16.2</span> <span>Pattern items</span> </div> </a> <ul id="toc-Pattern_items-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Pattern" class="vector-toc-list-item vector-toc-level-4"> <a class="vector-toc-link" href="#Pattern"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.6.16.3</span> <span>Pattern</span> </div> </a> <ul id="toc-Pattern-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Captures" class="vector-toc-list-item vector-toc-level-4"> <a class="vector-toc-link" href="#Captures"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.6.16.4</span> <span>Captures</span> </div> </a> <ul id="toc-Captures-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> </ul> </li> <li id="toc-Table_library" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Table_library"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.7</span> <span>Table library</span> </div> </a> <ul id="toc-Table_library-sublist" class="vector-toc-list"> <li id="toc-table.concat" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#table.concat"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.7.1</span> <span>table.concat</span> </div> </a> <ul id="toc-table.concat-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-table.insert" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#table.insert"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.7.2</span> <span>table.insert</span> </div> </a> <ul id="toc-table.insert-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-table.maxn" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#table.maxn"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.7.3</span> <span>table.maxn</span> </div> </a> <ul id="toc-table.maxn-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-table.remove" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#table.remove"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.7.4</span> <span>table.remove</span> </div> </a> <ul id="toc-table.remove-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-table.sort" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#table.sort"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.7.5</span> <span>table.sort</span> </div> </a> <ul id="toc-table.sort-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> </ul> </li> <li id="toc-Scribunto_libraries" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Scribunto_libraries"> <div class="vector-toc-text"> <span class="vector-toc-numb">4</span> <span>Scribunto libraries</span> </div> </a> <button aria-controls="toc-Scribunto_libraries-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Scribunto libraries subsection</span> </button> <ul id="toc-Scribunto_libraries-sublist" class="vector-toc-list"> <li id="toc-Base_functions" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Base_functions"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.1</span> <span>Base functions</span> </div> </a> <ul id="toc-Base_functions-sublist" class="vector-toc-list"> <li id="toc-mw.addWarning" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.addWarning"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.1.1</span> <span>mw.addWarning</span> </div> </a> <ul id="toc-mw.addWarning-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.allToString" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.allToString"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.1.2</span> <span>mw.allToString</span> </div> </a> <ul id="toc-mw.allToString-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.clone" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.clone"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.1.3</span> <span>mw.clone</span> </div> </a> <ul id="toc-mw.clone-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.getCurrentFrame" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.getCurrentFrame"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.1.4</span> <span>mw.getCurrentFrame</span> </div> </a> <ul id="toc-mw.getCurrentFrame-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.incrementExpensiveFunctionCount" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.incrementExpensiveFunctionCount"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.1.5</span> <span>mw.incrementExpensiveFunctionCount</span> </div> </a> <ul id="toc-mw.incrementExpensiveFunctionCount-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.isSubsting" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.isSubsting"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.1.6</span> <span>mw.isSubsting</span> </div> </a> <ul id="toc-mw.isSubsting-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.loadData" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.loadData"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.1.7</span> <span>mw.loadData</span> </div> </a> <ul id="toc-mw.loadData-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.loadJsonData" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.loadJsonData"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.1.8</span> <span>mw.loadJsonData</span> </div> </a> <ul id="toc-mw.loadJsonData-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.dumpObject" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.dumpObject"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.1.9</span> <span>mw.dumpObject</span> </div> </a> <ul id="toc-mw.dumpObject-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.log" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.log"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.1.10</span> <span>mw.log</span> </div> </a> <ul id="toc-mw.log-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.logObject" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.logObject"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.1.11</span> <span>mw.logObject</span> </div> </a> <ul id="toc-mw.logObject-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Frame_object" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Frame_object"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.2</span> <span>Frame object</span> </div> </a> <ul id="toc-Frame_object-sublist" class="vector-toc-list"> <li id="toc-frame.args" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#frame.args"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.2.1</span> <span>frame.args</span> </div> </a> <ul id="toc-frame.args-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-frame:callParserFunction" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#frame:callParserFunction"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.2.2</span> <span>frame:callParserFunction</span> </div> </a> <ul id="toc-frame:callParserFunction-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-frame:expandTemplate" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#frame:expandTemplate"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.2.3</span> <span>frame:expandTemplate</span> </div> </a> <ul id="toc-frame:expandTemplate-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-frame:extensionTag" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#frame:extensionTag"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.2.4</span> <span>frame:extensionTag</span> </div> </a> <ul id="toc-frame:extensionTag-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-frame:getParent" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#frame:getParent"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.2.5</span> <span>frame:getParent</span> </div> </a> <ul id="toc-frame:getParent-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-frame:getTitle" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#frame:getTitle"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.2.6</span> <span>frame:getTitle</span> </div> </a> <ul id="toc-frame:getTitle-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-frame:newChild" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#frame:newChild"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.2.7</span> <span>frame:newChild</span> </div> </a> <ul id="toc-frame:newChild-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-frame:preprocess" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#frame:preprocess"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.2.8</span> <span>frame:preprocess</span> </div> </a> <ul id="toc-frame:preprocess-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-frame:getArgument" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#frame:getArgument"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.2.9</span> <span>frame:getArgument</span> </div> </a> <ul id="toc-frame:getArgument-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-frame:newParserValue" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#frame:newParserValue"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.2.10</span> <span>frame:newParserValue</span> </div> </a> <ul id="toc-frame:newParserValue-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-frame:newTemplateParserValue" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#frame:newTemplateParserValue"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.2.11</span> <span>frame:newTemplateParserValue</span> </div> </a> <ul id="toc-frame:newTemplateParserValue-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-frame:argumentPairs" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#frame:argumentPairs"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.2.12</span> <span>frame:argumentPairs</span> </div> </a> <ul id="toc-frame:argumentPairs-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Hash_library" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Hash_library"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.3</span> <span>Hash library</span> </div> </a> <ul id="toc-Hash_library-sublist" class="vector-toc-list"> <li id="toc-mw.hash.hashValue" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.hash.hashValue"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.3.1</span> <span>mw.hash.hashValue</span> </div> </a> <ul id="toc-mw.hash.hashValue-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.hash.listAlgorithms" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.hash.listAlgorithms"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.3.2</span> <span>mw.hash.listAlgorithms</span> </div> </a> <ul id="toc-mw.hash.listAlgorithms-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-HTML_library" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#HTML_library"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.4</span> <span>HTML library</span> </div> </a> <ul id="toc-HTML_library-sublist" class="vector-toc-list"> <li id="toc-mw.html.create" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.html.create"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.4.1</span> <span>mw.html.create</span> </div> </a> <ul id="toc-mw.html.create-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.html:node" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.html:node"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.4.2</span> <span>mw.html:node</span> </div> </a> <ul id="toc-mw.html:node-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.html:wikitext" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.html:wikitext"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.4.3</span> <span>mw.html:wikitext</span> </div> </a> <ul id="toc-mw.html:wikitext-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.html:newline" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.html:newline"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.4.4</span> <span>mw.html:newline</span> </div> </a> <ul id="toc-mw.html:newline-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.html:tag" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.html:tag"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.4.5</span> <span>mw.html:tag</span> </div> </a> <ul id="toc-mw.html:tag-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.html:attr" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.html:attr"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.4.6</span> <span>mw.html:attr</span> </div> </a> <ul id="toc-mw.html:attr-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.html:getAttr" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.html:getAttr"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.4.7</span> <span>mw.html:getAttr</span> </div> </a> <ul id="toc-mw.html:getAttr-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.html:addClass" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.html:addClass"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.4.8</span> <span>mw.html:addClass</span> </div> </a> <ul id="toc-mw.html:addClass-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.html:css" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.html:css"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.4.9</span> <span>mw.html:css</span> </div> </a> <ul id="toc-mw.html:css-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.html:cssText" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.html:cssText"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.4.10</span> <span>mw.html:cssText</span> </div> </a> <ul id="toc-mw.html:cssText-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.html:done" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.html:done"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.4.11</span> <span>mw.html:done</span> </div> </a> <ul id="toc-mw.html:done-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.html:allDone" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.html:allDone"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.4.12</span> <span>mw.html:allDone</span> </div> </a> <ul id="toc-mw.html:allDone-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Language_library" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Language_library"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5</span> <span>Language library</span> </div> </a> <ul id="toc-Language_library-sublist" class="vector-toc-list"> <li id="toc-mw.language.fetchLanguageName" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.language.fetchLanguageName"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5.1</span> <span>mw.language.fetchLanguageName</span> </div> </a> <ul id="toc-mw.language.fetchLanguageName-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.language.fetchLanguageNames" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.language.fetchLanguageNames"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5.2</span> <span>mw.language.fetchLanguageNames</span> </div> </a> <ul id="toc-mw.language.fetchLanguageNames-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.language.getContentLanguage" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.language.getContentLanguage"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5.3</span> <span>mw.language.getContentLanguage</span> </div> </a> <ul id="toc-mw.language.getContentLanguage-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.language.getFallbacksFor" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.language.getFallbacksFor"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5.4</span> <span>mw.language.getFallbacksFor</span> </div> </a> <ul id="toc-mw.language.getFallbacksFor-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.language.isKnownLanguageTag" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.language.isKnownLanguageTag"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5.5</span> <span>mw.language.isKnownLanguageTag</span> </div> </a> <ul id="toc-mw.language.isKnownLanguageTag-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.language.isSupportedLanguage" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.language.isSupportedLanguage"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5.6</span> <span>mw.language.isSupportedLanguage</span> </div> </a> <ul id="toc-mw.language.isSupportedLanguage-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.language.isValidBuiltInCode" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.language.isValidBuiltInCode"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5.7</span> <span>mw.language.isValidBuiltInCode</span> </div> </a> <ul id="toc-mw.language.isValidBuiltInCode-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.language.isValidCode" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.language.isValidCode"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5.8</span> <span>mw.language.isValidCode</span> </div> </a> <ul id="toc-mw.language.isValidCode-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.language.new" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.language.new"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5.9</span> <span>mw.language.new</span> </div> </a> <ul id="toc-mw.language.new-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.language:getCode" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.language:getCode"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5.10</span> <span>mw.language:getCode</span> </div> </a> <ul id="toc-mw.language:getCode-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.language:toBcp47Code" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.language:toBcp47Code"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5.11</span> <span>mw.language:toBcp47Code</span> </div> </a> <ul id="toc-mw.language:toBcp47Code-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.language:getFallbackLanguages" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.language:getFallbackLanguages"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5.12</span> <span>mw.language:getFallbackLanguages</span> </div> </a> <ul id="toc-mw.language:getFallbackLanguages-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.language:isRTL" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.language:isRTL"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5.13</span> <span>mw.language:isRTL</span> </div> </a> <ul id="toc-mw.language:isRTL-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.language:lc" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.language:lc"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5.14</span> <span>mw.language:lc</span> </div> </a> <ul id="toc-mw.language:lc-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.language:lcfirst" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.language:lcfirst"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5.15</span> <span>mw.language:lcfirst</span> </div> </a> <ul id="toc-mw.language:lcfirst-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.language:uc" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.language:uc"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5.16</span> <span>mw.language:uc</span> </div> </a> <ul id="toc-mw.language:uc-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.language:ucfirst" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.language:ucfirst"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5.17</span> <span>mw.language:ucfirst</span> </div> </a> <ul id="toc-mw.language:ucfirst-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.language:caseFold" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.language:caseFold"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5.18</span> <span>mw.language:caseFold</span> </div> </a> <ul id="toc-mw.language:caseFold-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.language:formatNum" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.language:formatNum"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5.19</span> <span>mw.language:formatNum</span> </div> </a> <ul id="toc-mw.language:formatNum-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.language:formatDate" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.language:formatDate"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5.20</span> <span>mw.language:formatDate</span> </div> </a> <ul id="toc-mw.language:formatDate-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.language:formatDuration" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.language:formatDuration"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5.21</span> <span>mw.language:formatDuration</span> </div> </a> <ul id="toc-mw.language:formatDuration-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.language:parseFormattedNumber" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.language:parseFormattedNumber"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5.22</span> <span>mw.language:parseFormattedNumber</span> </div> </a> <ul id="toc-mw.language:parseFormattedNumber-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.language:convertPlural" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.language:convertPlural"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5.23</span> <span>mw.language:convertPlural</span> </div> </a> <ul id="toc-mw.language:convertPlural-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.language:convertGrammar" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.language:convertGrammar"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5.24</span> <span>mw.language:convertGrammar</span> </div> </a> <ul id="toc-mw.language:convertGrammar-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.language:gender" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.language:gender"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5.25</span> <span>mw.language:gender</span> </div> </a> <ul id="toc-mw.language:gender-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.language:getArrow" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.language:getArrow"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5.26</span> <span>mw.language:getArrow</span> </div> </a> <ul id="toc-mw.language:getArrow-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.language:getDir" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.language:getDir"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5.27</span> <span>mw.language:getDir</span> </div> </a> <ul id="toc-mw.language:getDir-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.language:getDirMark" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.language:getDirMark"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5.28</span> <span>mw.language:getDirMark</span> </div> </a> <ul id="toc-mw.language:getDirMark-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.language:getDirMarkEntity" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.language:getDirMarkEntity"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5.29</span> <span>mw.language:getDirMarkEntity</span> </div> </a> <ul id="toc-mw.language:getDirMarkEntity-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.language:getDurationIntervals" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.language:getDurationIntervals"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5.30</span> <span>mw.language:getDurationIntervals</span> </div> </a> <ul id="toc-mw.language:getDurationIntervals-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Message_library" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Message_library"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.6</span> <span>Message library</span> </div> </a> <ul id="toc-Message_library-sublist" class="vector-toc-list"> <li id="toc-mw.message.new" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.message.new"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.6.1</span> <span>mw.message.new</span> </div> </a> <ul id="toc-mw.message.new-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.message.newFallbackSequence" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.message.newFallbackSequence"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.6.2</span> <span>mw.message.newFallbackSequence</span> </div> </a> <ul id="toc-mw.message.newFallbackSequence-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.message.newRawMessage" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.message.newRawMessage"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.6.3</span> <span>mw.message.newRawMessage</span> </div> </a> <ul id="toc-mw.message.newRawMessage-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.message.rawParam" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.message.rawParam"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.6.4</span> <span>mw.message.rawParam</span> </div> </a> <ul id="toc-mw.message.rawParam-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.message.numParam" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.message.numParam"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.6.5</span> <span>mw.message.numParam</span> </div> </a> <ul id="toc-mw.message.numParam-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.message.getDefaultLanguage" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.message.getDefaultLanguage"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.6.6</span> <span>mw.message.getDefaultLanguage</span> </div> </a> <ul id="toc-mw.message.getDefaultLanguage-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.message:params" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.message:params"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.6.7</span> <span>mw.message:params</span> </div> </a> <ul id="toc-mw.message:params-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.message:rawParams" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.message:rawParams"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.6.8</span> <span>mw.message:rawParams</span> </div> </a> <ul id="toc-mw.message:rawParams-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.message:numParams" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.message:numParams"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.6.9</span> <span>mw.message:numParams</span> </div> </a> <ul id="toc-mw.message:numParams-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.message:inLanguage" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.message:inLanguage"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.6.10</span> <span>mw.message:inLanguage</span> </div> </a> <ul id="toc-mw.message:inLanguage-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.message:useDatabase" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.message:useDatabase"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.6.11</span> <span>mw.message:useDatabase</span> </div> </a> <ul id="toc-mw.message:useDatabase-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.message:plain" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.message:plain"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.6.12</span> <span>mw.message:plain</span> </div> </a> <ul id="toc-mw.message:plain-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.message:exists" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.message:exists"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.6.13</span> <span>mw.message:exists</span> </div> </a> <ul id="toc-mw.message:exists-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.message:isBlank" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.message:isBlank"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.6.14</span> <span>mw.message:isBlank</span> </div> </a> <ul id="toc-mw.message:isBlank-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.message:isDisabled" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.message:isDisabled"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.6.15</span> <span>mw.message:isDisabled</span> </div> </a> <ul id="toc-mw.message:isDisabled-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Site_library" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Site_library"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.7</span> <span>Site library</span> </div> </a> <ul id="toc-Site_library-sublist" class="vector-toc-list"> <li id="toc-mw.site.currentVersion" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.site.currentVersion"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.7.1</span> <span>mw.site.currentVersion</span> </div> </a> <ul id="toc-mw.site.currentVersion-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.site.scriptPath" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.site.scriptPath"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.7.2</span> <span>mw.site.scriptPath</span> </div> </a> <ul id="toc-mw.site.scriptPath-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.site.server" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.site.server"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.7.3</span> <span>mw.site.server</span> </div> </a> <ul id="toc-mw.site.server-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.site.siteName" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.site.siteName"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.7.4</span> <span>mw.site.siteName</span> </div> </a> <ul id="toc-mw.site.siteName-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.site.stylePath" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.site.stylePath"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.7.5</span> <span>mw.site.stylePath</span> </div> </a> <ul id="toc-mw.site.stylePath-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.site.namespaces" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.site.namespaces"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.7.6</span> <span>mw.site.namespaces</span> </div> </a> <ul id="toc-mw.site.namespaces-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.site.contentNamespaces" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.site.contentNamespaces"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.7.7</span> <span>mw.site.contentNamespaces</span> </div> </a> <ul id="toc-mw.site.contentNamespaces-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.site.subjectNamespaces" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.site.subjectNamespaces"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.7.8</span> <span>mw.site.subjectNamespaces</span> </div> </a> <ul id="toc-mw.site.subjectNamespaces-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.site.talkNamespaces" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.site.talkNamespaces"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.7.9</span> <span>mw.site.talkNamespaces</span> </div> </a> <ul id="toc-mw.site.talkNamespaces-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.site.stats" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.site.stats"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.7.10</span> <span>mw.site.stats</span> </div> </a> <ul id="toc-mw.site.stats-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.site.stats.pagesInCategory" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.site.stats.pagesInCategory"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.7.11</span> <span>mw.site.stats.pagesInCategory</span> </div> </a> <ul id="toc-mw.site.stats.pagesInCategory-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.site.stats.pagesInNamespace" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.site.stats.pagesInNamespace"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.7.12</span> <span>mw.site.stats.pagesInNamespace</span> </div> </a> <ul id="toc-mw.site.stats.pagesInNamespace-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.site.stats.usersInGroup" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.site.stats.usersInGroup"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.7.13</span> <span>mw.site.stats.usersInGroup</span> </div> </a> <ul id="toc-mw.site.stats.usersInGroup-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.site.interwikiMap" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.site.interwikiMap"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.7.14</span> <span>mw.site.interwikiMap</span> </div> </a> <ul id="toc-mw.site.interwikiMap-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Text_library" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Text_library"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.8</span> <span>Text library</span> </div> </a> <ul id="toc-Text_library-sublist" class="vector-toc-list"> <li id="toc-mw.text.decode" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.text.decode"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.8.1</span> <span>mw.text.decode</span> </div> </a> <ul id="toc-mw.text.decode-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.text.encode" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.text.encode"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.8.2</span> <span>mw.text.encode</span> </div> </a> <ul id="toc-mw.text.encode-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.text.jsonDecode" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.text.jsonDecode"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.8.3</span> <span>mw.text.jsonDecode</span> </div> </a> <ul id="toc-mw.text.jsonDecode-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.text.jsonEncode" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.text.jsonEncode"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.8.4</span> <span>mw.text.jsonEncode</span> </div> </a> <ul id="toc-mw.text.jsonEncode-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.text.killMarkers" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.text.killMarkers"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.8.5</span> <span>mw.text.killMarkers</span> </div> </a> <ul id="toc-mw.text.killMarkers-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.text.listToText" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.text.listToText"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.8.6</span> <span>mw.text.listToText</span> </div> </a> <ul id="toc-mw.text.listToText-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.text.nowiki" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.text.nowiki"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.8.7</span> <span>mw.text.nowiki</span> </div> </a> <ul id="toc-mw.text.nowiki-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.text.split" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.text.split"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.8.8</span> <span>mw.text.split</span> </div> </a> <ul id="toc-mw.text.split-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.text.gsplit" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.text.gsplit"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.8.9</span> <span>mw.text.gsplit</span> </div> </a> <ul id="toc-mw.text.gsplit-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.text.tag" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.text.tag"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.8.10</span> <span>mw.text.tag</span> </div> </a> <ul id="toc-mw.text.tag-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.text.trim" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.text.trim"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.8.11</span> <span>mw.text.trim</span> </div> </a> <ul id="toc-mw.text.trim-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.text.truncate" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.text.truncate"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.8.12</span> <span>mw.text.truncate</span> </div> </a> <ul id="toc-mw.text.truncate-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.text.unstripNoWiki" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.text.unstripNoWiki"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.8.13</span> <span>mw.text.unstripNoWiki</span> </div> </a> <ul id="toc-mw.text.unstripNoWiki-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.text.unstrip" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.text.unstrip"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.8.14</span> <span>mw.text.unstrip</span> </div> </a> <ul id="toc-mw.text.unstrip-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Title_library" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Title_library"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.9</span> <span>Title library</span> </div> </a> <ul id="toc-Title_library-sublist" class="vector-toc-list"> <li id="toc-mw.title.equals" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.title.equals"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.9.1</span> <span>mw.title.equals</span> </div> </a> <ul id="toc-mw.title.equals-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.title.compare" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.title.compare"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.9.2</span> <span>mw.title.compare</span> </div> </a> <ul id="toc-mw.title.compare-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.title.getCurrentTitle" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.title.getCurrentTitle"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.9.3</span> <span>mw.title.getCurrentTitle</span> </div> </a> <ul id="toc-mw.title.getCurrentTitle-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.title.new" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.title.new"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.9.4</span> <span>mw.title.new</span> </div> </a> <ul id="toc-mw.title.new-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.title.makeTitle" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.title.makeTitle"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.9.5</span> <span>mw.title.makeTitle</span> </div> </a> <ul id="toc-mw.title.makeTitle-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Title_objects" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Title_objects"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.9.6</span> <span>Title objects</span> </div> </a> <ul id="toc-Title_objects-sublist" class="vector-toc-list"> <li id="toc-File_metadata" class="vector-toc-list-item vector-toc-level-4"> <a class="vector-toc-link" href="#File_metadata"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.9.6.1</span> <span>File metadata</span> </div> </a> <ul id="toc-File_metadata-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Expensive_properties" class="vector-toc-list-item vector-toc-level-4"> <a class="vector-toc-link" href="#Expensive_properties"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.9.6.2</span> <span>Expensive properties</span> </div> </a> <ul id="toc-Expensive_properties-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> </ul> </li> <li id="toc-URI_library" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#URI_library"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.10</span> <span>URI library</span> </div> </a> <ul id="toc-URI_library-sublist" class="vector-toc-list"> <li id="toc-mw.uri.encode" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.uri.encode"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.10.1</span> <span>mw.uri.encode</span> </div> </a> <ul id="toc-mw.uri.encode-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.uri.decode" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.uri.decode"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.10.2</span> <span>mw.uri.decode</span> </div> </a> <ul id="toc-mw.uri.decode-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.uri.anchorEncode" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.uri.anchorEncode"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.10.3</span> <span>mw.uri.anchorEncode</span> </div> </a> <ul id="toc-mw.uri.anchorEncode-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.uri.buildQueryString" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.uri.buildQueryString"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.10.4</span> <span>mw.uri.buildQueryString</span> </div> </a> <ul id="toc-mw.uri.buildQueryString-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.uri.parseQueryString" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.uri.parseQueryString"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.10.5</span> <span>mw.uri.parseQueryString</span> </div> </a> <ul id="toc-mw.uri.parseQueryString-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.uri.canonicalUrl" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.uri.canonicalUrl"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.10.6</span> <span>mw.uri.canonicalUrl</span> </div> </a> <ul id="toc-mw.uri.canonicalUrl-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.uri.fullUrl" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.uri.fullUrl"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.10.7</span> <span>mw.uri.fullUrl</span> </div> </a> <ul id="toc-mw.uri.fullUrl-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.uri.localUrl" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.uri.localUrl"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.10.8</span> <span>mw.uri.localUrl</span> </div> </a> <ul id="toc-mw.uri.localUrl-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.uri.new" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.uri.new"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.10.9</span> <span>mw.uri.new</span> </div> </a> <ul id="toc-mw.uri.new-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.uri.validate" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.uri.validate"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.10.10</span> <span>mw.uri.validate</span> </div> </a> <ul id="toc-mw.uri.validate-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-URI_object" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#URI_object"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.10.11</span> <span>URI object</span> </div> </a> <ul id="toc-URI_object-sublist" class="vector-toc-list"> <li id="toc-mw.uri:parse" class="vector-toc-list-item vector-toc-level-4"> <a class="vector-toc-link" href="#mw.uri:parse"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.10.11.1</span> <span>mw.uri:parse</span> </div> </a> <ul id="toc-mw.uri:parse-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.uri:clone" class="vector-toc-list-item vector-toc-level-4"> <a class="vector-toc-link" href="#mw.uri:clone"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.10.11.2</span> <span>mw.uri:clone</span> </div> </a> <ul id="toc-mw.uri:clone-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.uri:extend" class="vector-toc-list-item vector-toc-level-4"> <a class="vector-toc-link" href="#mw.uri:extend"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.10.11.3</span> <span>mw.uri:extend</span> </div> </a> <ul id="toc-mw.uri:extend-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> </ul> </li> <li id="toc-Ustring_library" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Ustring_library"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.11</span> <span>Ustring library</span> </div> </a> <ul id="toc-Ustring_library-sublist" class="vector-toc-list"> <li id="toc-mw.ustring.maxPatternLength" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.ustring.maxPatternLength"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.11.1</span> <span>mw.ustring.maxPatternLength</span> </div> </a> <ul id="toc-mw.ustring.maxPatternLength-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ustring.maxStringLength" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.ustring.maxStringLength"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.11.2</span> <span>mw.ustring.maxStringLength</span> </div> </a> <ul id="toc-mw.ustring.maxStringLength-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ustring.byte" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.ustring.byte"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.11.3</span> <span>mw.ustring.byte</span> </div> </a> <ul id="toc-mw.ustring.byte-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ustring.byteoffset" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.ustring.byteoffset"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.11.4</span> <span>mw.ustring.byteoffset</span> </div> </a> <ul id="toc-mw.ustring.byteoffset-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ustring.char" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.ustring.char"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.11.5</span> <span>mw.ustring.char</span> </div> </a> <ul id="toc-mw.ustring.char-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ustring.codepoint" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.ustring.codepoint"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.11.6</span> <span>mw.ustring.codepoint</span> </div> </a> <ul id="toc-mw.ustring.codepoint-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ustring.find" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.ustring.find"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.11.7</span> <span>mw.ustring.find</span> </div> </a> <ul id="toc-mw.ustring.find-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ustring.format" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.ustring.format"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.11.8</span> <span>mw.ustring.format</span> </div> </a> <ul id="toc-mw.ustring.format-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ustring.gcodepoint" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.ustring.gcodepoint"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.11.9</span> <span>mw.ustring.gcodepoint</span> </div> </a> <ul id="toc-mw.ustring.gcodepoint-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ustring.gmatch" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.ustring.gmatch"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.11.10</span> <span>mw.ustring.gmatch</span> </div> </a> <ul id="toc-mw.ustring.gmatch-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ustring.gsub" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.ustring.gsub"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.11.11</span> <span>mw.ustring.gsub</span> </div> </a> <ul id="toc-mw.ustring.gsub-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ustring.isutf8" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.ustring.isutf8"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.11.12</span> <span>mw.ustring.isutf8</span> </div> </a> <ul id="toc-mw.ustring.isutf8-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ustring.len" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.ustring.len"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.11.13</span> <span>mw.ustring.len</span> </div> </a> <ul id="toc-mw.ustring.len-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ustring.lower" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.ustring.lower"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.11.14</span> <span>mw.ustring.lower</span> </div> </a> <ul id="toc-mw.ustring.lower-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ustring.match" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.ustring.match"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.11.15</span> <span>mw.ustring.match</span> </div> </a> <ul id="toc-mw.ustring.match-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ustring.rep" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.ustring.rep"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.11.16</span> <span>mw.ustring.rep</span> </div> </a> <ul id="toc-mw.ustring.rep-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ustring.sub" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.ustring.sub"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.11.17</span> <span>mw.ustring.sub</span> </div> </a> <ul id="toc-mw.ustring.sub-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ustring.toNFC" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.ustring.toNFC"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.11.18</span> <span>mw.ustring.toNFC</span> </div> </a> <ul id="toc-mw.ustring.toNFC-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ustring.toNFD" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.ustring.toNFD"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.11.19</span> <span>mw.ustring.toNFD</span> </div> </a> <ul id="toc-mw.ustring.toNFD-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ustring.toNFKC" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.ustring.toNFKC"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.11.20</span> <span>mw.ustring.toNFKC</span> </div> </a> <ul id="toc-mw.ustring.toNFKC-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ustring.toNFKD" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.ustring.toNFKD"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.11.21</span> <span>mw.ustring.toNFKD</span> </div> </a> <ul id="toc-mw.ustring.toNFKD-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ustring.upper" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#mw.ustring.upper"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.11.22</span> <span>mw.ustring.upper</span> </div> </a> <ul id="toc-mw.ustring.upper-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Ustring_patterns" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Ustring_patterns"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.11.23</span> <span>Ustring patterns</span> </div> </a> <ul id="toc-Ustring_patterns-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> </ul> </li> <li id="toc-Loadable_libraries" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Loadable_libraries"> <div class="vector-toc-text"> <span class="vector-toc-numb">5</span> <span>Loadable libraries</span> </div> </a> <button aria-controls="toc-Loadable_libraries-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Loadable libraries subsection</span> </button> <ul id="toc-Loadable_libraries-sublist" class="vector-toc-list"> <li id="toc-bit32" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#bit32"> <div class="vector-toc-text"> <span class="vector-toc-numb">5.1</span> <span>bit32</span> </div> </a> <ul id="toc-bit32-sublist" class="vector-toc-list"> <li id="toc-bit32.band" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#bit32.band"> <div class="vector-toc-text"> <span class="vector-toc-numb">5.1.1</span> <span>bit32.band</span> </div> </a> <ul id="toc-bit32.band-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-bit32.bnot" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#bit32.bnot"> <div class="vector-toc-text"> <span class="vector-toc-numb">5.1.2</span> <span>bit32.bnot</span> </div> </a> <ul id="toc-bit32.bnot-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-bit32.bor" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#bit32.bor"> <div class="vector-toc-text"> <span class="vector-toc-numb">5.1.3</span> <span>bit32.bor</span> </div> </a> <ul id="toc-bit32.bor-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-bit32.btest" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#bit32.btest"> <div class="vector-toc-text"> <span class="vector-toc-numb">5.1.4</span> <span>bit32.btest</span> </div> </a> <ul id="toc-bit32.btest-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-bit32.bxor" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#bit32.bxor"> <div class="vector-toc-text"> <span class="vector-toc-numb">5.1.5</span> <span>bit32.bxor</span> </div> </a> <ul id="toc-bit32.bxor-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-bit32.extract" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#bit32.extract"> <div class="vector-toc-text"> <span class="vector-toc-numb">5.1.6</span> <span>bit32.extract</span> </div> </a> <ul id="toc-bit32.extract-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-bit32.replace" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#bit32.replace"> <div class="vector-toc-text"> <span class="vector-toc-numb">5.1.7</span> <span>bit32.replace</span> </div> </a> <ul id="toc-bit32.replace-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-bit32.lshift" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#bit32.lshift"> <div class="vector-toc-text"> <span class="vector-toc-numb">5.1.8</span> <span>bit32.lshift</span> </div> </a> <ul id="toc-bit32.lshift-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-bit32.rshift" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#bit32.rshift"> <div class="vector-toc-text"> <span class="vector-toc-numb">5.1.9</span> <span>bit32.rshift</span> </div> </a> <ul id="toc-bit32.rshift-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-bit32.arshift" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#bit32.arshift"> <div class="vector-toc-text"> <span class="vector-toc-numb">5.1.10</span> <span>bit32.arshift</span> </div> </a> <ul id="toc-bit32.arshift-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-bit32.lrotate" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#bit32.lrotate"> <div class="vector-toc-text"> <span class="vector-toc-numb">5.1.11</span> <span>bit32.lrotate</span> </div> </a> <ul id="toc-bit32.lrotate-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-bit32.rrotate" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#bit32.rrotate"> <div class="vector-toc-text"> <span class="vector-toc-numb">5.1.12</span> <span>bit32.rrotate</span> </div> </a> <ul id="toc-bit32.rrotate-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-libraryUtil" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#libraryUtil"> <div class="vector-toc-text"> <span class="vector-toc-numb">5.2</span> <span>libraryUtil</span> </div> </a> <ul id="toc-libraryUtil-sublist" class="vector-toc-list"> <li id="toc-libraryUtil.checkType" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#libraryUtil.checkType"> <div class="vector-toc-text"> <span class="vector-toc-numb">5.2.1</span> <span>libraryUtil.checkType</span> </div> </a> <ul id="toc-libraryUtil.checkType-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-libraryUtil.checkTypeMulti" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#libraryUtil.checkTypeMulti"> <div class="vector-toc-text"> <span class="vector-toc-numb">5.2.2</span> <span>libraryUtil.checkTypeMulti</span> </div> </a> <ul id="toc-libraryUtil.checkTypeMulti-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-libraryUtil.checkTypeForIndex" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#libraryUtil.checkTypeForIndex"> <div class="vector-toc-text"> <span class="vector-toc-numb">5.2.3</span> <span>libraryUtil.checkTypeForIndex</span> </div> </a> <ul id="toc-libraryUtil.checkTypeForIndex-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-libraryUtil.checkTypeForNamedArg" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#libraryUtil.checkTypeForNamedArg"> <div class="vector-toc-text"> <span class="vector-toc-numb">5.2.4</span> <span>libraryUtil.checkTypeForNamedArg</span> </div> </a> <ul id="toc-libraryUtil.checkTypeForNamedArg-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-libraryUtil.makeCheckSelfFunction" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#libraryUtil.makeCheckSelfFunction"> <div class="vector-toc-text"> <span class="vector-toc-numb">5.2.5</span> <span>libraryUtil.makeCheckSelfFunction</span> </div> </a> <ul id="toc-libraryUtil.makeCheckSelfFunction-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-luabit" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#luabit"> <div class="vector-toc-text"> <span class="vector-toc-numb">5.3</span> <span>luabit</span> </div> </a> <ul id="toc-luabit-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-strict" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#strict"> <div class="vector-toc-text"> <span class="vector-toc-numb">5.4</span> <span>strict</span> </div> </a> <ul id="toc-strict-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-ustring" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#ustring"> <div class="vector-toc-text"> <span class="vector-toc-numb">5.5</span> <span>ustring</span> </div> </a> <ul id="toc-ustring-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Extension_libraries" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Extension_libraries"> <div class="vector-toc-text"> <span class="vector-toc-numb">6</span> <span>Extension libraries</span> </div> </a> <button aria-controls="toc-Extension_libraries-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Extension libraries subsection</span> </button> <ul id="toc-Extension_libraries-sublist" class="vector-toc-list"> <li id="toc-mw.wikibase" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#mw.wikibase"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.1</span> <span>mw.wikibase</span> </div> </a> <ul id="toc-mw.wikibase-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.wikibase.lexeme" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#mw.wikibase.lexeme"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.2</span> <span>mw.wikibase.lexeme</span> </div> </a> <ul id="toc-mw.wikibase.lexeme-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.wikibase.mediainfo" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#mw.wikibase.mediainfo"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.3</span> <span>mw.wikibase.mediainfo</span> </div> </a> <ul id="toc-mw.wikibase.mediainfo-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.bcmath" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#mw.bcmath"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.4</span> <span>mw.bcmath</span> </div> </a> <ul id="toc-mw.bcmath-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.smw" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#mw.smw"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.5</span> <span>mw.smw</span> </div> </a> <ul id="toc-mw.smw-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ext.data" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#mw.ext.data"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.6</span> <span>mw.ext.data</span> </div> </a> <ul id="toc-mw.ext.data-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ext.cargo" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#mw.ext.cargo"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.7</span> <span>mw.ext.cargo</span> </div> </a> <ul id="toc-mw.ext.cargo-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ext.cattools" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#mw.ext.cattools"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.8</span> <span>mw.ext.cattools</span> </div> </a> <ul id="toc-mw.ext.cattools-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ext.FlaggedRevs" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#mw.ext.FlaggedRevs"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.9</span> <span>mw.ext.FlaggedRevs</span> </div> </a> <ul id="toc-mw.ext.FlaggedRevs-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ext.TitleBlacklist" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#mw.ext.TitleBlacklist"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.10</span> <span>mw.ext.TitleBlacklist</span> </div> </a> <ul id="toc-mw.ext.TitleBlacklist-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ext.ParserFunctions" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#mw.ext.ParserFunctions"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.11</span> <span>mw.ext.ParserFunctions</span> </div> </a> <ul id="toc-mw.ext.ParserFunctions-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ext.proofreadPage" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#mw.ext.proofreadPage"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.12</span> <span>mw.ext.proofreadPage</span> </div> </a> <ul id="toc-mw.ext.proofreadPage-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ext.articlePlaceholder" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#mw.ext.articlePlaceholder"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.13</span> <span>mw.ext.articlePlaceholder</span> </div> </a> <ul id="toc-mw.ext.articlePlaceholder-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ext.externalData" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#mw.ext.externalData"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.14</span> <span>mw.ext.externalData</span> </div> </a> <ul id="toc-mw.ext.externalData-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ext.UnlinkedWikibase" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#mw.ext.UnlinkedWikibase"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.15</span> <span>mw.ext.UnlinkedWikibase</span> </div> </a> <ul id="toc-mw.ext.UnlinkedWikibase-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.ext.seo" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#mw.ext.seo"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.16</span> <span>mw.ext.seo</span> </div> </a> <ul id="toc-mw.ext.seo-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mw.slots" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#mw.slots"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.17</span> <span>mw.slots</span> </div> </a> <ul id="toc-mw.slots-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Differences_from_standard_Lua" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Differences_from_standard_Lua"> <div class="vector-toc-text"> <span class="vector-toc-numb">7</span> <span>Differences from standard Lua</span> </div> </a> <button aria-controls="toc-Differences_from_standard_Lua-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Differences from standard Lua subsection</span> </button> <ul id="toc-Differences_from_standard_Lua-sublist" class="vector-toc-list"> <li id="toc-Changed_functions" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Changed_functions"> <div class="vector-toc-text"> <span class="vector-toc-numb">7.1</span> <span>Changed functions</span> </div> </a> <ul id="toc-Changed_functions-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Removed_functions_and_packages" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Removed_functions_and_packages"> <div class="vector-toc-text"> <span class="vector-toc-numb">7.2</span> <span>Removed functions and packages</span> </div> </a> <ul id="toc-Removed_functions_and_packages-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Additional_caveats" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Additional_caveats"> <div class="vector-toc-text"> <span class="vector-toc-numb">7.3</span> <span>Additional caveats</span> </div> </a> <ul id="toc-Additional_caveats-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Writing_Scribunto_libraries" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Writing_Scribunto_libraries"> <div class="vector-toc-text"> <span class="vector-toc-numb">8</span> <span>Writing Scribunto libraries</span> </div> </a> <button aria-controls="toc-Writing_Scribunto_libraries-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Writing Scribunto libraries subsection</span> </button> <ul id="toc-Writing_Scribunto_libraries-sublist" class="vector-toc-list"> <li id="toc-Library" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Library"> <div class="vector-toc-text"> <span class="vector-toc-numb">8.1</span> <span>Library</span> </div> </a> <ul id="toc-Library-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Test_cases" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Test_cases"> <div class="vector-toc-text"> <span class="vector-toc-numb">8.2</span> <span>Test cases</span> </div> </a> <ul id="toc-Test_cases-sublist" class="vector-toc-list"> <li id="toc-Test_cases_in_another_extension" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Test_cases_in_another_extension"> <div class="vector-toc-text"> <span class="vector-toc-numb">8.2.1</span> <span>Test cases in another extension</span> </div> </a> <ul id="toc-Test_cases_in_another_extension-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Documentation" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Documentation"> <div class="vector-toc-text"> <span class="vector-toc-numb">8.3</span> <span>Documentation</span> </div> </a> <ul id="toc-Documentation-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-See_also" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#See_also"> <div class="vector-toc-text"> <span class="vector-toc-numb">9</span> <span>See also</span> </div> </a> <ul id="toc-See_also-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-License" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#License"> <div class="vector-toc-text"> <span class="vector-toc-numb">10</span> <span>License</span> </div> </a> <ul id="toc-License-sublist" class="vector-toc-list"> </ul> </li> </ul> </div> </div> </nav> </div> </div> <div class="mw-content-container"> <main id="content" class="mw-body"> <header class="mw-body-header vector-page-titlebar"> <nav aria-label="Contents" class="vector-toc-landmark"> <div id="vector-page-titlebar-toc" class="vector-dropdown vector-page-titlebar-toc vector-button-flush-left" > <input type="checkbox" id="vector-page-titlebar-toc-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-page-titlebar-toc" class="vector-dropdown-checkbox " aria-label="Toggle the table of contents" > <label id="vector-page-titlebar-toc-label" for="vector-page-titlebar-toc-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-listBullet mw-ui-icon-wikimedia-listBullet"></span> <span class="vector-dropdown-label-text">Toggle the table of contents</span> </label> <div class="vector-dropdown-content"> <div id="vector-page-titlebar-toc-unpinned-container" class="vector-unpinned-container"> </div> </div> </div> </nav> <h1 id="firstHeading" class="firstHeading mw-first-heading"><span class="mw-page-title-namespace">Extension</span><span class="mw-page-title-separator">:</span><span class="mw-page-title-main">Scribunto/Lua reference manual</span></h1> <div class="mw-indicators"> <div id="mw-indicator-tpl-shortcut" class="mw-indicator"><div class="mw-parser-output"><div class="mw-parser-output"><style data-mw-deduplicate="TemplateStyles:r6605561">.mw-parser-output .tpl-badge{background-color:var(--background-color-progressive-subtle,#eaf3ff);color:var(--color-base,#202122);border-radius:10px;display:inline-block;font-size:90%;padding:5px 8px}</style><div class="tpl-badge">shortcuts: <a href="/wiki/Lua_manual" class="mw-redirect" title="Lua manual"><b>Lua manual</b></a>&#160; <a href="/wiki/LUAREF" class="mw-redirect" title="LUAREF"><b>LUAREF</b></a></div></div></div></div> </div> </header> <div class="vector-page-toolbar"> <div class="vector-page-toolbar-container"> <div id="left-navigation"> <nav aria-label="Namespaces"> <div id="p-associated-pages" class="vector-menu vector-menu-tabs mw-portlet mw-portlet-associated-pages" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-nstab-extension" class="selected vector-tab-noicon mw-list-item"><a href="/wiki/Extension:Scribunto/Lua_reference_manual" title="View the subject page [c]" accesskey="c"><span>Extension</span></a></li><li id="ca-talk" class="vector-tab-noicon mw-list-item"><a href="/wiki/Extension_talk:Scribunto/Lua_reference_manual" rel="discussion" title="Discussion about the content page [t]" accesskey="t"><span>Discussion</span></a></li> </ul> </div> </div> <div id="vector-variants-dropdown" class="vector-dropdown emptyPortlet" > <input type="checkbox" id="vector-variants-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-variants-dropdown" class="vector-dropdown-checkbox " aria-label="Change language variant" > <label id="vector-variants-dropdown-label" for="vector-variants-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet" aria-hidden="true" ><span class="vector-dropdown-label-text">English</span> </label> <div class="vector-dropdown-content"> <div id="p-variants" class="vector-menu mw-portlet mw-portlet-variants emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> </div> </div> </nav> </div> <div id="right-navigation" class="vector-collapsible"> <nav aria-label="Views"> <div id="p-views" class="vector-menu vector-menu-tabs mw-portlet mw-portlet-views" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-view" class="selected vector-tab-noicon mw-list-item"><a href="/wiki/Extension:Scribunto/Lua_reference_manual"><span>Read</span></a></li><li id="ca-viewsource" class="vector-tab-noicon mw-list-item"><a href="/w/index.php?title=Extension:Scribunto/Lua_reference_manual&amp;action=edit" title="This page is protected.&#10;You can view its source [e]" accesskey="e"><span>View source</span></a></li><li id="ca-history" class="vector-tab-noicon mw-list-item"><a href="/w/index.php?title=Extension:Scribunto/Lua_reference_manual&amp;action=history" title="Past revisions of this page [h]" accesskey="h"><span>View history</span></a></li> </ul> </div> </div> </nav> <nav class="vector-page-tools-landmark" aria-label="Page tools"> <div id="vector-page-tools-dropdown" class="vector-dropdown vector-page-tools-dropdown" > <input type="checkbox" id="vector-page-tools-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-page-tools-dropdown" class="vector-dropdown-checkbox " aria-label="Tools" > <label id="vector-page-tools-dropdown-label" for="vector-page-tools-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet" aria-hidden="true" ><span class="vector-dropdown-label-text">Tools</span> </label> <div class="vector-dropdown-content"> <div id="vector-page-tools-unpinned-container" class="vector-unpinned-container"> <div id="vector-page-tools" class="vector-page-tools vector-pinnable-element"> <div class="vector-pinnable-header vector-page-tools-pinnable-header vector-pinnable-header-unpinned" data-feature-name="page-tools-pinned" data-pinnable-element-id="vector-page-tools" data-pinned-container-id="vector-page-tools-pinned-container" data-unpinned-container-id="vector-page-tools-unpinned-container" > <div class="vector-pinnable-header-label">Tools</div> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-page-tools.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-page-tools.unpin">hide</button> </div> <div id="p-cactions" class="vector-menu mw-portlet mw-portlet-cactions emptyPortlet vector-has-collapsible-items" title="More options" > <div class="vector-menu-heading"> Actions </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-more-view" class="selected vector-more-collapsible-item mw-list-item"><a href="/wiki/Extension:Scribunto/Lua_reference_manual"><span>Read</span></a></li><li id="ca-more-viewsource" class="vector-more-collapsible-item mw-list-item"><a href="/w/index.php?title=Extension:Scribunto/Lua_reference_manual&amp;action=edit"><span>View source</span></a></li><li id="ca-more-history" class="vector-more-collapsible-item mw-list-item"><a href="/w/index.php?title=Extension:Scribunto/Lua_reference_manual&amp;action=history"><span>View history</span></a></li> </ul> </div> </div> <div id="p-tb" class="vector-menu mw-portlet mw-portlet-tb" > <div class="vector-menu-heading"> General </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="t-whatlinkshere" class="mw-list-item"><a href="/wiki/Special:WhatLinksHere/Extension:Scribunto/Lua_reference_manual" title="A list of all wiki pages that link here [j]" accesskey="j"><span>What links here</span></a></li><li id="t-recentchangeslinked" class="mw-list-item"><a href="/wiki/Special:RecentChangesLinked/Extension:Scribunto/Lua_reference_manual" rel="nofollow" title="Recent changes in pages linked from this page [k]" accesskey="k"><span>Related changes</span></a></li><li id="t-upload" class="mw-list-item"><a href="//commons.wikimedia.org/wiki/Special:UploadWizard" title="Upload files [u]" accesskey="u"><span>Upload file</span></a></li><li id="t-specialpages" class="mw-list-item"><a href="/wiki/Special:SpecialPages" title="A list of all special pages [q]" accesskey="q"><span>Special pages</span></a></li><li id="t-permalink" class="mw-list-item"><a href="/w/index.php?title=Extension:Scribunto/Lua_reference_manual&amp;oldid=6855937" title="Permanent link to this revision of this page"><span>Permanent link</span></a></li><li id="t-info" class="mw-list-item"><a href="/w/index.php?title=Extension:Scribunto/Lua_reference_manual&amp;action=info" title="More information about this page"><span>Page information</span></a></li><li id="t-cite" class="mw-list-item"><a href="/w/index.php?title=Special:CiteThisPage&amp;page=Extension%3AScribunto%2FLua_reference_manual&amp;id=6855937&amp;wpFormIdentifier=titleform" title="Information on how to cite this page"><span>Cite this page</span></a></li><li id="t-urlshortener" class="mw-list-item"><a href="/w/index.php?title=Special:UrlShortener&amp;url=https%3A%2F%2Fwww.mediawiki.org%2Fwiki%2FExtension%3AScribunto%2FLua_reference_manual"><span>Get shortened URL</span></a></li><li id="t-urlshortener-qrcode" class="mw-list-item"><a href="/w/index.php?title=Special:QrCode&amp;url=https%3A%2F%2Fwww.mediawiki.org%2Fwiki%2FExtension%3AScribunto%2FLua_reference_manual"><span>Download QR code</span></a></li> </ul> </div> </div> <div id="p-coll-print_export" class="vector-menu mw-portlet mw-portlet-coll-print_export" > <div class="vector-menu-heading"> Print/export </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="coll-create_a_book" class="mw-list-item"><a href="/w/index.php?title=Special:Book&amp;bookcmd=book_creator&amp;referer=Extension%3AScribunto%2FLua+reference+manual"><span>Create a book</span></a></li><li id="coll-download-as-rl" class="mw-list-item"><a href="/w/index.php?title=Special:DownloadAsPdf&amp;page=Extension%3AScribunto%2FLua_reference_manual&amp;action=show-download-screen"><span>Download as PDF</span></a></li><li id="t-print" class="mw-list-item"><a href="/w/index.php?title=Extension:Scribunto/Lua_reference_manual&amp;printable=yes" title="Printable version of this page [p]" accesskey="p"><span>Printable version</span></a></li> </ul> </div> </div> <div id="p-wikibase-otherprojects" class="vector-menu mw-portlet mw-portlet-wikibase-otherprojects" > <div class="vector-menu-heading"> In other projects </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li class="wb-otherproject-link wb-otherproject-wikiversity mw-list-item"><a href="https://en.wikiversity.org/wiki/Lua/Scribunto_Lua" hreflang="en"><span>Wikiversity</span></a></li><li id="t-wikibase" class="wb-otherproject-link wb-otherproject-wikibase-dataitem mw-list-item"><a href="https://www.wikidata.org/wiki/Special:EntityPage/Q26134952" title="Link to connected data repository item [g]" accesskey="g"><span>Wikidata item</span></a></li> </ul> </div> </div> </div> </div> </div> </div> </nav> </div> </div> </div> <div class="vector-column-end"> <div class="vector-sticky-pinned-container"> <nav class="vector-page-tools-landmark" aria-label="Page tools"> <div id="vector-page-tools-pinned-container" class="vector-pinned-container"> </div> </nav> <nav class="vector-appearance-landmark" aria-label="Appearance"> <div id="vector-appearance-pinned-container" class="vector-pinned-container"> <div id="vector-appearance" class="vector-appearance vector-pinnable-element"> <div class="vector-pinnable-header vector-appearance-pinnable-header vector-pinnable-header-pinned" data-feature-name="appearance-pinned" data-pinnable-element-id="vector-appearance" data-pinned-container-id="vector-appearance-pinned-container" data-unpinned-container-id="vector-appearance-unpinned-container" > <div class="vector-pinnable-header-label">Appearance</div> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-appearance.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-appearance.unpin">hide</button> </div> </div> </div> </nav> </div> </div> <div id="bodyContent" class="vector-body" aria-labelledby="firstHeading" data-mw-ve-target-container> <div class="vector-body-before-content"> <div id="siteSub" class="noprint">From mediawiki.org</div> </div> <div id="contentSub"><div id="mw-content-subtitle"><div class="subpages">&lt; <bdi dir="ltr"><a href="/wiki/Special:MyLanguage/Extension:Scribunto" title="Special:MyLanguage/Extension:Scribunto">Extension:Scribunto</a></bdi></div></div></div> <div id="mw-content-text" class="mw-body-content"><div class="mw-pt-translate-header noprint nomobile" dir="ltr" lang="en"><a href="/w/index.php?title=Special:Translate&amp;group=page-Extension%3AScribunto%2FLua+reference+manual&amp;action=page&amp;filter=&amp;action_source=translate_page" title="Special:Translate">Translate this page</a></div><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr"><div class="mw-pt-languages noprint navigation-not-searchable" lang="en" dir="ltr"><div class="mw-pt-languages-label">Languages:</div><ul class="mw-pt-languages-list"><li><a href="/wiki/Extension:Scribunto/Lua_reference_manual/id" class="mw-pt-progress mw-pt-progress--low" title="Ekstensi:Pedoman referensi Scribunto/Lua (5% translated)" lang="id" dir="ltr">Bahasa Indonesia</a></li> <li><a href="/wiki/Extension:Scribunto/Lua_reference_manual/de" class="mw-pt-progress mw-pt-progress--med" title="Erweiterung:Scribunto/Lua-Referenzhandbuch (15% translated)" lang="de" dir="ltr">Deutsch</a></li> <li><span class="mw-pt-languages-ui mw-pt-languages-selected mw-pt-progress mw-pt-progress--complete" lang="en" dir="ltr">English</span></li> <li><a href="/wiki/Extension:Scribunto/Lua_reference_manual/eo" class="mw-pt-progress mw-pt-progress--med" title="Kromaĵo:Scribunto/Referenca manlibro pri Lua (49% translated)" lang="eo" dir="ltr">Esperanto</a></li> <li><a href="/wiki/Extension:Scribunto/Lua_reference_manual/vi" class="mw-pt-progress mw-pt-progress--low" title="Extension:Scribunto/Lua reference manual/vi (0% translated)" lang="vi" dir="ltr">Tiếng Việt</a></li> <li><a href="/wiki/Extension:Scribunto/Lua_reference_manual/tr" class="mw-pt-progress mw-pt-progress--med" title="Extension:Scribunto/Lua kaynak kılavuzu (59% translated)" lang="tr" dir="ltr">Türkçe</a></li> <li><a href="/wiki/Extension:Scribunto/Lua_reference_manual/ast" class="mw-pt-progress mw-pt-progress--low" title="Estensión:Scribunto/Manual de referencia de Lua (1% translated)" lang="ast" dir="ltr">asturianu</a></li> <li><a href="/wiki/Extension:Scribunto/Lua_reference_manual/ca" class="mw-pt-progress mw-pt-progress--low" title="Extension:Scribunto/Lua reference manual/ca (1% translated)" lang="ca" dir="ltr">català</a></li> <li><a href="/wiki/Extension:Scribunto/Lua_reference_manual/es" class="mw-pt-progress mw-pt-progress--med" title="Extensión:Scribunto/Manual de referencia de Lua (19% translated)" lang="es" dir="ltr">español</a></li> <li><a href="/wiki/Extension:Scribunto/Lua_reference_manual/fr" class="mw-pt-progress mw-pt-progress--high" title="Extension:Scribunto/Manuel de référence Lua (78% translated)" lang="fr" dir="ltr">français</a></li> <li><a href="/wiki/Extension:Scribunto/Lua_reference_manual/it" class="mw-pt-progress mw-pt-progress--low" title="Estensione:Scribunto/Manuale di riferimento per Lua (12% translated)" lang="it" dir="ltr">italiano</a></li> <li><a href="/wiki/Extension:Scribunto/Lua_reference_manual/hu" class="mw-pt-progress mw-pt-progress--low" title="Extension:Scribunto/Lua reference manual/hu (3% translated)" lang="hu" dir="ltr">magyar</a></li> <li><a href="/wiki/Extension:Scribunto/Lua_reference_manual/pl" class="mw-pt-progress mw-pt-progress--med" title="Extension:Scribunto/Lua reference manual (43% translated)" lang="pl" dir="ltr">polski</a></li> <li><a href="/wiki/Extension:Scribunto/Lua_reference_manual/pt-br" class="mw-pt-progress mw-pt-progress--low" title="Extensão:Scribunto/Manual de Refêrencia Lua (6% translated)" lang="pt-BR" dir="ltr">português do Brasil</a></li> <li><a href="/wiki/Extension:Scribunto/Lua_reference_manual/cs" class="mw-pt-progress mw-pt-progress--high" title="Extension:Scribunto/Lua reference manual (86% translated)" lang="cs" dir="ltr">čeština</a></li> <li><a href="/wiki/Extension:Scribunto/Lua_reference_manual/ru" class="mw-pt-progress mw-pt-progress--high" title="Расширение:Scribunto/Справочник Lua (70% translated)" lang="ru" dir="ltr">русский</a></li> <li><a href="/wiki/Extension:Scribunto/Lua_reference_manual/uk" class="mw-pt-progress mw-pt-progress--med" title="Розширення:Scribunto/Документація мови Lua (34% translated)" lang="uk" dir="ltr">українська</a></li> <li><a href="/wiki/Extension:Scribunto/Lua_reference_manual/he" class="mw-pt-progress mw-pt-progress--low" title="הרחבת סקריבונטו/לואה: הוראות הפעלה (6% translated)" lang="he" dir="rtl">עברית</a></li> <li><a href="/wiki/Extension:Scribunto/Lua_reference_manual/ar" class="mw-pt-progress mw-pt-progress--low" title="Extension:Scribunto/Lua reference manual/ar (0% translated)" lang="ar" dir="rtl">العربية</a></li> <li><a href="/wiki/Extension:Scribunto/Lua_reference_manual/kjp" class="mw-pt-progress mw-pt-progress--low" title="Extension:Scribunto/Lua ပ်ုယုံ့ စူးဖံင် (1% translated)" lang="kjp" dir="ltr">ဖၠုံလိက်</a></li> <li><a href="/wiki/Extension:Scribunto/Lua_reference_manual/my" class="mw-pt-progress mw-pt-progress--low" title="Extension:Scribunto/Lua အညွှန်း လက်စွဲ (1% translated)" lang="my" dir="ltr">မြန်မာဘာသာ</a></li> <li><a href="/wiki/Extension:Scribunto/Lua_reference_manual/zh" class="mw-pt-progress mw-pt-progress--high" title="Extension:Scribunto/Lua参考手册 (95% translated)" lang="zh" dir="ltr">中文</a></li> <li><a href="/wiki/Extension:Scribunto/Lua_reference_manual/ja" class="mw-pt-progress mw-pt-progress--med" title="Extension:Scribunto/Lua リファレンス マニュアル (29% translated)" lang="ja" dir="ltr">日本語</a></li> <li><a href="/wiki/Extension:Scribunto/Lua_reference_manual/ko" class="mw-pt-progress mw-pt-progress--low" title="확장기능:Scribunto/참고를 위한 Lua 설명서 (12% translated)" lang="ko" dir="ltr">한국어</a></li></ul></div> <p>This manual documents <a href="/wiki/Special:MyLanguage/Lua" title="Special:MyLanguage/Lua">Lua</a><span style="display:none"><a href="/wiki/Lua" title="Lua"> </a></span> as it is used in MediaWiki with the <a href="/wiki/Special:MyLanguage/Extension:Scribunto" title="Special:MyLanguage/Extension:Scribunto">Scribunto</a><span style="display:none"><a href="/wiki/Extension:Scribunto" title="Extension:Scribunto"> </a></span> extension. Some parts are derived from the <a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/index.html">Lua 5.1 reference manual</a>, which is available under the <a href="#License">MIT license</a>. </p> <style data-mw-deduplicate="TemplateStyles:r6651108">.mw-parser-output table.ombox{margin:4px 10%;border-collapse:collapse;border:1px solid #a2a9b1;background-color:#f8f9fa;color:#333;box-sizing:border-box}.mw-parser-output .ombox td.mbox-empty-cell{border:none;padding:0;width:1px}.mw-parser-output .ombox th.mbox-text,.mw-parser-output .ombox td.mbox-text{border:none;padding:0.25em 0.9em;width:100%}.mw-parser-output .ombox td.mbox-image{border:none;text-align:center;padding:2px 0 2px 0.9em}.mw-parser-output .ombox td.mbox-imageright{border:none;text-align:center;padding:2px 0.9em 2px 0}.mw-parser-output table.ombox-notice{border-color:#a2a9b1}.mw-parser-output table.ombox-speedy{background-color:#fee7e6;color:#333}.mw-parser-output table.ombox-speedy,.mw-parser-output table.ombox-delete{border-color:#b32424;border-width:2px}.mw-parser-output table.ombox-content{border-color:#f28500}.mw-parser-output table.ombox-style{border-color:#fc3}.mw-parser-output table.ombox-move{border-color:#9932cc}.mw-parser-output table.ombox-protection{border-color:#a2a9b1;border-width:2px}html body.mediawiki .mw-parser-output .ombox.mbox-small{clear:right;float:right;margin:4px 0 4px 1em;box-sizing:border-box;width:238px;font-size:88%;line-height:1.25em}@media screen{html.skin-theme-clientpref-night .mw-parser-output table.ombox{background-color:transparent;color:inherit}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output table.ombox{background-color:transparent;color:inherit}}</style><table class="ombox ombox-notice plainlinks" role="presentation"><tbody><tr><td class="mbox-image"><span typeof="mw:File"><span><img alt="" src="//upload.wikimedia.org/wikipedia/commons/thumb/e/ec/OOjs_UI_icon_information-progressive.svg/40px-OOjs_UI_icon_information-progressive.svg.png" decoding="async" width="40" height="40" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/e/ec/OOjs_UI_icon_information-progressive.svg/60px-OOjs_UI_icon_information-progressive.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/e/ec/OOjs_UI_icon_information-progressive.svg/80px-OOjs_UI_icon_information-progressive.svg.png 2x" data-file-width="20" data-file-height="20" /></span></span></td><td class="mbox-text">This page documents the latest version of the Scribunto extension. Some features may not be deployed yet.</td></tr></tbody></table> <div style="clear: right; margin-bottom: .5em; float: right; margin-left:2em; width: auto;"><meta property="mw:PageProp/toc" /></div> <div class="mw-heading mw-heading2"><h2 id="Introduction">Introduction</h2></div> <div class="mw-heading mw-heading3"><h3 id="Getting_started">Getting started</h3></div> <p>On a MediaWiki wiki with Scribunto enabled, <a href="/wiki/Special:MyLanguage/Help:Starting_a_new_page" title="Special:MyLanguage/Help:Starting a new page">create a page</a> with a title starting with <code>Module:</code>, for example "<a href="/wiki/Module:Bananas" title="Module:Bananas">Module:Bananas</a>". Into this new page, copy the following text: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="kd">local</span> <span class="n">p</span> <span class="o">=</span> <span class="p">{}</span> <span class="c1">--p stands for package</span> <span class="kr">function</span> <span class="nc">p</span><span class="p">.</span><span class="nf">hello</span><span class="p">(</span> <span class="n">frame</span> <span class="p">)</span> <span class="kr">return</span> <span class="s2">&quot;Hello, world!&quot;</span> <span class="kr">end</span> <span class="kr">return</span> <span class="n">p</span> </pre></div> <p>Save that, then on another (non-module) page, as on a <a href="/wiki/Sandbox" class="mw-redirect" title="Sandbox">sandbox page</a>, write: </p> <pre>{{#invoke:Bananas|hello}} </pre> <p>Except that you should replace "Bananas" with whatever you called your module. This will call the "hello" function exported from that module. The <code>{{#invoke:Bananas|hello}}</code> will be replaced with the text that the function returned, in this case, "Hello, world!" </p><p>It's generally a good idea to invoke Lua code from the context of a template. This means that from the perspective of a calling page, the syntax is independent of whether the template logic is implemented in Lua or in wikitext. It also avoids the introduction of additional complex syntax into the content namespace of a wiki. </p> <div class="mw-heading mw-heading3"><h3 id="Module_structure">Module structure</h3></div> <p>The module itself must return a Lua table containing the functions that may be called by <code>{{#invoke:}}</code>. Generally, as shown above, a local variable is declared holding a table, functions are added to this table, and the table is returned at the end of the module code. </p><p>Any functions that are not added to this table, whether local or global, will not be accessible by <code>{{#invoke:}}</code>, but globals might be accessible from other modules loaded using <code><a href="#require">require()</a></code>. It is generally good style for the module to declare all functions and variables local. </p> <div class="mw-heading mw-heading3"><h3 id="Accessing_parameters_from_wikitext">Accessing parameters from wikitext</h3></div> <p>Functions called by <code>{{#invoke:}}</code> will be passed a single parameter, that being a <a href="#frame-object">frame object</a>. To access the parameters passed to the <code>{{#invoke:}}</code>, code will typically use the <code><a href="#frame.args">args</a></code> table of that frame object. It's also possible to access the parameters passed to the template containing the <code>{{#invoke:}}</code> by using <code><a href="#frame:getParent">frame:getParent()</a></code> and accessing that frame's <code>args</code>. </p><p>This frame object is also used to access context-specific features of the wikitext parser, such as <a href="#frame:callParserFunction">calling parser functions</a>, <a href="#frame:expandTemplate">expanding templates</a>, and <a href="#frame:preprocess">expanding arbitrary wikitext strings</a>. </p> <div class="mw-heading mw-heading3"><h3 id="Returning_text">Returning text</h3></div> <p>The module function should usually return a single string; whatever values are returned will be passed through <a href="#tostring">tostring()</a> and then concatenated with no separator. This string is incorporated into the wikitext as the result of the <code>{{#invoke:}}</code>. </p><p>At this point in the page parse, templates have already been expanded, parser functions and extension tags have already been processed, and <a href="/wiki/Special:MyLanguage/Pre-save_transforms" title="Special:MyLanguage/Pre-save transforms">pre-save transforms</a> (i.e., signature tilde expansion, pipe trick, etc.) have already happened. Therefore the module cannot use these features in its output text. For example, if a module returns <code>"Hello, [[world]]! {{welcome}}"</code>, the page will read "Hello, <a href="/wiki/World" class="mw-redirect" title="World">world</a>! {{welcome}}". </p><p>On the other hand, <a href="/wiki/Special:MyLanguage/Help:Substitution" title="Special:MyLanguage/Help:Substitution">subst</a> is handled at an earlier stage of processing, so with <code>{{subst:#invoke:}}</code> only other attempted substitutions will be processed. Since the failed substitution will remain in the wikitext, they will then be processed on the <i>next</i> edit. This should generally be avoided. </p> <div class="mw-heading mw-heading3"><h3 id="Module_documentation">Module documentation</h3></div> <p>Scribunto allows modules to be documented by automatically associating the module with a wikitext documentation page; by default, the "/doc" subpage of the module is used for this purpose and is transcluded above the module source code on the module page. For example, the documentation for "Module:Bananas" would be at "Module:Bananas/doc". </p><p>This can be configured using the following <a href="/wiki/Special:MyLanguage/Help:System_message" title="Special:MyLanguage/Help:System message">Help:System message</a><span style="display:none"><a href="/wiki/Help:System_message" title="Help:System message"> </a></span>: </p> <ul><li><code>scribunto-doc-page-name</code> — Sets the name of the page used for documentation. The name of the module (without the Module: prefix) is passed as <code>$1</code>. If in the module namespace, the pages specified here will be interpreted as wikitext rather than Lua source and may not be used with <code>{{#invoke:}}</code>. The default is "Module:$1/doc", i.e. the /doc subpage of the module. Note that parser functions and other brace expansion may not be used in this message.</li> <li><code>scribunto-doc-page-does-not-exist</code> — Message displayed when the doc page does not exist. The name of the page is passed as <code>$1</code>. The default is empty.</li> <li><code>scribunto-doc-page-show</code> — Message displayed when the doc page does exist. The name of the page is passed as <code>$1</code>. The default is to transclude the documentation page.</li> <li><code>scribunto-doc-page-header</code> — Header displayed when viewing the documentation page itself. The name of the module (with Module: prefix) being documented is passed as <code>$1</code>. The default simply displays a short explanation in italics.</li></ul> <p>Note that modules cannot be directly categorized and cannot have interwiki links directly added. These could be placed on the documentation page inside <code class="mw-highlight" style="white-space:nowrap"><span class="p">&#8206;&lt;</span><span class="nt">includeonly</span><span class="p">&gt;</span>...<span class="p">&#8206;&lt;&#47;</span><span class="nt">includeonly</span><span class="p">&gt;</span></code> tags, where they will be applied to the module when the documentation page is transcluded onto the module page. </p> <div class="mw-heading mw-heading3"><h3 id="Renaming_or_moving_modules">Renaming or moving modules</h3></div> <p>To rename or move a module, use the <u>Move Page</u> link in the Tools sidebar. You will want to move both the module itself, as well as the subpage containing its documentation. </p><p>To manually create a module redirect, use the following syntax: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="kr">return</span> <span class="nb">require</span> <span class="s">[[Module:Foo]]</span> </pre></div> <p>Replace <code>Foo</code> with the name of the module you'd like to redirect to. </p> <div class="mw-heading mw-heading2"><h2 id="Lua_language">Lua language</h2></div> <div class="mw-heading mw-heading3"><h3 id="Tokens">Tokens</h3></div> <p><span class="anchor" id="name"></span> A <i>name</i> (also called an <i>identifier</i>) in Lua can be any string of letters, digits, and underscores, not beginning with a digit. Names are case-sensitive; "foo", "Foo", and "FOO" are all different names. </p><p>The following keywords are reserved and may not be used as names: </p> <div style="margin:0.3em 1.6em; column-width: 10em;"> <ul><li><code>and</code></li> <li><code>break</code></li> <li><code>do</code></li> <li><code>else</code></li> <li><code>elseif</code></li> <li><code>end</code></li> <li><code>false</code></li> <li><code>for</code></li> <li><code>function</code></li> <li><code>if</code></li> <li><code>in</code></li> <li><code>local</code></li> <li><code>nil</code></li> <li><code>not</code></li> <li><code>or</code></li> <li><code>repeat</code></li> <li><code>return</code></li> <li><code>then</code></li> <li><code>true</code></li> <li><code>until</code></li> <li><code>while</code></li></ul> </div> <p>Names starting with an underscore followed by uppercase letters are reserved for internal Lua global variables. </p><p>Other tokens are: </p> <div style="margin:0.3em 1.6em; column-width: 10em;"> <ul><li><code>#</code></li> <li><code>%</code></li> <li><code>(</code></li> <li><code>)</code></li> <li><code>*</code></li> <li><code>+</code></li> <li><code>,</code></li> <li><code>-</code></li> <li><code>--</code></li> <li><code>.</code></li> <li><code>..</code></li> <li><code>...</code></li> <li><code>/</code></li> <li><code>:</code></li> <li><code>;</code></li> <li><code>&lt;</code></li> <li><code>&lt;=</code></li> <li><code>=</code></li> <li><code>==</code></li> <li><code>&gt;</code></li> <li><code>&gt;=</code></li> <li><code>[</code></li> <li><code>]</code></li> <li><code>^</code></li> <li><code>{</code></li> <li><code>}</code></li> <li><code>~=</code></li></ul> </div> <div class="mw-heading mw-heading3"><h3 id="Comments">Comments</h3></div> <p>A comment starts with a <code>--</code> anywhere outside a string. If the <code>--</code> is immediately followed by <a href="#long_brackets">an opening long bracket</a>, the comment continues to the corresponding closing long bracket; otherwise the comment runs to the end of the current line. </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">-- A comment in Lua starts with a double-hyphen and runs to the end of the line.</span> <span class="cm">--[[ Multi-line strings &amp; comments</span> <span class="cm"> are adorned with double square brackets. ]]</span> <span class="cm">--[=[ Comments like this can have other --[[comments]] nested. ]=]</span> <span class="cm">--[==[ Comments like this can have other</span> <span class="cm"> --[===[ long --[=[comments]=] --nested</span> <span class="cm"> ]===] multiple times, even if all of them are</span> <span class="cm"> --[[ not delimited with matching long brackets! ]===]</span> <span class="cm"> ]==]</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="Data_types">Data types</h3></div> <p>Lua is a dynamically-typed language, which means that variables and function arguments have no type, only the values assigned to them. All values carry a type. </p><p>Lua has eight basic data types, however only six are relevant to the Scribunto extension. The <code><a href="#type">type()</a></code> function will return the type of a value. </p><p>The <code><a href="#tostring">tostring()</a></code> function will convert a value to a string. The <code><a href="#tonumber">tonumber()</a></code> function will convert a value to a number if possible, and otherwise will return nil. There are no explicit functions to convert a value to other data types. </p><p>Numbers are automatically converted to strings when used where a string is expected, e.g. when used with the concatenation operator. Strings recognized by <code><a href="#tonumber">tonumber()</a></code> are automatically converted to numbers when used with arithmetic operators. When a boolean value is expected, all values other than nil and false are considered to be true. </p> <div class="mw-heading mw-heading4"><h4 id="nil">nil</h4></div> <p><code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="s2">&quot;nil&quot;</span></code> is the data type of <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">nil</span></code>, which exists to represent the absence of a value. </p><p>Nil may not be used as a key in a table, and there is no difference between an unassigned table key and a key assigned a nil value. </p><p>When converted to a string, the result is <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="s2">&quot;nil&quot;</span></code>. When converted to boolean, nil is considered false. </p><p>Note: Lua does make a distinction between <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">nil</span></code> and nothing at all in some limited situations. For example, <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="nb">tostring</span><span class="p">(</span><span class="kc">nil</span><span class="p">)</span></code> returns <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="s2">&quot;nil&quot;</span></code>, but <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="nb">tostring</span><span class="p">()</span></code> throws an error, as the first parameter is required. This distinction is particularly relevant to the <a href="#select">select()</a> function. </p> <div class="mw-heading mw-heading4"><h4 id="boolean">boolean</h4></div> <p>Boolean values are <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">true</span></code> and <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">false</span></code>. </p><p>When converted to a string, the result is <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="s2">&quot;true&quot;</span></code> or <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="s2">&quot;false&quot;</span></code>. </p><p>Unlike many other languages, boolean values may not be directly converted to numbers. And unlike many other languages, only <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">false</span></code> and nil are considered false for boolean conversion; the number 0 and the empty string are both considered true. </p> <div class="mw-heading mw-heading4"><h4 id="string">string</h4></div> <p>Lua strings are considered a series of 8-bit bytes; it is up to the application to interpret them in any particular encoding. </p><p>String literals may be delimited by either single or double quotes (<code>'</code> or <code>"</code>); like JavaScript and unlike PHP, there is no difference between the two. The following escape sequences are recognized: </p> <div style="column-width:20em;"> <ul><li><code>\a</code> (bell, byte 7)</li> <li><code>\b</code> (backspace, byte 8)</li> <li><code>\t</code> (horizontal tab, byte 9)</li> <li><code>\n</code> (newline, byte 10)</li> <li><code>\v</code> (vertical tab, byte 11)</li> <li><code>\f</code> (form feed, byte 12)</li> <li><code>\r</code> (carriage return, byte 13)</li> <li><code>\"</code> (double quote, byte 34)</li> <li><code>\'</code> (single quote, byte 39)</li> <li><code>\\</code> (backslash, byte 92)</li></ul> </div> <p>A literal newline may also be included in a string by preceding it with a backslash. Bytes may also be specified using an escape sequence '\<i>ddd</i>', where <i>ddd</i> is the decimal value of the byte in the range 0–255. To include Unicode characters using escape sequences, the individual bytes for the <a href="https://en.wikipedia.org/wiki/UTF-8" class="extiw" title="w:UTF-8">UTF-8</a> encoding must be specified; in general, it will be more straightforward to enter the Unicode characters directly. </p><p><span class="anchor" id="long_brackets"></span> Literal strings can also be defined using <i>long brackets</i>. An opening long bracket consists of an opening square bracket followed by zero or more equal signs followed by another opening square bracket, e.g. <code>[[</code>, <code>[=[</code>, or <code>[=====[</code>. The opening long bracket must be matched by the corresponding closing long bracket, e.g. <code>]]</code>, <code>]=]</code>, or <code>]=====]</code>. As a special case, if an opening long bracket is immediately followed by a newline then the newline is not included in the string, but a newline just before the closing long bracket is kept. Strings delimited by long brackets do not interpret escape sequences. </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">-- This long string</span> <span class="n">foo</span> <span class="o">=</span> <span class="s">[[</span> <span class="s">bar\tbaz</span> <span class="s">]]</span> <span class="c1">-- is equivalent to this quote-delimited string</span> <span class="n">foo</span> <span class="o">=</span> <span class="s1">&#39;bar</span><span class="se">\\</span><span class="s1">tbaz</span><span class="se">\n</span><span class="s1">&#39;</span> </pre></div> <p>Note that all strings are considered true when converted to boolean. This is unlike most other languages, where the empty string is usually considered false. </p> <div class="mw-heading mw-heading4"><h4 id="number">number</h4></div> <p>Lua has only one numeric type, which is typically represented internally as a <a href="https://en.wikipedia.org/wiki/double-precision_floating-point_format" class="extiw" title="w:double-precision floating-point format">64-bit double-precision floating-point value</a>. In this format, integers between <code>-9007199254740991</code> (-2<sup>53</sup> + 1) and <code>9007199254740991</code> (2<sup>53</sup> - 1) may be represented exactly; larger numbers and numbers with a fractional part may suffer from round-off error. </p><p>Number constants are specified using a period (<code>.</code>) as a decimal separator and without grouping separators, e.g. <code>123456.78</code>. Numbers may also be represented using <a href="https://en.wikipedia.org/wiki/E_notation" class="extiw" title="w:E notation">E notation</a> without spaces, e.g. <code>1.23e-10</code>, <code>123.45e20</code>, or <code>1.23E+5</code>. Integers may also be specified in hexadecimal notation using a <code>0x</code> prefix, e.g. <code>0x3A</code>. </p><p>A handful of number values are handled in a special way: </p> <ul><li>Postive and negative infinity, which evalute to being greater or less than every other number, respectively (except the NaNs - see below). These can be accessed in two ways: through the <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="n">math</span></code> library, as <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="nb">math.huge</span></code> and <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="o">-</span><span class="nb">math.huge</span></code>, or through numerical operations such as <code>1/0</code> and <code>-1/0</code>.</li> <li>Lua occasionally distinguishes <code>0</code> and <code>-0</code> (see the <a href="https://en.wikipedia.org/wiki/IEEE_754#Signed_zero" class="extiw" title="w:IEEE 754">IEEE 754</a> for more information on signed zeros). <code>0</code> and <code>-0</code> are strictly equivalent for almost all purposes, but behave differently in a small number of numerical operations (e.g. <code>1/0</code> returns infinity, while <code>1/-0</code> returns negative infinity). The distinction also affects conversions from number to string (and vice-versa).</li> <li>Positive and negative <a href="https://en.wikipedia.org/wiki/NaN" class="extiw" title="w:NaN">NaN</a> (standing for Not a Number). No constant is provided for either of these, but <code>0/0</code> evaluates to negative NaN. Note that both NaNs have the unique quality that any comparison which involves them evaluates to <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">false</span></code> (which means they do not even evaluate as being equal to themselves). The only practical distinction between the two is on type conversion to and from string (see below).</li></ul> <p>Note that all numbers (including <code>0</code>, <code>-0</code>, the infinities and NaNs) are considered true when converted to boolean. This is unlike most other languages, where <code>0</code> is usually considered false. When converted to a string, finite numbers are represented in decimal, and E notation if 10<sup>14</sup> or greater (e.g. <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="s2">&quot;1e+14&quot;</span></code>); the infinities are <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="s2">&quot;inf&quot;</span></code> and <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="s2">&quot;-inf&quot;</span></code>; and the NaNs are <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="s2">&quot;nan&quot;</span></code> and <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="s2">&quot;-nan&quot;</span></code>. </p><p><span style="color:#d73333" dir="ltr">Known bug</span>: the Lua interpreter will treat all instances of <code>0</code> <b>and</b> <code>-0</code> as whichever of the two is encountered first when the script is compiled, which means that the return values of <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="nb">tostring</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span></code>, <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="mi">1</span><span class="o">/-</span><span class="mi">0</span></code> (and so on) are affected by where they occur in the code. This can cause unexpected results, particularly if all instances of <code>0</code> are converted to <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="s2">&quot;-0&quot;</span></code> on return. If necessary, this can be circumvented by generating zero values using <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="nb">tonumber</span><span class="p">(</span><span class="s2">&quot;0&quot;</span><span class="p">)</span></code> and <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="nb">tonumber</span><span class="p">(</span><span class="s2">&quot;-0&quot;</span><span class="p">)</span></code>, which doesn't seem to cause or be affected by the issue. See <a rel="nofollow" class="external autonumber" href="https://lua-l.lua.narkive.com/k4kbwgKi/tostring-and-0">[1]</a>. </p> <div class="mw-heading mw-heading4"><h4 id="table">table</h4></div> <p>Lua tables are associative arrays, much like PHP arrays and JavaScript objects. </p><p>Tables are created using curly braces. The empty table is <code>{}</code>. To populate fields on creation, a comma- and/or semicolon-separated list of field specifiers may be included in the braces. These take any of several forms: </p> <ul><li><code style="white-space:nowrap">[<i><a href="#Expressions">expression1</a></i>] = <i><a href="#Expressions">expression2</a></i></code> uses the (first) value of <i>expression1</i> as the key and the (first) value of <i>expression2</i> as the value.</li> <li><code style="white-space:nowrap"><i><a href="#name">name</a></i> = <i><a href="#Expressions">expression</a></i></code> is equivalent to <code style="white-space:nowrap">["<i>name</i>"] = <i>expression</i></code></li> <li><code><i><a href="#Expressions">expression</a></i></code> is roughly equivalent to <code style="white-space:nowrap">[<i>i</i>] = <i>expression</i></code>, where <i>i</i> is an integer starting at 1 and incrementing with each field specification of this form. If this is the last field specifier and the expression has multiple values, all values are used; otherwise only the first is kept.</li></ul> <p>The fields in a table are accessed using bracket notation, e.g. <code>table[key]</code>. String keys that are also valid <a href="#name">names</a> may also be accessed using dot notation, e.g. <code>table.key</code> is equivalent to <code>table['key']</code>. Calling a function that is a value in the table may use colon notation; for example, <code style="white-space:nowrap">table:func( ... )</code>, which is equivalent to <code style="white-space:nowrap">table['func']( table, ... )</code> or <code style="white-space:nowrap">table.func( table, ... )</code>. </p><p><span class="anchor" id="sequence"></span> An <i>array</i> (also called a <i>sequence</i> or <i>list</i>) is a table with non-nil values for all positive integers from 1 to N and no value (nil) for all positive integers greater than N. Many Lua functions operate only on arrays, and ignore non-positive-integer keys. </p><p>Unlike many other languages such as PHP or JavaScript, any value except nil and NaN may be used as a key and no type conversion is performed. These are all valid and distinct: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">-- Create table</span> <span class="n">t</span> <span class="o">=</span> <span class="p">{}</span> <span class="n">t</span><span class="p">[</span><span class="s2">&quot;foo&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;foo&quot;</span> <span class="n">t</span><span class="p">.</span><span class="n">bar</span> <span class="o">=</span> <span class="s2">&quot;bar&quot;</span> <span class="n">t</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;one&quot;</span> <span class="n">t</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;two&quot;</span> <span class="n">t</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;three&quot;</span> <span class="n">t</span><span class="p">[</span><span class="mi">12</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;the number twelve&quot;</span> <span class="n">t</span><span class="p">[</span><span class="s2">&quot;12&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;the string twelve&quot;</span> <span class="n">t</span><span class="p">[</span><span class="kc">true</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;true&quot;</span> <span class="n">t</span><span class="p">[</span><span class="nb">tonumber</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;yes, even functions may be table keys&quot;</span> <span class="n">t</span><span class="p">[</span><span class="n">t</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;yes, a table may be a table key too. Even in itself.&quot;</span> <span class="c1">-- This creates a table roughly equivalent to the above</span> <span class="n">t2</span> <span class="o">=</span> <span class="p">{</span> <span class="n">foo</span> <span class="o">=</span> <span class="s2">&quot;foo&quot;</span><span class="p">,</span> <span class="n">bar</span> <span class="o">=</span> <span class="s2">&quot;bar&quot;</span><span class="p">,</span> <span class="s2">&quot;one&quot;</span><span class="p">,</span> <span class="s2">&quot;two&quot;</span><span class="p">,</span> <span class="p">[</span><span class="mi">12</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;the number twelve&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;12&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;the string twelve&quot;</span><span class="p">,</span> <span class="s2">&quot;three&quot;</span><span class="p">,</span> <span class="p">[</span><span class="kc">true</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;true&quot;</span><span class="p">,</span> <span class="p">[</span><span class="nb">tonumber</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;yes, even functions may be table keys&quot;</span><span class="p">,</span> <span class="p">}</span> <span class="n">t2</span><span class="p">[</span><span class="n">t2</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;yes, a table may be a table key too. Even in itself.&quot;</span> </pre></div> <p>Similarly, any value except nil may be stored as a value in a table. Storing nil is equivalent to deleting the key from the table, and accessing any key that has not been set will result in a nil value. </p><p>Note that tables are never implicitly copied in Lua; if a table is passed as an argument to the function and the function manipulates the keys or values in the table, those changes will be visible in the caller. </p><p>When converted to a string, the usual result is "table" but may be overridden using the <code>__tostring</code> <a href="#Metatables">metamethod</a>. Even the empty table is considered true as a boolean. </p> <div class="mw-heading mw-heading4"><h4 id="function">function</h4></div> <p>Functions in Lua are first-class values: they may be created anonymously, passed as arguments, assigned to variables, and so on. </p><p>Functions are created using the <code>function</code> keyword, and called using parentheses. <a href="https://en.wikipedia.org/wiki/syntactic_sugar" class="extiw" title="w:syntactic sugar">Syntactic sugar</a> is available for named functions, local functions, and functions that act like member functions to a table. See <a href="#Function_declarations">Function declarations</a> and <a href="#Function_calls">Function calls</a> below for details. </p><p>Lua functions are <a href="https://en.wikipedia.org/wiki/Closure_(computer_science)" class="extiw" title="w:Closure (computer science)">closures</a>, meaning that they maintain a reference to the scope in which they are declared and can access and manipulate variables in that scope. </p><p>Like tables, if a function is assigned to a different variable or passed as an argument to another function, it is still the same underlying "function object" that will be called. </p><p>When converted to a string, the result is "function". </p> <div class="mw-heading mw-heading4"><h4 id="Unsupported_types">Unsupported types</h4></div> <p><span class="anchor" id="userdata"></span> The <i>userdata</i> type is used to hold opaque values for extensions to Lua written in other languages; for example, a userdata might be used to hold a C pointer or struct. To allow for use of Scribunto in hosting environments where custom-compiled code is not allowed, no such extensions are used. </p><p><span class="anchor" id="thread"></span> The <i>thread</i> type represents the handles for coroutines, which are not available in Scribunto's sandbox. </p> <div class="mw-heading mw-heading3"><h3 id="Upvalues">Upvalues</h3></div> <p>There is a strict limit of max 60 unique upvalues acessed inside a function. An upvalue is a value declared outside of a function and used inside it. As upvalues do count: </p> <ul><li>variables (a table with many elements counts as one upvalue)</li> <li>functions (only those directly called from function in question, not their dependencies)</li></ul> <p>A violation of the limit can be triggered by a use of such a variable or function, not by its mere presence or availability. Repeated access to same upvalue does not exhaust the limit further. </p> <div class="mw-heading mw-heading3"><h3 id="Metatables">Metatables</h3></div> <p>Every table may have an associated table known as a <i>metatable</i>. The fields in the metatable are used by some operators and functions to specify different or fallback behavior for the table. The metatable for a table may be accessed using the <a href="#getmetatable">getmetatable()</a> function, and set with the <a href="#setmetatable">setmetatable()</a> function. </p><p>When being accessed for their meta functions, metatable fields are accessed as if with <a href="#rawget">rawget()</a>. </p><p>Metatable fields that affect the table itself are: </p> <dl><dt>__index</dt> <dd>This is used when a table access <code>t[key]</code> would return nil. If the value of this field is a table, the access will be repeated in that table, i.e. <code>__index[key]</code> (which may invoke that table's metatable's __index). If the value of this field is a function, the function will be called as <code style="white-space:nowrap">__index( t, key )</code>. The <a href="#rawget">rawget()</a> function bypasses this metamethod.</dd> <dt>__newindex</dt> <dd>This is used when assigning a key to a table <code style="white-space:nowrap">t[key] = value</code> where <code style="white-space:nowrap"><a href="#rawget">rawget</a>( t, key )</code> would return nil. If the value of this field is a table, the assignment will be made to that table instead, i.e. <code style="white-space:nowrap">__newindex[key] = value</code> (which may invoke that table's metatable's __newindex). If the value of this field is a function, the function will be called as <code style="white-space:nowrap">__newindex( t, key, value )</code>. The <a href="#rawset">rawset()</a> function bypasses this metamethod.</dd> <dt>__call</dt> <dd>This is used when function call syntax is used on a table, <code style="white-space:nowrap">t( ··· )</code>. The value must be a function, which is called as something like <code style="white-space:nowrap">__call( t, ··· )</code>.</dd> <dt><span class="anchor" id="weak_tables"></span>__mode</dt> <dd>This is used to make tables holding weak references. The value must be a string. By default, any value that is used as a key or as a value in a table will not be garbage collected. But if this metafield contains the letter 'k', keys may be garbage collected if there are no non-weak references, and if it contains 'v' values may be; in either case, both the corresponding key and value are removed from the table. Note that behavior is undefined if this field is altered after the table is used as a metatable.</dd></dl> <p>Other metatable fields include: </p> <div style="margin:0 1.6em; column-width: 10em;"> <ul><li><a href="#Arithmetic_operators">__add</a><sup><a href="#binop-note">†</a></sup></li> <li><a href="#Arithmetic_operators">__sub</a><sup><a href="#binop-note">†</a></sup></li> <li><a href="#Arithmetic_operators">__mul</a><sup><a href="#binop-note">†</a></sup></li> <li><a href="#Arithmetic_operators">__div</a><sup><a href="#binop-note">†</a></sup></li> <li><a href="#Arithmetic_operators">__mod</a><sup><a href="#binop-note">†</a></sup></li> <li><a href="#Arithmetic_operators">__pow</a><sup><a href="#binop-note">†</a></sup></li> <li><a href="#Arithmetic_operators">__unm</a></li> <li><a href="#Concatenation_operator">__concat</a><sup><a href="#binop-note">†</a></sup></li> <li><a href="#Relational_operators">__eq</a><sup><a href="#relop-note">‡</a></sup></li> <li><a href="#Relational_operators">__lt</a><sup><a href="#relop-note">‡</a></sup></li> <li><a href="#Relational_operators">__le</a><sup><a href="#relop-note">‡</a></sup></li> <li><a href="#pairs">__pairs</a></li> <li><a href="#ipairs">__ipairs</a></li> <li>__metatable<sup><a href="#metatable-note">*</a></sup></li> <li><a href="#tostring">__tostring</a></li></ul> </div> <div style="font-size:smaller"> <div id="binop-note" style="padding:0 1em;text-indent: -1em;"><sup>†</sup> For binary operators, Lua looks first at the left argument's metatable (if any) then the right's when looking for a metamethod to use.</div> <div id="relop-note" style="padding:0 1em;text-indent: -1em;"><sup>‡</sup> For relational operators, the metamethod is only used if the same function is specified in both arguments' metatables. Different anonymous functions, even with identical body and closure, may not be considered the same.</div> <div id="metatable-note" style="padding:0 1em;text-indent: -1em;"><sup>*</sup> __metatable affects both <a href="#getmetatable">getmetatable()</a> and <a href="#setmetatable">setmetatable()</a></div> </div> <p>Note: In Lua, all strings also share a single metatable, in which <code>__index</code> refers to the <code><a href="#String_library">string</a></code> table. This metatable is not accessible in Scribunto, nor is the referenced <code>string</code> table; the string table available to modules is a copy. </p> <div class="mw-heading mw-heading3"><h3 id="Variables">Variables</h3></div> <p>Variables are places that store values. There are three kinds of variables in Lua: global variables, local variables, and table fields. </p><p>A <a href="#name">name</a> represents a global or local variable (or a function argument, which is just a kind of local variable). Variables are assumed to be global unless explicitly declared as local using the <code>local</code> keyword. Any variable that has not been assigned a value is considered to have a nil value. </p><p>Global variables are stored in a standard Lua table called an <i>environment</i>; this table is often available as the global variable <code>_G</code>. It is possible to set a metatable for this global variable table; the __index and __newindex metamethods will be called for accesses of and assignments to global variables just as they would for accesses of and assignments to fields in any other table. </p><p>The environment for a function may be accessed using the <a href="#getfenv">getfenv()</a> function and changed using the <a href="#setfenv">setfenv()</a> function; in Scribunto, these functions are severely restricted if they are available at all. </p><p>Local variables are lexically scoped; see <a href="#Local_variable_declarations">Local variable declarations</a> for details. </p> <div class="mw-heading mw-heading3"><h3 id="Expressions">Expressions</h3></div> <p>An <i>expression</i> is something that has values: literals (numbers, strings, true, false, nil), anonymous function declarations, table constructors, variable references, function calls, the <a href="#varargs">vararg expression</a>, expressions wrapped in parentheses, unary operators applied to expressions, and expressions combined with binary operators. </p><p>Most expressions have one value; function calls and the vararg expression can have any number. Note that wrapping a function call or vararg expression in parentheses will lose all except the first value. </p><p><span class="anchor" id="expression-list"></span><span class="anchor" id="exp-list"></span> Expression lists are comma-separated lists of expressions. All except the last expression are forced to one value (dropping additional values, or using nil if the expression has no values); all values from the last expression are included in the values of the expression list. </p> <div class="mw-heading mw-heading4"><h4 id="Arithmetic_operators">Arithmetic operators</h4></div> <p>Lua supports the usual arithmetic operators: addition, subtraction, multiplication, division, modulo, exponentiation, and negation. </p><p>When all operands are numbers or strings for which <a href="#tonumber">tonumber()</a> returns non-nil, the operations have their usual meaning. </p><p>If either operand is a table with an appropriate <a href="#Metatables">metamethod</a>, the metamethod will be called. </p> <table class="wikitable" style="text-align:center"> <tbody><tr> <th>Operator</th> <th>Function</th> <th>Example</th> <th>Metamethod</th> <th>Notes </th></tr> <tr> <td>+</td> <td>Addition</td> <td>a + b</td> <td>__add</td> <td> </td></tr> <tr> <td>-</td> <td>Subtraction</td> <td>a - b</td> <td>__sub</td> <td> </td></tr> <tr> <td>*</td> <td>Multiplication</td> <td>a * b</td> <td>__mul</td> <td> </td></tr> <tr> <td>/</td> <td>Division</td> <td>a / b</td> <td>__div</td> <td>division by zero is not an error; NaN or infinity will be returned </td></tr> <tr> <td>%</td> <td>Modulo</td> <td>a&#160;% b</td> <td>__mod</td> <td>defined as <code style="white-space:nowrap">a&#160;% b == a - math.floor( a / b ) * b</code> </td></tr> <tr> <td>^</td> <td>Exponentiation</td> <td>a ^ b</td> <td>__pow</td> <td>non-integer exponents are allowed </td></tr> <tr> <td>-</td> <td>Negation</td> <td>-a</td> <td>__unm</td> <td> </td></tr></tbody></table> <div class="mw-heading mw-heading4"><h4 id="Relational_operators">Relational operators</h4></div> <p>The relational operators in Lua are <code>==</code>, <code>~=</code>, <code>&lt;</code>, <code>&gt;</code>, <code>&lt;=</code>, and <code>&gt;=</code>. The result of a relational operator is always a boolean. </p><p>Equality (<code>==</code>) first compares the types of its operands; if they are different, the result is false. Then it compares the values: nil, boolean, number, and string are compared in the expected manner. Functions are equal if they refer to the exact same function object; <code style="white-space:nowrap">function() end == function() end</code> will return false, as it is comparing two different anonymous functions. Tables are by default compared in the same manner, but this may be changed using the __eq <a href="#Metatables">metamethod</a>. </p><p>Inequality (<code>~=</code>) is the exact negation of equality. </p><p>For the ordering operators, if both are numbers or both are strings, they are compared directly. Next, metamethods are checked: </p> <ul><li><code style="white-space:nowrap">a &lt; b</code> uses <code>__lt</code></li> <li><code style="white-space:nowrap">a &lt;= b</code> uses <code>__le</code> if available, or if <code>__lt</code> is available then it is considered equivalent to <code style="white-space:nowrap">not ( b &lt; a )</code></li> <li><code style="white-space:nowrap">a &gt; b</code> is considered equivalent to <code style="white-space:nowrap">b &lt; a</code></li> <li><code style="white-space:nowrap">a &gt;= b</code> is considered equivalent to <code style="white-space:nowrap">b &lt;= a</code></li></ul> <p>If the necessary metamethods are not available, an error is raised. </p> <div class="mw-heading mw-heading4"><h4 id="Logical_operators">Logical operators</h4></div> <p>The logical operators are <code>and</code>, <code>or</code>, and <code>not</code>. All use the standard interpretation where nil and false are considered false and anything else is considered true. </p><p>For <code>and</code>, if the left operand is considered false then it is returned and the second operand is not evaluated; otherwise the second operand is returned. </p><p>For <code>or</code>, if the left operand is considered true then it is returned and the second operand is not evaluated; otherwise the second operand is returned. </p><p>For <code>not</code>, the result is always true or false. </p><p>Note that <code>and</code> and <code>or</code> short circuit. For example, <code style="white-space:nowrap">foo() or bar()</code> will only call <code>bar()</code> if <code>foo()</code> returns false or nil as its first value. </p> <div class="mw-heading mw-heading4"><h4 id="Concatenation_operator">Concatenation operator</h4></div> <p>The concatenation operator is two dots, used as <code style="white-space:nowrap">a .. b</code>. If both operands are numbers or strings, they are converted to strings and concatenated. Otherwise if a __concat <a href="#Metatables">metamethod</a> is available, it is used. Otherwise, an error is raised. </p><p>Note that Lua strings are immutable and Lua does not provide any sort of "string builder", so a loop that repeatedly does <code style="white-space:nowrap">a = a .. b</code> will have to create a new string for each iteration and eventually garbage-collect the old strings. If many strings need concatenating, it may be faster to use <a href="#string.format">string.format()</a> or to insert all the strings into a <a href="#sequence">sequence</a> and use <a href="#table.concat">table.concat()</a> at the end. </p> <div class="mw-heading mw-heading4"><h4 id="Length_operator">Length operator</h4></div> <p>The length operator is <code>#</code>, used as <code>#a</code>. If <code>a</code> is a string, it returns the length in bytes. If <code>a</code> is a <a href="#sequence">sequence</a> table, it returns the length of the sequence. </p><p>If <code>a</code> is a table that is <i>not</i> a sequence, the <code>#a</code> may return 0 or any value N such that <code>a[N]</code> is not nil and <code>a[N+1]</code> is nil, even if there are non-nil values at higher indexes. For example, </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">-- This is not a sequence, because a[3] is nil and a[4] is not.</span> <span class="n">a</span> <span class="o">=</span> <span class="p">{</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="kc">nil</span><span class="p">,</span> <span class="mi">4</span> <span class="p">}</span> <span class="c1">-- This may output either 2 or 4.</span> <span class="c1">-- And this may change even if the table is not modified.</span> <span class="n">mw</span><span class="p">.</span><span class="n">log</span><span class="p">(</span> <span class="o">#</span><span class="n">a</span> <span class="p">)</span> </pre></div> <div class="mw-heading mw-heading4"><h4 id="Operator_precedence">Operator precedence</h4></div> <p>Lua's operator precedence or <a href="https://en.wikipedia.org/wiki/order_of_operations" class="extiw" title="w:order of operations">order of operations</a>, from highest to lowest: </p> <ol><li><code>^</code></li> <li><code>not</code> <code>#</code> <code>-</code> (negation)</li> <li><code>*</code> <code>/</code> <code>%</code></li> <li><code>+</code> <code>-</code> (subtraction)</li> <li><code>..</code></li> <li><code>&lt;</code> <code>&gt;</code> <code>&lt;=</code> <code>&gt;=</code> <code>~=</code> <code>==</code></li> <li><code>and</code></li> <li><code>or</code></li></ol> <p>Within a precedence level, most binary operators are left-associative, i.e. <code style="white-space:nowrap">a / b / c</code> is interpreted as <code style="white-space:nowrap">(a / b) / c</code>. Exponentiation and concatenation are right-associative, i.e. <code style="white-space:nowrap">a ^ b ^ c</code> is interpreted as <code style="white-space:nowrap">a ^ (b ^ c)</code>. </p> <div class="mw-heading mw-heading4"><h4 id="Function_calls">Function calls</h4></div> <p>Lua function calls look like those in most other languages: a name followed by a list of arguments in parentheses: </p> <pre>func( <a href="#expression-list"><i>expression-list</i></a> ) </pre> <p>As is usual with expression lists in Lua, the last expression in the list may supply multiple argument values. </p><p>If the function is called with fewer values in the expression list than there are arguments in the function definition, the extra arguments will have a nil value. If the expression list contains more values than there are arguments, the excess values are discarded. It is also possible for a function to take a variable number of arguments; see <a href="#Function_declarations">Function declarations</a> for details. </p><p>Lua also allows direct calling of a function return value, i.e. <code>func()()</code>. If an expression more complex than a variable access is needed to determine the function to be called, a parenthesized expression may be used in place of the variable access. </p><p>Lua has syntactic sugar for two common cases. The first is when a table is being used as an object, and the function is to be called as a method on the object. The syntax </p> <pre>table:name( <a href="#expression-list"><i>expression-list</i></a> ) </pre> <p>is exactly equivalent to </p> <pre>table.name( table, <a href="#expression-list"><i>expression-list</i></a> ) </pre> <p><span class="anchor" id="named_arguments"></span> The second common case is Lua's method of implementing <i>named arguments</i> by passing a table containing the name-to-value mappings as the only positional argument to the function. In this case, the parentheses around the argument list may be omitted. This also works if the function is to be passed a single literal string. For example, the calls </p> <pre style="white-space:pre-wrap">func{ arg1 = <i>exp</i>, arg2 = <i>exp</i> } func"string"</pre> <p>are equivalent to </p> <pre style="white-space:pre-wrap">func( { arg1 = <i>exp</i>, arg2 = <i>exp</i> } ) func( "string" )</pre> <p>These may be combined; the following calls are equivalent: </p> <pre style="white-space:pre-wrap">table:name{ arg1 = <i>exp</i>, arg2 = <i>exp</i> } table.name( table, { arg1 = <i>exp</i>, arg2 = <i>exp</i> } )</pre> <div class="mw-heading mw-heading4"><h4 id="Function_declarations">Function declarations</h4></div> <p>The syntax for function declaration looks like this: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"> <pre><span class="kr">function</span> <span class="nf"><i>name</i><sub>optional</sub></span> <span class="p">(</span> <span class="nf"><i>var-list</i><sub>optional</sub></span> <span class="p">)</span> <a href="#block"><span class="nf"><i>block</i></span></a> <span class="kr">end</span> </pre> </div> <p>All variables in <i>var-list</i> are local to the function, with values assigned from the expression list in the <a href="#Function_calls">function call</a>. Additional local variables may be declared inside the block. </p><p>When the function is called, the statements in <i>block</i> are executed after local variables corresponding to <i>var-list</i> are created and assigned values. If a <a href="#return">return statement</a> is reached, the block is exited and the values of the function call expression are those given by the return statement. If execution reaches the end of the function's block without encountering a return statement, the result of the function call expression has zero values. </p><p>Lua functions are <a href="https://en.wikipedia.org/wiki/Closure_(computer_science)" class="extiw" title="w:Closure (computer science)">lexical closures</a>. A common idiom is to declare "private static" variables as locals in the scope where the function is declared. For example, </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">-- This returns a function that adds a number to its argument</span> <span class="kr">function</span> <span class="nf">makeAdder</span><span class="p">(</span> <span class="n">n</span> <span class="p">)</span> <span class="kr">return</span> <span class="kr">function</span><span class="p">(</span> <span class="n">x</span> <span class="p">)</span> <span class="c1">-- The variable n from the outer scope is available here to be added to x</span> <span class="kr">return</span> <span class="n">x</span> <span class="o">+</span> <span class="n">n</span> <span class="kr">end</span> <span class="kr">end</span> <span class="kd">local</span> <span class="n">add5</span> <span class="o">=</span> <span class="n">makeAdder</span><span class="p">(</span> <span class="mi">5</span> <span class="p">)</span> <span class="n">mw</span><span class="p">.</span><span class="n">log</span><span class="p">(</span> <span class="n">add5</span><span class="p">(</span> <span class="mi">6</span> <span class="p">)</span> <span class="p">)</span> <span class="c1">-- prints 11</span> </pre></div> <p><span class="anchor" id="varargs"></span> A function may be declared to accept a variable number of arguments, by specifying <code>...</code> as the final item in the <i>var-list</i>: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"> <pre><span class="kr">function</span> <span class="nf"><i>name</i><sub>optional</sub></span> <span class="p">(</span> <span class="nf"><i>var-list</i></span><span class="p">,</span> <span class="p">...</span> <span class="p">)</span> <a href="#block"><span class="nf"><i>block</i></span></a> <span class="kr">end</span> <span class="c1">-- or</span> <span class="kr">function</span> <span class="nf"><i>name</i><sub>optional</sub></span> <span class="p">(</span> <span class="p">...</span> <span class="p">)</span> <a href="#block"><span class="nf"><i>block</i></span></a> <span class="kr">end</span> </pre> </div> <p>Within the block, the varargs expression <code>...</code> may be used, with the result being all the extra values in the function call. For example, </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="kd">local</span> <span class="n">join</span> <span class="o">=</span> <span class="kr">function</span> <span class="p">(</span> <span class="n">separator</span><span class="p">,</span> <span class="p">...</span> <span class="p">)</span> <span class="c1">-- get the extra arguments as a new table</span> <span class="kd">local</span> <span class="n">args</span> <span class="o">=</span> <span class="p">{</span> <span class="p">...</span> <span class="p">}</span> <span class="c1">-- get the count of extra arguments, correctly</span> <span class="kd">local</span> <span class="n">n</span> <span class="o">=</span> <span class="nb">select</span><span class="p">(</span> <span class="s1">&#39;#&#39;</span><span class="p">,</span> <span class="p">...</span> <span class="p">)</span> <span class="kr">return</span> <span class="nb">table.concat</span><span class="p">(</span> <span class="n">args</span><span class="p">,</span> <span class="n">separator</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">n</span> <span class="p">)</span> <span class="kr">end</span> <span class="n">join</span><span class="p">(</span> <span class="s1">&#39;, &#39;</span><span class="p">,</span> <span class="s1">&#39;foo&#39;</span><span class="p">,</span> <span class="s1">&#39;bar&#39;</span><span class="p">,</span> <span class="s1">&#39;baz&#39;</span> <span class="p">)</span> <span class="c1">-- returns the string &quot;foo, bar, baz&quot;</span> </pre></div> <p>The <a href="#select">select()</a> function is designed to work with the varargs expression; in particular, <code style="white-space:nowrap">select( '#', ... )</code> should be used instead of <code style="white-space:nowrap">#{ ... }</code> to count the number of values in the varargs expression, because <code style="white-space:nowrap">{ ... }</code> may not be a <a href="#sequence">sequence</a>. </p><p>Lua provides syntactic sugar to combine function declaration and assignment to a variable; see <a href="#Function_declaration_statements">Function declaration statements</a> for details. </p><p>Note that this will not work: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"> <pre><span class="kr">local</span> <span class="nf">factorial</span> <span class="o">=</span> <span class="kr">function</span> <span class="p">(</span> <span class="n">n</span> <span class="p">)</span> <span class="kr">if</span> <span class="n">n</span> <span class="o">&lt;=</span> <span class="mi">2</span> <span class="kr">then</span> <span class="kr">return</span> <span class="n">n</span> <span class="kr">else</span> <span class="kr">return</span> <span class="n">n</span> <span class="o">*</span> <span class="nf"><s>factorial</s></span><span class="p">(</span> <span class="n">n</span> <span class="o">-</span> <span class="mi">1</span> <span class="p">)</span> <span class="kr">end</span> <span class="kr">end</span> </pre> </div> <p>Since the function declaration is processed before the local variable assignment statement is complete, "factorial" inside the function body refers to the (probably undefined) variable of that name in an outer scope. This problem may be avoided by declaring the local variable first and then assigning it in a subsequent statement, or by using the <a href="#Function_declaration_statements">function declaration statement</a> syntax. </p> <div class="mw-heading mw-heading3"><h3 id="Statements">Statements</h3></div> <p>A <i>statement</i> is the basic unit of execution: one assignment, control structure, function call, variable declaration, etc. </p><p><span class="anchor" id="chunk"></span> A <i>chunk</i> is a sequence of statements, optionally separated by semicolons. A chunk is basically considered the body of an anonymous function, so it can declare local variables, receive arguments, and return values. </p><p><span class="anchor" id="block"></span> A <i>block</i> is also a sequence of statements, just like a chunk. A block can be delimited to create a single statement: <code style="white-space:nowrap">do <i>block</i> end</code>. These may be used to limit the scope of local variables, or to add a <code>return</code> or <code>break</code> in the middle of another block. </p> <div class="mw-heading mw-heading4"><h4 id="Assignments">Assignments</h4></div> <p><code style="white-space:nowrap"><i>variable-list</i> = <a href="#expression-list"><i>expression-list</i></a></code> </p><p>The <i>variable-list</i> is a comma-separated list of variables; the <i>expression-list</i> is a comma-separated list of one or more expressions. All expressions are evaluated before any assignments are performed, so <code style="white-space:nowrap">a, b = b, a</code> will swap the values of <var>a</var> and <var>b</var>. </p> <div class="mw-heading mw-heading4"><h4 id="Local_variable_declarations">Local variable declarations</h4></div> <p><code style="white-space:nowrap">local <i>variable-list</i></code> </p><p><code style="white-space:nowrap">local <i>variable-list</i> = <a href="#expression-list"><i>expression-list</i></a></code> </p><p>Local variables may be declared anywhere within a <a href="#block">block</a> or <a href="#block">chunk</a>. The first form, without an expression list, declares the variables but does not assign a value so all variables have nil as a value. The second form assigns values to the local variables, as described in <a href="#Assignments">Assignments</a> above. </p><p>Note that visibility of the local variable begins with the statement after the local variable declaration. So a declaration like <code style="white-space:nowrap">local x = x</code> declares a local variable x and assigns it the value of x from the outer scope. The local variable remains in scope until the end of the innermost block containing the local variable declaration. </p> <div class="mw-heading mw-heading4"><h4 id="Control_structures">Control structures</h4></div> <p><span class="anchor" id="while"></span> <code style="white-space:nowrap">while <i>exp</i> do <i><a href="#block">block</a></i> end</code> </p><p>The while statement repeats a block as long as an expression evaluates to a true value. </p><p><span class="anchor" id="repeat"></span> <code style="white-space:nowrap">repeat <i><a href="#block">block</a></i> until <i>exp</i></code> </p><p>The repeat statement repeats a block until an expression evaluates to a true value. Local variables declared inside the block may be accessed in the expression. </p><p><span class="anchor" id="for"></span> <code style="white-space:nowrap">for <i>name</i> = <i>exp1</i>, <i>exp2</i>, <i>exp3</i> do <i><a href="#block">block</a></i> end</code><br /> <code style="white-space:nowrap">for <i>name</i> = <i>exp1</i>, <i>exp2</i> do <i><a href="#block">block</a></i> end</code> </p><p>This first form of the for loop will declare a local variable, and repeat the block for values from <i>exp1</i> to <i>exp2</i> adding <i>exp3</i> on each iteration. Note that <i>exp3</i> may be omitted entirely, in which case 1 is used, but non-numeric values such as <code>nil</code> and <code>false</code> are an error. All expressions are evaluated once before the loop is started. </p><p>This form of the for loop is roughly equivalent to </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="kr">do</span> <span class="kd">local</span> <span class="n">var</span><span class="p">,</span> <span class="n">limit</span><span class="p">,</span> <span class="n">step</span> <span class="o">=</span> <span class="nb">tonumber</span><span class="p">(</span> <span class="n">exp1</span> <span class="p">),</span> <span class="nb">tonumber</span><span class="p">(</span> <span class="n">exp2</span> <span class="p">),</span> <span class="nb">tonumber</span><span class="p">(</span> <span class="n">exp3</span> <span class="p">)</span> <span class="kr">if</span> <span class="ow">not</span> <span class="p">(</span> <span class="n">var</span> <span class="ow">and</span> <span class="n">limit</span> <span class="ow">and</span> <span class="n">step</span> <span class="p">)</span> <span class="kr">then</span> <span class="nb">error</span><span class="p">()</span> <span class="kr">end</span> <span class="kr">while</span> <span class="p">(</span> <span class="n">step</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">var</span> <span class="o">&lt;=</span> <span class="n">limit</span> <span class="p">)</span> <span class="ow">or</span> <span class="p">(</span> <span class="n">step</span> <span class="o">&lt;=</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">var</span> <span class="o">&gt;=</span> <span class="n">limit</span> <span class="p">)</span> <span class="kr">do</span> <span class="kd">local</span> <span class="n">name</span> <span class="o">=</span> <span class="n">var</span> <span class="n">block</span> <span class="n">var</span> <span class="o">=</span> <span class="n">var</span> <span class="o">+</span> <span class="n">step</span> <span class="kr">end</span> <span class="kr">end</span> </pre></div> <p>except that the variables var, limit, and step are not accessible anywhere else. Note that the variable <i>name</i> is local to the block; to use the value after the loop, it must be copied to a variable declared outside the loop. </p><p><span class="anchor" id="iterators"></span> <code style="white-space:nowrap">for <i>var-list</i> in <a href="#expression-list"><i>expression-list</i></a> do <i><a href="#block">block</a></i> end</code> </p><p>The second form of the for loop works with <i>iterator</i> functions. As in the first form, the <i>expression-list</i> is evaluated only once before beginning the loop. </p><p>This form of the for loop is roughly equivalent to </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="kr">do</span> <span class="kd">local</span> <span class="n">func</span><span class="p">,</span> <span class="n">static</span><span class="p">,</span> <span class="n">var</span> <span class="o">=</span> <span class="n">expression</span><span class="o">-</span><span class="n">list</span> <span class="kr">while</span> <span class="kc">true</span> <span class="kr">do</span> <span class="kd">local</span> <span class="n">var</span><span class="o">-</span><span class="n">list</span> <span class="o">=</span> <span class="n">func</span><span class="p">(</span> <span class="n">static</span><span class="p">,</span> <span class="n">var</span> <span class="p">)</span> <span class="n">var</span> <span class="o">=</span> <span class="n">var1</span> <span class="c1">-- &#39;&#39;var1&#39;&#39; is the first variable in &#39;&#39;var-list&#39;&#39;</span> <span class="kr">if</span> <span class="n">var</span> <span class="o">==</span> <span class="kc">nil</span> <span class="kr">then</span> <span class="kr">break</span> <span class="kr">end</span> <span class="n">block</span> <span class="kr">end</span> <span class="kr">end</span> </pre></div> <p>except that again the variables func, static, and var are not accessible anywhere else. Note that the variables in <i>var-list</i> are local to the block; to use them after the loop, they must be copied to variables declared outside the loop. </p><p>Often the <i>expression-list</i> is a single function call that returns the three values. If the iterator function can be written so it only depends on the parameters passed into it, that would be the most efficient. If not, <a rel="nofollow" class="external text" href="https://www.lua.org/pil/7.4.html">Programming in Lua</a> suggests that a closure be preferred to returning a table as the static variable and updating its members on each iteration. </p><p><span class="anchor" id="if"></span> <code style="white-space:nowrap">if <i>exp1</i> then <i><a href="#block">block1</a></i> elseif <i>exp2</i> then <i><a href="#block">block2</a></i> else <i><a href="#block">block3</a></i> end</code> </p><p>Executes <i>block1</i> if <i>exp1</i> returns true, otherwise executes <i>block2</i> if <i>exp2</i> returns true, and <i>block3</i> otherwise. The <code style="white-space:nowrap">else <i>block3</i></code> portion may be omitted, and the <code style="white-space:nowrap">elseif <i>exp2</i> then <i>block2</i></code> portion may be repeated or omitted as necessary. </p><p><span class="anchor" id="return"></span> <code style="white-space:nowrap">return <a href="#expression-list"><i>expression-list</i></a></code> </p><p>The return statement is used to return values from a function or a <a href="#chunk">chunk</a> (which is just a function). The <i>expression-list</i> is a comma-separated list of zero or more expressions. </p><p>Lua implements <a href="https://en.wikipedia.org/wiki/tail_call" class="extiw" title="w:tail call">tail calls</a>: if <i>expression-list</i> consists of exactly one expression which is a function call, the current stack frame will be reused for the call to that function. This has implication for functions that deal with the call stack, such as <code><a href="#getfenv">getfenv()</a></code> and <code><a href="#debug.traceback">debug.traceback()</a></code>. </p><p>The return statement must be the last statement in its <a href="#block">block</a>. If for some reason a return is needed in the middle of a block, an explicit block <code style="white-space:nowrap">do return end</code> may be used. </p><p><span class="anchor" id="break"></span> <code>break</code> </p><p>The break statement is used to terminate the execution of a while, repeat, or for loop, skipping to the next statement after the loop. </p><p>The break statement must be the last statement in its <a href="#block">block</a>. If for some reason a break is needed in the middle of a block, an explicit block <code style="white-space:nowrap">do break end</code> may be used. </p><p>Unlike some other languages, Lua does not have a "continue" statement for loops (i.e. a statement to move onto the next iteration without breaking the loop altogether). It is straightforward to achieve the same effect by nesting a <code style="white-space:nowrap">repeat ... until true</code> block immediately inside the main loop, which will only ever iterate once for each iteration of the main loop (as its condition is always true). Using <code style="white-space:nowrap">break</code> will only end the inner loop, which has the practical effect of causing the main loop to continue onto the next iteration. If it is necessary to use <code style="white-space:nowrap">break</code> on the main loop, simply declare a variable which is checked each time the inner loop completes, and set it when necessary. </p> <div class="mw-heading mw-heading4"><h4 id="Function_calls_as_statements">Function calls as statements</h4></div> <p>A function call may be used as a statement; in this case, the function is being called only for any side effects it may have (e.g. <a href="#mw.log">mw.log()</a> logs values) and any return values are discarded. </p> <div class="mw-heading mw-heading4"><h4 id="Function_declaration_statements">Function declaration statements</h4></div> <p>Lua provides syntactic sugar to make declaring a function and assigning it to a variable more natural. The following pairs of declarations are equivalent </p> <pre>-- Basic declaration function func( <i>var-list</i> ) <i><a href="#block">block</a></i> end func = function ( <i>var-list</i> ) <i><a href="#block">block</a></i> end </pre> <pre>-- Local function local function func( <i>var-list</i> ) <i><a href="#block">block</a></i> end local func; func = function ( <i>var-list</i> ) <i><a href="#block">block</a></i> end </pre> <pre>-- Function as a field in a table function table.func( <i>var-list</i> ) <i><a href="#block">block</a></i> end table.func = function ( <i>var-list</i> ) <i><a href="#block">block</a></i> end </pre> <pre>-- Function as a method in a table function table:func( <i>var-list</i> ) <i><a href="#block">block</a></i> end table.func = function ( self, <i>var-list</i> ) <i><a href="#block">block</a></i> end </pre> <p>Note the colon notation here parallels the colon notation for <a href="#Function_calls">function calls</a>, adding an implicit argument named <code>self</code> at the beginning of the arguments list. </p> <div class="mw-heading mw-heading3"><h3 id="Error_handling">Error handling</h3></div> <p>Errors may be "thrown" using the <a href="#error">error()</a> and <a href="#assert">assert()</a> functions. To "catch" errors, use <a href="#pcall">pcall()</a> or <a href="#xpcall">xpcall()</a>. Note that certain internal Scribunto errors cannot be caught in Lua code. </p> <div class="mw-heading mw-heading3"><h3 id="Garbage_collection">Garbage collection</h3></div> <p>Lua performs automatic memory management. This means that you have to worry neither about allocating memory for new objects nor about freeing it when the objects are no longer needed. Lua manages memory automatically by running a <i>garbage collector</i> from time to time to collect all dead objects (that is, objects that are no longer accessible from Lua) and objects that are only reachable via <a href="#weak_tables">weak references</a>. All memory used by Lua is subject to automatic management: tables, functions, strings, etc. </p><p>Garbage collection happens automatically, and cannot be configured from within Scribunto. </p> <div class="mw-heading mw-heading2"><h2 id="Standard_libraries">Standard libraries</h2></div> <p>The standard Lua libraries provide essential services and performance-critical functions to Lua. Only those portions of the standard libraries that are available in Scribunto are documented here. </p> <div class="mw-heading mw-heading3"><h3 id="Basic_functions">Basic functions</h3></div> <div class="mw-heading mw-heading4"><h4 id="G">_G</h4></div> <p><span id="_G"></span> </p><p>This variable holds a reference to the current global variable table; the global variable <code>foo</code> may also be accessed as <code>_G.foo</code>. Note, however, that there is nothing special about _G itself; it may be reassigned in the same manner as any other variable: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="n">foo</span> <span class="o">=</span> <span class="mi">1</span> <span class="n">mw</span><span class="p">.</span><span class="n">log</span><span class="p">(</span> <span class="n">foo</span> <span class="p">)</span> <span class="c1">-- logs &quot;1&quot;</span> <span class="n">_G</span><span class="p">.</span><span class="n">foo</span> <span class="o">=</span> <span class="mi">2</span> <span class="n">mw</span><span class="p">.</span><span class="n">log</span><span class="p">(</span> <span class="n">foo</span> <span class="p">)</span> <span class="c1">-- logs &quot;2&quot;</span> <span class="nb">_G</span> <span class="o">=</span> <span class="p">{}</span> <span class="c1">-- _G no longer points to the global variable table</span> <span class="n">_G</span><span class="p">.</span><span class="n">foo</span> <span class="o">=</span> <span class="mi">3</span> <span class="n">mw</span><span class="p">.</span><span class="n">log</span><span class="p">(</span> <span class="n">foo</span> <span class="p">)</span> <span class="c1">-- still logs &quot;2&quot;</span> </pre></div> <p>The global variable table may be used just like any other table. For example, </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">-- Call a function whose name is stored in a variable</span> <span class="nb">_G</span><span class="p">[</span><span class="n">var</span><span class="p">]()</span> <span class="c1">-- Log the names and stringified values of all global variables</span> <span class="kr">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="kr">in</span> <span class="nb">pairs</span><span class="p">(</span> <span class="nb">_G</span> <span class="p">)</span> <span class="kr">do</span> <span class="n">mw</span><span class="p">.</span><span class="n">log</span><span class="p">(</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="p">)</span> <span class="kr">end</span> <span class="c1">-- Log the creation of new global variables</span> <span class="nb">setmetatable</span><span class="p">(</span> <span class="nb">_G</span><span class="p">,</span> <span class="p">{</span> <span class="n">__newindex</span> <span class="o">=</span> <span class="kr">function</span> <span class="p">(</span> <span class="n">t</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="p">)</span> <span class="n">mw</span><span class="p">.</span><span class="n">log</span><span class="p">(</span> <span class="s2">&quot;Creation of new global variable &#39;&quot;</span> <span class="o">..</span> <span class="n">k</span> <span class="o">..</span> <span class="s2">&quot;&#39;&quot;</span> <span class="p">)</span> <span class="nb">rawset</span><span class="p">(</span> <span class="n">t</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="p">)</span> <span class="kr">end</span> <span class="p">}</span> <span class="p">)</span> </pre></div> <div class="mw-heading mw-heading4"><h4 id="VERSION">_VERSION</h4></div> <p><span id="_VERSION"></span> </p><p>A string containing the running version of Lua, e.g. "Lua 5.1". </p> <div class="mw-heading mw-heading4"><h4 id="assert">assert</h4></div> <p><code style="white-space:nowrap">assert( v, message, ... )</code> </p><p>If <code>v</code> is nil or false, issues an error. In this case, <code>message</code> is used as the text of the error: if nil (or unspecified), the text is "assertion failed!"; if a string or number, the text is that value; otherwise assert itself will raise an error. </p><p>If <code>v</code> is any other value, assert returns all arguments including <code>v</code> and <code>message</code>. </p><p>A somewhat common idiom in Lua is for a function to return a "true" value in normal operation, and on failure return nil or false as the first value and an error message as the second value. Easy error checking can then be implemented by wrapping the call in a call to <code>assert</code>: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">-- This doesn&#39;t check for errors</span> <span class="kd">local</span> <span class="n">result1</span><span class="p">,</span> <span class="n">result2</span><span class="p">,</span> <span class="n">etc</span> <span class="o">=</span> <span class="n">func</span><span class="p">(</span> <span class="p">...</span> <span class="p">)</span> <span class="c1">-- This works the same, but does check for errors</span> <span class="kd">local</span> <span class="n">result1</span><span class="p">,</span> <span class="n">result2</span><span class="p">,</span> <span class="n">etc</span> <span class="o">=</span> <span class="nb">assert</span><span class="p">(</span> <span class="n">func</span><span class="p">(</span> <span class="p">...</span> <span class="p">)</span> <span class="p">)</span> </pre></div> <div class="mw-heading mw-heading4"><h4 id="error">error</h4></div> <p><code style="white-space:nowrap">error( message, level )</code> </p><p>Issues an error, with text <code>message</code>. </p><p><code>error</code> normally adds some information about the location of the error. If <code>level</code> is 1 or omitted, that information is the location of the call to <code>error</code> itself; 2 uses the location of the call of the function that called error; and so on. Passing 0 omits inclusion of the location information. </p> <div class="mw-heading mw-heading4"><h4 id="getfenv">getfenv</h4></div> <p><code style="white-space:nowrap">getfenv( f )</code> </p><p>Note this function may not be available, depending on <code>allowEnvFuncs</code> in the engine configuration. </p><p>Returns an <i>environment</i> (global variable table), as specified by <code>f</code>: </p> <ul><li>If 1, nil, or omitted, returns the environment of the function calling <code>getfenv</code>. Often this will be the same as <a href="#_G">_G</a>.</li> <li>Integers 2–10 return the environment of functions higher in the call stack. For example, 2 returns the environment for the function that called the current function, 3 returns the environment for the function calling that function, and so on. An error will be raised if the value is higher than the number of function calls in the stack, or if the targeted stack level returned with a tail call.</li> <li>Passing a function returns the environment that will be used when that function is called.</li></ul> <p>The environments used by all standard library functions and Scribunto library functions are protected. Attempting to access these environments using <code>getfenv</code> will return nil instead. </p> <div class="mw-heading mw-heading4"><h4 id="getmetatable">getmetatable</h4></div> <p><code style="white-space:nowrap">getmetatable( table )</code> </p><p>Returns the <a href="#Metatables">metatable</a> of a <a href="#table">table</a>. Any other type will return nil. </p><p>If the metatable has a <code>__metatable</code> field, that value will be returned instead of the actual metatable. </p> <div class="mw-heading mw-heading4"><h4 id="ipairs">ipairs</h4></div> <p><code style="white-space:nowrap">ipairs( t )</code> </p><p>Returns three values: an iterator function, the table <code>t</code>, and 0. This is intended for use in the <a href="#iterators">iterator form of <code>for</code></a>: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="kr">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">v</span> <span class="kr">in</span> <span class="nb">ipairs</span><span class="p">(</span> <span class="n">t</span> <span class="p">)</span> <span class="kr">do</span> <span class="c1">-- process each index-value pair</span> <span class="kr">end</span> </pre></div> <p>This will iterate over the pairs ( 1, t[1] ), ( 2, t[2] ), and so on, stopping when t[i] would be nil. </p><p>The standard behavior may be overridden by providing an <code>__ipairs</code> <a href="#Metatables">metamethod</a>. If that metamethod exists, the call to ipairs will return the three values returned by <code style="white-space:nowrap">__ipairs( t )</code> instead. </p> <div class="mw-heading mw-heading4"><h4 id="next">next</h4></div> <p><code style="white-space:nowrap">next( table, key )</code> </p><p>This allows for iterating over the keys in a table. If <code>key</code> is nil or unspecified, returns the "first" key in the table and its value; otherwise, it returns the "next" key and its value. When no more keys are available, returns nil. It is possible to check whether a table is empty using the expression <code style="white-space:nowrap">next( t ) == nil</code>. </p><p>Note that the order in which the keys are returned is not specified, even for tables with numeric indexes. To traverse a table in numerical order, use a <a href="#for">numerical for</a> or <a href="#ipairs">ipairs</a>. </p><p>Behavior is undefined if, when using next for traversal, any non-existing key is assigned a value. Assigning a new value (including nil) to an existing field is allowed. </p> <div class="mw-heading mw-heading4"><h4 id="pairs">pairs</h4></div> <p><code style="white-space:nowrap">pairs( t )</code> </p><p>Returns three values: an iterator function (<a href="#next">next</a> or a work-alike), the table <code>t</code>, and nil. This is intended for use in the <a href="#iterators">iterator form of <code>for</code></a>: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="kr">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="kr">in</span> <span class="nb">pairs</span><span class="p">(</span> <span class="n">t</span> <span class="p">)</span> <span class="kr">do</span> <span class="c1">-- process each key-value pair</span> <span class="kr">end</span> </pre></div> <p>This will iterate over the key-value pairs in <code>t</code> just as <a href="#next">next</a> would; see the documentation for <a href="#next">next</a> for restrictions on modifying the table during traversal. </p><p>The standard behavior may be overridden by providing a __pairs <a href="#Metatables">metamethod</a>. If that metamethod exists, the call to pairs will return the three values returned by <code style="white-space:nowrap">__pairs( t )</code> instead. </p> <div class="mw-heading mw-heading4"><h4 id="pcall">pcall</h4></div> <p><code style="white-space:nowrap">pcall( f, ... )</code> </p><p>Calls the function <code>f</code> with the given arguments in <i>protected mode</i>. This means that if an error is raised during the call to <code>f</code>, pcall will return false and the error message raised. If no error occurs, pcall will return true and all values returned by the call. </p><p>In <a href="https://en.wikipedia.org/wiki/pseudocode" class="extiw" title="w:pseudocode">pseudocode</a>, <code>pcall</code> might be defined something like this: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="kr">function</span> <span class="nf">pcall</span><span class="p">(</span> <span class="n">f</span><span class="p">,</span> <span class="p">...</span> <span class="p">)</span> <span class="n">try</span> <span class="kr">return</span> <span class="kc">true</span><span class="p">,</span> <span class="n">f</span><span class="p">(</span> <span class="p">...</span> <span class="p">)</span> <span class="n">catch</span> <span class="p">(</span> <span class="n">message</span> <span class="p">)</span> <span class="kr">return</span> <span class="kc">false</span><span class="p">,</span> <span class="n">message</span> <span class="kr">end</span> <span class="kr">end</span> </pre></div> <div class="mw-heading mw-heading4"><h4 id="rawequal">rawequal</h4></div> <p><code style="white-space:nowrap">rawequal( a, b )</code> </p><p>This is equivalent to <code style="white-space:nowrap">a == b</code> except that it ignores any __eq <a href="#Metatables">metamethod</a>. </p> <div class="mw-heading mw-heading4"><h4 id="rawget">rawget</h4></div> <p><code style="white-space:nowrap">rawget( table, k )</code> </p><p>This is equivalent to <code>table[k]</code> except that it ignores any __index <a href="#Metatables">metamethod</a>. </p> <div class="mw-heading mw-heading4"><h4 id="rawset">rawset</h4></div> <p><code style="white-space:nowrap">rawset( table, k, v )</code> </p><p>This is equivalent to <code style="white-space:nowrap">table[k] = v</code> except that it ignores any __newindex <a href="#Metatables">metamethod</a>. </p> <div class="mw-heading mw-heading4"><h4 id="select">select</h4></div> <p><code style="white-space:nowrap">select( index, ... )</code> </p><p>If <code>index</code> is a number, returns all arguments in <code>...</code> from that index onwards. If <code>index</code> is the string <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="s2">&quot;#&quot;</span></code>, returns the number of arguments in <code>...</code>. </p><p>Note: unlike tables, lists of arguments (including the <a href="#varargs">vararg expression</a> <code>...</code>) treat <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">nil</span></code> as a distinct value (see documentation for <a href="#Length_operator">#</a> and <a href="#unpack">unpack</a> for the problem with <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">nil</span></code> in tables). For example: </p> <ul><li><code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="nb">select</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="s2">&quot;foo&quot;</span><span class="p">,</span> <span class="s2">&quot;bar&quot;</span><span class="p">)</span></code> returns <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="s2">&quot;bar&quot;</span></code>.</li> <li><code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="nb">select</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="s2">&quot;foo&quot;</span><span class="p">,</span> <span class="kc">nil</span><span class="p">,</span> <span class="s2">&quot;bar&quot;</span><span class="p">,</span> <span class="kc">nil</span><span class="p">)</span></code> returns <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">nil</span><span class="p">,</span> <span class="s2">&quot;bar&quot;</span><span class="p">,</span> <span class="kc">nil</span></code>.</li> <li><code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="nb">select</span><span class="p">(</span><span class="s2">&quot;#&quot;</span><span class="p">,</span> <span class="s2">&quot;foo&quot;</span><span class="p">,</span> <span class="s2">&quot;bar&quot;</span><span class="p">)</span></code> returns <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="mi">2</span></code>.</li> <li><code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="nb">select</span><span class="p">(</span><span class="s2">&quot;#&quot;</span><span class="p">,</span> <span class="s2">&quot;foo&quot;</span><span class="p">,</span> <span class="s2">&quot;bar&quot;</span><span class="p">,</span> <span class="kc">nil</span><span class="p">)</span></code> returns <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="mi">3</span></code>.</li></ul> <p>In other words, <code>select</code> is roughly like the following (except that it also handles any <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">nil</span></code> arguments after the final non-nil argument): </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="kr">function</span> <span class="nf">select</span><span class="p">(</span> <span class="n">index</span><span class="p">,</span> <span class="p">...</span> <span class="p">)</span> <span class="kd">local</span> <span class="n">t</span> <span class="o">=</span> <span class="p">{</span> <span class="p">...</span> <span class="p">}</span> <span class="kd">local</span> <span class="n">maxindex</span> <span class="o">=</span> <span class="n">table</span><span class="p">.</span><span class="n">maxn</span><span class="p">(</span> <span class="n">t</span> <span class="p">)</span> <span class="kr">if</span> <span class="n">index</span> <span class="o">==</span> <span class="s2">&quot;#&quot;</span> <span class="kr">then</span> <span class="kr">return</span> <span class="n">maxindex</span> <span class="kr">else</span> <span class="kr">return</span> <span class="n">unpack</span><span class="p">(</span> <span class="n">t</span><span class="p">,</span> <span class="n">index</span><span class="p">,</span> <span class="n">maxindex</span> <span class="p">)</span> <span class="kr">end</span> <span class="kr">end</span> </pre></div> <div class="mw-heading mw-heading4"><h4 id="setmetatable">setmetatable</h4></div> <p><code style="white-space:nowrap">setmetatable( table, metatable )</code> </p><p>Sets the <a href="#Metatables">metatable</a> of a <a href="#table">table</a>. <code>metatable</code> may be nil, but must be explicitly provided. </p><p>If the current metatable has a __metatable field, <code>setmetatable</code> will throw an error. </p> <div class="mw-heading mw-heading4"><h4 id="tonumber">tonumber</h4></div> <p><code style="white-space:nowrap">tonumber( value, base )</code> </p><p>Tries to convert <code>value</code> to a number. If it is already a number or a string convertible to a number, then <code>tonumber</code> returns this number; otherwise, it returns nil. </p><p>The optional <code>base</code> (default 10) specifies the base to interpret the numeral. The base may be any integer between 2 and 36, inclusive. In bases above 10, the letter 'A' (in either upper or lower case) represents 10, 'B' represents 11, and so forth, with 'Z' representing 35. </p><p>In base 10, the value may have a decimal part, be expressed in <a href="https://en.wikipedia.org/wiki/E_notation" class="extiw" title="w:E notation">E notation</a>, and may have a leading "0x" to indicate base 16. In other bases, only unsigned integers are accepted. </p> <div class="mw-heading mw-heading4"><h4 id="tostring">tostring</h4></div> <p><code style="white-space:nowrap">tostring( value )</code> </p><p>Converts <code>value</code> to a string. See <a href="#Data_types">Data types</a> above for details on how each type is converted. </p><p>The standard behavior for tables may be overridden by providing a __tostring <a href="#Metatables">metamethod</a>. If that metamethod exists, the call to tostring will return the single value returned by <code style="white-space:nowrap">__tostring( value )</code> instead. </p> <div class="mw-heading mw-heading4"><h4 id="type">type</h4></div> <p><code style="white-space:nowrap">type( value )</code> </p><p>Returns the type of <code>value</code> as a string: <code>"<a href="#nil">nil</a>"</code>, <code>"<a href="#number">number</a>"</code>, <code>"<a href="#string">string</a>"</code>, <code>"<a href="#boolean">boolean</a>"</code>, <code>"<a href="#table">table</a>"</code>, or <code>"<a href="#function">function</a>"</code>. </p> <div class="mw-heading mw-heading4"><h4 id="unpack">unpack</h4></div> <p><code style="white-space:nowrap">unpack( table, i, j )</code> </p><p>Returns values from the given table, something like <code style="white-space:nowrap">table[i], table[i+1], ···, table[j]</code> would do if written out manually. If nil or not given, <code>i</code> defaults to 1 and <code>j</code> defaults to <code style="white-space:nowrap"><a href="#Length_operator">#table</a></code>. </p><p>If the table does not have a value for a particular key, unpack will return nil for that value. For example, <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="n">unpack</span><span class="p">({</span><span class="s2">&quot;foo&quot;</span><span class="p">,</span> <span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;bar&quot;</span><span class="p">},</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span></code> returns <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="s2">&quot;foo&quot;</span><span class="p">,</span> <span class="kc">nil</span><span class="p">,</span> <span class="s2">&quot;bar&quot;</span><span class="p">,</span> <span class="kc">nil</span></code>. </p><p>Note that results are not deterministic if <code>table</code> is not a <a href="#sequence">sequence</a> and <code>j</code> is nil or unspecified; see <a href="#Length_operator">Length operator</a> for details. </p> <div class="mw-heading mw-heading4"><h4 id="xpcall">xpcall</h4></div> <p><code style="white-space:nowrap">xpcall( f, errhandler )</code> </p><p>This is much like <code><a href="#pcall">pcall</a></code>, except that the error message is passed to the function <code>errhandler</code> before being returned. </p><p>In <a href="https://en.wikipedia.org/wiki/pseudocode" class="extiw" title="w:pseudocode">pseudocode</a>, <code>xpcall</code> might be defined something like this: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="kr">function</span> <span class="nf">xpcall</span><span class="p">(</span> <span class="n">f</span><span class="p">,</span> <span class="n">errhandler</span> <span class="p">)</span> <span class="n">try</span> <span class="kr">return</span> <span class="kc">true</span><span class="p">,</span> <span class="n">f</span><span class="p">()</span> <span class="n">catch</span> <span class="p">(</span> <span class="n">message</span> <span class="p">)</span> <span class="n">message</span> <span class="o">=</span> <span class="n">errhandler</span><span class="p">(</span> <span class="n">message</span> <span class="p">)</span> <span class="kr">return</span> <span class="kc">false</span><span class="p">,</span> <span class="n">message</span> <span class="kr">end</span> <span class="kr">end</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="Debug_library">Debug library</h3></div> <div class="mw-heading mw-heading4"><h4 id="debug.traceback">debug.traceback</h4></div> <p><code style="white-space:nowrap">debug.traceback( message, level )</code> </p><p>Returns a string with a traceback of the call stack. An optional message string is appended at the beginning of the traceback. An optional level number tells at which stack level to start the traceback. </p> <div class="mw-heading mw-heading3"><h3 id="Math_library">Math library</h3></div> <div class="mw-heading mw-heading4"><h4 id="math.abs">math.abs</h4></div> <p><code style="white-space:nowrap">math.abs( x )</code> </p><p>Returns the absolute value of <code>x</code>. </p> <div class="mw-heading mw-heading4"><h4 id="math.acos">math.acos</h4></div> <p><code style="white-space:nowrap">math.acos( x )</code> </p><p>Returns the arc cosine of <code>x</code> (given in radians). </p> <div class="mw-heading mw-heading4"><h4 id="math.asin">math.asin</h4></div> <p><code style="white-space:nowrap">math.asin( x )</code> </p><p>Returns the arc sine of <code>x</code> (given in radians). </p> <div class="mw-heading mw-heading4"><h4 id="math.atan">math.atan</h4></div> <p><code style="white-space:nowrap">math.atan( x )</code> </p><p>Returns the arc tangent of <code>x</code> (given in radians). </p> <div class="mw-heading mw-heading4"><h4 id="math.atan2">math.atan2</h4></div> <p><code style="white-space:nowrap">math.atan2( y, x )</code> </p><p>Returns the arc tangent of <code>y/x</code> (given in radians), using the signs of both parameters to find the quadrant of the result. </p> <div class="mw-heading mw-heading4"><h4 id="math.ceil">math.ceil</h4></div> <p><code style="white-space:nowrap">math.ceil( x )</code> </p><p>Returns the smallest integer larger than or equal to <code>x</code>. </p> <div class="mw-heading mw-heading4"><h4 id="math.cos">math.cos</h4></div> <p><code style="white-space:nowrap">math.cos( x )</code> </p><p>Returns the cosine of <code>x</code> (given in radians). </p> <div class="mw-heading mw-heading4"><h4 id="math.cosh">math.cosh</h4></div> <p><code style="white-space:nowrap">math.cosh( x )</code> </p><p>Returns the hyperbolic cosine of <code>x</code>. </p> <div class="mw-heading mw-heading4"><h4 id="math.deg">math.deg</h4></div> <p><code style="white-space:nowrap">math.deg( x )</code> </p><p>Returns the angle <code>x</code> (given in radians) in degrees. </p> <div class="mw-heading mw-heading4"><h4 id="math.exp">math.exp</h4></div> <p><code style="white-space:nowrap">math.exp( x )</code> </p><p>Returns the value <math class="mwe-math-element" xmlns="http://www.w3.org/1998/Math/MathML"><mrow data-mjx-texclass="ORD"><mstyle displaystyle="true" scriptlevel="0"><msup><mi>e</mi><mrow data-mjx-texclass="ORD"><mi>x</mi></mrow></msup></mstyle></mrow></math>. </p> <div class="mw-heading mw-heading4"><h4 id="math.floor">math.floor</h4></div> <p><code style="white-space:nowrap">math.floor( x )</code> </p><p>Returns the largest integer smaller than or equal to <code>x</code>. </p> <div class="mw-heading mw-heading4"><h4 id="math.fmod">math.fmod</h4></div> <p><code style="white-space:nowrap">math.fmod( x, y )</code> </p><p>Returns the remainder of the division of <code>x</code> by <code>y</code> that rounds the quotient towards zero. For example, <code>math.fmod( 10, 3 )</code> yields <code>1</code>. </p> <div class="mw-heading mw-heading4"><h4 id="math.frexp">math.frexp</h4></div> <p><code style="white-space:nowrap">math.frexp( x )</code> </p><p>Returns two values <code>m</code> and <code>e</code> such that: </p> <ul><li>If <code>x</code> is finite and non-zero: <math class="mwe-math-element" xmlns="http://www.w3.org/1998/Math/MathML"><mrow data-mjx-texclass="ORD"><mstyle displaystyle="true" scriptlevel="0"><mi>x</mi><mo>=</mo><mi>m</mi><mo>&#xd7;</mo><msup><mn>2</mn><mrow data-mjx-texclass="ORD"><mi>e</mi></mrow></msup></mstyle></mrow></math>, <code>e</code> is an integer, and the absolute value of <code>m</code> is in the range <math class="mwe-math-element" xmlns="http://www.w3.org/1998/Math/MathML"><mrow data-mjx-texclass="ORD"><mstyle displaystyle="true" scriptlevel="0"><mo stretchy="false">[</mo><mn>0</mn><mo stretchy="false">.</mo><mn>5</mn><mo>,</mo><mn>1</mn><mo stretchy="false">)</mo></mstyle></mrow></math></li> <li>If <code>x</code> is zero: <code>m</code> and <code>e</code> are 0</li> <li>If <code>x</code> is NaN or infinite: <code>m</code> is <code>x</code> and <code>e</code> is not specified</li></ul> <div class="mw-heading mw-heading4"><h4 id="math.huge">math.huge</h4></div> <p>The value representing positive infinity; larger than or equal to any other numerical value. </p> <div class="mw-heading mw-heading4"><h4 id="math.ldexp">math.ldexp</h4></div> <p><code style="white-space:nowrap">math.ldexp( m, e )</code> </p><p>Returns <math class="mwe-math-element" xmlns="http://www.w3.org/1998/Math/MathML"><mrow data-mjx-texclass="ORD"><mstyle displaystyle="true" scriptlevel="0"><mi>m</mi><mo stretchy="false">&#xd7;</mo><msup><mn>2</mn><mrow data-mjx-texclass="ORD"><mi>e</mi></mrow></msup></mstyle></mrow></math> (<code>e</code> should be an integer). </p> <div class="mw-heading mw-heading4"><h4 id="math.log">math.log</h4></div> <p><code style="white-space:nowrap">math.log( x )</code> </p><p>Returns the natural logarithm of <code>x</code>. </p> <div class="mw-heading mw-heading4"><h4 id="math.log10">math.log10</h4></div> <p><code style="white-space:nowrap">math.log10( x )</code> </p><p>Returns the base-10 logarithm of <code>x</code>. </p> <div class="mw-heading mw-heading4"><h4 id="math.max">math.max</h4></div> <p><code style="white-space:nowrap">math.max( x, ... )</code> </p><p>Returns the maximum value among its arguments. </p><p>Behavior with NaNs is not specified. With the current implementation, NaN will be returned if <code>x</code> is NaN, but any other NaNs will be ignored. </p> <div class="mw-heading mw-heading4"><h4 id="math.min">math.min</h4></div> <p><code style="white-space:nowrap">math.min( x, ... )</code> </p><p>Returns the minimum value among its arguments. </p><p>Behavior with NaNs is not specified. With the current implementation, NaN will be returned if <code>x</code> is NaN, but any other NaNs will be ignored. </p> <div class="mw-heading mw-heading4"><h4 id="math.modf">math.modf</h4></div> <p><code style="white-space:nowrap">math.modf( x )</code> </p><p>Returns two numbers, the integral part of <code>x</code> and the fractional part of <code>x</code>. For example, <code>math.modf( 1.25 )</code> yields <code>1, 0.25</code>. </p> <div class="mw-heading mw-heading4"><h4 id="math.pi">math.pi</h4></div> <p>The value of <math class="mwe-math-element" xmlns="http://www.w3.org/1998/Math/MathML"><mrow data-mjx-texclass="ORD"><mstyle displaystyle="true" scriptlevel="0"><mi>&#x3c0;</mi></mstyle></mrow></math>. </p> <div class="mw-heading mw-heading4"><h4 id="math.pow">math.pow</h4></div> <p><code style="white-space:nowrap">math.pow( x, y )</code> </p><p>Equivalent to <code>x^y</code>. </p> <div class="mw-heading mw-heading4"><h4 id="math.rad">math.rad</h4></div> <p><code style="white-space:nowrap">math.rad( x )</code> </p><p>Returns the angle <code>x</code> (given in degrees) in radians. </p> <div class="mw-heading mw-heading4"><h4 id="math.random">math.random</h4></div> <p><code style="white-space:nowrap">math.random( m, n )</code> </p><p>Returns a pseudo-random number. </p><p>The arguments <code>m</code> and <code>n</code> may be omitted, but if specified must be convertible to integers. </p> <ul><li>With no arguments, returns a real number in the range <math class="mwe-math-element" xmlns="http://www.w3.org/1998/Math/MathML"><mrow data-mjx-texclass="ORD"><mstyle displaystyle="true" scriptlevel="0"><mo stretchy="false">[</mo><mn>0</mn><mo>,</mo><mn>1</mn><mo stretchy="false">)</mo></mstyle></mrow></math></li> <li>With one argument, returns an integer in the range <math class="mwe-math-element" xmlns="http://www.w3.org/1998/Math/MathML"><mrow data-mjx-texclass="ORD"><mstyle displaystyle="true" scriptlevel="0"><mo stretchy="false">[</mo><mn>1</mn><mo>,</mo><mi>m</mi><mo stretchy="false">]</mo></mstyle></mrow></math></li> <li>With two arguments, returns an integer in the range <math class="mwe-math-element" xmlns="http://www.w3.org/1998/Math/MathML"><mrow data-mjx-texclass="ORD"><mstyle displaystyle="true" scriptlevel="0"><mo stretchy="false">[</mo><mi>m</mi><mo>,</mo><mi>n</mi><mo stretchy="false">]</mo></mstyle></mrow></math></li></ul> <p>Note that incorrect output may be produced if <code>m</code> or <code>n</code> are less than −2147483648 or greater than 2147483647, or if <code>n - m</code> is greater than 2147483646. </p> <div class="mw-heading mw-heading4"><h4 id="math.randomseed">math.randomseed</h4></div> <p><code style="white-space:nowrap">math.randomseed( x )</code> </p><p>Sets <code>x</code> as the <a href="https://en.wikipedia.org/wiki/Random_seed" class="extiw" title="w:Random seed">seed</a> for the pseudo-random generator. </p><p>Note that using the same seed will cause <code>math.random</code> to output the same sequence of numbers. </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="nb">math.randomseed</span><span class="p">(</span> <span class="nb">tonumber</span><span class="p">(</span> <span class="n">mw</span><span class="p">.</span><span class="n">getContentLanguage</span><span class="p">():</span><span class="n">formatDate</span><span class="p">(</span> <span class="s2">&quot;U&quot;</span> <span class="p">)</span> <span class="p">)</span> <span class="o">*</span> <span class="mi">10000</span> <span class="o">+</span> <span class="nb">os.clock</span><span class="p">()</span> <span class="o">*</span> <span class="mi">10000</span> <span class="p">)</span> </pre></div> <div class="mw-heading mw-heading4"><h4 id="math.sin">math.sin</h4></div> <p><code style="white-space:nowrap">math.sin( x )</code> </p><p>Returns the sine of <code>x</code> (given in radians). </p> <div class="mw-heading mw-heading4"><h4 id="math.sinh">math.sinh</h4></div> <p><code style="white-space:nowrap">math.sinh( x )</code> </p><p>Returns the hyperbolic sine of <code>x</code>. </p> <div class="mw-heading mw-heading4"><h4 id="math.sqrt">math.sqrt</h4></div> <p><code style="white-space:nowrap">math.sqrt( x )</code> </p><p>Returns the square root of <code>x</code>. Equivalent to <code>x^0.5</code>. </p> <div class="mw-heading mw-heading4"><h4 id="math.tan">math.tan</h4></div> <p><code style="white-space:nowrap">math.tan( x )</code> </p><p>Returns the tangent of <code>x</code> (given in radians). </p> <div class="mw-heading mw-heading4"><h4 id="math.tanh">math.tanh</h4></div> <p><code style="white-space:nowrap">math.tanh( x )</code> </p><p>Returns the hyperbolic tangent of <code>x</code>. </p> <div class="mw-heading mw-heading3"><h3 id="Operating_system_library">Operating system library</h3></div> <div class="mw-heading mw-heading4"><h4 id="os.clock">os.clock</h4></div> <p><code>os.clock()</code> </p><p>Returns an approximation of the amount in seconds of CPU time used by the program. </p> <div class="mw-heading mw-heading4"><h4 id="os.date">os.date</h4></div> <p><code style="white-space:nowrap">os.date( format, time )</code> </p> <dl><dd><i><a href="#mw.language:formatDate">Language library's formatDate</a> may be used for more comprehensive date formatting</i></dd></dl> <p>Returns a string or a table containing date and time, formatted according to <code>format</code>. If the format is omitted or nil, "%c" is used. </p><p>If <code>time</code> is given, it is the time to be formatted (see <code><a href="#os.time">os.time()</a></code>). Otherwise the current time is used. </p><p>If <code>format</code> starts with '!', then the date is formatted in UTC rather than the server's local time. After this optional character, if format is the string "*t", then date returns a table with the following fields: </p> <ul><li>year (full)</li> <li>month (1–12)</li> <li>day (1–31)</li> <li>hour (0–23)</li> <li>min (0–59)</li> <li>sec (0–60, to allow for <a href="https://en.wikipedia.org/wiki/leap_second" class="extiw" title="w:leap second">leap seconds</a>)</li> <li>wday (weekday, Sunday is 1)</li> <li>yday (day of the year)</li> <li>isdst (daylight saving flag, a boolean; may be absent if the information is not available)</li></ul> <p>If format is not "*t", then date returns the date as a string, formatted according to the same rules as the C function <a rel="nofollow" class="external text" href="http://man7.org/linux/man-pages/man3/strftime.3.html">strftime</a>. </p> <div class="mw-heading mw-heading4"><h4 id="os.difftime">os.difftime</h4></div> <p><code style="white-space:nowrap">os.difftime( t2, t1 )</code> </p><p>Returns the number of seconds from <code>t1</code> to <code>t2</code>. </p> <div class="mw-heading mw-heading4"><h4 id="os.time">os.time</h4></div> <p><code style="white-space:nowrap">os.time( table )</code> </p><p>Returns a number representing the current time. </p><p>When called without arguments, returns the current time. If passed a table, the time encoded in the table will be parsed. The table must have the fields "year", "month", and "day", and may also include "hour" (default 12), "min" (default 0), "sec" (default 0), and "isdst". </p> <div class="mw-heading mw-heading3"><h3 id="Package_library">Package library</h3></div> <div class="mw-heading mw-heading4"><h4 id="require">require</h4></div> <p><code style="white-space:nowrap">require( modulename )</code> </p><p>Loads the specified module. </p><p>First, it looks in <code>package.loaded[modulename]</code> to see if the module is already loaded. If so, returns <code>package.loaded[modulename]</code>. </p><p>Otherwise, it calls each loader in the <code>package.loaders</code> sequence to attempt to find a loader for the module. If a loader is found, that loader is called. The value returned by the loader is stored into <code>package.loaded[modulename]</code> and is returned. </p><p>See the documentation for <code><a href="#package.loaders">package.loaders</a></code> for information on the loaders available. </p><p>For example, if you have a module "Module:Giving" containing the following: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="kd">local</span> <span class="n">p</span> <span class="o">=</span> <span class="p">{}</span> <span class="n">p</span><span class="p">.</span><span class="n">someDataValue</span> <span class="o">=</span> <span class="s1">&#39;Hello!&#39;</span> <span class="kr">return</span> <span class="n">p</span> </pre></div> <p>You can load this in another module with code such as this: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="kd">local</span> <span class="n">giving</span> <span class="o">=</span> <span class="nb">require</span><span class="p">(</span> <span class="s2">&quot;Module:Giving&quot;</span> <span class="p">)</span> <span class="kd">local</span> <span class="n">value</span> <span class="o">=</span> <span class="n">giving</span><span class="p">.</span><span class="n">someDataValue</span> <span class="c1">-- value is now &#39;Hello!&#39;</span> </pre></div> <div class="mw-heading mw-heading4"><h4 id="package.loaded">package.loaded</h4></div> <p>This table holds the loaded modules. The keys are the module names, and the values are the values returned when the module was loaded. </p> <div class="mw-heading mw-heading4"><h4 id="package.loaders">package.loaders</h4></div> <p>This table holds the sequence of searcher functions to use when loading modules. Each searcher function is called with a single argument, the name of the module to load. If the module is found, the searcher must return a function that will actually load the module and return the value to be returned by <a href="#require">require</a>. Otherwise, it must return nil. </p><p>Scribunto provides two searchers: </p> <ol><li>Look in <code>package.preload[modulename]</code> for the loader function</li> <li>Look in the <a href="#Loadable_libraries">modules provided with Scribunto</a> for the module name, and if that fails look in the Module: namespace. The "Module:" prefix must be provided.</li></ol> <p>Note that the standard Lua loaders are <b>not</b> included. </p> <div class="mw-heading mw-heading4"><h4 id="package.preload">package.preload</h4></div> <p>This table holds loader functions, used by the first searcher Scribunto includes in <a href="#package.loaders">package.loaders</a>. </p> <div class="mw-heading mw-heading4"><h4 id="package.seeall">package.seeall</h4></div> <p><code style="white-space:nowrap">package.seeall( table )</code> </p><p>Sets the __index <a href="#Metatables">metamethod</a> for <code>table</code> to <a href="#_G">_G</a>. </p> <div class="mw-heading mw-heading3"><h3 id="String_library">String library</h3></div> <p>In all string functions, the first character is at position&#160;1, not position&#160;0 as in C, PHP, and JavaScript. Indexes may be negative, in which case they count from the end of the string: position&#160;-1 is the last character in the string, -2 is the second-last, and so on. </p><p><span style="color:#d73333" dir="ltr">Warning:</span> The string library assumes one-byte character encodings. <b>It cannot handle Unicode characters</b>. To operate on Unicode strings, use the corresponding methods in the <a href="#Ustring_library">Scribunto Ustring library</a>. </p> <div class="mw-heading mw-heading4"><h4 id="string.byte">string.byte</h4></div> <p><code style="white-space:nowrap">string.byte( s, i, j )</code> </p><p>If the string is considered as an array of bytes, returns the byte values for <code>s[i]</code>, <code>s[i+1]</code>, ···, <code>s[j]</code>. The default value for <code>i</code> is&#160;1; the default value for <code>j</code> is&#160;<code>i</code>. Identical to <a href="#mw.ustring.byte">mw.ustring.byte()</a>. </p> <div class="mw-heading mw-heading4"><h4 id="string.char">string.char</h4></div> <p><code style="white-space:nowrap">string.char( ... )</code> </p><p>Receives zero or more integers. Returns a string with length equal to the number of arguments, in which each character has the byte value equal to its corresponding argument. </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="kd">local</span> <span class="n">value</span> <span class="o">=</span> <span class="nb">string.char</span><span class="p">(</span> <span class="mh">0x48</span><span class="p">,</span> <span class="mh">0x65</span><span class="p">,</span> <span class="mh">0x6c</span><span class="p">,</span> <span class="mh">0x6c</span><span class="p">,</span> <span class="mh">0x6f</span><span class="p">,</span> <span class="mh">0x21</span> <span class="p">)</span> <span class="c1">--value is now &#39;Hello!&#39;</span> </pre></div> <p>See <a href="#mw.ustring.char">mw.ustring.char()</a> for a similar function that uses Unicode codepoints rather than byte values. </p> <div class="mw-heading mw-heading4"><h4 id="string.find">string.find</h4></div> <p><code style="white-space:nowrap">string.find( s, pattern, init, plain )</code> </p><p>Looks for the first match of <code><a href="#Patterns">pattern</a></code> in the string <code>s</code>. If it finds a match, then <code>find</code> returns the offsets in&#160;<code>s</code> where this occurrence starts and ends; otherwise, it returns nil. If the pattern has captures, then in a successful match the captured values are also returned after the two indices. </p><p>A third, optional numerical argument <code>init</code> specifies where to start the search; its default value is&#160;1 and can be negative. A value of true as a fourth, optional argument <code>plain</code> turns off the pattern matching facilities, so the function does a plain "find substring" operation, with no characters in <code>pattern</code> being considered "magic". </p><p>Note that if <code>plain</code> is given, then <code>init</code> must be given as well. </p><p>See <a href="#mw.ustring.find">mw.ustring.find()</a> for a similar function extended as described in <a href="#Ustring_patterns">Ustring patterns</a> and where the <code>init</code> offset is in characters rather than bytes. </p> <div class="mw-heading mw-heading4"><h4 id="string.format">string.format</h4></div> <p><code style="white-space:nowrap">string.format( formatstring, ... )</code> </p><p>Returns a formatted version of its variable number of arguments following the description given in its first argument (which must be a string). </p><p>The format string uses a limited subset of the <a rel="nofollow" class="external text" href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/printf.html"><code>printf</code> format specifiers</a>: </p> <ul><li>Recognized flags are <code>'-', '+', ' ', '#',</code> and <code>'0'</code>.</li> <li>Integer field widths up to 99 are supported. <code>'*'</code> is not supported.</li> <li>Integer precisions up to 99 are supported. <code>'*'</code> is not supported.</li> <li>Length modifiers are not supported.</li> <li>Recognized conversion specifiers are <code>'c', 'd', 'i', 'o', 'u', 'x', 'X', 'e', 'E', 'f', 'g', 'G', 's', '%',</code> and the non-standard <code>'q'</code>.</li> <li>Positional specifiers (e.g. "%2$s") are not supported.</li></ul> <p>The conversion specifier <code>q</code> is like <code>s</code>, but formats the string in a form suitable to be safely read back by the Lua interpreter: the string is written between double quotes, and all double quotes, newlines, embedded zeros, and backslashes in the string are correctly escaped when written. </p><p>Conversion between strings and numbers is performed as specified in <a href="#Data_types">Data types</a>; other types are not automatically converted to strings. Strings containing NUL characters (byte value 0) are not properly handled. </p><p>Identical to <a href="#mw.ustring.format">mw.ustring.format()</a>. </p> <div class="mw-heading mw-heading4"><h4 id="string.gmatch">string.gmatch</h4></div> <p><code style="white-space:nowrap">string.gmatch( s, pattern )</code> </p><p>Returns an iterator function that, each time it is called, returns the next captures from <a href="#Patterns"><code>pattern</code></a> over string <code>s</code>. If <code>pattern</code> specifies no captures, then the whole match is produced in each call. </p><p>For this function, a '<code>^</code>' at the start of a pattern is not magic, as this would prevent the iteration. It is treated as a literal character. </p><p>See <a href="#mw.ustring.gmatch&gt;">mw.ustring.gmatch()</a> for a similar function for which the pattern is extended as described in <a href="#Ustring_patterns">Ustring patterns</a>. </p> <div class="mw-heading mw-heading4"><h4 id="string.gsub">string.gsub</h4></div> <p><code style="white-space:nowrap">string.gsub( s, pattern, repl, n )</code> </p><p>Returns a copy of <code>s</code> in which all (or the first <code>n</code>, if given) occurrences of the <a href="#Patterns"><code>pattern</code></a> have been replaced by a replacement string specified by <code>repl</code>, which can be a string, a table, or a function. <code>gsub</code> also returns, as its second value, the total number of matches that occurred. </p><p>If <code>repl</code> is a string, then its value is used for replacement. The character&#160;<code>%</code> works as an escape character: any sequence in <code>repl</code> of the form <code>%<i>d</i></code>, with <i>d</i> between 1 and 9, stands for the value of the <i>d</i>-th captured substring. The sequence <code>%0</code> stands for the whole match, and the sequence <code>%%</code> stands for a single&#160;<code>%</code>. </p><p>If <code>repl</code> is a table, then the table is queried for every match, using the first capture as the key; if the pattern specifies no captures, then the whole match is used as the key. </p><p>If <code>repl</code> is a function, then this function is called every time a match occurs, with all captured substrings passed as arguments, in order; if the pattern specifies no captures, then the whole match is passed as a sole argument. </p><p>If the value returned by the table query or by the function call is a string or a number, then it is used as the replacement string; otherwise, if it is false or nil, then there is no replacement (that is, the original match is kept in the string). </p><p>See <a href="#mw.ustring.gsub">mw.ustring.gsub()</a> for a similar function in which the pattern is extended as described in <a href="#Ustring_patterns">Ustring patterns</a>. </p> <div class="mw-heading mw-heading4"><h4 id="string.len">string.len</h4></div> <p><code style="white-space:nowrap">string.len( s )</code> </p><p>Returns the length of the string, in bytes. Is not confused by ASCII NUL characters. Equivalent to <code style="white-space:nowrap"><a href="#Length_operator">#s</a></code>. </p><p>See <a href="#mw.ustring.len">mw.ustring.len()</a> for a similar function using Unicode codepoints rather than bytes. </p> <div class="mw-heading mw-heading4"><h4 id="string.lower">string.lower</h4></div> <p><code style="white-space:nowrap">string.lower( s )</code> </p><p>Returns a copy of this string with all ASCII uppercase letters changed to lowercase. All other characters are left unchanged. </p><p>See <a href="#mw.ustring.lower">mw.ustring.lower()</a> for a similar function in which all characters with uppercase to lowercase definitions in Unicode are converted. </p> <div class="mw-heading mw-heading4"><h4 id="string.match">string.match</h4></div> <p><code style="white-space:nowrap">string.match( s, pattern, init )</code> </p><p>Looks for the first match of <a href="#Patterns"><code>pattern</code></a> in the string. If it finds one, then <code>match</code> returns the captures from the pattern; otherwise it returns nil. If <code>pattern</code> specifies no captures, then the whole match is returned. </p><p>A third, optional numerical argument <code>init</code> specifies where to start the search; its default value is&#160;1 and can be negative. </p><p>See <a href="#mw.ustring.match">mw.ustring.match()</a> for a similar function in which the pattern is extended as described in <a href="#Ustring_patterns">Ustring patterns</a> and the <code>init</code> offset is in characters rather than bytes. </p> <div class="mw-heading mw-heading4"><h4 id="string.rep">string.rep</h4></div> <p><code style="white-space:nowrap">string.rep( s, n )</code> </p><p>Returns a string that is the concatenation of <code>n</code> copies of the string <code>s</code>. Identical to <a href="#mw.ustring.rep">mw.ustring.rep()</a>. </p> <div class="mw-heading mw-heading4"><h4 id="string.reverse">string.reverse</h4></div> <p><code style="white-space:nowrap">string.reverse( s )</code> </p><p>Returns a string that is the string <code>s</code> reversed (bytewise). </p> <div class="mw-heading mw-heading4"><h4 id="string.sub">string.sub</h4></div> <p><code style="white-space:nowrap">string.sub( s, i, j )</code> </p><p>Returns the substring of <code>s</code> that starts at <code>i</code> and continues until <code>j</code>; <code>i</code> and <code>j</code> can be negative. If <code>j</code> is nil or omitted, it will continue until the end of the string. </p><p>In particular, the call <code>string.sub(s,1,j)</code> returns a prefix of <code>s</code> with length <code>j</code>, and <code style="white-space:nowrap">string.sub(s, -i)</code> returns a suffix of <code>s</code> with length <code>i</code>. </p><p>See <a href="#mw.ustring.sub">mw.ustring.sub()</a> for a similar function in which the offsets are characters rather than bytes. </p> <div class="mw-heading mw-heading4"><h4 id="string.ulower">string.ulower</h4></div> <p><code style="white-space:nowrap">string.ulower( s )</code> </p><p>An alias for <a href="#mw.ustring.lower">mw.ustring.lower()</a>. </p> <div class="mw-heading mw-heading4"><h4 id="string.upper">string.upper</h4></div> <p><code style="white-space:nowrap">string.upper( s )</code> </p><p>Returns a copy of this string with all ASCII lowercase letters changed to uppercase. All other characters are left unchanged. </p><p>See <a href="#mw.ustring.upper">mw.ustring.upper()</a> for a similar function in which all characters with lowercase to uppercase definitions in Unicode are converted. </p> <div class="mw-heading mw-heading4"><h4 id="string.uupper">string.uupper</h4></div> <p><code style="white-space:nowrap">string.uupper( s )</code> </p><p>An alias for <a href="#mw.ustring.upper">mw.ustring.upper()</a>. </p> <div class="mw-heading mw-heading4"><h4 id="Patterns">Patterns</h4></div> <p>Note that Lua's patterns are similar to <a href="https://en.wikipedia.org/wiki/regular_expression" class="extiw" title="w:regular expression">regular expressions</a>, but are not identical. In particular, note the following differences from regular expressions and <a href="https://en.wikipedia.org/wiki/PCRE" class="extiw" title="w:PCRE">PCRE</a>: </p> <ul><li>The quoting character is percent (<code>%</code>), not backslash (<code>\</code>).</li> <li>Dot (<code>.</code>) always matches all characters, including newlines.</li> <li>No case-insensitive mode.</li> <li>No alternation (the <code>|</code> operator).</li> <li>Quantifiers (<code>*</code>, <code>+</code>, <code>?</code>, and <code>-</code>) may only be applied to individual characters or character classes, not to capture groups.</li> <li>The only non-greedy quantifier is <code>-</code>, which is equivalent to PCRE's <code>*?</code> quantifier.</li> <li>No generalized finite quantifier (e.g. the <code>{<i>n</i>,<i>m</i>}</code> quantifier in PCRE).</li> <li>The only zero-width assertions are <code>^</code>, <code>$</code>, and the <code>%f[set]</code> "frontier" pattern; assertions such as PCRE's <code>\b</code> or <code>(?=···)</code> are not present.</li> <li>Patterns themselves do not recognize character escapes such as <code>\<i>ddd</i></code>. However, since patterns are <a href="#string">strings</a> these sort of escapes may be used in the string literals used to create the pattern-string.</li></ul> <p>Also note that a pattern cannot contain embedded zero bytes (ASCII NUL, <code>"\0"</code>). Use <code>%z</code> instead. </p><p>Also see <a href="#Ustring_patterns">Ustring patterns</a> for a similar pattern-matching scheme using Unicode characters. </p> <div class="mw-heading mw-heading5"><h5 id="Character_class">Character class</h5></div> <p>A <i>character class</i> is used to represent a set of characters. The following combinations are allowed in describing a character class: </p> <table class="wikitable"> <tbody><tr> <th scope="row"><code><var style="padding-right: 1px;">x</var></code> </th> <td>(where <code><var style="padding-right: 1px;">x</var></code> is not one of the magic characters <code>^$()%.[]*+-?</code>) represents the character <code><var style="padding-right: 1px;">x</var></code> itself. </td></tr> <tr> <th scope="row"><code>.</code> </th> <td>(a dot) Represents all characters. </td></tr> <tr> <th scope="row"><code>%a</code> </th> <td>Represents all ASCII letters. </td></tr> <tr> <th scope="row"><code>%c</code> </th> <td>Represents all ASCII control characters. </td></tr> <tr> <th scope="row"><code>%d</code> </th> <td>Represents all digits. </td></tr> <tr> <th scope="row"><code>%l</code> </th> <td>Represents all ASCII lowercase letters. </td></tr> <tr> <th scope="row"><code>%p</code> </th> <td>Represents all punctuation characters. </td></tr> <tr> <th scope="row"><code>%s</code> </th> <td>Represents all ASCII space characters. </td></tr> <tr> <th scope="row"><code>%u</code> </th> <td>Represents all ASCII uppercase letters. </td></tr> <tr> <th scope="row"><code>%w</code> </th> <td>Represents all ASCII alphanumeric characters. Note it doesn't include the underscore character (<code>_</code>), contrarily to the usual class <code>\w</code> in regular expressions. </td></tr> <tr> <th scope="row"><code>%x</code> </th> <td>Represents all hexadecimal digits. </td></tr> <tr> <th scope="row"><code>%z</code> </th> <td>Represents ASCII NUL, the zero byte. </td></tr> <tr> <th scope="row"><code>%A</code> </th> <td>All characters not in <code>%a</code>. </td></tr> <tr> <th scope="row"><code>%C</code> </th> <td>All characters not in <code>%c</code>. </td></tr> <tr> <th scope="row"><code>%D</code> </th> <td>All characters not in <code>%d</code>. </td></tr> <tr> <th scope="row"><code>%L</code> </th> <td>All characters not in <code>%l</code>. </td></tr> <tr> <th scope="row"><code>%P</code> </th> <td>All characters not in <code>%p</code>. </td></tr> <tr> <th scope="row"><code>%S</code> </th> <td>All characters not in <code>%s</code>. </td></tr> <tr> <th scope="row"><code>%U</code> </th> <td>All characters not in <code>%u</code>. </td></tr> <tr> <th scope="row"><code>%W</code> </th> <td>All characters not in <code>%w</code>. </td></tr> <tr> <th scope="row"><code>%X</code> </th> <td>All characters not in <code>%x</code>. </td></tr> <tr> <th scope="row"><code>%Z</code> </th> <td>All characters not in <code>%z</code>. </td></tr> <tr> <th scope="row"><code>%<var style="padding-right: 1px;">y</var></code> </th> <td>(where <code><var style="padding-right: 1px;">y</var></code> is any non-alphanumeric character) represents the character <code><var style="padding-right: 1px;">y</var></code>. This is the standard way to escape the magic characters. Any punctuation character (even the non magic) can be preceded by a '<code>%</code>' when used to represent itself in a pattern. </td></tr> <tr> <th scope="row"><code>[<var style="padding-right: 1px;">set</var>]</code> </th> <td> <p>Represents the class which is the union of all characters in <var style="padding-right: 1px;">set</var>. A range of characters can be specified by separating the end characters of the range with a '<code>-</code>'. All classes <code>%<var style="padding-right: 1px;">y</var></code> described above can also be used as components in <var style="padding-right: 1px;">set</var>. All other characters in <var style="padding-right: 1px;">set</var> represent themselves. For example, <code>[%w_]</code> (or <code>[_%w]</code>) represents all alphanumeric characters plus the underscore, and <code style="white-space:nowrap">[0-7]</code> represents the octal digits. To include literal '<code>-</code>' in the set, use '<code>%-</code>', so <code style="white-space:nowrap">[0-7%l%-]</code> represents the octal digits plus the lowercase letters plus the '<code>-</code>' character. </p><p>The interaction between ranges and classes is not defined. Therefore, patterns like <code>[%a-z]</code> or <code>[a-%%]</code> have no meaning. </p> </td></tr> <tr> <th scope="row"><code>[^<var style="padding-right: 1px;">set</var>]</code> </th> <td>Represents the complement of <var style="padding-right: 1px;">set</var>, where <var style="padding-right: 1px;">set</var> is interpreted as above. </td></tr></tbody></table> <div class="mw-heading mw-heading5"><h5 id="Pattern_items">Pattern items</h5></div> <p>A <i>pattern item</i> can be </p> <ul><li>a single character class, which matches any single character in the class;</li> <li>a single character class followed by '<code>*</code>', which matches 0 or more repetitions of characters in the class. These repetition items will always match the longest possible sequence;</li> <li>a single character class followed by '<code>+</code>', which matches 1 or more repetitions of characters in the class. These repetition items will always match the longest possible sequence;</li> <li>a single character class followed by '<code>-</code>', which also matches 0 or more repetitions of characters in the class. Unlike '<code>*</code>', these repetition items will always match the <i>shortest</i> possible sequence;</li> <li>a single character class followed by '<code>?</code>', which matches 0 or 1 occurrence of a character in the class;</li> <li><code>%<i>n</i></code>, for <i>n</i> between 1 and 9; such item matches a substring equal to the <i>n</i>-th captured string (see below);</li> <li><code>%b<i>xy</i></code>, where <i>x</i> and <i>y</i> are two distinct characters; such item matches strings that start with&#160;<i>x</i>, end with&#160;<i>y</i>, and where the <i>x</i> and <i>y</i> are <i>balanced</i>. This means that, if one reads the string from left to right, counting +1 for an <i>x</i> and -1 for a <i>y</i>, the ending <i>y</i> is the first <i>y</i> where the count reaches 0. For instance, the item <code>%b()</code> matches expressions with balanced parentheses.</li> <li><code>%f[<i>set</i>]</code>, a <i>frontier pattern</i>; such item matches an empty string at any position such that the next character belongs to <i>set</i> and the previous character does not belong to <i>set</i>. The set <i>set</i> is interpreted as previously described. The beginning and the end of the subject are handled as if they were the character&#160;'\0'.<br /><small>Note that frontier patterns were present but undocumented in Lua&#160;5.1, and officially added to Lua in 5.2. The implementation in Lua&#160;5.2.1 is unchanged from that in 5.1.0.</small></li></ul> <div class="mw-heading mw-heading5"><h5 id="Pattern">Pattern</h5></div> <p>A <i>pattern</i> is a sequence of pattern items. </p><p>A <code>^</code> at the beginning of a pattern anchors the match at the beginning of the subject string. A <code>$</code> at the end of a pattern anchors the match at the end of the subject string. At other positions, <code>^</code> and <code>$</code> have no special meaning and represent themselves. </p> <div class="mw-heading mw-heading5"><h5 id="Captures">Captures</h5></div> <p>A pattern can contain sub-patterns enclosed in parentheses; they describe <i>captures</i>. When a match succeeds, the substrings of the subject string that match captures are stored ("captured") for future use. Captures are numbered according to their left parentheses. For instance, in the pattern <code>(a*(.)%w(%s*))</code>, the part of the string matching <code>a*(.)%w(%s*)</code> is stored as the first capture (and therefore has number&#160;1); the character matching <code>.</code> is captured with number&#160;2, and the part matching <code>%s*</code> has number&#160;3. </p><p>Capture references can appear in the pattern string itself, and refer back to text that was captured earlier in the match. For example, <code>([a-z])%1</code> will match any pair of identical lowercase letters, while <code>([a-z])([a-z])([a-z])[a-z]%3%2%1</code> will match any 7-letter <a href="https://en.wikipedia.org/wiki/Palindrome" class="extiw" title="w:Palindrome">palindrome</a>. </p><p>As a special case, the empty capture <code>()</code> captures the current string position (a number). For instance, if we apply the pattern <code>"()aa()"</code> on the string <code>"flaaap"</code>, there will be two captures: 3&#160;and&#160;5. </p><p><span style="color:#d73333" dir="ltr">Known limitations</span>: Unlike <a href="#Ustring_patterns">Ustring library patterns</a>, String library patterns may not contain more than 32 captures. If the pattern has more, then the String function will throw an error. Because the Ustring library has its own maximum of 10,000 bytes for patterns (unlike the String library), it is therefore impossible to use a pattern which exceeds both limits, as it will be incompatible with both libraries. </p> <div class="mw-heading mw-heading3"><h3 id="Table_library">Table library</h3></div> <p>Most functions in the table library assume that the table represents a <a href="#sequence">sequence</a>. </p><p>The functions <code>table.foreach()</code>, <code>table.foreachi()</code>, and <code>table.getn()</code> may be available but are deprecated; use a for loop with <code><a href="#pairs">pairs()</a></code>, a for loop with <code><a href="#ipairs">ipairs()</a></code>, or the <a href="#Length_operator&lt;/tvar&gt;">length operator</a> <code>#</code>, respectively. The function <code>table.setn()</code> is completely obsolete, however, and will throw an error if used. </p> <div class="mw-heading mw-heading4"><h4 id="table.concat">table.concat</h4></div> <p><code style="white-space:nowrap">table.concat( table, sep, i, j )</code> </p><p>Given an array where all elements are strings or numbers, returns <code style="white-space:nowrap">table[i] .. sep .. table[i+1] ··· sep .. table[j]</code>. </p><p>The default value for <code>sep</code> is an empty string, the default for <code>i</code> is 1, and the default for <code>j</code> is the length of the table. If <code>i</code> is greater than <code>j</code>, it returns an empty string. </p> <div class="mw-heading mw-heading4"><h4 id="table.insert">table.insert</h4></div> <p><code style="white-space:nowrap">table.insert( table, value )</code> <br /> <code style="white-space:nowrap">table.insert( table, pos, value )</code> </p><p>Inserts element <code>value</code> at position <code>pos</code> in <code>table</code>, shifting up other elements to open space, if necessary. The default value for <code>pos</code> is the length of the table plus 1, so that a call <code style="white-space:nowrap">table.insert(t, x)</code> inserts <code>x</code> at the end of table <code>t</code>. </p><p>Elements up to <code>#table</code> are shifted; see <a href="#Length_operator">Length operator</a> for caveats if the table is not a <a href="#sequence">sequence</a>. </p><p><span style="color:#d73333" dir="ltr">Note</span>: when using the <code>pos</code> parameter, <code>value</code> should not be <code>nil</code>. Attempting to insert an explicit <code>nil</code> value into the middle of a table will result in undefined behaviour, which may delete elements in the table unpredictably. </p> <div class="mw-heading mw-heading4"><h4 id="table.maxn">table.maxn</h4></div> <p><code style="white-space:nowrap">table.maxn( table )</code> </p><p>Returns the largest positive numerical index of the given table, or zero if the table has no positive numerical indices. </p><p>To do this, it iterates over the whole table. This is roughly equivalent to </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="kr">function</span> <span class="nc">table</span><span class="p">.</span><span class="nf">maxn</span><span class="p">(</span> <span class="n">table</span> <span class="p">)</span> <span class="kd">local</span> <span class="n">maxn</span><span class="p">,</span> <span class="n">k</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="kc">nil</span> <span class="kr">repeat</span> <span class="n">k</span> <span class="o">=</span> <span class="nb">next</span><span class="p">(</span> <span class="n">table</span><span class="p">,</span> <span class="n">k</span> <span class="p">)</span> <span class="kr">if</span> <span class="nb">type</span><span class="p">(</span> <span class="n">k</span> <span class="p">)</span> <span class="o">==</span> <span class="s1">&#39;number&#39;</span> <span class="ow">and</span> <span class="n">k</span> <span class="o">&gt;</span> <span class="n">maxn</span> <span class="kr">then</span> <span class="n">maxn</span> <span class="o">=</span> <span class="n">k</span> <span class="kr">end</span> <span class="kr">until</span> <span class="ow">not</span> <span class="n">k</span> <span class="kr">return</span> <span class="n">maxn</span> <span class="kr">end</span> </pre></div> <div class="mw-heading mw-heading4"><h4 id="table.remove">table.remove</h4></div> <p><code style="white-space:nowrap">table.remove( table, pos )</code> </p><p>Removes from <code>table</code> the element at position <code>pos</code>, shifting down other elements to close the space, if necessary. Returns the value of the removed element. The default value for <code>pos</code> is the length of the table, so that a call <code style="white-space:nowrap">table.remove( t )</code> removes the last element of table <code>t</code>. </p><p>Elements up to <code>#table</code> are shifted; see <a href="#Length_operator">Length operator</a> for caveats if the table is not a <a href="#sequence">sequence</a>. </p> <div class="mw-heading mw-heading4"><h4 id="table.sort">table.sort</h4></div> <p><code style="white-space:nowrap">table.sort( table, comp )</code> </p><p>Sorts table elements in a given order, <i>in-place</i>, from <code>table[1]</code> to <code>table[#table]</code>. If <code>comp</code> is given, then it must be a function that receives two table elements, and returns <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">true</span></code> when the first is less than the second (so that <code style="white-space:nowrap">not comp(a[i+1],a[i])</code> will be true after the sort). If <code>comp</code> is not given, then the standard Lua operator <code>&lt;</code> is used instead. The sort algorithm is not stable; that is, elements considered equal by the given order may have their relative positions changed by the sort. </p> <div class="mw-heading mw-heading2"><h2 id="Scribunto_libraries">Scribunto libraries</h2></div> <p>All Scribunto libraries are located in the table <code>mw</code>. </p> <div class="mw-heading mw-heading3"><h3 id="Base_functions">Base functions</h3></div> <div class="mw-heading mw-heading4"><h4 id="mw.addWarning">mw.addWarning</h4></div> <p><code style="white-space:nowrap">mw.addWarning( text )</code> </p><p>Adds a warning which is displayed above the preview when previewing an edit. <code>text</code> is parsed as wikitext. </p> <div class="mw-heading mw-heading4"><h4 id="mw.allToString">mw.allToString</h4></div> <p><code style="white-space:nowrap">mw.allToString( ... )</code> </p><p>Calls <a href="#tostring">tostring()</a> on all arguments, then concatenates them with tabs as separators. </p> <div class="mw-heading mw-heading4"><h4 id="mw.clone">mw.clone</h4></div> <p><code style="white-space:nowrap">mw.clone( value )</code> </p><p>Creates a deep copy of a value. All tables (and their metatables) are reconstructed from scratch. Functions are still shared, however. </p> <div class="mw-heading mw-heading4"><h4 id="mw.getCurrentFrame">mw.getCurrentFrame</h4></div> <p><code>mw.getCurrentFrame()</code> </p><p>Returns the current <a href="#frame-object">frame object</a>, typically the frame object from the most recent <code>#invoke</code>. </p> <div class="mw-heading mw-heading4"><h4 id="mw.incrementExpensiveFunctionCount">mw.incrementExpensiveFunctionCount</h4></div> <p><code>mw.incrementExpensiveFunctionCount()</code> </p><p>Adds one to the "expensive parser function" count, and throws an exception if it exceeds the limit (see <code><a href="/wiki/Special:MyLanguage/Manual:$wgExpensiveParserFunctionLimit" title="Special:MyLanguage/Manual:$wgExpensiveParserFunctionLimit">$wgExpensiveParserFunctionLimit</a><span style="display:none"><a href="/wiki/Manual:$wgExpensiveParserFunctionLimit" title="Manual:$wgExpensiveParserFunctionLimit"> </a></span></code>). </p> <div class="mw-heading mw-heading4"><h4 id="mw.isSubsting">mw.isSubsting</h4></div> <p><code>mw.isSubsting()</code> </p><p>Returns true if the current <code>#invoke</code> is being <a href="/wiki/Special:MyLanguage/Manual:Substitution" title="Special:MyLanguage/Manual:Substitution">substed</a>, <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">false</span></code> otherwise. See <a href="#Returning_text">Returning text</a> above for discussion on differences when substing versus not substing. </p> <div class="mw-heading mw-heading4"><h4 id="mw.loadData">mw.loadData</h4></div> <p><code style="white-space:nowrap">mw.loadData( module )</code> </p><p>Sometimes a module needs large tables of data; for example, a general-purpose module to convert units of measure might need a large table of recognized units and their conversion factors. And sometimes these modules will be used many times in one page. Parsing the large data table for every <code>{{#invoke:}}</code> can use a significant amount of time. To avoid this issue, <code>mw.loadData()</code> is provided. </p><p><code>mw.loadData</code> works like <code><a href="#require">require()</a></code>, with the following differences: </p> <ul><li>The loaded module is evaluated only once per page, rather than once per <code>{{#invoke:}}</code> call.</li> <li>The loaded module is not recorded in <code><a href="#package.loaded">package.loaded</a></code>.</li> <li>The value returned from the loaded module must be a table. Other data types are not supported.</li> <li>The returned table (and all subtables) may contain only booleans, numbers, strings, and other tables. Other data types, particularly functions, are not allowed.</li> <li>The returned table (and all subtables) may not have a <a href="#Metatables">metatable</a>.</li> <li>All table keys must be booleans, numbers, or strings.</li> <li>The table actually returned by <code>mw.loadData()</code> has metamethods that provide read-only access to the table returned by the module. Since it does not contain the data directly, <code><a href="#pairs">pairs()</a></code> and <code><a href="#ipairs">ipairs()</a></code> will work but other methods, including <code><a href="#Length_operator">#value</a></code>, <code style="white-space:nowrap"><a href="#next">next()</a></code>, and the functions in the <a href="#Table_library">Table library</a>, will not work correctly.</li></ul> <p>The hypothetical unit-conversion module mentioned above might store its code in "Module:Convert" and its data in "Module:Convert/data", and "Module:Convert" would use <code style="white-space:nowrap">local data = mw.loadData( 'Module:Convert/data' )</code> to efficiently load the data. </p> <div class="mw-heading mw-heading4"><h4 id="mw.loadJsonData">mw.loadJsonData</h4></div> <p><code style="white-space:nowrap">mw.loadJsonData( page )</code> </p><p>This is the same as <code>mw.loadData()</code> above, except it loads data from JSON pages rather than Lua tables. The JSON content must be an array or object. See also <code><a href="#mw.text.jsonDecode">mw.text.jsonDecode()</a></code>. </p> <div class="mw-heading mw-heading4"><h4 id="mw.dumpObject">mw.dumpObject</h4></div> <p><code style="white-space:nowrap">mw.dumpObject( object )</code> </p><p>Serializes <code>object</code> to a human-readable representation, then returns the resulting string. </p> <div class="mw-heading mw-heading4"><h4 id="mw.log">mw.log</h4></div> <p><span class="anchor" id="print"></span> <code style="white-space:nowrap">mw.log( ... )</code> </p><p>Passes the arguments to <a href="#mw.allToString">mw.allToString()</a>, then appends the resulting string to the log buffer. </p><p>In the debug console, the function <code>print()</code> is an alias for this function. </p> <div class="mw-heading mw-heading4"><h4 id="mw.logObject">mw.logObject</h4></div> <p><code style="white-space:nowrap">mw.logObject( object )</code> <br /> <code style="white-space:nowrap">mw.logObject( object, prefix )</code> </p><p>Calls <a href="#mw.dumpObject">mw.dumpObject()</a> and appends the resulting string to the log buffer. If <code>prefix</code> is given, it will be added to the log buffer followed by an equals sign before the serialized string is appended (i.e. the logged text will be "prefix = object-string"). <span class="anchor" id="frame-object"></span> </p> <div class="mw-heading mw-heading3"><h3 id="Frame_object">Frame object</h3></div> <p>The frame object is the interface to the parameters passed to <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" dir="ltr">{{#invoke:}}</code>, and to the parser. </p><p>Note that there is no frame library, and there is no global variable named <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="n">frame</span></code>. A frame object is typically obtained by being passed as a parameter to the function called by <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" dir="ltr">{{#invoke:}}</code>, and can also be obtained from <code><a href="#mw.getCurrentFrame">mw.getCurrentFrame()</a></code>. </p> <div class="mw-heading mw-heading4"><h4 id="frame.args">frame.args</h4></div> <p>A table for accessing the arguments passed to the frame. For example, if a module is called from wikitext with </p> <div class="mw-highlight mw-highlight-lang-text mw-content-ltr" dir="ltr"><pre><span></span>{{#invoke:module|function|arg1|arg2|name=arg3}} </pre></div> <p>then <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="n">frame</span><span class="p">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span></code> will return <code>"arg1"</code>, <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="n">frame</span><span class="p">.</span><span class="n">args</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span></code> will return <code>"arg2"</code>, and <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="n">frame</span><span class="p">.</span><span class="n">args</span><span class="p">[</span><span class="s1">&#39;name&#39;</span><span class="p">]</span></code> (or <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="n">frame</span><span class="p">.</span><span class="n">args</span><span class="p">.</span><span class="n">name</span></code>) will return <code>"arg3"</code>. It is also possible to iterate over arguments using <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="nb">pairs</span><span class="p">(</span> <span class="n">frame</span><span class="p">.</span><span class="n">args</span> <span class="p">)</span></code> or <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="nb">ipairs</span><span class="p">(</span> <span class="n">frame</span><span class="p">.</span><span class="n">args</span> <span class="p">)</span></code>. However, due to how Lua implements table iterators, iterating over arguments will return them in an unspecified order, and there's no way to know the original order as they appear in wikitext. </p><p>Note that values in this table are always strings; <code><a href="#tonumber">tonumber()</a></code> may be used to convert them to numbers, if necessary. Keys, however, are numbers even if explicitly supplied in the invocation: <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" dir="ltr">{{#invoke:module|function|1|2=2}}</code> gives string values <code>"1"</code> and <code>"2"</code> indexed by numeric keys <code>1</code> and <code>2</code>. </p><p>As in MediaWiki template invocations, named arguments will have leading and trailing whitespace removed from both the name and the value before they are passed to Lua, whereas unnamed arguments will not have whitespace stripped. </p><p>For performance reasons, <code>frame.args</code> uses a metatable, rather than directly containing the arguments. Argument values are requested from MediaWiki on demand. This means that most other table methods will not work correctly, including <code><a href="#Length_operator">#frame.args</a></code>, <code style="white-space:nowrap"><a href="#next">next</a>( frame.args )</code>, and the functions in the <a href="#Table_library">Table library</a>. </p><p>If preprocessor syntax such as template invocations and triple-brace arguments are included within an argument to <code>#invoke</code>, they will not be expanded, after being passed to Lua, until their values are being requested in Lua. If certain special tags written in XML notation, such as <code class="mw-highlight" style="white-space:nowrap"><span class="p">&#8206;&lt;</span><span class="nt">pre</span><span class="p">&gt;</span></code>, <code class="mw-highlight" style="white-space:nowrap"><span class="p">&#8206;&lt;</span><span class="nt">nowiki</span><span class="p">&gt;</span></code>, <code class="mw-highlight" style="white-space:nowrap"><span class="p">&#8206;&lt;</span><span class="nt">gallery</span><span class="p">&gt;</span></code> and <code class="mw-highlight" style="white-space:nowrap"><span class="p">&#8206;&lt;</span><span class="nt">ref</span><span class="p">&gt;</span></code>, are included as arguments to <code>#invoke</code>, then these tags will be converted to "<a href="/wiki/Strip_marker" title="Strip marker">strip markers</a>" — special strings which begin with a delete character (ASCII 127), to be replaced with HTML after they are returned from #invoke. </p> <div class="mw-heading mw-heading4"><h4 id="frame:callParserFunction">frame:callParserFunction</h4></div> <style data-mw-deduplicate="TemplateStyles:r6219282">.mw-parser-output .plainlist ul{line-height:inherit;list-style:none none;margin:0}.mw-parser-output .plainlist ul li{margin-bottom:0}</style><div class="plainlist"><ul><li><code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="n">frame</span><span class="p">:</span><span class="n">callParserFunction</span><span class="p">(</span> <span class="n">name</span><span class="p">,</span> <span class="n">args</span> <span class="p">)</span></code></li><li><code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="n">frame</span><span class="p">:</span><span class="n">callParserFunction</span><span class="p">(</span> <span class="n">name</span><span class="p">,</span> <span class="p">...</span> <span class="p">)</span></code></li><li><code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><span class="n">frame</span><span class="p">:</span><span class="n">callParserFunction</span><span class="p">{</span> <span class="n">name</span> <span class="o">=</span> <span class="n">string</span><span class="p">,</span> <span class="n">args</span> <span class="o">=</span> <span class="n">table</span> <span class="p">}</span></code></li></ul></div> <dl><dd><i>Note the use of <a href="#named_arguments">named arguments</a>.</i></dd></dl> <p>Call a <a href="/wiki/Special:MyLanguage/Help:Magic_words#Parser_functions" title="Special:MyLanguage/Help:Magic words">parser function</a>, returning an appropriate string. This is preferable to <code>frame:preprocess</code>, but whenever possible, native Lua functions or Scribunto library functions should be preferred to this interface. </p><p>The following calls are approximately equivalent to the indicated wikitext: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">-- {{ns:0}}</span> <span class="n">frame</span><span class="p">:</span><span class="n">callParserFunction</span><span class="p">(</span> <span class="s1">&#39;ns&#39;</span><span class="p">,</span> <span class="p">{</span> <span class="mi">0</span> <span class="p">}</span> <span class="p">)</span> <span class="n">frame</span><span class="p">:</span><span class="n">callParserFunction</span><span class="p">(</span> <span class="s1">&#39;ns&#39;</span><span class="p">,</span> <span class="mi">0</span> <span class="p">)</span> <span class="n">frame</span><span class="p">:</span><span class="n">callParserFunction</span><span class="p">{</span> <span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;ns&#39;</span><span class="p">,</span> <span class="n">args</span> <span class="o">=</span> <span class="p">{</span> <span class="mi">0</span> <span class="p">}</span> <span class="p">}</span> <span class="c1">-- {{#tag:nowiki|some text}}</span> <span class="n">frame</span><span class="p">:</span><span class="n">callParserFunction</span><span class="p">(</span> <span class="s1">&#39;#tag&#39;</span><span class="p">,</span> <span class="p">{</span> <span class="s1">&#39;nowiki&#39;</span><span class="p">,</span> <span class="s1">&#39;some text&#39;</span> <span class="p">}</span> <span class="p">)</span> <span class="n">frame</span><span class="p">:</span><span class="n">callParserFunction</span><span class="p">(</span> <span class="s1">&#39;#tag&#39;</span><span class="p">,</span> <span class="s1">&#39;nowiki&#39;</span><span class="p">,</span> <span class="s1">&#39;some text&#39;</span> <span class="p">)</span> <span class="n">frame</span><span class="p">:</span><span class="n">callParserFunction</span><span class="p">(</span> <span class="s1">&#39;#tag:nowiki&#39;</span><span class="p">,</span> <span class="s1">&#39;some text&#39;</span> <span class="p">)</span> <span class="n">frame</span><span class="p">:</span><span class="n">callParserFunction</span><span class="p">{</span> <span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;#tag&#39;</span><span class="p">,</span> <span class="n">args</span> <span class="o">=</span> <span class="p">{</span> <span class="s1">&#39;nowiki&#39;</span><span class="p">,</span> <span class="s1">&#39;some text&#39;</span> <span class="p">}</span> <span class="p">}</span> <span class="c1">-- {{#tag:ref|some text|name=foo|group=bar}}</span> <span class="n">frame</span><span class="p">:</span><span class="n">callParserFunction</span><span class="p">(</span> <span class="s1">&#39;#tag&#39;</span><span class="p">,</span> <span class="p">{</span> <span class="s1">&#39;ref&#39;</span><span class="p">,</span> <span class="s1">&#39;some text&#39;</span><span class="p">,</span> <span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;foo&#39;</span><span class="p">,</span> <span class="n">group</span> <span class="o">=</span> <span class="s1">&#39;bar&#39;</span> <span class="p">}</span> <span class="p">)</span> </pre></div> <p>Note that, as with <a href="#frame:expandTemplate">frame:expandTemplate()</a>, the function name and arguments are not preprocessed before being passed to the parser function. </p> <div class="mw-heading mw-heading4"><h4 id="frame:expandTemplate">frame:expandTemplate</h4></div> <p><code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><span class="n">frame</span><span class="p">:</span><span class="n">expandTemplate</span><span class="p">{</span> <span class="n">title</span> <span class="o">=</span> <span class="n">title</span><span class="p">,</span> <span class="n">args</span> <span class="o">=</span> <span class="n">table</span> <span class="p">}</span></code> </p> <dl><dd><i>Note the use of <a href="#named_arguments">named arguments</a>.</i></dd></dl> <p>This is equivalent to a call to <a href="#frame:callParserFunction">frame:callParserFunction()</a> with function name <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="s1">&#39;msg&#39;</span></code> (see <a href="/wiki/Special:MyLanguage/Help:Magic_words#Transclusion_modifiers" title="Special:MyLanguage/Help:Magic words">Help:Magic words#Transclusion modifiers</a>) and with <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="n">title</span></code> prepended to <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="n">args</span></code>. </p><p>This is transclusion. The call: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="n">frame</span><span class="p">:</span><span class="n">expandTemplate</span><span class="p">{</span> <span class="n">title</span> <span class="o">=</span> <span class="s1">&#39;template&#39;</span><span class="p">,</span> <span class="n">args</span> <span class="o">=</span> <span class="p">{</span> <span class="s1">&#39;arg1&#39;</span><span class="p">,</span> <span class="s1">&#39;arg2&#39;</span><span class="p">,</span> <span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;arg3&#39;</span> <span class="p">}</span> <span class="p">}</span> </pre></div> <p>does roughly the same thing from Lua that <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" dir="ltr">{{template|arg1|arg2|name=arg3}}</code> does in wikitext. As in transclusion, if the passed title does not contain a namespace prefix it will be assumed to be in the Template: namespace. </p><p>Note that the title and arguments are not preprocessed before being passed into the template: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">-- This is roughly equivalent to wikitext like {{template|{{!}}}}</span> <span class="n">frame</span><span class="p">:</span><span class="n">expandTemplate</span><span class="p">{</span> <span class="n">title</span> <span class="o">=</span> <span class="s1">&#39;template&#39;</span><span class="p">,</span> <span class="n">args</span> <span class="o">=</span> <span class="p">{</span> <span class="s1">&#39;|&#39;</span> <span class="p">}</span> <span class="p">}</span> <span class="n">frame</span><span class="p">:</span><span class="n">callParserFunction</span><span class="p">{</span> <span class="s1">&#39;msg&#39;</span><span class="p">,</span> <span class="p">{</span> <span class="s1">&#39;template&#39;</span><span class="p">,</span> <span class="s1">&#39;|&#39;</span> <span class="p">}</span> <span class="p">}</span> <span class="c1">-- This is roughly equivalent to wikitext like {{template|{{((}}!{{))}}}}</span> <span class="n">frame</span><span class="p">:</span><span class="n">expandTemplate</span><span class="p">{</span> <span class="n">title</span> <span class="o">=</span> <span class="s1">&#39;template&#39;</span><span class="p">,</span> <span class="n">args</span> <span class="o">=</span> <span class="p">{</span> <span class="s1">&#39;{{!}}&#39;</span> <span class="p">}</span> <span class="p">}</span> <span class="n">frame</span><span class="p">:</span><span class="n">callParserFunction</span><span class="p">{</span> <span class="s1">&#39;msg&#39;</span><span class="p">,</span> <span class="p">{</span> <span class="s1">&#39;template&#39;</span><span class="p">,</span> <span class="s1">&#39;{{!}}&#39;</span> <span class="p">}</span> <span class="p">}</span> </pre></div> <div class="mw-heading mw-heading4"><h4 id="frame:extensionTag">frame:extensionTag</h4></div> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r6219282"><div class="plainlist"><ul><li><code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="n">frame</span><span class="p">:</span><span class="n">extensionTag</span><span class="p">(</span> <span class="n">name</span><span class="p">,</span> <span class="n">content</span><span class="p">,</span> <span class="n">args</span> <span class="p">)</span></code></li><li><code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><span class="n">frame</span><span class="p">:</span><span class="n">extensionTag</span><span class="p">{</span> <span class="n">name</span> <span class="o">=</span> <span class="n">string</span><span class="p">,</span> <span class="n">content</span> <span class="o">=</span> <span class="n">string</span><span class="p">,</span> <span class="n">args</span> <span class="o">=</span> <span class="n">table_or_string</span> <span class="p">}</span></code></li></ul></div> <p>This is equivalent to a call to <a href="#frame:callParserFunction">frame:callParserFunction()</a> with function name <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="s1">&#39;#tag&#39;</span></code> (see <a href="/wiki/Special:MyLanguage/Help:Magic_words#Miscellaneous" title="Special:MyLanguage/Help:Magic words">Help:Magic_words#Miscellaneous</a>) and with <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="n">name</span></code> and <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="n">content</span></code> prepended to <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="n">args</span></code>. </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">-- These are equivalent</span> <span class="n">frame</span><span class="p">:</span><span class="n">extensionTag</span><span class="p">(</span> <span class="s1">&#39;ref&#39;</span><span class="p">,</span> <span class="s1">&#39;some text&#39;</span><span class="p">,</span> <span class="p">{</span> <span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;foo&#39;</span><span class="p">,</span> <span class="n">group</span> <span class="o">=</span> <span class="s1">&#39;bar&#39;</span> <span class="p">}</span> <span class="p">)</span> <span class="n">frame</span><span class="p">:</span><span class="n">extensionTag</span><span class="p">{</span> <span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;ref&#39;</span><span class="p">,</span> <span class="n">content</span> <span class="o">=</span> <span class="s1">&#39;some text&#39;</span><span class="p">,</span> <span class="n">args</span> <span class="o">=</span> <span class="p">{</span> <span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;foo&#39;</span><span class="p">,</span> <span class="n">group</span> <span class="o">=</span> <span class="s1">&#39;bar&#39;</span> <span class="p">}</span> <span class="p">}</span> <span class="n">frame</span><span class="p">:</span><span class="n">callParserFunction</span><span class="p">(</span> <span class="s1">&#39;#tag&#39;</span><span class="p">,</span> <span class="p">{</span> <span class="s1">&#39;ref&#39;</span> <span class="p">,</span> <span class="s1">&#39;some text&#39;</span><span class="p">,</span> <span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;foo&#39;</span><span class="p">,</span> <span class="n">group</span> <span class="o">=</span> <span class="s1">&#39;bar&#39;</span> <span class="p">}</span> <span class="p">)</span> <span class="c1">-- These are equivalent</span> <span class="n">frame</span><span class="p">:</span><span class="n">extensionTag</span><span class="p">{</span> <span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;ref&#39;</span><span class="p">,</span> <span class="n">content</span> <span class="o">=</span> <span class="s1">&#39;some text&#39;</span><span class="p">,</span> <span class="n">args</span> <span class="o">=</span> <span class="p">{</span> <span class="s1">&#39;some other text&#39;</span> <span class="p">}</span> <span class="p">}</span> <span class="n">frame</span><span class="p">:</span><span class="n">callParserFunction</span><span class="p">(</span> <span class="s1">&#39;#tag&#39;</span><span class="p">,</span> <span class="p">{</span> <span class="s1">&#39;ref&#39;</span><span class="p">,</span> <span class="s1">&#39;some text&#39;</span><span class="p">,</span> <span class="s1">&#39;some other text&#39;</span> <span class="p">}</span> <span class="p">)</span> </pre></div> <div class="mw-heading mw-heading4"><h4 id="frame:getParent">frame:getParent</h4></div> <p><code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="n">frame</span><span class="p">:</span><span class="n">getParent</span><span class="p">()</span></code> </p><p>Called on the frame created by <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" dir="ltr">{{#invoke:}}</code>, returns the frame for the page that called <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" dir="ltr">{{#invoke:}}</code>. Called on that frame, returns nil. </p><p>For instance, if the template <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" dir="ltr">{{Example}}</code> contains the code <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" dir="ltr">{{#invoke:ModuleName|FunctionName|A|B}}</code>, and a page transcludes that template with the code <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" dir="ltr">{{Example|C|D}}</code>, then in <i>Module:ModuleName</i>, calling <code>frame.args[1]</code> and <code>frame.args[2]</code> returns <code>"A"</code> and <code>"B"</code>, and calling <code>frame:getParent().args[1]</code> and <code>frame:getParent().args[2]</code> returns <code>"C"</code> and <code>"D"</code>, with <code>frame</code> being the first argument in the function call. </p> <div class="mw-heading mw-heading4"><h4 id="frame:getTitle">frame:getTitle</h4></div> <p><code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="n">frame</span><span class="p">:</span><span class="n">getTitle</span><span class="p">()</span></code> </p><p>Returns the title associated with the frame as a string. For the frame created by <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" dir="ltr">{{#invoke:}}</code>, this is the title of the module invoked. </p> <div class="mw-heading mw-heading4"><h4 id="frame:newChild">frame:newChild</h4></div> <p><code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><span class="n">frame</span><span class="p">:</span><span class="n">newChild</span><span class="p">{</span> <span class="n">title</span> <span class="o">=</span> <span class="n">title</span><span class="p">,</span> <span class="n">args</span> <span class="o">=</span> <span class="n">table</span> <span class="p">}</span></code> </p> <dl><dd><i>Note the use of <a href="#named_arguments">named arguments</a>.</i></dd></dl> <p>Create a new <a href="#frame-object">Frame object</a> that is a child of the current frame, with optional arguments and title. </p><p>This is mainly intended for use in modules that call other modules whose name is defined by the caller (e.g. <code>{{<a href="https://en.wikipedia.org/wiki/Module:Params" class="extiw" title="w:Module:Params">#invoke:params</a>|<a href="https://en.wikipedia.org/wiki/Module:Params#concat_and_invoke" class="extiw" title="w:Module:Params">concat_and_invoke</a>}}</code>), or in the debug console for testing functions that would normally be called by <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" dir="ltr">{{#invoke:}}</code>. The number of frames that may be created at any one time is limited. </p> <div class="mw-heading mw-heading4"><h4 id="frame:preprocess">frame:preprocess</h4></div> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r6219282"><div class="plainlist"><ul><li><code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="n">frame</span><span class="p">:</span><span class="n">preprocess</span><span class="p">(</span> <span class="n">string</span> <span class="p">)</span></code></li><li><code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><span class="n">frame</span><span class="p">:</span><span class="n">preprocess</span><span class="p">{</span> <span class="n">text</span> <span class="o">=</span> <span class="n">string</span> <span class="p">}</span></code></li></ul></div> <p>This expands wikitext in the context of the frame, i.e. templates, parser functions, and parameters such as <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" dir="ltr">{{{1}}}</code> are expanded, and returns the expanded text. Certain special tags written in XML-style notation, such as <code class="mw-highlight" style="white-space:nowrap"><span class="p">&#8206;&lt;</span><span class="nt">pre</span><span class="p">&gt;</span></code>, <code class="mw-highlight" style="white-space:nowrap"><span class="p">&#8206;&lt;</span><span class="nt">nowiki</span><span class="p">&gt;</span></code>, <code class="mw-highlight" style="white-space:nowrap"><span class="p">&#8206;&lt;</span><span class="nt">gallery</span><span class="p">&gt;</span></code> and <code class="mw-highlight" style="white-space:nowrap"><span class="p">&#8206;&lt;</span><span class="nt">ref</span><span class="p">&gt;</span></code>, will be replaced with "<a href="/wiki/Special:MyLanguage/strip_marker" title="Special:MyLanguage/strip marker">strip markers</a>" — special strings which begin with a delete character (ASCII 127), to be replaced with HTML after they are returned from <code>#invoke</code>. </p><p>If you are expanding a single template, use <code><a href="#frame:expandTemplate">frame:expandTemplate</a></code> instead of trying to construct a wikitext string to pass to this method. It's faster and less prone to error if the arguments contain pipe characters or other wikimarkup. </p><p>If you are expanding a single parser function, use <code><a href="#frame:callParserFunction">frame:callParserFunction</a></code> for the same reasons. </p> <div class="mw-heading mw-heading4"><h4 id="frame:getArgument">frame:getArgument</h4></div> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r6219282"><div class="plainlist"><ul><li><code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="n">frame</span><span class="p">:</span><span class="n">getArgument</span><span class="p">(</span> <span class="n">arg</span> <span class="p">)</span></code></li><li><code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><span class="n">frame</span><span class="p">:</span><span class="n">getArgument</span><span class="p">{</span> <span class="n">name</span> <span class="o">=</span> <span class="n">arg</span> <span class="p">}</span></code></li></ul></div> <p>Gets an object for the specified argument, or nil if the argument is not provided. </p><p>The returned object has one method, <code>object:expand()</code>, that returns the expanded wikitext for the argument. </p> <div class="mw-heading mw-heading4"><h4 id="frame:newParserValue">frame:newParserValue</h4></div> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r6219282"><div class="plainlist"><ul><li><code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="n">frame</span><span class="p">:</span><span class="n">newParserValue</span><span class="p">(</span> <span class="n">text</span> <span class="p">)</span></code></li><li><code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><span class="n">frame</span><span class="p">:</span><span class="n">newParserValue</span><span class="p">{</span> <span class="n">text</span> <span class="o">=</span> <span class="n">text</span> <span class="p">}</span></code></li></ul></div> <p>Returns an object with one method, <code>object:expand()</code>, that returns the result of <code style="white-space:nowrap"><a href="#frame:preprocess">frame:preprocess</a>( text )</code>. </p> <div class="mw-heading mw-heading4"><h4 id="frame:newTemplateParserValue">frame:newTemplateParserValue</h4></div> <p><code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><span class="n">frame</span><span class="p">:</span><span class="n">newTemplateParserValue</span><span class="p">{</span> <span class="n">title</span> <span class="o">=</span> <span class="n">title</span><span class="p">,</span> <span class="n">args</span> <span class="o">=</span> <span class="n">table</span> <span class="p">}</span></code> </p> <dl><dd><i>Note the use of <a href="#named_arguments">named arguments</a>.</i></dd></dl> <p>Returns an object with one method, <code>object:expand()</code>, that returns the result of <code><a href="#frame:expandTemplate">frame:expandTemplate</a></code> called with the given arguments. </p> <div class="mw-heading mw-heading4"><h4 id="frame:argumentPairs">frame:argumentPairs</h4></div> <p><code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="n">frame</span><span class="p">:</span><span class="n">argumentPairs</span><span class="p">()</span></code> </p><p>Same as <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="nb">pairs</span><span class="p">(</span> <span class="n">frame</span><span class="p">.</span><span class="n">args</span> <span class="p">)</span></code>. Included for backwards compatibility. </p> <div class="mw-heading mw-heading3"><h3 id="Hash_library">Hash library</h3></div> <div class="mw-heading mw-heading4"><h4 id="mw.hash.hashValue">mw.hash.hashValue</h4></div> <p><code style="white-space:nowrap">mw.hash.hashValue( algo, value )</code> </p><p>Hashes a string value with the specified algorithm. Valid algorithms may be fetched using <a href="#mw.hash.listAlgorithms">mw.hash.listAlgorithms()</a>. </p> <div class="mw-heading mw-heading4"><h4 id="mw.hash.listAlgorithms">mw.hash.listAlgorithms</h4></div> <p><code style="white-space:nowrap">mw.hash.listAlgorithms()</code> </p><p>Returns a list of supported hashing algorithms, for use in <a href="#mw.hash.hashValue">mw.hash.hashValue()</a>. </p> <div class="mw-heading mw-heading3"><h3 id="HTML_library">HTML library</h3></div> <p><code>mw.html</code> is a fluent interface for building complex HTML from Lua. On many Wikimedia wikis this was formerly implemented in <code>Module:HtmlBuilder</code>. A mw.html object can be created using <code><a href="#mw.html.create">mw.html.create</a></code>. </p><p><span class="anchor" id="mw.html-object"></span> Functions documented as <code>mw.html.<var>name</var></code> are available on the global <code>mw.html</code> table; functions documented as <code>mw.html:<var>name</var></code> and <code>html:<var>name</var></code> are methods of an mw.html object (see <code><a href="#mw.html.create">mw.html.create</a></code>). </p><p>A basic example could look like this: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="kd">local</span> <span class="n">div</span> <span class="o">=</span> <span class="n">mw</span><span class="p">.</span><span class="n">html</span><span class="p">.</span><span class="n">create</span><span class="p">(</span> <span class="s1">&#39;div&#39;</span> <span class="p">)</span> <span class="n">div</span> <span class="p">:</span><span class="n">attr</span><span class="p">(</span> <span class="s1">&#39;id&#39;</span><span class="p">,</span> <span class="s1">&#39;testdiv&#39;</span> <span class="p">)</span> <span class="p">:</span><span class="n">css</span><span class="p">(</span> <span class="s1">&#39;width&#39;</span><span class="p">,</span> <span class="s1">&#39;100%&#39;</span> <span class="p">)</span> <span class="p">:</span><span class="n">wikitext</span><span class="p">(</span> <span class="s1">&#39;Some text&#39;</span> <span class="p">)</span> <span class="p">:</span><span class="n">tag</span><span class="p">(</span> <span class="s1">&#39;hr&#39;</span> <span class="p">)</span> <span class="kr">return</span> <span class="nb">tostring</span><span class="p">(</span> <span class="n">div</span> <span class="p">)</span> <span class="c1">-- Output: &lt;div id=&quot;testdiv&quot; style=&quot;width:100%;&quot;&gt;Some text&lt;hr /&gt;&lt;/div&gt;</span> </pre></div> <div class="mw-heading mw-heading4"><h4 id="mw.html.create">mw.html.create</h4></div> <p><code style="white-space:nowrap">mw.html.create( tagName, args )</code> </p><p>Creates a new mw.html object containing a <code>tagName</code> html element. You can also pass an empty string or nil as <code>tagName</code> in order to create an empty mw.html object. </p><p><code>args</code> can be a table with the following keys: </p> <ul><li><code>args.selfClosing</code>: Force the current tag to be self-closing, even if mw.html doesn't recognize it as self-closing</li> <li><code>args.parent</code>: Parent of the current mw.html instance (intended for internal usage)</li></ul> <div class="mw-heading mw-heading4"><h4 id="mw.html:node">mw.html:node</h4></div> <p><code style="white-space:nowrap"><a href="#mw.html-object">html</a>:node( builder )</code> </p><p>Appends a child mw.html (<code>builder</code>) node to the current mw.html instance. If a nil parameter is passed, this is a no-op. A (<code>builder</code>) node is a string representation of an html element. </p> <div class="mw-heading mw-heading4"><h4 id="mw.html:wikitext">mw.html:wikitext</h4></div> <p><code style="white-space:nowrap"><a href="#mw.html-object">html</a>:wikitext( ... )</code> </p><p>Appends an undetermined number of wikitext strings to the mw.html object. </p><p>Note that this stops at the first <i>nil</i> item. </p><p>Basic wikitext will get parsed, like HTML, links, bold, lists or tables. However, templates and parser functions won't be evaluated if they are passed directly to this function, unless they came from template parameters. Those will be rendered in plain text instead. To evaluate them, they'll have to be passed through <a href="#frame:preprocess">frame:preprocess</a>. </p> <div class="mw-heading mw-heading4"><h4 id="mw.html:newline">mw.html:newline</h4></div> <p><code style="white-space:nowrap"><a href="#mw.html-object">html</a>:newline()</code> </p><p>Appends a newline to the mw.html object. Useful when used before and after <a href="#mw.html:wikitext">mw.html:wikitext()</a>, when the wikitext contains lists or tables, whose syntax only has a special meaning when present at the start of a line. </p> <div class="mw-heading mw-heading4"><h4 id="mw.html:tag">mw.html:tag</h4></div> <p><code style="white-space:nowrap"><a href="#mw.html-object">html</a>:tag( tagName, args )</code> </p><p>Appends a new child node with the given <code>tagName</code> to the builder, and returns a mw.html instance representing that new node. The <code>args</code> parameter is identical to that of <code><a href="#mw.html.create">mw.html.create</a></code> </p><p>Note that contrarily to other methods such as <code><a href="#mw.html:node">html:node()</a></code>, this method doesn't return the current mw.html instance, but the mw.html instance of the newly inserted tag. Make sure to use <a href="#mw.html:done"><code>html:done()</code></a> to go up to the parent mw.html instance, or <a href="#mw.html:allDone"><code>html:allDone()</code></a> if you have nested tags on several levels. </p> <div class="mw-heading mw-heading4"><h4 id="mw.html:attr">mw.html:attr</h4></div> <p><code style="white-space:nowrap"><a href="#mw.html-object">html</a>:attr( name, value )</code> <br /> <code style="white-space:nowrap"><a href="#mw.html-object">html</a>:attr( table )</code> </p><p>Set an HTML attribute with the given <code>name</code> and <code>value</code> on the node. Alternatively a table holding name-&gt;value pairs of attributes to set can be passed. In the first form, a value of nil causes any attribute with the given name to be unset if it was previously set. </p> <div class="mw-heading mw-heading4"><h4 id="mw.html:getAttr">mw.html:getAttr</h4></div> <p><code style="white-space:nowrap"><a href="#mw.html-object">html</a>:getAttr( name )</code> </p><p>Get the value of a html attribute previously set using <a href="#mw.html:attr"><code>html:attr()</code></a> with the given <code>name</code>. </p> <div class="mw-heading mw-heading4"><h4 id="mw.html:addClass">mw.html:addClass</h4></div> <p><code style="white-space:nowrap"><a href="#mw.html-object">html</a>:addClass( class )</code> </p><p>Adds a class name to the node's class attribute. If a nil parameter is passed, this is a no-op. </p> <div class="mw-heading mw-heading4"><h4 id="mw.html:css">mw.html:css</h4></div> <p><code style="white-space:nowrap"><a href="#mw.html-object">html</a>:css( name, value )</code> <br /> <code style="white-space:nowrap"><a href="#mw.html-object">html</a>:css( table )</code> </p><p>Set a CSS property with the given <code>name</code> and <code>value</code> on the node. Alternatively a table holding name-&gt;value pairs of properties to set can be passed. In the first form, a value of nil causes any property with the given name to be unset if it was previously set. </p> <div class="mw-heading mw-heading4"><h4 id="mw.html:cssText">mw.html:cssText</h4></div> <p><code style="white-space:nowrap"><a href="#mw.html-object">html</a>:cssText( css )</code> </p><p>Add some raw <code>css</code> to the node's style attribute. If a nil parameter is passed, this is a no-op. </p> <div class="mw-heading mw-heading4"><h4 id="mw.html:done">mw.html:done</h4></div> <p><code style="white-space:nowrap"><a href="#mw.html-object">html</a>:done()</code> </p><p>Returns the parent node under which the current node was created. Like jQuery.end, this is a convenience function to allow the construction of several child nodes to be chained together into a single statement. </p> <div class="mw-heading mw-heading4"><h4 id="mw.html:allDone">mw.html:allDone</h4></div> <p><code style="white-space:nowrap"><a href="#mw.html-object">html</a>:allDone()</code> </p><p>Like <a href="#mw.html:done"><code>html:done()</code></a>, but traverses all the way to the root node of the tree and returns it. </p> <div class="mw-heading mw-heading3"><h3 id="Language_library">Language library</h3></div> <p>Language codes are described at <a href="/wiki/Special:MyLanguage/Language_code" title="Special:MyLanguage/Language code">language code</a>. Many of MediaWiki's language codes are similar to <a href="https://en.wikipedia.org/wiki/IETF_language_tag" class="extiw" title="w:IETF language tag">IETF language tags</a>, but not all MediaWiki language codes are valid IETF tags or vice versa. </p><p><span class="anchor" id="mw.language-object"></span> Functions documented as <code>mw.language.<var>name</var></code> are available on the global <code>mw.language</code> table; functions documented as <code>mw.language:<var>name</var></code> and <code>lang:<var>name</var></code> are methods of a language object (see <a href="#mw.language.new"><code>mw.language.new</code></a> or <a href="#mw.language.getContentLanguage"><code>mw.language.getContentLanguage</code></a>). </p> <div class="mw-heading mw-heading4"><h4 id="mw.language.fetchLanguageName">mw.language.fetchLanguageName</h4></div> <p><code style="white-space:nowrap">mw.language.fetchLanguageName( code, inLanguage )</code> </p><p>The full name of the language for the given language code: native name (language autonym) by default, name translated in target language if a value is given for <var>inLanguage</var>. </p> <div class="mw-heading mw-heading4"><h4 id="mw.language.fetchLanguageNames">mw.language.fetchLanguageNames</h4></div> <p><code style="white-space:nowrap">mw.language.fetchLanguageNames()</code> <br /> <code style="white-space:nowrap">mw.language.fetchLanguageNames( inLanguage )</code> <br /> <code style="white-space:nowrap">mw.language.fetchLanguageNames( inLanguage, include )</code> </p><p>Fetch the list of languages known to MediaWiki, returning a table mapping language code to language name. </p><p>By default the name returned is the language autonym; passing a language code for <var>inLanguage</var> returns all names in that language. </p><p>By default, only language names known to MediaWiki are returned; passing <code>'all'</code> for <var>include</var> will return all available languages (from <a href="/wiki/Special:MyLanguage/Extension:CLDR" title="Special:MyLanguage/Extension:CLDR">Extension:CLDR</a><span style="display:none"><a href="/wiki/Extension:CLDR" title="Extension:CLDR"> </a></span>), while passing <code>'mwfile'</code> will include only languages having customized messages included with MediaWiki core or enabled extensions. To explicitly select the default, <code>'mw'</code> may be passed. </p> <div class="mw-heading mw-heading4"><h4 id="mw.language.getContentLanguage">mw.language.getContentLanguage</h4></div> <p><code>mw.language.getContentLanguage()</code> <br /> <code>mw.getContentLanguage()</code> </p><p>Returns a new language object for the wiki's default content language. </p> <div class="mw-heading mw-heading4"><h4 id="mw.language.getFallbacksFor">mw.language.getFallbacksFor</h4></div> <figure class="mw-default-size" typeof="mw:File/Thumb"><a href="/wiki/File:MediaWiki_fallback_chains.svg" class="mw-file-description"><img src="//upload.wikimedia.org/wikipedia/commons/thumb/2/26/MediaWiki_fallback_chains.svg/220px-MediaWiki_fallback_chains.svg.png" decoding="async" width="220" height="251" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/2/26/MediaWiki_fallback_chains.svg/330px-MediaWiki_fallback_chains.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/2/26/MediaWiki_fallback_chains.svg/440px-MediaWiki_fallback_chains.svg.png 2x" data-file-width="512" data-file-height="585" /></a><figcaption>Fallback chains</figcaption></figure> <p><code style="white-space:nowrap">mw.language.getFallbacksFor( code )</code> </p><p>Returns a list of MediaWiki's fallback language codes for the specified code. </p> <div class="mw-heading mw-heading4"><h4 id="mw.language.isKnownLanguageTag">mw.language.isKnownLanguageTag</h4></div> <p><code style="white-space:nowrap">mw.language.isKnownLanguageTag( code )</code> </p><p>Returns <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">true</span></code> if a language code is known to MediaWiki. </p><p>A language code is "known" if it is a "valid built-in code" (i.e. it returns <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">true</span></code> for <a href="#mw.language.isValidBuiltInCode"><code>mw.language.isValidBuiltInCode</code></a>) and returns a non-empty string for <a href="#mw.language.fetchLanguageName"><code>mw.language.fetchLanguageName</code></a>. </p> <div class="mw-heading mw-heading4"><h4 id="mw.language.isSupportedLanguage">mw.language.isSupportedLanguage</h4></div> <p><code style="white-space:nowrap">mw.language.isSupportedLanguage( code )</code> </p><p>Checks whether any localisation is available for that language code in MediaWiki. </p><p>A language code is "supported" if it is a "valid" code (returns <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">true</span></code> for <a href="#mw.language.isValidCode"><code>mw.language.isValidCode</code></a>), contains no uppercase letters, and has a message file in the currently-running version of MediaWiki. </p><p>It is possible for a language code to be "supported" but not "known" (i.e. returning <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">true</span></code> for <a href="#mw.language.isKnownLanguageTag"><code>mw.language.isKnownLanguageTag</code></a>). Also note that certain codes are "supported" despite <a href="#mw.language.isValidBuiltInCode"><code>mw.language.isValidBuiltInCode</code></a> returning <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">false</span></code>. </p> <div class="mw-heading mw-heading4"><h4 id="mw.language.isValidBuiltInCode">mw.language.isValidBuiltInCode</h4></div> <p><code style="white-space:nowrap">mw.language.isValidBuiltInCode( code )</code> </p><p>Returns <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">true</span></code> if a language code is of a valid form for the purposes of internal customisation of MediaWiki. </p><p>The code may not actually correspond to any known language. </p><p>A language code is a "valid built-in code" if it is a "valid" code (i.e. it returns <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">true</span></code> for <a href="#mw.language.isValidCode"><code>mw.language.isValidCode</code></a>); consists of only ASCII letters, numbers, and hyphens; and is at least two characters long. </p><p>Note that some codes are "supported" (i.e. returning <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">true</span></code> from <a href="#mw.language.isSupportedLanguage"><code>mw.language.isSupportedLanguage</code></a>) even though this function returns <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">false</span></code>. </p> <div class="mw-heading mw-heading4"><h4 id="mw.language.isValidCode">mw.language.isValidCode</h4></div> <p><code style="white-space:nowrap">mw.language.isValidCode( code )</code> </p><p>Returns <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">true</span></code> if a language code string is of a valid form, whether or not it exists. This includes codes which are used solely for customisation via the MediaWiki namespace. </p><p>The code may not actually correspond to any known language. </p><p>A language code is valid if it does not contain certain unsafe characters (colons, single- or double-quotes, slashs, backslashs, angle brackets, ampersands, or ASCII NULs) and is otherwise allowed in a page title. </p> <div class="mw-heading mw-heading4"><h4 id="mw.language.new">mw.language.new</h4></div> <p><code style="white-space:nowrap">mw.language.new( code )</code> <br /> <code style="white-space:nowrap">mw.getLanguage( code )</code> </p><p>Creates a new language object. Language objects do not have any publicly accessible properties, but they do have several methods, which are documented below. </p><p>There is a limit of 200 on the number of distinct language codes that may be used on a page. Exceeding this limit will result in errors. </p> <div class="mw-heading mw-heading4"><h4 id="mw.language:getCode">mw.language:getCode</h4></div> <p><code style="white-space:nowrap"><a href="#mw.language-object">lang</a>:getCode()</code> </p><p>Returns the language code for this language object. </p> <div class="mw-heading mw-heading4"><h4 id="mw.language:toBcp47Code">mw.language:toBcp47Code</h4></div> <p><code style="white-space:nowrap"><a href="#mw.language-object">lang</a>:toBcp47Code()</code> </p><p>Returns the standard <a href="https://en.wikipedia.org/wiki/IETF_language_tag" class="extiw" title="w:IETF language tag">BCP-47</a> language code for this language object. This is the code string which is appropriate to use in HTML, for example as the value of a <code>lang</code> attribute. </p> <div class="mw-heading mw-heading4"><h4 id="mw.language:getFallbackLanguages">mw.language:getFallbackLanguages</h4></div> <p><code style="white-space:nowrap"><a href="#mw.language-object">lang</a>:getFallbackLanguages()</code> </p><p>Returns a list of MediaWiki's fallback language codes for this language object. Equivalent to <code style="white-space:nowrap">mw.language.getFallbacksFor( lang:getCode() )</code>. </p> <div class="mw-heading mw-heading4"><h4 id="mw.language:isRTL">mw.language:isRTL</h4></div> <p><code style="white-space:nowrap"><a href="#mw.language-object">lang</a>:isRTL()</code> </p><p>Returns <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">true</span></code> if the language is written right-to-left, <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">false</span></code> if it is written left-to-right. </p> <div class="mw-heading mw-heading4"><h4 id="mw.language:lc">mw.language:lc</h4></div> <p><code style="white-space:nowrap"><a href="#mw.language-object">lang</a>:lc( s )</code> </p><p>Converts the string to lowercase, honoring any special rules for the given language. </p><p>When the <a href="#Ustring_library">Ustring library</a> is loaded, the <a href="#mw.ustring.lower">mw.ustring.lower()</a> function is implemented as a call to <code style="white-space:nowrap">mw.language.getContentLanguage():lc( s )</code>. </p> <div class="mw-heading mw-heading4"><h4 id="mw.language:lcfirst">mw.language:lcfirst</h4></div> <p><code style="white-space:nowrap"><a href="#mw.language-object">lang</a>:lcfirst( s )</code> </p><p>Converts the first character of the string to lowercase, as with <a href="#mw.language:lc"><code>lang:lc()</code></a>. </p> <div class="mw-heading mw-heading4"><h4 id="mw.language:uc">mw.language:uc</h4></div> <p><code style="white-space:nowrap"><a href="#mw.language-object">lang</a>:uc( s )</code> </p><p>Converts the string to uppercase, honoring any special rules for the given language. </p><p>When the <a href="#Ustring_library">Ustring library</a> is loaded, the <a href="#mw.ustring.upper"><code>mw.ustring.upper()</code></a> function is implemented as a call to <code style="white-space:nowrap">mw.language.getContentLanguage():uc( s )</code>. </p> <div class="mw-heading mw-heading4"><h4 id="mw.language:ucfirst">mw.language:ucfirst</h4></div> <p><code style="white-space:nowrap"><a href="#mw.language-object">lang</a>:ucfirst( s )</code> </p><p>Converts the first character of the string to uppercase, as with <a href="#mw.language:uc">lang:uc()</a>. </p> <div class="mw-heading mw-heading4"><h4 id="mw.language:caseFold">mw.language:caseFold</h4></div> <p><code style="white-space:nowrap"><a href="#mw.language-object">lang</a>:caseFold( s )</code> </p><p>Converts the string to a representation appropriate for case-insensitive comparison. Note that the result may not make any sense when displayed. </p> <div class="mw-heading mw-heading4"><h4 id="mw.language:formatNum">mw.language:formatNum</h4></div> <p><code style="white-space:nowrap"><a href="#mw.language-object">lang</a>:formatNum( n )</code> <br /> <code style="white-space:nowrap"><a href="#mw.language-object">lang</a>:formatNum( n, options )</code> </p><p>Formats a number with grouping and decimal separators appropriate for the given language. Given 123456.78, this may produce "123,456.78", "123.456,78", or even something like "١٢٣٬٤٥٦٫٧٨" depending on the language and wiki configuration. </p><p>The <code>options</code> is a table of options, which can be: </p> <ul><li><code>noCommafy</code>: Set <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">true</span></code> to omit grouping separators and use a dot (<code>.</code>) as the decimal separator. Digit transformation may still occur, which may include transforming the decimal separator.</li></ul> <div class="mw-heading mw-heading4"><h4 id="mw.language:formatDate">mw.language:formatDate</h4></div> <p><code style="white-space:nowrap"><a href="#mw.language-object">lang</a>:formatDate( format, timestamp, local )</code> </p><p>Formats a date according to the given format string. If <code>timestamp</code> is omitted, the default is the current time. The value for <code>local</code> must be a boolean or nil; if <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">true</span></code>, the time is formatted in the <a href="/wiki/Special:MyLanguage/Manual:$wgLocaltimezone" title="Special:MyLanguage/Manual:$wgLocaltimezone">wiki's local time</a> rather than in UTC. </p><p>The format string and supported values for <code>timestamp</code> are identical to those for the <a href="/wiki/Special:MyLanguage/Help:Extension:ParserFunctions#.23time" title="Special:MyLanguage/Help:Extension:ParserFunctions">#time parser function</a> from <a href="/wiki/Special:MyLanguage/Extension:ParserFunctions" title="Special:MyLanguage/Extension:ParserFunctions">Extension:ParserFunctions</a><span style="display:none"><a href="/wiki/Extension:ParserFunctions" title="Extension:ParserFunctions"> </a></span>. Note however that backslashes may need to be doubled in a Lua string literal, since Lua also uses backslash as an escape character while wikitext does not: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">-- This string literal contains a newline, not the two characters &quot;\n&quot;, so it is not equivalent to {{#time:\n}}.</span> <span class="n">lang</span><span class="p">:</span><span class="n">formatDate</span><span class="p">(</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="p">)</span> <span class="c1">-- This is equivalent to {{#time:\n}}, not {{#time:\\n}}.</span> <span class="n">lang</span><span class="p">:</span><span class="n">formatDate</span><span class="p">(</span> <span class="s1">&#39;</span><span class="se">\\</span><span class="s1">n&#39;</span> <span class="p">)</span> <span class="c1">-- This is equivalent to {{#time:\\n}}, not {{#time:\\\\n}}.</span> <span class="n">lang</span><span class="p">:</span><span class="n">formatDate</span><span class="p">(</span> <span class="s1">&#39;</span><span class="se">\\\\</span><span class="s1">n&#39;</span> <span class="p">)</span> </pre></div> <div class="mw-heading mw-heading4"><h4 id="mw.language:formatDuration">mw.language:formatDuration</h4></div> <p><code style="white-space:nowrap"><a href="#mw.language-object">lang</a>:formatDuration( seconds )</code> <br /> <code style="white-space:nowrap"><a href="#mw.language-object">lang</a>:formatDuration( seconds, chosenIntervals )</code> </p><p>Breaks a duration in seconds into more human-readable units, e.g. 12345 to 3 hours, 25 minutes and 45 seconds, returning the result as a string. </p><p><code>chosenIntervals</code>, if given, is a table with values naming the interval units to use in the response. These include '<code>millennia</code>', '<code>centuries</code>', '<code>decades</code>', '<code>years</code>', '<code>weeks</code>', '<code>days</code>', '<code>hours</code>', '<code>minutes</code>', and '<code>seconds</code>'. </p> <div class="mw-heading mw-heading4"><h4 id="mw.language:parseFormattedNumber">mw.language:parseFormattedNumber</h4></div> <p><code style="white-space:nowrap"><a href="#mw.language-object">lang</a>:parseFormattedNumber( s )</code> </p><p>This takes a number as formatted by <a href="#mw.language:formatNum">lang:formatNum()</a> and returns the actual number. In other words, this is basically a language-aware version of <a href="#tonumber"><code>tonumber()</code></a>. </p> <div class="mw-heading mw-heading4"><h4 id="mw.language:convertPlural">mw.language:convertPlural</h4></div> <p><span class="anchor" id="mw.language:plural"></span> <code style="white-space:nowrap"><a href="#mw.language-object">lang</a>:convertPlural( n, ... )</code> <br /> <code style="white-space:nowrap"><a href="#mw.language-object">lang</a>:convertPlural( n, forms )</code> <br /> <code style="white-space:nowrap"><a href="#mw.language-object">lang</a>:plural( n, ... )</code> <br /> <code style="white-space:nowrap"><a href="#mw.language-object">lang</a>:plural( n, forms )</code> </p><p>This chooses the appropriate grammatical form from <code>forms</code> (which must be a <a href="#sequence">sequence</a> table) or <code>...</code> based on the number <code>n</code>. For example, in English you might use <code style="white-space:nowrap">n .. ' ' .. lang:plural( n, 'sock', 'socks' )</code> or <code style="white-space:nowrap">n .. ' ' .. lang:plural( n, { 'sock', 'socks' } )</code> to generate grammatically-correct text whether there is only 1 sock or 200 socks. </p><p>The necessary values for the sequence are language-dependent, see <a href="/wiki/Special:MyLanguage/Help:Magic_words#Localization" title="Special:MyLanguage/Help:Magic words">localization of magic words</a> and <a href="https://translatewiki.net/wiki/Special:MyLanguage/FAQ#PLURAL" class="extiw" title="translatewiki:Special:MyLanguage/FAQ">translatewiki's FAQ on PLURAL</a> for some details. </p> <div class="mw-heading mw-heading4"><h4 id="mw.language:convertGrammar">mw.language:convertGrammar</h4></div> <p><span class="anchor" id="mw.language:grammar"></span> <code style="white-space:nowrap"><a href="#mw.language-object">lang</a>:convertGrammar( word, case )</code> <br /> <code style="white-space:nowrap"><a href="#mw.language-object">lang</a>:grammar( case, word )</code> </p> <dl><dd><i>Note the different parameter order between the two aliases. <code>convertGrammar</code> matches the order of the method of the same name on MediaWiki's Language object, while <code>grammar</code> matches the order of the parser function of the same name, documented at <a href="/wiki/Special:MyLanguage/Help:Magic_words#Localisation" title="Special:MyLanguage/Help:Magic words">Help:Magic words#Localisation</a>.</i></dd></dl> <p>This chooses the appropriate inflected form of <code>word</code> for the given inflection code <code>case</code>. </p><p>The possible values for <code>word</code> and <code>case</code> are language-dependent, see <a href="/wiki/Special:MyLanguage/Help:Magic_words#Localisation" title="Special:MyLanguage/Help:Magic words">Special:MyLanguage/Help:Magic words#Localisation</a> and <a href="https://translatewiki.net/wiki/Special:MyLanguage/Grammar" class="extiw" title="translatewiki:Special:MyLanguage/Grammar">translatewiki:Grammar</a> for some details. </p> <div class="mw-heading mw-heading4"><h4 id="mw.language:gender">mw.language:gender</h4></div> <p><code style="white-space:nowrap"><a href="#mw.language-object">lang</a>:gender( what, masculine, feminine, neutral )</code> <br /> <code style="white-space:nowrap"><a href="#mw.language-object">lang</a>:gender( what, { masculine, feminine, neutral } )</code> </p><p>Chooses the string corresponding to the gender of <code>what</code>, which may be "male", "female", or a registered user name. </p> <div class="mw-heading mw-heading4"><h4 id="mw.language:getArrow">mw.language:getArrow</h4></div> <p><code style="white-space:nowrap"><a href="#mw.language-object">lang</a>:getArrow( direction )</code> </p><p>Returns a Unicode arrow character corresponding to <code>direction</code>: </p> <ul><li><b>forwards</b>: Either "→" or "←" depending on the directionality of the language.</li> <li><b>backwards</b>: Either "←" or "→" depending on the directionality of the language.</li> <li><b>left</b>: "←"</li> <li><b>right</b>: "→"</li> <li><b>up</b>: "↑"</li> <li><b>down</b>: "↓"</li></ul> <div class="mw-heading mw-heading4"><h4 id="mw.language:getDir">mw.language:getDir</h4></div> <p><code style="white-space:nowrap"><a href="#mw.language-object">lang</a>:getDir()</code> </p><p>Returns "ltr" or "rtl", depending on the directionality of the language. </p> <div class="mw-heading mw-heading4"><h4 id="mw.language:getDirMark">mw.language:getDirMark</h4></div> <p><code style="white-space:nowrap"><a href="#mw.language-object">lang</a>:getDirMark( opposite )</code> </p><p>Returns a string containing either U+200E (the left-to-right mark) or U+200F (the right-to-left mark), depending on the directionality of the language and whether <code>opposite</code> is a true or false value. </p> <div class="mw-heading mw-heading4"><h4 id="mw.language:getDirMarkEntity">mw.language:getDirMarkEntity</h4></div> <p><code style="white-space:nowrap"><a href="#mw.language-object">lang</a>:getDirMarkEntity( opposite )</code> </p><p>Returns "&amp;lrm;" or "&amp;rlm;", depending on the directionality of the language and whether <code>opposite</code> is a true or false value. </p> <div class="mw-heading mw-heading4"><h4 id="mw.language:getDurationIntervals">mw.language:getDurationIntervals</h4></div> <p><code style="white-space:nowrap"><a href="#mw.language-object">lang</a>:getDurationIntervals( seconds )</code> <br /> <code style="white-space:nowrap"><a href="#mw.language-object">lang</a>:getDurationIntervals( seconds, chosenIntervals )</code> </p><p>Breaks a duration in seconds into more human-readable units, e.g. 12345 to 3 hours, 25 minutes and 45 seconds, returning the result as a table mapping unit names to numbers. </p><p><code>chosenIntervals</code>, if given, is a table with values naming the interval units to use in the response. These include '<code>millennia</code>', '<code>centuries</code>', '<code>decades</code>', '<code>years</code>', '<code>weeks</code>', '<code>days</code>', '<code>hours</code>', '<code>minutes</code>', and '<code>seconds</code>'. </p><p>Those unit keywords are also the keys used in the response table. Only units with a non-zero value are set in the response, unless the response would be empty in which case the smallest unit is returned with a value of 0. </p> <div class="mw-heading mw-heading3"><h3 id="Message_library">Message library</h3></div> <p>This library is an interface to the localisation messages and the MediaWiki: namespace. </p><p><span class="anchor" id="mw.message-object"></span> Functions documented as <code>mw.message.<var>name</var></code> are available on the global <code>mw.message</code> table; functions documented as <code>mw.message:<var>name</var></code> and <code>msg:<var>name</var></code> are methods of a message object (see <a href="#mw.message.new"><code>mw.message.new</code></a>). </p> <div class="mw-heading mw-heading4"><h4 id="mw.message.new">mw.message.new</h4></div> <p><code style="white-space:nowrap">mw.message.new( key, ... )</code> </p><p>Creates a new message object for the given message <code>key</code>. The remaining parameters are passed to the new object's <code><a href="#mw.message:params">params()</a></code> method. </p><p>The message object has no properties, but has several methods documented below. </p> <div class="mw-heading mw-heading4"><h4 id="mw.message.newFallbackSequence">mw.message.newFallbackSequence</h4></div> <p><code style="white-space:nowrap">mw.message.newFallbackSequence( ... )</code> </p><p>Creates a new message object for the given messages (the first one that exists will be used). </p><p>The message object has no properties, but has several methods documented below. </p> <div class="mw-heading mw-heading4"><h4 id="mw.message.newRawMessage">mw.message.newRawMessage</h4></div> <p><code style="white-space:nowrap">mw.message.newRawMessage( msg, ... )</code> </p><p>Creates a new message object, using the given text directly rather than looking up an internationalized message. The remaining parameters are passed to the new object's <code><a href="#mw.message:params">params()</a></code> method. </p><p>The message object has no properties, but has several methods documented below. </p> <div class="mw-heading mw-heading4"><h4 id="mw.message.rawParam">mw.message.rawParam</h4></div> <p><code style="white-space:nowrap">mw.message.rawParam( value )</code> </p><p>Wraps the value so that it will not be parsed as wikitext by <code><a href="#mw.message:parse">msg:parse()</a></code>. </p> <div class="mw-heading mw-heading4"><h4 id="mw.message.numParam">mw.message.numParam</h4></div> <p><code style="white-space:nowrap">mw.message.numParam( value )</code> </p><p>Wraps the value so that it will automatically be formatted as by <code><a href="#mw.language:formatNum">lang:formatNum()</a></code>. Note this does not depend on the <a href="#Language_library">Language library</a> actually being available. </p> <div class="mw-heading mw-heading4"><h4 id="mw.message.getDefaultLanguage">mw.message.getDefaultLanguage</h4></div> <p><code style="white-space:nowrap">mw.message.getDefaultLanguage()</code> </p><p>Returns a Language object for the default language. </p> <div class="mw-heading mw-heading4"><h4 id="mw.message:params">mw.message:params</h4></div> <p><code style="white-space:nowrap"><a href="#mw.message-object">msg</a>:params( ... )</code> <br /> <code style="white-space:nowrap"><a href="#mw.message-object">msg</a>:params( params )</code> </p><p>Add parameters to the message, which may be passed as individual arguments or as a <a href="#sequence">sequence</a> table. Parameters must be numbers, strings, or the special values returned by <a href="#mw.message.numParam">mw.message.numParam()</a> or <a href="#mw.message.rawParam">mw.message.rawParam()</a>. If a sequence table is used, parameters must be directly present in the table; references using the <a href="#Metatables">__index metamethod</a> will not work. </p><p>Returns the <code>msg</code> object, to allow for call chaining. </p> <div class="mw-heading mw-heading4"><h4 id="mw.message:rawParams">mw.message:rawParams</h4></div> <p><code style="white-space:nowrap"><a href="#mw.message-object">msg</a>:rawParams( ... )</code> <br /> <code style="white-space:nowrap"><a href="#mw.message-object">msg</a>:rawParams( params )</code> </p><p>Like <a href="#mw.message:params">:params()</a>, but has the effect of passing all the parameters through <a href="#mw.message.rawParam">mw.message.rawParam()</a> first. </p><p>Returns the <code>msg</code> object, to allow for call chaining. </p> <div class="mw-heading mw-heading4"><h4 id="mw.message:numParams">mw.message:numParams</h4></div> <p><code style="white-space:nowrap"><a href="#mw.message-object">msg</a>:numParams( ... )</code> <br /> <code style="white-space:nowrap"><a href="#mw.message-object">msg</a>:numParams( params )</code> </p><p>Like <a href="#mw.message:params">:params()</a>, but has the effect of passing all the parameters through <a href="#mw.message.numParam">mw.message.numParam()</a> first. </p><p>Returns the <code>msg</code> object, to allow for call chaining. </p> <div class="mw-heading mw-heading4"><h4 id="mw.message:inLanguage">mw.message:inLanguage</h4></div> <p><code style="white-space:nowrap"><a href="#mw.message-object">msg</a>:inLanguage( lang )</code> </p><p>Specifies the language to use when processing the message. <code>lang</code> may be a string or a table with a <code>getCode()</code> method (i.e. a <a href="#Language_library">Language object</a>). </p><p>The default language is the one returned by <code><a href="#mw.message.getDefaultLanguage">mw.message.getDefaultLanguage()</a></code>. </p><p>Returns the <code>msg</code> object, to allow for call chaining. </p> <div class="mw-heading mw-heading4"><h4 id="mw.message:useDatabase">mw.message:useDatabase</h4></div> <p><code style="white-space:nowrap"><a href="#mw.message-object">msg</a>:useDatabase( bool )</code> </p><p>Specifies whether to look up messages in the MediaWiki: namespace (i.e. look in the database), or just use the default messages distributed with MediaWiki. </p><p>The default is <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">true</span></code>. </p><p>Returns the <code>msg</code> object, to allow for call chaining. </p> <div class="mw-heading mw-heading4"><h4 id="mw.message:plain">mw.message:plain</h4></div> <p><code style="white-space:nowrap"><a href="#mw.message-object">msg</a>:plain()</code> </p><p>Substitutes the parameters and returns the message wikitext as-is. Template calls and parser functions are intact. </p> <div class="mw-heading mw-heading4"><h4 id="mw.message:exists">mw.message:exists</h4></div> <p><code style="white-space:nowrap"><a href="#mw.message-object">msg</a>:exists()</code> </p><p>Returns a boolean indicating whether the message key exists. </p> <div class="mw-heading mw-heading4"><h4 id="mw.message:isBlank">mw.message:isBlank</h4></div> <p><code style="white-space:nowrap"><a href="#mw.message-object">msg</a>:isBlank()</code> </p><p>Returns a boolean indicating whether the message key has content. Returns <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">true</span></code> if the message key does not exist or the message is the empty string. </p> <div class="mw-heading mw-heading4"><h4 id="mw.message:isDisabled">mw.message:isDisabled</h4></div> <p><code style="white-space:nowrap"><a href="#mw.message-object">msg</a>:isDisabled()</code> </p><p>Returns a boolean indicating whether the message key is disabled. Returns <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">true</span></code> if the message key does not exist or if the message is the empty string or the string "-". </p> <div class="mw-heading mw-heading3"><h3 id="Site_library">Site library</h3></div> <div class="mw-heading mw-heading4"><h4 id="mw.site.currentVersion">mw.site.currentVersion</h4></div> <p>A string holding the current version of MediaWiki. </p> <div class="mw-heading mw-heading4"><h4 id="mw.site.scriptPath">mw.site.scriptPath</h4></div> <p>The value of <code><a href="/wiki/Special:MyLanguage/Manual:$wgScriptPath" title="Special:MyLanguage/Manual:$wgScriptPath">$wgScriptPath</a><span style="display:none"><a href="/wiki/Manual:$wgScriptPath" title="Manual:$wgScriptPath"> </a></span></code>. </p> <div class="mw-heading mw-heading4"><h4 id="mw.site.server">mw.site.server</h4></div> <p>The value of <code><a href="/wiki/Special:MyLanguage/Manual:$wgServer" title="Special:MyLanguage/Manual:$wgServer">$wgServer</a><span style="display:none"><a href="/wiki/Manual:$wgServer" title="Manual:$wgServer"> </a></span></code>. </p> <div class="mw-heading mw-heading4"><h4 id="mw.site.siteName">mw.site.siteName</h4></div> <p>The value of <code><a href="/wiki/Special:MyLanguage/Manual:$wgSitename" title="Special:MyLanguage/Manual:$wgSitename">$wgSitename</a><span style="display:none"><a href="/wiki/Manual:$wgSitename" title="Manual:$wgSitename"> </a></span></code>. </p> <div class="mw-heading mw-heading4"><h4 id="mw.site.stylePath">mw.site.stylePath</h4></div> <p>The value of <code><a href="/wiki/Special:MyLanguage/Manual:$wgStylePath" title="Special:MyLanguage/Manual:$wgStylePath">$wgStylePath</a><span style="display:none"><a href="/wiki/Manual:$wgStylePath" title="Manual:$wgStylePath"> </a></span></code>. </p> <div class="mw-heading mw-heading4"><h4 id="mw.site.namespaces">mw.site.namespaces</h4></div> <p>Table holding data for all namespaces, indexed by number. </p><p>The data available is: </p> <ul><li><b>id</b>: Namespace number.</li> <li><b>name</b>: Local namespace name.</li> <li><b>canonicalName</b>: Canonical namespace name.</li> <li><b>displayName</b>: Set on namespace 0, the name to be used for display (since the name is often the empty string).</li> <li><b>hasSubpages</b>: Whether subpages are enabled for the namespace.</li> <li><b>hasGenderDistinction</b>: Whether the namespace has different aliases for different genders.</li> <li><b>isCapitalized</b>: Whether the first letter of pages in the namespace is capitalized.</li> <li><b>isContent</b>: Whether this is a content namespace.</li> <li><b>isIncludable</b>: Whether pages in the namespace can be transcluded.</li> <li><b>isMovable</b>: Whether pages in the namespace can be moved.</li> <li><b>isSubject</b>: Whether this is a subject namespace.</li> <li><b>isTalk</b>: Whether this is a talk namespace.</li> <li><b>defaultContentModel</b>: The default content model for the namespace, as a string.</li> <li><b>aliases</b>: List of aliases for the namespace.</li> <li><b>subject</b>: Reference to the corresponding subject namespace's data.</li> <li><b>talk</b>: Reference to the corresponding talk namespace's data.</li> <li><b>associated</b>: Reference to the associated namespace's data.</li></ul> <p>A metatable is also set that allows for looking up namespaces by name (localized or canonical). For example, both <code>mw.site.namespaces[4]</code> and <code>mw.site.namespaces.Project</code> will return information about the Project namespace. </p> <div class="mw-heading mw-heading4"><h4 id="mw.site.contentNamespaces">mw.site.contentNamespaces</h4></div> <p>Table holding just the content namespaces, indexed by number. See <a href="#mw.site.namespaces">mw.site.namespaces</a> for details. </p> <div class="mw-heading mw-heading4"><h4 id="mw.site.subjectNamespaces">mw.site.subjectNamespaces</h4></div> <p>Table holding just the subject namespaces, indexed by number. See <a href="#mw.site.namespaces">mw.site.namespaces</a> for details. </p> <div class="mw-heading mw-heading4"><h4 id="mw.site.talkNamespaces">mw.site.talkNamespaces</h4></div> <p>Table holding just the talk namespaces, indexed by number. See <a href="#mw.site.namespaces">mw.site.namespaces</a> for details. </p> <div class="mw-heading mw-heading4"><h4 id="mw.site.stats">mw.site.stats</h4></div> <p>Table holding site statistics. Available statistics are: </p> <ul><li><b>pages</b>: Number of pages in the wiki.</li> <li><b>articles</b>: Number of articles in the wiki.</li> <li><b>files</b>: Number of files in the wiki.</li> <li><b>edits</b>: Number of edits in the wiki.</li> <li><b>users</b>: Number of users in the wiki.</li> <li><b>activeUsers</b>: Number of active users in the wiki.</li> <li><b>admins</b>: Number of users in group 'sysop' in the wiki.</li></ul> <p><br /> </p> <div class="mw-heading mw-heading4"><h4 id="mw.site.stats.pagesInCategory">mw.site.stats.pagesInCategory</h4></div> <p><code style="white-space:nowrap">mw.site.stats.pagesInCategory( category, which )</code> </p> <dl><dd><span style="color:#d73333" dir="ltr">This function is <a href="/wiki/Special:MyLanguage/Manual:$wgExpensiveParserFunctionLimit" title="Special:MyLanguage/Manual:$wgExpensiveParserFunctionLimit">expensive</a></span></dd></dl> <p>Gets statistics about the category. If <code>which</code> has the special value "<code>*</code>", the result is a table with the following properties: </p> <ul><li><b>all</b>: Total pages, files, and subcategories.</li> <li><b>subcats</b>: Number of subcategories.</li> <li><b>files</b>: Number of files.</li> <li><b>pages</b>: Number of pages.</li></ul> <p>If <code>which</code> is one of the above keys ("all", "subcats", "files", "pages"), the result is a number with the corresponding value. </p><p>Each new category queried will increment the expensive function count. </p> <div class="mw-heading mw-heading4"><h4 id="mw.site.stats.pagesInNamespace">mw.site.stats.pagesInNamespace</h4></div> <p><code style="white-space:nowrap">mw.site.stats.pagesInNamespace( namespace )</code> </p><p>Returns the number of pages in the given namespace (specify by number). </p> <div class="mw-heading mw-heading4"><h4 id="mw.site.stats.usersInGroup">mw.site.stats.usersInGroup</h4></div> <p><code style="white-space:nowrap">mw.site.stats.usersInGroup( group )</code> </p><p>Returns the number of users in the given group. </p> <div class="mw-heading mw-heading4"><h4 id="mw.site.interwikiMap">mw.site.interwikiMap</h4></div> <p><code style="white-space:nowrap">mw.site.interwikiMap( filter )</code> </p><p>Returns a table holding data about available <a href="/wiki/Special:MyLanguage/Manual:Interwiki" title="Special:MyLanguage/Manual:Interwiki">interwiki</a> prefixes. If <code>filter</code> is the string "local", then only data for local interwiki prefixes is returned. If <code>filter</code> is the string "!local", then only data for non-local prefixes is returned. If no filter is specified, data for all prefixes is returned. A "local" prefix in this context is one that is for the same project. For example, on the English Wikipedia, other-language Wikipedias are considered local, while Wiktionary and such are not. </p><p>Keys in the table returned by this function are interwiki prefixes, and the values are subtables with the following properties: </p><p><br /> </p> <ul><li><b>prefix</b> - the interwiki prefix.</li> <li><b>url</b> - the URL that the interwiki points to. The page name is represented by the parameter $1.</li> <li><b>isProtocolRelative</b> - a boolean showing whether the URL is <a href="https://en.wikipedia.org/wiki/Protocol-relative_URL" class="extiw" title="w:Protocol-relative URL">protocol-relative</a>.</li> <li><b>isLocal</b> - whether the URL is for a site in the current project.</li> <li><b>isCurrentWiki</b> - whether the URL is for the current wiki.</li> <li><b>isTranscludable</b> - whether pages using this interwiki prefix are <a href="/wiki/Transclusion" title="Transclusion">transcludable</a>. This requires <a href="/wiki/Special:MyLanguage/Manual:$wgEnableScaryTranscluding" title="Special:MyLanguage/Manual:$wgEnableScaryTranscluding">scary transclusion</a>, which is disabled on Wikimedia wikis.</li> <li><b>isExtraLanguageLink</b> - whether the interwiki is listed in <code><a href="/wiki/Special:MyLanguage/Manual:$wgExtraInterlanguageLinkPrefixes" title="Special:MyLanguage/Manual:$wgExtraInterlanguageLinkPrefixes">$wgExtraInterlanguageLinkPrefixes</a><span style="display:none"><a href="/wiki/Manual:$wgExtraInterlanguageLinkPrefixes" title="Manual:$wgExtraInterlanguageLinkPrefixes"> </a></span></code>.</li> <li><b>displayText</b> - for links listed in $wgExtraInterlanguageLinkPrefixes, this is the display text shown for the interlanguage link. Nil if not specified.</li> <li><b>tooltip</b> - for links listed in $wgExtraInterlanguageLinkPrefixes, this is the tooltip text shown when users hover over the interlanguage link. Nil if not specified.</li></ul> <div class="mw-heading mw-heading3"><h3 id="Text_library">Text library</h3></div> <p>The text library provides some common text processing functions missing from the <a href="#String_library">String library</a> and the <a href="#Ustring_library">Ustring library</a>. These functions are safe for use with UTF-8 strings. </p> <div class="mw-heading mw-heading4"><h4 id="mw.text.decode">mw.text.decode</h4></div> <p><code style="white-space:nowrap">mw.text.decode( string )</code> <br /> <code style="white-space:nowrap">mw.text.decode( string, decodeNamedEntities )</code> </p><p>Replaces <a href="https://en.wikipedia.org/wiki/HTML_entities" class="extiw" title="w:HTML entities">HTML entities</a> in the string with the corresponding characters. </p><p>If boolean <code>decodeNamedEntities</code> is omitted or false, the only named entities recognized are <code>&amp;lt;</code> (&lt;), <code>&amp;gt;</code> (&gt;), <code>&amp;amp;</code> (&amp;), <code>&amp;quot;</code> (") and <code>&amp;nbsp;</code> (the non-breaking space, U+00A0). Otherwise, the list of HTML5 named entities to recognize is loaded from PHP's <a rel="nofollow" class="external text" href="https://php.net/get_html_translation_table"><code>get_html_translation_table</code></a> function. </p><p><span style="color:#d73333" dir="ltr">Known bugs</span>: Approximately 600 of around 2,200 named entities in the HTML5 standard do not get decoded, even when <code>decodeNamedEntities</code> is used; this includes approximately 40 of around 250 entities which are also included in HTML4. This occurs because PHP's <code>get_html_translation_table</code> function returns only one mapping for each character, so for example <code><code class="mw-highlight mw-highlight-lang-text mw-content-ltr" dir="ltr">&amp;rarr;</code></code> is not decoded since PHP returns only <code><code class="mw-highlight mw-highlight-lang-text mw-content-ltr" dir="ltr">&amp;srarr;</code></code> as the mapping for <code><code class="mw-highlight mw-highlight-lang-text mw-content-ltr" dir="ltr">→</code></code>. </p> <div class="mw-heading mw-heading4"><h4 id="mw.text.encode">mw.text.encode</h4></div> <p><code style="white-space:nowrap">mw.text.encode( string )</code> <br /> <code style="white-space:nowrap">mw.text.encode( string, charset )</code> </p><p>Replaces characters in a string with <a href="https://en.wikipedia.org/wiki/HTML_entities" class="extiw" title="w:HTML entities">HTML entities</a>. Five characters are replaced with the appropriate named entities: <code>&lt;</code>, <code>&gt;</code>, <code>&amp;</code>, <code>"</code> and the non-breaking space (U+00A0). All others are replaced with numeric entities. </p><p>If <code>charset</code> is supplied, it should be a string as appropriate to go inside brackets in a <a href="#Ustring_patterns">Ustring pattern</a>, i.e. the "set" in <code>[set]</code>. The default charset contains six characters: <code>&lt;</code>, <code>&gt;</code>, <code>&amp;</code>, <code>"</code>, <code>'</code> and the non-breaking space (U+00A0). </p> <div class="mw-heading mw-heading4"><h4 id="mw.text.jsonDecode">mw.text.jsonDecode</h4></div> <p><code style="white-space:nowrap">mw.text.jsonDecode( string )</code> <br /> <code style="white-space:nowrap">mw.text.jsonDecode( string, flags )</code> </p><p>Decodes a JSON string. <code>flags</code> is 0 or a combination (use <code>+</code>) of the flags <code>mw.text.JSON_PRESERVE_KEYS</code> and <code>mw.text.JSON_TRY_FIXING</code>. </p><p>Normally JSON's zero-based arrays are renumbered to Lua one-based sequence tables; to prevent this, pass <code>mw.text.JSON_PRESERVE_KEYS</code>. </p><p>To relax certain requirements in JSON, such as no terminal comma in arrays or objects, pass <code>mw.text.JSON_TRY_FIXING</code>. This is not recommended. </p><p>Limitations: </p> <ul><li>Decoded JSON arrays may not be Lua sequences if the array contains null values.</li> <li>JSON objects will drop keys having null values.</li> <li>It is not possible to directly tell whether the input was a JSON array or a JSON object with sequential integer keys.</li> <li>A JSON object having sequential integer keys beginning with 1 will decode to the same table structure as a JSON array with the same values, despite these not being at all equivalent, unless <code>mw.text.JSON_PRESERVE_KEYS</code> is used.</li></ul> <div class="mw-heading mw-heading4"><h4 id="mw.text.jsonEncode">mw.text.jsonEncode</h4></div> <p><code style="white-space:nowrap">mw.text.jsonEncode( value )</code> <br /> <code style="white-space:nowrap">mw.text.jsonEncode( value, flags )</code> </p><p>Encode a JSON string. Errors are raised if the passed value cannot be encoded in JSON. <code>flags</code> is 0 or a combination (use <code>+</code>) of the flags <code>mw.text.JSON_PRESERVE_KEYS</code> and <code>mw.text.JSON_PRETTY</code>. </p><p>Normally Lua one-based sequence tables are encoded as JSON zero-based arrays; when <code>mw.text.JSON_PRESERVE_KEYS</code> is set in <code>flags</code>, zero-based sequence tables are encoded as JSON arrays. </p><p>Limitations: </p> <ul><li>Empty tables are always encoded as empty arrays (<code>[]</code>), not empty objects (<code>{}</code>).</li> <li>Sequence tables cannot be encoded as JSON objects without adding a "dummy" element.</li> <li>To produce objects or arrays with nil values, a tricky implementation of the <code>__pairs</code> metamethod is required.</li> <li>A Lua table having sequential integer keys beginning with 0 will encode as a JSON array, the same as a Lua table having integer keys beginning with 1, unless <code>mw.text.JSON_PRESERVE_KEYS</code> is used.</li> <li>When both a number and the string representation of that number are used as keys in the same table, behavior is unspecified.</li></ul> <div class="mw-heading mw-heading4"><h4 id="mw.text.killMarkers">mw.text.killMarkers</h4></div> <p><code style="white-space:nowrap">mw.text.killMarkers( string )</code> </p><p>Removes all MediaWiki <a href="/wiki/Strip_marker" title="Strip marker">strip markers</a> from a string. </p> <div class="mw-heading mw-heading4"><h4 id="mw.text.listToText">mw.text.listToText</h4></div> <p><code style="white-space:nowrap">mw.text.listToText( list )</code> <br /> <code style="white-space:nowrap">mw.text.listToText( list, separator, conjunction )</code> </p><p>Joins a list, prose-style. In other words, it's like <code><a href="#table.concat">table.concat()</a></code> but with a different separator before the final item. </p><p>The default separator is taken from <a href="/wiki/MediaWiki:Comma-separator" title="MediaWiki:Comma-separator">MediaWiki:comma-separator</a> in the wiki's content language, and the default conjunction is <a href="/wiki/MediaWiki:And" title="MediaWiki:And">MediaWiki:and</a> concatenated with <a href="/wiki/MediaWiki:Word-separator" title="MediaWiki:Word-separator">MediaWiki:word-separator</a>. </p><p>Examples, using the default values for the messages: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span> <span class="c1">-- Returns the empty string</span> <span class="n">mw</span><span class="p">.</span><span class="n">text</span><span class="p">.</span><span class="n">listToText</span><span class="p">(</span> <span class="p">{}</span> <span class="p">)</span> <span class="c1">-- Returns &quot;1&quot;</span> <span class="n">mw</span><span class="p">.</span><span class="n">text</span><span class="p">.</span><span class="n">listToText</span><span class="p">(</span> <span class="p">{</span> <span class="mi">1</span> <span class="p">}</span> <span class="p">)</span> <span class="c1">-- Returns &quot;1 and 2&quot;</span> <span class="n">mw</span><span class="p">.</span><span class="n">text</span><span class="p">.</span><span class="n">listToText</span><span class="p">(</span> <span class="p">{</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span> <span class="p">}</span> <span class="p">)</span> <span class="c1">-- Returns &quot;1, 2, 3, 4 and 5&quot;</span> <span class="n">mw</span><span class="p">.</span><span class="n">text</span><span class="p">.</span><span class="n">listToText</span><span class="p">(</span> <span class="p">{</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span> <span class="p">}</span> <span class="p">)</span> <span class="c1">-- Returns &quot;1; 2; 3; 4 or 5&quot;</span> <span class="n">mw</span><span class="p">.</span><span class="n">text</span><span class="p">.</span><span class="n">listToText</span><span class="p">(</span> <span class="p">{</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span> <span class="p">},</span> <span class="s1">&#39;; &#39;</span><span class="p">,</span> <span class="s1">&#39; or &#39;</span> <span class="p">)</span> </pre></div> <div class="mw-heading mw-heading4"><h4 id="mw.text.nowiki">mw.text.nowiki</h4></div> <p><code style="white-space:nowrap">mw.text.nowiki( string )</code> </p><p>Replaces various characters in the string with <a href="https://en.wikipedia.org/wiki/HTML_entities" class="extiw" title="w:HTML entities">HTML entities</a> to prevent their interpretation as wikitext. This includes: </p> <ul><li>The following characters: <code>"</code>, <code>&amp;</code>, <code>'</code>, <code>&lt;</code>, <code>=</code>, <code>&gt;</code>, <code>[</code>, <code>]</code>, <code>{</code>, <code>|</code>, <code>}</code></li> <li>The following characters at the start of the string or immediately after a newline: <code>#</code>, <code>*</code>, <code>:</code>, <code>;</code>, space, tab (<code>\t</code>)</li> <li>Blank lines will have one of the associated newline or carriage return characters escaped</li> <li><code>----</code> at the start of the string or immediately after a newline will have the first <code>-</code> escaped</li> <li><code>__</code> will have one underscore escaped</li> <li><code>://</code> will have the colon escaped</li> <li>A whitespace character following <code>ISBN</code>, <code>RFC</code>, or <code>PMID</code> will be escaped</li></ul> <div class="mw-heading mw-heading4"><h4 id="mw.text.split">mw.text.split</h4></div> <p><code style="white-space:nowrap">mw.text.split( string, pattern, plain )</code> </p><p>Splits the string into substrings at boundaries matching the <a href="#Ustring_patterns">Ustring pattern</a> <code>pattern</code>. If <code>plain</code> is specified and <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">true</span></code>, <code>pattern</code> will be interpreted as a literal string rather than as a Lua pattern (just as with the parameter of the same name for <code><a href="#mw.ustring.find">mw.ustring.find()</a></code>). Returns a table containing the substrings. </p><p>For example, <code style="white-space:nowrap">mw.text.split( 'a b\tc\nd', '%s' )</code> would return a table <code style="white-space:nowrap">{ 'a', 'b', 'c', 'd' }</code>. </p><p>If <code>pattern</code> matches the empty string, <code>string</code> will be split into individual characters. </p><p>Note that this function can be over 60 times slower than a reimplementation that is not Unicode-aware, such as the following: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="kr">function</span> <span class="nf">split</span><span class="p">(</span><span class="n">text</span><span class="p">,</span> <span class="n">pattern</span><span class="p">,</span> <span class="n">plain</span><span class="p">)</span> <span class="kd">local</span> <span class="n">ret</span> <span class="o">=</span> <span class="p">{}</span> <span class="kd">local</span> <span class="n">s</span><span class="p">,</span> <span class="n">l</span> <span class="o">=</span> <span class="mi">1</span><span class="p">,</span> <span class="nb">string.len</span><span class="p">(</span> <span class="n">text</span> <span class="p">)</span> <span class="kr">while</span> <span class="n">s</span> <span class="kr">do</span> <span class="kd">local</span> <span class="n">e</span><span class="p">,</span> <span class="n">n</span> <span class="o">=</span> <span class="nb">string.find</span><span class="p">(</span> <span class="n">text</span><span class="p">,</span> <span class="n">pattern</span><span class="p">,</span> <span class="n">s</span><span class="p">,</span> <span class="n">plain</span> <span class="p">)</span> <span class="kr">if</span> <span class="ow">not</span> <span class="n">e</span> <span class="kr">then</span> <span class="n">ret</span><span class="p">[</span><span class="o">#</span><span class="n">ret</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="nb">string.sub</span> <span class="p">(</span> <span class="n">text</span><span class="p">,</span> <span class="n">s</span> <span class="p">)</span> <span class="n">s</span> <span class="o">=</span> <span class="kc">nil</span> <span class="kr">elseif</span> <span class="n">n</span> <span class="o">&lt;</span> <span class="n">e</span> <span class="kr">then</span> <span class="c1">-- Empty separator!</span> <span class="n">ret</span><span class="p">[</span><span class="o">#</span><span class="n">ret</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="nb">string.sub</span> <span class="p">(</span> <span class="n">text</span><span class="p">,</span> <span class="n">s</span><span class="p">,</span> <span class="n">e</span> <span class="p">)</span> <span class="kr">if</span> <span class="n">e</span> <span class="o">&lt;</span> <span class="n">l</span> <span class="kr">then</span> <span class="n">s</span> <span class="o">=</span> <span class="n">e</span> <span class="o">+</span> <span class="mi">1</span> <span class="kr">else</span> <span class="n">s</span> <span class="o">=</span> <span class="kc">nil</span> <span class="kr">end</span> <span class="kr">else</span> <span class="n">ret</span><span class="p">[</span><span class="o">#</span><span class="n">ret</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">e</span> <span class="o">&gt;</span> <span class="n">s</span> <span class="ow">and</span> <span class="nb">string.sub</span><span class="p">(</span> <span class="n">text</span><span class="p">,</span> <span class="n">s</span><span class="p">,</span> <span class="n">e</span> <span class="o">-</span> <span class="mi">1</span> <span class="p">)</span> <span class="ow">or</span> <span class="s1">&#39;&#39;</span> <span class="n">s</span> <span class="o">=</span> <span class="n">n</span> <span class="o">+</span> <span class="mi">1</span> <span class="kr">end</span> <span class="kr">end</span> <span class="kr">return</span> <span class="n">ret</span> <span class="kr">end</span> </pre></div> <div class="mw-heading mw-heading4"><h4 id="mw.text.gsplit">mw.text.gsplit</h4></div> <p><code style="white-space:nowrap">mw.text.gsplit( string, pattern, plain )</code> </p><p>Returns an <a href="#iterators">iterator function</a> that will iterate over the substrings that would be returned by the equivalent call to <code><a href="#mw.text.split">mw.text.split()</a></code>. </p><p>Note that this function can be over 60 times slower than a reimplementation that is not Unicode-aware, such as the following: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="kr">function</span> <span class="nf">gsplit</span><span class="p">(</span> <span class="n">text</span><span class="p">,</span> <span class="n">pattern</span><span class="p">,</span> <span class="n">plain</span> <span class="p">)</span> <span class="kd">local</span> <span class="n">s</span><span class="p">,</span> <span class="n">l</span> <span class="o">=</span> <span class="mi">1</span><span class="p">,</span> <span class="nb">string.len</span><span class="p">(</span> <span class="n">text</span> <span class="p">)</span> <span class="kr">return</span> <span class="kr">function</span> <span class="p">()</span> <span class="kr">if</span> <span class="n">s</span> <span class="kr">then</span> <span class="kd">local</span> <span class="n">e</span><span class="p">,</span> <span class="n">n</span> <span class="o">=</span> <span class="nb">string.find</span><span class="p">(</span> <span class="n">text</span><span class="p">,</span> <span class="n">pattern</span><span class="p">,</span> <span class="n">s</span><span class="p">,</span> <span class="n">plain</span> <span class="p">)</span> <span class="kd">local</span> <span class="n">ret</span> <span class="kr">if</span> <span class="ow">not</span> <span class="n">e</span> <span class="kr">then</span> <span class="n">ret</span> <span class="o">=</span> <span class="nb">string.sub</span><span class="p">(</span> <span class="n">text</span><span class="p">,</span> <span class="n">s</span> <span class="p">)</span> <span class="n">s</span> <span class="o">=</span> <span class="kc">nil</span> <span class="kr">elseif</span> <span class="n">n</span> <span class="o">&lt;</span> <span class="n">e</span> <span class="kr">then</span> <span class="c1">-- Empty separator!</span> <span class="n">ret</span> <span class="o">=</span> <span class="nb">string.sub</span><span class="p">(</span> <span class="n">text</span><span class="p">,</span> <span class="n">s</span><span class="p">,</span> <span class="n">e</span> <span class="p">)</span> <span class="kr">if</span> <span class="n">e</span> <span class="o">&lt;</span> <span class="n">l</span> <span class="kr">then</span> <span class="n">s</span> <span class="o">=</span> <span class="n">e</span> <span class="o">+</span> <span class="mi">1</span> <span class="kr">else</span> <span class="n">s</span> <span class="o">=</span> <span class="kc">nil</span> <span class="kr">end</span> <span class="kr">else</span> <span class="n">ret</span> <span class="o">=</span> <span class="n">e</span> <span class="o">&gt;</span> <span class="n">s</span> <span class="ow">and</span> <span class="nb">string.sub</span><span class="p">(</span> <span class="n">text</span><span class="p">,</span> <span class="n">s</span><span class="p">,</span> <span class="n">e</span> <span class="o">-</span> <span class="mi">1</span> <span class="p">)</span> <span class="ow">or</span> <span class="s1">&#39;&#39;</span> <span class="n">s</span> <span class="o">=</span> <span class="n">n</span> <span class="o">+</span> <span class="mi">1</span> <span class="kr">end</span> <span class="kr">return</span> <span class="n">ret</span> <span class="kr">end</span> <span class="kr">end</span><span class="p">,</span> <span class="kc">nil</span><span class="p">,</span> <span class="kc">nil</span> <span class="kr">end</span> </pre></div> <div class="mw-heading mw-heading4"><h4 id="mw.text.tag">mw.text.tag</h4></div> <p><code style="white-space:nowrap">mw.text.tag( name, attrs, content )</code> <br /> <code style="white-space:nowrap">mw.text.tag{ name = string, attrs = table, content = string|false }</code> </p> <dl><dd><i>Note the use of <a href="#named_arguments">named arguments</a>.</i></dd></dl> <p>Generates an HTML-style tag for <code>name</code>. </p><p>If <code>attrs</code> is given, it must be a table with string keys. String and number values are used as the value of the attribute; boolean <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">true</span></code> results in the key being output as an HTML5 valueless parameter; boolean <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">false</span></code> skips the key entirely; and anything else is an error. </p><p>If <code>content</code> is not given (or is nil), only the opening tag is returned. If <code>content</code> is boolean <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">false</span></code>, a self-closed tag is returned. Otherwise it must be a string or number, in which case that content is enclosed in the constructed opening and closing tag. Note the content is not automatically HTML-encoded; use <a href="#mw.text.encode">mw.text.encode()</a> if needed. </p><p>For properly returning extension tags such as <code class="mw-highlight" style="white-space:nowrap"><span class="p">&#8206;&lt;</span><span class="nt">ref</span><span class="p">&gt;</span></code>, use <a href="#frame:extensionTag">frame:extensionTag()</a> instead. </p> <div class="mw-heading mw-heading4"><h4 id="mw.text.trim">mw.text.trim</h4></div> <p><code style="white-space:nowrap">mw.text.trim( string )</code> <br /> <code style="white-space:nowrap">mw.text.trim( string, charset )</code> </p><p>Remove whitespace or other characters from the beginning and end of a string. </p><p>If <code>charset</code> is supplied, it should be a string as appropriate to go inside brackets in a <a href="#Ustring_patterns">Ustring pattern</a>, i.e. the "set" in <code>[set]</code>. The default charset is ASCII whitespace, <code>%s</code>, which is equivalent to <code style="white-space:nowrap">"\t\r\n\f\v "</code>. </p> <div class="mw-heading mw-heading4"><h4 id="mw.text.truncate">mw.text.truncate</h4></div> <p><code style="white-space:nowrap">mw.text.truncate( text, length )</code> <br /> <code style="white-space:nowrap">mw.text.truncate( text, length, ellipsis )</code> <br /> <code style="white-space:nowrap">mw.text.truncate( text, length, ellipsis, adjustLength )</code> </p><p>Truncates <code>text</code> to the specified length in code points, adding <code>ellipsis</code> if truncation was performed. If length is positive, the end of the string will be truncated; if negative, the beginning will be removed. If <code>adjustLength</code> is given and <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">true</span></code>, the resulting string including ellipsis will not be longer than the specified length. </p><p>The default value for <code>ellipsis</code> is taken from <a href="/wiki/MediaWiki:Ellipsis" title="MediaWiki:Ellipsis">MediaWiki:ellipsis</a> in the wiki's content language. </p><p>Examples, using the default "..." ellipsis: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="c1">-- Returns &quot;foobarbaz&quot;</span> <span class="n">mw</span><span class="p">.</span><span class="n">text</span><span class="p">.</span><span class="n">truncate</span><span class="p">(</span> <span class="s2">&quot;foobarbaz&quot;</span><span class="p">,</span> <span class="mi">9</span> <span class="p">)</span> <span class="c1">-- Returns &quot;fooba...&quot;</span> <span class="n">mw</span><span class="p">.</span><span class="n">text</span><span class="p">.</span><span class="n">truncate</span><span class="p">(</span> <span class="s2">&quot;foobarbaz&quot;</span><span class="p">,</span> <span class="mi">5</span> <span class="p">)</span> <span class="c1">-- Returns &quot;...arbaz&quot;</span> <span class="n">mw</span><span class="p">.</span><span class="n">text</span><span class="p">.</span><span class="n">truncate</span><span class="p">(</span> <span class="s2">&quot;foobarbaz&quot;</span><span class="p">,</span> <span class="o">-</span><span class="mi">5</span> <span class="p">)</span> <span class="c1">-- Returns &quot;foo...&quot;</span> <span class="n">mw</span><span class="p">.</span><span class="n">text</span><span class="p">.</span><span class="n">truncate</span><span class="p">(</span> <span class="s2">&quot;foobarbaz&quot;</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="kc">nil</span><span class="p">,</span> <span class="kc">true</span> <span class="p">)</span> <span class="c1">-- Returns &quot;foobarbaz&quot;, because that&#39;s shorter than &quot;foobarba...&quot;</span> <span class="n">mw</span><span class="p">.</span><span class="n">text</span><span class="p">.</span><span class="n">truncate</span><span class="p">(</span> <span class="s2">&quot;foobarbaz&quot;</span><span class="p">,</span> <span class="mi">8</span> <span class="p">)</span> </pre></div> <div class="mw-heading mw-heading4"><h4 id="mw.text.unstripNoWiki">mw.text.unstripNoWiki</h4></div> <p><code style="white-space:nowrap">mw.text.unstripNoWiki( string )</code> </p><p>Replaces MediaWiki &lt;nowiki&gt; <a href="/wiki/Strip_marker" title="Strip marker">strip markers</a> with the corresponding text. Other types of strip markers are not changed. </p> <div class="mw-heading mw-heading4"><h4 id="mw.text.unstrip">mw.text.unstrip</h4></div> <p><code style="white-space:nowrap">mw.text.unstrip( string )</code> </p><p>Equivalent to <code style="white-space:nowrap">mw.text.killMarkers( mw.text.unstripNoWiki( string ) )</code>. </p><p>This no longer reveals the HTML behind special page transclusion, &lt;ref&gt; tags, and so on as it did in earlier versions of Scribunto. </p> <div class="mw-heading mw-heading3"><h3 id="Title_library">Title library</h3></div> <div class="mw-heading mw-heading4"><h4 id="mw.title.equals">mw.title.equals</h4></div> <p><code style="white-space:nowrap">mw.title.equals( a, b )</code> </p><p>Test for whether two titles are equal. Note that fragments are ignored in the comparison. </p> <div class="mw-heading mw-heading4"><h4 id="mw.title.compare">mw.title.compare</h4></div> <p><code style="white-space:nowrap">mw.title.compare( a, b )</code> </p><p>Returns -1, 0, or 1 to indicate whether the title <code>a</code> is less than, equal to, or greater than title <code>b</code>. </p><p>This compares titles by interwiki prefix (if any) as strings, then by namespace number, then by the unprefixed title text as a string. These string comparisons use Lua's standard <code>&lt;</code> operator. </p> <div class="mw-heading mw-heading4"><h4 id="mw.title.getCurrentTitle">mw.title.getCurrentTitle</h4></div> <p><code style="white-space:nowrap">mw.title.getCurrentTitle()</code> </p><p>Returns the title object for the current page. </p> <div class="mw-heading mw-heading4"><h4 id="mw.title.new">mw.title.new</h4></div> <p><code style="white-space:nowrap">mw.title.new( text, namespace )</code> <br /> <code style="white-space:nowrap">mw.title.new( ID )</code> </p> <dl><dd><span style="color:#d73333" dir="ltr">This function is <a href="/wiki/Special:MyLanguage/Manual:$wgExpensiveParserFunctionLimit" title="Special:MyLanguage/Manual:$wgExpensiveParserFunctionLimit">expensive</a> when called with an ID</span></dd></dl> <p>Creates a new title object. </p><p>If a number <code>ID</code> is given, an object is created for the title with that page_id. The title referenced will be counted as linked from the current page. If the page_id does not exist, returns nil. The expensive function count will be incremented if the title object created is not for a title that has already been loaded. </p><p>If a string <code>text</code> is given instead, an object is created for that title (even if the page does not exist). If the text string does not specify a namespace, <code>namespace</code> (which may be any key found in <code><a href="#mw.site.namespaces">mw.site.namespaces</a></code>) will be used. If the text is not a valid title, nil is returned. </p> <div class="mw-heading mw-heading4"><h4 id="mw.title.makeTitle">mw.title.makeTitle</h4></div> <p><code style="white-space:nowrap">mw.title.makeTitle( namespace, title, fragment, interwiki )</code> </p><p>Creates a title object with title <code>title</code> in namespace <code>namespace</code>, optionally with the specified <code>fragment</code> and <code>interwiki</code> prefix. <code>namespace</code> may be any key found in <code><a href="#mw.site.namespaces">mw.site.namespaces</a></code>. If the resulting title is not valid, returns nil. </p><p>Note that, unlike <code><a href="#mw.title.new">mw.title.new()</a></code>, this method will always apply the specified namespace. For example, <code style="white-space:nowrap">mw.title.makeTitle( 'Template', 'Module:Foo' )</code> will create an object for the page Template:Module:Foo, while <code style="white-space:nowrap">mw.title.new( 'Module:Foo', 'Template' )</code> will create an object for the page Module:Foo. </p><p>Note also that functionality for interwiki titles is limited to <code>interwiki</code> / <code>isExternal</code> / <code>isLocal</code> and URL-related methods; other methods might not behave as expected. </p> <div class="mw-heading mw-heading4"><h4 id="Title_objects">Title objects</h4></div> <p>A title object has a number of properties and methods. Most of the properties are read-only. </p><p>Note that fields ending with <code>text</code> return titles as string values whereas the fields ending with <code>title</code> return title objects. </p> <ul><li><b>id</b>: The page_id. <code>0</code> if the page does not exist. <span style="color:#d73333" dir="ltr">This <a href="#Expensive_properties">may be expensive</a></span>.</li> <li><b>interwiki</b>: The interwiki prefix, or the empty string if none.</li> <li><b>namespace</b>: The namespace number.</li> <li><b>fragment</b>: The fragment (aka section/anchor linking), or the empty string. May be assigned.</li> <li><b>nsText</b>: The text of the namespace for the page.</li> <li><b>subjectNsText</b>: The text of the subject namespace for the page.</li> <li><b>talkNsText</b>: The text of the talk namespace for the page, or <code>nil</code> if this title cannot have a talk page. <small>(added in MediaWiki 1.42.0-wmf.15, refs <a href="https://phabricator.wikimedia.org/T180911" class="extiw" title="phab:T180911">T180911</a>)</small></li> <li><b>text</b>: The title of the page, without the namespace or interwiki prefixes.</li> <li><b>prefixedText</b>: The title of the page, with the namespace and interwiki prefixes.</li> <li><b>fullText</b>: The title of the page, with the namespace and interwiki prefixes and the fragment. Interwiki is not returned if equal to the current.</li> <li><b>rootText</b>: If this is a subpage, the title of the root page without prefixes. Otherwise, the same as <code>title.text</code>.</li> <li><b>baseText</b>: If this is a subpage, the title of the page it is a subpage of without prefixes. Otherwise, the same as <code>title.text</code>.</li> <li><b>subpageText</b>: If this is a subpage, just the subpage name. Otherwise, the same as <code>title.text</code>.</li> <li><b>canTalk</b>: Whether the page for this title could have a talk page.</li> <li><b>exists</b>: Whether the page exists. Alias for <code>file.exists</code> for Media-namespace titles. For File-namespace titles this checks the existence of the file description page, not the file itself. <span style="color:#d73333" dir="ltr">This <a href="#Expensive_properties">may be expensive</a></span>.</li> <li><b>file</b>, <b>fileExists</b>: See <a href="#File_metadata">#File metadata</a> below.</li> <li><b>isContentPage</b>: Whether this title is in a content namespace.</li> <li><b>isExternal</b>: Whether this title has an interwiki prefix.</li> <li><b>isLocal</b>: Whether this title is in this project. For example, on the English Wikipedia, any other Wikipedia is considered "local" while Wiktionary and such are not.</li> <li><b>isRedirect</b>: Whether this is the title for a page that is a redirect. <span style="color:#d73333" dir="ltr">This <a href="#Expensive_properties">may be expensive</a></span>.</li> <li><b>isSpecialPage</b>: Whether this is the title for a possible special page (i.e. a page in the Special: namespace).</li> <li><b>isSubpage</b>: Whether this title is a subpage of some other title.</li> <li><b>isTalkPage</b>: Whether this is a title for a talk page.</li> <li><b>isSubpageOf( title2 )</b>: Whether this title is a subpage of the given title.</li> <li><b>inNamespace( ns )</b>: Whether this title is in the given namespace. Namespaces may be specified by anything that is a key found in <code><a href="#mw.site.namespaces">mw.site.namespaces</a></code>.</li> <li><b>inNamespaces( ... )</b>: Whether this title is in any of the given namespaces. Namespaces may be specified by anything that is a key found in <code><a href="#mw.site.namespaces">mw.site.namespaces</a></code>.</li> <li><b>hasSubjectNamespace( ns )</b>: Whether this title's subject namespace is in the given namespace. Namespaces may be specified by anything that is a key found in <code><a href="#mw.site.namespaces">mw.site.namespaces</a></code>.</li> <li><b>contentModel</b>: The content model for this title, as a string. <span style="color:#d73333" dir="ltr">This <a href="#Expensive_properties">may be expensive</a></span>.</li></ul> <ul><li><b>basePageTitle</b>: The same as <code style="white-space:nowrap">mw.title.makeTitle( title.namespace, title.baseText )</code>.</li> <li><b>rootPageTitle</b>: The same as <code style="white-space:nowrap">mw.title.makeTitle( title.namespace, title.rootText )</code>.</li> <li><b>talkPageTitle</b>: The same as <code style="white-space:nowrap">mw.title.makeTitle( mw.site.namespaces[title.namespace].talk.id, title.text )</code>, or <code>nil</code> if this title cannot have a talk page.</li> <li><b>subjectPageTitle</b>: The same as <code style="white-space:nowrap">mw.title.makeTitle( mw.site.namespaces[title.namespace].subject.id, title.text )</code>.</li> <li><b>redirectTarget:</b> Returns a title object of the target of the redirect page if the page is a redirect and the page exists, returns <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">false</span></code> otherwise.</li> <li><b>protectionLevels</b>: The page's protection levels. This is a table with keys corresponding to each action (e.g., <code>"edit"</code> and <code>"move"</code>). The table values are arrays, the first item of which is a string containing the protection level. If the page is unprotected, either the table values or the array items will be <code>nil</code>. <span style="color:#d73333" dir="ltr">This is <a href="/wiki/Special:MyLanguage/Manual:$wgExpensiveParserFunctionLimit" title="Special:MyLanguage/Manual:$wgExpensiveParserFunctionLimit">expensive</a></span>.</li> <li><b>cascadingProtection</b>: The cascading protections applicable to the page. This is a table with keys <code>"restrictions"</code> (itself a table with keys like <code>protectionLevels</code> has) and <code>"sources"</code> (an array listing titles where the protections cascade from). If no protections cascade to the page, <code>"restrictions"</code> and <code>"sources"</code> will be empty. <span style="color:#d73333" dir="ltr">This is <a href="/wiki/Special:MyLanguage/Manual:$wgExpensiveParserFunctionLimit" title="Special:MyLanguage/Manual:$wgExpensiveParserFunctionLimit">expensive</a></span>.</li> <li><b>categories</b>: <i>(since v1.43.0-wmf.18)</i> The list of categories used on the page. <span style="color:#d73333" dir="ltr">This is <a href="/wiki/Special:MyLanguage/Manual:$wgExpensiveParserFunctionLimit" title="Special:MyLanguage/Manual:$wgExpensiveParserFunctionLimit">expensive</a></span></li> <li><b>subPageTitle( text )</b>: The same as <code style="white-space:nowrap">mw.title.makeTitle( title.namespace, title.text .. '/' .. <var>text</var> )</code>.</li> <li><b>partialUrl()</b>: Returns <code>title.text</code> encoded as it would be in a URL.</li> <li><b>fullUrl( query, proto )</b>: Returns the full URL (with optional query table/string) for this title. <var>proto</var> may be specified to control the scheme of the resulting url: <code>"http"</code>, <code>"https"</code>, <code>"relative"</code> (the default), or <code>"canonical"</code>.</li> <li><b>localUrl( query )</b>: Returns the local URL (with optional query table/string) for this title.</li> <li><b>canonicalUrl( query )</b>: Returns the canonical URL (with optional query table/string) for this title.</li> <li><b>content</b> or <b>getContent()</b>: Returns the (unparsed) content of the page, or <code>nil</code> if there is no page. The page will be recorded as a transclusion.</li> <li><b>pageLang</b>: A <a href="#Language_library">language object</a> for the title's <a href="/wiki/Special:MyLanguage/Manual:Language#Page_content_language" title="Special:MyLanguage/Manual:Language">page content language</a>, which defaults to the wiki's content language. <span style="color:#d73333" dir="ltr">This is <a href="/wiki/Special:MyLanguage/Manual:$wgExpensiveParserFunctionLimit" title="Special:MyLanguage/Manual:$wgExpensiveParserFunctionLimit">expensive</a></span>.</li></ul> <p>Title objects may be compared using <a href="#Relational_operators">relational operators</a>. <code style="white-space:nowrap"><a href="#tostring">tostring</a>( title )</code> will return <code>title.prefixedText</code>. </p><p>Note that accessing any <a href="#Expensive_properties">expensive</a> field on a title object records a "link" to the page (as shown on <a href="/wiki/Special:WhatLinksHere" title="Special:WhatLinksHere">Special:WhatLinksHere</a>, for example). Using the title object's <code>getContent()</code> method or accessing the <code>redirectTarget</code> field records it as <code>file</code> or <code>fileExists</code> fields records it as a "file link". </p> <div class="mw-heading mw-heading5"><h5 id="File_metadata">File metadata</h5></div> <p>Title objects representing a page in the File or Media namespace will have a property called <code>file</code>. <span style="color:#d73333" dir="ltr">This is <a href="/wiki/Special:MyLanguage/Manual:$wgExpensiveParserFunctionLimit" title="Special:MyLanguage/Manual:$wgExpensiveParserFunctionLimit">expensive</a>.</span> This is a table, structured as follows: </p> <ul><li><b>exists</b>: Whether the file exists. It will be recorded as an image usage. The <code>fileExists</code> property on a Title object exists for backwards compatibility reasons and is an alias for this property. If this is <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">false</span></code>, all other file properties will be <code>nil</code>.</li> <li><b>width</b>: The width of the file. If the file contains multiple pages, this is the width of the first page.</li> <li><b>height</b>: The height of the file. If the file contains multiple pages, this is the height of the first page.</li> <li><b>pages</b>: If the file format supports multiple pages, this is a table containing tables for each page of the file; otherwise, it is <code>nil</code>. The <a href="#Length_operator"># operator</a> can be used to get the number of pages in the file. Each individual page table contains a width and height property.</li> <li><b>size</b>: The size of the file in bytes.</li> <li><b>mimeType</b>: The <a href="https://en.wikipedia.org/wiki/MIME_type" class="extiw" title="w:MIME type">MIME type</a> of the file.</li> <li><b>length</b>: The length (duration) of the media file in seconds. Zero for media types which do not support length.</li></ul> <div class="mw-heading mw-heading5"><h5 id="Expensive_properties">Expensive properties</h5></div> <p>The properties <code>id</code>, <code>isRedirect</code>, <code>exists</code>, and <code>contentModel</code> require fetching data about the title from the database. For this reason, the <a href="/wiki/Special:MyLanguage/Manual:$wgExpensiveParserFunctionLimit" title="Special:MyLanguage/Manual:$wgExpensiveParserFunctionLimit">expensive function count</a> is incremented the first time one of them is accessed for a page other than the current page. Subsequent accesses of any of these properties for that page will not increment the expensive function count again. </p><p>Other properties marked as expensive will always increment the expensive function count the first time they are accessed for a page other than the current page. </p> <div class="mw-heading mw-heading3"><h3 id="URI_library">URI library</h3></div> <div class="mw-heading mw-heading4"><h4 id="mw.uri.encode">mw.uri.encode</h4></div> <p><code style="white-space:nowrap">mw.uri.encode( string, enctype )</code> </p><p><a href="https://en.wikipedia.org/wiki/Percent-encoding" class="extiw" title="w:Percent-encoding">Percent-encodes</a> the string. The default type, <code>"QUERY"</code>, encodes spaces using '+' for use in query strings; <code>"PATH"</code> encodes spaces as %20; and <code>"WIKI"</code> encodes spaces as '_'. </p><p>Note that the "WIKI" format is not entirely reversible, as both spaces and underscores are encoded as '_'. </p> <div class="mw-heading mw-heading4"><h4 id="mw.uri.decode">mw.uri.decode</h4></div> <p><code style="white-space:nowrap">mw.uri.decode( string, enctype )</code> </p><p><a href="https://en.wikipedia.org/wiki/Percent-encoding" class="extiw" title="w:Percent-encoding">Percent-decodes</a> the string. The default type, <code>"QUERY"</code>, decodes '+' to space; <code>"PATH"</code> does not perform any extra decoding; and <code>"WIKI"</code> decodes '_' to space. </p> <div class="mw-heading mw-heading4"><h4 id="mw.uri.anchorEncode">mw.uri.anchorEncode</h4></div> <p><code style="white-space:nowrap">mw.uri.anchorEncode( string )</code> </p><p>Encodes a string for use in a MediaWiki URI fragment. </p> <div class="mw-heading mw-heading4"><h4 id="mw.uri.buildQueryString">mw.uri.buildQueryString</h4></div> <p><code style="white-space:nowrap">mw.uri.buildQueryString( table )</code> </p><p>Encodes a table as a URI query string. Keys should be strings; values may be strings or numbers, sequence tables, or boolean false. </p> <div class="mw-heading mw-heading4"><h4 id="mw.uri.parseQueryString">mw.uri.parseQueryString</h4></div> <p><code style="white-space:nowrap">mw.uri.parseQueryString( s, i, j )</code> </p><p>Decodes the query string <code>s</code> to a table. Keys in the string without values will have a value of <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">false</span></code>; keys repeated multiple times will have sequence tables as values; and others will have strings as values. </p><p>The optional numerical arguments <code>i</code> and <code>j</code> can be used to specify a substring of <code>s</code> to be parsed, rather than the entire string. <code>i</code> is the position of the first character of the substring, and defaults to 1. <code>j</code> is the position of the last character of the substring, and defaults to the length of the string. Both <code>i</code> and <code>j</code> can be negative, as in <a href="#string.sub">string.sub</a>. </p> <div class="mw-heading mw-heading4"><h4 id="mw.uri.canonicalUrl">mw.uri.canonicalUrl</h4></div> <p><code style="white-space:nowrap">mw.uri.canonicalUrl( page, query )</code> </p><p>Returns a <a href="#URI_object">URI object</a> for the <a href="/wiki/Special:MyLanguage/Help:Magic_words#URL_data" title="Special:MyLanguage/Help:Magic words">canonical URL</a> for a page, with optional query string/table. </p> <div class="mw-heading mw-heading4"><h4 id="mw.uri.fullUrl">mw.uri.fullUrl</h4></div> <p><code style="white-space:nowrap">mw.uri.fullUrl( page, query )</code> </p><p>Returns a <a href="#URI_object">URI object</a> for the <a href="/wiki/Special:MyLanguage/Help:Magic_words#URL_data" title="Special:MyLanguage/Help:Magic words">full URL</a> for a page, with optional query string/table. </p> <div class="mw-heading mw-heading4"><h4 id="mw.uri.localUrl">mw.uri.localUrl</h4></div> <p><code style="white-space:nowrap">mw.uri.localUrl( page, query )</code> </p><p>Returns a <a href="#URI_object">URI object</a> for the <a href="/wiki/Special:MyLanguage/Help:Magic_words#URL_data" title="Special:MyLanguage/Help:Magic words">local URL</a> for a page, with optional query string/table. </p> <div class="mw-heading mw-heading4"><h4 id="mw.uri.new">mw.uri.new</h4></div> <p><code style="white-space:nowrap">mw.uri.new( string )</code> </p><p>Constructs a new <a href="#URI_object">URI object</a> for the passed string or table. See the description of URI objects for the possible fields for the table. </p> <div class="mw-heading mw-heading4"><h4 id="mw.uri.validate">mw.uri.validate</h4></div> <p><code style="white-space:nowrap">mw.uri.validate( table )</code> </p><p>Validates the passed table (or URI object). Returns a boolean indicating whether the table was valid, and on failure a string explaining what problems were found. </p> <div class="mw-heading mw-heading4"><h4 id="URI_object">URI object</h4></div> <p>The URI object has the following fields, some or all of which may be nil: </p> <ul><li><b>protocol</b>: String protocol/scheme</li> <li><b>user</b>: String user</li> <li><b>password</b>: String password</li> <li><b>host</b>: String host name</li> <li><b>port</b>: Integer port</li> <li><b>path</b>: String path</li> <li><b>query</b>: A table, as from <a href="#mw.uri.parseQueryString">mw.uri.parseQueryString</a></li> <li><b>fragment</b>: String fragment.</li></ul> <p>The following properties are also available: </p> <ul><li><b>userInfo</b>: String user and password</li> <li><b>hostPort</b>: String host and port</li> <li><b>authority</b>: String user, password, host, and port</li> <li><b>queryString</b>: String version of the query table</li> <li><b>relativePath</b>: String path, query string, and fragment</li></ul> <p><a href="#tostring"><code>tostring()</code></a> will give the URI string. </p><p>Methods of the URI object are: </p> <div class="mw-heading mw-heading5"><h5 id="mw.uri:parse">mw.uri:parse</h5></div> <p><code style="white-space:nowrap">uri:parse( string )</code> </p><p>Parses a string into the current URI object. Any fields specified in the string will be replaced in the current object; fields not specified will keep their old values. </p> <div class="mw-heading mw-heading5"><h5 id="mw.uri:clone">mw.uri:clone</h5></div> <p><code>uri:clone()</code> </p><p>Makes a copy of the URI object. </p> <div class="mw-heading mw-heading5"><h5 id="mw.uri:extend">mw.uri:extend</h5></div> <p><code style="white-space:nowrap">uri:extend( parameters )</code> </p><p>Merges the parameters table into the object's query table. </p> <div class="mw-heading mw-heading3"><h3 id="Ustring_library">Ustring library</h3></div> <p>The ustring library is intended to be a direct reimplementation of the standard <a href="#String_library">String library</a>, except that the methods operate on characters in UTF-8 encoded strings rather than bytes. </p><p>Most functions will raise an error if the string is not valid UTF-8; exceptions are noted. </p> <div class="mw-heading mw-heading4"><h4 id="mw.ustring.maxPatternLength">mw.ustring.maxPatternLength</h4></div> <p>The maximum allowed length of a pattern, in bytes. </p> <div class="mw-heading mw-heading4"><h4 id="mw.ustring.maxStringLength">mw.ustring.maxStringLength</h4></div> <p>The maximum allowed length of a string, in bytes. </p> <div class="mw-heading mw-heading4"><h4 id="mw.ustring.byte">mw.ustring.byte</h4></div> <p><code style="white-space:nowrap">mw.ustring.byte( s, i, j )</code> </p><p>Returns individual bytes; identical to <a href="#string.byte">string.byte()</a>. </p> <div class="mw-heading mw-heading4"><h4 id="mw.ustring.byteoffset">mw.ustring.byteoffset</h4></div> <p><code style="white-space:nowrap">mw.ustring.byteoffset( s, l, i )</code> </p><p>Returns the byte offset of a character in the string. The default for both <code>l</code> and <code>i</code> is 1. <code>i</code> may be negative, in which case it counts from the end of the string. </p><p>The character at <code>l</code> == 1 is the first character starting at or after byte <code>i</code>; the character at <code>l</code> == 0 is the first character starting at or before byte <code>i</code>. Note this may be the same character. Greater or lesser values of <code>l</code> are calculated relative to these. </p> <div class="mw-heading mw-heading4"><h4 id="mw.ustring.char">mw.ustring.char</h4></div> <p><code style="white-space:nowrap">mw.ustring.char( ... )</code> </p><p>Much like <a href="#string.char">string.char()</a>, except that the integers are Unicode codepoints rather than byte values. </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="kd">local</span> <span class="n">value</span> <span class="o">=</span> <span class="n">mw</span><span class="p">.</span><span class="n">ustring</span><span class="p">.</span><span class="n">char</span><span class="p">(</span> <span class="mh">0x41f</span><span class="p">,</span> <span class="mh">0x440</span><span class="p">,</span> <span class="mh">0x438</span><span class="p">,</span> <span class="mh">0x432</span><span class="p">,</span> <span class="mh">0x435</span><span class="p">,</span> <span class="mh">0x442</span><span class="p">,</span> <span class="mh">0x21</span> <span class="p">)</span> <span class="c1">-- value is now &#39;Привет!&#39;</span> </pre></div> <div class="mw-heading mw-heading4"><h4 id="mw.ustring.codepoint">mw.ustring.codepoint</h4></div> <p><code style="white-space:nowrap">mw.ustring.codepoint( s, i, j )</code> </p><p>Much like <a href="#string.byte">string.byte()</a>, except that the return values are codepoints and the offsets are characters rather than bytes. </p> <div class="mw-heading mw-heading4"><h4 id="mw.ustring.find">mw.ustring.find</h4></div> <p><code style="white-space:nowrap">mw.ustring.find( s, pattern, init, plain )</code> </p><p>Much like <a href="#string.find">string.find()</a>, except that the pattern is extended as described in <a href="#Ustring_patterns">Ustring patterns</a> and the <code>init</code> offset is in characters rather than bytes. </p> <div class="mw-heading mw-heading4"><h4 id="mw.ustring.format">mw.ustring.format</h4></div> <p><code style="white-space:nowrap">mw.ustring.format( format, ... )</code> </p><p>Identical to <a href="#string.format">string.format()</a>. Widths and precisions for strings are expressed in bytes, not codepoints. </p> <div class="mw-heading mw-heading4"><h4 id="mw.ustring.gcodepoint">mw.ustring.gcodepoint</h4></div> <p><code style="white-space:nowrap">mw.ustring.gcodepoint( s, i, j )</code> </p><p>Returns three values for iterating over the codepoints in the string. <code>i</code> defaults to 1, and <code>j</code> to -1. This is intended for use in the <a href="#iterators">iterator form of <code>for</code></a>: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="kr">for</span> <span class="n">codepoint</span> <span class="kr">in</span> <span class="n">mw</span><span class="p">.</span><span class="n">ustring</span><span class="p">.</span><span class="n">gcodepoint</span><span class="p">(</span> <span class="n">s</span> <span class="p">)</span> <span class="kr">do</span> <span class="c1">-- block</span> <span class="kr">end</span> </pre></div> <div class="mw-heading mw-heading4"><h4 id="mw.ustring.gmatch">mw.ustring.gmatch</h4></div> <p><code style="white-space:nowrap">mw.ustring.gmatch( s, pattern )</code> </p><p>Much like <a href="#string.gmatch">string.gmatch()</a>, except that the pattern is extended as described in <a href="#Ustring_patterns">Ustring patterns</a>. </p><p><span style="color:#d73333" dir="ltr">Known bug</span> - When used with a pattern which can match the empty string, the function will get stuck in an infinite loop. For example, the following loop never terminates: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="kr">for</span> <span class="n">capture</span> <span class="kr">in</span> <span class="n">mw</span><span class="p">.</span><span class="n">ustring</span><span class="p">.</span><span class="n">gmatch</span><span class="p">(</span> <span class="s2">&quot;foo bar&quot;</span><span class="p">,</span> <span class="s2">&quot;.*&quot;</span> <span class="p">)</span> <span class="kr">do</span> <span class="c1">-- block</span> <span class="kr">end</span> </pre></div> <div class="mw-heading mw-heading4"><h4 id="mw.ustring.gsub">mw.ustring.gsub</h4></div> <p><code style="white-space:nowrap">mw.ustring.gsub( s, pattern, repl, n )</code> </p><p>Much like <a href="#string.gsub">string.gsub()</a>, except that the pattern is extended as described in <a href="#Ustring_patterns">Ustring patterns</a>. </p><p><span style="color:#d73333" dir="ltr">Known bugs</span>: When <code>repl</code> is a table, it is possible to use numbers as keys instead of strings (e.g. to replace instances of <code><code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><span class="s2">&quot;5&quot;</span></code></code> in a string, the value at key <code><code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><span class="p">[</span><span class="mi">5</span><span class="p">]</span></code></code> or <code><code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><span class="p">[</span><span class="s2">&quot;5&quot;</span><span class="p">]</span></code></code> would be used); as such, the output is not predictable if they have different (non-nil) values. This is not an issue for <a href="#string.gsub">string.gsub()</a>, which ignores any numbers as keys. </p> <div class="mw-heading mw-heading4"><h4 id="mw.ustring.isutf8">mw.ustring.isutf8</h4></div> <p><code style="white-space:nowrap">mw.ustring.isutf8( string )</code> </p><p>Returns <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">true</span></code> if the string is valid UTF-8, <code class="mw-highlight mw-highlight-lang-lua mw-content-ltr" style="" dir="ltr"><span class="kc">false</span></code> if not. </p> <div class="mw-heading mw-heading4"><h4 id="mw.ustring.len">mw.ustring.len</h4></div> <p><code style="white-space:nowrap">mw.ustring.len( string )</code> </p><p>Returns the length of the string in codepoints, or nil if the string is not valid UTF-8. </p><p>See <a href="#string.len">string.len()</a> for a similar function that uses byte length rather than codepoints. </p> <div class="mw-heading mw-heading4"><h4 id="mw.ustring.lower">mw.ustring.lower</h4></div> <p><code style="white-space:nowrap">mw.ustring.lower( string )</code> </p><p>Much like <a href="#string.lower">string.lower()</a>, except that all characters with lowercase to uppercase definitions in Unicode are converted. </p><p>If the <a href="#Language_library">Language library</a> is also loaded, this will instead call <a href="#mw.language:lc">lc()</a> on the default language object. </p> <div class="mw-heading mw-heading4"><h4 id="mw.ustring.match">mw.ustring.match</h4></div> <p><code style="white-space:nowrap">mw.ustring.match( s, pattern, init )</code> </p><p>Much like <a href="#string.match">string.match()</a>, except that the pattern is extended as described in <a href="#Ustring_patterns">Ustring patterns</a> and the <code>init</code> offset is in characters rather than bytes. </p> <div class="mw-heading mw-heading4"><h4 id="mw.ustring.rep">mw.ustring.rep</h4></div> <p><code style="white-space:nowrap">mw.ustring.rep( string, n )</code> </p><p>Identical to <a href="#string.rep">string.rep()</a>. </p> <div class="mw-heading mw-heading4"><h4 id="mw.ustring.sub">mw.ustring.sub</h4></div> <p><code style="white-space:nowrap">mw.ustring.sub( s, i, j )</code> </p><p>Much like <a href="#string.sub">string.sub()</a>, except that the offsets are characters rather than bytes. </p> <div class="mw-heading mw-heading4"><h4 id="mw.ustring.toNFC">mw.ustring.toNFC</h4></div> <p><code style="white-space:nowrap">mw.ustring.toNFC( string )</code> </p><p>Converts the string to <a href="https://en.wikipedia.org/wiki/Normalization_Form_C" class="extiw" title="w:Normalization Form C">Normalization Form C</a> (also known as Normalization Form Canonical Composition). Returns nil if the string is not valid UTF-8. </p> <div class="mw-heading mw-heading4"><h4 id="mw.ustring.toNFD">mw.ustring.toNFD</h4></div> <p><code style="white-space:nowrap">mw.ustring.toNFD( s )</code> </p><p>Converts the string to <a href="https://en.wikipedia.org/wiki/Normalization_Form_D" class="extiw" title="w:Normalization Form D">Normalization Form D</a> (also known as Normalization Form Canonical Decomposition). Returns nil if the string is not valid UTF-8. </p> <div class="mw-heading mw-heading4"><h4 id="mw.ustring.toNFKC">mw.ustring.toNFKC</h4></div> <p><code style="white-space:nowrap">mw.ustring.toNFKC( s )</code> </p><p>Converts the string to <a href="https://en.wikipedia.org/wiki/Normalization_Form_KC" class="extiw" title="w:Normalization Form KC">Normalization Form KC</a> (also known as Normalization Form Compatibility Composition). Returns nil if the string is not valid UTF-8. </p> <div class="mw-heading mw-heading4"><h4 id="mw.ustring.toNFKD">mw.ustring.toNFKD</h4></div> <p><code style="white-space:nowrap">mw.ustring.toNFKD( s )</code> </p><p>Converts the string to <a href="https://en.wikipedia.org/wiki/Normalization_Form_KD" class="extiw" title="w:Normalization Form KD">Normalization Form KD</a> (also known as Normalization Form Compatibility Decomposition). Returns nil if the string is not valid UTF-8. </p> <div class="mw-heading mw-heading4"><h4 id="mw.ustring.upper">mw.ustring.upper</h4></div> <p><code style="white-space:nowrap">mw.ustring.upper( s )</code> </p><p>Much like <a href="#string.upper">string.upper()</a>, except that all characters with uppercase to lowercase definitions in Unicode are converted. </p><p>If the <a href="#Language_library">Language library</a> is also loaded, this will instead call <a href="#mw.language:uc">uc()</a> on the default language object. </p> <div class="mw-heading mw-heading4"><h4 id="Ustring_patterns">Ustring patterns</h4></div> <p>Patterns in the ustring functions use the same syntax as the <a href="#Patterns">String library patterns</a>. The major difference is that the character classes are redefined in terms of <a href="https://en.wikipedia.org/wiki/Unicode_character_property" class="extiw" title="w:Unicode character property">Unicode character properties</a>: </p> <ul><li><b><code>%a</code></b>: represents all characters with General Category "Letter".</li> <li><b><code>%c</code></b>: represents all characters with General Category "Control".</li> <li><b><code>%d</code></b>: represents all characters with General Category "Number, decimal digit".</li> <li><b><code>%l</code></b>: represents all characters with General Category "Lowercase Letter".</li> <li><b><code>%p</code></b>: represents all characters with General Category "Punctuation".</li> <li><b><code>%s</code></b>: represents all characters with General Category "Separator", plus tab, linefeed, carriage return, vertical tab, and form feed.</li> <li><b><code>%u</code></b>: represents all characters with General Category "Uppercase Letter".</li> <li><b><code>%w</code></b>: represents all characters with General Category "Letter" or "Decimal Number".</li> <li><b><code>%x</code></b>: adds fullwidth character versions of the hex digits.</li></ul> <p>Like in <a href="#Patterns">String library patterns</a>, <b><code>%A</code></b>, <b><code>%C</code></b>, <b><code>%D</code></b>, <b><code>%L</code></b>, <b><code>%P</code></b>, <b><code>%S</code></b>, <b><code>%U</code></b>, <b><code>%W</code></b> and <b><code>%X</code></b> here represent the complementary set ("all characters <i>without</i> given General Category"). </p><p>In all cases, characters are interpreted as Unicode characters instead of bytes, so ranges such as <code>[0-9]</code>, patterns such as <code>%b«»</code>, and quantifiers applied to multibyte characters will work correctly. Empty captures will capture the position in code points rather than bytes. </p><p><span style="color:#d73333" dir="ltr">Known limitations</span>: Unlike <a href="#Patterns">String library patterns</a>, Ustring library patterns have a maximum length of 10,000 bytes. If the pattern exceeds this length, then the Ustring function will throw an error. Because the String library has its own maximum of 32 captures (unlike the Ustring library), it is therefore impossible to use a pattern which exceeds both limits, as it will be incompatible with both libraries. </p><p><span style="color:#d73333" dir="ltr">Note</span>: 9 ASCII characters, <b><code>$</code></b>, <b><code>+</code></b>, <b><code>&lt;</code></b>, <b><code>=</code></b>, <b><code>&gt;</code></b>, <b><code>^</code></b>, <b><code>`</code></b>, <b><code>|</code></b>, <b><code>~</code></b>, can be matched by <b><code>%p</code></b> in the string library but not in the ustring library, as Unicode classifies them as Symbols rather than Punctuation. </p> <div class="mw-heading mw-heading2"><h2 id="Loadable_libraries">Loadable libraries</h2></div> <p>These libraries are not included by default, but if needed may be loaded using <code><a href="#require">require()</a></code>. </p> <div class="mw-heading mw-heading3"><h3 id="bit32">bit32</h3></div> <p>This emulation of the Lua 5.2 <code>bit32</code> library may be loaded using: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span> <span class="n">bit32</span> <span class="o">=</span> <span class="nb">require</span><span class="p">(</span> <span class="s1">&#39;bit32&#39;</span> <span class="p">)</span> </pre></div> <p>The bit32 library provides <a href="https://en.wikipedia.org/wiki/Bitwise_operation" class="extiw" title="w:Bitwise operation">bitwise operations</a> on unsigned 32-bit integers. Input numbers are truncated to integers (in an unspecified manner) and reduced modulo 2<sup>32</sup> so the value is in the range 0 to 2<sup>32</sup>−1; return values are also in this range. </p><p>When bits are numbered (as in <a href="#bit32.extract">bit32.extract()</a>), 0 is the least-significant bit (the one with value 2<sup>0</sup>) and 31 is the most-significant (the one with value 2<sup>31</sup>). </p> <div class="mw-heading mw-heading4"><h4 id="bit32.band">bit32.band</h4></div> <p><code style="white-space:nowrap">bit32.band( ... )</code> </p><p>Returns the <a href="https://en.wikipedia.org/wiki/Bitwise_operation#AND" class="extiw" title="w:Bitwise operation">bitwise AND</a> of its arguments: the result has a bit set only if that bit is set in all of the arguments. </p><p>If given zero arguments, the result has all bits set. </p> <div class="mw-heading mw-heading4"><h4 id="bit32.bnot">bit32.bnot</h4></div> <p><code style="white-space:nowrap">bit32.bnot( x )</code> </p><p>Returns the <a href="https://en.wikipedia.org/wiki/Bitwise_operation#NOT" class="extiw" title="w:Bitwise operation">bitwise complement</a> of <code>x</code>. </p> <div class="mw-heading mw-heading4"><h4 id="bit32.bor">bit32.bor</h4></div> <p><code style="white-space:nowrap">bit32.bor( ... )</code> </p><p>Returns the <a href="https://en.wikipedia.org/wiki/Bitwise_operation#OR" class="extiw" title="w:Bitwise operation">bitwise OR</a> of its arguments: the result has a bit set if that bit is set in any of the arguments. </p><p>If given zero arguments, the result has all bits clear. </p> <div class="mw-heading mw-heading4"><h4 id="bit32.btest">bit32.btest</h4></div> <p><code style="white-space:nowrap">bit32.btest( ... )</code> </p><p>Equivalent to <code style="white-space:nowrap">bit32.band( ... ) ~= 0</code> </p> <div class="mw-heading mw-heading4"><h4 id="bit32.bxor">bit32.bxor</h4></div> <p><code style="white-space:nowrap">bit32.bxor( ... )</code> </p><p>Returns the <a href="https://en.wikipedia.org/wiki/Bitwise_operation#XOR" class="extiw" title="w:Bitwise operation">bitwise XOR</a> of its arguments: the result has a bit set if that bit is set in an odd number of the arguments. </p><p>If given zero arguments, the result has all bits clear. </p> <div class="mw-heading mw-heading4"><h4 id="bit32.extract">bit32.extract</h4></div> <p><code style="white-space:nowrap">bit32.extract( n, field, width )</code> </p><p>Extracts <code>width</code> bits from <code>n</code>, starting with bit <code>field</code>. Accessing bits outside of the range 0 to 31 is an error. </p><p>If not specified, the default for <code>width</code> is 1. </p> <div class="mw-heading mw-heading4"><h4 id="bit32.replace">bit32.replace</h4></div> <p><code style="white-space:nowrap">bit32.replace( n, v, field, width )</code> </p><p>Replaces <code>width</code> bits in <code>n</code>, starting with bit <code>field</code>, with the low <code>width</code> bits from <code>v</code>. Accessing bits outside of the range 0 to 31 is an error. </p><p>If not specified, the default for <code>width</code> is 1. </p> <div class="mw-heading mw-heading4"><h4 id="bit32.lshift">bit32.lshift</h4></div> <p><code style="white-space:nowrap">bit32.lshift( n, disp )</code> </p><p>Returns the number <code>n</code> <a href="https://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts" class="extiw" title="w:Bitwise operation">shifted</a> <code>disp</code> bits to the left. This is a <a href="https://en.wikipedia.org/wiki/Logical_shift" class="extiw" title="w:Logical shift">logical shift</a>: inserted bits are 0. This is generally equivalent to multiplying by 2<sup><code>disp</code></sup>. </p><p>Note that a displacement over 31 will result in 0. </p> <div class="mw-heading mw-heading4"><h4 id="bit32.rshift">bit32.rshift</h4></div> <p><code style="white-space:nowrap">bit32.rshift( n, disp )</code> </p><p>Returns the number <code>n</code> <a href="https://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts" class="extiw" title="w:Bitwise operation">shifted</a> <code>disp</code> bits to the right. This is a <a href="https://en.wikipedia.org/wiki/Logical_shift" class="extiw" title="w:Logical shift">logical shift</a>: inserted bits are 0. This is generally equivalent to dividing by 2<sup><code>disp</code></sup>. </p><p>Note that a displacement over 31 will result in 0. </p> <div class="mw-heading mw-heading4"><h4 id="bit32.arshift">bit32.arshift</h4></div> <p><code style="white-space:nowrap">bit32.arshift( n, disp )</code> </p><p>Returns the number <code>n</code> shifted <code>disp</code> bits to the right. This is an <a href="https://en.wikipedia.org/wiki/Arithmetic_shift" class="extiw" title="w:Arithmetic shift">arithmetic shift</a>: if <code>disp</code> is positive, the inserted bits will be the same as bit 31 in the original number. </p><p>Note that a displacement over 31 will result in 0 or 4294967295. </p> <div class="mw-heading mw-heading4"><h4 id="bit32.lrotate">bit32.lrotate</h4></div> <p><code style="white-space:nowrap">bit32.lrotate( n, disp )</code> </p><p>Returns the number <code>n</code> <a href="https://en.wikipedia.org/wiki/Bitwise_operation#Rotate_no_carry" class="extiw" title="w:Bitwise operation">rotated</a> <code>disp</code> bits to the left. </p><p>Note that rotations are equivalent modulo 32: a rotation of 32 is the same as a rotation of 0, 33 is the same as 1, and so on. </p> <div class="mw-heading mw-heading4"><h4 id="bit32.rrotate">bit32.rrotate</h4></div> <p><code style="white-space:nowrap">bit32.rrotate( n, disp )</code> </p><p>Returns the number <code>n</code> <a href="https://en.wikipedia.org/wiki/Bitwise_operation#Rotate_no_carry" class="extiw" title="w:Bitwise operation">rotated</a> <code>disp</code> bits to the right. </p><p>Note that rotations are equivalent modulo 32: a rotation of 32 is the same as a rotation of 0, 33 is the same as 1, and so on. </p> <div class="mw-heading mw-heading3"><h3 id="libraryUtil">libraryUtil</h3></div> <p>This library contains methods useful when implementing Scribunto libraries. It may be loaded using: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span> <span class="n">libraryUtil</span> <span class="o">=</span> <span class="nb">require</span><span class="p">(</span> <span class="s1">&#39;libraryUtil&#39;</span> <span class="p">)</span> </pre></div> <div class="mw-heading mw-heading4"><h4 id="libraryUtil.checkType">libraryUtil.checkType</h4></div> <p><code style="white-space:nowrap">libraryUtil.checkType( name, argIdx, arg, expectType, nilOk )</code> </p><p>Raises an error if <code style="white-space:nowrap"><a href="#type">type</a>( arg )</code> does not match <code>expectType</code>. In addition, no error will be raised if <code>arg</code> is nil and <code>nilOk</code> is true. </p><p><code>name</code> is the name of the calling function, and <code>argIdx</code> is the position of the argument in the argument list. These are used in formatting the error message. </p> <div class="mw-heading mw-heading4"><h4 id="libraryUtil.checkTypeMulti">libraryUtil.checkTypeMulti</h4></div> <p><code style="white-space:nowrap">libraryUtil.checkTypeMulti( name, argIdx, arg, expectTypes )</code> </p><p>Raises an error if <code style="white-space:nowrap"><a href="#type">type</a>( arg )</code> does not match any of the strings in the array <code>expectTypes</code>. </p><p>This is for arguments that have more than one valid type. </p> <div class="mw-heading mw-heading4"><h4 id="libraryUtil.checkTypeForIndex">libraryUtil.checkTypeForIndex</h4></div> <p><code style="white-space:nowrap">libraryUtil.checkTypeForIndex( index, value, expectType )</code> </p><p>Raises an error if <code style="white-space:nowrap"><a href="#type">type</a>( value )</code> does not match <code>expectType</code>. </p><p>This is intended for use in implementing a <code>__newindex</code> <a href="#Metatables">metamethod</a>. </p> <div class="mw-heading mw-heading4"><h4 id="libraryUtil.checkTypeForNamedArg">libraryUtil.checkTypeForNamedArg</h4></div> <p><code style="white-space:nowrap">libraryUtil.checkTypeForNamedArg( name, argName, arg, expectType, nilOk )</code> </p><p>Raises an error if <code style="white-space:nowrap"><a href="#type">type</a>( arg )</code> does not match <code>expectType</code>. In addition, no error will be raised if <code>arg</code> is nil and <code>nilOk</code> is true. </p><p>This is intended to be used as an equivalent to <code><a href="#libraryUtil.checkType">libraryUtil.checkType()</a></code> in methods called using Lua's "named argument" syntax, <code style="white-space:nowrap">func{ name = value }</code>. </p> <div class="mw-heading mw-heading4"><h4 id="libraryUtil.makeCheckSelfFunction">libraryUtil.makeCheckSelfFunction</h4></div> <p><code style="white-space:nowrap">libraryUtil.makeCheckSelfFunction( libraryName, varName, selfObj, selfObjDesc )</code> </p><p>This is intended for use in implementing "methods" on object tables that are intended to be called with the <code>obj:method()</code> syntax. It returns a function that should be called at the top of these methods with the <code>self</code> argument and the method name, which will raise an error if that <code>self</code> object is not <code>selfObj</code>. </p><p>This function will generally be used in a library's constructor function, something like this: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span> <span class="kr">function</span> <span class="nc">myLibrary</span><span class="p">.</span><span class="nf">new</span><span class="p">()</span> <span class="kd">local</span> <span class="n">obj</span> <span class="o">=</span> <span class="p">{}</span> <span class="kd">local</span> <span class="n">checkSelf</span> <span class="o">=</span> <span class="n">libraryUtil</span><span class="p">.</span><span class="n">makeCheckSelfFunction</span><span class="p">(</span> <span class="s1">&#39;myLibrary&#39;</span><span class="p">,</span> <span class="s1">&#39;obj&#39;</span><span class="p">,</span> <span class="n">obj</span><span class="p">,</span> <span class="s1">&#39;myLibrary object&#39;</span> <span class="p">)</span> <span class="kr">function</span> <span class="nc">obj</span><span class="p">:</span><span class="nf">method</span><span class="p">()</span> <span class="n">checkSelf</span><span class="p">(</span> <span class="n">self</span><span class="p">,</span> <span class="s1">&#39;method&#39;</span> <span class="p">)</span> <span class="kr">end</span> <span class="kr">function</span> <span class="nc">obj</span><span class="p">:</span><span class="nf">method2</span><span class="p">()</span> <span class="n">checkSelf</span><span class="p">(</span> <span class="n">self</span><span class="p">,</span> <span class="s1">&#39;method2&#39;</span> <span class="p">)</span> <span class="kr">end</span> <span class="kr">return</span> <span class="n">obj</span> <span class="kr">end</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="luabit">luabit</h3></div> <p>The <a rel="nofollow" class="external text" href="http://luaforge.net/projects/bit/">luabit</a> library modules "bit" and "hex" may be loaded using: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span> <span class="n">bit</span> <span class="o">=</span> <span class="nb">require</span><span class="p">(</span> <span class="s1">&#39;luabit.bit&#39;</span> <span class="p">)</span> <span class="n">hex</span> <span class="o">=</span> <span class="nb">require</span><span class="p">(</span> <span class="s1">&#39;luabit.hex&#39;</span> <span class="p">)</span> </pre></div> <p>Note that the <a href="#bit32">bit32 library</a> contains the same operations as "luabit.bit", and the operations in "luabit.hex" may be performed using <code><a href="#string.format">string.format()</a></code> and <code><a href="#tonumber">tonumber()</a></code>. </p><p>The luabit module "noki" is not available, as it is entirely useless in Scribunto. The luabit module "utf8" is also not available, as it was considered redundant to the <a href="#Ustring_library">Ustring library</a>. </p> <div class="mw-heading mw-heading3"><h3 id="strict">strict</h3></div> <p>The <i>strict</i> library is not a normal library; it causes an error to be raised whenever a new variable is used that is not explicitly scoped as a local variable (e.g., global variable assignment references). This functionality is typically enabled by loading at the top of a module using: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span> <span class="nb">require</span><span class="p">(</span> <span class="s1">&#39;strict&#39;</span> <span class="p">)</span> </pre></div> <p>On many Wikimedia wikis this was formerly implemented in <code>Module:No globals</code>, which was replaced via <a href="https://phabricator.wikimedia.org/T209310" class="extiw" title="phab:T209310">phab:T209310</a>. It is in part derived from <a rel="nofollow" class="external text" href="https://www.lua.org/extras/5.1/strict.lua">strict.lua</a>. </p> <div class="mw-heading mw-heading3"><h3 id="ustring">ustring</h3></div> <p>The pure-Lua backend to the <a href="#Ustring_library">Ustring library</a> may be loaded using: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span> <span class="n">ustring</span> <span class="o">=</span> <span class="nb">require</span><span class="p">(</span> <span class="s1">&#39;ustring&#39;</span> <span class="p">)</span> </pre></div> <p>In all cases the Ustring library (<code>mw.ustring</code>) should be used instead, as that replaces many of the slower and more memory-intensive operations with callbacks into PHP code. </p> <div class="mw-heading mw-heading2"><h2 id="Extension_libraries">Extension libraries</h2></div> <p>Some MediaWiki extensions provide additional Scribunto libraries. These are also located in the table <code>mw</code>, usually in the table <code>mw.ext</code>, however, they are only present when certain extensions are installed (in addition to the Scribunto extension itself). </p><p>Such extensions use Scribunto provided hooks: </p> <ul><li><a href="/wiki/Category:ScribuntoExternalLibraries_extensions" title="Category:ScribuntoExternalLibraries extensions">ScribuntoExternalLibraries</a></li> <li><a href="/wiki/Category:ScribuntoExternalLibraryPaths_extensions" title="Category:ScribuntoExternalLibraryPaths extensions">ScribuntoExternalLibraryPaths</a></li></ul> <p><a href="#Writing_Scribunto_libraries">Writing Scribunto libraries</a> provides information on how such libraries can be developed to provide Lua interfaces for MediaWiki extensions. </p> <div class="mw-heading mw-heading3"><h3 id="mw.wikibase">mw.wikibase</h3></div> <p><a href="/wiki/Special:MyLanguage/Extension:Wikibase_Client" title="Special:MyLanguage/Extension:Wikibase Client">Wikibase Client</a><span style="display:none"><a href="/wiki/Extension:Wikibase_Client" title="Extension:Wikibase Client"> </a></span> provides access to localizable structured data, most notably <a href="https://www.wikidata.org/wiki/Special:MyLanguage/Wikidata:Main_Page" class="extiw" title="d:Special:MyLanguage/Wikidata:Main Page">Wikidata</a>. See <a href="https://doc.wikimedia.org/Wikibase/master/php/docs_topics_lua.html" class="extiw" title="wmdoc:Wikibase/master/php/docs topics lua.html">docs_topics_lua.html</a> and <a href="/wiki/Special:MyLanguage/Extension:Wikibase_Client/Lua" title="Special:MyLanguage/Extension:Wikibase Client/Lua">Extension:Wikibase Client/Lua</a><span style="display:none"><a href="/wiki/Extension:Wikibase_Client/Lua" title="Extension:Wikibase Client/Lua"> </a></span>. </p> <div class="mw-heading mw-heading3"><h3 id="mw.wikibase.lexeme">mw.wikibase.lexeme</h3></div> <p><a href="/wiki/Special:MyLanguage/Extension:WikibaseLexeme" title="Special:MyLanguage/Extension:WikibaseLexeme">WikibaseLexeme</a><span style="display:none"><a href="/wiki/Extension:WikibaseLexeme" title="Extension:WikibaseLexeme"> </a></span> provides access to Wikibase Lexeme entities. This is supported by <a href="https://www.wikidata.org/wiki/Special:MyLanguage/Wikidata:Lexicographical_data" class="extiw" title="d:Special:MyLanguage/Wikidata:Lexicographical data">Wikidata:Lexicographical data</a>. See <a href="https://doc.wikimedia.org/WikibaseLexeme/master/php/md_docs_2topics_2lua.html" class="extiw" title="wmdoc:WikibaseLexeme/master/php/md docs 2topics 2lua.html">md_docs_2topics_2lua.html</a> and <a href="/wiki/Special:MyLanguage/Extension:WikibaseLexeme/Lua" title="Special:MyLanguage/Extension:WikibaseLexeme/Lua">Extension:WikibaseLexeme/Lua</a><span style="display:none"><a href="/wiki/Extension:WikibaseLexeme/Lua" title="Extension:WikibaseLexeme/Lua"> </a></span>. </p> <div class="mw-heading mw-heading3"><h3 id="mw.wikibase.mediainfo">mw.wikibase.mediainfo</h3></div> <p><a href="/wiki/Special:MyLanguage/Extension:WikibaseMediaInfo" title="Special:MyLanguage/Extension:WikibaseMediaInfo">WikibaseMediaInfo</a><span style="display:none"><a href="/wiki/Extension:WikibaseMediaInfo" title="Extension:WikibaseMediaInfo"> </a></span> provides access to Wikibase MediaInfo entities. See <a href="/wiki/Special:MyLanguage/Extension:WikibaseMediaInfo/Lua" title="Special:MyLanguage/Extension:WikibaseMediaInfo/Lua">WikibaseMediaInfo/Lua</a><span style="display:none"><a href="/wiki/Extension:WikibaseMediaInfo/Lua" title="Extension:WikibaseMediaInfo/Lua"> </a></span>. This is supported by <a href="https://commons.wikimedia.org/wiki/Special:MyLanguage/Commons:Structured_data" class="extiw" title="c:Special:MyLanguage/Commons:Structured data">Structured Data on Commons</a>. See <a href="https://commons.wikimedia.org/wiki/Special:MyLanguage/Commons:Structured_data/Lua" class="extiw" title="c:Special:MyLanguage/Commons:Structured data/Lua">Structured data/Lua</a>. </p> <div class="mw-heading mw-heading3"><h3 id="mw.bcmath">mw.bcmath</h3></div> <p><a href="/wiki/Special:MyLanguage/Extension:BCmath" title="Special:MyLanguage/Extension:BCmath">BCmath</a><span style="display:none"><a href="/wiki/Extension:BCmath" title="Extension:BCmath"> </a></span> provides arbitrary-precision arithmetic to Lua modules. See BCmath documentation via "LDoc" link at <a href="/wiki/Special:MyLanguage/Extension:BCmath#Usage" title="Special:MyLanguage/Extension:BCmath">BCmath § Usage</a>. </p> <div class="mw-heading mw-heading3"><h3 id="mw.smw">mw.smw</h3></div> <p><a href="/wiki/Special:MyLanguage/Extension:Semantic_Scribunto" title="Special:MyLanguage/Extension:Semantic Scribunto">Semantic Scribunto</a><span style="display:none"><a href="/wiki/Extension:Semantic_Scribunto" title="Extension:Semantic Scribunto"> </a></span> provides native Scribunto support for the <a href="/wiki/Special:MyLanguage/Extension:Semantic_MediaWiki" title="Special:MyLanguage/Extension:Semantic MediaWiki">Semantic MediaWiki</a><span style="display:none"><a href="/wiki/Extension:Semantic_MediaWiki" title="Extension:Semantic MediaWiki"> </a></span> extension. </p> <div class="mw-heading mw-heading3"><h3 id="mw.ext.data">mw.ext.data</h3></div> <p><a href="/wiki/Special:MyLanguage/Extension:JsonConfig" title="Special:MyLanguage/Extension:JsonConfig">JsonConfig</a><span style="display:none"><a href="/wiki/Extension:JsonConfig" title="Extension:JsonConfig"> </a></span> provides access to localizable tabular and map data. See <a href="/wiki/Special:MyLanguage/Extension:JsonConfig/Tabular" title="Special:MyLanguage/Extension:JsonConfig/Tabular">JsonConfig/Tabular</a><span style="display:none"><a href="/wiki/Extension:JsonConfig/Tabular" title="Extension:JsonConfig/Tabular"> </a></span>. <a href="/wiki/Special:MyLanguage/Help:Tabular_Data" title="Special:MyLanguage/Help:Tabular Data">Tabular Data</a><span style="display:none"><a href="/wiki/Help:Tabular_Data" class="mw-redirect" title="Help:Tabular Data"> </a></span> and GeoJSON <a href="/wiki/Special:MyLanguage/Help:Map_Data" title="Special:MyLanguage/Help:Map Data">Map Data</a><span style="display:none"><a href="/wiki/Help:Map_Data" title="Help:Map Data"> </a></span> is supported in the "<a href="https://meta.wikimedia.org/wiki/DataNamespace" class="extiw" title="m:DataNamespace">Data</a>:" namespace at Commons. </p> <ul><li><code>mw.ext.data.get( <i>pagename</i> )</code></li></ul> <div class="mw-heading mw-heading3"><h3 id="mw.ext.cargo">mw.ext.cargo</h3></div> <p><a href="/wiki/Special:MyLanguage/Extension:Cargo" title="Special:MyLanguage/Extension:Cargo">Cargo</a><span style="display:none"><a href="/wiki/Extension:Cargo" title="Extension:Cargo"> </a></span> provides a means to query its data store from Lua. See <a href="/wiki/Special:MyLanguage/Extension:Cargo/Other_features#Lua_support" title="Special:MyLanguage/Extension:Cargo/Other features">Extension:Cargo/Other features#Lua support</a><span style="display:none"><a href="/wiki/Extension:Cargo/Other_features#Lua_support" title="Extension:Cargo/Other features"> </a></span>. </p> <div class="mw-heading mw-heading3"><h3 id="mw.ext.cattools">mw.ext.cattools</h3></div> <p><a href="/wiki/Special:MyLanguage/Extension:CategoryToolbox" title="Special:MyLanguage/Extension:CategoryToolbox">CategoryToolbox</a><span style="display:none"><a href="/wiki/Extension:CategoryToolbox" title="Extension:CategoryToolbox"> </a></span> provides a means to check from Lua if a certain page belongs to a category. Is is experimental and not enabled on public WikiMedia wikis. </p> <div class="mw-heading mw-heading3"><h3 id="mw.ext.FlaggedRevs">mw.ext.FlaggedRevs</h3></div> <p><a href="/wiki/Special:MyLanguage/Extension:FlaggedRevs" title="Special:MyLanguage/Extension:FlaggedRevs">FlaggedRevs</a><span style="display:none"><a href="/wiki/Extension:FlaggedRevs" title="Extension:FlaggedRevs"> </a></span> provides a means to access the stability settings of a page from Lua. </p> <div class="mw-heading mw-heading3"><h3 id="mw.ext.TitleBlacklist">mw.ext.TitleBlacklist</h3></div> <p><a href="/wiki/Special:MyLanguage/Extension:TitleBlacklist" title="Special:MyLanguage/Extension:TitleBlacklist">TitleBlacklist</a><span style="display:none"><a href="/wiki/Extension:TitleBlacklist" title="Extension:TitleBlacklist"> </a></span> provides a means to test and obtain information about blacklisted page naming entries from Lua. </p> <div class="mw-heading mw-heading3"><h3 id="mw.ext.ParserFunctions">mw.ext.ParserFunctions</h3></div> <p><a href="/wiki/Special:MyLanguage/Extension:ParserFunctions" title="Special:MyLanguage/Extension:ParserFunctions">ParserFunctions</a><span style="display:none"><a href="/wiki/Extension:ParserFunctions" title="Extension:ParserFunctions"> </a></span> provides a means from Lua to evaluate expressions in the same way as its PHP-based parser function <code><a href="/wiki/Special:MyLanguage/Help:Extension:ParserFunctions##expr" title="Special:MyLanguage/Help:Extension:ParserFunctions">&#35;expr</a><span style="display:none"><a href="/wiki/Help:Extension:ParserFunctions###expr" title="Help:Extension:ParserFunctions"> </a></span></code>. </p> <div class="mw-heading mw-heading3"><h3 id="mw.ext.proofreadPage">mw.ext.proofreadPage</h3></div> <p><a href="/wiki/Special:MyLanguage/Extension:Proofread_Page" title="Special:MyLanguage/Extension:Proofread Page">Proofread Page</a><span style="display:none"><a href="/wiki/Extension:Proofread_Page" title="Extension:Proofread Page"> </a></span> provides access to Index and Page namespaces. See <a href="/wiki/Special:MyLanguage/Extension:Proofread_Page/Lua_reference" title="Special:MyLanguage/Extension:Proofread Page/Lua reference">Extension:Proofread Page/Lua reference</a><span style="display:none"><a href="/wiki/Extension:Proofread_Page/Lua_reference" title="Extension:Proofread Page/Lua reference"> </a></span>. This is supported by <a href="https://wikisource.org/wiki/Wikisource:ProofreadPage" class="extiw" title="oldwikisource:Wikisource:ProofreadPage">Wikisource:ProofreadPage</a>. See <a href="/wiki/Special:MyLanguage/Help:Extension:ProofreadPage" title="Special:MyLanguage/Help:Extension:ProofreadPage">Help:Extension:ProofreadPage</a><span style="display:none"><a href="/wiki/Help:Extension:ProofreadPage" title="Help:Extension:ProofreadPage"> </a></span>. </p> <div class="mw-heading mw-heading3"><h3 id="mw.ext.articlePlaceholder">mw.ext.articlePlaceholder</h3></div> <p><a href="/wiki/Special:MyLanguage/Extension:ArticlePlaceholder" title="Special:MyLanguage/Extension:ArticlePlaceholder">ArticlePlaceholder</a><span style="display:none"><a href="/wiki/Extension:ArticlePlaceholder" title="Extension:ArticlePlaceholder"> </a></span> provides a means to override default Wikibase renderings from Lua. See <a href="/wiki/Special:MyLanguage/Extension:ArticlePlaceholder/Module:AboutTopic" title="Special:MyLanguage/Extension:ArticlePlaceholder/Module:AboutTopic">Extension:ArticlePlaceholder/Module:AboutTopic</a><span style="display:none"><a href="/wiki/Extension:ArticlePlaceholder/Module:AboutTopic" title="Extension:ArticlePlaceholder/Module:AboutTopic"> </a></span>. </p> <div class="mw-heading mw-heading3"><h3 id="mw.ext.externalData">mw.ext.externalData</h3></div> <p><a href="/wiki/Special:MyLanguage/Extension:ExternalData" title="Special:MyLanguage/Extension:ExternalData">ExternalData</a><span style="display:none"><a href="/wiki/Extension:ExternalData" class="mw-redirect" title="Extension:ExternalData"> </a></span> provides a means to get structured data from Internet from Lua. See <a href="/wiki/Special:MyLanguage/Extension:External_Data/Lua" title="Special:MyLanguage/Extension:External Data/Lua">Extension:External Data/Lua</a><span style="display:none"><a href="/wiki/Extension:External_Data/Lua" title="Extension:External Data/Lua"> </a></span>. </p> <div class="mw-heading mw-heading3"><h3 id="mw.ext.UnlinkedWikibase">mw.ext.UnlinkedWikibase</h3></div> <p>See <a href="/wiki/Special:MyLanguage/Extension:UnlinkedWikibase" title="Special:MyLanguage/Extension:UnlinkedWikibase">UnlinkedWikibase</a><span style="display:none"><a href="/wiki/Extension:UnlinkedWikibase" title="Extension:UnlinkedWikibase"> </a></span> </p> <ul><li><code>mw.ext.UnlinkedWikibase.getEntity( <i>id</i> )</code></li> <li><code>mw.ext.UnlinkedWikibase.query( <i>sparql</i> )</code></li></ul> <div class="mw-heading mw-heading3"><h3 id="mw.ext.seo">mw.ext.seo</h3></div> <p><a href="/wiki/Extension:WikiSEO" title="Extension:WikiSEO">WikiSEO</a> provides a means to set SEO Data for the current page. See <a href="/wiki/Extension:WikiSEO#Usage_in_lua_modules" title="Extension:WikiSEO">Extension:WikiSEO#Usage in lua modules</a>. </p> <div class="mw-heading mw-heading3"><h3 id="mw.slots">mw.slots</h3></div> <p><a href="/wiki/Special:MyLanguage/Extension:WSSlots" title="Special:MyLanguage/Extension:WSSlots">WSSlots</a><span style="display:none"><a href="/wiki/Extension:WSSlots" title="Extension:WSSlots"> </a></span> provides a number of Lua functions for working with <a href="/wiki/Special:MyLanguage/Multi-Content_Revisions" title="Special:MyLanguage/Multi-Content Revisions">MCR</a> slots: </p> <ul><li><code>mw.slots.slotContent(<i>slotName</i>, <i>pageName</i>)</code></li> <li><code>mw.slots.slotTemplates(<i>slotName</i>, <i>pageName</i>)</code> (deprecated)</li> <li><code>mw.slots.slotContentModel(<i>slotName</i>, <i>pageName</i>)</code></li> <li><code>mw.slots.slotData(<i>slotName</i>, <i>pageName</i>)</code></li></ul> <div class="mw-heading mw-heading2"><h2 id="Differences_from_standard_Lua">Differences from standard Lua</h2></div> <div class="mw-heading mw-heading3"><h3 id="Changed_functions">Changed functions</h3></div> <p>The following functions have been <b>modified</b>: </p> <dl><dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#pdf-setfenv">setfenv()</a></dt> <dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#pdf-getfenv">getfenv()</a></dt> <dd>May not be available, depending on the configuration. If available, attempts to access parent environments will fail.</dd> <dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#pdf-getmetatable">getmetatable()</a></dt> <dd>Works on tables only to prevent unauthorized access to parent environments.</dd> <dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#pdf-tostring">tostring()</a></dt> <dd>Pointer addresses of tables and functions are not provided. This is to make memory corruption vulnerabilities more difficult to exploit.</dd> <dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#pdf-pairs">pairs()</a></dt> <dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#pdf-ipairs">ipairs()</a></dt> <dd>Support for the __pairs and __ipairs metamethods (added in Lua 5.2) has been added.</dd> <dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#pdf-pcall">pcall()</a></dt> <dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#pdf-xpcall">xpcall()</a></dt> <dd>Certain internal errors cannot be intercepted.</dd> <dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#pdf-require">require()</a></dt> <dd>Can fetch certain built-in modules distributed with Scribunto, as well as modules present in the Module namespace of the wiki. To fetch wiki modules, use the full page name including the namespace. Cannot otherwise access the local filesystem.</dd></dl> <div class="mw-heading mw-heading3"><h3 id="Removed_functions_and_packages">Removed functions and packages</h3></div> <p>The following packages are <b>mostly removed</b>. Only those functions listed are available: </p> <dl><dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#5.3">package.*</a></dt> <dd>Filesystem and C library access has been removed. Available functions and tables are: <dl><dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#pdf-package.loaded">package.loaded</a></dt> <dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#pdf-package.preload">package.preload</a></dt> <dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#pdf-package.loaders">package.loaders</a></dt> <dd>Loaders which access the local filesystem or load C libraries are not present. A loader for Module-namespace pages is added.</dd> <dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#pdf-package.seeall">package.seeall()</a></dt></dl></dd></dl> <dl><dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#5.8">os.*</a></dt> <dd>There are some insecure functions in here, such as os.execute(), which can't be allowed. Available functions are: <dl><dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#pdf-os.clock">os.clock()</a></dt> <dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#pdf-os.date">os.date()</a></dt> <dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#pdf-os.difftime">os.difftime()</a></dt> <dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#pdf-os.time">os.time()</a></dt></dl></dd></dl> <dl><dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#5.9">debug.*</a></dt> <dd>Most of the functions are insecure. Available functions are: <dl><dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#pdf-debug.traceback">debug.traceback()</a></dt></dl></dd></dl> <p>The following functions and packages are <b>not</b> available: </p> <dl><dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#pdf-collectgarbage">collectgarbage()</a></dt> <dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#pdf-module">module()</a></dt> <dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#2.11">coroutine.*</a></dt> <dd>No application is known for us, so it has not been reviewed for security.</dd> <dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#pdf-dofile">dofile()</a></dt> <dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#pdf-loadfile">loadfile()</a></dt> <dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#5.7">io.*, file.*</a></dt> <dd>Allows local filesystem access, which is insecure.</dd> <dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#pdf-load">load()</a></dt> <dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#pdf-loadstring">loadstring()</a></dt> <dd>These were omitted to allow for static analysis of the Lua source code. Also, allowing these would allow Lua code to be added directly to article and template pages, which was not desired for usability reasons.</dd> <dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#pdf-print">print()</a></dt> <dd>This was <a href="https://lists.wikimedia.org/pipermail/wikitech-l/2012-April/059995.html" class="extiw" title="mailarchive:wikitech-l/2012-April/059995.html">discussed on wikitech-l</a> and it was decided that it should be omitted in favour of return values, to improve code quality. If necessary, mw.log() may be used to output information to the debug console.</dd> <dt><a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/manual.html#pdf-string.dump">string.dump()</a></dt> <dd>May expose private data from parent environments.</dd></dl> <div class="mw-heading mw-heading3"><h3 id="Additional_caveats">Additional caveats</h3></div> <dl><dt>Referential data structures</dt> <dd>Circular data structures and data structures where the same node may be reached by more than one path cannot be correctly sent to PHP. Attempting to do so will cause undefined behavior. This includes (but is not limited to) returning such data structures from the module called by <code>{{#invoke:}}</code> and passing such data structures as parameters to Scribunto library functions that are implemented as callbacks into PHP. <br />Such data structures may be used freely within Lua, including as the return values of modules loaded with <code><a href="#mw.loadData">mw.loadData()</a></code>.</dd></dl> <div class="mw-heading mw-heading2"><h2 id="Writing_Scribunto_libraries">Writing Scribunto libraries</h2></div> <p>This information is useful to developers writing additional Scribunto libraries, whether for inclusion in Scribunto itself or for providing an interface for their own extensions. </p><p>A Scribunto library will generally consist of five parts: </p> <ul><li>The PHP portion of the library.</li> <li>The Lua portion of the library.</li> <li>The PHP portion of the test cases.</li> <li>The Lua portion of the test cases.</li> <li>The documentation.</li></ul> <p>Existing libraries serve as a good example. </p> <div class="mw-heading mw-heading3"><h3 id="Library">Library</h3></div> <p>The PHP portion of the library is a class that must extend <code>Scribunto_LuaLibraryBase</code>. See the documentation for that class for implementation details. In the Scribunto extension, this file should be placed in <code>engines/LuaCommon/<i>Name</i>Library.php</code>, and a mapping added to <code>Scribunto_LuaEngine::$libraryClasses</code>. Other extensions should use the <a href="/wiki/Extension:Scribunto/Hooks/ScribuntoExternalLibraries" title="Extension:Scribunto/Hooks/ScribuntoExternalLibraries">ScribuntoExternalLibraries</a> hook. In either case, the key should match the Lua module name ("mw.<i>name</i>" for libraries in Scribunto, or "mw.ext.<i>name</i>" for extension libraries). </p><p>The Lua portion of the library sets up the table containing the functions that can be called from Lua modules. In the Scribunto extension, the file should be placed in <code>engines/LuaCommon/lualib/mw.<i>name</i>.lua</code>. This file should generally include boilerplate something like this: </p> <div class="mw-highlight mw-highlight-lang-lua mw-content-ltr" dir="ltr"><pre><span></span><span class="kd">local</span> <span class="n">object</span> <span class="o">=</span> <span class="p">{}</span> <span class="kd">local</span> <span class="n">php</span> <span class="kr">function</span> <span class="nc">object</span><span class="p">.</span><span class="nf">setupInterface</span><span class="p">(</span> <span class="n">options</span> <span class="p">)</span> <span class="c1">-- Remove setup function</span> <span class="n">object</span><span class="p">.</span><span class="n">setupInterface</span> <span class="o">=</span> <span class="kc">nil</span> <span class="c1">-- Copy the PHP callbacks to a local variable, and remove the global</span> <span class="n">php</span> <span class="o">=</span> <span class="n">mw_interface</span> <span class="n">mw_interface</span> <span class="o">=</span> <span class="kc">nil</span> <span class="c1">-- Do any other setup here</span> <span class="c1">-- Install into the mw global</span> <span class="n">mw</span> <span class="o">=</span> <span class="n">mw</span> <span class="ow">or</span> <span class="p">{}</span> <span class="n">mw</span><span class="p">.</span><span class="n">ext</span> <span class="o">=</span> <span class="n">mw</span><span class="p">.</span><span class="n">ext</span> <span class="ow">or</span> <span class="p">{}</span> <span class="n">mw</span><span class="p">.</span><span class="n">ext</span><span class="p">.</span><span class="n">NAME</span> <span class="o">=</span> <span class="n">object</span> <span class="c1">-- Indicate that we&#39;re loaded</span> <span class="nb">package.loaded</span><span class="p">[</span><span class="s1">&#39;mw.ext.NAME&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">object</span> <span class="kr">end</span> <span class="kr">return</span> <span class="n">object</span> </pre></div> <p>The module in <code>engines/LuaCommon/lualib/libraryUtil.lua</code> (load this with <code>local util = require 'libraryUtil'</code>) contains some functions that may be helpful. </p><p>Be sure to run the Scribunto test cases with your library loaded, even if your library doesn't itself provide any test cases. The standard test cases include tests for things like libraries adding unexpected global variables. Also, if the library is loaded with PHP, any upvalues that its Lua functions have will not be reset between #invoke's. Care must be taken to ensure that modules can't abuse this to transfer information between #invoke's. </p> <div class="mw-heading mw-heading3"><h3 id="Test_cases">Test cases</h3></div> <p>The Scribunto extension includes a base class for test cases, <code>Scribunto_LuaEngineTestBase</code>, which will run the tests against both the <a href="/wiki/Special:MyLanguage/LuaSandbox" title="Special:MyLanguage/LuaSandbox">LuaSandbox</a><span style="display:none"><a href="/wiki/LuaSandbox" title="LuaSandbox"> </a></span> and <a href="/wiki/Special:MyLanguage/Extension:Scribunto#LuaStandalone" title="Special:MyLanguage/Extension:Scribunto">LuaStandalone</a><span style="display:none"><a href="/wiki/Extension:Scribunto#LuaStandalone" title="Extension:Scribunto"> </a></span> engines. The library's test case should extend this class, and should not override <code>static function suite()</code>. In the Scribunto extension, the test case should be in <code>tests/engines/LuaCommon/<i>Name</i>LibraryTest.php</code> and added to the array in <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nx">ScribuntoHooks</span><span class="o">::</span><span class="na">unitTestsList</span><span class="p">()</span></code> (in <code>common/Hooks.php</code>); extensions should add the test case in their own <code><a href="/wiki/Special:MyLanguage/Manual:Hooks/UnitTestsList" title="Special:MyLanguage/Manual:Hooks/UnitTestsList">UnitTestsList</a><span style="display:none"><a href="/wiki/Manual:Hooks/UnitTestsList" title="Manual:Hooks/UnitTestsList"> </a></span></code> hook function, probably conditional on whether <code>$wgAutoloadClasses['Scribunto_LuaEngineTestBase']</code> is set. </p><p>Most of the time, all that is needed to make the test case is this: </p> <pre>class <i>ClassName</i>Test extends Scribunto_LuaEngineTestBase { protected static $moduleName = '<i>ClassName</i>Test'; function getTestModules() { return parent::getTestModules() + array( '<i>ClassName</i>Test' =&gt; __DIR__ . '/<i>ClassName</i>Tests.lua'; ); } } </pre> <p>This will load the file <code><i>ClassName</i>Tests.lua</code> as if it were the page "Module:<i>ClassName</i>Tests", expecting it to return an object with the following properties: </p> <ul><li><b>count</b>: Integer, number of tests</li> <li><b>provide( n )</b>: Function that returns three values: <code>n</code>, the name of test <code>n</code>, and a string that is the expected output for test <code>n</code>.</li> <li><b>run( n )</b>: Function that runs test <code>n</code> and returns one string.</li></ul> <p>If <code>getTestModules()</code> is declared as shown, "Module:TestFramework" is available which provides many useful helper methods. If this is used, <code><i>ClassName</i>Tests.lua</code> would look something like this: </p> <pre>local testframework = require 'Module:TestFramework' return testframework.getTestProvider( { -- Tests go here } ) </pre> <p>Each test is itself a table, with the following properties: </p> <ul><li><b>name</b>: The name of the test.</li> <li><b>func</b>: The function to execute.</li> <li><b>args</b>: Optional table of arguments to pass to the function.</li> <li><b>expect</b>: Results to expect.</li> <li><b>type</b>: Optional "type" of the test, default is "Normal".</li></ul> <p>The type controls the format of <code>expect</code> and how <code>func</code> is called. Included types are: </p> <ul><li><b>Normal</b>: <code>expect</code> is a table of return values, or a string if the test should raise an error. <code>func</code> is simply called.</li> <li><b>Iterator</b>: <code>expect</code> is a table of tables of return values. <code>func</code> is called as with an <a href="#iterators">iterated for loop</a>, and each iteration's return values are accumulated.</li> <li><b>ToString</b>: Like "Normal", except each return value is passed through <code><a href="#tostring">tostring()</a></code>.</li></ul> <div class="mw-heading mw-heading4"><h4 id="Test_cases_in_another_extension">Test cases in another extension</h4></div> <p>There are (at least) two ways to run PHPUnit tests: </p> <ol><li>Run phpunit against core, allowing the tests/phpunit/suites/ExtensionsTestSuite.php to find the extension's tests using the <a href="/wiki/Special:MyLanguage/Manual:Hooks/UnitTestsList" title="Special:MyLanguage/Manual:Hooks/UnitTestsList">UnitTestsList</a><span style="display:none"><a href="/wiki/Manual:Hooks/UnitTestsList" title="Manual:Hooks/UnitTestsList"> </a></span> hook. If your extension's test class names all contain a unique component (e.g. the extension's name), the <code>--filter</code> option may be used to run only your extension's tests.</li> <li>Run phpunit against the extension directory, where it will pick up any file ending in "Test.php".</li></ol> <p>Either of these will work fine if Scribunto is loaded in LocalSettings.php. And it is easy for method #1 to work if Scribunto is not loaded, as the UnitTestsList hook can easily be written to avoid returning the Scribunto test when <code class="mw-highlight mw-highlight-lang-php mw-content-ltr" style="" dir="ltr"><span class="nv">$wgAutoloadClasses</span><span class="p">[</span> <span class="s1">&#39;Scribunto_LuaEngineTestBase&#39;</span> <span class="p">]</span></code> is not set. </p><p>But <a href="/wiki/Jenkins" class="mw-redirect" title="Jenkins">Jenkins</a> uses method #2. For Jenkins to properly run the tests, you will need to add Scribunto as a dependency for your extension. See <a href="https://gerrit.wikimedia.org/r/56570" class="extiw" title="gerrit:56570">Gerrit change 56570</a> for an example of how this is done. </p><p>If for some reason you need the tests to be able to run using method #2 without Scribunto loaded, one workaround is to add this check to the top of your unit test file: </p> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span> <span class="k">if</span> <span class="p">(</span> <span class="o">!</span><span class="nb">isset</span><span class="p">(</span> <span class="nv">$GLOBALS</span><span class="p">[</span><span class="s1">&#39;wgAutoloadClasses&#39;</span><span class="p">][</span><span class="s1">&#39;Scribunto_LuaEngineTestBase&#39;</span><span class="p">]</span> <span class="p">)</span> <span class="p">)</span> <span class="p">{</span> <span class="k">return</span><span class="p">;</span> <span class="p">}</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="Documentation">Documentation</h3></div> <p>Modules included in Scribunto should include documentation in the <a href="#Scribunto_libraries">Scribunto libraries</a> section above. Extension libraries should include documentation in a subpage of their own extension page, and link to that documentation from the <a href="#Extension_libraries">Extension libraries</a> subsection above. </p> <div class="mw-heading mw-heading2"><h2 id="See_also">See also</h2></div> <ul><li><a href="https://en.wikipedia.org/wiki/Lua_(programming_language)" class="extiw" title="w:Lua (programming language)">Lua (programming language)</a></li></ul> <div class="mw-heading mw-heading2"><h2 id="License">License</h2></div> <p>This manual is derived from the <a rel="nofollow" class="external text" href="https://www.lua.org/manual/5.1/index.html">Lua 5.1 reference manual</a>, which is available under the <a rel="nofollow" class="external text" href="https://www.lua.org/license.html">MIT license</a>. </p> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r6651108"><table class="ombox ombox-notice plainlinks" role="presentation"><tbody><tr><td class="mbox-empty-cell"></td><td class="mbox-text">Copyright © 1994–2012 Lua.org, PUC-Rio. <p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: </p><p>The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. </p> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</td></tr></tbody></table> <p>This derivative manual may also be copied under the terms of the same license. </p> <!-- NewPP limit report Parsed by mw‐web.codfw.main‐f69cdc8f6‐d7pw2 Cached time: 20241123064455 Cache expiry: 2592000 Reduced expiry: false Complications: [show‐toc] CPU time usage: 0.961 seconds Real time usage: 1.126 seconds Preprocessor visited node count: 15503/1000000 Post‐expand include size: 55692/2097152 bytes Template argument size: 15953/2097152 bytes Highest expansion depth: 13/100 Expensive parser function count: 202/500 Unstrip recursion depth: 0/20 Unstrip post‐expand size: 90028/5000000 bytes Lua time usage: 0.118/10.000 seconds Lua memory usage: 2070991/52428800 bytes Number of Wikibase entities loaded: 0/400 --> <!-- Transclusion expansion time report (%,ms,calls,template) 100.00% 425.787 1 -total 37.38% 159.145 44 Template:Ll 21.71% 92.437 64 Template:Pagelang 19.01% 80.961 88 Template:Translatable 17.84% 75.958 93 Template:Luai 16.58% 70.590 95 Template:Inline-code 7.36% 31.344 2 Template:Mbox 6.94% 29.536 20 Template:Red 6.69% 28.489 22 Template:Dir 5.83% 24.828 25 Template:Anchor --> <!-- Saved in parser cache with key mediawikiwiki:pcache:idhash:94994-0!canonical and timestamp 20241123064455 and revision id 6855937. Rendering was triggered because: page-view --> </div><!--esi <esi:include src="/esitest-fa8a495983347898/content" /> --><noscript><img src="https://login.wikimedia.org/wiki/Special:CentralAutoLogin/start?type=1x1" alt="" width="1" height="1" style="border: none; position: absolute;"></noscript> <div class="printfooter" data-nosnippet="">Retrieved from "<a dir="ltr" href="https://www.mediawiki.org/w/index.php?title=Extension:Scribunto/Lua_reference_manual&amp;oldid=6855937">https://www.mediawiki.org/w/index.php?title=Extension:Scribunto/Lua_reference_manual&amp;oldid=6855937</a>"</div></div> <div id="catlinks" class="catlinks" data-mw="interface"><div id="mw-normal-catlinks" class="mw-normal-catlinks"><a href="/wiki/Special:Categories" title="Special:Categories">Category</a>: <ul><li><a href="/wiki/Category:Lua" title="Category:Lua">Lua</a></li></ul></div></div> </div> </main> </div> <div class="mw-footer-container"> <footer id="footer" class="mw-footer" > <ul id="footer-info"> <li id="footer-info-lastmod"> This page was last edited on 16 November 2024, at 13:52.</li> <li id="footer-info-copyright">Text is available under the <a rel="nofollow" class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-ShareAlike License</a>; additional terms may apply. Text in <a class="external text" href="https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents">the Help: namespace</a> is available under the <a rel="nofollow" class="external text" href="https://creativecommons.org/publicdomain/zero/1.0/">Creative Commons CC0 License</a>. By using this site, you agree to the <a class="external text" href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Terms_of_Use">Terms of Use</a> and <a class="external text" href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Privacy_policy">Privacy Policy</a>.</li> </ul> <ul id="footer-places"> <li id="footer-places-privacy"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Privacy_policy">Privacy policy</a></li> <li id="footer-places-about"><a href="/wiki/Project:About">About mediawiki.org</a></li> <li id="footer-places-disclaimers"><a href="/wiki/Project:General_disclaimer">Disclaimers</a></li> <li id="footer-places-wm-codeofconduct"><a href="https://www.mediawiki.org/wiki/Special:MyLanguage/Code_of_Conduct">Code of Conduct</a></li> <li id="footer-places-developers"><a href="https://developer.wikimedia.org">Developers</a></li> <li id="footer-places-statslink"><a href="https://stats.wikimedia.org/#/www.mediawiki.org">Statistics</a></li> <li id="footer-places-cookiestatement"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Cookie_statement">Cookie statement</a></li> <li id="footer-places-mobileview"><a href="//m.mediawiki.org/w/index.php?title=Extension:Scribunto/Lua_reference_manual&amp;mobileaction=toggle_view_mobile" class="noprint stopMobileRedirectToggle">Mobile view</a></li> </ul> <ul id="footer-icons" class="noprint"> <li id="footer-copyrightico"><a href="https://wikimediafoundation.org/" class="cdx-button cdx-button--fake-button cdx-button--size-large cdx-button--fake-button--enabled"><img src="/static/images/footer/wikimedia-button.svg" width="84" height="29" alt="Wikimedia Foundation" loading="lazy"></a></li> <li id="footer-poweredbyico"><a href="https://www.mediawiki.org/" class="cdx-button cdx-button--fake-button cdx-button--size-large cdx-button--fake-button--enabled"><img src="/w/resources/assets/poweredby_mediawiki.svg" alt="Powered by MediaWiki" width="88" height="31" loading="lazy"></a></li> </ul> </footer> </div> </div> </div> <div class="vector-settings" id="p-dock-bottom"> <ul></ul> </div><script>(RLQ=window.RLQ||[]).push(function(){mw.config.set({"wgHostname":"mw-web.codfw.main-f69cdc8f6-4xwft","wgBackendResponseTime":153,"wgPageParseReport":{"limitreport":{"cputime":"0.961","walltime":"1.126","ppvisitednodes":{"value":15503,"limit":1000000},"postexpandincludesize":{"value":55692,"limit":2097152},"templateargumentsize":{"value":15953,"limit":2097152},"expansiondepth":{"value":13,"limit":100},"expensivefunctioncount":{"value":202,"limit":500},"unstrip-depth":{"value":0,"limit":20},"unstrip-size":{"value":90028,"limit":5000000},"entityaccesscount":{"value":0,"limit":400},"timingprofile":["100.00% 425.787 1 -total"," 37.38% 159.145 44 Template:Ll"," 21.71% 92.437 64 Template:Pagelang"," 19.01% 80.961 88 Template:Translatable"," 17.84% 75.958 93 Template:Luai"," 16.58% 70.590 95 Template:Inline-code"," 7.36% 31.344 2 Template:Mbox"," 6.94% 29.536 20 Template:Red"," 6.69% 28.489 22 Template:Dir"," 5.83% 24.828 25 Template:Anchor"]},"scribunto":{"limitreport-timeusage":{"value":"0.118","limit":"10.000"},"limitreport-memusage":{"value":2070991,"limit":52428800}},"cachereport":{"origin":"mw-web.codfw.main-f69cdc8f6-d7pw2","timestamp":"20241123064455","ttl":2592000,"transientcontent":false}}});});</script> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10