Wikipedia suwiki https://su.wikipedia.org/wiki/Tepas MediaWiki 1.47.0-wmf.16 first-letter Média Husus Obrolan Pamaké Obrolan pamaké Wikipedia Obrolan Wikipedia Gambar Obrolan gambar MédiaWiki Obrolan MédiaWiki Citakan Obrolan citakan Pitulung Obrolan pitulung Kategori Obrolan kategori Portal Obrolan portal TimedText TimedText talk Modul Pembicaraan Modul Acara Pembicaraan Acara Gambar:Cepot Wayang.jpg 6 16694 712264 711418 2026-08-26T09:13:54Z Badak Jawa 28990 /* */ 712264 wikitext text/x-wiki phoiac9h4m842xq45sp7s6u21eteeq1 Wikipedia:Lua 4 41001 712257 712256 2026-08-25T18:30:20Z Nimmzo 37272 /* Unit testing */ revisted from the Debug console point of view: what are `self` and the unsercore `_` parameter? 712257 wikitext text/x-wiki {{tarjamahkeun|Inggris}} {{WikiProject Lua/header}} {{Information page|WP:Lua}} {{Namespaces}} Lua mangrupakeun basa pamrograman nu ayeuna geus sadia di Wikipedia Sunda ngaliwatan ekstensi MediaWiki [[mw:Extension:Scribunto|Scribunto]].<br /> Kode Lua ayeuna bisa diasupkeun kana témplat wiki ku maké fungsi parser <syntaxhighlight lang="lua" inline>{{#invoke:}}</syntaxhighlight> dina kaca pamaké anjeun. == Halo, dunya! dina Lua == The Lua source code is stored in a wiki page with the prefix <syntaxhighlight lang="lua" inline>Modul:</syntaxhighlight> (e.g., [[Modul:Bananas]]). These individual modules are then invoked (by code <syntaxhighlight lang="lua" inline>{{#invoke:}}</syntaxhighlight>) on another wiki page (e.g., [[Modul:Bananas/doc]] uses the code <syntaxhighlight lang="lua" inline>{{#invoke:Bananas|hello}}</syntaxhighlight> to print the text <syntaxhighlight lang="lua" inline>"Hello, world!"</syntaxhighlight>). Modules are run on normal wiki pages using the <code>#invoke</code> parser function. The syntax of <code>#invoke</code> is similar to template syntax, but with some differences. The most important difference is that you need to specify a ''function name''. A function is a set of Lua instructions that takes input values, processes them, and returns an output value.<ref>You can also have multiple output values, but functions that do this are not normally meant to be accessed from wiki pages.</ref> This is much like what a template does: you give it arguments, it processes them, and you get a result.<br /> However, you can define many functions in one Lua module, whereas you can only define one template on one page. Furthermore, you can't just run a Lua module directly - you can only run one of the module's functions. The module is just a container for the functions, and doesn't do anything by itself. So there are two reasons that we need to input a function name: # We can't run a module by itself. # Without specifying a function name, Lua will not know which function it is we want to run. Run a module from your user page like this: <blockquote><syntaxhighlight lang="lua" line> {{#invoke:NgaranModul|ngaranFungsi}} </syntaxhighlight></blockquote> For example, [[Modul:Bananas]] is the simplest possible script, providing a single function with no arguments.<br /> The function is named <code>hello</code> in lowercase. We can run this module in this way. Anjeun teu kudu masang atawa nyimpen nanaon. # Édit kaca pamaké anjeun. # Témpélkeun panggilan di handap ieu dina awal hiji baris anyar dina kaca pamaké anjeun: <blockquote><syntaxhighlight lang="wikitext" line highlight=1 copy> {{#invoke:Bananas|hello}} </syntaxhighlight></blockquote> <ol start="3"> <li>Klik <code>Témbongkeun sawangan</code>. Panggilan fungsi <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> dina [[Modul:Bananas]] diganti ku ieu di handap: Halo, dunya!</li> </ol> <blockquote><syntaxhighlight lang="text" line> Hello, world! </syntaxhighlight></blockquote> <ol start="4"> <li>Klik <code style="color:#bf3c2c;>Bolay</code>. Lamun dipenta, klik <code>Tinggalkeun</code>.</li> <li>Kaca pamaké anjeun tetep '''teu''' dirobah.</li> </ol> === Using arguments === Arguments are passed to modules in the same way that they are passed to templates. Note, however, that the text after the first pipe character <code>|</code> is always the function name; the first positional argument is the text after the ''second'' pipe. <blockquote><syntaxhighlight lang="lua" line> {{#invoke:NgaranModul|ngaranFungsi|arguménPosisional1}} </syntaxhighlight></blockquote> For example, another [[Modul:BananasArgs]] demonstrates how to access and use parameters.<br /> The <code>hello</code> function greets different people depending on the first positional argument. It works like this: Dina kaca pamaké anjeun: <blockquote><syntaxhighlight lang="wikitext" line highlight=1 copy> # {{#invoke:BananasArgs|hello|Mariam}} # {{#invoke:BananasArgs|hello|Mohamed}} </syntaxhighlight></blockquote> <blockquote> # {{#invoke:BananasArgs|hello|Mariam}} # {{#invoke:BananasArgs|hello|Mohamed}} </blockquote> ;Named arguments key=value <blockquote><syntaxhighlight lang="lua" line> {{#invoke:NgaranModul|ngaranFungsi|argNgaran1=nilai1|argNgaran2=nilai2}} </syntaxhighlight></blockquote> The <syntaxhighlight lang="lua" inline>Modul:</syntaxhighlight>BananasArgs also has a function named <code>count_fruit</code> which uses the named arguments <code>bananas</code> and <code>apples</code> to count the number of bananas and apples we have. It can be run switching the order of the parameters: Dina kaca pamaké anjeun: <blockquote><syntaxhighlight lang="wikitext" line highlight=1 copy> # {{#invoke:BananasArgs|count_fruit|apples=3|bananas=4}} # {{#invoke:BananasArgs|count_fruit|bananas=5|apples=2}} </syntaxhighlight></blockquote> <blockquote> # {{#invoke:BananasArgs|count_fruit|apples=3|bananas=4}} # {{#invoke:BananasArgs|count_fruit|bananas=5|apples=2}} </blockquote> Most modules have a documentation page explaining what arguments can be used and what their effects will be. == Konsol debug: Mimiti diajar Lua == <code>Debug Console</code> dina Lua Scribunto nyaéta alat anu aman tur interaktif pikeun diajar Lua dina Wikipedia. # Klik <code>Témbongkeun sumber</code> dina kaca [[Modul:Yesno]]. # Gulung ka handap kaca nepi ka bagian <code>Debug console</code>. # Témpélkeun komentar jeung panggilan kana kotak asup <span style="color:#86888c;">kulawu</span> (di luhur tombol <code>Kosongkan</code>). <blockquote><syntaxhighlight lang="lua" line highlight=2 copy> --[[Program Lua munggaran anjeun nu mirip Hello World]]-- print("Wilujeng sumping di " .. _VERSION .. "!") -- Ngarangkep vérsi Lua ku `..` </syntaxhighlight></blockquote> <ol start="4"> <li>Pencét {{key press|Enter}} sakali pikeun ngalaksanakeun dua paréntah Lua éta.</li> <li>Hasilna bakal muncul di handap garis paréntah Lua <syntaxhighlight lang="lua" inline>print</syntaxhighlight>:</li> </ol> <blockquote><syntaxhighlight lang="text" line start=3> Wilujeng sumping di Lua 5.1! </syntaxhighlight></blockquote> <ol start="6"> <li>Pencét {{key press|Up}} <code>Panah ka luhur</code> pikeun ngurilingan paréntah Lua saméméhna.</li> <li>Opsional, klik <code>Kosongkan</code> pikeun ngaberesihan ''ngan'' <code>Debug Console</code>; éditor Lua di luhur moal '''teu''' robah.</li> </ol> ; Generator HTML dina Debug console Panggil pungsi <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> dina <code>Modul:</code>Bananas: <blockquote><syntaxhighlight lang="lua" line highlight=2 copy> local modCau = require('Modul:Bananas') -- muat modul dina Debug console print(modCau.hello()) -- tampilkeun "Hello, world!" </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="text" line start=3> Hello, world! </syntaxhighlight></blockquote> ; Argumén <blockquote><syntaxhighlight lang="lua" line highlight=3,5 copy> local modCau = require('Modul:BananasArgs') local frame = mw.getCurrentFrame() frame.args = {"Mariam"}; print(modCau.hello(frame)) -- "Hello, Mariam!" frame.args = {"Mohamed"}; print(modCau.hello(frame)) frame.args = {apples="3", bananas="4"}; print(modCau.count_fruit(frame)) frame.args = {bananas="5", apples="2"}; print(modCau.count_fruit(frame)) </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="lua" line start=7> Hello, Mariam! Hello, Mohamed! I have 4 bananas and 3 apples I have 5 bananas and 2 apples </syntaxhighlight></blockquote> ; Fungsi idéntitas <code>callParserFunction</code> [[mw:Help:Extension:ParserFunctions##if|#if]] <blockquote><syntaxhighlight lang="lua" line highlight=3 copy> local yesno = require('Modul:Yesno') -- #if yesno teras mulangkeun parameter asupanna local frame = mw.getCurrentFrame() print(frame:callParserFunction("#if", yesno("Yes"), "Yes", 'henteu')) print(frame:callParserFunction("#if", yesno('teu'), "Leres", 'teu')) </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="text" line start=5> Yes teu </syntaxhighlight></blockquote> # Tutup <code>Modul:</code>Yesno anu dijaga anu tetep '''teu''' robah. == Request a script == Visit [[:en:Wikipedia talk:Lua]] to request help in writing a Lua script to perform a specific task on Wikipedia or another Wikimedia Foundation project. == History == [[mw:Manual:MediaWiki architecture#Magic words and templates|Sordid history]]. [[mw:Help:Extension:ParserFunctions|ParserFunctions]], [[mw:Extension:Lua|Lua extension]], wiki scripting language debated (JavaScript v. Lua), [[mw:Extension:WikiScripts]], Tim writes [[mw:Extension:Scribunto|Scribunto]] with initial support for Lua. Discussed for years, Lua was installed in 2012 for testing on [[test2wiki:|test2.wikipedia.org]], with open invitation to all editors to experiment with developing Lua modules. Lua was installed on the English Wikipedia in February 2013, after testing on mediawiki.org and Wikimedia test wikis. == About Lua == :''See also [[:File:WMF Tech Talk 2013-02-28 slides - Scribunto presentation.pdf|Brad Jorsch's short presentation for a basic example of how to convert a wikitext template into a Lua module.]]'' Lua is a scripting language which can be used to analyze data, calculate expressions, and format results using functions or object-oriented programming. Although some Lua scripts can be kept simple, for easy understanding, Lua allows complex structures including tables, dynamic functions, and associative arrays where index subscripts can be words as well as index numbers. Lua also supports recursion of re-nested functions, so care should be taken to avoid excessive complexity where other users would not understand how to maintain a Lua module. The following is an example of Lua source code for the <code>hello</code> function contained in [[Modul:Bananas]]: <syntaxhighlight lang="lua" line highlight=3> --[[Modul:Bananas]]-- local p = {} -- tabel modul nu diperlukeun, diinisialisasi minangka tabel kosong function p.hello() -- Nangtukeun fungsi hello. return "Hello, world!" -- Mulangkeun hasil fungsi dina wangun string. end -- Ahir fungsi. return p -- Mulangkeun tabel modul. </syntaxhighlight> A sample of Lua is highlighted by tag <code><nowiki><syntaxhighlight lang="lua" line highlight=1 copy> ... </syntaxhighlight></nowiki></code> placed around the Lua source code. For instructions on how to use Lua within MediaWiki (and hence Wikipedia), see [[mw:Extension:Scribunto/Lua reference manual]]. == Unit testing == A unit testing framework for Lua scripts on Wikipedia is available at [[Modul:ScribuntoUnit]].<br /> It allows you to execute your script on a given set of inputs and verify that the expected outputs are produced.<br /> Unit tests are especially useful for rapidly detecting regressions, where modifications to a script introduce new problems. By convention, unit tests for a module like [[Modul:Bananas]] are placed in <syntaxhighlight lang="lua" inline>Modul:</syntaxhighlight> <code>Bananas</code>'''<code>/testcases</code>'''.<br /> They are executed on [[Pembicaraan Modul:Bananas/testcases]] with <syntaxhighlight lang="lua" inline>{{#invoke:Bananas/testcases|</syntaxhighlight>'''<code>run</code>'''<syntaxhighlight lang="lua" inline>}}</syntaxhighlight>. Dina kaca pamaké anjeun: <blockquote><syntaxhighlight lang="wikitext" line highlight=1 copy> {{#invoke:Bananas/testcases|run}} </syntaxhighlight></blockquote> <blockquote> {{#invoke:Bananas/testcases|run}} </blockquote> Each test method must begin with <syntaxhighlight lang="lua" inline>p:</syntaxhighlight>'''<code>test_</code>'''. An example from [[Modul:Bananas/testcases]] is below. <syntaxhighlight lang="lua" line highlight=4 copy> --[[Modul:Bananas/testcases]]-- local p = require('Modul:ScribuntoUnit').new() local modCau = require('Modul:Bananas') -- Didatangan kaca obrolan pikeun ngajalankeun tés. function p:test_halo() -- Tés unit pikeun [[Modul:Bananas]]. self:assertEquals('Hello, world!', modCau.hello()) end return p </syntaxhighlight> Di konsol debug [[modul:Yesno]]: <blockquote><syntaxhighlight lang="lua" line highlight=10 copy> local self = { assertEquals = function(_, wikitext, expected) local got = mw.getCurrentFrame():preprocess(wikitext) print('"' .. expected .. '": Diarepkeun') print('"' .. got .. '": Saleresna') return got == expected end } </syntaxhighlight></blockquote> [[Modul:ScribuntoUnit]] originates from Hungarian Wikipedia.<br /> It throws real errors that are trapped using protected calls. It also has a method to compare floats within a given precision. Pikeun daptar sakabéh modul nu ngagunakeun tés unit, tingali [[Husus:NumbuKaDieu/Modul:ScribuntoUnit|nu dipaké]]. == Wikipedia-specific features == Overall: Lua can only get input as text strings passed to the <code><nowiki>{{#invoke:}}</nowiki></code> and what can be fetched via <code>[[mw:Extension:Scribunto/Lua reference manual#mw.title.new|mw.title.new(...)]]:getContent()</code> and <code>[[mw:Extension:Scribunto/Lua reference manual#frame:expandTemplate|frame:expandTemplate()]]</code>. Lua output will not be preprocessed unless <code>frame:</code>'''<code>[[mw:Extension:Scribunto/Lua reference manual#frame:preprocess|preprocess()]]</code>''' is explicitly called, meaning that template calls and parser functions in the output will not work correctly. Langkung hade ngagunakeun fungsi '''<code>[[mw:Extension:Scribunto/Lua reference manual#mw.ustring.len|mw.ustring.len]]</code>''' tibatan <code>[[mw:Extension:Scribunto/Lua reference manual#string.len|string.len]]</code>: Di konsol debug [[modul:Yesno]]: <blockquote><syntaxhighlight lang="lua" line highlight=2,8 copy> --[[Alfabét Latin]]-- local content_lang = mw.getContentLanguage().code -- su local lang = mw.getCurrentFrame():callParserFunction("#language", content_lang) local lenUnicode, lenByte, lenSharp = mw.ustring.len(lang), string.len(lang), #lang print(("lang: \"%s\". Mw.ustring.len = %d String.len = %d Sharp = %d"):format(lang, lenUnicode, lenByte, lenSharp)) --[[Unicode]]-- lang = "اَكسارا ڤَيڮَون" -- Aksara Pégon lenUnicode, lenByte, lenSharp = mw.ustring.len(lang), string.len(lang), #lang print(("lang: \"%s\". Mw.ustring.len = %d String.len = %d Sharp = %d"):format(lang, lenUnicode, lenByte, lenSharp)) </syntaxhighlight></blockquote> <code>Konsol debug</code> ngarojong Unicode, tapi henteu ngarojong téks katuhu-ka-kenca: <blockquote><syntaxhighlight lang="text" line start=11> lang: "Sunda". Mw.ustring.len = 5 String.len = 5 Sharp = 5 lang: "اَكسارا ڤَيڮَون". Mw.ustring.len = 15 String.len = 29 Sharp = 29 </syntaxhighlight></blockquote> {| class="wikitable" ![[Alfabét Latin]] !Aksara !Arah !Jumlah karakter !Panjang dina bait |- |'''Sunda''' |[[Basa Sunda]]. |→ kenca ka katuhu. |5 |5 |- |[[Hurup Pégon]] |style="direction:rtl; text-align:right;" |'''اَكسارا ڤَيڮَون'''. |← '''Katuhu''' ka kenca |'''15''' ('''[[Unicode]]''') + 1 titik |<span style="color:red;">29</span> + 1 |} {{#invoke:Utf8debug|ek|اَكسارا ڤَيڮَون.}} Lua code in a wiki page is limited to '''10 s'''econds CPU time (you can look in the source code of a rendered page to see how long a template or module took to parse). Relative to standard Lua, Scribunto offers safe functions (see the [[mw:Extension:Scribunto/Lua reference manual#Differences from standard Lua|differences]] from standard Lua). === Lua input limitations === Lua code in Scribunto is only run when the page is being parsed. Therefore, the only user input that Lua can receive is by ''page editing'' - it cannot create a box that calculates the square root of a number you type in, or recalculate a piece of the Mandelbrot set depending on which part of the parent set you click on. The input Lua can receive includes any transcludeable text page on Wikipedia. This does ''not'' include graphics files (not even .SVG files, although they are actually text, unless you cut and paste it onto a Wiki text page), the list of pages listed in a [[:Kategori:Lua-based templates|category]], nor the contents of [[Wikipedia:Transclusion#Special pages|non-transcludeable]] [[Husus:IndeksAwalan/Modul:|special pages]]. === Wikitext === Transcluded Wikipedia headers frequently contain a hidden code such as <syntaxhighlight lang="lua" inline>"UNIQ5ae8f2aa414ff233-h-3--QINU"</syntaxhighlight> which may need to be stripped out in order for them to be parsed effectively. <blockquote><syntaxhighlight lang="lua" line highlight=1 copy> print(string.reverse("UNIQ")) -- Urutan sabalikna tina "UNIQ" nyaéta "QINU" </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="lua" line start=2> QINU </syntaxhighlight></blockquote> Wikilinks of the type <code><nowiki>[[Wikipedia:Pitulung</nowiki></code>'''<code><nowiki>|</nowiki></code>'''<code><nowiki>]]</nowiki></code> won't work if returned as output - they need to be written explicitly as <syntaxhighlight lang="lua" inline>[[Wikipedia:Pitulung|</syntaxhighlight>'''<code><nowiki>Pitulung</nowiki></code>'''<syntaxhighlight lang="lua" inline>]]</syntaxhighlight>. Other pre-save transforms, such as replacing <code>~~<nowiki/>~~</code> with signatures, will also fail to be processed. Template transclusions, parser function calls, and variable substitutions (i.e. anything with a <code><nowiki>{{...}}</nowiki></code>) will not be processed, nor will tags such as {{tag|ref|o}} or {{tag|nowiki|o}}. == Labeling converted templates == {{lua|Module:Bananas}} Please place the {{tl|lua}} template on the documentation subpage of all templates that use Lua. It will help to better communicate Lua usage and template conversions. {{clear}} == See also == * [[Husus:IndeksAwalan/Modul:]] daptar modul Lua * [[:Kategori:Lua-based templates]] &ndash; l-groups ta templates based kan Lua ; English Wikipedia-specific resources * [[:mw:Manual:Coding conventions/Lua]] &ndash; standards to improve the readability of code through consistency * [[:en:Help:Lua debugging]] &ndash; a how-to guide about debugging Lua modules * [[:en:Module:Sandbox]] provides a pseudo-namespace for experimenting with Lua modules * [[:en:Wikipedia talk:Lua]] &ndash; requests for Lua-based templates or tasks == Notes == {{reflist}} {{WikiProject Lua/header}} [[Category:Wikipedia modules]] 5ow4mpqzuv4k74bh7zmjsznog435e5b 712258 712257 2026-08-25T20:40:42Z Nimmzo 37272 /* Unit testing */ The principle of the test is to compare the expected result with the actual result got using [[mw:Extension:Scribunto/Lua reference manual#frame:preprocess|preprocess()]]. With the separator `:` between `self` and `assertEquals`, the first parameter `_` is not needed. With the separator `.`, self must be the first parameter. 712258 wikitext text/x-wiki {{tarjamahkeun|Inggris}} {{WikiProject Lua/header}} {{Information page|WP:Lua}} {{Namespaces}} Lua mangrupakeun basa pamrograman nu ayeuna geus sadia di Wikipedia Sunda ngaliwatan ekstensi MediaWiki [[mw:Extension:Scribunto|Scribunto]].<br /> Kode Lua ayeuna bisa diasupkeun kana témplat wiki ku maké fungsi parser <syntaxhighlight lang="lua" inline>{{#invoke:}}</syntaxhighlight> dina kaca pamaké anjeun. == Halo, dunya! dina Lua == The Lua source code is stored in a wiki page with the prefix <syntaxhighlight lang="lua" inline>Modul:</syntaxhighlight> (e.g., [[Modul:Bananas]]). These individual modules are then invoked (by code <syntaxhighlight lang="lua" inline>{{#invoke:}}</syntaxhighlight>) on another wiki page (e.g., [[Modul:Bananas/doc]] uses the code <syntaxhighlight lang="lua" inline>{{#invoke:Bananas|hello}}</syntaxhighlight> to print the text <syntaxhighlight lang="lua" inline>"Hello, world!"</syntaxhighlight>). Modules are run on normal wiki pages using the <code>#invoke</code> parser function. The syntax of <code>#invoke</code> is similar to template syntax, but with some differences. The most important difference is that you need to specify a ''function name''. A function is a set of Lua instructions that takes input values, processes them, and returns an output value.<ref>You can also have multiple output values, but functions that do this are not normally meant to be accessed from wiki pages.</ref> This is much like what a template does: you give it arguments, it processes them, and you get a result.<br /> However, you can define many functions in one Lua module, whereas you can only define one template on one page. Furthermore, you can't just run a Lua module directly - you can only run one of the module's functions. The module is just a container for the functions, and doesn't do anything by itself. So there are two reasons that we need to input a function name: # We can't run a module by itself. # Without specifying a function name, Lua will not know which function it is we want to run. Run a module from your user page like this: <blockquote><syntaxhighlight lang="lua" line> {{#invoke:NgaranModul|ngaranFungsi}} </syntaxhighlight></blockquote> For example, [[Modul:Bananas]] is the simplest possible script, providing a single function with no arguments.<br /> The function is named <code>hello</code> in lowercase. We can run this module in this way. Anjeun teu kudu masang atawa nyimpen nanaon. # Édit kaca pamaké anjeun. # Témpélkeun panggilan di handap ieu dina awal hiji baris anyar dina kaca pamaké anjeun: <blockquote><syntaxhighlight lang="wikitext" line highlight=1 copy> {{#invoke:Bananas|hello}} </syntaxhighlight></blockquote> <ol start="3"> <li>Klik <code>Témbongkeun sawangan</code>. Panggilan fungsi <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> dina [[Modul:Bananas]] diganti ku ieu di handap: Halo, dunya!</li> </ol> <blockquote><syntaxhighlight lang="text" line> Hello, world! </syntaxhighlight></blockquote> <ol start="4"> <li>Klik <code style="color:#bf3c2c;>Bolay</code>. Lamun dipenta, klik <code>Tinggalkeun</code>.</li> <li>Kaca pamaké anjeun tetep '''teu''' dirobah.</li> </ol> === Using arguments === Arguments are passed to modules in the same way that they are passed to templates. Note, however, that the text after the first pipe character <code>|</code> is always the function name; the first positional argument is the text after the ''second'' pipe. <blockquote><syntaxhighlight lang="lua" line> {{#invoke:NgaranModul|ngaranFungsi|arguménPosisional1}} </syntaxhighlight></blockquote> For example, another [[Modul:BananasArgs]] demonstrates how to access and use parameters.<br /> The <code>hello</code> function greets different people depending on the first positional argument. It works like this: Dina kaca pamaké anjeun: <blockquote><syntaxhighlight lang="wikitext" line highlight=1 copy> # {{#invoke:BananasArgs|hello|Mariam}} # {{#invoke:BananasArgs|hello|Mohamed}} </syntaxhighlight></blockquote> <blockquote> # {{#invoke:BananasArgs|hello|Mariam}} # {{#invoke:BananasArgs|hello|Mohamed}} </blockquote> ;Named arguments key=value <blockquote><syntaxhighlight lang="lua" line> {{#invoke:NgaranModul|ngaranFungsi|argNgaran1=nilai1|argNgaran2=nilai2}} </syntaxhighlight></blockquote> The <syntaxhighlight lang="lua" inline>Modul:</syntaxhighlight>BananasArgs also has a function named <code>count_fruit</code> which uses the named arguments <code>bananas</code> and <code>apples</code> to count the number of bananas and apples we have. It can be run switching the order of the parameters: Dina kaca pamaké anjeun: <blockquote><syntaxhighlight lang="wikitext" line highlight=1 copy> # {{#invoke:BananasArgs|count_fruit|apples=3|bananas=4}} # {{#invoke:BananasArgs|count_fruit|bananas=5|apples=2}} </syntaxhighlight></blockquote> <blockquote> # {{#invoke:BananasArgs|count_fruit|apples=3|bananas=4}} # {{#invoke:BananasArgs|count_fruit|bananas=5|apples=2}} </blockquote> Most modules have a documentation page explaining what arguments can be used and what their effects will be. == Konsol debug: Mimiti diajar Lua == <code>Debug Console</code> dina Lua Scribunto nyaéta alat anu aman tur interaktif pikeun diajar Lua dina Wikipedia. # Klik <code>Témbongkeun sumber</code> dina kaca [[Modul:Yesno]]. # Gulung ka handap kaca nepi ka bagian <code>Debug console</code>. # Témpélkeun komentar jeung panggilan kana kotak asup <span style="color:#86888c;">kulawu</span> (di luhur tombol <code>Kosongkan</code>). <blockquote><syntaxhighlight lang="lua" line highlight=2 copy> --[[Program Lua munggaran anjeun nu mirip Hello World]]-- print("Wilujeng sumping di " .. _VERSION .. "!") -- Ngarangkep vérsi Lua ku `..` </syntaxhighlight></blockquote> <ol start="4"> <li>Pencét {{key press|Enter}} sakali pikeun ngalaksanakeun dua paréntah Lua éta.</li> <li>Hasilna bakal muncul di handap garis paréntah Lua <syntaxhighlight lang="lua" inline>print</syntaxhighlight>:</li> </ol> <blockquote><syntaxhighlight lang="text" line start=3> Wilujeng sumping di Lua 5.1! </syntaxhighlight></blockquote> <ol start="6"> <li>Pencét {{key press|Up}} <code>Panah ka luhur</code> pikeun ngurilingan paréntah Lua saméméhna.</li> <li>Opsional, klik <code>Kosongkan</code> pikeun ngaberesihan ''ngan'' <code>Debug Console</code>; éditor Lua di luhur moal '''teu''' robah.</li> </ol> ; Generator HTML dina Debug console Panggil pungsi <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> dina <code>Modul:</code>Bananas: <blockquote><syntaxhighlight lang="lua" line highlight=2 copy> local modCau = require('Modul:Bananas') -- muat modul dina Debug console print(modCau.hello()) -- tampilkeun "Hello, world!" </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="text" line start=3> Hello, world! </syntaxhighlight></blockquote> ; Argumén <blockquote><syntaxhighlight lang="lua" line highlight=3,5 copy> local modCau = require('Modul:BananasArgs') local frame = mw.getCurrentFrame() frame.args = {"Mariam"}; print(modCau.hello(frame)) -- "Hello, Mariam!" frame.args = {"Mohamed"}; print(modCau.hello(frame)) frame.args = {apples="3", bananas="4"}; print(modCau.count_fruit(frame)) frame.args = {bananas="5", apples="2"}; print(modCau.count_fruit(frame)) </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="lua" line start=7> Hello, Mariam! Hello, Mohamed! I have 4 bananas and 3 apples I have 5 bananas and 2 apples </syntaxhighlight></blockquote> ; Fungsi idéntitas <code>callParserFunction</code> [[mw:Help:Extension:ParserFunctions##if|#if]] <blockquote><syntaxhighlight lang="lua" line highlight=3 copy> local yesno = require('Modul:Yesno') -- #if yesno teras mulangkeun parameter asupanna local frame = mw.getCurrentFrame() print(frame:callParserFunction("#if", yesno("Yes"), "Yes", 'henteu')) print(frame:callParserFunction("#if", yesno('teu'), "Leres", 'teu')) </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="text" line start=5> Yes teu </syntaxhighlight></blockquote> # Tutup <code>Modul:</code>Yesno anu dijaga anu tetep '''teu''' robah. == Request a script == Visit [[:en:Wikipedia talk:Lua]] to request help in writing a Lua script to perform a specific task on Wikipedia or another Wikimedia Foundation project. == History == [[mw:Manual:MediaWiki architecture#Magic words and templates|Sordid history]]. [[mw:Help:Extension:ParserFunctions|ParserFunctions]], [[mw:Extension:Lua|Lua extension]], wiki scripting language debated (JavaScript v. Lua), [[mw:Extension:WikiScripts]], Tim writes [[mw:Extension:Scribunto|Scribunto]] with initial support for Lua. Discussed for years, Lua was installed in 2012 for testing on [[test2wiki:|test2.wikipedia.org]], with open invitation to all editors to experiment with developing Lua modules. Lua was installed on the English Wikipedia in February 2013, after testing on mediawiki.org and Wikimedia test wikis. == About Lua == :''See also [[:File:WMF Tech Talk 2013-02-28 slides - Scribunto presentation.pdf|Brad Jorsch's short presentation for a basic example of how to convert a wikitext template into a Lua module.]]'' Lua is a scripting language which can be used to analyze data, calculate expressions, and format results using functions or object-oriented programming. Although some Lua scripts can be kept simple, for easy understanding, Lua allows complex structures including tables, dynamic functions, and associative arrays where index subscripts can be words as well as index numbers. Lua also supports recursion of re-nested functions, so care should be taken to avoid excessive complexity where other users would not understand how to maintain a Lua module. The following is an example of Lua source code for the <code>hello</code> function contained in [[Modul:Bananas]]: <syntaxhighlight lang="lua" line highlight=3> --[[Modul:Bananas]]-- local p = {} -- tabel modul nu diperlukeun, diinisialisasi minangka tabel kosong function p.hello() -- Nangtukeun fungsi hello. return "Hello, world!" -- Mulangkeun hasil fungsi dina wangun string. end -- Ahir fungsi. return p -- Mulangkeun tabel modul. </syntaxhighlight> A sample of Lua is highlighted by tag <code><nowiki><syntaxhighlight lang="lua" line highlight=1 copy> ... </syntaxhighlight></nowiki></code> placed around the Lua source code. For instructions on how to use Lua within MediaWiki (and hence Wikipedia), see [[mw:Extension:Scribunto/Lua reference manual]]. == Unit testing == A unit testing framework for Lua scripts on Wikipedia is available at [[Modul:ScribuntoUnit]].<br /> It allows you to execute your script on a given set of inputs and verify that the expected outputs are produced.<br /> Unit tests are especially useful for rapidly detecting regressions, where modifications to a script introduce new problems. By convention, unit tests for a module like [[Modul:Bananas]] are placed in <syntaxhighlight lang="lua" inline>Modul:</syntaxhighlight> <code>Bananas</code>'''<code>/testcases</code>'''.<br /> They are executed on [[Pembicaraan Modul:Bananas/testcases]] with <syntaxhighlight lang="lua" inline>{{#invoke:Bananas/testcases|</syntaxhighlight>'''<code>run</code>'''<syntaxhighlight lang="lua" inline>}}</syntaxhighlight>. Dina kaca pamaké anjeun: <blockquote><syntaxhighlight lang="wikitext" line highlight=1 copy> {{#invoke:Bananas/testcases|run}} </syntaxhighlight></blockquote> <blockquote> {{#invoke:Bananas/testcases|run}} </blockquote> Each test method must begin with <syntaxhighlight lang="lua" inline>p:</syntaxhighlight>'''<code>test_</code>'''. An example from [[Modul:Bananas/testcases]] is below. <syntaxhighlight lang="lua" line highlight=4 copy> --[[Modul:Bananas/testcases]]-- local p = require('Modul:ScribuntoUnit').new() local modCau = require('Modul:Bananas') -- Didatangan kaca obrolan pikeun ngajalankeun tés. function p:test_halo() -- Tés unit pikeun [[Modul:Bananas]]. self:assertEquals('Hello, world!', modCau.hello()) end return p </syntaxhighlight> Di konsol debug [[modul:Yesno]]: <blockquote><syntaxhighlight lang="lua" line highlight=10 copy> local self = { assertEquals = function(_, wikitext, expected) local got = mw.getCurrentFrame():preprocess(wikitext) print('"' .. expected .. '": Diarepkeun') print('"' .. got .. '": Saleresna') return got == expected end } -- Pamisah `:` tanpa `self` print(self:assertEquals( '{{#invoke:Bananas|hello}}', 'Hello, world!')) -- Pamisah `.` jeung `self` print(self.assertEquals(self, '{{#invoke:Bananas|hello}}', 'Hello, world!')) </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="lua" line start=13> "Hello, world!": Diarepkeun "Hello, world!": Sakuduna true "Hello, world!": Diarepkeun "Hello, world!": Sakuduna true </syntaxhighlight></blockquote> [[Modul:ScribuntoUnit]] originates from Hungarian Wikipedia.<br /> It throws real errors that are trapped using protected calls. It also has a method to compare floats within a given precision. Pikeun daptar sakabéh modul nu ngagunakeun tés unit, tingali [[Husus:NumbuKaDieu/Modul:ScribuntoUnit|nu dipaké]]. == Wikipedia-specific features == Overall: Lua can only get input as text strings passed to the <code><nowiki>{{#invoke:}}</nowiki></code> and what can be fetched via <code>[[mw:Extension:Scribunto/Lua reference manual#mw.title.new|mw.title.new(...)]]:getContent()</code> and <code>[[mw:Extension:Scribunto/Lua reference manual#frame:expandTemplate|frame:expandTemplate()]]</code>. Lua output will not be preprocessed unless <code>frame:</code>'''<code>[[mw:Extension:Scribunto/Lua reference manual#frame:preprocess|preprocess()]]</code>''' is explicitly called, meaning that template calls and parser functions in the output will not work correctly. Langkung hade ngagunakeun fungsi '''<code>[[mw:Extension:Scribunto/Lua reference manual#mw.ustring.len|mw.ustring.len]]</code>''' tibatan <code>[[mw:Extension:Scribunto/Lua reference manual#string.len|string.len]]</code>: Di konsol debug [[modul:Yesno]]: <blockquote><syntaxhighlight lang="lua" line highlight=2,8 copy> --[[Alfabét Latin]]-- local content_lang = mw.getContentLanguage().code -- su local lang = mw.getCurrentFrame():callParserFunction("#language", content_lang) local lenUnicode, lenByte, lenSharp = mw.ustring.len(lang), string.len(lang), #lang print(("lang: \"%s\". Mw.ustring.len = %d String.len = %d Sharp = %d"):format(lang, lenUnicode, lenByte, lenSharp)) --[[Unicode]]-- lang = "اَكسارا ڤَيڮَون" -- Aksara Pégon lenUnicode, lenByte, lenSharp = mw.ustring.len(lang), string.len(lang), #lang print(("lang: \"%s\". Mw.ustring.len = %d String.len = %d Sharp = %d"):format(lang, lenUnicode, lenByte, lenSharp)) </syntaxhighlight></blockquote> <code>Konsol debug</code> ngarojong Unicode, tapi henteu ngarojong téks katuhu-ka-kenca: <blockquote><syntaxhighlight lang="text" line start=11> lang: "Sunda". Mw.ustring.len = 5 String.len = 5 Sharp = 5 lang: "اَكسارا ڤَيڮَون". Mw.ustring.len = 15 String.len = 29 Sharp = 29 </syntaxhighlight></blockquote> {| class="wikitable" ![[Alfabét Latin]] !Aksara !Arah !Jumlah karakter !Panjang dina bait |- |'''Sunda''' |[[Basa Sunda]]. |→ kenca ka katuhu. |5 |5 |- |[[Hurup Pégon]] |style="direction:rtl; text-align:right;" |'''اَكسارا ڤَيڮَون'''. |← '''Katuhu''' ka kenca |'''15''' ('''[[Unicode]]''') + 1 titik |<span style="color:red;">29</span> + 1 |} {{#invoke:Utf8debug|ek|اَكسارا ڤَيڮَون.}} Lua code in a wiki page is limited to '''10 s'''econds CPU time (you can look in the source code of a rendered page to see how long a template or module took to parse). Relative to standard Lua, Scribunto offers safe functions (see the [[mw:Extension:Scribunto/Lua reference manual#Differences from standard Lua|differences]] from standard Lua). === Lua input limitations === Lua code in Scribunto is only run when the page is being parsed. Therefore, the only user input that Lua can receive is by ''page editing'' - it cannot create a box that calculates the square root of a number you type in, or recalculate a piece of the Mandelbrot set depending on which part of the parent set you click on. The input Lua can receive includes any transcludeable text page on Wikipedia. This does ''not'' include graphics files (not even .SVG files, although they are actually text, unless you cut and paste it onto a Wiki text page), the list of pages listed in a [[:Kategori:Lua-based templates|category]], nor the contents of [[Wikipedia:Transclusion#Special pages|non-transcludeable]] [[Husus:IndeksAwalan/Modul:|special pages]]. === Wikitext === Transcluded Wikipedia headers frequently contain a hidden code such as <syntaxhighlight lang="lua" inline>"UNIQ5ae8f2aa414ff233-h-3--QINU"</syntaxhighlight> which may need to be stripped out in order for them to be parsed effectively. <blockquote><syntaxhighlight lang="lua" line highlight=1 copy> print(string.reverse("UNIQ")) -- Urutan sabalikna tina "UNIQ" nyaéta "QINU" </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="lua" line start=2> QINU </syntaxhighlight></blockquote> Wikilinks of the type <code><nowiki>[[Wikipedia:Pitulung</nowiki></code>'''<code><nowiki>|</nowiki></code>'''<code><nowiki>]]</nowiki></code> won't work if returned as output - they need to be written explicitly as <syntaxhighlight lang="lua" inline>[[Wikipedia:Pitulung|</syntaxhighlight>'''<code><nowiki>Pitulung</nowiki></code>'''<syntaxhighlight lang="lua" inline>]]</syntaxhighlight>. Other pre-save transforms, such as replacing <code>~~<nowiki/>~~</code> with signatures, will also fail to be processed. Template transclusions, parser function calls, and variable substitutions (i.e. anything with a <code><nowiki>{{...}}</nowiki></code>) will not be processed, nor will tags such as {{tag|ref|o}} or {{tag|nowiki|o}}. == Labeling converted templates == {{lua|Module:Bananas}} Please place the {{tl|lua}} template on the documentation subpage of all templates that use Lua. It will help to better communicate Lua usage and template conversions. {{clear}} == See also == * [[Husus:IndeksAwalan/Modul:]] daptar modul Lua * [[:Kategori:Lua-based templates]] &ndash; l-groups ta templates based kan Lua ; English Wikipedia-specific resources * [[:mw:Manual:Coding conventions/Lua]] &ndash; standards to improve the readability of code through consistency * [[:en:Help:Lua debugging]] &ndash; a how-to guide about debugging Lua modules * [[:en:Module:Sandbox]] provides a pseudo-namespace for experimenting with Lua modules * [[:en:Wikipedia talk:Lua]] &ndash; requests for Lua-based templates or tasks == Notes == {{reflist}} {{WikiProject Lua/header}} [[Category:Wikipedia modules]] i4sctz2v6wflm9o5mt08ge67sj9986d 712259 712258 2026-08-25T20:50:14Z Nimmzo 37272 /* Unit testing */ Running [[Modul:Bananas/testcases]] in Debug console. It's the run of [[Modul:ScribuntoUnit#L-550]] 712259 wikitext text/x-wiki {{tarjamahkeun|Inggris}} {{WikiProject Lua/header}} {{Information page|WP:Lua}} {{Namespaces}} Lua mangrupakeun basa pamrograman nu ayeuna geus sadia di Wikipedia Sunda ngaliwatan ekstensi MediaWiki [[mw:Extension:Scribunto|Scribunto]].<br /> Kode Lua ayeuna bisa diasupkeun kana témplat wiki ku maké fungsi parser <syntaxhighlight lang="lua" inline>{{#invoke:}}</syntaxhighlight> dina kaca pamaké anjeun. == Halo, dunya! dina Lua == The Lua source code is stored in a wiki page with the prefix <syntaxhighlight lang="lua" inline>Modul:</syntaxhighlight> (e.g., [[Modul:Bananas]]). These individual modules are then invoked (by code <syntaxhighlight lang="lua" inline>{{#invoke:}}</syntaxhighlight>) on another wiki page (e.g., [[Modul:Bananas/doc]] uses the code <syntaxhighlight lang="lua" inline>{{#invoke:Bananas|hello}}</syntaxhighlight> to print the text <syntaxhighlight lang="lua" inline>"Hello, world!"</syntaxhighlight>). Modules are run on normal wiki pages using the <code>#invoke</code> parser function. The syntax of <code>#invoke</code> is similar to template syntax, but with some differences. The most important difference is that you need to specify a ''function name''. A function is a set of Lua instructions that takes input values, processes them, and returns an output value.<ref>You can also have multiple output values, but functions that do this are not normally meant to be accessed from wiki pages.</ref> This is much like what a template does: you give it arguments, it processes them, and you get a result.<br /> However, you can define many functions in one Lua module, whereas you can only define one template on one page. Furthermore, you can't just run a Lua module directly - you can only run one of the module's functions. The module is just a container for the functions, and doesn't do anything by itself. So there are two reasons that we need to input a function name: # We can't run a module by itself. # Without specifying a function name, Lua will not know which function it is we want to run. Run a module from your user page like this: <blockquote><syntaxhighlight lang="lua" line> {{#invoke:NgaranModul|ngaranFungsi}} </syntaxhighlight></blockquote> For example, [[Modul:Bananas]] is the simplest possible script, providing a single function with no arguments.<br /> The function is named <code>hello</code> in lowercase. We can run this module in this way. Anjeun teu kudu masang atawa nyimpen nanaon. # Édit kaca pamaké anjeun. # Témpélkeun panggilan di handap ieu dina awal hiji baris anyar dina kaca pamaké anjeun: <blockquote><syntaxhighlight lang="wikitext" line highlight=1 copy> {{#invoke:Bananas|hello}} </syntaxhighlight></blockquote> <ol start="3"> <li>Klik <code>Témbongkeun sawangan</code>. Panggilan fungsi <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> dina [[Modul:Bananas]] diganti ku ieu di handap: Halo, dunya!</li> </ol> <blockquote><syntaxhighlight lang="text" line> Hello, world! </syntaxhighlight></blockquote> <ol start="4"> <li>Klik <code style="color:#bf3c2c;>Bolay</code>. Lamun dipenta, klik <code>Tinggalkeun</code>.</li> <li>Kaca pamaké anjeun tetep '''teu''' dirobah.</li> </ol> === Using arguments === Arguments are passed to modules in the same way that they are passed to templates. Note, however, that the text after the first pipe character <code>|</code> is always the function name; the first positional argument is the text after the ''second'' pipe. <blockquote><syntaxhighlight lang="lua" line> {{#invoke:NgaranModul|ngaranFungsi|arguménPosisional1}} </syntaxhighlight></blockquote> For example, another [[Modul:BananasArgs]] demonstrates how to access and use parameters.<br /> The <code>hello</code> function greets different people depending on the first positional argument. It works like this: Dina kaca pamaké anjeun: <blockquote><syntaxhighlight lang="wikitext" line highlight=1 copy> # {{#invoke:BananasArgs|hello|Mariam}} # {{#invoke:BananasArgs|hello|Mohamed}} </syntaxhighlight></blockquote> <blockquote> # {{#invoke:BananasArgs|hello|Mariam}} # {{#invoke:BananasArgs|hello|Mohamed}} </blockquote> ;Named arguments key=value <blockquote><syntaxhighlight lang="lua" line> {{#invoke:NgaranModul|ngaranFungsi|argNgaran1=nilai1|argNgaran2=nilai2}} </syntaxhighlight></blockquote> The <syntaxhighlight lang="lua" inline>Modul:</syntaxhighlight>BananasArgs also has a function named <code>count_fruit</code> which uses the named arguments <code>bananas</code> and <code>apples</code> to count the number of bananas and apples we have. It can be run switching the order of the parameters: Dina kaca pamaké anjeun: <blockquote><syntaxhighlight lang="wikitext" line highlight=1 copy> # {{#invoke:BananasArgs|count_fruit|apples=3|bananas=4}} # {{#invoke:BananasArgs|count_fruit|bananas=5|apples=2}} </syntaxhighlight></blockquote> <blockquote> # {{#invoke:BananasArgs|count_fruit|apples=3|bananas=4}} # {{#invoke:BananasArgs|count_fruit|bananas=5|apples=2}} </blockquote> Most modules have a documentation page explaining what arguments can be used and what their effects will be. == Konsol debug: Mimiti diajar Lua == <code>Debug Console</code> dina Lua Scribunto nyaéta alat anu aman tur interaktif pikeun diajar Lua dina Wikipedia. # Klik <code>Témbongkeun sumber</code> dina kaca [[Modul:Yesno]]. # Gulung ka handap kaca nepi ka bagian <code>Debug console</code>. # Témpélkeun komentar jeung panggilan kana kotak asup <span style="color:#86888c;">kulawu</span> (di luhur tombol <code>Kosongkan</code>). <blockquote><syntaxhighlight lang="lua" line highlight=2 copy> --[[Program Lua munggaran anjeun nu mirip Hello World]]-- print("Wilujeng sumping di " .. _VERSION .. "!") -- Ngarangkep vérsi Lua ku `..` </syntaxhighlight></blockquote> <ol start="4"> <li>Pencét {{key press|Enter}} sakali pikeun ngalaksanakeun dua paréntah Lua éta.</li> <li>Hasilna bakal muncul di handap garis paréntah Lua <syntaxhighlight lang="lua" inline>print</syntaxhighlight>:</li> </ol> <blockquote><syntaxhighlight lang="text" line start=3> Wilujeng sumping di Lua 5.1! </syntaxhighlight></blockquote> <ol start="6"> <li>Pencét {{key press|Up}} <code>Panah ka luhur</code> pikeun ngurilingan paréntah Lua saméméhna.</li> <li>Opsional, klik <code>Kosongkan</code> pikeun ngaberesihan ''ngan'' <code>Debug Console</code>; éditor Lua di luhur moal '''teu''' robah.</li> </ol> ; Generator HTML dina Debug console Panggil pungsi <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> dina <code>Modul:</code>Bananas: <blockquote><syntaxhighlight lang="lua" line highlight=2 copy> local modCau = require('Modul:Bananas') -- muat modul dina Debug console print(modCau.hello()) -- tampilkeun "Hello, world!" </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="text" line start=3> Hello, world! </syntaxhighlight></blockquote> ; Argumén <blockquote><syntaxhighlight lang="lua" line highlight=3,5 copy> local modCau = require('Modul:BananasArgs') local frame = mw.getCurrentFrame() frame.args = {"Mariam"}; print(modCau.hello(frame)) -- "Hello, Mariam!" frame.args = {"Mohamed"}; print(modCau.hello(frame)) frame.args = {apples="3", bananas="4"}; print(modCau.count_fruit(frame)) frame.args = {bananas="5", apples="2"}; print(modCau.count_fruit(frame)) </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="lua" line start=7> Hello, Mariam! Hello, Mohamed! I have 4 bananas and 3 apples I have 5 bananas and 2 apples </syntaxhighlight></blockquote> ; Fungsi idéntitas <code>callParserFunction</code> [[mw:Help:Extension:ParserFunctions##if|#if]] <blockquote><syntaxhighlight lang="lua" line highlight=3 copy> local yesno = require('Modul:Yesno') -- #if yesno teras mulangkeun parameter asupanna local frame = mw.getCurrentFrame() print(frame:callParserFunction("#if", yesno("Yes"), "Yes", 'henteu')) print(frame:callParserFunction("#if", yesno('teu'), "Leres", 'teu')) </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="text" line start=5> Yes teu </syntaxhighlight></blockquote> # Tutup <code>Modul:</code>Yesno anu dijaga anu tetep '''teu''' robah. == Request a script == Visit [[:en:Wikipedia talk:Lua]] to request help in writing a Lua script to perform a specific task on Wikipedia or another Wikimedia Foundation project. == History == [[mw:Manual:MediaWiki architecture#Magic words and templates|Sordid history]]. [[mw:Help:Extension:ParserFunctions|ParserFunctions]], [[mw:Extension:Lua|Lua extension]], wiki scripting language debated (JavaScript v. Lua), [[mw:Extension:WikiScripts]], Tim writes [[mw:Extension:Scribunto|Scribunto]] with initial support for Lua. Discussed for years, Lua was installed in 2012 for testing on [[test2wiki:|test2.wikipedia.org]], with open invitation to all editors to experiment with developing Lua modules. Lua was installed on the English Wikipedia in February 2013, after testing on mediawiki.org and Wikimedia test wikis. == About Lua == :''See also [[:File:WMF Tech Talk 2013-02-28 slides - Scribunto presentation.pdf|Brad Jorsch's short presentation for a basic example of how to convert a wikitext template into a Lua module.]]'' Lua is a scripting language which can be used to analyze data, calculate expressions, and format results using functions or object-oriented programming. Although some Lua scripts can be kept simple, for easy understanding, Lua allows complex structures including tables, dynamic functions, and associative arrays where index subscripts can be words as well as index numbers. Lua also supports recursion of re-nested functions, so care should be taken to avoid excessive complexity where other users would not understand how to maintain a Lua module. The following is an example of Lua source code for the <code>hello</code> function contained in [[Modul:Bananas]]: <syntaxhighlight lang="lua" line highlight=3> --[[Modul:Bananas]]-- local p = {} -- tabel modul nu diperlukeun, diinisialisasi minangka tabel kosong function p.hello() -- Nangtukeun fungsi hello. return "Hello, world!" -- Mulangkeun hasil fungsi dina wangun string. end -- Ahir fungsi. return p -- Mulangkeun tabel modul. </syntaxhighlight> A sample of Lua is highlighted by tag <code><nowiki><syntaxhighlight lang="lua" line highlight=1 copy> ... </syntaxhighlight></nowiki></code> placed around the Lua source code. For instructions on how to use Lua within MediaWiki (and hence Wikipedia), see [[mw:Extension:Scribunto/Lua reference manual]]. == Unit testing == A unit testing framework for Lua scripts on Wikipedia is available at [[Modul:ScribuntoUnit]].<br /> It allows you to execute your script on a given set of inputs and verify that the expected outputs are produced.<br /> Unit tests are especially useful for rapidly detecting regressions, where modifications to a script introduce new problems. By convention, unit tests for a module like [[Modul:Bananas]] are placed in <syntaxhighlight lang="lua" inline>Modul:</syntaxhighlight> <code>Bananas</code>'''<code>/testcases</code>'''.<br /> They are executed on [[Pembicaraan Modul:Bananas/testcases]] with <syntaxhighlight lang="lua" inline>{{#invoke:Bananas/testcases|</syntaxhighlight>'''<code>run</code>'''<syntaxhighlight lang="lua" inline>}}</syntaxhighlight>. Dina kaca pamaké anjeun: <blockquote><syntaxhighlight lang="wikitext" line highlight=1 copy> {{#invoke:Bananas/testcases|run}} </syntaxhighlight></blockquote> <blockquote> {{#invoke:Bananas/testcases|run}} </blockquote> Each test method must begin with <syntaxhighlight lang="lua" inline>p:</syntaxhighlight>'''<code>test_</code>'''. An example from [[Modul:Bananas/testcases]] is below. <syntaxhighlight lang="lua" line highlight=4 copy> --[[Modul:Bananas/testcases]]-- local p = require('Modul:ScribuntoUnit').new() local modCau = require('Modul:Bananas') -- Didatangan kaca obrolan pikeun ngajalankeun tés. function p:test_halo() -- Tés unit pikeun [[Modul:Bananas]]. self:assertEquals('Hello, world!', modCau.hello()) end return p </syntaxhighlight> Di konsol debug [[modul:Yesno]]: <blockquote><syntaxhighlight lang="lua" line highlight=10 copy> local self = { assertEquals = function(_, wikitext, expected) local got = mw.getCurrentFrame():preprocess(wikitext) print('"' .. expected .. '": Diarepkeun') print('"' .. got .. '": Saleresna') return got == expected end } -- Pamisah `:` tanpa `self` print(self:assertEquals( '{{#invoke:Bananas|hello}}', 'Hello, world!')) -- Pamisah `.` jeung `self` print(self.assertEquals(self, '{{#invoke:Bananas|hello}}', 'Hello, world!')) </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="lua" line start=13> "Hello, world!": Diarepkeun "Hello, world!": Sakuduna true "Hello, world!": Diarepkeun "Hello, world!": Sakuduna true </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="lua" line highlight=2 copy> local modTest = require('Modul:Bananas/testcases') print(modTest.run(mw.getCurrentFrame())) </syntaxhighlight></blockquote> [[Modul:ScribuntoUnit]] originates from Hungarian Wikipedia.<br /> It throws real errors that are trapped using protected calls. It also has a method to compare floats within a given precision. Pikeun daptar sakabéh modul nu ngagunakeun tés unit, tingali [[Husus:NumbuKaDieu/Modul:ScribuntoUnit|nu dipaké]]. == Wikipedia-specific features == Overall: Lua can only get input as text strings passed to the <code><nowiki>{{#invoke:}}</nowiki></code> and what can be fetched via <code>[[mw:Extension:Scribunto/Lua reference manual#mw.title.new|mw.title.new(...)]]:getContent()</code> and <code>[[mw:Extension:Scribunto/Lua reference manual#frame:expandTemplate|frame:expandTemplate()]]</code>. Lua output will not be preprocessed unless <code>frame:</code>'''<code>[[mw:Extension:Scribunto/Lua reference manual#frame:preprocess|preprocess()]]</code>''' is explicitly called, meaning that template calls and parser functions in the output will not work correctly. Langkung hade ngagunakeun fungsi '''<code>[[mw:Extension:Scribunto/Lua reference manual#mw.ustring.len|mw.ustring.len]]</code>''' tibatan <code>[[mw:Extension:Scribunto/Lua reference manual#string.len|string.len]]</code>: Di konsol debug [[modul:Yesno]]: <blockquote><syntaxhighlight lang="lua" line highlight=2,8 copy> --[[Alfabét Latin]]-- local content_lang = mw.getContentLanguage().code -- su local lang = mw.getCurrentFrame():callParserFunction("#language", content_lang) local lenUnicode, lenByte, lenSharp = mw.ustring.len(lang), string.len(lang), #lang print(("lang: \"%s\". Mw.ustring.len = %d String.len = %d Sharp = %d"):format(lang, lenUnicode, lenByte, lenSharp)) --[[Unicode]]-- lang = "اَكسارا ڤَيڮَون" -- Aksara Pégon lenUnicode, lenByte, lenSharp = mw.ustring.len(lang), string.len(lang), #lang print(("lang: \"%s\". Mw.ustring.len = %d String.len = %d Sharp = %d"):format(lang, lenUnicode, lenByte, lenSharp)) </syntaxhighlight></blockquote> <code>Konsol debug</code> ngarojong Unicode, tapi henteu ngarojong téks katuhu-ka-kenca: <blockquote><syntaxhighlight lang="text" line start=11> lang: "Sunda". Mw.ustring.len = 5 String.len = 5 Sharp = 5 lang: "اَكسارا ڤَيڮَون". Mw.ustring.len = 15 String.len = 29 Sharp = 29 </syntaxhighlight></blockquote> {| class="wikitable" ![[Alfabét Latin]] !Aksara !Arah !Jumlah karakter !Panjang dina bait |- |'''Sunda''' |[[Basa Sunda]]. |→ kenca ka katuhu. |5 |5 |- |[[Hurup Pégon]] |style="direction:rtl; text-align:right;" |'''اَكسارا ڤَيڮَون'''. |← '''Katuhu''' ka kenca |'''15''' ('''[[Unicode]]''') + 1 titik |<span style="color:red;">29</span> + 1 |} {{#invoke:Utf8debug|ek|اَكسارا ڤَيڮَون.}} Lua code in a wiki page is limited to '''10 s'''econds CPU time (you can look in the source code of a rendered page to see how long a template or module took to parse). Relative to standard Lua, Scribunto offers safe functions (see the [[mw:Extension:Scribunto/Lua reference manual#Differences from standard Lua|differences]] from standard Lua). === Lua input limitations === Lua code in Scribunto is only run when the page is being parsed. Therefore, the only user input that Lua can receive is by ''page editing'' - it cannot create a box that calculates the square root of a number you type in, or recalculate a piece of the Mandelbrot set depending on which part of the parent set you click on. The input Lua can receive includes any transcludeable text page on Wikipedia. This does ''not'' include graphics files (not even .SVG files, although they are actually text, unless you cut and paste it onto a Wiki text page), the list of pages listed in a [[:Kategori:Lua-based templates|category]], nor the contents of [[Wikipedia:Transclusion#Special pages|non-transcludeable]] [[Husus:IndeksAwalan/Modul:|special pages]]. === Wikitext === Transcluded Wikipedia headers frequently contain a hidden code such as <syntaxhighlight lang="lua" inline>"UNIQ5ae8f2aa414ff233-h-3--QINU"</syntaxhighlight> which may need to be stripped out in order for them to be parsed effectively. <blockquote><syntaxhighlight lang="lua" line highlight=1 copy> print(string.reverse("UNIQ")) -- Urutan sabalikna tina "UNIQ" nyaéta "QINU" </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="lua" line start=2> QINU </syntaxhighlight></blockquote> Wikilinks of the type <code><nowiki>[[Wikipedia:Pitulung</nowiki></code>'''<code><nowiki>|</nowiki></code>'''<code><nowiki>]]</nowiki></code> won't work if returned as output - they need to be written explicitly as <syntaxhighlight lang="lua" inline>[[Wikipedia:Pitulung|</syntaxhighlight>'''<code><nowiki>Pitulung</nowiki></code>'''<syntaxhighlight lang="lua" inline>]]</syntaxhighlight>. Other pre-save transforms, such as replacing <code>~~<nowiki/>~~</code> with signatures, will also fail to be processed. Template transclusions, parser function calls, and variable substitutions (i.e. anything with a <code><nowiki>{{...}}</nowiki></code>) will not be processed, nor will tags such as {{tag|ref|o}} or {{tag|nowiki|o}}. == Labeling converted templates == {{lua|Module:Bananas}} Please place the {{tl|lua}} template on the documentation subpage of all templates that use Lua. It will help to better communicate Lua usage and template conversions. {{clear}} == See also == * [[Husus:IndeksAwalan/Modul:]] daptar modul Lua * [[:Kategori:Lua-based templates]] &ndash; l-groups ta templates based kan Lua ; English Wikipedia-specific resources * [[:mw:Manual:Coding conventions/Lua]] &ndash; standards to improve the readability of code through consistency * [[:en:Help:Lua debugging]] &ndash; a how-to guide about debugging Lua modules * [[:en:Module:Sandbox]] provides a pseudo-namespace for experimenting with Lua modules * [[:en:Wikipedia talk:Lua]] &ndash; requests for Lua-based templates or tasks == Notes == {{reflist}} {{WikiProject Lua/header}} [[Category:Wikipedia modules]] 7cjcflo3ipoqe3mmgd96utfyrsf2oaa 712260 712259 2026-08-25T21:00:34Z Nimmzo 37272 /* Unit testing */ Principle of unit testing 712260 wikitext text/x-wiki {{tarjamahkeun|Inggris}} {{WikiProject Lua/header}} {{Information page|WP:Lua}} {{Namespaces}} Lua mangrupakeun basa pamrograman nu ayeuna geus sadia di Wikipedia Sunda ngaliwatan ekstensi MediaWiki [[mw:Extension:Scribunto|Scribunto]].<br /> Kode Lua ayeuna bisa diasupkeun kana témplat wiki ku maké fungsi parser <syntaxhighlight lang="lua" inline>{{#invoke:}}</syntaxhighlight> dina kaca pamaké anjeun. == Halo, dunya! dina Lua == The Lua source code is stored in a wiki page with the prefix <syntaxhighlight lang="lua" inline>Modul:</syntaxhighlight> (e.g., [[Modul:Bananas]]). These individual modules are then invoked (by code <syntaxhighlight lang="lua" inline>{{#invoke:}}</syntaxhighlight>) on another wiki page (e.g., [[Modul:Bananas/doc]] uses the code <syntaxhighlight lang="lua" inline>{{#invoke:Bananas|hello}}</syntaxhighlight> to print the text <syntaxhighlight lang="lua" inline>"Hello, world!"</syntaxhighlight>). Modules are run on normal wiki pages using the <code>#invoke</code> parser function. The syntax of <code>#invoke</code> is similar to template syntax, but with some differences. The most important difference is that you need to specify a ''function name''. A function is a set of Lua instructions that takes input values, processes them, and returns an output value.<ref>You can also have multiple output values, but functions that do this are not normally meant to be accessed from wiki pages.</ref> This is much like what a template does: you give it arguments, it processes them, and you get a result.<br /> However, you can define many functions in one Lua module, whereas you can only define one template on one page. Furthermore, you can't just run a Lua module directly - you can only run one of the module's functions. The module is just a container for the functions, and doesn't do anything by itself. So there are two reasons that we need to input a function name: # We can't run a module by itself. # Without specifying a function name, Lua will not know which function it is we want to run. Run a module from your user page like this: <blockquote><syntaxhighlight lang="lua" line> {{#invoke:NgaranModul|ngaranFungsi}} </syntaxhighlight></blockquote> For example, [[Modul:Bananas]] is the simplest possible script, providing a single function with no arguments.<br /> The function is named <code>hello</code> in lowercase. We can run this module in this way. Anjeun teu kudu masang atawa nyimpen nanaon. # Édit kaca pamaké anjeun. # Témpélkeun panggilan di handap ieu dina awal hiji baris anyar dina kaca pamaké anjeun: <blockquote><syntaxhighlight lang="wikitext" line highlight=1 copy> {{#invoke:Bananas|hello}} </syntaxhighlight></blockquote> <ol start="3"> <li>Klik <code>Témbongkeun sawangan</code>. Panggilan fungsi <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> dina [[Modul:Bananas]] diganti ku ieu di handap: Halo, dunya!</li> </ol> <blockquote><syntaxhighlight lang="text" line> Hello, world! </syntaxhighlight></blockquote> <ol start="4"> <li>Klik <code style="color:#bf3c2c;>Bolay</code>. Lamun dipenta, klik <code>Tinggalkeun</code>.</li> <li>Kaca pamaké anjeun tetep '''teu''' dirobah.</li> </ol> === Using arguments === Arguments are passed to modules in the same way that they are passed to templates. Note, however, that the text after the first pipe character <code>|</code> is always the function name; the first positional argument is the text after the ''second'' pipe. <blockquote><syntaxhighlight lang="lua" line> {{#invoke:NgaranModul|ngaranFungsi|arguménPosisional1}} </syntaxhighlight></blockquote> For example, another [[Modul:BananasArgs]] demonstrates how to access and use parameters.<br /> The <code>hello</code> function greets different people depending on the first positional argument. It works like this: Dina kaca pamaké anjeun: <blockquote><syntaxhighlight lang="wikitext" line highlight=1 copy> # {{#invoke:BananasArgs|hello|Mariam}} # {{#invoke:BananasArgs|hello|Mohamed}} </syntaxhighlight></blockquote> <blockquote> # {{#invoke:BananasArgs|hello|Mariam}} # {{#invoke:BananasArgs|hello|Mohamed}} </blockquote> ;Named arguments key=value <blockquote><syntaxhighlight lang="lua" line> {{#invoke:NgaranModul|ngaranFungsi|argNgaran1=nilai1|argNgaran2=nilai2}} </syntaxhighlight></blockquote> The <syntaxhighlight lang="lua" inline>Modul:</syntaxhighlight>BananasArgs also has a function named <code>count_fruit</code> which uses the named arguments <code>bananas</code> and <code>apples</code> to count the number of bananas and apples we have. It can be run switching the order of the parameters: Dina kaca pamaké anjeun: <blockquote><syntaxhighlight lang="wikitext" line highlight=1 copy> # {{#invoke:BananasArgs|count_fruit|apples=3|bananas=4}} # {{#invoke:BananasArgs|count_fruit|bananas=5|apples=2}} </syntaxhighlight></blockquote> <blockquote> # {{#invoke:BananasArgs|count_fruit|apples=3|bananas=4}} # {{#invoke:BananasArgs|count_fruit|bananas=5|apples=2}} </blockquote> Most modules have a documentation page explaining what arguments can be used and what their effects will be. == Konsol debug: Mimiti diajar Lua == <code>Debug Console</code> dina Lua Scribunto nyaéta alat anu aman tur interaktif pikeun diajar Lua dina Wikipedia. # Klik <code>Témbongkeun sumber</code> dina kaca [[Modul:Yesno]]. # Gulung ka handap kaca nepi ka bagian <code>Debug console</code>. # Témpélkeun komentar jeung panggilan kana kotak asup <span style="color:#86888c;">kulawu</span> (di luhur tombol <code>Kosongkan</code>). <blockquote><syntaxhighlight lang="lua" line highlight=2 copy> --[[Program Lua munggaran anjeun nu mirip Hello World]]-- print("Wilujeng sumping di " .. _VERSION .. "!") -- Ngarangkep vérsi Lua ku `..` </syntaxhighlight></blockquote> <ol start="4"> <li>Pencét {{key press|Enter}} sakali pikeun ngalaksanakeun dua paréntah Lua éta.</li> <li>Hasilna bakal muncul di handap garis paréntah Lua <syntaxhighlight lang="lua" inline>print</syntaxhighlight>:</li> </ol> <blockquote><syntaxhighlight lang="text" line start=3> Wilujeng sumping di Lua 5.1! </syntaxhighlight></blockquote> <ol start="6"> <li>Pencét {{key press|Up}} <code>Panah ka luhur</code> pikeun ngurilingan paréntah Lua saméméhna.</li> <li>Opsional, klik <code>Kosongkan</code> pikeun ngaberesihan ''ngan'' <code>Debug Console</code>; éditor Lua di luhur moal '''teu''' robah.</li> </ol> ; Generator HTML dina Debug console Panggil pungsi <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> dina <code>Modul:</code>Bananas: <blockquote><syntaxhighlight lang="lua" line highlight=2 copy> local modCau = require('Modul:Bananas') -- muat modul dina Debug console print(modCau.hello()) -- tampilkeun "Hello, world!" </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="text" line start=3> Hello, world! </syntaxhighlight></blockquote> ; Argumén <blockquote><syntaxhighlight lang="lua" line highlight=3,5 copy> local modCau = require('Modul:BananasArgs') local frame = mw.getCurrentFrame() frame.args = {"Mariam"}; print(modCau.hello(frame)) -- "Hello, Mariam!" frame.args = {"Mohamed"}; print(modCau.hello(frame)) frame.args = {apples="3", bananas="4"}; print(modCau.count_fruit(frame)) frame.args = {bananas="5", apples="2"}; print(modCau.count_fruit(frame)) </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="lua" line start=7> Hello, Mariam! Hello, Mohamed! I have 4 bananas and 3 apples I have 5 bananas and 2 apples </syntaxhighlight></blockquote> ; Fungsi idéntitas <code>callParserFunction</code> [[mw:Help:Extension:ParserFunctions##if|#if]] <blockquote><syntaxhighlight lang="lua" line highlight=3 copy> local yesno = require('Modul:Yesno') -- #if yesno teras mulangkeun parameter asupanna local frame = mw.getCurrentFrame() print(frame:callParserFunction("#if", yesno("Yes"), "Yes", 'henteu')) print(frame:callParserFunction("#if", yesno('teu'), "Leres", 'teu')) </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="text" line start=5> Yes teu </syntaxhighlight></blockquote> # Tutup <code>Modul:</code>Yesno anu dijaga anu tetep '''teu''' robah. == Request a script == Visit [[:en:Wikipedia talk:Lua]] to request help in writing a Lua script to perform a specific task on Wikipedia or another Wikimedia Foundation project. == History == [[mw:Manual:MediaWiki architecture#Magic words and templates|Sordid history]]. [[mw:Help:Extension:ParserFunctions|ParserFunctions]], [[mw:Extension:Lua|Lua extension]], wiki scripting language debated (JavaScript v. Lua), [[mw:Extension:WikiScripts]], Tim writes [[mw:Extension:Scribunto|Scribunto]] with initial support for Lua. Discussed for years, Lua was installed in 2012 for testing on [[test2wiki:|test2.wikipedia.org]], with open invitation to all editors to experiment with developing Lua modules. Lua was installed on the English Wikipedia in February 2013, after testing on mediawiki.org and Wikimedia test wikis. == About Lua == :''See also [[:File:WMF Tech Talk 2013-02-28 slides - Scribunto presentation.pdf|Brad Jorsch's short presentation for a basic example of how to convert a wikitext template into a Lua module.]]'' Lua is a scripting language which can be used to analyze data, calculate expressions, and format results using functions or object-oriented programming. Although some Lua scripts can be kept simple, for easy understanding, Lua allows complex structures including tables, dynamic functions, and associative arrays where index subscripts can be words as well as index numbers. Lua also supports recursion of re-nested functions, so care should be taken to avoid excessive complexity where other users would not understand how to maintain a Lua module. The following is an example of Lua source code for the <code>hello</code> function contained in [[Modul:Bananas]]: <syntaxhighlight lang="lua" line highlight=3> --[[Modul:Bananas]]-- local p = {} -- tabel modul nu diperlukeun, diinisialisasi minangka tabel kosong function p.hello() -- Nangtukeun fungsi hello. return "Hello, world!" -- Mulangkeun hasil fungsi dina wangun string. end -- Ahir fungsi. return p -- Mulangkeun tabel modul. </syntaxhighlight> A sample of Lua is highlighted by tag <code><nowiki><syntaxhighlight lang="lua" line highlight=1 copy> ... </syntaxhighlight></nowiki></code> placed around the Lua source code. For instructions on how to use Lua within MediaWiki (and hence Wikipedia), see [[mw:Extension:Scribunto/Lua reference manual]]. == Unit testing == A unit testing framework for Lua scripts on Wikipedia is available at [[Modul:ScribuntoUnit]].<br /> It allows you to execute your script on a given set of inputs and verify that the expected outputs are produced.<br /> Unit tests are especially useful for rapidly detecting regressions, where modifications to a script introduce new problems. By convention, unit tests for a module like [[Modul:Bananas]] are placed in <syntaxhighlight lang="lua" inline>Modul:</syntaxhighlight> <code>Bananas</code>'''<code>/testcases</code>'''.<br /> They are executed on [[Pembicaraan Modul:Bananas/testcases]] with <syntaxhighlight lang="lua" inline>{{#invoke:Bananas/testcases|</syntaxhighlight>'''<code>run</code>'''<syntaxhighlight lang="lua" inline>}}</syntaxhighlight>. Dina kaca pamaké anjeun: <blockquote><syntaxhighlight lang="wikitext" line highlight=1 copy> {{#invoke:Bananas/testcases|run}} </syntaxhighlight></blockquote> <blockquote> {{#invoke:Bananas/testcases|run}} </blockquote> Each test method must begin with <syntaxhighlight lang="lua" inline>p:</syntaxhighlight>'''<code>test_</code>'''. An example from [[Modul:Bananas/testcases]] is below. <syntaxhighlight lang="lua" line highlight=4 copy> --[[Modul:Bananas/testcases]]-- local p = require('Modul:ScribuntoUnit').new() local modCau = require('Modul:Bananas') -- Didatangan kaca obrolan pikeun ngajalankeun tés. function p:test_halo() -- Tés unit pikeun [[Modul:Bananas]]. self:assertEquals('Hello, world!', modCau.hello()) end return p </syntaxhighlight> {{collapse top|title=Prinsip uji hijian}} Di konsol debug [[modul:Yesno]]: <blockquote><syntaxhighlight lang="lua" line highlight=10 copy> local self = { assertEquals = function(_, wikitext, expected) local got = mw.getCurrentFrame():preprocess(wikitext) print('"' .. expected .. '": Diarepkeun') print('"' .. got .. '": Saleresna') return got == expected end } -- Pamisah `:` tanpa `self` print(self:assertEquals( '{{#invoke:Bananas|hello}}', 'Hello, world!')) -- Pamisah `.` jeung `self` print(self.assertEquals(self, '{{#invoke:Bananas|hello}}', 'Hello, world!')) </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="lua" line start=13> "Hello, world!": Diarepkeun "Hello, world!": Sakuduna true "Hello, world!": Diarepkeun "Hello, world!": Sakuduna true </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="lua" line highlight=2 copy> local modTest = require('Modul:Bananas/testcases') print(modTest.run(mw.getCurrentFrame())) </syntaxhighlight></blockquote> Lamun tésna hasil, nilai anu diarepkeun jeung nilai sabenerna teu dipintonkeun supaya tabel hasil jadi leuwih basajan: <blockquote><syntaxhighlight lang="lua" line start=3> [[File:Yes check.svg|20px|alt=Ya|link=]]<span style="display:none">Y</span> Sakabéh tés lulus. </syntaxhighlight></blockquote> {{collapse bottom}} [[Modul:ScribuntoUnit]] originates from Hungarian Wikipedia.<br /> It throws real errors that are trapped using protected calls. It also has a method to compare floats within a given precision. Pikeun daptar sakabéh modul nu ngagunakeun tés unit, tingali [[Husus:NumbuKaDieu/Modul:ScribuntoUnit|nu dipaké]]. == Wikipedia-specific features == Overall: Lua can only get input as text strings passed to the <code><nowiki>{{#invoke:}}</nowiki></code> and what can be fetched via <code>[[mw:Extension:Scribunto/Lua reference manual#mw.title.new|mw.title.new(...)]]:getContent()</code> and <code>[[mw:Extension:Scribunto/Lua reference manual#frame:expandTemplate|frame:expandTemplate()]]</code>. Lua output will not be preprocessed unless <code>frame:</code>'''<code>[[mw:Extension:Scribunto/Lua reference manual#frame:preprocess|preprocess()]]</code>''' is explicitly called, meaning that template calls and parser functions in the output will not work correctly. Langkung hade ngagunakeun fungsi '''<code>[[mw:Extension:Scribunto/Lua reference manual#mw.ustring.len|mw.ustring.len]]</code>''' tibatan <code>[[mw:Extension:Scribunto/Lua reference manual#string.len|string.len]]</code>: Di konsol debug [[modul:Yesno]]: <blockquote><syntaxhighlight lang="lua" line highlight=2,8 copy> --[[Alfabét Latin]]-- local content_lang = mw.getContentLanguage().code -- su local lang = mw.getCurrentFrame():callParserFunction("#language", content_lang) local lenUnicode, lenByte, lenSharp = mw.ustring.len(lang), string.len(lang), #lang print(("lang: \"%s\". Mw.ustring.len = %d String.len = %d Sharp = %d"):format(lang, lenUnicode, lenByte, lenSharp)) --[[Unicode]]-- lang = "اَكسارا ڤَيڮَون" -- Aksara Pégon lenUnicode, lenByte, lenSharp = mw.ustring.len(lang), string.len(lang), #lang print(("lang: \"%s\". Mw.ustring.len = %d String.len = %d Sharp = %d"):format(lang, lenUnicode, lenByte, lenSharp)) </syntaxhighlight></blockquote> <code>Konsol debug</code> ngarojong Unicode, tapi henteu ngarojong téks katuhu-ka-kenca: <blockquote><syntaxhighlight lang="text" line start=11> lang: "Sunda". Mw.ustring.len = 5 String.len = 5 Sharp = 5 lang: "اَكسارا ڤَيڮَون". Mw.ustring.len = 15 String.len = 29 Sharp = 29 </syntaxhighlight></blockquote> {| class="wikitable" ![[Alfabét Latin]] !Aksara !Arah !Jumlah karakter !Panjang dina bait |- |'''Sunda''' |[[Basa Sunda]]. |→ kenca ka katuhu. |5 |5 |- |[[Hurup Pégon]] |style="direction:rtl; text-align:right;" |'''اَكسارا ڤَيڮَون'''. |← '''Katuhu''' ka kenca |'''15''' ('''[[Unicode]]''') + 1 titik |<span style="color:red;">29</span> + 1 |} {{#invoke:Utf8debug|ek|اَكسارا ڤَيڮَون.}} Lua code in a wiki page is limited to '''10 s'''econds CPU time (you can look in the source code of a rendered page to see how long a template or module took to parse). Relative to standard Lua, Scribunto offers safe functions (see the [[mw:Extension:Scribunto/Lua reference manual#Differences from standard Lua|differences]] from standard Lua). === Lua input limitations === Lua code in Scribunto is only run when the page is being parsed. Therefore, the only user input that Lua can receive is by ''page editing'' - it cannot create a box that calculates the square root of a number you type in, or recalculate a piece of the Mandelbrot set depending on which part of the parent set you click on. The input Lua can receive includes any transcludeable text page on Wikipedia. This does ''not'' include graphics files (not even .SVG files, although they are actually text, unless you cut and paste it onto a Wiki text page), the list of pages listed in a [[:Kategori:Lua-based templates|category]], nor the contents of [[Wikipedia:Transclusion#Special pages|non-transcludeable]] [[Husus:IndeksAwalan/Modul:|special pages]]. === Wikitext === Transcluded Wikipedia headers frequently contain a hidden code such as <syntaxhighlight lang="lua" inline>"UNIQ5ae8f2aa414ff233-h-3--QINU"</syntaxhighlight> which may need to be stripped out in order for them to be parsed effectively. <blockquote><syntaxhighlight lang="lua" line highlight=1 copy> print(string.reverse("UNIQ")) -- Urutan sabalikna tina "UNIQ" nyaéta "QINU" </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="lua" line start=2> QINU </syntaxhighlight></blockquote> Wikilinks of the type <code><nowiki>[[Wikipedia:Pitulung</nowiki></code>'''<code><nowiki>|</nowiki></code>'''<code><nowiki>]]</nowiki></code> won't work if returned as output - they need to be written explicitly as <syntaxhighlight lang="lua" inline>[[Wikipedia:Pitulung|</syntaxhighlight>'''<code><nowiki>Pitulung</nowiki></code>'''<syntaxhighlight lang="lua" inline>]]</syntaxhighlight>. Other pre-save transforms, such as replacing <code>~~<nowiki/>~~</code> with signatures, will also fail to be processed. Template transclusions, parser function calls, and variable substitutions (i.e. anything with a <code><nowiki>{{...}}</nowiki></code>) will not be processed, nor will tags such as {{tag|ref|o}} or {{tag|nowiki|o}}. == Labeling converted templates == {{lua|Module:Bananas}} Please place the {{tl|lua}} template on the documentation subpage of all templates that use Lua. It will help to better communicate Lua usage and template conversions. {{clear}} == See also == * [[Husus:IndeksAwalan/Modul:]] daptar modul Lua * [[:Kategori:Lua-based templates]] &ndash; l-groups ta templates based kan Lua ; English Wikipedia-specific resources * [[:mw:Manual:Coding conventions/Lua]] &ndash; standards to improve the readability of code through consistency * [[:en:Help:Lua debugging]] &ndash; a how-to guide about debugging Lua modules * [[:en:Module:Sandbox]] provides a pseudo-namespace for experimenting with Lua modules * [[:en:Wikipedia talk:Lua]] &ndash; requests for Lua-based templates or tasks == Notes == {{reflist}} {{WikiProject Lua/header}} [[Category:Wikipedia modules]] 22crp314lm7bbg6ou6bvr7h3jmc05o7 712261 712260 2026-08-25T21:10:05Z Nimmzo 37272 /* Unit testing */ The generated HTML tags and wikitable 712261 wikitext text/x-wiki {{tarjamahkeun|Inggris}} {{WikiProject Lua/header}} {{Information page|WP:Lua}} {{Namespaces}} Lua mangrupakeun basa pamrograman nu ayeuna geus sadia di Wikipedia Sunda ngaliwatan ekstensi MediaWiki [[mw:Extension:Scribunto|Scribunto]].<br /> Kode Lua ayeuna bisa diasupkeun kana témplat wiki ku maké fungsi parser <syntaxhighlight lang="lua" inline>{{#invoke:}}</syntaxhighlight> dina kaca pamaké anjeun. == Halo, dunya! dina Lua == The Lua source code is stored in a wiki page with the prefix <syntaxhighlight lang="lua" inline>Modul:</syntaxhighlight> (e.g., [[Modul:Bananas]]). These individual modules are then invoked (by code <syntaxhighlight lang="lua" inline>{{#invoke:}}</syntaxhighlight>) on another wiki page (e.g., [[Modul:Bananas/doc]] uses the code <syntaxhighlight lang="lua" inline>{{#invoke:Bananas|hello}}</syntaxhighlight> to print the text <syntaxhighlight lang="lua" inline>"Hello, world!"</syntaxhighlight>). Modules are run on normal wiki pages using the <code>#invoke</code> parser function. The syntax of <code>#invoke</code> is similar to template syntax, but with some differences. The most important difference is that you need to specify a ''function name''. A function is a set of Lua instructions that takes input values, processes them, and returns an output value.<ref>You can also have multiple output values, but functions that do this are not normally meant to be accessed from wiki pages.</ref> This is much like what a template does: you give it arguments, it processes them, and you get a result.<br /> However, you can define many functions in one Lua module, whereas you can only define one template on one page. Furthermore, you can't just run a Lua module directly - you can only run one of the module's functions. The module is just a container for the functions, and doesn't do anything by itself. So there are two reasons that we need to input a function name: # We can't run a module by itself. # Without specifying a function name, Lua will not know which function it is we want to run. Run a module from your user page like this: <blockquote><syntaxhighlight lang="lua" line> {{#invoke:NgaranModul|ngaranFungsi}} </syntaxhighlight></blockquote> For example, [[Modul:Bananas]] is the simplest possible script, providing a single function with no arguments.<br /> The function is named <code>hello</code> in lowercase. We can run this module in this way. Anjeun teu kudu masang atawa nyimpen nanaon. # Édit kaca pamaké anjeun. # Témpélkeun panggilan di handap ieu dina awal hiji baris anyar dina kaca pamaké anjeun: <blockquote><syntaxhighlight lang="wikitext" line highlight=1 copy> {{#invoke:Bananas|hello}} </syntaxhighlight></blockquote> <ol start="3"> <li>Klik <code>Témbongkeun sawangan</code>. Panggilan fungsi <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> dina [[Modul:Bananas]] diganti ku ieu di handap: Halo, dunya!</li> </ol> <blockquote><syntaxhighlight lang="text" line> Hello, world! </syntaxhighlight></blockquote> <ol start="4"> <li>Klik <code style="color:#bf3c2c;>Bolay</code>. Lamun dipenta, klik <code>Tinggalkeun</code>.</li> <li>Kaca pamaké anjeun tetep '''teu''' dirobah.</li> </ol> === Using arguments === Arguments are passed to modules in the same way that they are passed to templates. Note, however, that the text after the first pipe character <code>|</code> is always the function name; the first positional argument is the text after the ''second'' pipe. <blockquote><syntaxhighlight lang="lua" line> {{#invoke:NgaranModul|ngaranFungsi|arguménPosisional1}} </syntaxhighlight></blockquote> For example, another [[Modul:BananasArgs]] demonstrates how to access and use parameters.<br /> The <code>hello</code> function greets different people depending on the first positional argument. It works like this: Dina kaca pamaké anjeun: <blockquote><syntaxhighlight lang="wikitext" line highlight=1 copy> # {{#invoke:BananasArgs|hello|Mariam}} # {{#invoke:BananasArgs|hello|Mohamed}} </syntaxhighlight></blockquote> <blockquote> # {{#invoke:BananasArgs|hello|Mariam}} # {{#invoke:BananasArgs|hello|Mohamed}} </blockquote> ;Named arguments key=value <blockquote><syntaxhighlight lang="lua" line> {{#invoke:NgaranModul|ngaranFungsi|argNgaran1=nilai1|argNgaran2=nilai2}} </syntaxhighlight></blockquote> The <syntaxhighlight lang="lua" inline>Modul:</syntaxhighlight>BananasArgs also has a function named <code>count_fruit</code> which uses the named arguments <code>bananas</code> and <code>apples</code> to count the number of bananas and apples we have. It can be run switching the order of the parameters: Dina kaca pamaké anjeun: <blockquote><syntaxhighlight lang="wikitext" line highlight=1 copy> # {{#invoke:BananasArgs|count_fruit|apples=3|bananas=4}} # {{#invoke:BananasArgs|count_fruit|bananas=5|apples=2}} </syntaxhighlight></blockquote> <blockquote> # {{#invoke:BananasArgs|count_fruit|apples=3|bananas=4}} # {{#invoke:BananasArgs|count_fruit|bananas=5|apples=2}} </blockquote> Most modules have a documentation page explaining what arguments can be used and what their effects will be. == Konsol debug: Mimiti diajar Lua == <code>Debug Console</code> dina Lua Scribunto nyaéta alat anu aman tur interaktif pikeun diajar Lua dina Wikipedia. # Klik <code>Témbongkeun sumber</code> dina kaca [[Modul:Yesno]]. # Gulung ka handap kaca nepi ka bagian <code>Debug console</code>. # Témpélkeun komentar jeung panggilan kana kotak asup <span style="color:#86888c;">kulawu</span> (di luhur tombol <code>Kosongkan</code>). <blockquote><syntaxhighlight lang="lua" line highlight=2 copy> --[[Program Lua munggaran anjeun nu mirip Hello World]]-- print("Wilujeng sumping di " .. _VERSION .. "!") -- Ngarangkep vérsi Lua ku `..` </syntaxhighlight></blockquote> <ol start="4"> <li>Pencét {{key press|Enter}} sakali pikeun ngalaksanakeun dua paréntah Lua éta.</li> <li>Hasilna bakal muncul di handap garis paréntah Lua <syntaxhighlight lang="lua" inline>print</syntaxhighlight>:</li> </ol> <blockquote><syntaxhighlight lang="text" line start=3> Wilujeng sumping di Lua 5.1! </syntaxhighlight></blockquote> <ol start="6"> <li>Pencét {{key press|Up}} <code>Panah ka luhur</code> pikeun ngurilingan paréntah Lua saméméhna.</li> <li>Opsional, klik <code>Kosongkan</code> pikeun ngaberesihan ''ngan'' <code>Debug Console</code>; éditor Lua di luhur moal '''teu''' robah.</li> </ol> ; Generator HTML dina Debug console Panggil pungsi <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> dina <code>Modul:</code>Bananas: <blockquote><syntaxhighlight lang="lua" line highlight=2 copy> local modCau = require('Modul:Bananas') -- muat modul dina Debug console print(modCau.hello()) -- tampilkeun "Hello, world!" </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="text" line start=3> Hello, world! </syntaxhighlight></blockquote> ; Argumén <blockquote><syntaxhighlight lang="lua" line highlight=3,5 copy> local modCau = require('Modul:BananasArgs') local frame = mw.getCurrentFrame() frame.args = {"Mariam"}; print(modCau.hello(frame)) -- "Hello, Mariam!" frame.args = {"Mohamed"}; print(modCau.hello(frame)) frame.args = {apples="3", bananas="4"}; print(modCau.count_fruit(frame)) frame.args = {bananas="5", apples="2"}; print(modCau.count_fruit(frame)) </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="lua" line start=7> Hello, Mariam! Hello, Mohamed! I have 4 bananas and 3 apples I have 5 bananas and 2 apples </syntaxhighlight></blockquote> ; Fungsi idéntitas <code>callParserFunction</code> [[mw:Help:Extension:ParserFunctions##if|#if]] <blockquote><syntaxhighlight lang="lua" line highlight=3 copy> local yesno = require('Modul:Yesno') -- #if yesno teras mulangkeun parameter asupanna local frame = mw.getCurrentFrame() print(frame:callParserFunction("#if", yesno("Yes"), "Yes", 'henteu')) print(frame:callParserFunction("#if", yesno('teu'), "Leres", 'teu')) </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="text" line start=5> Yes teu </syntaxhighlight></blockquote> # Tutup <code>Modul:</code>Yesno anu dijaga anu tetep '''teu''' robah. == Request a script == Visit [[:en:Wikipedia talk:Lua]] to request help in writing a Lua script to perform a specific task on Wikipedia or another Wikimedia Foundation project. == History == [[mw:Manual:MediaWiki architecture#Magic words and templates|Sordid history]]. [[mw:Help:Extension:ParserFunctions|ParserFunctions]], [[mw:Extension:Lua|Lua extension]], wiki scripting language debated (JavaScript v. Lua), [[mw:Extension:WikiScripts]], Tim writes [[mw:Extension:Scribunto|Scribunto]] with initial support for Lua. Discussed for years, Lua was installed in 2012 for testing on [[test2wiki:|test2.wikipedia.org]], with open invitation to all editors to experiment with developing Lua modules. Lua was installed on the English Wikipedia in February 2013, after testing on mediawiki.org and Wikimedia test wikis. == About Lua == :''See also [[:File:WMF Tech Talk 2013-02-28 slides - Scribunto presentation.pdf|Brad Jorsch's short presentation for a basic example of how to convert a wikitext template into a Lua module.]]'' Lua is a scripting language which can be used to analyze data, calculate expressions, and format results using functions or object-oriented programming. Although some Lua scripts can be kept simple, for easy understanding, Lua allows complex structures including tables, dynamic functions, and associative arrays where index subscripts can be words as well as index numbers. Lua also supports recursion of re-nested functions, so care should be taken to avoid excessive complexity where other users would not understand how to maintain a Lua module. The following is an example of Lua source code for the <code>hello</code> function contained in [[Modul:Bananas]]: <syntaxhighlight lang="lua" line highlight=3> --[[Modul:Bananas]]-- local p = {} -- tabel modul nu diperlukeun, diinisialisasi minangka tabel kosong function p.hello() -- Nangtukeun fungsi hello. return "Hello, world!" -- Mulangkeun hasil fungsi dina wangun string. end -- Ahir fungsi. return p -- Mulangkeun tabel modul. </syntaxhighlight> A sample of Lua is highlighted by tag <code><nowiki><syntaxhighlight lang="lua" line highlight=1 copy> ... </syntaxhighlight></nowiki></code> placed around the Lua source code. For instructions on how to use Lua within MediaWiki (and hence Wikipedia), see [[mw:Extension:Scribunto/Lua reference manual]]. == Unit testing == A unit testing framework for Lua scripts on Wikipedia is available at [[Modul:ScribuntoUnit]].<br /> It allows you to execute your script on a given set of inputs and verify that the expected outputs are produced.<br /> Unit tests are especially useful for rapidly detecting regressions, where modifications to a script introduce new problems. By convention, unit tests for a module like [[Modul:Bananas]] are placed in <syntaxhighlight lang="lua" inline>Modul:</syntaxhighlight> <code>Bananas</code>'''<code>/testcases</code>'''.<br /> They are executed on [[Pembicaraan Modul:Bananas/testcases]] with <syntaxhighlight lang="lua" inline>{{#invoke:Bananas/testcases|</syntaxhighlight>'''<code>run</code>'''<syntaxhighlight lang="lua" inline>}}</syntaxhighlight>. Dina kaca pamaké anjeun: <blockquote><syntaxhighlight lang="wikitext" line highlight=1 copy> {{#invoke:Bananas/testcases|run}} </syntaxhighlight></blockquote> <blockquote> {{#invoke:Bananas/testcases|run}} </blockquote> Each test method must begin with <syntaxhighlight lang="lua" inline>p:</syntaxhighlight>'''<code>test_</code>'''. An example from [[Modul:Bananas/testcases]] is below. <syntaxhighlight lang="lua" line highlight=4 copy> --[[Modul:Bananas/testcases]]-- local p = require('Modul:ScribuntoUnit').new() local modCau = require('Modul:Bananas') -- Didatangan kaca obrolan pikeun ngajalankeun tés. function p:test_halo() -- Tés unit pikeun [[Modul:Bananas]]. self:assertEquals('Hello, world!', modCau.hello()) end return p </syntaxhighlight> {{collapse top|title=Prinsip uji hijian}} Di konsol debug [[modul:Yesno]]: <blockquote><syntaxhighlight lang="lua" line highlight=10 copy> local self = { assertEquals = function(_, wikitext, expected) local got = mw.getCurrentFrame():preprocess(wikitext) print('"' .. expected .. '": Diarepkeun') print('"' .. got .. '": Saleresna') return got == expected end } -- Pamisah `:` tanpa `self` print(self:assertEquals( '{{#invoke:Bananas|hello}}', 'Hello, world!')) -- Pamisah `.` jeung `self` print(self.assertEquals(self, '{{#invoke:Bananas|hello}}', 'Hello, world!')) </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="lua" line start=13> "Hello, world!": Diarepkeun "Hello, world!": Sakuduna true "Hello, world!": Diarepkeun "Hello, world!": Sakuduna true </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="lua" line highlight=2 copy> local modTest = require('Modul:Bananas/testcases') print(modTest.run(mw.getCurrentFrame())) </syntaxhighlight></blockquote> Lamun tésna hasil, nilai anu diarepkeun jeung nilai sabenerna teu dipintonkeun supaya tabel hasil jadi leuwih basajan: <blockquote><syntaxhighlight lang="lua" line start=3> [[File:Yes check.svg|20px|alt=Ya|link=]]<span style="display:none">Y</span> Sakabéh tés lulus. {| class="wikitable scribunto-test-table" ! ! Ngaran ! Diarepkeun ! Saleresna |- | [[File:Yes check.svg|20px|alt=Ya|link=]]<span style="display:none">Y</span> | test_halo | | |} </syntaxhighlight></blockquote> {{collapse bottom}} [[Modul:ScribuntoUnit]] originates from Hungarian Wikipedia.<br /> It throws real errors that are trapped using protected calls. It also has a method to compare floats within a given precision. Pikeun daptar sakabéh modul nu ngagunakeun tés unit, tingali [[Husus:NumbuKaDieu/Modul:ScribuntoUnit|nu dipaké]]. == Wikipedia-specific features == Overall: Lua can only get input as text strings passed to the <code><nowiki>{{#invoke:}}</nowiki></code> and what can be fetched via <code>[[mw:Extension:Scribunto/Lua reference manual#mw.title.new|mw.title.new(...)]]:getContent()</code> and <code>[[mw:Extension:Scribunto/Lua reference manual#frame:expandTemplate|frame:expandTemplate()]]</code>. Lua output will not be preprocessed unless <code>frame:</code>'''<code>[[mw:Extension:Scribunto/Lua reference manual#frame:preprocess|preprocess()]]</code>''' is explicitly called, meaning that template calls and parser functions in the output will not work correctly. Langkung hade ngagunakeun fungsi '''<code>[[mw:Extension:Scribunto/Lua reference manual#mw.ustring.len|mw.ustring.len]]</code>''' tibatan <code>[[mw:Extension:Scribunto/Lua reference manual#string.len|string.len]]</code>: Di konsol debug [[modul:Yesno]]: <blockquote><syntaxhighlight lang="lua" line highlight=2,8 copy> --[[Alfabét Latin]]-- local content_lang = mw.getContentLanguage().code -- su local lang = mw.getCurrentFrame():callParserFunction("#language", content_lang) local lenUnicode, lenByte, lenSharp = mw.ustring.len(lang), string.len(lang), #lang print(("lang: \"%s\". Mw.ustring.len = %d String.len = %d Sharp = %d"):format(lang, lenUnicode, lenByte, lenSharp)) --[[Unicode]]-- lang = "اَكسارا ڤَيڮَون" -- Aksara Pégon lenUnicode, lenByte, lenSharp = mw.ustring.len(lang), string.len(lang), #lang print(("lang: \"%s\". Mw.ustring.len = %d String.len = %d Sharp = %d"):format(lang, lenUnicode, lenByte, lenSharp)) </syntaxhighlight></blockquote> <code>Konsol debug</code> ngarojong Unicode, tapi henteu ngarojong téks katuhu-ka-kenca: <blockquote><syntaxhighlight lang="text" line start=11> lang: "Sunda". Mw.ustring.len = 5 String.len = 5 Sharp = 5 lang: "اَكسارا ڤَيڮَون". Mw.ustring.len = 15 String.len = 29 Sharp = 29 </syntaxhighlight></blockquote> {| class="wikitable" ![[Alfabét Latin]] !Aksara !Arah !Jumlah karakter !Panjang dina bait |- |'''Sunda''' |[[Basa Sunda]]. |→ kenca ka katuhu. |5 |5 |- |[[Hurup Pégon]] |style="direction:rtl; text-align:right;" |'''اَكسارا ڤَيڮَون'''. |← '''Katuhu''' ka kenca |'''15''' ('''[[Unicode]]''') + 1 titik |<span style="color:red;">29</span> + 1 |} {{#invoke:Utf8debug|ek|اَكسارا ڤَيڮَون.}} Lua code in a wiki page is limited to '''10 s'''econds CPU time (you can look in the source code of a rendered page to see how long a template or module took to parse). Relative to standard Lua, Scribunto offers safe functions (see the [[mw:Extension:Scribunto/Lua reference manual#Differences from standard Lua|differences]] from standard Lua). === Lua input limitations === Lua code in Scribunto is only run when the page is being parsed. Therefore, the only user input that Lua can receive is by ''page editing'' - it cannot create a box that calculates the square root of a number you type in, or recalculate a piece of the Mandelbrot set depending on which part of the parent set you click on. The input Lua can receive includes any transcludeable text page on Wikipedia. This does ''not'' include graphics files (not even .SVG files, although they are actually text, unless you cut and paste it onto a Wiki text page), the list of pages listed in a [[:Kategori:Lua-based templates|category]], nor the contents of [[Wikipedia:Transclusion#Special pages|non-transcludeable]] [[Husus:IndeksAwalan/Modul:|special pages]]. === Wikitext === Transcluded Wikipedia headers frequently contain a hidden code such as <syntaxhighlight lang="lua" inline>"UNIQ5ae8f2aa414ff233-h-3--QINU"</syntaxhighlight> which may need to be stripped out in order for them to be parsed effectively. <blockquote><syntaxhighlight lang="lua" line highlight=1 copy> print(string.reverse("UNIQ")) -- Urutan sabalikna tina "UNIQ" nyaéta "QINU" </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="lua" line start=2> QINU </syntaxhighlight></blockquote> Wikilinks of the type <code><nowiki>[[Wikipedia:Pitulung</nowiki></code>'''<code><nowiki>|</nowiki></code>'''<code><nowiki>]]</nowiki></code> won't work if returned as output - they need to be written explicitly as <syntaxhighlight lang="lua" inline>[[Wikipedia:Pitulung|</syntaxhighlight>'''<code><nowiki>Pitulung</nowiki></code>'''<syntaxhighlight lang="lua" inline>]]</syntaxhighlight>. Other pre-save transforms, such as replacing <code>~~<nowiki/>~~</code> with signatures, will also fail to be processed. Template transclusions, parser function calls, and variable substitutions (i.e. anything with a <code><nowiki>{{...}}</nowiki></code>) will not be processed, nor will tags such as {{tag|ref|o}} or {{tag|nowiki|o}}. == Labeling converted templates == {{lua|Module:Bananas}} Please place the {{tl|lua}} template on the documentation subpage of all templates that use Lua. It will help to better communicate Lua usage and template conversions. {{clear}} == See also == * [[Husus:IndeksAwalan/Modul:]] daptar modul Lua * [[:Kategori:Lua-based templates]] &ndash; l-groups ta templates based kan Lua ; English Wikipedia-specific resources * [[:mw:Manual:Coding conventions/Lua]] &ndash; standards to improve the readability of code through consistency * [[:en:Help:Lua debugging]] &ndash; a how-to guide about debugging Lua modules * [[:en:Module:Sandbox]] provides a pseudo-namespace for experimenting with Lua modules * [[:en:Wikipedia talk:Lua]] &ndash; requests for Lua-based templates or tasks == Notes == {{reflist}} {{WikiProject Lua/header}} [[Category:Wikipedia modules]] a2l1c0vk33qo22f1yyxk9zp1v29huyi 712262 712261 2026-08-25T21:20:20Z Nimmzo 37272 /* Unit testing */ You can run [[Modul:ScribuntoUnit]] without creating the page [[Modul:Bananas/testcases]]. The generated HTML is identical. 712262 wikitext text/x-wiki {{tarjamahkeun|Inggris}} {{WikiProject Lua/header}} {{Information page|WP:Lua}} {{Namespaces}} Lua mangrupakeun basa pamrograman nu ayeuna geus sadia di Wikipedia Sunda ngaliwatan ekstensi MediaWiki [[mw:Extension:Scribunto|Scribunto]].<br /> Kode Lua ayeuna bisa diasupkeun kana témplat wiki ku maké fungsi parser <syntaxhighlight lang="lua" inline>{{#invoke:}}</syntaxhighlight> dina kaca pamaké anjeun. == Halo, dunya! dina Lua == The Lua source code is stored in a wiki page with the prefix <syntaxhighlight lang="lua" inline>Modul:</syntaxhighlight> (e.g., [[Modul:Bananas]]). These individual modules are then invoked (by code <syntaxhighlight lang="lua" inline>{{#invoke:}}</syntaxhighlight>) on another wiki page (e.g., [[Modul:Bananas/doc]] uses the code <syntaxhighlight lang="lua" inline>{{#invoke:Bananas|hello}}</syntaxhighlight> to print the text <syntaxhighlight lang="lua" inline>"Hello, world!"</syntaxhighlight>). Modules are run on normal wiki pages using the <code>#invoke</code> parser function. The syntax of <code>#invoke</code> is similar to template syntax, but with some differences. The most important difference is that you need to specify a ''function name''. A function is a set of Lua instructions that takes input values, processes them, and returns an output value.<ref>You can also have multiple output values, but functions that do this are not normally meant to be accessed from wiki pages.</ref> This is much like what a template does: you give it arguments, it processes them, and you get a result.<br /> However, you can define many functions in one Lua module, whereas you can only define one template on one page. Furthermore, you can't just run a Lua module directly - you can only run one of the module's functions. The module is just a container for the functions, and doesn't do anything by itself. So there are two reasons that we need to input a function name: # We can't run a module by itself. # Without specifying a function name, Lua will not know which function it is we want to run. Run a module from your user page like this: <blockquote><syntaxhighlight lang="lua" line> {{#invoke:NgaranModul|ngaranFungsi}} </syntaxhighlight></blockquote> For example, [[Modul:Bananas]] is the simplest possible script, providing a single function with no arguments.<br /> The function is named <code>hello</code> in lowercase. We can run this module in this way. Anjeun teu kudu masang atawa nyimpen nanaon. # Édit kaca pamaké anjeun. # Témpélkeun panggilan di handap ieu dina awal hiji baris anyar dina kaca pamaké anjeun: <blockquote><syntaxhighlight lang="wikitext" line highlight=1 copy> {{#invoke:Bananas|hello}} </syntaxhighlight></blockquote> <ol start="3"> <li>Klik <code>Témbongkeun sawangan</code>. Panggilan fungsi <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> dina [[Modul:Bananas]] diganti ku ieu di handap: Halo, dunya!</li> </ol> <blockquote><syntaxhighlight lang="text" line> Hello, world! </syntaxhighlight></blockquote> <ol start="4"> <li>Klik <code style="color:#bf3c2c;>Bolay</code>. Lamun dipenta, klik <code>Tinggalkeun</code>.</li> <li>Kaca pamaké anjeun tetep '''teu''' dirobah.</li> </ol> === Using arguments === Arguments are passed to modules in the same way that they are passed to templates. Note, however, that the text after the first pipe character <code>|</code> is always the function name; the first positional argument is the text after the ''second'' pipe. <blockquote><syntaxhighlight lang="lua" line> {{#invoke:NgaranModul|ngaranFungsi|arguménPosisional1}} </syntaxhighlight></blockquote> For example, another [[Modul:BananasArgs]] demonstrates how to access and use parameters.<br /> The <code>hello</code> function greets different people depending on the first positional argument. It works like this: Dina kaca pamaké anjeun: <blockquote><syntaxhighlight lang="wikitext" line highlight=1 copy> # {{#invoke:BananasArgs|hello|Mariam}} # {{#invoke:BananasArgs|hello|Mohamed}} </syntaxhighlight></blockquote> <blockquote> # {{#invoke:BananasArgs|hello|Mariam}} # {{#invoke:BananasArgs|hello|Mohamed}} </blockquote> ;Named arguments key=value <blockquote><syntaxhighlight lang="lua" line> {{#invoke:NgaranModul|ngaranFungsi|argNgaran1=nilai1|argNgaran2=nilai2}} </syntaxhighlight></blockquote> The <syntaxhighlight lang="lua" inline>Modul:</syntaxhighlight>BananasArgs also has a function named <code>count_fruit</code> which uses the named arguments <code>bananas</code> and <code>apples</code> to count the number of bananas and apples we have. It can be run switching the order of the parameters: Dina kaca pamaké anjeun: <blockquote><syntaxhighlight lang="wikitext" line highlight=1 copy> # {{#invoke:BananasArgs|count_fruit|apples=3|bananas=4}} # {{#invoke:BananasArgs|count_fruit|bananas=5|apples=2}} </syntaxhighlight></blockquote> <blockquote> # {{#invoke:BananasArgs|count_fruit|apples=3|bananas=4}} # {{#invoke:BananasArgs|count_fruit|bananas=5|apples=2}} </blockquote> Most modules have a documentation page explaining what arguments can be used and what their effects will be. == Konsol debug: Mimiti diajar Lua == <code>Debug Console</code> dina Lua Scribunto nyaéta alat anu aman tur interaktif pikeun diajar Lua dina Wikipedia. # Klik <code>Témbongkeun sumber</code> dina kaca [[Modul:Yesno]]. # Gulung ka handap kaca nepi ka bagian <code>Debug console</code>. # Témpélkeun komentar jeung panggilan kana kotak asup <span style="color:#86888c;">kulawu</span> (di luhur tombol <code>Kosongkan</code>). <blockquote><syntaxhighlight lang="lua" line highlight=2 copy> --[[Program Lua munggaran anjeun nu mirip Hello World]]-- print("Wilujeng sumping di " .. _VERSION .. "!") -- Ngarangkep vérsi Lua ku `..` </syntaxhighlight></blockquote> <ol start="4"> <li>Pencét {{key press|Enter}} sakali pikeun ngalaksanakeun dua paréntah Lua éta.</li> <li>Hasilna bakal muncul di handap garis paréntah Lua <syntaxhighlight lang="lua" inline>print</syntaxhighlight>:</li> </ol> <blockquote><syntaxhighlight lang="text" line start=3> Wilujeng sumping di Lua 5.1! </syntaxhighlight></blockquote> <ol start="6"> <li>Pencét {{key press|Up}} <code>Panah ka luhur</code> pikeun ngurilingan paréntah Lua saméméhna.</li> <li>Opsional, klik <code>Kosongkan</code> pikeun ngaberesihan ''ngan'' <code>Debug Console</code>; éditor Lua di luhur moal '''teu''' robah.</li> </ol> ; Generator HTML dina Debug console Panggil pungsi <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> dina <code>Modul:</code>Bananas: <blockquote><syntaxhighlight lang="lua" line highlight=2 copy> local modCau = require('Modul:Bananas') -- muat modul dina Debug console print(modCau.hello()) -- tampilkeun "Hello, world!" </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="text" line start=3> Hello, world! </syntaxhighlight></blockquote> ; Argumén <blockquote><syntaxhighlight lang="lua" line highlight=3,5 copy> local modCau = require('Modul:BananasArgs') local frame = mw.getCurrentFrame() frame.args = {"Mariam"}; print(modCau.hello(frame)) -- "Hello, Mariam!" frame.args = {"Mohamed"}; print(modCau.hello(frame)) frame.args = {apples="3", bananas="4"}; print(modCau.count_fruit(frame)) frame.args = {bananas="5", apples="2"}; print(modCau.count_fruit(frame)) </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="lua" line start=7> Hello, Mariam! Hello, Mohamed! I have 4 bananas and 3 apples I have 5 bananas and 2 apples </syntaxhighlight></blockquote> ; Fungsi idéntitas <code>callParserFunction</code> [[mw:Help:Extension:ParserFunctions##if|#if]] <blockquote><syntaxhighlight lang="lua" line highlight=3 copy> local yesno = require('Modul:Yesno') -- #if yesno teras mulangkeun parameter asupanna local frame = mw.getCurrentFrame() print(frame:callParserFunction("#if", yesno("Yes"), "Yes", 'henteu')) print(frame:callParserFunction("#if", yesno('teu'), "Leres", 'teu')) </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="text" line start=5> Yes teu </syntaxhighlight></blockquote> # Tutup <code>Modul:</code>Yesno anu dijaga anu tetep '''teu''' robah. == Request a script == Visit [[:en:Wikipedia talk:Lua]] to request help in writing a Lua script to perform a specific task on Wikipedia or another Wikimedia Foundation project. == History == [[mw:Manual:MediaWiki architecture#Magic words and templates|Sordid history]]. [[mw:Help:Extension:ParserFunctions|ParserFunctions]], [[mw:Extension:Lua|Lua extension]], wiki scripting language debated (JavaScript v. Lua), [[mw:Extension:WikiScripts]], Tim writes [[mw:Extension:Scribunto|Scribunto]] with initial support for Lua. Discussed for years, Lua was installed in 2012 for testing on [[test2wiki:|test2.wikipedia.org]], with open invitation to all editors to experiment with developing Lua modules. Lua was installed on the English Wikipedia in February 2013, after testing on mediawiki.org and Wikimedia test wikis. == About Lua == :''See also [[:File:WMF Tech Talk 2013-02-28 slides - Scribunto presentation.pdf|Brad Jorsch's short presentation for a basic example of how to convert a wikitext template into a Lua module.]]'' Lua is a scripting language which can be used to analyze data, calculate expressions, and format results using functions or object-oriented programming. Although some Lua scripts can be kept simple, for easy understanding, Lua allows complex structures including tables, dynamic functions, and associative arrays where index subscripts can be words as well as index numbers. Lua also supports recursion of re-nested functions, so care should be taken to avoid excessive complexity where other users would not understand how to maintain a Lua module. The following is an example of Lua source code for the <code>hello</code> function contained in [[Modul:Bananas]]: <syntaxhighlight lang="lua" line highlight=3> --[[Modul:Bananas]]-- local p = {} -- tabel modul nu diperlukeun, diinisialisasi minangka tabel kosong function p.hello() -- Nangtukeun fungsi hello. return "Hello, world!" -- Mulangkeun hasil fungsi dina wangun string. end -- Ahir fungsi. return p -- Mulangkeun tabel modul. </syntaxhighlight> A sample of Lua is highlighted by tag <code><nowiki><syntaxhighlight lang="lua" line highlight=1 copy> ... </syntaxhighlight></nowiki></code> placed around the Lua source code. For instructions on how to use Lua within MediaWiki (and hence Wikipedia), see [[mw:Extension:Scribunto/Lua reference manual]]. == Unit testing == A unit testing framework for Lua scripts on Wikipedia is available at [[Modul:ScribuntoUnit]].<br /> It allows you to execute your script on a given set of inputs and verify that the expected outputs are produced.<br /> Unit tests are especially useful for rapidly detecting regressions, where modifications to a script introduce new problems. By convention, unit tests for a module like [[Modul:Bananas]] are placed in <syntaxhighlight lang="lua" inline>Modul:</syntaxhighlight> <code>Bananas</code>'''<code>/testcases</code>'''.<br /> They are executed on [[Pembicaraan Modul:Bananas/testcases]] with <syntaxhighlight lang="lua" inline>{{#invoke:Bananas/testcases|</syntaxhighlight>'''<code>run</code>'''<syntaxhighlight lang="lua" inline>}}</syntaxhighlight>. Dina kaca pamaké anjeun: <blockquote><syntaxhighlight lang="wikitext" line highlight=1 copy> {{#invoke:Bananas/testcases|run}} </syntaxhighlight></blockquote> <blockquote> {{#invoke:Bananas/testcases|run}} </blockquote> Each test method must begin with <syntaxhighlight lang="lua" inline>p:</syntaxhighlight>'''<code>test_</code>'''. An example from [[Modul:Bananas/testcases]] is below. <syntaxhighlight lang="lua" line highlight=4 copy> --[[Modul:Bananas/testcases]]-- local p = require('Modul:ScribuntoUnit').new() local modCau = require('Modul:Bananas') -- Didatangan kaca obrolan pikeun ngajalankeun tés. function p:test_halo() -- Tés unit pikeun [[Modul:Bananas]]. self:assertEquals('Hello, world!', modCau.hello()) end return p </syntaxhighlight> {{collapse top|title=Prinsip uji hijian}} Di konsol debug [[modul:Yesno]]: <blockquote><syntaxhighlight lang="lua" line highlight=10 copy> local self = { assertEquals = function(_, wikitext, expected) local got = mw.getCurrentFrame():preprocess(wikitext) print('"' .. expected .. '": Diarepkeun') print('"' .. got .. '": Saleresna') return got == expected end } -- Pamisah `:` tanpa `self` print(self:assertEquals( '{{#invoke:Bananas|hello}}', 'Hello, world!')) -- Pamisah `.` jeung `self` print(self.assertEquals(self, '{{#invoke:Bananas|hello}}', 'Hello, world!')) </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="lua" line start=13> "Hello, world!": Diarepkeun "Hello, world!": Sakuduna true "Hello, world!": Diarepkeun "Hello, world!": Sakuduna true </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="lua" line highlight=2 copy> local modTest = require('Modul:Bananas/testcases') print(modTest.run(mw.getCurrentFrame())) </syntaxhighlight></blockquote> Lamun tésna hasil, nilai anu diarepkeun jeung nilai sabenerna teu dipintonkeun supaya tabel hasil jadi leuwih basajan: <blockquote><syntaxhighlight lang="lua" line start=3> [[File:Yes check.svg|20px|alt=Ya|link=]]<span style="display:none">Y</span> Sakabéh tés lulus. {| class="wikitable scribunto-test-table" ! ! Ngaran ! Diarepkeun ! Saleresna |- | [[File:Yes check.svg|20px|alt=Ya|link=]]<span style="display:none">Y</span> | test_halo | | |} </syntaxhighlight></blockquote> Ngajalankeun [[Modul:ScribuntoUnit]] langsung dina [[Modul:Bananas]] tanpa nyimpen [[Modul:Bananas/testcases]]: <blockquote><syntaxhighlight lang="lua" line highlight=1,3 copy> local modTest = require('Modul:ScribuntoUnit').new() local modCau = require('Modul:Bananas') function modTest:test_halo() self:assertEquals('Hello, world!', modCau.hello()) end print(modTest.run(mw.getCurrentFrame())) </syntaxhighlight></blockquote> HTML anu dihasilkeun sarua. {{collapse bottom}} [[Modul:ScribuntoUnit]] originates from Hungarian Wikipedia.<br /> It throws real errors that are trapped using protected calls. It also has a method to compare floats within a given precision. Pikeun daptar sakabéh modul nu ngagunakeun tés unit, tingali [[Husus:NumbuKaDieu/Modul:ScribuntoUnit|nu dipaké]]. == Wikipedia-specific features == Overall: Lua can only get input as text strings passed to the <code><nowiki>{{#invoke:}}</nowiki></code> and what can be fetched via <code>[[mw:Extension:Scribunto/Lua reference manual#mw.title.new|mw.title.new(...)]]:getContent()</code> and <code>[[mw:Extension:Scribunto/Lua reference manual#frame:expandTemplate|frame:expandTemplate()]]</code>. Lua output will not be preprocessed unless <code>frame:</code>'''<code>[[mw:Extension:Scribunto/Lua reference manual#frame:preprocess|preprocess()]]</code>''' is explicitly called, meaning that template calls and parser functions in the output will not work correctly. Langkung hade ngagunakeun fungsi '''<code>[[mw:Extension:Scribunto/Lua reference manual#mw.ustring.len|mw.ustring.len]]</code>''' tibatan <code>[[mw:Extension:Scribunto/Lua reference manual#string.len|string.len]]</code>: Di konsol debug [[modul:Yesno]]: <blockquote><syntaxhighlight lang="lua" line highlight=2,8 copy> --[[Alfabét Latin]]-- local content_lang = mw.getContentLanguage().code -- su local lang = mw.getCurrentFrame():callParserFunction("#language", content_lang) local lenUnicode, lenByte, lenSharp = mw.ustring.len(lang), string.len(lang), #lang print(("lang: \"%s\". Mw.ustring.len = %d String.len = %d Sharp = %d"):format(lang, lenUnicode, lenByte, lenSharp)) --[[Unicode]]-- lang = "اَكسارا ڤَيڮَون" -- Aksara Pégon lenUnicode, lenByte, lenSharp = mw.ustring.len(lang), string.len(lang), #lang print(("lang: \"%s\". Mw.ustring.len = %d String.len = %d Sharp = %d"):format(lang, lenUnicode, lenByte, lenSharp)) </syntaxhighlight></blockquote> <code>Konsol debug</code> ngarojong Unicode, tapi henteu ngarojong téks katuhu-ka-kenca: <blockquote><syntaxhighlight lang="text" line start=11> lang: "Sunda". Mw.ustring.len = 5 String.len = 5 Sharp = 5 lang: "اَكسارا ڤَيڮَون". Mw.ustring.len = 15 String.len = 29 Sharp = 29 </syntaxhighlight></blockquote> {| class="wikitable" ![[Alfabét Latin]] !Aksara !Arah !Jumlah karakter !Panjang dina bait |- |'''Sunda''' |[[Basa Sunda]]. |→ kenca ka katuhu. |5 |5 |- |[[Hurup Pégon]] |style="direction:rtl; text-align:right;" |'''اَكسارا ڤَيڮَون'''. |← '''Katuhu''' ka kenca |'''15''' ('''[[Unicode]]''') + 1 titik |<span style="color:red;">29</span> + 1 |} {{#invoke:Utf8debug|ek|اَكسارا ڤَيڮَون.}} Lua code in a wiki page is limited to '''10 s'''econds CPU time (you can look in the source code of a rendered page to see how long a template or module took to parse). Relative to standard Lua, Scribunto offers safe functions (see the [[mw:Extension:Scribunto/Lua reference manual#Differences from standard Lua|differences]] from standard Lua). === Lua input limitations === Lua code in Scribunto is only run when the page is being parsed. Therefore, the only user input that Lua can receive is by ''page editing'' - it cannot create a box that calculates the square root of a number you type in, or recalculate a piece of the Mandelbrot set depending on which part of the parent set you click on. The input Lua can receive includes any transcludeable text page on Wikipedia. This does ''not'' include graphics files (not even .SVG files, although they are actually text, unless you cut and paste it onto a Wiki text page), the list of pages listed in a [[:Kategori:Lua-based templates|category]], nor the contents of [[Wikipedia:Transclusion#Special pages|non-transcludeable]] [[Husus:IndeksAwalan/Modul:|special pages]]. === Wikitext === Transcluded Wikipedia headers frequently contain a hidden code such as <syntaxhighlight lang="lua" inline>"UNIQ5ae8f2aa414ff233-h-3--QINU"</syntaxhighlight> which may need to be stripped out in order for them to be parsed effectively. <blockquote><syntaxhighlight lang="lua" line highlight=1 copy> print(string.reverse("UNIQ")) -- Urutan sabalikna tina "UNIQ" nyaéta "QINU" </syntaxhighlight></blockquote> <blockquote><syntaxhighlight lang="lua" line start=2> QINU </syntaxhighlight></blockquote> Wikilinks of the type <code><nowiki>[[Wikipedia:Pitulung</nowiki></code>'''<code><nowiki>|</nowiki></code>'''<code><nowiki>]]</nowiki></code> won't work if returned as output - they need to be written explicitly as <syntaxhighlight lang="lua" inline>[[Wikipedia:Pitulung|</syntaxhighlight>'''<code><nowiki>Pitulung</nowiki></code>'''<syntaxhighlight lang="lua" inline>]]</syntaxhighlight>. Other pre-save transforms, such as replacing <code>~~<nowiki/>~~</code> with signatures, will also fail to be processed. Template transclusions, parser function calls, and variable substitutions (i.e. anything with a <code><nowiki>{{...}}</nowiki></code>) will not be processed, nor will tags such as {{tag|ref|o}} or {{tag|nowiki|o}}. == Labeling converted templates == {{lua|Module:Bananas}} Please place the {{tl|lua}} template on the documentation subpage of all templates that use Lua. It will help to better communicate Lua usage and template conversions. {{clear}} == See also == * [[Husus:IndeksAwalan/Modul:]] daptar modul Lua * [[:Kategori:Lua-based templates]] &ndash; l-groups ta templates based kan Lua ; English Wikipedia-specific resources * [[:mw:Manual:Coding conventions/Lua]] &ndash; standards to improve the readability of code through consistency * [[:en:Help:Lua debugging]] &ndash; a how-to guide about debugging Lua modules * [[:en:Module:Sandbox]] provides a pseudo-namespace for experimenting with Lua modules * [[:en:Wikipedia talk:Lua]] &ndash; requests for Lua-based templates or tasks == Notes == {{reflist}} {{WikiProject Lua/header}} [[Category:Wikipedia modules]] ocra35mep61jr8rfv4ra2hhwa715wrr