ৱিকিপিডিয়া:লুৱা
এইখন এখন তথ্য পৃষ্ঠা, ইয়াত ৱিকিপিডিয়া ব্যৱহাৰ আৰু অৰ্হতা সমন্ধীয় কিছু সমজুৱা তথ্য বৰ্ণনা কৰা হৈছে। যিহেতু ই নিজে কোনো নীতি আৰু নিৰ্দেশনা নহয়, সেয়ে অন্য ৱিকিপিডিয়া নীতি আৰু নিয়মসমূহৰ জৰিয়তে নিশ্চিত হবলৈ উপদেশ দিয়া হ'ল। যদি অন্য কোনো নীতি সম্পৰ্কীয় পৃষ্ঠাৰ লগত এই পৃষ্ঠাৰ অমিল দেখা পাইছে, তেন্তে অনুগ্ৰহ কৰি আমাক অৱগত কৰাওক। |
বিষয় নামস্থানসমূহ | বাৰ্তা নামস্থানসমূহ | ||
---|---|---|---|
0 | (মূল/প্ৰবন্ধ) | বাৰ্তা | 1 |
2 | সদস্য | সদস্য বাৰ্তা | 3 |
4 | ৱিকিপিডিয়া | ৱিকিপিডিয়া বাৰ্তা | 5 |
6 | চিত্ৰ | চিত্ৰ বাৰ্তা | 7 |
8 | মিডিয়াৱিকি | মিডিয়াৱিকি আলোচনা | 9 |
10 | সাঁচ | সাঁচ বাৰ্তা | 11 |
12 | সহায় | সহায় বাৰ্তা | 13 |
14 | শ্ৰেণী | শ্ৰেণী বাৰ্তা | 15 |
100 | ৱিকিচ'ৰা | ৱিকিচ'ৰা আলোচনা | 101 |
828 | Module | Module talk | 829 |
2300 | [[ৱিকিপিডিয়া:গেজেট|]] | 2301 | |
2302 | [[ৱিকিপিডিয়া:গেজেট|]] | 2303 | |
-1 | বিশেষ | ||
-2 | মাধ্যম |
Lua is a programming language that is now available via the Scribunto MediaWiki extension on the English Wikipedia. Lua code can now be embedded into wiki templates by employing the "{{#invoke:}}" functionality of Scribunto. This extension supports Lua 5.1 জুলাই 2015 অনুসৰি[update].
The Lua source code is stored in pages called modules (e.g., Module:Bananas). These individual modules are then invoked (by code {{#invoke:}}
) on template pages (e.g. Module:Bananas/doc uses the code {{#invoke:Bananas|hello}}
to print the text "Hello, world!").
Running a module
[সম্পাদনা কৰক]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.[1] 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.
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.
The simplest way to run a module from a wiki page is like this:
{{#invoke:module name|function name}}
For example, we can run Module:Bananas in this way, which has one function named "hello".
{{#invoke:Bananas|hello}}
→ Script error: No such module "Bananas".
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 is always the function name; the first positional argument is the text after the second pipe.
{{#invoke:module name|function name|first positional argument|second positional argument|named argument = value}}
For example, in Module:BananasArgs, the "hello" function greets different people depending on the first positional argument. It works like this:
{{#invoke:BananasArgs|hello|Kate}}
→ Script error: No such module "BananasArgs".{{#invoke:BananasArgs|hello|Fred}}
→ Script error: No such module "BananasArgs".
BananasArgs also has a function named "count_fruit" which uses the named arguments bananas
and apples
to count the number of bananas and apples we have. It can be run like this:
{{#invoke:BananasArgs|count_fruit|apples=3|bananas=4}}
→ Script error: No such module "BananasArgs".{{#invoke:BananasArgs|count_fruit|bananas=5|apples=2}}
→ Script error: No such module "BananasArgs".
Most modules will have a documentation page explaining what arguments can be used and what their effects will be.
Example modules
[সম্পাদনা কৰক]- Module:Bananas: The simplest possible script, providing a single function with no arguments.
- Module:Basic example: Demonstrates how to use conditions and template parameters.
- Module:BananasArgs: Demonstrates how to access and use parameters.
Request a script
[সম্পাদনা কৰক]Visit Wikipedia:Lua requests to request help in writing a Lua script to perform a specific task on Wikipedia or another Wikimedia Foundation project.
History
[সম্পাদনা কৰক]Sordid history. {{qif}}, ParserFunctions, Lua extension, wiki scripting language debated (JavaScript v. Lua), mw:Extension:WikiScripts, Tim writes Scribunto with initial support for Lua.
Discussed for years, Lua was installed in 2012 for testing on 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
[সম্পাদনা কৰক]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 a hello world function contained in Module:HelloWorld:
[[:Module:HelloWorld]]
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)".
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 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 (or old) 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. {{#invoke: Bananas/testcases | run_tests}}
. Test methods must begin with "test". A simple example from Module:Bananas/testcases is below.
-- 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
For a list of all modules using unit tests, see Special:Whatlinkshere/Module:UnitTests.
There's also an alternative unit testing framework 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.
Wikipedia-specific features
[সম্পাদনা কৰক]Overall: Lua can only get input as text strings passed to the {{#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 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 .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 category, nor the contents of non-transcludeable special pages.
Wikitext
[সম্পাদনা কৰক]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.
Wikilinks using the Pipe trick [[Wikipedia:Help|]] won't work if returned as output - they need to be written explicitly as [[Wikipedia:Help|Help]] Other pre-save transforms, such as replacing ~~~~ with signatures, will also fail to be processed. Template transclusions, parser function calls, and variable substitutions (i.e. anything with a {{...}}
) will not be processed, nor will tags such as <ref></ref>
or <nowiki></nowiki>
.
Labeling converted templates
[সম্পাদনা কৰক]এই সাঁচে লুৱা ব্যৱহাৰ কৰে: |
Please place the {{lua}} template on the documentation subpage of all templates that use Lua. It will help to better communicate Lua usage and template conversions.
See also
[সম্পাদনা কৰক]- English Wikipedia-specific resources
- Special:PrefixIndex/Module: – tracking of Lua modules can be done by using Special:PrefixIndex
- Help:Lua debugging – a how-to guide about debugging Lua modules
- Module:Sandbox provides a pseudo-namespace for experimenting with Lua modules
- WP:Lua requests – requests for Lua-based templates or tasks
- Category:Lua-based templates – groups of Lua-based templates
- Category:Lua metamodules –
- MediaWiki Lua documentation
- Manual:Coding conventions/Lua – standards to improve the readability of code through consistency
- mw:Extension:Scribunto/Lua reference manual
Notes
[সম্পাদনা কৰক]- ↑ You can also have multiple output values, but functions that do this are not normally meant to be accessed from wiki pages.