This HTML5 document contains 14 embedded RDF statements represented using HTML+Microdata notation.

The embedded RDF content will be recognized by any processor of HTML5 Microdata.

PrefixNamespace IRI
n13http://dbkwik.webdatacommons.org/resource/ysvqf3cgakGCvRh_6rWSRg==
n11http://dbkwik.webdatacommons.org/resource/RRY6-kal9u_M8rg9du46IQ==
n15http://dbkwik.webdatacommons.org/ontology/
dctermshttp://purl.org/dc/terms/
n9http://dbkwik.webdatacommons.org/resource/1gIiz5J7w1EnTAy-jYeJGg==
n3http://dbkwik.webdatacommons.org/jaz/property/
n17http://dbkwik.webdatacommons.org/resource/xfBm26_nJNmBCgdi7qzAlQ==
n4http://dbkwik.webdatacommons.org/resource/wyZD0wBkHipknMBC7s5uyw==
n10http://dbkwik.webdatacommons.org/resource/JJn9qIeZW7UCno3mUrljxg==
rdfshttp://www.w3.org/2000/01/rdf-schema#
n2http://dbkwik.webdatacommons.org/resource/nK9MPmat--EHLIS9w4tPgQ==
n12http://dbkwik.webdatacommons.org/resource/rOpwFp5c8sE0EFCCmG9ejA==
n7http://dbkwik.webdatacommons.org/resource/mhnRJextRALbHuub6RV66Q==
n8http://dbkwik.webdatacommons.org/resource/IQr3kTBoEHbqsFq7E8Yj9w==
rdfhttp://www.w3.org/1999/02/22-rdf-syntax-ns#
n14http://dbkwik.webdatacommons.org/resource/Vw52zlHyra_wb0PhSTvc3w==
xsdhhttp://www.w3.org/2001/XMLSchema#
n16http://dbkwik.webdatacommons.org/resource/3-IBky-LVWuF__SG4dyAFQ==
Subject Item
n2:
rdfs:label
Lua (programming language)
rdfs:comment
{{WikiProject Lua/header}} {{Information page|WP:Lua}} {{Namespaces}} [[Lua (programming language)|Lua]] is a programming language that is now available, via the [[mw:Extension:Scribunto|Scribunto]] MediaWiki extension, on the English Wikipedia. Lua code can now be embedded into wiki templates by employing the "{{#invoke:}}" functionality of the Scribunto MediaWiki extension.
dcterms:subject
n7:
n3:wikiPageUsesTemplate
n4: n8: n9: n10: n11: n12: n13: n14: n16: n17:
n15:abstract
{{WikiProject Lua/header}} {{Information page|WP:Lua}} {{Namespaces}} [[Lua (programming language)|Lua]] is a programming language that is now available, via the [[mw:Extension:Scribunto|Scribunto]] MediaWiki extension, on the English Wikipedia. Lua code can now be embedded into wiki templates by employing the "{{#invoke:}}" functionality of the Scribunto MediaWiki extension. The Lua [[source code]] is stored in pages called modules (e.g., [[Module:Bananas]]). These individual modules are then invoked (by code <nowiki> {{#invoke:}}) on template pages (e.g., [[Module:Bananas/doc]] uses the code <code> <nowiki> {{#invoke:Bananas|hello}} to print the text "Hello, world!"). </nowiki></code> </nowiki> <code> <p> == Running a module ==</p> <p> Modules are run on normal wiki pages using the #invoke parser function. The syntax of #invoke 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 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. However, you can define many functions in one Lua module, whereas you can only define one template on one page.</p> <p> 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, and without specifying a function name, Lua will not know which function it is we want to run.</p> <p> The simplest way to run a module from a wiki page is like this:</p> <p> {{#invoke:''module name''|''function name''}}</p> <p> For example, we can run [[Module:Bananas]] in this way, which has one function named "hello". </p> <ul> <li> <code> <nowiki> {{#invoke:Bananas|hello}} → </nowiki></code></li> </ul><code> <p> === Using arguments ===</p> <p> 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 is always the function name; the first positional argument is the text after the ''second'' pipe.</p> <p> {{#invoke:''module name''|''function name''|''first positional argument''|''second positional argument''|''named argument'' = ''value''}}</p> <p> For example, in [[Module:BananasArgs]], the "hello" function greets different people depending on the first positional argument. It works like this:</p> <ul> <li> <code> <nowiki> {{#invoke:BananasArgs|hello|Kate}} → </nowiki></code></li> </ul><code> <ul> <li> <code> <nowiki> {{#invoke:BananasArgs|hello|Fred}} → </nowiki></code></li> </ul><code> <p> BananasArgs also has a function named "count_fruit" 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 like this:</p> <ul> <li> <code> <nowiki> {{#invoke:BananasArgs|count_fruit|apples=3|bananas=4}} → </nowiki></code></li> </ul><code> <ul> <li> <code> <nowiki> {{#invoke:BananasArgs|count_fruit|bananas=5|apples=2}} → </nowiki></code></li> </ul><code> <p> Most modules will have a documentation page explaining what arguments can be used and what their effects will be.</p> <p> == Example modules ==</p> <p> * [[Module:Bananas]]: The simplest possible script, providing a single function with no arguments.</p> <p> * [[Module:BananasArgs]]: Demonstrates how to access and use parameters.</p> <p> == Request a script ==</p> <p> Visit '''[[Wikipedia:Lua requests]]''' to request help in writing a Lua script to perform a specific task on Wikipedia or another Wikimedia Foundation project.</p> <p> == History ==</p> <p> [[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.</p> <p> 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.</p> <p> == About Lua ==</p> <p> :''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.]]''</p> <p> 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 array]]s where index [[subscript]]s 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 a [[hello world]] function contained in [[Module:HelloWorld]]:</p> <p> <syntaxhighlight lang="lua"></syntaxhighlight></p> <p> -- All Lua modules on Wikipedia must begin by defining a variable that will hold their</p> <p> -- externally accessible functions. They can have any name and may also hold data.</p> <p> my_object = {}</p> <p> -- Add a function to the variable. These are callable in Wikipedia via the #invoke command.</p> <p> -- "frame" will contain the data that Wikipedia sends this function when it is called. </p> <p> my_object.hello = function( frame ) </p> <p> -- Declare a local variable and assign data to it.</p> <p> local str = "Hello World!" </p> <p> -- Quit this function and send the information in "str" back to Wikipedia.</p> <p> -- The "print" function is not allowed, so all output is accomplished via </p> <p> -- returning strings in this fashion.</p> <p> return str </p> <p> -- End the function.</p> <p> end</p> <p> -- All modules end by returning the variable containing its functions to Wikipedia.</p> <p> return my_object</p> <p> -- We can now use this module by calling {{#invoke: HelloWorld | hello }}.</p> <p> -- The #invoke command begins with the module's name, in this case "HelloWorld",</p> <p> -- then takes the name of one of its functions as an argument, in this case "hello".</p> <p> </p> <p> A sample of Lua is highlighted by tag "<source lang="lua">...</source>" placed around the Lua source code. To view some more complex examples of Lua, see article: "[[Lua (programming language)]]".</p> <p> For instructions on how to use Lua within MediaWiki (and hence Wikipedia), see [[mw:Extension:Scribunto/Lua reference manual]].</p> <p> == Unit testing ==</p> <p> A unit testing framework for Lua scripts on Wikipedia is available at [[Module:UnitTests]]. It allows you to execute your script on a given set of inputs and verify that the expected outputs are produced. Unit tests are especially useful for rapidly detecting regressions, where modifications to a script introduce new problems.</p> <p> 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}}. Test methods must begin with "test". A simple example from [[Module:Bananas/testcases]] is below. </nowiki></code></p><code> <p> <syntaxhighlight lang="lua"></syntaxhighlight></p> <p> -- Unit tests for [[Module:Bananas]]. Click talk page to run tests.</p> <p> local p = require('Module:UnitTests')</p> <p> function p:test_hello()</p> <p> self:preprocess_equals('{{#invoke:Bananas | hello}}', 'Hello, world!')</p> <p> end</p> <p> return p</p> <p> </p> <p> For a list of all modules using unit tests, see [[Special:Whatlinkshere/Module:UnitTests]]. </p> <p> There's also an alternative unit testing framework [[Special:Whatlinkshere/Module:ScribuntoUnit|in use]] called [[Module:ScribuntoUnit]], that originates from Hungarian Wikipedia. Feature-wise it's very similar to [[Module:UnitTests]], but it has a different coding style, and throws real errors that are trapped using protected calls. It also has a method to compare floats within a given precision.</p> <p> == Wikipedia-specific features ==</p> <p> Overall: Lua can only get input as text strings passed to the <code> <nowiki> {{#invoke:}} 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 {{section link|mw:Extension:Scribunto/Lua reference manual|Differences from standard Lua}}). </nowiki></code></p><code> <p> === Lua input limitations ===</p> <p> 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]].</p> <p> === Wikitext ===</p> <p> Transcluded Wikipedia headers frequently contain a hidden code such as "UNIQ5ae8f2aa414ff233-h-3--QINU" which may need to be stripped out in order for them to be parsed effectively.</p> <p> Wikilinks of the type ''' <nowiki> [[Wikipedia:Help|]] <b> won't work if returned as output - they need to be written explicitly as </b>[[Wikipedia:Help|Help]] <b>. Other pre-save transforms, such as replacing <code>~~~~</code> with signatures, will also fail to be processed. Template transclusions, parser function calls, and variable substitutions (i.e. anything with a <code>{{...}}</code>) will not be processed, nor will tags such as <code style="white-space:nowrap;"> <ref></ref></code> or <code style="white-space:nowrap;"> <nowiki></nowiki></code>.</b> </nowiki></p> <p> == Labeling converted templates ==</p> <p> {{lua|Module:Bananas}}</p> <p> 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.</p> <p> {{clear}}</p> <p> == See also ==</p> <p> ; English Wikipedia-specific resources</p> <p> * [[Wikipedia:Lua style guide]] – standards to improve the readability of code through consistency</p> <p> * [[Special:PrefixIndex/Module:]] – tracking of Lua modules can be done by using [[Special:PrefixIndex]]</p> <p> * [[Help:Lua debugging]] – a how-to guide about [[debugging]] Lua modules</p> <p> * [[Module:Sandbox]] provides a pseudo-namespace for experimenting with Lua modules</p> <p> * [[WP:Lua requests]] – requests for Lua-based templates or tasks</p> <p> * [[:Category:Lua-based templates]] – groups of Lua-based templates</p> <p> * [[:Category:Lua metamodules]] –</p> <p> == Notes ==</p> <p> {{reflist}}</p> <p> {{Wikipedia technical help|collapsed}}</p> <p> [[Category:Wikipedia modules]]</p></code></code></code></code></code></code></code></code>