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 Citakan:Pulitik Bangladés 10 38987 712200 433725 2026-08-22T13:51:31Z Temporaryaccount69 37304 Koréksi. 712200 wikitext text/x-wiki {{sidebar with collapsible lists | name = Pulitik Bangladés | wraplinks = true | bodyclass = vcard | bodystyle = width:auto | liststyle = text-align:left | title = {{politics sidebar title|country=Bangladés|image=Government Seal of Bangladesh.svg|size=130px|title=Bangladés}} | list1title = Konstitusi | list1 = *[[Undang-Undang Dasar Bangladés|Undang-Undang Dasar]] | list2title = Parlemén | list2 = *[[Jatiyo Sangshad]] **[[Daptar Juru Carios Jatiyo Sangshad|Juru Carios]] *[[Pulitik Bangladés|Pulitik]] **[[Daptar partéy pulitik di Bangladés|Partéy pulitik]] | list3title = [[Hukum Bangladés|Yudikatif]] | list3 = *[[Mahkamah Agung Bangladés|Mahkamah Agung]] *[[Hak asasi manusa di Bangladés|HAM]] | list4title = Éksekutif | list4 = *[[Présidén Bangladés|Présidén]] ([[Daptar Présidén Bangladés|Daptar]]) **[[Abdul Hamid (pulitikus)|Abdul Hamid]] *[[Perdana Mentri Bangladés|Perdana Mentri]] ([[Daptar Perdana Mentri Bangladés|Dapatar]]) **[[Syéikh Hasina]] | list5title = Administratif | list5 = *[[Divisi di Bangladés|Divisi]] *[[distrik di Bangladés|Distrik]] *[[Upazila di Bangladés|Upazila]] | list6title = [[Pamilihan umum di Bangladés|Pamilihan umum]] | list6 = *[[Komisi Pamilihan Umum Bangladés|Komisi Pamilihan Umum]] *[[Pamilihan umum di Bangladés|Pamilihan umum]] **[[Jatiyo Sangshad|Parlemén]]: [[Pamilihan umum Pakistan 1970|1970]],<br> [[Pamilihan umum législatif Bangladés 1973|1973]], [[Pamilihan umum législatif Bangladés 1979|1979]], [[Pamilihan umum législatif Bangladés 1986|1986]],<br> [[Pamilihan umum législatif Bangladés 1988|1988]], [[Pamilihan umum législatif Bangladés 1991|1991]], [[Pamilihan umum législatif Bangladés February 1996|1996]],<br> [[Pamilihan umum législatif Bangladés June 1996|1996]], [[Pamilihan umum législatif Bangladés 2001|2001]], [[Pamilihan umum législatif Bangladés 2008|2008]] **[[Présidén Bangladés|Présidén]]: [[Pamilihan umum Présidén Bangladés 1978|1978]],<br> [[Pamilihan umum Présidén Bangladés 1981|1981]], [[Pamilihan umum Présidén Bangladés 1986|1986]] | list7title = Hubungan luar nagri | list7 = *[[Hubungan luar nagri Bangladés|Hubungan luar nagri]] | below = {{politics sidebar below|Bangladés|countrynorm=Bangladesh}} }}<noinclude> {{clear}} ==Tingali ogé== {{Politics of Asia templates}} [[Category:citakan pulitik dumasar nagara|Banglades]] [[Category:citakan puliik jeung pamaréntahan Bangladés]] </noinclude> tsrsvrbkigs182221y9m7gd1g1gyqw3 Wikipedia:Lua 4 41001 712203 712182 2026-08-22T14:40:23Z Nimmzo 37272 /* Unit testing */ Replaced legacy [[:en:Module:UnitTests]] with more powerful [[Modul:ScribuntoUnit]] 712203 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. == 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]]. {{tl|qif}}, [[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 [[Module:Bananas]] are placed in [[Module:Bananas/testcases]], and are executed on [[Module talk:Bananas/testcases]] with e.g. <code><nowiki>{{#invoke: Bananas/testcases | run_tests}}</nowiki></code>. Test methods must begin with "test". A simple example from [[Module:Bananas/testcases]] is below. <syntaxhighlight lang="lua"> -- Unit tests for [[Module:Bananas]]. Click talk page to run tests. local p = require('Module:UnitTests') function p:test_hello() self:preprocess_equals('{{#invoke:Bananas | hello}}', 'Hello, world!') end return p </syntaxhighlight> [[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. For a list of all modules using unit tests, see [[Special:Whatlinkshere/Module:UnitTests]]. == 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 mw.title.new(...):getContent() and frame:expandTemplate(). Lua output will not be preprocessed unless frame:preprocess() is explicitly called, meaning that template calls, parser functions, etc. in the output will not work correctly. Also, all Lua in the page is limited to 10 seconds CPU time (you can look in the source code of a rendered page to see how long a template or module took to parse). And relative to standard Lua, Scribunto's Lua lacks all sorts of functions (see [[mw:Extension:Scribunto/Lua reference manual#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 [[Wikipedia:SVG help|.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 [[Help:Category|category]], nor the contents of [[Wikipedia:Transclusion#Special pages|non-transcludeable]] [[Help:Special|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]] c842f8znfsy0gx22afsepovda8dp09f 712204 712203 2026-08-22T14:50:14Z Nimmzo 37272 /* Unit testing */ Removed space separator in {{#invoke: Bananas/testcases | run_tests}}. In [[Modul:ScribuntoUnit]], `run_tests` is simplified to `run` 712204 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. == 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]]. {{tl|qif}}, [[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|run}}</syntaxhighlight>. Test methods must begin with "test". A simple example from [[Module:Bananas/testcases]] is below. <syntaxhighlight lang="lua"> -- Unit tests for [[Module:Bananas]]. Click talk page to run tests. local p = require('Module:UnitTests') function p:test_hello() self:preprocess_equals('{{#invoke:Bananas | hello}}', 'Hello, world!') end return p </syntaxhighlight> [[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. For a list of all modules using unit tests, see [[Special:Whatlinkshere/Module:UnitTests]]. == 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 mw.title.new(...):getContent() and frame:expandTemplate(). Lua output will not be preprocessed unless frame:preprocess() is explicitly called, meaning that template calls, parser functions, etc. in the output will not work correctly. Also, all Lua in the page is limited to 10 seconds CPU time (you can look in the source code of a rendered page to see how long a template or module took to parse). And relative to standard Lua, Scribunto's Lua lacks all sorts of functions (see [[mw:Extension:Scribunto/Lua reference manual#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 [[Wikipedia:SVG help|.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 [[Help:Category|category]], nor the contents of [[Wikipedia:Transclusion#Special pages|non-transcludeable]] [[Help:Special|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]] 5vj32d4din3znvj5qovs6hg9bhfrjbi 712205 712204 2026-08-22T15:00:15Z Nimmzo 37272 /* Unit testing */ Highlighted the key information 712205 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. == 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]]. {{tl|qif}}, [[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>. Each test method must begin with <syntaxhighlight lang="lua" inline>p:</syntaxhighlight>'''<code>test_</code>'''. A simple example from [[Modul:Bananas/testcases]] is below. <syntaxhighlight lang="lua"> -- Unit tests for [[Module:Bananas]]. Click talk page to run tests. local p = require('Module:UnitTests') function p:test_hello() self:preprocess_equals('{{#invoke:Bananas | hello}}', 'Hello, world!') end return p </syntaxhighlight> [[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. For a list of all modules using unit tests, see [[Special:Whatlinkshere/Module:UnitTests]]. == 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 mw.title.new(...):getContent() and frame:expandTemplate(). Lua output will not be preprocessed unless frame:preprocess() is explicitly called, meaning that template calls, parser functions, etc. in the output will not work correctly. Also, all Lua in the page is limited to 10 seconds CPU time (you can look in the source code of a rendered page to see how long a template or module took to parse). And relative to standard Lua, Scribunto's Lua lacks all sorts of functions (see [[mw:Extension:Scribunto/Lua reference manual#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 [[Wikipedia:SVG help|.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 [[Help:Category|category]], nor the contents of [[Wikipedia:Transclusion#Special pages|non-transcludeable]] [[Help:Special|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]] 85gahbyet0lm44mv92edu5ksjyyl2fr 712206 712205 2026-08-22T15:10:20Z Nimmzo 37272 /* Unit testing */ After `p:test_`, the name of the function of test is free: `p:test_halo()` does not need to match the English name of the function to be tested: `hello`. You are also free to name the `local modCau` as you want. 712206 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. == 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]]. {{tl|qif}}, [[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>. 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> [[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. For a list of all modules using unit tests, see [[Special:Whatlinkshere/Module:UnitTests]]. == 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 mw.title.new(...):getContent() and frame:expandTemplate(). Lua output will not be preprocessed unless frame:preprocess() is explicitly called, meaning that template calls, parser functions, etc. in the output will not work correctly. Also, all Lua in the page is limited to 10 seconds CPU time (you can look in the source code of a rendered page to see how long a template or module took to parse). And relative to standard Lua, Scribunto's Lua lacks all sorts of functions (see [[mw:Extension:Scribunto/Lua reference manual#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 [[Wikipedia:SVG help|.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 [[Help:Category|category]], nor the contents of [[Wikipedia:Transclusion#Special pages|non-transcludeable]] [[Help:Special|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]] f1uws0lz1b5ortxekc3acsl2ifhmabn 712207 712206 2026-08-22T15:20:38Z Nimmzo 37272 /* Unit testing */ Introducing [[Modul:ScribuntoUnit]]. If it works in your user page, it should work elsewhere. Lamun tésna hasil, nilai anu diarepkeun jeung nilai sabenerna teu dipintonkeun supaya tabel hasil jadi leuwih basajan. To localize the unit test framework, edit [[Modul:ScribuntoUnit/config]] 712207 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. == 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]]. {{tl|qif}}, [[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> [[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. For a list of all modules using unit tests, see [[Special:Whatlinkshere/Module:UnitTests]]. == 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 mw.title.new(...):getContent() and frame:expandTemplate(). Lua output will not be preprocessed unless frame:preprocess() is explicitly called, meaning that template calls, parser functions, etc. in the output will not work correctly. Also, all Lua in the page is limited to 10 seconds CPU time (you can look in the source code of a rendered page to see how long a template or module took to parse). And relative to standard Lua, Scribunto's Lua lacks all sorts of functions (see [[mw:Extension:Scribunto/Lua reference manual#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 [[Wikipedia:SVG help|.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 [[Help:Category|category]], nor the contents of [[Wikipedia:Transclusion#Special pages|non-transcludeable]] [[Help:Special|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]] 7u042ctdewjlw1puo7cd8ie3cj0itlj 712208 712207 2026-08-22T15:30:25Z Nimmzo 37272 /* Unit testing */ Added [[Husus:NumbuKaDieu/Modul:ScribuntoUnit]] 712208 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. == 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]]. {{tl|qif}}, [[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> [[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 mw.title.new(...):getContent() and frame:expandTemplate(). Lua output will not be preprocessed unless frame:preprocess() is explicitly called, meaning that template calls, parser functions, etc. in the output will not work correctly. Also, all Lua in the page is limited to 10 seconds CPU time (you can look in the source code of a rendered page to see how long a template or module took to parse). And relative to standard Lua, Scribunto's Lua lacks all sorts of functions (see [[mw:Extension:Scribunto/Lua reference manual#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 [[Wikipedia:SVG help|.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 [[Help:Category|category]], nor the contents of [[Wikipedia:Transclusion#Special pages|non-transcludeable]] [[Help:Special|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]] 11b53zhnlp7fiqvgv879qtbj7axpmod Saléndro 0 106269 712209 676906 2026-08-22T20:17:38Z Kavlyco 27228 712209 wikitext text/x-wiki [[Gambar:Slendro_on_C.png|jmpl|400x400px|Notasi Kulon kanggo nyeratkeun jangkahna laras Saléndro. Angka di handapeunnana make Kepatihan anu dipaké dina karawitan Jawa, lain Sunda{{Audio|Slendro on C.mid|Play}}]] [[Gambar:Slendro_vs_whole_tone_scale_on_C.png|ka|jmpl|350x350px| ''Laras Saléndro Jawar (dina gamelan Jawa)'' dibandingkeun jeung [[Whole tone scale|''whole tone scale'']], dina C {{Audio|Slendro vs whole tone scale on C.mid|Play both}} atawa {{Audio|5-tet scale on C.mid|Play equal-tempered scale}} .]] '''Saléndro, sléndro''' atawa '''salindru''' mangrupa salasahiji tina dua laras anu dipaké dina waditra sarupaning [[gamelan]] Jawa. [[Laras]] ieu ogé dipaké dina rupa-rupa [[waditra]] jeung [[karawitan]] Sunda, contona dina kacapi, rebab, atwa gamelan nu dipaké dina [[wayang]], [[jaipongan]], jsb. Laras ieu leuwih babari diajarna tibatan laras pélog atawa laras séjénna, ku sabab ieu ngan ukur lima genta atawa [[nada]] nu deukeut jarakna tur ampir rata dina hiji [[gembyang]]. [[Gambar:Suling lubang enam laras Salendro koleksi jurusan Karawitan ISBI Bandung.webm|jmpl|Suling genep liang, laras saléndro]] Numutkeun mitologi [[Pulo Jawa|Jawa]], gamelan Saléndro leuwih kolot ti batan gamelan Pélog. Dina titi laras Sunda, Saléndro miboga 5 (lima) genta sagembyang, nyaéta 1 2 3 4 5 (G E+ D C A+) kalayan jangkah anu sarua atawa lamun béda ogé, bédana jangkahna leutik. Aya dua laras saléndro nu lumrah dipaké, nyaéta laras saléndro padantara jeung saléndro bédantara. Saléndro padantara nyaéta laras anu dijieun tina ngabagi hiji gembyang jadi 5. Sagembyang eusina 1200 cents, anu bakal dibagi jadi 5, hasilna 240 cents jarak jangkahna unggal gentana. Dina prakna, saléndro padantara henteu pas 240 cents, bisa leuwih atawa kurang.<ref>{{Cite book|title=Guide to Sundanese Music: a Practical Introduction to Gamelan Saleńdro/pelog, Gamelan Degung, Panambih Tembang Sunda|url=https://books.google.co.id/books/about/Guide_to_Sundanese_Music_a_Practical_Int.html?id=npajzQEACAAJ&redir_esc=y|publisher=Simon Cook|date=1992|language=en|first=Simon|last=Cook}}</ref> Laras saléndro nu kadua nyaéta saléndro bédantara. Laras nu ieu miboga jangkah nu teu rata. Di jaman kiwari, laras ieu mindeng dipake dina sagala rupa waditra kulon, sarupaning gitar, atawa piano. Laras ieu leuwih babari dipaké dina waditra kulon ku sabab bisa dipake dina waditra nu maké 12ED (12 ''Equal Division'') anu matak teu kudu bener-bener ngabagi sagembyang jadi 5 nada. Lian ti dinya, aya ogé sistem ngabagi sagembyang jadi 17 nada<ref name=":0">{{Cite book|title=Ringkesan pangawikan rinenggaswara: ringkesan elmuning kanajagan|url=https://books.google.co.id/books/about/Ringkesan_pangawikan_rinenggaswara.html?id=MC4YNQAACAAJ&redir_esc=y|publisher=Noord-hoff-Kolff|date=1989|language=jw|first=Machjar Angga|last=Kusumadinata (Raden.)}}</ref>, atawa 17ED (17 ''Equal Division'') anu diserat ku Raden Machjar Angga Koesoemadinata dina buku Ringkesan Pangawikan Rinenggaswara. {| class="wikitable" |+Ngaran Nada ! rowspan="2" |Notasi Daminatila ! colspan="2" |Ngaran Sunda ! rowspan="2" |Notasi Kepatihan ! colspan="4" | Ngaran Jawa |- !Ngaran Seratan !Ngaran Buhun ! Ngaran Seratan ! Ngaran Pondok ! Ngaran Buhun ! Hartina |- |1 |da |tugu, barang | 6 | enem | nem | nem | genep |- |2 |mi |kenong, loloran | 5 | lima | ma | lima | leungeun, lima |- |3 |na |panelu | 3 |telu | lu | dhadha | dada |- |4 |ti |galimer, bem | 2 | loro | ro | gulu | sirah |- |5 |la |singgul | 1 | siji | ji | barang | barang |} <references />{{Gamelan}}{{Authority control}} [[Kategori:Gamelan]] [[Kategori:Laras]] [[Kategori:Karawitan]] q9bpnstctpg9ixe1zzkgd6xk4c8g0ic Modul:ScribuntoUnit/config 828 108828 712199 712198 2026-08-22T13:30:10Z Nimmzo 37272 localized. About `{{PLURAL:$1|tés|tés}}`, "tés" (singular of test ) is equal to "tés" (plural of tests) 712199 Scribunto text/plain -- Tabel cfg, dijieun ku modul ieu, ngamuat sakabéh string jeung konfigurasi nu bisa dilokalisasi, -- sangkan leuwih gampang pikeun mindahkeun modul ieu ka wiki séjén. local cfg = {} -- Ulah ngédit baris ieu. -- successIndicator jeung failureIndicator aya dina kolom kahiji -- tina wikitable nu dihasilkeun salaku kaluaran jeung nuduhkeun naha tés lulus. -- Dua string ieu diprosés heula ku frame.preprocess. -- successIndicator: lamun tés lulus -- failureIndicator: lamun tés gagal cfg.successIndicator = "{{tick}}" cfg.failureIndicator = "{{cross}}" -- Judul kolom: cfg.nameString = "Ngaran" cfg.expectedString = "Diarepkeun" cfg.actualString = "Saleresna" -- String di luhur nu dipaké pikeun nuduhkeun yén sakabéh tés geus lulus. cfg.successSummary = "Sakabéh tés lulus." -- String di luhur nu dipaké pikeun nuduhkeun yén hiji atawa leuwih tés gagal. -- $1 diganti ku jumlah tés nu gagal. -- String ieu diprosés heula ku frame.preprocess. cfg.failureSummary = "'''$1 {{PLURAL:$1|tés|tés}} gagal'''." -- String format pikeun tampilan pondok tina tés dina displayResultsAsShort. -- String format ieu dipasrahkeun langsung ka string.format. cfg.shortResultsFormat = "hasil: %d, kasalahan: %d, diliwatan: %d" -- Kategori anu ditambahkeun ka kaca nu gagal hiji atawa leuwih tés. -- Setel jadi nil pikeun mareuman kategorizasi kaca nu gagal hiji atawa leuwih tés. cfg.failureCategory = "[[Kategori:Tés Lua gagal ngagunakeun Modul:ScribuntoUnit]]" -- Ahirna, balikkeun tabel konfigurasi. return cfg -- Ulah ngédit baris ieu. i59arhk9okrh2xaj91f3if4dt0fscgn Modul:Bananas/testcases 828 108829 712201 2026-08-22T14:00:09Z Nimmzo 37272 Running unit test framework [[Modul:ScribuntoUnit]] on [[Modul:Bananas]]. Define the function p:test_halo() 712201 Scribunto text/plain --[[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 guo5wqt63sygeiwsnk1r8sadxdbvu60 Pembicaraan Modul:Bananas/testcases 829 108830 712202 2026-08-22T14:30:08Z Nimmzo 37272 Added Sawala (Sundanese), Talk (English), and Pembicaraan (Indonesian): Start a discussion about the unit test campaign for [[Modul:Bananas]] 712202 wikitext text/x-wiki {{#invoke:Bananas/testcases|run}} 6imb3c7inf1g3mtn31coeu6900grdah