විකිපීඩියා
siwiki
https://si.wikipedia.org/wiki/%E0%B6%B8%E0%B7%94%E0%B6%BD%E0%B7%8A_%E0%B6%B4%E0%B7%92%E0%B6%A7%E0%B7%94%E0%B7%80
MediaWiki 1.47.0-wmf.2
first-letter
මාධ්යය
විශේෂ
සාකච්ඡාව
පරිශීලක
පරිශීලක සාකච්ඡාව
විකිපීඩියා
විකිපීඩියා සාකච්ඡාව
ගොනුව
ගොනුව සාකච්ඡාව
මාධ්යවිකි
මාධ්යවිකි සාකච්ඡාව
සැකිල්ල
සැකිලි සාකච්ඡාව
උදවු
උදවු සාකච්ඡාව
ප්රවර්ගය
ප්රවර්ග සාකච්ඡාව
ද්වාරය
ද්වාරය සාකච්ඡාව
MOS
MOS talk
TimedText
TimedText talk
Module
Module talk
Event
Event talk
සාමය
0
1684
790911
764884
2026-05-19T15:12:57Z
~2026-30147-02
79026
790911
wikitext
text/x-wiki
{{otheruses}}
[[ගොනුව:Peace dove.svg|right|thumb| තම හොටෙහි [[ඔලිව් අත්ත]]ක් දරාගෙන සිටින සාම පරෙවියා සාමයේ සංකේතයක් ලෙස පුළුල් ලෙස ව්යවහාර වේ.]]
'''සාමය''' යනු [[සහජීවනය]] පවතින එනම් එදිරිවාදකම් රහිතවූ අවස්ථාවකි. ප්රචණ්ඩ ජාත්යන්තර කලහයක විරාමය සනිටුහන් කිරීමටද මෙම පද වචනය භාවිත වේ; මෙම ජාත්යන්තර සන්දර්භය තුල අර්ථ විග්රහය කළහොත් පදයේ අර්ථය වනුයේ [[යුද්ධය]] යන්නේ විරුද්ධාර්ථයයි. කිසියම් ඕනෑම පාර්ශවයන් කිහිපයක් අතර [[ගෞරවාන්විත සැළකිල්ල]], [[යුක්ති සාධාරණත්වය]], හා [[හොඳහිත]] යන ගුණාංග විදහාපාන සම්බන්ධතාවයක් පවතී නම් එයද ''සාමය'' ලෙස හැඳින්විය හැක. තවද ලෝක සාම දිනය යෙදී ඇත්තේ සැප්තැම්බර් 21වන දාටයි.
සාමාන්ය වශයෙන් සැලකූ කල යම් අයෙකු වෙනත් පරිසර වලට සාපේක්ෂව ''[[සාමකාමී]]'' ලෙස හඳුන්වන නිසල, ශාන්ත, හා සන්සුන් පරිසරයක් ඇසුරෙහි පවතින්නේ නම් ඔහුට හෝ ඇයට සාමය ලඟා විය හැකිය. ඉහත ආකාරයේ සාමයක් යම් අයෙකුට ලඟා කර ගත හැක්කේ ස්වෝත්සාහයෙන් තම ඇතුලාන්ත චරිතය "සාමලැදි" බවට පත්කොට ගෙන ස්වකීය අභ්යන්තරයෙහි සන්සුන් බව, ශාන්ත බව හා [[සමතුලිතතාවය]] පවත්වාගෙන යෑමෙනි.
== සාමයේ විවිධ පැතිකඩ තේරුම් ගැනීම ==
=== හිංසාව විරහිත වීම (අවිහිංසාව) සාමය ලෙස ===
[[ගොනුව:Peace symbol (fixed width).svg|right|thumb|අති පුළුල් ලෙස [[සාමයේ සංකේතය]] ලෙස පිළිගැනීමකට පාත්රව ඇති [[න්යෂ්ටික අවි හරණය පිළිබඳ ව්යාපාරය]] හි සංකේතය.]]
'''සාමය''' යන සංකල්පය වර්තමානයේ ඉතාමත් මතභේදයට තුඩුදුන් මාතෘකාවකි. නිසැකයෙන්ම සාමය යනු ධනාත්මක සංකල්පයකි; ඇත්තවශයෙන්ම මෙලොව කිසිවෙකු සාමයට කෙලින්ම විරුද්ධ නොවේ; [[world peace|ලෝක සාමය]] යනු මනුෂ්යයින් වශයෙන් අත්කරගත යුතු උතුම් තත්වයකි. කෙසේනමුත් සාමය යනු කුමක්ද? සාමය අත්කර ගත හැක්කේ කෙසේද? සාමය ඇත්තවශයෙන්ම ළගා කරගත හැකිද? යන ඒවා පිළිබදව විවධාකාර පුද්ගල කොට්ඨාෂ අතාරහි තියුණු වෙනස්කම් ඇත.
== සාමය යනු කුමක්ද? ==
සාමය යන්නට විවිධ අර්ථ ඇත: වචනය යොදන ආකාරය හා තැන අනුවද අර්ථය වෙනස්වේ.
=== යුද්ධයෙන් තොර වීම ===
ඉතාම සරල හා දළ අදහස නම් [[war|යුද්ධයෙන්]] තොර වීමයි. ([[Ancient Rome|පුරාණ රෝම වරු]]න්ගේ අදහසට අනුව, ''Pax'', යන්න ''Absentia Belli'' ලෙස, එනම් ''යුද්ධයෙන් තොර වීම''.)
{{Authority control}}
[[ප්රවර්ගය:International relations]]
[[ප්රවර්ගය:සාමය]]
[[ප්රවර්ගය:Personal life]]
{{අසම්පූර්ණ}}
p5nnvdqv3pakfibxckwy60akd6uprsy
නිදහස් හා විවෘත මූලාශ්ර මෘදුකාංග
0
2117
790925
790714
2026-05-19T18:56:13Z
Amherst99
18480
/* */
790925
wikitext
text/x-wiki
{{නිදහස් මෘදුකාංග}}
[[ගොනුව:Heckert GNU white.svg|thumb|200px|right|[[GNU]] නිදහස් මෘදුකාංග ලාංඡනය]]
[[නිදහස් මෘදුකාංග පදනම]]<!-- Free Software Foundation --> මගින් අර්ථ දක්වා ඇති අන්දමට '''නිදහස් මෘදුකාංග''' යනු බාධාවකින් තොරව භාවිතා කිරීමට, පිටපත් කිරීමට, අධ්යායනය කිරීමට, වෙනස් කිරීමට හා යලි බෙදා හැරීමට හැකි [[මෘදුකාංග]] <!-- software --> වේ. මෘදුකාංගයක්, නිදහස් මෘදුකාංගයක් ලෙස බෙදා හැරීමේ සාමාන්ය ක්රමය වනුයේ මෘදුකාංගය එය ලබන්නා වෙත [[නිදහස් මෘදුකාංග බලපත්රය]]ක් සමග ලියාපදිංචි කිරීම (හෝ public domain තුළ වීම) සහ මෘදුකාංගයෙහි [[මූල කේතය]] මුදා හැරීම වේ. (for a [[compiled language]]).
==භාවිතය== <!-- Usage -->
{{Expand section}}
1960 දශකයේ නිර්මාණය වූ විශාල ප්රමාණයේ වානිජ පරිගණක වෙළෙඳපොළට පැමිණියේ ඊට අවශ්ය පරිගණක වැඩසටහනද සමඟිනි. එම මෘදුකාංග වල ප්රභව කේතයද රහස් ඒවා නොවුණි. නමුත් 70 දශකය වන විට මෙම සම්ප්රදාය නැතිවී ගියේය. එයට හේතුව වූයේ මිලදී ගතයුතු, බුද්ධිමය දේපළ අයිතියක් ඇති පරිගණක වැඩසටහන් වෙළෙඳපොළට නිකුත්වීමයි.
එකල තිබූ යුනික්ස් (Unix) මෙහෙයුම් පද්ධතියද එවැනි පරිගණක වැඩසටහනකි.
පරිගණක වැඩසටහන් පරිගණක භාවිත කරන්නාට අවශ්ය සේ වෙනස් කරගත හැකි සහ නොමිලයේ ලබාදෙන මෘදුකාංග වියයුතු බවට මතයක් 80 දශකයේදී ව්යාප්ත වී ගියේය.
මේ බව දැනගත් එවකට මැසවුසෙට්ස් තාක්ෂණ ආයතනයෙහි (MIT) ක්රමලේඛ ශිල්පියෙකු ලෙස කටයුතු කළ ස්ටොල්මාන් තමා සේවය කළ තාක්ෂණ ආයතනයෙන් ඉවත් වී කාටත් නිදහසේ භාවිතයට ගත හැකි පරිගණක මෙහෙයුම් පද්ධතියක් තැනීමේ කටයුතු ආරම්භ කළේය. මෙසේ තැනූ මෙහෙයුම් පද්ධතිය ග්නූ (GNU) ලෙස නම් කරන ලදි.
ග්නූ යන්නෙහි තේරුම එන මෙහෙයුම් පද්ධතිය වැඩසටහන් ගණනාවක එකතුවක් ලෙස ඉදිරිපත් කරන ලද බවයි. මෙහෙයුම් පද්ධතියක අත්යවශ්ය අංගයන් වන කර්නලය හෙවත් ප්රධාන මෙහෙයුම් කේත පද්ධතිය, ඩ්රයිවර්ස් වැඩසටහන්, යූසර් ඉන්ටර් ෆේස් මෙන්ම සිස්ටම් යුටිලිටීස්ද එහි අන්තර්ගත වීම විශේෂත්වයකි. ඒවාට අදාළවන කේත ලියමින් ග්නූ ව්යාපෘතිය (www.gnu.org) ඔහුවිසින් ආරම්භ කළේ 1983 දීය.
==තවද බලන්න== <!-- See also -->
{{portalpar|නිදහස් මෘදුකාංග}}
{{wikinewscat|FLOSS}}
* [[DADVSI]]
* [[Dual license]]
* [[Free software magazine]]
* [[Free audio software]]
* [[Free file format]]
* [[නිදහස් හා විවෘත මූලාශ්ර මෘදුකාංග]]
* [http://en.wikibooks.org/wiki/FLOSS_Concept_Booklet FLOSS Concept Booklet] on [[Wikibooks]]
* [[නිදහස් මෘදුකාංග පදනම]] <!--Free Software Foundation-->
* [[නිදහස් මෘදුකාංග බලපත්ර]] <!-- Free software licenses -->
* [[GNU General Public License]]
* [[GNU|GNU Project]]
* [[List of free software packages]]
* [[List of liberated software]]
* [[විවෘත මූලාශ්ර]] <!-- Open source -->
* [[විවෘත මූලාශ්ර vs. නිදහස් මෘදුකාංග]] <!-- Open source vs. free software -->
* [[විවෘත ප්රමිතිය]] <!-- Open standard -->
* [[Open format]]
* [[Software Freedom Day]]
{{software distribution}}
<!-- Category:Free software -->
www.ubuntu.com,
www.shipit.ubuntu.com
==උදාහරණ== <!--Examples-->
Some examples of FOSS include: the [[ලිනක්ස් kernel]]<!--Linux kernel-->, the [[KDE]] and [[GNOME]] desktops, [[BIND]] and [[මොසිල්ලා ෆයර්ෆොක්ස්|Firefox]]<!--Mozilla Firefox|Firefox-->.
==බලපත්ර== <!--Licenses-->
The most well known and popular F/OSS licenses include: [[GNU General Public License]] (GPL)<!--GNU General Public License-->, [[GNU Lesser General Public License]] (LGPL)<!--GNU Lesser General Public License-->, [[BSD license]]<!--BSD license-->, [[Apache License]]<!--Apache License-->, [[MIT License]]<!--MIT License--> and [[Mozilla Public License]]<!--Mozilla Public License-->.
There are a number of endorsed F/OSS definitions, and related lists of licenses. The above licenses are approved by all definitions.
F/OSS definitions and guidelines:
* [[විවෘත මූලාශ්ර Definition]] <!--Open Source Definition-->, from the [[විවෘත මූලාශ්ර Initiative]] <!--Open Source Initiative-->
* [[Free software license|Free software definition]], from the [[නිදහස් මෘදුකාංග පදනම]] <!--Free Software Foundation-->
* [[ඩේබියන් නිදහස් මෘදුකාංග Guidelines]] <!--Debian Free Software Guidelines-->
Lists of licenses:
* [[විවෘත-මූලාශ්ර බලපත්රය#OSI approved බලපත්ර|OSI අනුමත කළ බලපත්ර]]<!--Open-source license#OSI approved licenses|OSI approved licenses-->
* [http://www.gnu.org/philosophy/license-list.html නිදහස් මෘදුකාංග පදනමේ නිදහස් සහ නොනිදහස් බලපත්ර ලැයිස්තුව]<!--The Free Software Foundation's list of free and unfree licenses-->
==සංස්කෘතිය== <!-- Culture -->
The [[විවෘත මූලාශ්ර සංස්කෘතිය|F/OSS සංස්කෘතිය]]<!--Open source culture|F/OSS culture--> and [[විවෘත මූලාශ්ර ප්රජාව|F/OSS community]]<!--Open source community|F/OSS community--> stem from [[hacker සංස්කෘතිය]]<!--hacker culture-->.
==අඩවියෙන් බැහැර පිටු== <!-- External links -->
* [http://www.gnu.org/philosophy/free-sw.html The Free Software Definition] - published by FSF
* [http://www.ffii.org/index.en.html Foundation for a Free Information Infrastructure (FFII)] {{Webarchive|url=https://web.archive.org/web/20060719042925/http://www.ffii.org/index.en.html |date=2006-07-19 }}.
* [http://en.howto.wikicities.com/wiki/Free_Software_and_Open_Source_software_%28Where_to_find%29 Free Software and Open Source software (Where to find)] {{Webarchive|url=https://web.archive.org/web/20060209162702/http://en.howto.wikicities.com/wiki/Free_Software_and_Open_Source_software_(Where_to_find) |date=2006-02-09 }} - from Wikisolutions
* [http://www.gnu.org/licenses/license-list.html FSF's list of free software licenses] {{Webarchive|url=https://web.archive.org/web/20110825004145/http://www.gnu.org/licenses/license-list.html |date=2011-08-25 }}, including clarifications on often confused non-free licenses
* [http://www.gnu.org/directory FSF/UNESCO directory of free software packages] {{Webarchive|url=https://web.archive.org/web/20090107091903/http://www.gnu.org./directory/ |date=2009-01-07 }}
* [http://www.gnu.org/philosophy/ The GNU philosophy pages]
* [http://www.gnu.org/philosophy/free-software-for-freedom.html FSF's comparison of "Open Source" and "Free Software"]
* [http://www.dwheeler.com/oss_fs_why.html Why Open Source Software / Free Software (OSS/FS)? Look at the Numbers!] — David Wheeler's analysis of the advantages of OSS/FS.
* [http://ciaran.compsoc.com/texts/ Free software transcripts by Ciaran O'Riordan] {{Webarchive|url=https://web.archive.org/web/20070809064001/http://ciaran.compsoc.com/texts/ |date=2007-08-09 }}
* [http://www.freewebs.com/freesofts4win/ The best free softwares for Windows XP and Windows Vista]
{{portalpar|නිදහස් මෘදුකාංග}} <!--portalpar|Free software-->
{{Software-type-stub}}
[[ප්රවර්ගය:නිදහස් මෘදුකාංග]]
[[ප්රවර්ගය:Software licenses]]
[[ප්රවර්ගය:Libre]]
[[ප්රවර්ගය:නිදහස් මෘදුකාංග සංස්කෘතිය හා ලියැවිලි]]
lcuato8dhd907g5i3p143y3y31pghpe
අධි ස්පන්දනය කිරීම - ස්ථානීය හා ක්රියාත්මකරියාත්මක වීමේ නිරවද්යතාව
0
16763
790933
357890
2026-05-20T03:15:55Z
EmausBot
5927
Fixing double redirect from [[අධිස්පන්දනය කිරීම (Overclocking)#ස්ථායීතාව හා ක්රියාත්මක වීමේ නිරවද්යතාව]] to [[අධිස්පන්දනය කිරීම]]
790933
wikitext
text/x-wiki
#යළියොමුව [[අධිස්පන්දනය කිරීම#ස්ථායීතාව හා ක්රියාත්මක වීමේ නිරවද්යතාව]]
0k49llwwavug04aqxrfolmaicultvdo
රබින්ද්රනාත් තාගෝර්
0
27329
790953
783277
2026-05-20T10:57:56Z
Yasasuru
23090
790953
wikitext
text/x-wiki
{{Infobox Writer <!-- for more information see [[:Template:Infobox Writer/doc]] -->
| name = රබින්ද්රනාථ් ඨාකූර්
| image = Rabindranath Tagore in 1909.jpg
| imagesize = 200px
| alt = Late-middle-aged bearded man in white robes looks to the left with serene composure.
| caption =
| pseudonym = ගුරුදේව්/බානුසිංහ
| birthdate = {{Birth date|1861|5|7|df=y}}
| birthplace = [[කල්කටා]], [[Bengal Presidency]], [[බ්රිතාන්ය රාජ්|බ්රිතාන්ය ඉන්දියාව]]<!-- DO NOT CHANGE THIS WITHOUT DISCUSSION ON THE TALK PAGE FIRST -->
| deathdate = {{Death date and age|1941|8|7|1861|5|8|df=y}}
| deathplace = කල්කටා, බෙංගාල පළාත, බ්රිතාන්ය ඉන්දියාව<!-- DO NOT CHANGE THIS WITHOUT DISCUSSION ON THE TALK PAGE FIRST -->
| occupation = [[Poet]], [[writer]], [[lecture]]r
| genre = [[Poet]], [[novelist]], [[Short story|short-story writer]], [[essayist]], [[playwright]], [[thespian]], [[educationist]], [[spiritualist]], [[philosopher]], [[internationalism (politics)|internationalist]], [[painting|painter]], [[cultural relativist]], [[orator]], [[composer]], [[song-writer]], [[singer]], [[artist]]
| ethnicity = [[බෙංගාලි ජනයා|බෙංගාලි]]
| nationality = [[ඉන්දියාව|ඉන්දියානු]]
| movement = [[බෙංගාල පුනරුදය]]
| notableworks = ''[[ගීතාංජලී]]'' <br /> ''ගෝරා'' <br /> ''ඝරේ-බෛරේ''
| subject = [[සාහිත්යය]]
| influenced = [[D.R. Bendre]], [[André Gide]], [[Yasunari Kawabata]], [[Kuvempu]], [[Gabriela Mistral]], [[Pablo Neruda]], [[Octavio Paz]]
| signature = Rabindranath Tagore Signature.svg|alt=Close-up on a Bengali word handwritten with angular, jaunty letters.
| spouse = මෘනාලිනී දේවී (1883–1900)
| children =
| awards = {{Awd|[[සාහිත්යය සඳහා නොබෙල් ත්යාගය]]|1913}}
}}
[[ක්රි.ව.1818 පළමු නිදහස් සටන|ක්රි.ව]]. 1861 මැයි මස 7 වැනිදා ඉන්දියාවේ කල්කටා නගරයේ පොරසාන්ක්වේ ප්රදේශයේ දී '''රබින්ද්රනාත් තාගෝර්''' උපත ලැබීය. ඔහු බෙංගාලි ජාතිකයෙකි. පවුලේ දහහතර වැනියා ලෙස උපත ලැබූ "තාගොර්" පවුලේ කුඩාම දරුවා බාලම දරුවා විය. මේ සමයේ භාරත දේශයේ පැවති කුල භේදය තාගෝර් ජීවිතයටද තදින්ම බල පෑ බව කිව හැකිය.
තාගෝර් කුඩා කාලයේදීම පෙම්බර මෑණියන් අභාවප්රාප්ත වීම ඔහුට බලවත් පහරක් විය. ඔහුගේ පියා වූයේ දේවේන්ද්රනාත් තාගෝර් ය. තවද ඔහුගේ මුත්තණුවන් වූයේ ද්වාර්කනාත් තාගෝර්ය. ඔහුට මදකට හෝ සැනසීම ළඟා කර දුන් තම නෑනන්ඩියද 1884 දී පරලෝ සැපත් වූවාය.
1883 දී විවාහ වූ මේ කවියා 1900 වන විට දරුවන් පස් දෙනකුගේ පියෙකි. ඒ වන විටත් තාගෝර් තම දේශයට බලවත් සේ ආදරය කරන්නට පටන් ගෙන තිබිණි. තම රටේ උරුමය රැකීමට [[ශාන්ති නිකේතන විද්යාපීඨය]] ආරම්භ කළ තාගෝර් එහි ප්රථම දේශනයේදීම කියා සිටියේ සියලු ආගම්වලට හා ජාතීන්ට ගරු කිරීම උසස් ජාතික ගුණාංගයක් බවය. ඒ වන විට මුලු ජාතියම පිළිගත් තාගෝර් කවියාට, ලෝකයේ සිටින ජනප්රිය හා ශ්රේෂ්ඨතම සාහිත්යකරුවාට පිරිනැමෙන වටිනාම ත්යාගය වන [[නොබෙල් ත්යාගය|නොබෙල් ත්යාගයත්]] ලැබී තිබිණි. ඒ ඔහුගේ ගීතාංජලී කෘතිය වෙනුවෙනි. එම ත්යාගය 1913 නොවැම්බර් මාසයේදී තාගෝර් කවියාට පිරි නමනු ලැබීමෙන් එසේ ආසියාතිකයකුට පළමු වරට එම ත්යාගය හිමි විය.එවක පටන් ඔහු බෙංගාල මහා කවියා ලෙස ලොව පුරා ප්රසිද්ධ විය
තාගෝර් භාෂාවන් කිහිපයකින්ම කවි ලීවේය. නොබෙල් ත්යාගය දිනා ගැනීමත් සමගම 1913 දීම සාහිත්යාචාර්යවරයෙකු ලෙස කල්කටා විශ්වවිද්යාලයේ ගෞරවයට පත් වුණු එතුමා සිරිමත් රබීන්ද්රනාත් තාගෝර් යන නමින් 1915 දී [[නයිට් පදවිය|නයිට් පදවියකින්]] පුද ලැබුවේය.
1918 දී විශ්ව භාරතී නම් විශ්වවිද්යාලය ශාන්ති නිකේතනය තුළම ආරම්භ කරනු ලැබිණි. මෙම විශ්වවිද්යාලය දුප්පත්ම දරුවන්ගේ හැකියාවන් මතම බොහෝ විට ගොඩ නැගී තිබිණි.
1920-1921 අතර භාරත දේශයේ තැන් කිහිපයකම කැරැල්ලක් හටගෙන තිබිණි. මෙහිදී බ්රිතාන්ය ආණ්ඩුකාරවරයාගේ අනු දැනුම මත කැරැල්ල මැඬලීම සඳහා යුද්ධ භටයින් යොදවා භාරත වැසියන් හය සියයක් පමණ ප්රමාණයක් සංහාරය කරනු ලැබිණ. [[යුද්ධ නීතිය (මාෂල් ලෝ)]] යටතේ ජනතා නායකත්වය සහමුලින්ම මර්දනය කිරීමට යටත් විජිතවාදීන් සූදානම් වත්ම තාගෝර් බ්රිතාන්ය පාලනයට විරුද්ධව තනියම භාරත ජනතාවට නායකත්වය දුන්නේය. තාගෝර්තුමා ලංකාවටද දෙවරක්ම පැමිණ ඇත.එතුමා විසින් 1934 මැයි මස 08වන දින හොරණ ශ්රීපාලි විද්යාලය සඳහා මුල්ගල තබන ලදී. 1941 අගෝස්තු 08 වැනිදා තාගෝර්තුමා අවසන් හුස්ම හෙළීය.
== කෘති ==
එතුමා ලියූ කෘති කිහිපයක් පහත දැක්වේ.
* කබි කහානි (කවියාගේ කතාව) (1878)
* සන්ධ්යා සංගීත් (1882)
* ප්රභාත් සංගීත් (1883)
* ස්මරන්මා
* නසී (1890)
* සොනාර් ටාර් (1894)
* සාධනා (1913)
* බලකා (1916)
* තාගෝර්ගේ රන් පොත (1931)
* ගීතාංජලී (1913)
==කාව්ය==
* ගීතාංජලී (1912)
* කථ ඕ කාහිනී
* නෛවේද්ය (1901)
==නාට්ය==
* සොබා දහමේ පළිගැනීම
* භග්න හෘදය (1881)
* තැපැල් කන්තෝරුව (1914)
* අඳුරු කුටියේ රජතුමා (1914)
[[ප්රවර්ගය:1861 උපත්]]
[[ප්රවර්ගය:1941 මරණ]]
dbo9qh1csc9e644qmdy758j6f39fm14
අධි ස්පන්දනය කිරීම - ස්ථානීය හා ක්රියාත්මක වීමේ නිරවද්යතාව
0
37092
790932
357889
2026-05-20T03:15:45Z
EmausBot
5927
Fixing double redirect from [[අධිස්පන්දනය කිරීම (Overclocking)#ස්ථායීතාව හා ක්රියාත්මක වීමේ නිරවද්යතාව]] to [[අධිස්පන්දනය කිරීම]]
790932
wikitext
text/x-wiki
#යළියොමුව [[අධිස්පන්දනය කිරීම#ස්ථායීතාව හා ක්රියාත්මක වීමේ නිරවද්යතාව]]
0k49llwwavug04aqxrfolmaicultvdo
තුන්ගුස්කා සිද්ධිය
0
40326
790931
774605
2026-05-20T02:27:25Z
Geoffroi
75294
([[c:GR|GR]]) [[c:COM:FR|File renamed]]: [[File:Meteoroid size comparison.svg]] → [[File:Impacting asteroids size comparison.svg]] [[c:COM:FR#FR3|Criterion 3]] (obvious error) · The objects in the image had been misidentified, compare edit summary of most recent update
790931
wikitext
text/x-wiki
{{සැකිල්ල:කටු පරිවර්තනය}}
{{Infobox event|title=තුන්ගුස්කා සිද්ධිය|image=|caption=Trees knocked over by the Tunguska blast. Photograph from the Soviet Academy of Science 1927 expedition led by [[Leonid Kulik]].|date={{Start date and age|1908|6|30}}|time=07:17|place=[[පොඩ්කමෙනයා තුන්ගුස්කා ගඟ]], [[සයිබීරියාව]], රුසියානු අධිරාජ්යය|coordinates={{Coord|60|54|11|N|101|54|35|E|region:RU-KYA_type:event_scale:300000|display=inline,title}}<ref name=Farinella-2001/>|cause=කුඩා [[ග්රහක]] හෝ [[ධූමකේතුව]] විය හැකි [[උල්කාපාත වායු පිපිරීම]]|outcome={{convert|2150|sqkm|abbr=on}} ක වන ප්රදේශයක් සමතලා විය.<br />දේශීය ශාක හා සතුන් සඳහා වන විනාශය|reported property damage=හානි වූ ගොඩනැගිලි කිහිපයක්|reported deaths=0 තහවුරු, 3 විය හැකි}}
තුන්ගුස්කා සිදුවීම (ඉඳහිට තුන්ගුස්කා සිද්ධිය ලෙසද හැඳින්වේ) යනු 1908 ජූනි 30 වන දින උදෑසන රුසියාවේ යෙනිසෙස්ක් (දැන් ක්රස්නොයාර්ස්ක් ක්රා) හි පොඩ්කාමැන්නායි තුන්ගුස්කා ගඟ අසල සිදුවූ මෙගාටොන් 12 ක<ref name="jenniskens">{{cite journal|last1=Jenniskens|first1=P|year=2019|title=Tunguska eyewitness accounts, injuries and casualties|journal=[[Icarus (journal)|Icarus]]|volume=327|pages=4–18|bibcode=2019Icar..327....4J|doi=10.1016/j.icarus.2019.01.001|s2cid=127618395}}</ref> පමණ පිපිරීමකි.<ref name="Farinella-2001">{{cite journal|last1=Farinella|first1=Paolo|last2=Foschini|first2=L.|last3=Froeschlé|first3=Christiane|last4=Gonczi|first4=R.|last5=Jopek|first5=T. J.|last6=Longo|first6=G.|last7=Michel|first7=Patrick|year=2001|title=Probable asteroidal origin of the Tunguska Cosmic Body|url=http://www-th.bo.infn.it/tunguska/aah2886.pdf|url-status=live|journal=Astronomy & Astrophysics|volume=377|issue=3|pages=1081–1097|bibcode=2001A&A...377.1081F|doi=10.1051/0004-6361:20011054|archive-url=https://web.archive.org/web/20131009172144/http://www-th.bo.infn.it/tunguska/aah2886.pdf|archive-date=9 October 2013|access-date=1 September 2015|doi-access=free}}</ref><ref name="trayner">{{cite journal|last1=Trayner|first1=C|year=1994|title=Perplexities of the Tunguska meteorite|journal=[[The Observatory (journal)|The Observatory]]|volume=114|pages=227–231|bibcode=1994Obs...114..227T}}</ref> විරල ජනාකීර්ණ නැගෙනහිර සයිබීරියානු ටයිගා ප්රදේශයේ ඇති වූ පිපිරීමෙන් වනාන්තරයේ කිලෝමීටර් 2,150 (වර්ග සැතපුම් 830) ක ප්රදේශයක ගස් මිලියන 80 ක් සමතලා වී ඇති අතර ඇසින් දුටු සාක්ෂිකරුවන්ගේ වාර්තා අනුව අවම වශයෙන් පුද්ගලයින් තිදෙනෙකු මෙම සිද්ධියෙන් මිය යන්නට ඇත.<ref name="SAO/NASA - ADS">{{Cite journal|last1=Gritzner|first1=C|year=1997|title=Human Casualties in Impact Events|journal=WGN|volume=25|pages=222|bibcode=1997JIMO...25..222G}}</ref><ref name="CBC">{{cite web |last1=Jay |first1=Paul |title=The Tunguska event |url=http://www.cbc.ca/news/technology/the-tunguska-event-1.742329 |url-status=live |archive-url=https://web.archive.org/web/20210301020151/https://www.cbc.ca/news/technology/the-tunguska-event-1.742329 |archive-date=1 March 2021 |access-date=20 July 2017 |publisher=CBC News}}</ref><ref>{{cite web |last1=Coppins |first1=Philip |title=The Tunguska explosion: an unexpected loud bang and explosion |url=http://philipcoppens.com/tunguska.html |url-status=live |archive-url=https://web.archive.org/web/20171214071358/http://philipcoppens.com/tunguska.html |archive-date=14 December 2017 |access-date=8 October 2017 |website=philipcoppins.com}}</ref><ref name="delong.typepad.com">{{cite web |title=Reported Deaths and Injuries from Meteorite Impact |url=http://delong.typepad.com/sdj/2008/06/reported-deaths.html |url-status=live |archive-url=https://web.archive.org/web/20210224083055/https://delong.typepad.com/sdj/2008/06/reported-deaths.html |archive-date=24 February 2021 |access-date=8 October 2017 |website=delong.typepad.com}}</ref><ref name="jenniskens2">{{cite journal|last1=Jenniskens|first1=P|year=2019|title=Tunguska eyewitness accounts, injuries and casualties|journal=[[Icarus (journal)|Icarus]]|volume=327|pages=4–18|bibcode=2019Icar..327....4J|doi=10.1016/j.icarus.2019.01.001|s2cid=127618395}}</ref> පිපිරුම සාමාන්යයෙන් උල්කාපාත වායු පිපිරීමක් ලෙස සැලකේ: මීටර් 50-60 (අඩි 160-200) පමණ ප්රමාණයේ ගල් සහිත ග්රහකයක වායුගෝලීය පිපිරීම.<ref name="jenniskens3">{{cite journal|last1=Jenniskens|first1=P|year=2019|title=Tunguska eyewitness accounts, injuries and casualties|journal=[[Icarus (journal)|Icarus]]|volume=327|pages=4–18|bibcode=2019Icar..327....4J|doi=10.1016/j.icarus.2019.01.001|s2cid=127618395}}</ref><ref name="de Pater">{{cite book|last1=de Pater|first1=Imke|last2=Lissauer|first2=Jack|title=Planetary Sciences|date=2001|publisher=Cambridge University Press|isbn=0521482194}}</ref> ග්රහකය නැගෙනහිර-ගිණිකොන දෙසින් ළඟා වූ අතර, එය 27 km/s (60,000 mph) (~Ma 80) පමණ සාපේක්ෂ ඉහළ වේගයකින් විය හැකිය.<ref name="jenniskens4">{{cite journal|last1=Jenniskens|first1=P|year=2019|title=Tunguska eyewitness accounts, injuries and casualties|journal=[[Icarus (journal)|Icarus]]|volume=327|pages=4–18|bibcode=2019Icar..327....4J|doi=10.1016/j.icarus.2019.01.001|s2cid=127618395}}</ref> බලපෑම් ආවාටයක් සොයා නොගත්තද, එය බලපෑම් සිදුවීමක් ලෙස වර්ගීකරණය කර ඇත; මෙම වස්තුව පෘථිවි පෘෂ්ඨයේ ගැටෙනවාට වඩා කිලෝමීටර් 5 සිට 10 දක්වා (සැතපුම් 3 සිට 6 දක්වා) උන්නතාංශයක පුපුරා ගොස් ඇතැයි සැලකේ.<ref>{{cite APOD|date=14 November 2007|title=Tunguska: The Largest Recent Impact Event|access-date=12 September 2011}}</ref>
ප්රාග් ඓතිහාසික යුගයේ ඊට වඩා විශාල බලපෑම් සිදුවී ඇතත්, වාර්තාගත ඉතිහාසයේ පෘථිවිය මත සිදු වූ විශාලතම බලපෑම් සිදුවීම තුන්ගුස්කා සිදුවීමයි. මෙම විශාලත්වයේ පිපිරීමක් විශාල නාගරික ප්රදේශයක් විනාශ කිරීමට සමත් වනු ඇත.<ref name="Longo 2007 303–330">{{cite book|last=Longo|first=Giuseppe|editor-last=Bobrowsky|editor-first=Peter T.|editor2-last=Rickman|editor2-first=Hans|title=Comet/Asteroid Impacts and Human Society, An Interdisciplinary Approach|chapter=18: The Tunguska event|pages=303–330|publisher=Springer-Verlag|place=Berlin; Heidelberg; New York|publication-date=2007|chapter-url=http://www-th.bo.infn.it/tunguska/Asteroids-Chapter-18.pdf|isbn=978-3-540-32709-7|year=2007|archive-url=https://web.archive.org/web/20131014200044/http://www-th.bo.infn.it/tunguska/Asteroids-Chapter-18.pdf|archive-date=14 October 2013|url-status=dead|bibcode=2007caih.book.....B}}</ref> එය ජනප්රිය සංස්කෘතියේ බොහෝ වාර ගණනක් සඳහන් කර ඇති අතර, ග්රහක බලපෑම් වළක්වා ගැනීම පිළිබඳ සැබෑ ලෝක සාකච්ඡාවට ද අනුබල දී ඇත.{{Citation needed|date=June 2020}}
== විස්තරය ==
[[File:Russia-CIA_WFB_Map--Tunguska.png|link=https://en.wikipedia.org/wiki/File:Russia-CIA_WFB_Map--Tunguska.png|thumb|සයිබීරියාවේ සිදුවීමේ ස්ථානය (නවීන සිතියම)]]
1908 ජූනි 30 (එන්. එස්.) (රුසියාවේ 1908 ජූනි 17, ඕ. එස්. ලෙස උපුටා දක්වා ඇත, 1918 දී [[සෝවියට් දින දසුන]] ක්රියාත්මක කිරීමට පෙර), දේශීය වේලාවෙන් 07:17 ට පමණ, බයිකල් විලට වයඹින් පිහිටි කඳුකරයේ ඉවෙන්කි ස්වදේශිකයෝ සහ රුසියානු පදිංචිකරුවෝ හිරු සා නුදුරින් දීප්තිමත් නිල් පැහැති ආලෝකයක් අහස හරහා ගොස් තුනී මාවතක් තබනු නිරික්සූ හ. ක්ෂිතිජයට සමීප ව, වලාකුළක් නිපදවන ෆ්ලෑෂ් එකක්, පසුව භූ දර්ශනයට රතු එළියක් දැල්වූ ගිනි කණුවක් විය. කණුව දෙකට පැලී මැලැවී කළු පැහැයට හැරිණි. විනාඩි දහයකට පමණ පසු කාලතුවක්කු ප්රහාරයක් වැනි හඬක් ඇසෙන්නට විය. පිපිරීමට ආසන්නව ඇසින් දුටු සාක්ෂිකරුවන් වාර්තා කළේ ශබ්දයේ ප්රභවය නැඟෙනහිර සිට උතුරට ගමන් කළ බවයි. එම ශබ්දයන් සමඟ කම්පන තරංගයක් ඇති වූ අතර ඉන් කිලෝමීටර් සිය ගණනක් දුරින් තිබූ ජනේල පවා කැඩී ගියේය.<ref name="jenniskens5">{{cite journal|last1=Jenniskens|first1=P|year=2019|title=Tunguska eyewitness accounts, injuries and casualties|journal=[[Icarus (journal)|Icarus]]|volume=327|pages=4–18|bibcode=2019Icar..327....4J|doi=10.1016/j.icarus.2019.01.001|s2cid=127618395}}</ref>
යුරේසියාව පුරා භූ කම්පන මධ්යස්ථානවල පිපිරුම සටහන් වී ඇති අතර, පිපිරීමෙන් ඇති වූ වායු තරංග ජර්මනිය, ඩෙන්මාර්කය, ක්රොඒෂියාව සහ එක්සත් රාජධානිය - සහ බටාවියාව, ලන්දේසි නැගෙනහිර ඉන්දීය කොදෙව් සහ වොෂින්ටන්, ඩී.සී. දක්වා පැතිරිණි.<ref name=":0">{{Cite journal|last=Whipple|first=F. J. W.|year=1934|title=On Phenomena related to the great Siberian meteor|journal=Quarterly Journal of the Royal Meteorological Society|volume=60|issue=257|pages=505–522|bibcode=1934QJRMS..60..505W|doi=10.1002/qj.49706025709|issn=0035-9009}}</ref> සමහර ස්ථානවල ඇති වූ කම්පන තරංගය රිච්ටර් පරිමාණයේ 5.0 ක භූමිකම්පාවකට සමාන බව ගණන් බලා ඇත.<ref name="Traynor2">{{cite journal|last=Traynor|first=Chris|year=1997|title=The Tunguska Event|journal=[[Journal of the British Astronomical Association]]|volume=107|issue=3}}</ref> ඉක්බිති දින කිහිපය තුළ ආසියාවේ සහ යුරෝපයේ රෑ අහස දීප්තිමත් විය. ස්වීඩනයේ සහ ස්කොට්ලන්තයේ මධ්යම රාත්රියේ දී (ෆ්ලෑෂ් බල්බ ආධාරයෙන් තොරව) දීප්තිමත් ලෙස ආලෝකමත් කරන ලද ඡායාරූප සාර්ථක ලෙස ලබා ගැනීම පිළිබඳ සමකාලීන වාර්තා තිබේ.<ref name=":02">{{Cite journal|last=Whipple|first=F. J. W.|year=1934|title=On Phenomena related to the great Siberian meteor|journal=Quarterly Journal of the Royal Meteorological Society|volume=60|issue=257|pages=505–522|bibcode=1934QJRMS..60..505W|doi=10.1002/qj.49706025709|issn=0035-9009}}</ref> පිපිරීමේ ප්රතිඵලයක් ලෙස අතිශය අඩු උෂ්ණත්වවල දී නිර්මාණය වූ ඉහළ උන්නතාංශ අයිස් අංශු හරහා ආලෝකය ගමන් කිරීම නිසා මෙම තිරසාර දිලිසෙන බලපෑම ඇති වූ බව න්යාය ගතකර ඇත - දශක ගණනාවකට පසු අභ්යවකාශ ෂටල මගින් සංසිද්ධිය ප්රතිනිෂ්පාදනය කරන ලදී.<ref>Cornell University (24 June 2009). <!-- I don't know how to add this but I thought this might be helpful to add to the above section https://en.wikipedia.org/wiki/Noctilucent_cloud --> [https://www.sciencedaily.com/releases/2009/06/090624152941.htm Space Shuttle Science Shows How 1908 Tunguska Explosion Was Caused By A Comet.] {{Webarchive|url=https://web.archive.org/web/20180421035433/https://www.sciencedaily.com/releases/2009/06/090624152941.htm|date=21 April 2018}}</ref><ref>{{cite journal|last1=Kelley|first1=M. C.|last2=Seyler|first2=C. E.|last3=Larsen|first3=M. F.|year=2009|title=Two-dimensional Turbulence, Space Shuttle Plume Transport in the Thermosphere, and a Possible Relation to the Great Siberian Impact Event|journal=Geophys. Res. Lett.|volume=36|issue=14|pages=L14103|bibcode=2009GeoRL..3614103K|doi=10.1029/2009GL038362|doi-access=free}}</ref> එක්සත් ජනපදයේ, කැලිෆෝනියාවේ මවුන්ට් විල්සන් නිරීක්ෂණාගාරයේ ස්මිත්සෝනියන් තාරකා භෞතික නිරීක්ෂණ වැඩසටහනක් විසින් අත්හිටුවන ලද දූවිලි අංශුවල වැඩි වීමක් සමඟ අනුකූලව වායුගෝලීය විනිවිදභාවයේ මාස ගණනක අඩුවීමක් නිරික්සිණි.<ref>{{cite journal|last1=Turco|first1=R.P.|last2=et.|first2=al.|date=April 1982|title=An Analysis of the Physical, Chemical, Optical and Historical Impacts of the 1908 Tunguska Meteor Fall|journal=Icarus|volume=50|issue=1|pages=1–52|bibcode=1982Icar...50....1T|doi=10.1016/0019-1035(82)90096-3}}</ref>
=== තෝරාගත් ඇසින් දුටු සාක්ෂිකරුවන්ගේ වාර්තා ===
[[File:Тунгус_метеорит_Топи_Тунгуски_до14сент1930_ВС1931.JPG|link=https://en.wikipedia.org/wiki/File:%D0%A2%D1%83%D0%BD%D0%B3%D1%83%D1%81_%D0%BC%D0%B5%D1%82%D0%B5%D0%BE%D1%80%D0%B8%D1%82_%D0%A2%D0%BE%D0%BF%D0%B8_%D0%A2%D1%83%D0%BD%D0%B3%D1%83%D1%81%D0%BA%D0%B8_%D0%B4%D0%BE14%D1%81%D0%B5%D0%BD%D1%821930_%D0%92%D0%A11931.JPG|දකුණ|thumb|තුන්ගුස්කා වගුරු බිම්, එය වැටුණු ප්රදේශය වටා. මෙම ඡායාරූපය Around the World, 1931 සඟරාවෙන්. මුල් ඡායාරූපය 1927 සහ 1930 අතර (අනුමාන වශයෙන් 1930 සැප්තැම්බර් 14 ට පසුව නොවේ).]]
1908 දී පිපිරුම සිදු වූ සයිබීරියාවේ ප්රදේශය ඉතා විරල ජනාකීර්ණ වූවත්, ඒ වන විට අවට ප්රදේශයේ සිටි ඇසින් දුටු සාක්ෂිකරුවන්ගේ වාර්තා ඇති අතර, ප්රාදේශීය පුවත්පත් මෙම සිදුවීම සිදුවී ටික වේලාවකට පසු වාර්තා කළේය.
එස්. සෙමෙනොව් ගේ සාක්ෂියට අනුව, 1930 දී රුසියානු ඛනිජ විද්යාඥ ලියොනිඩ් කුලික්ගේ ගවේෂණය වාර්තා කර ඇත:<ref>N. V. Vasiliev, A. F. Kovalevsky, S. A. Razin, L. E. Epiktetova (1981). ''[http://tunguska.tsc.ru/ru/science/1/0 Eyewitness accounts of Tunguska (Crash).] {{Webarchive|url=https://web.archive.org/web/20070930161327/http://tunguska.tsc.ru/ru/science/1/0|date=30 September 2007}}'', Section 6, Item 4</ref>
{{Quote|text=උදෑසන ආහාරය ගන්නා විට මම පිපිරුමෙන් කිලෝමීටර් 65ක් පමණ දකුණින් උතුරට මුහුණලා වානවර වෙළඳපොලේ නිවස අසල වාඩි වී සිටියෙමි. මම හදිසියේම දුටුවේ කෙලින්ම උතුරට, ඔන්කෝල්ගේ තුන්ගුස්කා පාරට උඩින්, අහස දෙකට බෙදී වනාන්තරය පුරා ගින්නක් ඉහළට හා පළලින් දිස්වන බවයි [සෙමෙනොව් පෙන්වා දුන් පරිදි, අංශක 50 ක් පමණ ඉහළට - ගවේෂණ සටහන]. අහසේ බෙදීම විශාල වූ අතර මුළු උතුරු පැත්තම ගින්නෙන් වැසී ගියේය. ඒ වෙලාවේ මගේ කමිසය ගිනි ගත්තා වගේ මට දරාගන්න බැරි තරමටම මම රත් වුණා. ගින්න ඇති වූ උතුරු දෙසින් දැඩි තාපයක් පැමිණියේය. මට මගේ කමිසය ඉරා දමා බිමට විසි කිරීමට අවශ්ය විය, නමුත් එවිට අහස වසා දැමුණි, සහ ශක්තිමත් පහරක් නාද වූ අතර මාව මීටර් කිහිපයක් විසි කරන ලදී. මට මොහොතකට සිහිය නැති වූ නමුත් පසුව මගේ බිරිඳ පිටතට දිව ගොස් මාව නිවසට ගෙන ගියාය. ඊට පස්සේ එහෙම ඝෝෂාවක් ආවා, හරියට ගල් වැටෙනවා වගේ, කාලතුවක්කු වෙඩි තියනවා වගේ, පොළව කම්පා වෙලා, මම බිම ඉන්නකොට, ගල් පර්වත කඩාවැටෙයි කියලා බයට මම මගේ හිස පහත් කළා. අහස විවර වූ විට, කාලතුවක්කු වලින් මෙන් උණුසුම් සුළඟක් ගෙවල් අතරට දිව ගිය අතර, එය මාර්ග මෙන් පොළවේ සලකුණු ඉතිරි කර, සමහර වගාවන්ට හානි කළේය. පසුව අපි දැක්කා බොහෝ ජනේල කැඩී ගොස් ඇති අතර, ගබඩාවේ යකඩ අගුලේ කොටසක් කඩා වැටී ඇත.}}
1926 දී අයි. එම්. සුස්ලොව් විසින් වාර්තා කරන ලද පරිදි, ශානියාගිර් ගෝත්රයේ චුචාන්ගේ සාක්ෂිය:<ref>Vasiliev, Section 5</ref>
{{Quote|text=අපේ චෙකරන් අයියා එක්ක ගඟ අයිනේ පැල්පතක් තිබිණි. අප සිටියේ නිදාගෙන යි. අපි දෙ දෙනාම එක් වරම ඇහැරුණුමු. කවුරු හෝ අප තල්ලු කළේ ය. අපට විසිල් සදක් ඇසුණා සේ මැ තද සුළඟක් දැනිණි. "ඔබට ඔය කුරුල්ලන් ඔක්කොම උඩින් පියාඹනවා ඇසෙත් ද?" යැ යි චෙකරන් කී ය. අප දෙ දෙනාම සිටියේ පැල්පතේ, එළියේ වෙන්නේ කුමක් දැ යි නො පෙනෙයි. එක් වරම මම යළිත් තල්ලු විණිමි, මෙ වර මම ගින්නට වැටිණිමි. මම බය විණිමි. චෙකරන්ටත් බය සිතිණි. අප තාත්තා අම්මා මල්ලී කියා කෑගසන්නට පටන් ගත්තත් කිසිවෙක් පිළිතුරු නො දිනි. පැල්පතින් ඔබට (ඔබ්බට) ශබ්දයක් ඇසිණි, අපට ගස් කඩා වැටෙනු ඇසිණි. චෙකරන්ටත් මටත් අපගේ නිදි මලුවලින් බැස එළියට පැනීමට අවශ්ය වූවත් ඉක්බිති අකුණු සැර වැදිණි. මෙය පළමු ගිගුරුම විය. පොළොව සෙලැවීමටත් ගල් ගැසීමටත් පටන් ගත් අතර, සුළඟ අපේ පැල්පතට පහර දී එය පෙරළා දැමී. මගේ සිරුර පොලුවලින් පහළට තල්ලු කර ඇති, නමුත් මගේ හිස පැහැදිලි විය. එ විට මම පුදුමයක් දිටිමි: ගස් කඩා වැටෙයි, අතු ගිනිබත් වෙයි, එය බලවත් දීප්තිමත් විය, මම මෙය කෙසේ කියම් ද, දෙ වන හිරු මෙන්, මගේ ඇස් රිදිණි, මම ඒවා වසා ගතිමි. එය රුසියානුවන් අකුණු ලෙස හඳුන්වන ආකාරයට විය. එ කෙණෙහි මැ විශාල ගිගුරුම් හඬක් ඇති විය. මෙය දෙ වන ගිගුරුම විය. උදෑසන හිරු රශ්මියත් වලාකුළුත් නො තිබිණි, අපේ හිරු සුපුරුදු පරිදි දීප්තිමත් ලෙස බබළමින් සිටි අතර, හදිසියේ මැ දෙ වන එකක් පැමිණි!
චෙකරන්ටයි මටයි අපේ පැල්පතේ නටබුන් යටින් එළියට එන්න ටිකක් අමාරු වුණා. ඊට පස්සේ අපි උඩින් දැක්කා, නමුත් වෙනත් තැනක, තවත් ෆ්ලෑෂ් එකක් ආවා, විශාල ගිගුරුම් හඬක් ආවා. මෙය තෙවැනි ගිගුරුම් පහරයි. හුළඟ ආයෙත් ආවා, අපිව අපේ කකුලෙන් බිමට දැම්මා, වැටුණු ගස්වලට ගැහුවා.
අපි වැටුණු ගස් දෙස බැලුවෙමු, ගස් මුදුන් කඩා වැටෙනු බලා සිටියෙමු, ගින්න දෙස බලා සිටියෙමු. එක්වරම චෙකරන් "උඩ බලන්න" යැයි කෑගසමින් අත පෙන්වීය. මම බැලූ විට තවත් ෆ්ලෑෂ් එකක් දුටුවෙමි, එය තවත් අකුණු සැරයක් ඇති කළේය. ඒත් ඉස්සරට වඩා සද්දේ අඩුයි. මෙය සාමාන්ය ගිගුරුම් හඬක් මෙන් සිව්වැනි පහර දීමයි.
දැන් මට හොඳට මතකයි තවත් එක් ගිගුරුම් පහරක් ද ඇති විය, නමුත් එය කුඩා වූ අතර කොහේ හරි දුරින් විය.}}
''සිබිර් පුවත්පත,'' 1908 ජූලි 2:<ref>Vasiliev, Section 1, Item 2</ref>
{{Quote|text=ජූනි මස 17 වන දින උදෑසන,<ref>[[Gregorian calendar]]: 30 June</ref> 9:00 ට පමණ, අපි අසාමාන්ය ස්වභාවික සිදුවීමක් නිරික්සූමු. කිරෙන්ස්ක් සිට කිලෝමීටර් 213 ක් උතුරින් පිහිටි උතුරු කරෙලින්ස්කි ගම්මානයේ ගොවියෝ වයඹ දෙසින්, ක්ෂිතිජයට තරමක් ඉහළින්, විනාඩි 10 ක් පහළට ගමන් කළ අමුතු දීප්තිමත් (බැලීමට නොහැකි) නිල්-සුදු දෙයක් දුටු. එය "පයිප්ප", එනම් සිලින්ඩරයක් ලෙස පෙනී සිටියේය. අහස වලාකුළු රහිත වූ අතර දීප්තිමත් එය සාමාන්ය දිශාවට කුඩා අඳුරු වලාකුළක් පමණක් නිරික්සිණි. එය උණුසුම් හා වියලි විය. එය පොළොවට (වනාන්තර) ළං වූ විට, දීප්තිමත් ඇති බවක් පෙනෙන්නට තිබිණි. පසු ව යෝධ කළු දුමාරයක් බවට පත් විය. විශාල ගල් කඩා වැටෙන්නාක් මෙන් හෝ කාලතුවක්කු වෙඩි තැබීමක් මෙන් විශාල තට්ටු කිරීමක් (ගිගුරුම් සහිත නොවේ) ඇසිණි. සියලු ගොඩනැගිලි සෙලැවිණි. ඒ සමඟ ම වලාකුළ අවිනිශ්චිත හැඩතලවල ගිනිදැල් නිකුත් කිරීමට පටන් ගති. සියලුම ගම් වැසියෝ කලබලයට පත් වී පාරට බටු. ලෝකයේ අවසානය යැ යි සිතා කාන්තාවෝ කෑ ගැසූ හ.
මෙම රේඛා කිරෙන්ස්ක් නගරයට උතුරින් කිලෝමීටර් 6.4ක් පමණ වනාන්තරයේ සිට අතර ඊසාන දිගට යම් ආකාරයක කාලතුවක්කු ප්රහාරයක් ඇසිණි, එය විනාඩි 15 ක පරතරයකින් අවම වශයෙන් 10 වතාවක් පුනරාවර්තනය විය. කිරෙන්ස්ක්හි, ඊසාන දිගට මුහුණලා ඇති බිත්තිවල ගොඩනැගිලි කිහිපයක ජනෙල් වීදුරු සෙලැවිණි.}}
''සයිබීරියන් ලයිෆ්'' පුවත්පත, 1908 ජූලි 27:<ref>Vasiliev, Section 1, Item 3</ref>{{Quote|උල්කාපාතය වැටෙන විට, භූමියේ දැඩි කම්පන නිරීක්ෂණය කරන ලද අතර, කන්ස්ක් දිස්ත්රික්කය හි ලොවට් ගම්මානය අසල විශාල කැලිබර් කාලතුවක්කු වලින් මෙන් ශක්තිමත් පිපිරීම් දෙකක් ඇසිණි.|sign=|source=}}
''ක්රස්නෝයාරෙට්ස්'' පුවත්පත, 1908 ජූලි 13:<ref>Vasiliev, Section 1, Item 5</ref>{{Quote|කෙෂෙම්ස්කෝයි ගම්මානය. 17 වැනි දින අසාමාන්ය වායුගෝලීය සිදුවීමක් නිරීක්ෂණය විය. 7:43 ට තද සුළඟකට සමාන ශබ්දයක් ඇසුණි. ඉක්බිතිව බිහිසුණු ඝෝෂාවක් ඇසුණු අතර, භූමිකම්පාවක් ඇති වූ අතර එය විශාල ලී කොටයකට හෝ බර ගලකට පහර දුන්නාක් මෙන් ගොඩනැගිලි වචනානුසාරයෙන් කම්පා විය. පළමු හා දෙවනුව, පසුව තුන්වන පහර පසුව සිදු විය. ඉන්පසුව, පළමු සහ තුන්වන පහර අතර පරතරය එකවර දුම්රිය දුසිම් ගණනක් ගමන් කරන ශබ්දයකට සමාන අසාමාන්ය භූගත රැට්ල් එකක් සමඟ විය. ඉන්පසුව, මිනිත්තු 5 සිට 6 දක්වා කාලතුවක්කු වෙඩි තැබීමේ නිශ්චිත සමානකමක් ඇසුණි: කෙටි, සමාන කාල පරාසයන් තුළ, එය ක්රමයෙන් දුර්වල විය. විනාඩි 1.5-2 කට පසු තවත් කාලතුවක්කු වෙඩි තැබීම වැනි, නමුත් තනි තනිව, ඝෝෂාකාරී සහ වෙව්ලීමක් සමඟ ශබ්ද හයක් ඇසුණි.
මුලින්ම බැලූ බැල්මට අහස පැහැදිලියි. සුළඟක්වත් වලාකුළුවත් තිබුණේ නැහැ. උතුරට සමීපව පරීක්ෂා කිරීමේදී, බොහෝ විට හඩ ඇසෙන විට, ක්ෂිතිජය අසල අළු වලාකුළක් දක්නට ලැබුණි, එය කුඩා වෙමින් හා විනිවිද පෙනෙන අතර සමහර විට සවස 2-3 පමණ වන විට සිදු විය. සම්පූර්ණයෙන්ම අතුරුදහන් විය.}}
[[File:Trajectory_Models_of_The_Tunguska_Fireball.svg|link=https://en.wikipedia.org/wiki/File:Trajectory_Models_of_The_Tunguska_Fireball.svg|alt=Trajectory Models of The Tunguska Fireball|මධ්යය|thumb|800x800පික්|තුන්ගුස්කා ගේ ගමන් පථය සහ ගම්මාන පහක ස්ථාන පෘථිවි පෘෂ්ඨයට සාමාන්ය තලයක් මතට ප්රක්ෂේපණය වී ගිනි බෝලයේ ප්රවේශ මාර්ගය හරහා ගමන් කරයි. පරිමාණය ලබා දී ඇත්තේ කිලෝමීටර 100 ක ආරම්භක උසකින් ය. දෘශ්ය විකිරණයේ ZR යන උච්ච කෝණ තුනක් උපකල්පනය කරන අතර පිළිවෙලින් ඝන, ඉරි සහ තිත් රේඛා මගින් සැලසුම් කරන ලද ගමන් පථයන් උපකල්පනය කෙරේ. වරහන් කළ දත්ත යනු ප්රක්ෂේපණ තලයේ සිට ස්ථානවල ඇති දුරයි: ප්ලස් ලකුණකින් දැක්වෙන්නේ එම ස්ථානය තලයට දකුණු-දකුණු දෙසින් බව; ඍණ ලකුණක්, එහි උතුරු-ඊසාන දෙසින්. මෙම රූපයේ සහ පෙළෙහි ගම් නාමවල අක්ෂර පරිවර්තනය I පත්රයට අනුකූල වන අතර වර්තමාන ලෝක සිතියම්වල අක්ෂර පරිවර්තනයට වඩා තරමක් වෙනස් වේ.]]
== විද්යාත්මක විමර්ශනය ==
1908 සිදුවීමෙන් පසුව, තුන්ගුස්කා පිපිරීම පිළිබඳව ඇස්තමේන්තු කර ඇති විද්වත් පත්රිකා 1,000ක් (බොහෝ රුසියානු භාෂාවෙන්) ප්රකාශයට පත් කර ඇත. වෙබ් අඩවියේ දුරස්ථභාවය සහ සිදුවීම සිදුවන අවස්ථාවේ පවතින සීමිත උපකරණ හේතුවෙන්, එහි හේතුව සහ විශාලත්වය පිළිබඳ නවීන විද්යාත්මක අර්ථකථන ප්රධාන වශයෙන් රඳා පවතින්නේ සිද්ධියෙන් වසර ගණනාවකට පසුව සිදු කරන ලද හානිය තක්සේරු කිරීම් සහ භූ විද්යාත්මක අධ්යයනයන් මත ය. එහි ශක්තිය පිළිබඳ ඇස්තමේන්තු TNT මෙගාටොන් 3-30 (පෙටජූල් 13-126) දක්වා පරාසයක පවතී.
1910 ගණන්වල රුසියාවට බලපෑ ප්රදේශය හුදකලා වීම සහ සැලකිය යුතු දේශපාලන පෙරළියක් හේතුවෙන් කලාපය පිළිබඳ කිසිදු විද්යාත්මක විශ්ලේෂණයක් සිදු නොවූයේ සිද්ධියෙන් දශකයකට වැඩි කාලයක් ගත වන තුරු ය. 1921 දී රුසියානු ඛනිජ විද්යාඥ ලියොනිඩ් කුලික් විසින් සෝවියට් විද්යා ඇකඩමිය සඳහා සමීක්ෂණයක් පැවැත්වීම සඳහා කණ්ඩායමක් පොඩ්කාමැන්නාය තුන්ගුස්කා ගංගා ද්රෝණියට ගෙන ගියේය.<ref>{{cite web |title=The Tunguska Impact – 100 Years Later |url=https://science.nasa.gov/science-news/science-at-nasa/2008/30jun_tunguska |url-status=live |archive-url=https://web.archive.org/web/20210516020717/https://science.nasa.gov/science-news/science-at-nasa/2008/30jun_tunguska/ |archive-date=16 May 2021 |access-date=13 January 2019 |website=NASA Science}}</ref> ඔවුන් කිසි විටෙක මධ්යම පිපිරුම් ප්රදේශයට නොපැමිණි නමුත්, මෙම සිදුවීම පිළිබඳ බොහෝ දේශීය වාර්තා කුලික්ට විස්වාස කිරීමට හේතු වූයේ පිපිරීම යෝධ උල්කාපාත පහරකින් සිදු වූවක් බවයි. ආපසු පැමිණීමෙන් පසු, උල්කාපාත යකඩ ගලවා ගැනීමේ අපේක්ෂාව මත පදනම්ව, සැක සහිත බලපෑම් කලාපයට ගවේෂණයක් සඳහා අරමුදල් සපයන ලෙස ඔහු සෝවියට් රජයට ඒත්තු ගැන්වීය.<ref name=":1">{{Cite web |date=June 2018 |title=This Month in Physics History |url=https://www.aps.org/publications/apsnews/201806/history.cfm |url-status=live |archive-url=https://web.archive.org/web/20210308025217/https://www.aps.org/publications/apsnews/201806/history.cfm |archive-date=8 March 2021 |access-date=22 December 2018 |website=American Physical Society}}</ref>
කුලික් විසින් 1927 දී තුන්ගුස්කා පිපිරුම් ස්ථානය වෙත විද්යාත්මක ගවේෂණයක් මෙහෙයවීය. ඔහු තම කණ්ඩායම පිපිරුම් ප්රදේශයේ මධ්යයට ගෙන යාමට ප්රදේශයේ ඉවෙන්කි දඩයම්කරුවන් කුලියට ගත් අතර එහිදී ඔවුන් බලපෑම් ආවාටයක් සොයා ගැනීමට අපේක්ෂා කළේය. ඔවුන් පුදුමයට පත් කරමින්, බිම් බිංදුවෙහි කිසිදු ආවාටයක් නොතිබුණි. ඒ වෙනුවට ඔවුන් සොයා ගත්තේ, දළ වශයෙන් කිලෝමීටර් 8ක් (සැතපුම් 5.0) හරහා, ගස් පිළිස්සුණු සහ අතුවලින් තොර, නමුත් තවමත් කෙළින් සිටගෙන සිටින කලාපයක්.<ref name=":12">{{Cite web |date=June 2018 |title=This Month in Physics History |url=https://www.aps.org/publications/apsnews/201806/history.cfm |url-status=live |archive-url=https://web.archive.org/web/20210308025217/https://www.aps.org/publications/apsnews/201806/history.cfm |archive-date=8 March 2021 |access-date=22 December 2018 |website=American Physical Society}}</ref> මධ්යයේ සිට බොහෝ දුරින් පිහිටි ගස් අර්ධ වශයෙන් පිළිස්සී ගොස් මධ්යයෙන් ඉවතට දිශාවට කඩා වැටී ඇති අතර, කඩා වැටුණු ගස්වල විශාල රේඩියල් රටාවක් නිර්මාණය විය.
1960 ගණන් වලදී, සමතලා කළ වනාන්තර කලාපය 2,150 km2 (වර්ග සැතපුම් 830) ක භූමි ප්රදේශයක් අත්පත් කරගෙන ඇති බව තහවුරු විය, එහි හැඩය කිලෝමීටර 70 (සැතපුම් 43) ක "පියාපත්" සහිත දැවැන්ත පැතිරුණු රාජාලි සමනලයෙකු හා සමාන වේ. "ශරීර දිග" කිලෝමීටර 55 (සැතපුම් 34)<ref>Boyarkina, A. P., Demin, D. V., Zotkin, I. T., Fast, W. G. "Estimation of the blast wave of the Tunguska meteorite from the forest destruction". ''Meteoritika'', Vol. 24, 1964, pp. 112–128 (in Russian).</ref><ref>{{Cite web |title=external image from ''Meteoritika'' article |url=https://i.imgur.com/n5q5EaD.jpg |url-status=live |archive-url=https://web.archive.org/web/20230304211831/https://i.imgur.com/n5q5EaD.jpg |archive-date=4 March 2023 |access-date=6 September 2022}}</ref> සමීපව පරීක්ෂා කිරීමේදී, කුලික් විසින් උල්කාපාත සිදුරු ලෙස වැරදි ලෙස නිගමනය කළ සිදුරු සොයා ගන්නා ලදී. ඔහුට ඒ කාලයේ සිදුරු හෑරීමට වත්කමක් තිබුණේ නැත.
ඊළඟ වසර 10 තුළ ප්රදේශයට තවත් ගවේෂණ තුනක් සිදු විය. කුලික් විසින් උල්කාපාත ආවාට විය හැකි යැයි සිතන, එක් එක් මීටර් 10 සිට 50 දක්වා (අඩි 33 සිට 164 දක්වා) විෂ්කම්භයකින් යුත් කුඩා "පොටෝල්" වගුරු බිම් දුසිම් ගණනක් සොයා ගන්නා ලදී. මෙම බොග් වලින් එකක් (ඊනියා "සුස්ලොව් ආවාටය", විෂ්කම්භය මීටර් 32 [අඩි 105]) ජලය බැස යාමට වෙහෙස මහන්සි වී ව්යායාම කිරීමෙන් පසුව, එය උල්කාපාත ආවාටයක් වීමේ හැකියාව බැහැර කරමින් පතුලේ පැරණි ගස් කඳක් සොයා ගත්තේය. 1938 දී කුලික් විසින් සමතලා කරන ලද වනාන්තරයේ මධ්යම කොටස (වර්ග කිලෝමීටර් 250 [වර්ග සැතපුම් 97]) ආවරණය වන ප්රදේශය<ref>{{cite web |author=Longo G. |title=The 1938 aerophotosurvey |url=http://www-th.bo.infn.it/tunguska/APS-photolist.htm |url-status=live |archive-url=https://web.archive.org/web/20210226195352/https://www-th.bo.infn.it/tunguska/APS-photolist.htm |archive-date=26 February 2021 |access-date=8 October 2017}}</ref> පිළිබඳ ගුවන් ඡායාරූප සමීක්ෂණයක් කිරීමට කටයුතු කළේය.<ref name="Bronshten2000">See: Bronshten (2000), p. 56.</ref> මෙම ගුවන් ඡායාරූපවල මුල් නෙගටිව් (සෙන්ටිමීටර 18 x 18 [අඟල් 7.1 කින් 7.1]) 1975 දී එවකට USSR විද්යා ඇකඩමියේ උල්කාපාත පිළිබඳ කමිටුවේ සභාපති වූ යෙව්ගනි ක්රිනොව්ගේ නියෝගයෙන් පුළුස්සා දමන ලදී.<ref name="Bronshten20002">See: Bronshten (2000), p. 56.</ref> රුසියානු නගරයේ ටොම්ස්ක් හි වැඩිදුර අධ්යයනය සඳහා ඡායාරූප මුද්රණ සංරක්ෂණය කර ඇත.<ref>Rubtsov (2009), p. 59.</ref>
1950 සහ 1960 ගණන් වලදී එම ප්රදේශයට යවන ලද ගවේෂණ මගින් පස පෙරීමේදී ක්ෂුද්ර සිලිකේට් සහ මැග්නටයිට් ගෝල සොයා ගන්නා ලදී. සමකාලීන ක්රම මගින් අනාවරණය කර ගත නොහැකි වුවද, කපන ලද ගස්වල සමාන ගෝල පවතිනු ඇතැයි පුරෝකථනය කරන ලදී. පසුකාලීන ගවේෂණ මගින් ගස්වල දුම්මලවල එවැනි ගෝල හඳුනා ගන්නා ලදී. රසායනික විශ්ලේෂණයෙන් පෙන්නුම් කළේ ගෝලවල යකඩවලට සාපේක්ෂව ඉහළ නිකල් ප්රමාණයක් අඩංගු වන අතර එය උල්කාපාතවල ද දක්නට ලැබෙන අතර ඒවා පිටසක්වල සම්භවයක් ඇති බවට නිගමනය විය. පසෙහි විවිධ ප්රදේශවල ගෝලවල සාන්ද්රණය ද උල්කාපාත වායු පිපිරීමකින් අපේක්ෂිත සුන්බුන් ව්යාප්තියට අනුකූල බව සොයා ගන්නා ලදී.<ref name="Florenskiy">{{cite journal|last=Florenskiy|first=K P|author-link=Kirill Florensky|year=1963|title=Preliminary results from the 1961 combined Tunguska meteorite expedition|url=http://abob.libs.uga.edu/bobk/tungmet.html|url-status=live|journal=Meteoritica|volume=23|archive-url=https://web.archive.org/web/20080720064557/http://abob.libs.uga.edu/bobk/tungmet.html|archive-date=20 July 2008|access-date=26 June 2007}}</ref> ගෝල පිළිබඳ පසුකාලීන අධ්යයනයන් අවට පරිසරයට සාපේක්ෂව වෙනත් බොහෝ ලෝහවල අසාමාන්ය අනුපාත සොයා ගන්නා ලද අතර, එය ඔවුන්ගේ පිටසක්වල සම්භවය පිළිබඳ වැඩිදුර සාක්ෂි ලෙස ගන්නා ලදී.<ref name="anomalies">Kolesnikov ''et al.'' "Finding of probable Tunguska Cosmic Body material: isotopic anomalies of carbon and hydrogen in peat", ''[[Planetary and Space Science]]'', Volume 47, Issues 6–7, 1 June 1999, pp. 905–916.</ref>
ප්රදේශයේ පීට් වගුරු බිම්වල රසායනික විශ්ලේෂණය මගින් බලපෑම් සිදුවීමකට අනුකූල ලෙස සැලකෙන බොහෝ විෂමතා ද අනාවරණය විය. 1908 ට අනුරූප වන වගුරු බිම්වල ඇති කාබන්, හයිඩ්රජන් සහ නයිට්රජන් සමස්ථානික අනුපාත යාබද ස්තරවල මනින ලද සමස්ථානික අනුපාත සමඟ නොගැලපෙන බව සොයා ගන්නා ලද අතර ප්රදේශයෙන් පිටත පිහිටි බොග් වල මෙම අසාමාන්යතාවය දක්නට නොලැබුණි. ක්රිටේසියස් - පැලියෝජීන් මායිමේ ඇති ඉරිඩියම් ස්ථරයට සමාන මෙම විෂමතා අනුපාත පෙන්වන බොග් ප්රදේශයේ අසාමාන්ය ලෙස ඉහළ ඉරිඩියම් ප්රතිශතයක් ද අඩංගු වේ. මෙම අසාමාන්ය සමානුපාතිකයන් බොග් වල තැන්පත් වී ඇති වැටෙන සිරුරේ සුන්බුන් නිසා ඇති වන බව විශ්වාස කෙරේ. නයිට්රජන් ඇසිඩ් වැස්සක් ලෙස තැන්පත් වී ඇති බවට විශ්වාස කෙරෙන අතර එය පිපිරීමෙන් ඇති වූ බවට සැක කෙරේ.<ref name="anomalies2">Kolesnikov ''et al.'' "Finding of probable Tunguska Cosmic Body material: isotopic anomalies of carbon and hydrogen in peat", ''[[Planetary and Space Science]]'', Volume 47, Issues 6–7, 1 June 1999, pp. 905–916.</ref><ref>Hou ''et al.'' "Discovery of iridium and other element anomalies near the 1908 Tunguska explosion site", ''[[Planetary and Space Science]]'', Volume 46, Issues 2–3, February–March 1998, pp. 179–188.</ref><ref>Kolesnikov ''et al.'' "Isotopic anomaly in peat nitrogen is a probable trace of acid rains caused by 1908 Tunguska bolide", ''[[Planetary and Space Science]]'', Volume 46, Issues 2–3, February–March 1998, pp. 163–167.</ref>
කෙසේ වෙතත් අනෙකුත් විද්යාඥයින් එකඟ නොවේ: "සමහර පත්රිකා වාර්තා කරන්නේ CI සහ CM කාබන්ඩයොක්සයිඩ් කොන්ඩ්රයිට් වලට සමාන අනුපාත සහිත හයිඩ්රජන්, කාබන් සහ නයිට්රජන් සමස්ථානික සංයුති TE (Kolesnikov et al. 1999, 2003) සිට සිද්ධිය වූ තුන්ගුස්කා පීට් ස්ථර වල තිබී ඇති බවයි. විෂමතා ද නිරීක්ෂණය කරන ලදී (Hou et al. 1998, 2004) වෙනත් රසායනාගාරවල සිදු කරන ලද මිනුම් මෙම ප්රතිඵල සනාථ කර නොමැත (Rocchia et al. 1990; Tositti et al. 2006).<ref name="Longo 2007 303–3302">{{cite book|last=Longo|first=Giuseppe|editor-last=Bobrowsky|editor-first=Peter T.|editor2-last=Rickman|editor2-first=Hans|title=Comet/Asteroid Impacts and Human Society, An Interdisciplinary Approach|chapter=18: The Tunguska event|pages=303–330|publisher=Springer-Verlag|place=Berlin; Heidelberg; New York|publication-date=2007|chapter-url=http://www-th.bo.infn.it/tunguska/Asteroids-Chapter-18.pdf|isbn=978-3-540-32709-7|year=2007|archive-url=https://web.archive.org/web/20131014200044/http://www-th.bo.infn.it/tunguska/Asteroids-Chapter-18.pdf|archive-date=14 October 2013|url-status=dead|bibcode=2007caih.book.....B}}</ref>
ජෝන් ඇන්ෆිනොජෙනොව් නම් පර්යේෂකයා යෝජනා කර ඇත්තේ, ජෝන් ගල ලෙස හැඳින්වෙන සිදුවීම් භූමියෙන් හමුවූ ගල් පර්වතයක් උල්කාපාතයේ ශේෂයක් බවයි.<ref>{{cite journal|last1=Anfinogenov|first1=John|display-authors=et al|date=15 November 2014|title=John's Stone: A possible fragment of the 1908 Tunguska meteorite|journal=Icarus|volume=245|pages=139–147|bibcode=2014Icar..243..139A|doi=10.1016/j.icarus.2014.09.006|s2cid=118541956}}</ref> නමුත් ක්වාර්ට්සයිට් වල ඔක්සිජන් සමස්ථානික විශ්ලේෂණයෙන් ඇඟවෙන්නේ එය ජල තාප සම්භවයක් ඇති බවත්, බොහෝ විට පර්මියන්-ට්රයැසික් සයිබීරියානු උගුල් මැග්මැටිස්වාදයට සම්බන්ධ බවත්ය.<ref>{{Cite journal|last1=Anfinogenova|first1=Yana|last2=Anfinogenov|first2=John|last3=Polonia|first3=Alina|last4=Gasperini|first4=Luca|last5=Franchi|first5=Fulvio|last6=Rocco|first6=Tommaso Di|last7=Breger|first7=Dee|last8=Bonatti|first8=Enrico|date=5 September 2015|title=Origin of John's Stone: A quartzitic boulder from the site of the 1908 Tunguska (Siberia) explosion|url=https://biust.pure.elsevier.com/en/publications/origin-of-johns-stone-a-quartzitic-boulder-from-the-site-of-the-1|url-status=live|journal=Icarus|volume=258|pages=297–308|bibcode=2015Icar..258..297B|doi=10.1016/j.icarus.2015.06.018|issn=0019-1035|archive-url=https://web.archive.org/web/20190730193654/https://biust.pure.elsevier.com/en/publications/origin-of-johns-stone-a-quartzitic-boulder-from-the-site-of-the-1|archive-date=30 July 2019|access-date=25 June 2019}}</ref>
2013 දී, පර්යේෂකයන් කණ්ඩායමක් බලපෑමට ලක් වූ ප්රදේශයේ මධ්යයට ආසන්නයේ ඇති පීට් බොග් වලින් ක්ෂුද්ර සාම්පල විශ්ලේෂණයක ප්රතිඵලය ප්රකාශයට පත් කළ අතර, එය පිටසක්වල සම්භවයක් ඇති කොටස් පෙන්නුම් කරයි.<ref>{{cite news|url=http://www.nature.com/news/rock-samples-suggest-meteor-caused-tunguska-blast-1.13163|title=Rock samples suggest meteor caused Tunguska blast|last=Peplow|first=Mark|date=10 June 2013|work=Nature|access-date=11 June 2013|archive-url=https://web.archive.org/web/20210526173227/https://www.nature.com/news/rock-samples-suggest-meteor-caused-tunguska-blast-1.13163|archive-date=26 May 2021|url-status=live}}</ref><ref>{{cite journal|last=Kvasnytsya|first=Victor|author2=R. Wirth|author3=L. Dobrzhinetskaya|author4=J. Matzel|author5=B. Jacobsen|author6=I. Hutcheon|author7=R. Tappero|author8=M. Kovalyukh|year=2013|title=New evidence of meteoritic origin of the Tunguska cosmic body|url=http://gfzpublic.gfz-potsdam.de/pubman/item/escidoc:247242|url-status=live|journal=Planet. Space Sci.|volume=84|pages=131–140|bibcode=2013P&SS...84..131K|doi=10.1016/j.pss.2013.05.003|archive-url=https://web.archive.org/web/20230304211918/https://gfzpublic.gfz-potsdam.de/pubman/faces/ViewItemOverviewPage.jsp?itemId=item_247242|archive-date=4 March 2023|access-date=13 January 2019}}</ref>
=== පෘථිවි බලපෑම් ආකෘතිය ===
[[File:Tunguska_and_Chelyabinsk_meteoroid_size.png|link=https://en.wikipedia.org/wiki/File:Tunguska_and_Chelyabinsk_meteoroid_size.png|thumb|තුන්ගුස්කා (TM ලකුණ) සහ චෙලියාබින්ස්ක් (CM) උල්කාපාතවල විය හැකි ප්රමාණයන් අයිෆල් කුළුණ සහ එම්පයර් ස්ටේට් ගොඩනැගිල්ලට සංසන්දනය කිරීම]]
පිපිරුම සඳහා ප්රමුඛතම විද්යාත්මක පැහැදිලි කිරීම පෘථිවි පෘෂ්ඨයේ සිට කිලෝමීටර් 6-10 (සැතපුම් 4-6) ක් ඉහළින් ග්රහකයක් මගින් උල්කාපාත වාතය පුපුරා යාමයි.
උල්කාපාත සෑම දිනකම අභ්යවකාශයේ සිට පෘථිවි වායුගෝලයට ඇතුළු වන අතර අවම වශයෙන් 11 km/s (7 mi/s) වේගයකින් ගමන් කරයි. වායුගෝලය හරහා ගමන් කරන විට එය ඉදිරිපිට වාතය සම්පීඩනය කිරීමෙන් ජනනය වන තාපය අතිමහත් වන අතර බොහෝ උල්කාපාත පොළොවට පැමිණීමට පෙර දැවී හෝ පුපුරා යයි. පිපිරීමේ නියම උස අනුව න්යෂ්ටික අවිවල බලපෑම් වලින් පරිමාණ නීති භාවිතා කරන විට ඇස්තමේන්තු කර ඇති පරිදි,<ref name="shoe2">{{cite journal|last=Shoemaker|first=Eugene|author-link=Eugene Merle Shoemaker|year=1983|title=Asteroid and Comet Bombardment of the Earth|journal=Annual Review of Earth and Planetary Sciences|volume=11|issue=1|pages=461–494|bibcode=1983AREPS..11..461S|doi=10.1146/annurev.ea.11.050183.002333}}</ref><ref name="Sandia National Laboratories">{{cite news|url=https://share.sandia.gov/news/resources/releases/2007/asteroid.html|title=Sandia supercomputers offer new explanation of Tunguska disaster|date=17 December 2007|access-date=22 December 2007|archive-url=https://web.archive.org/web/20130219203913/https://share.sandia.gov/news/resources/releases/2007/asteroid.html|archive-date=19 February 2013|publisher=[[Sandia National Laboratories]]|url-status=dead}}</ref> තුන්ගුස්කා වායු පිපිරීමේ ශක්තිය පිළිබඳ මුල් ඇස්තමේන්තු ටීඑන්ටී මෙගාටොන් 10-15 (පෙටජූල් 42-63) සිට ටීඑන්ටී මෙගාටොන් 30 (පීජේ 130) දක්වා පරාසයක පවතී.<ref name="shoe">{{cite journal|last=Shoemaker|first=Eugene|author-link=Eugene Merle Shoemaker|year=1983|title=Asteroid and Comet Bombardment of the Earth|journal=Annual Review of Earth and Planetary Sciences|volume=11|issue=1|pages=461–494|bibcode=1983AREPS..11..461S|doi=10.1146/annurev.ea.11.050183.002333}}</ref> වස්තුවේ ගම්යතාවයේ බලපෑම ඇතුලත් මෑත කාලීන ගණනය කිරීම් වලට අනුව න්යෂ්ටික පිපිරුමකට වඩා වැඩි ශක්තියක් පහලට නාභිගත වී ඇති බව සොයාගෙන ඇති අතර වායු පිපිරීමට TNT මෙගාටොන් 3 සිට 5 දක්වා ශක්ති පරාසයක් (13 සිට 21 දක්වා PJ) ඇති බව ඇස්තමේන්තු කර ඇත.<ref name="Sandia National Laboratories2">{{cite news|url=https://share.sandia.gov/news/resources/releases/2007/asteroid.html|title=Sandia supercomputers offer new explanation of Tunguska disaster|date=17 December 2007|access-date=22 December 2007|archive-url=https://web.archive.org/web/20130219203913/https://share.sandia.gov/news/resources/releases/2007/asteroid.html|archive-date=19 February 2013|publisher=[[Sandia National Laboratories]]|url-status=dead}}</ref> මෙගා ටොන් 15 (Mt) ඇස්තමේන්තුව ත්රිත්ව ශක්තියට වඩා 1,000 ගුණයකින් වැඩි ශක්තියක් නියෝජනය කරන අතර, 1954 දී එක්සත් ජනපදයේ කාසල් බ්රාවෝ න්යෂ්ටික අත්හදා බැලීමේ ශක්තියට (එය මෙගා ටොන් 15.2) සහ 1961 දී සෝවියට් දේශයේ සාර් බෝම්බ පරීක්ෂණයෙන් තුනෙන් එකකට සමාන වේ.<ref>Verma (2005), p 1.</ref> 2019 පත්රිකාවක් යෝජනා කරන්නේ තුන්ගුස්කා ඉසව්වේ පුපුරන සුලු බලය මෙගාටොන් 20-30 පමණ විය හැකි බවයි.<ref>{{cite journal|last1=Wheeler|first1=Lorien F.|last2=Mathias|first2=Donovan L.|year=2019|title=Probabilistic assessment of Tunguska-scale asteroid impacts|journal=Icarus|volume=327|pages=83–96|bibcode=2019Icar..327...83W|doi=10.1016/j.icarus.2018.12.017|doi-access=free}}</ref>
20 වන ශතවර්ෂයේ දෙවන භාගයේ සිට, අධෝරක්ත හා චන්ද්රිකා නිරීක්ෂණ හරහා පෘථිවි වායුගෝලය සමීපව නිරීක්ෂණය කිරීමෙන් පෙන්නුම් කර ඇත්තේ න්යෂ්ටික අවි හා සැසඳිය හැකි ශක්ති සහිත ග්රහක වාතය පුපුරා යාම සාමාන්යයෙන් සිදු වන නමුත්, තුන්ගුස්කා සිදුවීම ප්රමාණයේ, මෙගා ටොන් 5-15 සිදුවීම් වඩා දුර්ලභ වේ.<ref name="Chelyabinsk">{{Cite journal|last1=Borovička|first1=Jiří|last2=Spurný|first2=Pavel|last3=Brown|first3=Peter|last4=Wiegert|first4=Paul|last5=Kalenda|first5=Pavel|last6=Clark|first6=David|last7=Shrbený|first7=Lukáš|year=2013|title=The trajectory, structure and origin of the Chelyabinsk asteroidal impactor|journal=Nature|volume=503|issue=7475|pages=235–237|bibcode=2013Natur.503..235B|doi=10.1038/nature12671|pmid=24196708|s2cid=4399008}}</ref> ඉයුජින් ෂූමේකර් ඇස්තමේන්තු කළේ වාර්ෂිකව කිලෝටොන් 20ක සිදුවීම් සිදුවන බවත් තුන්ගුස්කා ප්රමාණයේ සිදුවීම් සෑම වසර 300කට වරක් සිදු වන බවත්ය.<ref name="shoe3">{{cite journal|last=Shoemaker|first=Eugene|author-link=Eugene Merle Shoemaker|year=1983|title=Asteroid and Comet Bombardment of the Earth|journal=Annual Review of Earth and Planetary Sciences|volume=11|issue=1|pages=461–494|bibcode=1983AREPS..11..461S|doi=10.1146/annurev.ea.11.050183.002333}}</ref><ref>{{cite web |last=Wiley |first=John P. Jr. |date=January 1995 |title=Phenomena, Comment & Notes |url=https://www.smithsonianmag.com/science-nature/phenomena-comment-notes-86860922/ |url-status=live |archive-url=https://archive.today/20120910221113/http://www.smithsonianmag.com/science-nature/phenom_jan95.html?c=y&page=2 |archive-date=10 September 2012 |work=Smithsonian}}</ref> වඩාත් මෑත කාලීන ඇස්තමේන්තු අනුව තුන්ගුස්කා ප්රමාණයේ සිදුවීම් වසර දහසකට වරක් සිදු වන අතර, සාමාන්යයෙන් වසරකට වරක් කිලෝටොන් 5ක වායු පිපිරීම් සිදුවේ.<ref name="Flux">{{cite journal|last1=Brown|first1=P.|last2=Spalding|first2=R.E.|last3=ReVelle|first3=D.O.|display-authors=et al|date=21 November 2002|title=The flux of small near-Earth objects colliding with the Earth|url=http://www.boulder.swri.edu/clark/brownnv2.pdf|url-status=live|journal=Nature|volume=420|issue=6913|pages=294–296|bibcode=2002Natur.420..294B|doi=10.1038/nature01238|pmid=12447433|archive-url=https://web.archive.org/web/20190113232133/http://www.boulder.swri.edu/clark/brownnv2.pdf|archive-date=13 January 2019|access-date=13 January 2019|s2cid=4380864}}</ref> මෙම වායු පිපිරීම් බොහොමයක් පෘථිවි වායුගෝලයට සාමාන්ය විනිවිද යාමේ ගැඹුර මත පදනම්ව, යාන්ත්රිකව දුර්වල වල්ගාතරු ද්රව්යවලට ප්රතිවිරුද්ධව, ග්රහක බලපෑම් නිසා ඇති වන බව සැලකේ.<ref name="Flux2">{{cite journal|last1=Brown|first1=P.|last2=Spalding|first2=R.E.|last3=ReVelle|first3=D.O.|display-authors=et al|date=21 November 2002|title=The flux of small near-Earth objects colliding with the Earth|url=http://www.boulder.swri.edu/clark/brownnv2.pdf|url-status=live|journal=Nature|volume=420|issue=6913|pages=294–296|bibcode=2002Natur.420..294B|doi=10.1038/nature01238|pmid=12447433|archive-url=https://web.archive.org/web/20190113232133/http://www.boulder.swri.edu/clark/brownnv2.pdf|archive-date=13 January 2019|access-date=13 January 2019|s2cid=4380864}}</ref> නවීන උපකරණ සමඟ නිරීක්ෂණය කළ විශාලතම ග්රහක වායු පිපිරුම වූයේ 2013 දී කිලෝටොන් 500 ක් බරැති චෙලියාබින්ස්ක් උල්කාපාතය වන අතර එය බිඳ දමා නව උල්කාපාත නිපදවයි.<ref name="Chelyabinsk2">{{Cite journal|last1=Borovička|first1=Jiří|last2=Spurný|first2=Pavel|last3=Brown|first3=Peter|last4=Wiegert|first4=Paul|last5=Kalenda|first5=Pavel|last6=Clark|first6=David|last7=Shrbený|first7=Lukáš|year=2013|title=The trajectory, structure and origin of the Chelyabinsk asteroidal impactor|journal=Nature|volume=503|issue=7475|pages=235–237|bibcode=2013Natur.503..235B|doi=10.1038/nature12671|pmid=24196708|s2cid=4399008}}</ref>
==== බැලූ බැල්මට බලපෑම් කල්පිතය ====
2020 දී රුසියානු විද්යාඥයින් පිරිසක් පෘථිවි වායුගෝලය හරහා ආනත කෝණවලින් මීටර් 200, 100 සහ 50 ක විෂ්කම්භයක් සහිත ග්රහක ගමන් කිරීම ගණනය කිරීම සඳහා පරිගණක ආකෘති මාලාවක් භාවිතා කළහ. ඔවුන් වස්තුවේ සංයුතිය යකඩ, පාෂාණ හෝ අයිස් වලින් සෑදුවාක් මෙන් උපකල්පන පරාසයක් භාවිතා කළහ. නිරීක්ෂණය කරන ලද සිදුවීමට වඩාත් සමීපව ගැලපෙන ආකෘතිය වූයේ විෂ්කම්භය මීටර් 200 ක් දක්වා වූ යකඩ ග්රහකයක් වන අතර එය තත්පරයට කිලෝමීටර 11.2 ක වේගයෙන් ගමන් කරන අතර එය පෘථිවි වායුගෝලයෙන් ඉවතට හැරී සූර්ය කක්ෂයට ආපසු පැමිණියේය.<ref>{{Cite journal|last1=Khrennikov|first1=Daniil E.|last2=Titov|first2=Andrei K.|last3=Ershov|first3=Alexander E.|last4=Pariev|first4=Vladimir I.|last5=Karpov|first5=Sergei V.|date=21 March 2020|title=On the possibility of through passage of asteroid bodies across the Earth's atmosphere|url=https://academic.oup.com/mnras/article/493/1/1344/5722124|url-status=live|journal=Monthly Notices of the Royal Astronomical Society|volume=493|issue=1|pages=1344–1351|arxiv=2009.14234|bibcode=2020MNRAS.493.1344K|doi=10.1093/mnras/staa329|issn=0035-8711|archive-url=https://web.archive.org/web/20201117100300/https://academic.oup.com/mnras/article/493/1/1344/5722124|archive-date=17 November 2020|access-date=7 May 2020|doi-access=free}}</ref><ref>{{Cite web |date=6 May 2020 |title=Most Explosive Meteor Impact: 1908 Tunguska Explosion Caused by Iron Asteroid That Entered Earth Then Bounced Back to Space |url=https://www.sciencetimes.com/articles/25599/20200506/explosive-meteor-impact-1908-tunguska-explosion-caused-iron-asteroid-entered.htm |url-status=live |archive-url=https://web.archive.org/web/20200507225419/http://www.sciencetimes.com/articles/25599/20200506/explosive-meteor-impact-1908-tunguska-explosion-caused-iron-asteroid-entered.htm |archive-date=7 May 2020 |access-date=7 May 2020 |website=Science Times}}</ref><ref>{{Cite web |title=World's largest 'explosion' could have been caused by iron asteroid entering and leaving atmosphere |url=https://siberiantimes.com/science/others/news/worlds-largest-explosion-could-have-been-caused-by-iron-asteroid-entering-and-leaving-atmosphere/ |url-status=live |archive-url=https://web.archive.org/web/20200507000035/http://siberiantimes.com/science/others/news/worlds-largest-explosion-could-have-been-caused-by-iron-asteroid-entering-and-leaving-atmosphere/ |archive-date=7 May 2020 |access-date=7 May 2020 |website=siberiantimes.com}}</ref>
==== පිපිරුම් රටාව ====
පිපිරුම් මධ්යස්ථානය අසල ගස්වලට පිපිරුම් බලපෑම සාම්ප්රදායික බ්ලෝඩවුන් මෙහෙයුමේ බලපෑමට සමාන විය. මෙම බලපෑම් ඇති වන්නේ විශාල වායු-පිපිරුම් පිපිරීම් මගින් නිපදවන පිපිරුම් තරංගය මගිනි. පිපිරුම් තරංගය සිරස් අතට පහළට ගමන් කරන විට පිපිරුමට කෙළින්ම පහළින් ඇති ගස් ඉවත් කරනු ලැබේ, නමුත් කෙළින් සිටගෙන සිටින අතර, පිපිරුම් තරංගය ඒවාට ළඟා වන විට තිරස් අතට සමීපව ගමන් කරන බැවින් දුරින් පිහිටි ගස් පෙරළේ.
1960 ගණන්වල මැද භාගයේ සිදු කරන ලද සෝවියට් අත්හදා බැලීම්, ආකෘති වනාන්තර (කම්බි කූරු මත ඇති ගිනිකූරු වලින් සාදන ලද) සහ කුඩා පුපුරණ ද්රව්ය ආරෝපණ කම්බි මත පහළට ලිස්සා ගොස්, තුන්ගුස්කා අඩවියේ ඇති රටාවට සමාන සමනල හැඩැති පිපිරුම් රටා නිපදවන ලදී. පර්යේෂණවලින් යෝජනා වූයේ වස්තුව දළ වශයෙන් පොළවේ සිට අංශක 30 ක කෝණයකින් සහ උතුරේ සිට අංශක 115 ක කෝණයකින් ළඟා වී ඇති අතර එය අහසේ පුපුරා ගොස් ඇති බවයි.<ref>{{IMDb title|id=1156463|title=Siberian Apocalypse}}</ref>
==== ග්රාහකය හෝ වල්ගා තරුව ====
1930 දී බ්රිතාන්ය කාලගුණ විද්යාඥ සහ ගණිතඥ එෆ්. ජේ. ඩබ්ලිව්. විප්ල් විසින් තුන්ගුස්කා, ශරීරය කුඩා වල්ගා තරුවක් බව යෝජනා කළේය. වල්ගාතරුවක් සමන්විත වන්නේ ජල අයිස් සහ ශීත කළ වායූන් වැනි දූවිලි හා වාෂ්පශීලී ද්රව්ය වලින් වන අතර පෘථිවි වායුගෝලය සමඟ ඇති වන බලපෑමෙන් සම්පූර්ණයෙන්ම වාෂ්ප වී පැහැදිලි හෝඩුවාවක් ඉතිරි නොවේ. වල්ගාතරුවේ කල්පිතයට තවදුරටත් සහය දැක්වුයේ වල්ගා තරුවේ වලිගයෙන් ඉහළ කොටස හරහා විසිරී ගිය දූවිලි හා අයිස් මගින් වායුගෝලයට පැහැදිලි කළ හැකි බලපෑමෙන් පසු සන්ධ්යාවන් කිහිපයක් පුරා යුරේසියාව පුරා නිරීක්ෂණය වූ දිලිසෙන අහසයි. (හෝ "ස්කයිග්ලෝස්" හෝ "දීප්තිමත් රාත්රී")<ref name="shoe4">{{cite journal|last=Shoemaker|first=Eugene|author-link=Eugene Merle Shoemaker|year=1983|title=Asteroid and Comet Bombardment of the Earth|journal=Annual Review of Earth and Planetary Sciences|volume=11|issue=1|pages=461–494|bibcode=1983AREPS..11..461S|doi=10.1146/annurev.ea.11.050183.002333}}</ref> ධූමකේතු උපකල්පනය 1960 ගණන් වන විට සෝවියට් තුන්ගුස්කා විමර්ශකයන් අතර පොදු පිළිගැනීමක් ලබා ගත්තේය.<ref name="shoe5">{{cite journal|last=Shoemaker|first=Eugene|author-link=Eugene Merle Shoemaker|year=1983|title=Asteroid and Comet Bombardment of the Earth|journal=Annual Review of Earth and Planetary Sciences|volume=11|issue=1|pages=461–494|bibcode=1983AREPS..11..461S|doi=10.1146/annurev.ea.11.050183.002333}}</ref>
1978 දී ස්ලෝවැක් තාරකා විද්යාඥ ඉයුබෝර් ක්රෙසාක් විසින් මෙම සිරුර වල්ගා තරුවේ එන්කේ ගේ ඛණ්ඩයක් බව යෝජනා කළේය. මෙය බ්රහස්පතිගේ කක්ෂය තුළ සම්පූර්ණයෙන්ම රැඳී සිටින වසර තුනකට වඩා කෙටි කාලයක් සහිත ආවර්තිතා වල්ගා තරුවකි. ජුනි 28-29 පමණ උපරිම ක්රියාකාරකම් සහිත වාර්ෂික උල්කාපාත වර්ෂාවක් වන බීටා ටෝරිඩ්ස් සඳහා ද එය වගකිව යුතුය.<ref>{{cite journal|last1=Kresak|first1=L'|year=1978|title=The Tunguska object – A fragment of Comet Encke|journal=Astronomical Institutes of Czechoslovakia|volume=29|issue=3|pages=129|bibcode=1978BAICz..29..129K}}</ref> තුන්ගුස්කා සිදුවීම එම වර්ෂාවේ උච්චතම ක්රියාකාරකම් සමග සමපාත වූ අතර තුන්ගුස්කා වස්තුවේ ආසන්න ගමන් පථය එන්කේ වල්ගා තරුව හි ඛණ්ඩයකින් අපේක්ෂා කළ හැකි දෙයට අනුකූල වේ.<ref name="shoe6">{{cite journal|last=Shoemaker|first=Eugene|author-link=Eugene Merle Shoemaker|year=1983|title=Asteroid and Comet Bombardment of the Earth|journal=Annual Review of Earth and Planetary Sciences|volume=11|issue=1|pages=461–494|bibcode=1983AREPS..11..461S|doi=10.1146/annurev.ea.11.050183.002333}}</ref> පොළොවේ සිට කිලෝමීටර් දස දහස් ගණනක් ඉහළින් මෙවැනි දේහ නිතර නිතර පිපිරෙන බව දැන් දන්නා කරුණකි. හමුදා චන්ද්රිකා දශක ගණනාවක් තිස්සේ මෙම පිපිරීම් නිරීක්ෂණය කර ඇත.<ref>{{cite journal|last1=Nemtchinov|first1=I.V.|last2=Jacobs|first2=C.|last3=Tagliaferri|first3=E.|year=1997|title=Analysis of Satellite Observations of Large Meteoroid Impacts|journal=[[Annals of the New York Academy of Sciences]]|volume=822|issue=1 Near–Earth Ob|pages=303–317|bibcode=1997NYASA.822..303N|doi=10.1111/j.1749-6632.1997.tb48348.x|s2cid=122983849}}</ref> 2019 වර්ෂයේදී තාරකා විද්යාඥයින් ජුලි 5-11 සහ ජූලි 21 - අගෝස්තු 10 අතර ටවුරිඩ් රංචුවේ සිට විෂ්කම්භය මීටර් 100 ක් පමණ වූ උපකල්පිත ග්රහක සෙවීය.<ref name="Plait">{{cite web |author=Phil Plait |author-link=Phil Plait |date=14 May 2019 |title=Could larger space rocks be hiding in the Beta Taurid Meteor stream? We may find out this summer |url=https://www.syfy.com/syfywire/could-larger-space-rocks-be-hiding-in-the-beta-taurid-meteor-stream-we-may-find-out-this |url-status=live |archive-url=https://web.archive.org/web/20190514152052/https://www.syfy.com/syfywire/could-larger-space-rocks-be-hiding-in-the-beta-taurid-meteor-stream-we-may-find-out-this |archive-date=14 May 2019 |access-date=17 May 2019 |publisher=Bad Astronomy}}</ref> 2020 පෙබරවාරි වන විට, එවැනි වස්තූන් සොයා ගැනීම් පිළිබඳ වාර්තා නොමැත.
1983 දී තාරකා විද්යාඥ Zdeněk Sekanina වල්ගා තරු කල්පිතය විවේචනය කරමින් පත්රිකාවක් ප්රකාශයට පත් කළේය. එවැනි නොගැඹුරු පථයක් ඔස්සේ වායුගෝලය හරහා ගමන් කරන ධූමකේතු ද්රව්ය වලින් සමන්විත ශරීරයක් විසුරුවා හැරිය යුතු බවත්, තුන්ගුස්කා ශරීරය පැහැදිලිවම පහළ වායුගෝලයට නොවෙනස්ව පැවති බවත් ඔහු පෙන්වා දුන්නේය. සෙකනිනා ද තර්ක කළේ සාක්ෂි මගින් ඝන පාෂාණමය වස්තුවක්, බොහෝ විට ග්රහක සම්භවයක් ඇති බව ය. 2001 දී ෆරිනෙල්ලා, ෆොස්චිනි සහ වෙනත් අය විසින් මෙම කල්පිතය තවදුරටත් ඉහළ නැංවීය. තුන්ගුස්කා වස්තුවේ වායුගෝලීය ගමන් පථ වලින් උපුටා ගන්නා ලද කක්ෂීය ආකෘති නිර්මාණය මත පදනම් වූ සම්භාවිතාව ගණනය කරන අධ්යනයක් නිකුත් කරන ලදී. ඔවුන් 83% ක සම්භාවිතාවකින් නිගමනය කළේ වස්තුව වල්ගා තරුවක් මත නොව, ග්රහක පටියෙන් ආරම්භ වන ග්රහක මාර්ගයක ගමන් කරන බවයි. (සම්භාවිතාව 17%)<ref name="Farinella-20012">{{cite journal|last1=Farinella|first1=Paolo|last2=Foschini|first2=L.|last3=Froeschlé|first3=Christiane|last4=Gonczi|first4=R.|last5=Jopek|first5=T. J.|last6=Longo|first6=G.|last7=Michel|first7=Patrick|year=2001|title=Probable asteroidal origin of the Tunguska Cosmic Body|url=http://www-th.bo.infn.it/tunguska/aah2886.pdf|url-status=live|journal=Astronomy & Astrophysics|volume=377|issue=3|pages=1081–1097|bibcode=2001A&A...377.1081F|doi=10.1051/0004-6361:20011054|archive-url=https://web.archive.org/web/20131009172144/http://www-th.bo.infn.it/tunguska/aah2886.pdf|archive-date=9 October 2013|access-date=1 September 2015|doi-access=free}}</ref> වල්ගා තරු කල්පිතයේ යෝජකයින් යෝජනා කර ඇත්තේ මෙම වස්තුව වායුගෝලය විනිවිද යාමට ඉඩ සලසන ගල් ආවරණයක් සහිත වඳ වී ගිය වල්ගා තරුවක් බවයි.
ග්රහක උපකල්පනයේ ඇති ප්රධාන දුෂ්කරතාවය නම්, ගල් සහිත වස්තුවක් පොළවේ ගැටෙන විශාල ආවාටයක් ඇති කළ යුතුව තිබුණත්, එවැනි ආවාටයක් හමු නොවීමයි. ග්රහකය වායුගෝලය හරහා ගමන් කිරීම නිසා විශාල පිපිරුමකින් ග්රහකය හදිසියේ විඝටනය වන ස්ථානයක් දක්වා පීඩනය සහ උෂ්ණත්වය ගොඩනැගීමට හේතු වූ බව උපකල්පනය කර ඇත. විනාශය කෙතරම් සම්පූර්ණ විය යුතුද යත්, සැලකිය යුතු ප්රමාණයේ කිසිදු ශේෂයක් නොනැසී පවතිනු ඇති අතර, පිපිරීමේදී ඉහළ වායුගෝලයට විසිරී ගිය ද්රව්ය අහස දිදුලන වීමට හේතු වන්නට ඇත. 1993 දී ප්රකාශයට පත් කරන ලද ආකෘති යෝජනා කළේ පාෂාණමය සිරුර මීටර් 60 (අඩි 200) පමණ හරස් අතට ඇති බවත්, සාමාන්ය කොන්ඩ්රයිට් සහ කාබන්ඩයොක්සයිඩ් කොන්ඩ්රයිට් අතර භෞතික ගුණ ඇති බවත්ය.{{citation needed|date=November 2014}} සාමාන්ය කාබන්ඩයොක්සයිඩ් කොන්ඩ්රයිට් ද්රව්ය ශීත කළ හොත් මිස ඉක්මනින් ජලය සමග දිය වීමට නැඹුරු වේ.<ref>{{cite news|url=https://science.nasa.gov/science-news/science-at-nasa/2000/ast01jun_1m|title=Arctic Asteroid!|access-date=8 October 2017|archive-url=https://web.archive.org/web/20170516210100/https://science.nasa.gov/science-news/science-at-nasa/2000/ast01jun_1m|archive-date=16 May 2017|website=Science at NASA|url-status=live}}</ref>
ක්රිස්ටෝපර් චයිබා සහ වෙනත් අය විසින් ගල් සහිත උල්කාපාතයක් තුන්ගුස්කා බලපෑම්කරුගේ හැසිරීම ප්රදර්ශනය කළ හැකි ක්රියාවලියක් යෝජනා කර ඇත. ඔවුන්ගේ ආකෘතීන් පෙන්නුම් කරන්නේ ශරීරයේ පහළට විරුද්ධ බලවේග එය එකට තබාගෙන සිටින සහජීවන බලයට වඩා විශාල වූ විට, එය පිඹින අතර, එහි ශක්තිය සියල්ලම පාහේ එකවර නිකුත් කරයි. එහි ප්රතිඵලය වන්නේ ආවාටයක් නොමැති අතර, හානිය තරමක් පුළුල් අරයක් පුරා බෙදා හැර ඇති අතර, පිපිරුමෙන් මුදා හරින ලද තාප ශක්තියෙන් සිදුවන සියලුම හානියයි.{{citation needed|date=June 2020}}
2008 දී උතුෂ්නිකොව් සහ රුඩෙන්කෝ විසින් සිදු කරන ලද තුන්ගුස්කා බලපෑමේ ත්රිමාන සංඛ්යාත්මක ආකෘති නිර්මාණය වල්ගා තරු කල්පිතයට සහය දක්වයි.<ref name="2008URpdf">Utyuzhnikov, S. V. and Rudenko, D. V. [https://web.archive.org/web/20180721193125/https://personalpages.manchester.ac.uk/staff/S.Utyuzhnikov/Papers/JAE_UR.pdf "An adaptive moving mesh method with application to nontstationary hypersonic flows in the atmosphere"] ''[[Proceedings of the Institution of Mechanical Engineers]]'', [[Proceedings of the Institution of Mechanical Engineers, Part G: Journal of Aerospace Engineering|Part G]], ''Journal of Aerospace Engineering'', 2008, 222 (5): 661–671</ref> ඔවුන්ගේ ප්රතිඵල අනුව, වල්ගා තරුව වායුගෝලය තුළ විසුරුවා හරින ලද අතර, වනාන්තරයේ විනාශය කම්පන තරංගය මගින් සිදු විය.
1990 ගණන් වලදී, බොලොග්නා විශ්ව විද්යාලයේ භෞතික විද්යාඥ ගුසෙප් ලෝන්ගෝ විසින් සම්බන්ධීකරණය කරන ලද ඉතාලි පර්යේෂකයන්, 1908 සිදුවීමේදී සිරවී ඇති අංශු පරීක්ෂා කිරීම සඳහා බලපෑම ඇති ප්රදේශයේ ගස්වල හරයෙන් දුම්මල නිස්සාරණය කරන ලදී. පාෂාණමය ග්රහකවල බහුලව දක්නට ලැබෙන සහ වල්ගාතරු වල කලාතුරකින් දක්නට ලැබෙන ඉහළ මට්ටමේ ද්රව්ය ඔවුන් විසින් සොයා ගන්නා ලදී.<ref>{{cite journal|last1=Longo|first1=G.|last2=Serra|first2=R.|last3=Cecchini|first3=S.|last4=Galli|first4=M.|year=1994|title=Search for microremnants of the Tunguska Cosmic Body|url=http://www-th.bo.infn.it/tunguska/papers/planetspace.html|url-status=live|journal=[[Planetary and Space Science]]|volume=42|issue=2|pages=163–177|bibcode=1994P&SS...42..163L|doi=10.1016/0032-0633(94)90028-0|archive-url=https://web.archive.org/web/20210412184723/https://www-th.bo.infn.it/tunguska/papers/planetspace.html|archive-date=12 April 2021|access-date=14 December 2007}}</ref><ref>{{cite journal|last1=Serra|first1=R.|last2=Cecchini|first2=S.|last3=Galli|first3=M.|last4=Longo|first4=G.|year=1994|title=Experimental hints on the fragmentation of the Tunguska cosmic body|url=http://www-th.bo.infn.it/tunguska/papers/pss2.html|url-status=live|journal=Planetary and Space Science|volume=42|issue=9|pages=777–783|bibcode=1994P&SS...42..777S|doi=10.1016/0032-0633(94)90120-1|archive-url=https://web.archive.org/web/20210519023519/https://www-th.bo.infn.it/tunguska/papers/pss2.html|archive-date=19 May 2021|access-date=14 December 2007}}</ref>
Kelly et al. (2009) ධූමකේතුවක් නිසා එහි බලපෑම ඇති වූ බව තර්ක කරන්නේ එහි බලපෑමෙන් පසු නිශාචර වලාකුළු දර්ශනය වීම නිසා ඉහළ වායුගෝලයේ ඇති ජල වාෂ්ප විශාල ප්රමාණයක් නිසා ඇති වූ සංසිද්ධියකි. ඔවුන් නිශාචර වලාකුළු සංසිද්ධිය නාසා හි එන්ඩෝවර් අභ්යවකාශ ෂටලයෙන් පිටවන පිහාටුවට සංසන්දනය කළහ.<ref>{{cite journal|last=Kelly|first=M.C.|author2=C. E. Seyler|author3=M. F. Larsen|date=22 June 2009|title=Two-dimensional turbulence, space shuttle plume transport in the thermosphere, and a possible relation to the Great Siberian Impact Event|journal=[[Geophysical Research Letters]]|type=Published online 22 July 2009|volume=36|issue=14|pages=L14103|bibcode=2009GeoRL..3614103K|doi=10.1029/2009GL038362|doi-access=free}}</ref><ref>{{cite web |last=Ju |first=Anne |date=24 June 2009 |title=A mystery solved: Space shuttle shows 1908 Tunguska explosion was caused by comet |url=http://news.cornell.edu/stories/2009/06/researchers-connect-shuttle-plume-1908-explosion |url-status=live |archive-url=https://web.archive.org/web/20180831223202/http://news.cornell.edu/stories/2009/06/researchers-connect-shuttle-plume-1908-explosion |archive-date=31 August 2018 |access-date=25 June 2009 |work=[[Cornell Chronicle]] |publisher=[[Cornell University]]}}</ref> 2009 දී එඩ්වඩ් ඩ්රොබිෂෙව්ස්කිගේ නායකත්වයෙන් යුත් රුසියානු පර්යේෂකයන් කණ්ඩායමක් යෝජනා කර ඇත්තේ 2005 NB<sub>56</sub> පෘථිවියට ආසන්න ග්රහකය තුන්ගුස්කා වස්තුවේ මව් ශරීරය සඳහා විය හැකි අපේක්ෂකයෙකු විය හැකි බවයි. තුන්ගුස්කා බලපෑමට දින තුනකට පෙර 1908 ජුනි 27 වන දින පෘථිවිය. 2005 NB<sub>56</sub> කක්ෂය දුර්වල ගුරුත්වාකර්ෂණ බලයේ බලපෑම් සමඟ පවා තුන්ගුස්කා වස්තුවේ ආකෘතිගත කක්ෂයට ගැලපෙන බවට කණ්ඩායම සැක කළේය.<ref>{{cite arXiv|title=A search for a present-day candidate for the Comet P/Tunguska-1908|first1=E. M.|last1=Drobyshevski|first2=T. Yu|last2=Galushina|first3=M. E.|last3=Drobyshevski|eprint=0903.3313|date=March 2009|class=astro-ph.EP}}</ref> 2013 දී, එක්සත් ජනපද-යුරෝපීය ඒකාබද්ධ කණ්ඩායමක් විසින් තුන්ගුස්කා අඩවියෙන් කොටස් විශ්ලේෂණය යකඩ උල්කාපාත සමග අනුකූල විය.<ref>{{cite web |date=1 July 2013 |title=Meteoroid, not comet, explains the 1908 Tunguska fireball |url=http://blogs.discovermagazine.com/d-brief/2013/07/01/meteoroid-not-comet-explains-the-1908-tunguska-fireball/ |url-status=dead |archive-url=https://web.archive.org/web/20130704043529/http://blogs.discovermagazine.com/d-brief/2013/07/01/meteoroid-not-comet-explains-the-1908-tunguska-fireball/ |archive-date=4 July 2013 |access-date=29 October 2013 |website=DiscoverMagazine.com blog}}</ref>
[[ගොනුව:Impacting asteroids size comparison.svg|thumb|හොබා උල්කාපාතය, බෝයිං 747 සහ New Routemaster බස් රථයක් සමඟ සැලකිය යුතු බලපෑම් වල ආසන්න ප්රමාණයන් සංසන්දනය කිරීම]]
2013 පෙබරවාරි චෙලියාබින්ස්ක් බොලයිඩ් සිදුවීම තුන්ගුස්කා ඉසව්ව සඳහා නව ආකෘති නිර්මාණය කිරීමට විද්යාඥයින්ට ප්රමාණවත් දත්ත ලබා දුන්නේය. පර්යේෂකයන් තුන්ගුස්කා සහ චෙලියාබින්ස්ක් යන දෙඅංශයෙන්ම දත්ත භාවිතා කර, සමාන උන්නතාංශවලදී කැඩී යාමේදී හෝ පුපුරා යාමේදී තුන්ගුස්කා පරිමාණයෙන් හානි සිදු කළ හැකි බොලයිඩ් සහ ඇතුල්වීමේ ගුණාංග මිලියන 50කට අධික සංයෝජන පිළිබඳ සංඛ්යානමය අධ්යයනයක් සිදු කළහ. සමහර ආකෘතීන් ගස් වැටීමේ රටාවට සමාන බලපෑම් මෙන්ම තුන්ගුස්කා හි වායුගෝලීය සහ භූ කම්පන පීඩන තරංගවලට සමාන බලපෑම් සහිත අවස්ථා නිර්මාණය කළ ගුණාංගවල සංයෝජන කෙරෙහි අවධානය යොමු කරන ලදී. විවිධ පරිගණක ආකෘති හතරක් සමාන ප්රතිඵල ලබා දුන්නේය; ඔවුන් නිගමනය කළේ තුන්ගුස්කා ප්රහාරය සඳහා කැමතිම අපේක්ෂකයා විෂ්කම්භය මීටර් 50 ත් 80 ත් (අඩි 164 සහ 262) අතර ගල් සිරුරක් වන අතර එය දළ වශයෙන් පැයට කිලෝමීටර 55,000 (පැයට සැතපුම් 34,000) වේගයෙන් වායුගෝලයට ඇතුළු වන අතර එය කිලෝමීටර 10 සිට 14 දක්වා (සැතපුම් 6 සිට 9 දක්වා) වේගයෙන් පුපුරා යයි. උන්නතාංශය, සහ මෙගාටොන් 10 සහ 30 අතරට සමාන පුපුරන ද්රව්ය ශක්තිය මුදා හැරීම. මෙය 1980 දී ශාන්ත පීටර්ස්බර්ග් ගිනිකඳු පිපිරීමට සමාන පිපිරුම් ශක්තියට සමාන වේ. පර්යේෂකයන් නිගමනය කළේ මෙම ප්රමාණයේ බලපෑම් කරන්නන් පෘථිවියට පහර දෙන්නේ සහස්ර සාමාන්ය අන්තර පරිමාණයකින් පමණක් බවයි.<ref name="nasatusk">{{cite web |last1=Smith |first1=Kimberly Ennico |date=25 June 2019 |title=Tunguska Revisited: 111-Year-Old Mystery Impact Inspires New, More Optimistic Asteroid Predictions |url=https://www.nasa.gov/feature/ames/tunguska-revisited-111-year-old-mystery-impact-inspires-new-more-optimistic-asteroid |url-status=live |archive-url=https://web.archive.org/web/20190701120323/https://www.nasa.gov/feature/ames/tunguska-revisited-111-year-old-mystery-impact-inspires-new-more-optimistic-asteroid/ |archive-date=1 July 2019 |access-date=6 July 2019 |website=NASA |ref=nasatusk}}</ref>
==== චෙකෝ විල ====
2007 ජූනි මාසයේදී, බොලොග්නා විශ්ව විද්යාලයේ විද්යාඥයන් විසින් තුන්ගුස්කා ප්රදේශයේ වැවක් මෙම සිදුවීමෙන් සිදුවිය හැකි බලපෑම් ආවාටයක් ලෙස හඳුනා ගන්නා ලදී. තුන්ගුස්කා ශරීරය මැද ගුවනේදී පිපිරී ගිය බවට ඔවුන් විවාදයක් නැත, නමුත් මීටර් 10 (අඩි 33) කැබැල්ලක් පිපිරීමෙන් බේරී බිම වැදී ඇති බව විශ්වාස කරති. චෙකෝ විල යනු මධ්යස්ථානයේ සිට උතුරු-වයඹ දෙසින් ආසන්න වශයෙන් කිලෝමීටර 8 (සැතපුම් 5.0) පමණ දුරින් පිහිටි කුඩා පාත්ර හැඩැති විලකි.<ref name="italy2">{{cite journal|last1=Gasperini|first1=L|last2=Alvisi|first2=F|last3=Biasini|first3=G|last4=Bonatti|first4=E|last5=Longo|first5=G|last6=Pipan|first6=M|last7=Ravaioli|first7=M|last8=Serra|first8=R|year=2007|title=A possible impact crater for the 1908 Tunguska Event|journal=Terra Nova|volume=19|issue=4|page=245|bibcode=2007TeNov..19..245G|doi=10.1111/j.1365-3121.2007.00742.x|doi-access=free}}</ref>
කල්පිතය වෙනත් බලපෑම් ආවාට විශේෂඥයින් විසින් විවාද කර ඇත.<ref name="rincon1">{{cite news|url=http://news.bbc.co.uk/2/hi/science/nature/6239334.stm|title=Team makes Tunguska crater claim|last=Paul|first=Rincon|date=27 June 2007|access-date=26 June 2007|archive-url=https://web.archive.org/web/20130218081649/http://news.bbc.co.uk/2/hi/science/nature/6239334.stm|archive-date=18 February 2013|publisher=BBC|url-status=live}}</ref> 1961 දී සිදු කරන ලද පරීක්ෂණයකින් චෙකෝ විලෙහි නවීන සම්භවයක් බැහැර කරන ලද අතර, විලෙහි පතුලෙහි මීටර ඝන රොන්මඩ නිධි පැවතීම අවම වශයෙන් අවුරුදු 5,000 ක වයසක් අඟවන බව පවසමින්, නමුත් වඩාත් මෑත පර්යේෂණවලින් පෙනී යන්නේ අවසාදිත ස්ථරයේ මීටරයක් හෝ ඊට වැඩි ප්රමාණයක් පමණක් බවයි. වැව් පතුලෙහි "සාමාන්ය ලැකුස්ට්රීන් අවසාදිතය", වයස අවුරුදු 100 ක් පමණ ගැඹුරට අනුරූප වේ.<ref>{{cite journal|last1=Gasperini|first1=L.|last2=Bonatti|first2=Enrico|last3=Longo|first3=Giuseppe|date=April 2008|title=Reply – Lake Cheko and the Tunguska Event: impact or non-impact?|journal=Terra Nova|volume=20|issue=2|pages=169–172|bibcode=2008TeNov..20..169G|doi=10.1111/j.1365-3121.2008.00792.x|s2cid=140554080}}</ref> වැව ටුන්ගුස්කා සිද්ධියෙන් සෑදුණු බවට උපකල්පනය සඳහා වැව පතුලේ ඇති ධ්වනි-දෝංකාර ශබ්ද සහාය සපයයි. ශබ්ද විල් පතුල සඳහා කේතුකාකාර හැඩයක් අනාවරණය විය, එය බලපෑම් ආවාටයකට අනුකූල වේ.<ref name="sciam">{{cite journal|last=Gasperini|first=L.|display-authors=etal|date=June 2008|title=The Tunguska Mystery|journal=Scientific American|volume=298|issue=6|pages=80–86|bibcode=2008SciAm.298f..80G|doi=10.1038/scientificamerican0608-80|pmid=18642546}}</ref> චුම්බක කියවීම්වලින් පෙන්නුම් කරන්නේ වැවේ ගැඹුරුම ස්ථානයට පහළින් ඇති විය හැකි මීටර ප්රමාණයේ පාෂාණ කැබැල්ලක් ගැටෙන සිරුරේ කොටසක් විය හැකි බවයි.<ref name="sciam2">{{cite journal|last=Gasperini|first=L.|display-authors=etal|date=June 2008|title=The Tunguska Mystery|journal=Scientific American|volume=298|issue=6|pages=80–86|bibcode=2008SciAm.298f..80G|doi=10.1038/scientificamerican0608-80|pmid=18642546}}</ref> අවසාන වශයෙන්, විලෙහි දිගු අක්ෂය කිලෝමීටර් 7.0 (සැතපුම් 4.3 ) පමණ දුරින් තුන්ගුස්කා පිපිරුම් මධ්යස්ථානය වෙත යොමු කරයි.<ref name="sciam3">{{cite journal|last=Gasperini|first=L.|display-authors=etal|date=June 2008|title=The Tunguska Mystery|journal=Scientific American|volume=298|issue=6|pages=80–86|bibcode=2008SciAm.298f..80G|doi=10.1038/scientificamerican0608-80|pmid=18642546}}</ref> එහි මූලාරම්භය තීරණය කිරීම සඳහා චෙකෝ විලෙහි තවමත් කටයුතු සිදු වෙමින් පවතී.<ref>{{cite news|url=http://news.nationalgeographic.com/news/2007/11/071107-russia-crater.html|title=Crater From 1908 Russian Space Impact Found, Team Says|date=7 November 2007|work=National Geographic|access-date=8 October 2017|archive-url=https://web.archive.org/web/20180515183648/https://news.nationalgeographic.com/news/2007/11/071107-russia-crater.html|archive-date=15 May 2018|url-status=live}}</ref>
අධ්යයනයේ ප්රධාන කරුණු නම්:
{{Quote|text=1908 තුන්ගුස්කා පිපිරීමේ කේන්ද්රස්ථානයට ආසන්නව සයිබීරියාවේ පිහිටි කුඩා විලක් වන චෙකෝ, කොස්මික් ශරීරයක කොටසක බලපෑමෙන් ඉතිරි වූ ආවාටයක් පිරවිය හැකිය. මෙම උපකල්පනයට සහාය දැක්වීමට හෝ ප්රතික්ෂේප කිරීමට වැවේ පතුලේ ඇති අවසාදිත හරයන් අධ්යයනය කරන ලදී. 175cm හරයක්, වැව මධ්යයට ආසන්නව එකතු කර ඇති අතර, ඉහළ c එකකින් සමන්විත වේ. රළු අවුල් සහගත ද්රව්ය උඩින් ලැකුස්ට්රීන් තැන්පතු 1m අනුපිළිවෙලක්. <sup>210</sup>Pb සහ <sup>137</sup>Cs පෙන්නුම් කරන්නේ පහළ සිට ඉහළ අනුපිළිවෙල දක්වා සංක්රමණය තුන්ගුස්කා සිදුවීමේ වේලාවට ආසන්නව සිදු වූ බවයි. පරාග විශ්ලේෂණයෙන් හෙළි වන්නේ ජලජ ශාකවල නටබුන් 1908 න් පසු ඉහළම අනුපිළිවෙලෙහි බහුලව පවතින නමුත් හරයේ පහළ 1908 කොටසෙහි නොමැති බවයි. කාබනික C, N සහ δ<sup>13</sup>C දත්ත ඇතුළුව මෙම ප්රතිඵලවලින් ඇඟවෙන්නේ චෙකෝ විල තුන්ගුස්කා සිදුවීම සිදු වූ අවස්ථාවේ ඇති වූ බවයි.
පරාග එකලස් කිරීම් ~100‐cm මට්ටමට ඉහළින් සහ පහළින් විවිධ ඒකක දෙකක් පවතින බව තහවුරු කරයි (රූපය 4). 100-cm දිග ඉහළ කොටසේ, අබීස්, බෙතුලා, ජුනිපෙරස්, ලැරික්ස්, පයිනස්, පයිසියා සහ පොපියුලස් වැනි ටයිගා වනාන්තර ගස්වල පරාග වලට අමතරව, හයිඩ්රොෆයිට් වල බහුල නටබුන් අඩංගු වේ, එනම් ''එනම්'' ජලජ ශාක යට තැන්පත් වී ඇත. අද පවතින තත්වයන්ට සමාන ලැකස්ට්රීන් තත්වයන්. සාමාන්යයෙන් මීටර් 3-4ක් පමණ ගැඹුරට ජලයේ වැඩෙන (Callitriche, Hottonia, Lemna, Hydrocharis, Myriophyllum, Nuphar, Nymphaea, Potamogeton, Sagittaria) නිදහසේ පාවෙන ශාක සහ මුල් බැසගත් ශාක යන දෙකම මේවාට ඇතුළත් වේ. ඊට වෙනස්ව, පහළ ඒකකයේ (සෙන්ටිමීටර 100 ට අඩු) බහුලව වනාන්තර ගස් පරාග අඩංගු වේ, නමුත් හයිඩ්රොෆයිට් නොමැත, එයින් ඇඟවෙන්නේ එකල විලක් නොතිබූ නමුත් වගුරු බිමක වැඩෙන ටයිගා වනාන්තරයකි (රූපය 5). පරාග සහ ක්ෂුද්ර අඟුරු ටයිගා වනාන්තරයේ හරයේ පහළ සිට ඉහළට ප්රගතිශීලී අඩුවීමක් පෙන්නුම් කරයි. මෙම අඩු කිරීම ගිනි (~100 cm ට අඩු දේශීය කථාංග දෙකක්), පසුව TE සහ වැව ගොඩනැගීම (100 සහ 90 සෙ.මී. අතර) සහ පසුව ඇති වූ ගිනිගැනීම් (ඉහළ 40 cm හි එක් දේශීය ගින්නක්) නිසා ඇති විය හැක.)<ref>{{Cite journal|first1=Luca|last1= Gasperini |first2=Enrico|last2=Bonatti|first3=Sonia|last3= Albertazzi|first4=Luisa|last4=Forlani|first5=Carla A.|last5=Accorsi|first6=Giuseppe|last6=Longo|first7=Mariangela|last7=Ravaioli|first8=Francesca|last8=Alvisi|first9=Alina|last9=Polonia |first10=Fabio|last10=Sacchetti|title=Sediments from Lake Cheko (Siberia), a possible impact crater for the 1908 Tunguska Event|journal=Terra Nova|volume=21|number=6|pages=489–494|date=December 2009|doi=10.1111/j.1365-3121.2009.00906.x|bibcode=2009TeNov..21..489G|doi-access=free}}</ref>}}
2017 දී රුසියානු විද්යාඥයින් විසින් කරන ලද නව පර්යේෂණ මගින් තුන්ගුස්කා සිදුවීමෙන් චෙකෝ විල නිර්මාණය වූ බවට ඇති න්යාය ප්රතික්ෂේප කිරීමක් පෙන්වා දෙන ලදී. වැව වසර 280ක් පැරණි හෝ ඊටත් වඩා පැරණි බව තීරණය කිරීමට ඔවුහු පාංශු පර්යේෂණ යොදා ගත්හ. ඕනෑම අවස්ථාවක තුන්ගුස්කා සිදුවීමට වඩා විල පැහැදිලිවම පැරණි බව පෙනේ.<ref>{{Cite news|url=http://ec-rgo-sfo.com/novosti/1183-ozero-cheko-starshe-tungusskogo-meteorita|title=ОЗЕРО ЧЕКО СТАРШЕ ТУНГУССКОГО МЕТЕОРИТА|last=Лебедева|first=Юлия|access-date=17 January 2018|archive-url=https://web.archive.org/web/20180118064548/http://ec-rgo-sfo.com/novosti/1183-ozero-cheko-starshe-tungusskogo-meteorita|archive-date=18 January 2018|url-status=live}}</ref> චෙකෝ විල පතුලේ ඇති පස් විශ්ලේෂණය කිරීමේදී, ඔවුන් 20 වන සියවසේ මැද භාගයේ නොවායා සෙම්ලියා හි න්යෂ්ටික අත්හදා බැලීම් වලින් රේඩියනියුක්ලයිඩ් දූෂණය ස්ථරයක් හඳුනා ගත්හ. මෙම ස්ථරයේ ගැඹුර වසරකට මිලිමීටර් 3.6 සහ 4.6 අතර සාමාන්ය වාර්ෂික අවසාදිත අනුපාතයක් ලබා දුන්නේය. මෙම අවසාදිත අගයන් ගැස්පෙරිනි එට් අල් විසින් ගණනය කරන ලද අගයෙන් අඩකට වඩා අඩුය. 1999 දී චෙකෝ විලෙන් ඔවුන් ලබාගත් හරය පිළිබඳ ඔවුන්ගේ විශ්ලේෂණය පිළිබඳ ඔවුන්ගේ 2009 ප්රකාශනයේ. 2017 දී රුසියානු විද්යාඥයන්, විල පතුලේ සිට ඇදී ගිය මිලිමීටර් 1260 ක දිග හර සාම්පලයේ අවම වශයෙන් එවැනි වාර්ෂික වෑල්ව් 280 ක් ගණන් කර ඇති අතර එය වයස අවුරුදු නියෝජනය කරයි. තුන්ගුස්කා සිදුවීමට වඩා විල පැරණිය.<ref>{{cite journal|last1=Rogozin|first1=D.Y.|last2=Darin|first2=A. V.|year=2017|title=Sedimentation Rate in Cheko Lake (Evenkia, Siberia): New Evidence on the Problem of the 1908 Tunguska Event|url=https://www.researchgate.net/publication/282458617|journal=Doklady Earth Sciences|volume=476|issue=2|page=1226|bibcode=2017DokES.476.1226R|doi=10.1134/S1028334X17100269|access-date=25 April 2020|s2cid=134128473}}</ref>
මීට අමතරව, බලපෑම් භෞතික විද්යාවේ ගැටළු තිබේ: නියම ප්රමාණයේ ගල් සහිත උල්කාපාතයකට වායුගෝලීය ගමන් මග නොනැසී පැවතීමට අවශ්ය යාන්ත්රික ශක්තියක් තිබිය නොහැක, නමුත් තවමත් ප්රමාණයෙන් ආවාටයක් කැණීමට තරම් විශාල ප්රවේගයක් රඳවා තබා ගනී.<ref>{{cite journal|last1=Collins|first1=G.S.|last2=Artemieva|first2=N.|year=2008|title=Evidence that Lake Cheko is not an impact crater|journal=Terra Nova|volume=20|issue=2|pages=165–168|bibcode=2008TeNov..20..165C|doi=10.1111/j.1365-3121.2008.00791.x|s2cid=31459798}}</ref>
=== භූ භෞතික උපකල්පන ===
තුන්ගුස්කා පිපිරුම කුඩා ග්රහකයක බලපෑමෙන් සිදු වූවක් බව විද්යාත්මක එකඟතාවක් වුවද, සමහර විසම්මුතීන් ඇත. තාරකා භෞතික විද්යාඥ වුල්ෆ්ගැන්ග් කුන්ඩ්ට් යෝජනා කර ඇත්තේ තුන්ගුස්කා සිදුවීමට හේතු වී ඇත්තේ පෘථිවි කබොල තුලින් ස්වභාවික වායු ටොන් මිලියන 10ක් මුදා හැරීම සහ ඉන් අනතුරුව පුපුරා යාම බවයි.<ref>{{cite journal|last=Kundt|first=W.|year=2001|title=The 1908 Tunguska catastrophe|url=http://tejas.serc.iisc.ernet.in/~currsci/aug252001/399.pdf|url-status=dead|journal=[[Current Science]]|volume=81|pages=399–407|archive-url=https://web.archive.org/web/20160304075707/http://tejas.serc.iisc.ernet.in/~currsci/aug252001/399.pdf|archive-date=4 March 2016}}</ref><ref>{{cite journal|last=Jones|first=N.|date=7 September 2002|title=Did blast from below destroy Tunguska?|url=https://www.newscientist.com/article/mg17523591.900-did-blast-from-below-destroy-tunguska.html|url-status=live|journal=[[New Scientist]]|volume=2359|page=14|archive-url=https://web.archive.org/web/20150531221204/http://www.newscientist.com/article/mg17523591.900-did-blast-from-below-destroy-tunguska.html|archive-date=31 May 2015|access-date=17 September 2017}}</ref><ref>{{cite book|first=W.|last=Kundt|contribution=Tunguska (1908) and its relevance for comet/asteroid impact statistics|title=Comet/Asteroid Impacts and Human Society|editor1-first=P. T.|editor1-last=Bobrowsky|editor2-first=H.|editor2-last=Rickman|year=2007|pages=331–339|publisher=Springer}}</ref><ref>[http://www.spacedaily.com/2006/080629040419.kk7pcjnx.html "100 years on, mystery shrouds massive 'cosmic impact' in Russia"] {{Webarchive|url=https://web.archive.org/web/20150924104203/http://www.spacedaily.com/2006/080629040419.kk7pcjnx.html|date=24 September 2015}}, [[Agence France-Presse]], 29 June 2008. Retrieved 8 October 2017.</ref><ref>Choi, Charles Q., [http://www.foxnews.com/story/2008/07/04/massive-tunguska-blast-still-unsolved-100-years-later/ "Massive Tunguska Blast Still Unsolved 100 Years Later"] {{Webarchive|url=https://web.archive.org/web/20130921154738/http://www.foxnews.com/story/2008/07/04/massive-tunguska-blast-still-unsolved-100-years-later/|date=21 September 2013}}, [[Fox News Channel]], 4 July 2008. Retrieved 8 October 2017.</ref> මූලික අදහස නම්, ස්වභාවික වායුව කබොලෙන් කාන්දු වූ අතර පසුව වායුගෝලයේ සමාන ඝනත්වය උසට නැඟී ඇත; එතැන් සිට, එය යම් ආකාරයක වික්රියාවක, සුළඟට ගසාගෙන ගිය අතර, අවසානයේදී අකුණු වැනි ජ්වලන ප්රභවයක් සොයා ගන්නා ලදී. වායුව දැල්වූ පසු, ගිනි දැල් දිගේ ඉරි තැළුණු අතර, පසුව පොළවේ කාන්දු වූ මූලාශ්රය දක්වා පහළට, පිපිරීමක් ඇති විය.
සමාන වර්නෙෂොට් කල්පිතය තුන්ගුස්කා සිදුවීමට විය හැකි හේතුවක් ලෙස ද යෝජනා කර ඇත.<ref>{{cite journal|last1=Phipps Morgan|first1=J.|last2=Reston|first2=T. J.|last3=Ranero|first3=C. R.|year=2004|title=Contemporaneous mass extinctions, continental flood basalts, and 'impact signals': are mantle plume-induced lithospheric gas explosions the causal link?|url=http://www.geo.cornell.edu/eas/PeoplePlaces/Faculty/JPM/VerneshotEPSL2004.pdf|url-status=live|journal=[[Earth and Planetary Science Letters]]|volume=217|issue=3–4|pages=263–284|bibcode=2004E&PSL.217..263P|doi=10.1016/s0012-821x(03)00602-2|archive-url=https://web.archive.org/web/20130607003245/http://www.geo.cornell.edu/eas/PeoplePlaces/Faculty/JPM/VerneshotEPSL2004.pdf|archive-date=7 June 2013|access-date=1 July 2008}}</ref><ref>{{cite journal|last1=Vannucchi|first1=P.|last2=Morgan|first2=J. P.|last3=Della Lunga|first3=D.|last4=Andronicos|first4=C. L.|last5=Morgan|first5=W. J.|year=2015|title=Direct evidence of ancient shock metamorphism at the site of the 1908 Tunguska event|url=https://zenodo.org/record/894872|url-status=live|journal=[[Earth and Planetary Science Letters]]|volume=409|pages=168–174|bibcode=2015E&PSL.409..168V|doi=10.1016/j.epsl.2014.11.001|archive-url=https://web.archive.org/web/20190430125540/https://zenodo.org/record/894872|archive-date=30 April 2019|access-date=18 May 2018}}</ref> වෙනත් පර්යේෂණ මගින් සිද්ධිය සඳහා භූ භෞතික යාන්ත්රණයක් යෝජනා කර ඇත.<ref>{{cite journal|last=Ol'khovatov|first=A. Yu.|year=2003|title=Geophysical circumstances of the 1908 Tunguska Event in Siberia, Russia|url=http://olkhov.narod.ru/earthmoonplanets.pdf|url-status=live|journal=[[Earth, Moon, and Planets]]|volume=93|issue=3|pages=163–173|bibcode=2003EM&P...93..163O|doi=10.1023/B:MOON.0000047474.85788.01|archive-url=https://web.archive.org/web/20150701173555/http://olkhov.narod.ru/earthmoonplanets.pdf|archive-date=1 July 2015|access-date=1 July 2015|s2cid=122496016}}</ref><ref>Sklublov G. T., Marin Yu. B., Skublov S. G., Bidyukov B. F., Logunova L. N., Gembitsky V. V., Nechaeva E. S. (2010), [http://olkhov.narod.ru/skublov_2010.pdf "Geological and mineralogical-geochemical peculiarities of loose sediments and primary rocks in epicenter of Tunguskaya catastrophe in 1908"] {{Webarchive|url=https://web.archive.org/web/20150701185841/http://olkhov.narod.ru/skublov_2010.pdf|date=1 July 2015}}, ''Proceedings of the Russian Mineralogical Society'', 139(1): 111–135 [in Russian, with English abstract].</ref><ref>Skublov G. T., Marin Yu. B., Skublov S. G., Logunova L. N., Nechaeva E. S., Savichev A. A. (2011), [http://olkhov.narod.ru/tunguska_skublov_2011.pdf "Mineralogical-geochemical features of primary rocks, loose sediments and catastrophic mosses in the Northern Swamp area (region of the Tunguska catastrophe in 1908)"] {{Webarchive|url=https://web.archive.org/web/20150701191558/http://olkhov.narod.ru/tunguska_skublov_2011.pdf|date=1 July 2015}}, ''Proceedings of the Russian Mineralogical Society'', 140(3): 120–138 [in Russian with English abstract].</ref>
== සමාන සිදුවීම් ==
2013 පෙබරවාරි 15 වන දින රුසියාවේ ඌරල් දිස්ත්රික්කයේ චෙලියාබින්ස්ක් හි ජනාකීර්ණ ප්රදේශයකට කුඩා වායු පිපිරීමක් සිදු විය. පිපිරෙන උල්කාපාතය මීටර් 17-20 (අඩි 56-66 ) පමණ වූ ග්රහකයක් බව තීරණය විය. එහි ඇස්තමේන්තුගත ආරම්භක ස්කන්ධය ටොන් 11,000 ක් වූ අතර ආසන්න වශයෙන් කිලෝ ටොන් 500 ක ශක්තියක් මුදා හැරීමකින් පුපුරා ගියේය.<ref name="nasatusk2">{{cite web |last1=Smith |first1=Kimberly Ennico |date=25 June 2019 |title=Tunguska Revisited: 111-Year-Old Mystery Impact Inspires New, More Optimistic Asteroid Predictions |url=https://www.nasa.gov/feature/ames/tunguska-revisited-111-year-old-mystery-impact-inspires-new-more-optimistic-asteroid |url-status=live |archive-url=https://web.archive.org/web/20190701120323/https://www.nasa.gov/feature/ames/tunguska-revisited-111-year-old-mystery-impact-inspires-new-more-optimistic-asteroid/ |archive-date=1 July 2019 |access-date=6 July 2019 |website=NASA |ref=nasatusk}}</ref> වාතය පුපුරා යාමෙන් තුවාල 1,200 කට වැඩි ප්රමාණයක් ඇති විය, ඒ ප්රධාන වශයෙන් එහි කම්පන තරංගයෙන් කැඩී ගිය ජනේල වලින් වැටෙන කැඩුණු වීදුරු වලිනි.<ref>{{cite news|url=https://www.reuters.com/article/uk-russia-meteorite/meteorite-hits-central-russia-more-than-500-people-hurt-idUSLNE91E00G20130215|title=Meteorite hits central Russia, more than 500 people hurt|last1=Shurmina|first1=Natalia|work=Reuters|access-date=8 October 2017|archive-url=https://web.archive.org/web/20171009041833/http://www.reuters.com/article/uk-russia-meteorite/meteorite-hits-central-russia-more-than-500-people-hurt-idUSLNE91E00G20130215|archive-date=9 October 2017|last2=Kuzmin|first2=Andrey|url-status=live}}</ref>
== යොමු කිරීම් ==
k25qd3q9800dopudo0fukn3g28nkjca
මිලිටරි
0
52939
790934
302452
2026-05-20T03:37:03Z
Lee
85
790934
wikitext
text/x-wiki
{{War}}
පවත්න හෝ ඇතිවියහැකි යයි වීහ්වාස කරන තර්ජන වලට විරුද්ධව සටන්කර ස්වකීය රට හෝ රාජ්ය ආයතන ආරක්ෂාකරගැනීම සදහා අවි භාවිතය ඇතුළුව මරණ සිදුවිය හැකි මට්ටමේ බලයන් යෙදවීමට රජයක් හෝ සමාජය විසින් හෝ අධිකාරිය ලබාදීඇති සංවිධාන '''මිලිටරි''' නම්වේ.
== අමතර අවධානටය ==
* [[සන්නද්ධ හමුදා]]
{{wikt}}
{{authority control}}
[[ප්රවර්ගය:මිලිටරි| ]]
9s04qrdbm57pf23gvdyf5j8vu1msj57
790936
790934
2026-05-20T03:41:52Z
Lee
85
790936
wikitext
text/x-wiki
{{War}}
පවත්න හෝ ඇතිවියහැකි යයි වීහ්වාස කරන තර්ජන වලට විරුද්ධව සටන්කර ස්වකීය රට හෝ රාජ්ය ආයතන ආරක්ෂාකරගැනීම සදහා අවි භාවිතය ඇතුළුව මරණ සිදුවිය හැකි මට්ටමේ බලයන් යෙදවීමට රජයක් හෝ සමාජය විසින් හෝ අධිකාරිය ලබාදීඇති සංවිධාන '''මිලිටරි''' නම්වේ.
== අමතර අවධානටය ==
* [[සන්නද්ධ හමුදා]]
{{wikt}}
{{Military and war}}
{{authority control}}
[[ප්රවර්ගය:මිලිටරි| ]]
7l4kgumeegsvazrd5fovtjo69v5dw6q
බටහිර ඉන්දීය කොදෙව් ක්රිකට් කණ්ඩායම
0
59164
790952
783909
2026-05-20T10:14:20Z
~2026-30237-88
79044
/* */
790952
wikitext
text/x-wiki
{{සමුද්දේශ විරහිත|date=ජනවාරි 2025}}{{Update|part=|date=ජනවාරි 2025}}{{තොරතුරුකොටුව ටෙස්ට් කණ්ඩායම
| team_name = බටහිර ඉන්දීය කොදෙව්
| image = West Indies Cricket Cap Insignia.svg
| image_caption = බටහිර ඉන්දීය කොදෙව් ක්රිකට් ලාංඡනය
| test status year = 1928
| current captain = [[ජේසන් හෝල්ඩර්]]<br> (ටෙස්ට් සහ එදිජා)<br> [[කාලෝස් බ්රැත්වේට්]]<br> (වි20)
| current coach = [[ස්ටුවර්ට් ලෝ]]
| first test match = එංගලන්තයට එරෙහිව<br> ලන්ඩන් හිදී<br> 23–26 ජූනි 1928
| first odi match = එංගලන්තයට එරෙහිව<br> ලීඩ්ස් හිදී<br> 5 සැප්තැම්බර් 1973
| first t20i match = නවසීලන්තයට එරෙහිව<br> ඕක්ලන්ඩ් හිදී<br> 16 පෙබරවාරි 2006
| h_pattern_la =
| h_pattern_b = _Spikesonwhite
| h_pattern_ra =
| h_pattern_pants =
| h_leftarm = FFFFFF
| h_body = 720524
| h_rightarm = FFFFFF
| h_pants = FFFFFF
| a_pattern_la = _yellowborder
| a_pattern_b =
| a_pattern_ra = _yellowborder
| a_pattern_pants = _yellowsides
| a_leftarm = 720524
| a_body = 720524
| a_rightarm = 720524
| a_pants = 720524
| t_pattern_la = _yellow_thin_border
| t_pattern_b = _win_t20wc26
| t_pattern_ra = _yellow_thin_border
| t_pattern_pants = _yellowsides
| t_leftarm = 720524
| t_body = 720524
| t_rightarm = 720524
| t_pants = 720524
| asofdate = 12 August 2023
}}
'''බටහිර ඉන්දීය කොදෙව්''' ලෙසින් හෝ ග්රාම්ය ලෙසින් '''වින්ඩීස්''' ලෙසින්ද හැඳින්වෙන, '''බටහිර ඉන්දීය කොදෙව් ක්රිකට් කණ්ඩායම''' යනු, ප්රධාන වශයෙන් ඉංග්රීසි -කතාකරන [[කැරිබියානු රටවල්]], බ්රිතාන්ය පරායත්ත සහ බ්රිතාන්ය-නොවන පරායත්ත 15 ක ක්රීඩා සන්ධීයනයක් නිරූපණය කරන, බහු-ජාතික [[ක්රිකට්]] කණ්ඩායමකි.
==ඉතිහාසය==
==කැරිබියානු රටවල්වල අනෙකුත් ක්රිකට් ආයතන==
* [[බාබඩෝස් ක්රිකට් සංගමය]] (BCA)
* [[ගයනා ක්රිකට් ආයතනය]] (GCB)
* [[ජැමෙයිකා ක්රිකට් සංගමය]] (JCA)
* [[ට්රිනිඩැඩ් සහ ටොබෑගෝ ක්රිකට් ආයතනය]] (TTCB)
* [[ලීවෝර්ඩ් දුපත් ක්රිකට් ආයතනය]] (LICB)
* [[වින්ඩ්වෝර්ඩ් දූපත් ක්රිකට් ආයතනය]] (WICBC)
==මුලාශ්ර==
dhytixi22wcsb9wm1tutv53nv5ekvec
භූමී පේඩ්නේකර්
0
89569
790962
759653
2026-05-20T11:32:59Z
Yasasuru
23090
/* */
790962
wikitext
text/x-wiki
{{short description|ඉන්දියානු නිළිය}}
{{Use dmy dates|date=November 2020}}
{{Infobox person
| name = භූමි පේඩ්නේකර
| image = Bhumi Pednekar promoting Sonchiriya.jpg
| image_size =
| caption = පේඩ්නේකර් ''[[සෝන්චිරියා]]'' හි ප්රවර්ධන උත්සවයක දී 2019
| birth_date = {{Birth date and age|1989|07|18|df=y}}
| birth_place = [[බොම්බේ]], [[මහරාෂ්ට්ර]], ඉන්දියාව
| occupation = නිළිය
| nationality =
| years_active = 2015–වර්තමානය
}}
'''භූමි පේඩ්නේකර්''' (උපත 1989 ජූලි 18) යනුවෙන් හැඳින්වෙන්නෙ [[බොලිවුඩ්|හින්දී චිත්රපටවල]] පෙනීසිටින නිළියකි. සය වසරක් [[යශ් රාජ් ෆිල්ම්ස්]] හි සහකාර නළුවරණ අධ්යක්ෂ ලෙස කටයුතු කිරීමෙන් පසු ඇය රංගනයට පිවිසියේ එම සමාගමේම ප්රේම වෘත්තාන්ත ප්රහසන චිත්රපටයක් වූ ''[[ඩම් ලගා කේ හඊශා]]'' (2015) හි තරබාරු මනාලියකගේ චරිතය තුළිනි. ඒ සඳහා ඇයට [[හොඳම කාන්තා ප්රවිෂ්ටය සඳහා ෆිල්ම්ෆෙයාර් සම්මානය]] හිමි විය.
Pednekar rose to prominence by playing headstrong small-town women in the comedy-dramas ''[[Toilet: Ek Prem Katha]]'' (2017), ''[[Shubh Mangal Saavdhan]]'' (2017), ''[[Sonchiriya]]'' (2019), ''[[Bala (2019 film)|Bala]]'' (2019), and ''[[Pati Patni Aur Woh (2019 film)|Pati Patni Aur Woh]]'' (2019).<ref name="small town">{{cite news|last=Dubey|first=Rachana|url=https://timesofindia.indiatimes.com/entertainment/hindi/bollywood/news/bhumi-pednekar-i-dont-mind-being-the-face-of-small-town-india-it-is-home-to-beautiful-stories/articleshow/71607615.cms|title=Bhumi Pednekar: I don't mind being the face of small-town India, it is home to beautiful stories|work=The Times of India|date=16 October 2019|access-date=27 December 2019|archive-date=16 March 2020|archive-url=https://web.archive.org/web/20200316023113/https://timesofindia.indiatimes.com/entertainment/hindi/bollywood/news/bhumi-pednekar-i-dont-mind-being-the-face-of-small-town-india-it-is-home-to-beautiful-stories/articleshow/71607615.cms|url-status=live}}</ref> For her portrayal of the septuagenarian sharpshooter [[Chandro Tomar]] in ''[[Saand Ki Aankh]]'' (2019), she shared the [[Filmfare Critics Award for Best Actress]], along with [[Taapsee Pannu]].<ref>{{cite news|url=https://timesofindia.indiatimes.com/entertainment/hindi/bollywood/news/65th-amazon-filmfare-awards-2020-live-updates-and-filmfare-awards-winners/liveblog/74145715.cms|title=65th Amazon Filmfare Awards 2020 live updates|work=The Times of India|date=15 February 2020|access-date=15 February 2020}}</ref>
== References ==
{{reflist}}
== External links ==
{{Commons category}}
* {{Twitter}}
* {{IMDb name|6277267}}
* {{Bollywood Hungama person|bhumi-pednekar}}
{{Navboxes
|title = Awards for Bhumi Pednekar
|list=
{{FilmfareAwardBestFemaleDebut}}
{{FilmfareCriticsAwardBestActress}}
{{ScreenAwardBestFemaleDebut}}
{{IIFAAwardBestFemaleDebut}}
{{Zee Cine Award for Best Female Debut}}
{{ZeeCineAwardBestSupportingActorFemale}}
}}
{{authority control}}
{{DEFAULTSORT:Pednekar, Bhumi}}
[[ප්රවර්ගය:1989 උපත්]]
[[ප්රවර්ගය:ජීවමාන ජනයා]]
[[ප්රවර්ගය:මුම්බායිහි නිළියෝ]]
[[Category:Actresses in Hindi cinema]]
[[ප්රවර්ගය:21 වන සියවස තුළ ඉන්දියානු නිළියෝ]]
[[Category:Marathi people]]
[[Category:Indian film actresses]]
[[Category:Zee Cine Awards winners]]
[[Category:Indian people of Marathi descent]]
[[Category:People of Haryanvi descent]]
[[Category:Forbes 30 Under 30 recipients]]
antdjt2jlmv7cvzermxcncvfmrmkkwj
790964
790962
2026-05-20T11:40:07Z
Yasasuru
23090
/* */
790964
wikitext
text/x-wiki
{{short description|ඉන්දියානු නිළිය}}
{{Use dmy dates|date=November 2020}}
{{Infobox person
| name = භූමි පේඩ්නේකර
| image = Bhumi Pednekar promoting Sonchiriya.jpg
| image_size =
| caption = පේඩ්නේකර් ''[[සෝන්චිරියා]]'' හි ප්රවර්ධන උත්සවයක දී 2019
| birth_date = {{Birth date and age|1989|07|18|df=y}}
| birth_place = [[බොම්බේ]], [[මහරාෂ්ට්ර]], ඉන්දියාව
| occupation = නිළිය
| nationality =
| years_active = 2015–වර්තමානය
}}
'''භූමි පේඩ්නේකර්''' (උපත 1989 ජූලි 18) යනුවෙන් හැඳින්වෙන්නෙ [[බොලිවුඩ්|හින්දී චිත්රපටවල]] පෙනීසිටින නිළියකි. සය වසරක් [[යශ් රාජ් ෆිල්ම්ස්]] හි සහකාර නළුවරණ අධ්යක්ෂ ලෙස කටයුතු කිරීමෙන් පසු ඇය රංගනයට පිවිසියේ එම සමාගමේම ප්රේම වෘත්තාන්ත ප්රහසන චිත්රපටයක් වූ ''[[ඩම් ලගා කේ හඊශා]]'' (2015) හි තරබාරු මනාලියකගේ චරිතය තුළිනි. ඒ සඳහා ඇයට [[හොඳම කාන්තා ප්රවිෂ්ටය සඳහා ෆිල්ම්ෆෙයාර් සම්මානය]] හිමි විය.
පේඩ්නේකර් ප්රසිද්ධියට පත්වූයේ ප්රහසන නාට්ය චිත්රපටවල ඇය නිරූපණය කළ ශක්තිමත් කාන්තා චරිත නිසායි. මේ අතරට ''[[ටොයිලට්: එක් ප්රේම්
කථා]]'' (2017), ''[[ශුභ් මංගල් සාව්ධාන්]]'' (2017), ''[[සෝන්චිරියා]]'' (2019), ''[[බාලා (2019 චිත්රපටය)|බාලා]]'' (2019), සහ ''[[පති පත්නී ඕර් වෝහ් (2019 චිත්රපටය)|පති පත්නී ඕර් වෝහ්]]'' (2019) වැනි චිත්රපට අයත් ය.<ref name="small town">{{cite news|last=Dubey|first=Rachana|url=https://timesofindia.indiatimes.com/entertainment/hindi/bollywood/news/bhumi-pednekar-i-dont-mind-being-the-face-of-small-town-india-it-is-home-to-beautiful-stories/articleshow/71607615.cms|title=Bhumi Pednekar: I don't mind being the face of small-town India, it is home to beautiful stories|work=The Times of India|date=16 October 2019|access-date=27 December 2019|archive-date=16 March 2020|archive-url=https://web.archive.org/web/20200316023113/https://timesofindia.indiatimes.com/entertainment/hindi/bollywood/news/bhumi-pednekar-i-dont-mind-being-the-face-of-small-town-india-it-is-home-to-beautiful-stories/articleshow/71607615.cms|url-status=live}}</ref> ''[[සාන්ද් කී ආන්ඛ්]]'' (2019) චිත්රපටයේ ඇය නිරූපණය කළ [[චන්ද්රෝ තෝමාර්]] නම් වියපත් චරිතය සඳහා ඇයට [[හොඳම නිළිය සඳහා වූ ෆිල්ම්ෆෙයාර් විචාරක සම්මානය]] හිමිවූයේ [[තාප්සී පන්නු]] සමඟ සමව ය.<ref>{{cite news|url=https://timesofindia.indiatimes.com/entertainment/hindi/bollywood/news/65th-amazon-filmfare-awards-2020-live-updates-and-filmfare-awards-winners/liveblog/74145715.cms|title=65th Amazon Filmfare Awards 2020 live updates|work=The Times of India|date=15 February 2020|access-date=15 February 2020}}</ref>
== References ==
{{reflist}}
== External links ==
{{Commons category}}
* {{Twitter}}
* {{IMDb name|6277267}}
* {{Bollywood Hungama person|bhumi-pednekar}}
{{Navboxes
|title = Awards for Bhumi Pednekar
|list=
{{FilmfareAwardBestFemaleDebut}}
{{FilmfareCriticsAwardBestActress}}
{{ScreenAwardBestFemaleDebut}}
{{IIFAAwardBestFemaleDebut}}
{{Zee Cine Award for Best Female Debut}}
{{ZeeCineAwardBestSupportingActorFemale}}
}}
{{authority control}}
{{DEFAULTSORT:Pednekar, Bhumi}}
[[ප්රවර්ගය:1989 උපත්]]
[[ප්රවර්ගය:ජීවමාන ජනයා]]
[[ප්රවර්ගය:මුම්බායිහි නිළියෝ]]
[[Category:Actresses in Hindi cinema]]
[[ප්රවර්ගය:21 වන සියවස තුළ ඉන්දියානු නිළියෝ]]
[[Category:Marathi people]]
[[Category:Indian film actresses]]
[[Category:Zee Cine Awards winners]]
[[Category:Indian people of Marathi descent]]
[[Category:People of Haryanvi descent]]
[[Category:Forbes 30 Under 30 recipients]]
dc74qfru0g3i3pmiaio2la0vp3zuocp
790965
790964
2026-05-20T11:41:41Z
Yasasuru
23090
790965
wikitext
text/x-wiki
{{short description|ඉන්දියානු නිළිය}}
{{Use dmy dates|date=November 2020}}
{{Infobox person
| name = භූමි පේඩ්නේකර
| image = Bhumi Pednekar promoting Sonchiriya.jpg
| image_size =
| caption = පේඩ්නේකර් ''[[සෝන්චිරියා]]'' හි ප්රවර්ධන උත්සවයක දී 2019
| birth_date = {{Birth date and age|1989|07|18|df=y}}
| birth_place = [[බොම්බේ]], [[මහරාෂ්ට්ර]], ඉන්දියාව
| occupation = නිළිය
| nationality =
| years_active = 2015–වර්තමානය
}}
'''භූමි පේඩ්නේකර්''' (උපත 1989 ජූලි 18) යනුවෙන් හැඳින්වෙන්නෙ [[බොලිවුඩ්|හින්දී චිත්රපටවල]] පෙනීසිටින නිළියකි. සය වසරක් [[යශ් රාජ් ෆිල්ම්ස්]] හි සහකාර නළුවරණ අධ්යක්ෂ ලෙස කටයුතු කිරීමෙන් පසු ඇය රංගනයට පිවිසියේ එම සමාගමේම ප්රේම වෘත්තාන්ත ප්රහසන චිත්රපටයක් වූ ''[[ඩම් ලගා කේ හඊශා]]'' (2015) හි තරබාරු මනාලියකගේ චරිතය තුළිනි. ඒ සඳහා ඇයට [[හොඳම කාන්තා ප්රවිෂ්ටය සඳහා ෆිල්ම්ෆෙයාර් සම්මානය]] හිමි විය.
පේඩ්නේකර් ප්රසිද්ධියට පත්වූයේ ප්රහසන නාට්ය චිත්රපටවල ඇය නිරූපණය කළ ශක්තිමත් කාන්තා චරිත නිසායි. මේ අතරට ''[[ටොයිලට්: එක් ප්රේම්
කථා]]'' (2017), ''[[ශුභ් මංගල් සාව්ධාන්]]'' (2017), ''[[සෝන්චිරියා]]'' (2019), ''[[බාලා (2019 චිත්රපටය)|බාලා]]'' (2019), සහ ''[[පති පත්නී ඕර් වෝහ් (2019 චිත්රපටය)|පති පත්නී ඕර් වෝහ්]]'' (2019) වැනි චිත්රපට අයත් ය.<ref name="small town">{{cite news|last=Dubey|first=Rachana|url=https://timesofindia.indiatimes.com/entertainment/hindi/bollywood/news/bhumi-pednekar-i-dont-mind-being-the-face-of-small-town-india-it-is-home-to-beautiful-stories/articleshow/71607615.cms|title=Bhumi Pednekar: I don't mind being the face of small-town India, it is home to beautiful stories|work=The Times of India|date=16 October 2019|access-date=27 December 2019|archive-date=16 March 2020|archive-url=https://web.archive.org/web/20200316023113/https://timesofindia.indiatimes.com/entertainment/hindi/bollywood/news/bhumi-pednekar-i-dont-mind-being-the-face-of-small-town-india-it-is-home-to-beautiful-stories/articleshow/71607615.cms|url-status=live}}</ref> ''[[සාන්ද් කී ආන්ඛ්]]'' (2019) චිත්රපටයේ ඇය නිරූපණය කළ [[චන්ද්රෝ තෝමාර්]] නම් වියපත් චරිතය සඳහා ඇයට [[හොඳම නිළිය සඳහා වූ ෆිල්ම්ෆෙයාර් විචාරක සම්මානය]] හිමිවූයේ [[තාප්සී පන්නු]] සමඟ සමව ය.<ref>{{cite news|url=https://timesofindia.indiatimes.com/entertainment/hindi/bollywood/news/65th-amazon-filmfare-awards-2020-live-updates-and-filmfare-awards-winners/liveblog/74145715.cms|title=65th Amazon Filmfare Awards 2020 live updates|work=The Times of India|date=15 February 2020|access-date=15 February 2020}}</ref>
== References ==
{{reflist}}
== බාහිර සබැඳි ==
{{Commons category}}
* {{Twitter}}
* {{IMDb name|6277267}}
* {{Bollywood Hungama person|bhumi-pednekar}}
{{Navboxes
|title = භූමි පේඩ්නේකර් ලද සම්මාන
|list=
{{FilmfareAwardBestFemaleDebut}}
{{FilmfareCriticsAwardBestActress}}
{{ScreenAwardBestFemaleDebut}}
{{IIFAAwardBestFemaleDebut}}
{{Zee Cine Award for Best Female Debut}}
{{ZeeCineAwardBestSupportingActorFemale}}
}}
{{authority control}}
{{DEFAULTSORT:පේඩ්නේකර්, භූමි}}
[[ප්රවර්ගය:1989 උපත්]]
[[ප්රවර්ගය:ජීවමාන ජනයා]]
[[ප්රවර්ගය:මුම්බායිහි නිළියෝ]]
[[Category:Actresses in Hindi cinema]]
[[ප්රවර්ගය:21 වන සියවස තුළ ඉන්දියානු නිළියෝ]]
[[Category:Marathi people]]
[[Category:Indian film actresses]]
[[Category:Zee Cine Awards winners]]
[[Category:Indian people of Marathi descent]]
[[Category:People of Haryanvi descent]]
[[Category:Forbes 30 Under 30 recipients]]
b4jsx2c3c9822ga8qgh4vod58olto5d
790966
790965
2026-05-20T11:41:53Z
Yasasuru
23090
790966
wikitext
text/x-wiki
{{short description|ඉන්දියානු නිළිය}}
{{Use dmy dates|date=November 2020}}
{{Infobox person
| name = භූමි පේඩ්නේකර
| image = Bhumi Pednekar promoting Sonchiriya.jpg
| image_size =
| caption = පේඩ්නේකර් ''[[සෝන්චිරියා]]'' හි ප්රවර්ධන උත්සවයක දී 2019
| birth_date = {{Birth date and age|1989|07|18|df=y}}
| birth_place = [[බොම්බේ]], [[මහරාෂ්ට්ර]], ඉන්දියාව
| occupation = නිළිය
| nationality =
| years_active = 2015–වර්තමානය
}}
'''භූමි පේඩ්නේකර්''' (උපත 1989 ජූලි 18) යනුවෙන් හැඳින්වෙන්නෙ [[බොලිවුඩ්|හින්දී චිත්රපටවල]] පෙනීසිටින නිළියකි. සය වසරක් [[යශ් රාජ් ෆිල්ම්ස්]] හි සහකාර නළුවරණ අධ්යක්ෂ ලෙස කටයුතු කිරීමෙන් පසු ඇය රංගනයට පිවිසියේ එම සමාගමේම ප්රේම වෘත්තාන්ත ප්රහසන චිත්රපටයක් වූ ''[[ඩම් ලගා කේ හඊශා]]'' (2015) හි තරබාරු මනාලියකගේ චරිතය තුළිනි. ඒ සඳහා ඇයට [[හොඳම කාන්තා ප්රවිෂ්ටය සඳහා ෆිල්ම්ෆෙයාර් සම්මානය]] හිමි විය.
පේඩ්නේකර් ප්රසිද්ධියට පත්වූයේ ප්රහසන නාට්ය චිත්රපටවල ඇය නිරූපණය කළ ශක්තිමත් කාන්තා චරිත නිසායි. මේ අතරට ''[[ටොයිලට්: එක් ප්රේම්
කථා]]'' (2017), ''[[ශුභ් මංගල් සාව්ධාන්]]'' (2017), ''[[සෝන්චිරියා]]'' (2019), ''[[බාලා (2019 චිත්රපටය)|බාලා]]'' (2019), සහ ''[[පති පත්නී ඕර් වෝහ් (2019 චිත්රපටය)|පති පත්නී ඕර් වෝහ්]]'' (2019) වැනි චිත්රපට අයත් ය.<ref name="small town">{{cite news|last=Dubey|first=Rachana|url=https://timesofindia.indiatimes.com/entertainment/hindi/bollywood/news/bhumi-pednekar-i-dont-mind-being-the-face-of-small-town-india-it-is-home-to-beautiful-stories/articleshow/71607615.cms|title=Bhumi Pednekar: I don't mind being the face of small-town India, it is home to beautiful stories|work=The Times of India|date=16 October 2019|access-date=27 December 2019|archive-date=16 March 2020|archive-url=https://web.archive.org/web/20200316023113/https://timesofindia.indiatimes.com/entertainment/hindi/bollywood/news/bhumi-pednekar-i-dont-mind-being-the-face-of-small-town-india-it-is-home-to-beautiful-stories/articleshow/71607615.cms|url-status=live}}</ref> ''[[සාන්ද් කී ආන්ඛ්]]'' (2019) චිත්රපටයේ ඇය නිරූපණය කළ [[චන්ද්රෝ තෝමාර්]] නම් වියපත් චරිතය සඳහා ඇයට [[හොඳම නිළිය සඳහා වූ ෆිල්ම්ෆෙයාර් විචාරක සම්මානය]] හිමිවූයේ [[තාප්සී පන්නු]] සමඟ සමව ය.<ref>{{cite news|url=https://timesofindia.indiatimes.com/entertainment/hindi/bollywood/news/65th-amazon-filmfare-awards-2020-live-updates-and-filmfare-awards-winners/liveblog/74145715.cms|title=65th Amazon Filmfare Awards 2020 live updates|work=The Times of India|date=15 February 2020|access-date=15 February 2020}}</ref>
== ආශ්රේයයන් ==
{{reflist}}
== බාහිර සබැඳි ==
{{Commons category}}
* {{Twitter}}
* {{IMDb name|6277267}}
* {{Bollywood Hungama person|bhumi-pednekar}}
{{Navboxes
|title = භූමි පේඩ්නේකර් ලද සම්මාන
|list=
{{FilmfareAwardBestFemaleDebut}}
{{FilmfareCriticsAwardBestActress}}
{{ScreenAwardBestFemaleDebut}}
{{IIFAAwardBestFemaleDebut}}
{{Zee Cine Award for Best Female Debut}}
{{ZeeCineAwardBestSupportingActorFemale}}
}}
{{authority control}}
{{DEFAULTSORT:පේඩ්නේකර්, භූමි}}
[[ප්රවර්ගය:1989 උපත්]]
[[ප්රවර්ගය:ජීවමාන ජනයා]]
[[ප්රවර්ගය:මුම්බායිහි නිළියෝ]]
[[Category:Actresses in Hindi cinema]]
[[ප්රවර්ගය:21 වන සියවස තුළ ඉන්දියානු නිළියෝ]]
[[Category:Marathi people]]
[[Category:Indian film actresses]]
[[Category:Zee Cine Awards winners]]
[[Category:Indian people of Marathi descent]]
[[Category:People of Haryanvi descent]]
[[Category:Forbes 30 Under 30 recipients]]
jh974g37ce326qdpy5hpk8diwlrlqqw
790967
790966
2026-05-20T11:43:40Z
Yasasuru
23090
790967
wikitext
text/x-wiki
{{short description|ඉන්දියානු නිළිය}}
{{Use dmy dates|date=November 2020}}
{{Infobox person
| name = භූමි පේඩ්නේකර
| image = Bhumi Pednekar promoting Sonchiriya.jpg
| image_size =
| caption = පේඩ්නේකර් ''[[සෝන්චිරියා]]'' හි ප්රවර්ධන උත්සවයක දී 2019
| birth_date = {{Birth date and age|1989|07|18|df=y}}
| birth_place = [[බොම්බේ]], [[මහරාෂ්ට්ර]], ඉන්දියාව
| occupation = නිළිය
| nationality =
| years_active = 2015–වර්තමානය
}}
'''භූමි පේඩ්නේකර්''' (උපත 1989 ජූලි 18) යනුවෙන් හැඳින්වෙන්නෙ [[බොලිවුඩ්|හින්දී චිත්රපටවල]] පෙනීසිටින නිළියකි. සය වසරක් [[යශ් රාජ් ෆිල්ම්ස්]] හි සහකාර නළුවරණ අධ්යක්ෂ ලෙස කටයුතු කිරීමෙන් පසු ඇය රංගනයට පිවිසියේ එම සමාගමේම ප්රේම වෘත්තාන්ත ප්රහසන චිත්රපටයක් වූ ''[[ඩම් ලගා කේ හඊශා]]'' (2015) හි තරබාරු මනාලියකගේ චරිතය තුළිනි. ඒ සඳහා ඇයට [[හොඳම කාන්තා ප්රවිෂ්ටය සඳහා ෆිල්ම්ෆෙයාර් සම්මානය]] හිමි විය.
පේඩ්නේකර් ප්රසිද්ධියට පත්වූයේ ප්රහසන නාට්ය චිත්රපටවල ඇය නිරූපණය කළ ශක්තිමත් කාන්තා චරිත නිසායි. මේ අතරට [[ටොයිලට්: එක් ප්රේම්
කථා]] (2017), ''[[ශුභ් මංගල් සාව්ධාන්]]'' (2017), ''[[සෝන්චිරියා]]'' (2019), ''[[බාලා (2019 චිත්රපටය)|බාලා]]'' (2019), සහ ''[[පති පත්නී ඕර් වෝහ් (2019 චිත්රපටය)|පති පත්නී ඕර් වෝහ්]]'' (2019) වැනි චිත්රපට අයත් ය.<ref name="small town">{{cite news|last=Dubey|first=Rachana|url=https://timesofindia.indiatimes.com/entertainment/hindi/bollywood/news/bhumi-pednekar-i-dont-mind-being-the-face-of-small-town-india-it-is-home-to-beautiful-stories/articleshow/71607615.cms|title=Bhumi Pednekar: I don't mind being the face of small-town India, it is home to beautiful stories|work=The Times of India|date=16 October 2019|access-date=27 December 2019|archive-date=16 March 2020|archive-url=https://web.archive.org/web/20200316023113/https://timesofindia.indiatimes.com/entertainment/hindi/bollywood/news/bhumi-pednekar-i-dont-mind-being-the-face-of-small-town-india-it-is-home-to-beautiful-stories/articleshow/71607615.cms|url-status=live}}</ref> ''[[සාන්ද් කී ආන්ඛ්]]'' (2019) චිත්රපටයේ ඇය නිරූපණය කළ [[චන්ද්රෝ තෝමාර්]] නම් වියපත් චරිතය සඳහා ඇයට [[හොඳම නිළිය සඳහා වූ ෆිල්ම්ෆෙයාර් විචාරක සම්මානය]] හිමිවූයේ [[තාප්සී පන්නු]] සමඟ සමව ය.<ref>{{cite news|url=https://timesofindia.indiatimes.com/entertainment/hindi/bollywood/news/65th-amazon-filmfare-awards-2020-live-updates-and-filmfare-awards-winners/liveblog/74145715.cms|title=65th Amazon Filmfare Awards 2020 live updates|work=The Times of India|date=15 February 2020|access-date=15 February 2020}}</ref>
== ආශ්රේයයන් ==
{{reflist}}
== බාහිර සබැඳි ==
{{Commons category}}
* {{Twitter}}
* {{IMDb name|6277267}}
* {{Bollywood Hungama person|bhumi-pednekar}}
{{Navboxes
|title = භූමි පේඩ්නේකර් ලද සම්මාන
|list=
{{FilmfareAwardBestFemaleDebut}}
{{FilmfareCriticsAwardBestActress}}
{{ScreenAwardBestFemaleDebut}}
{{IIFAAwardBestFemaleDebut}}
{{Zee Cine Award for Best Female Debut}}
{{ZeeCineAwardBestSupportingActorFemale}}
}}
{{authority control}}
{{DEFAULTSORT:පේඩ්නේකර්, භූමි}}
[[ප්රවර්ගය:1989 උපත්]]
[[ප්රවර්ගය:ජීවමාන ජනයා]]
[[ප්රවර්ගය:මුම්බායිහි නිළියෝ]]
[[Category:Actresses in Hindi cinema]]
[[ප්රවර්ගය:21 වන සියවස තුළ ඉන්දියානු නිළියෝ]]
[[Category:Marathi people]]
[[Category:Indian film actresses]]
[[Category:Zee Cine Awards winners]]
[[Category:Indian people of Marathi descent]]
[[Category:People of Haryanvi descent]]
[[Category:Forbes 30 Under 30 recipients]]
4qhwh42kvbrmlo4pkr902jadkw37osg
ඍතුපර්ණා සේන්ගුප්තා
0
91303
790958
665562
2026-05-20T11:17:52Z
Yasasuru
23090
/* */
790958
wikitext
text/x-wiki
{{short description|ඉන්දියානු නිළිය සහ නිෂ්පාදිකාව}}
{{Use dmy dates|date=August 2020}}
{{Infobox person
| name = ඍතුපර්ණා සේන්ගුප්තා
| image = Rituparna Sengupta - Singapore 2020 - Vhok John.jpg
| caption = සේන්ගුප්තා 2020 දී
| birth_date = {{birth date and age|df=yes|1970|11|7}}<ref>{{cite web|url=https://www.timesofindia.com/entertainment/bengali/movies/did-you-know/did-you-know-acting-wasnt-the-first-choice-for-rituparna/articleshow/76355801.cms|title=Did you know acting wasn't the first choice for Rituparna?|website=The Times of India|access-date=1 November 2020}}</ref>
| birth_place = [[කොල්කතා, බටහිර බෙංගාලය]], ඉන්දියාව
| yearsactive = 1989–වර්තමානය
| organization = භාව්නා ආජ් ඕ කාල්<ref>{{Cite web|url=https://timesofindia.indiatimes.com/entertainment/bengali/movies/news/ed-questions-rituparna-sengupta-over-rose-valley-scam/articleshow/70288827.cms|title=ED questions Rituparna Sengupta over Rose Valley scam - Times of India|website=The Times of India|language=en|access-date=2019-08-08}}</ref>
| occupation = නිළිය සහ [[චිත්රපට නිෂ්පාදක|නිෂ්පාදිකාව]]
| works = [[ඍතුපර්ණා සේන්ගුප්තාගේ දායකත්ව ලැයිස්තුව|සම්පූර්ණ ලැයිස්තුව]]
| alma_mater = [[කල්කටා විශ්වවිද්යාලය]]
| opponents =
| spouse = {{married|සංජේ චක්රබර්තී|1999}}
| children = 2
| birth_name = ඍතුපර්ණා සේන්ගුප්තා
| website = {{URL|http://www.rituparna.com/}}
}}
'''ඍතුපර්ණා සේන්ගුප්තා''' (''ඍතුපොර්ණා ශේන්ගුප්තා''; උපත 1970 නොවැම්බර් 7) යනුවෙන් හැඳින්වෙන්නේ [[බටහිර බෙංගාලයේ සිනමාව|බෙංගාලි]] සහ [[බොලිවුඩ්|හින්දී සිනමාව]] නිසා ප්රසිද්ධියට පත් ඉන්දියානු නිළියක සහ නිෂ්පාදිකාවකි.<ref>{{cite news| url=http://www.telegraphindia.com/1121103/jsp/entertainment/story_16152170.jsp#.UoJjenDPVV4 | location=Calcutta, India | work=The Telegraph | title=She's bold & beautiful | date=3 November 2012}}</ref>
<ref name="Bindloss2009">{{cite book|last=Bindloss|first=Joe|title=Northeast India|url=https://books.google.com/books?id=D_bYWjJOe9cC&pg=PA59|year=2009|publisher=Lonely Planet|isbn=9781741793192|page=59}}</ref> One of the most successful actresses of Bengali cinema, she rode the crest of her box office success in the late 1990s.<ref name=":3">{{Cite web|url=https://wow.outlookbusiness.com/rituparna-sengupta/|title=Why Rituparna Sengupta is the queen of versatility|website=Outlook Business Wow|language=en-US|access-date=6 November 2019}}</ref> She received a [[National Film Awards|National Award]], two [[Filmfare Awards East|Filmfare Awards]], four [[Bengal Film Journalists' Association – Best Actress Award|BFJA Awards]] and four Anandalok Awards.<ref>{{cite news|title=Bold & beautiful |url=http://www.newindianexpress.com/entertainment/2013/feb/19/bold--beautiful-451983.html |website=newindianexpress.com |date=19 February 2013}}</ref><ref>{{cite news|title=I don't want to lose grip on Tollywood: Rituparna Sengupta |url=https://www.deccanherald.com/content/91010/i-dont-want-lose-grip.html |website=www.deccanherald.com |date=24 August 2010}}</ref><ref name=":9">{{Cite web|url=https://www.youtube.com/watch?feature=youtu.be&v=gotsW2zKUuU|title=Interview with Prosenjit and Rituparna|website=[[YouTube]]|publisher=[[ABP Ananda]]|publication-date=14 May 2016}}</ref>
==References==
{{reflist}}
== External links ==
{{Commons category}}
* {{Official website|http://www.rituparna.com}}
* {{IMDb name|0784292|name=Rituparna Sengupta}}
* {{Bollywood Hungama person|rituparna-sengupta}}
{{National Film Award for Best Actress}}
{{Authority control}}
{{DEFAULTSORT:Sengupta, Rituparna}}
[[Category:Actresses from Kolkata]]
[[Category:Indian film actresses]]
[[Category:Actresses in Bengali cinema]]
[[Category:Actresses in Hindi cinema]]
[[ප්රවර්ගය:ජීවමාන ජනයා]]
[[ප්රවර්ගය:1970 උපත්]]
[[Category:Bengal Film Journalists' Association Award winners]]
[[Category:Best Actress National Film Award winners]]
[[Category:Lady Brabourne College alumni]]
[[Category:University of Calcutta alumni]]
[[Category:Kalakar Awards winners]]
[[ප්රවර්ගය:බෙංගාලි හින්දුවරු]]
49byvxd7odxq7q7o7fvlyrff49s66v6
790959
790958
2026-05-20T11:22:06Z
Yasasuru
23090
/* */
790959
wikitext
text/x-wiki
{{short description|ඉන්දියානු නිළිය සහ නිෂ්පාදිකාව}}
{{Use dmy dates|date=August 2020}}
{{Infobox person
| name = ඍතුපර්ණා සේන්ගුප්තා
| image = Rituparna Sengupta - Singapore 2020 - Vhok John.jpg
| caption = සේන්ගුප්තා 2020 දී
| birth_date = {{birth date and age|df=yes|1970|11|7}}<ref>{{cite web|url=https://www.timesofindia.com/entertainment/bengali/movies/did-you-know/did-you-know-acting-wasnt-the-first-choice-for-rituparna/articleshow/76355801.cms|title=Did you know acting wasn't the first choice for Rituparna?|website=The Times of India|access-date=1 November 2020}}</ref>
| birth_place = [[කොල්කතා, බටහිර බෙංගාලය]], ඉන්දියාව
| yearsactive = 1989–වර්තමානය
| organization = භාව්නා ආජ් ඕ කාල්<ref>{{Cite web|url=https://timesofindia.indiatimes.com/entertainment/bengali/movies/news/ed-questions-rituparna-sengupta-over-rose-valley-scam/articleshow/70288827.cms|title=ED questions Rituparna Sengupta over Rose Valley scam - Times of India|website=The Times of India|language=en|access-date=2019-08-08}}</ref>
| occupation = නිළිය සහ [[චිත්රපට නිෂ්පාදක|නිෂ්පාදිකාව]]
| works = [[ඍතුපර්ණා සේන්ගුප්තාගේ දායකත්ව ලැයිස්තුව|සම්පූර්ණ ලැයිස්තුව]]
| alma_mater = [[කල්කටා විශ්වවිද්යාලය]]
| opponents =
| spouse = {{married|සංජේ චක්රබර්තී|1999}}
| children = 2
| birth_name = ඍතුපර්ණා සේන්ගුප්තා
| website = {{URL|http://www.rituparna.com/}}
}}
'''ඍතුපර්ණා සේන්ගුප්තා''' (''ඍතුපොර්ණා ශේන්ගුප්තා''; උපත 1970 නොවැම්බර් 7) යනුවෙන් හැඳින්වෙන්නේ [[බටහිර බෙංගාලයේ සිනමාව|බෙංගාලි]] සහ [[බොලිවුඩ්|හින්දී සිනමාව]] නිසා ප්රසිද්ධියට පත් ඉන්දියානු නිළියක සහ නිෂ්පාදිකාවකි.<ref>{{cite news| url=http://www.telegraphindia.com/1121103/jsp/entertainment/story_16152170.jsp#.UoJjenDPVV4 | location=Calcutta, India | work=The Telegraph | title=She's bold & beautiful | date=3 November 2012}}</ref>
<ref name="Bindloss2009">{{cite book|last=Bindloss|first=Joe|title=Northeast India|url=https://books.google.com/books?id=D_bYWjJOe9cC&pg=PA59|year=2009|publisher=Lonely Planet|isbn=9781741793192|page=59}}</ref> බෙංගාලි සිනමාවේ සාර්ථකම නිළියන්ගෙන් අයකු ලෙස සැළකෙන ඇය පසුකාලීන 1990 දශකයේ සිය රංගන දිවියේ හිනිපෙත්තට ළඟා විය.<ref name=":3">{{Cite web|url=https://wow.outlookbusiness.com/rituparna-sengupta/|title=Why Rituparna Sengupta is the queen of versatility|website=Outlook Business Wow|language=en-US|access-date=6 November 2019}}</ref> ඇය [[ජාතික චිත්රපට සම්මාන]]යක්, [[ෆිල්ම්ෆෙයාර් සම්මාන]] ද්විත්වයක්, [[බෙංගාල චිත්රපට මාධ්යවේදීන්ගේ සංවිධානය - හොඳම නිළිය සම්මානය|BFJA සම්මාන]] හතරක් සහ ආනන්දලෝක් සම්මාන හතරක් ලබා ඇත.<ref>{{cite news|title=Bold & beautiful |url=http://www.newindianexpress.com/entertainment/2013/feb/19/bold--beautiful-451983.html |website=newindianexpress.com |date=19 February 2013}}</ref><ref>{{cite news|title=I don't want to lose grip on Tollywood: Rituparna Sengupta |url=https://www.deccanherald.com/content/91010/i-dont-want-lose-grip.html |website=www.deccanherald.com |date=24 August 2010}}</ref><ref name=":9">{{Cite web|url=https://www.youtube.com/watch?feature=youtu.be&v=gotsW2zKUuU|title=Interview with Prosenjit and Rituparna|website=[[YouTube]]|publisher=[[ABP Ananda]]|publication-date=14 May 2016}}</ref>
==References==
{{reflist}}
== External links ==
{{Commons category}}
* {{Official website|http://www.rituparna.com}}
* {{IMDb name|0784292|name=Rituparna Sengupta}}
* {{Bollywood Hungama person|rituparna-sengupta}}
{{National Film Award for Best Actress}}
{{Authority control}}
{{DEFAULTSORT:Sengupta, Rituparna}}
[[Category:Actresses from Kolkata]]
[[Category:Indian film actresses]]
[[Category:Actresses in Bengali cinema]]
[[Category:Actresses in Hindi cinema]]
[[ප්රවර්ගය:ජීවමාන ජනයා]]
[[ප්රවර්ගය:1970 උපත්]]
[[Category:Bengal Film Journalists' Association Award winners]]
[[Category:Best Actress National Film Award winners]]
[[Category:Lady Brabourne College alumni]]
[[Category:University of Calcutta alumni]]
[[Category:Kalakar Awards winners]]
[[ප්රවර්ගය:බෙංගාලි හින්දුවරු]]
pdoo4oadgqukd9685vuv5fuhit72qoj
790960
790959
2026-05-20T11:22:19Z
Yasasuru
23090
790960
wikitext
text/x-wiki
{{short description|ඉන්දියානු නිළිය සහ නිෂ්පාදිකාව}}
{{Use dmy dates|date=August 2020}}
{{Infobox person
| name = ඍතුපර්ණා සේන්ගුප්තා
| image = Rituparna Sengupta - Singapore 2020 - Vhok John.jpg
| caption = සේන්ගුප්තා 2020 දී
| birth_date = {{birth date and age|df=yes|1970|11|7}}<ref>{{cite web|url=https://www.timesofindia.com/entertainment/bengali/movies/did-you-know/did-you-know-acting-wasnt-the-first-choice-for-rituparna/articleshow/76355801.cms|title=Did you know acting wasn't the first choice for Rituparna?|website=The Times of India|access-date=1 November 2020}}</ref>
| birth_place = [[කොල්කතා, බටහිර බෙංගාලය]], ඉන්දියාව
| yearsactive = 1989–වර්තමානය
| organization = භාව්නා ආජ් ඕ කාල්<ref>{{Cite web|url=https://timesofindia.indiatimes.com/entertainment/bengali/movies/news/ed-questions-rituparna-sengupta-over-rose-valley-scam/articleshow/70288827.cms|title=ED questions Rituparna Sengupta over Rose Valley scam - Times of India|website=The Times of India|language=en|access-date=2019-08-08}}</ref>
| occupation = නිළිය සහ [[චිත්රපට නිෂ්පාදක|නිෂ්පාදිකාව]]
| works = [[ඍතුපර්ණා සේන්ගුප්තාගේ දායකත්ව ලැයිස්තුව|සම්පූර්ණ ලැයිස්තුව]]
| alma_mater = [[කල්කටා විශ්වවිද්යාලය]]
| opponents =
| spouse = {{married|සංජේ චක්රබර්තී|1999}}
| children = 2
| birth_name = ඍතුපර්ණා සේන්ගුප්තා
| website = {{URL|http://www.rituparna.com/}}
}}
'''ඍතුපර්ණා සේන්ගුප්තා''' (''ඍතුපොර්ණා ශේන්ගුප්තා''; උපත 1970 නොවැම්බර් 7) යනුවෙන් හැඳින්වෙන්නේ [[බටහිර බෙංගාලයේ සිනමාව|බෙංගාලි]] සහ [[බොලිවුඩ්|හින්දී සිනමාව]] නිසා ප්රසිද්ධියට පත් ඉන්දියානු නිළියක සහ නිෂ්පාදිකාවකි.<ref>{{cite news| url=http://www.telegraphindia.com/1121103/jsp/entertainment/story_16152170.jsp#.UoJjenDPVV4 | location=Calcutta, India | work=The Telegraph | title=She's bold & beautiful | date=3 November 2012}}</ref>
<ref name="Bindloss2009">{{cite book|last=Bindloss|first=Joe|title=Northeast India|url=https://books.google.com/books?id=D_bYWjJOe9cC&pg=PA59|year=2009|publisher=Lonely Planet|isbn=9781741793192|page=59}}</ref> බෙංගාලි සිනමාවේ සාර්ථකම නිළියන්ගෙන් අයකු ලෙස සැළකෙන ඇය පසුකාලීන 1990 දශකයේ සිය රංගන දිවියේ හිනිපෙත්තට ළඟා විය.<ref name=":3">{{Cite web|url=https://wow.outlookbusiness.com/rituparna-sengupta/|title=Why Rituparna Sengupta is the queen of versatility|website=Outlook Business Wow|language=en-US|access-date=6 November 2019}}</ref> ඇය [[ජාතික චිත්රපට සම්මාන]]යක්, [[ෆිල්ම්ෆෙයාර් සම්මාන]] ද්විත්වයක්, [[බෙංගාල චිත්රපට මාධ්යවේදීන්ගේ සංවිධානය - හොඳම නිළිය සම්මානය|BFJA සම්මාන]] හතරක් සහ ආනන්දලෝක් සම්මාන හතරක් ලබා ඇත.<ref>{{cite news|title=Bold & beautiful |url=http://www.newindianexpress.com/entertainment/2013/feb/19/bold--beautiful-451983.html |website=newindianexpress.com |date=19 February 2013}}</ref><ref>{{cite news|title=I don't want to lose grip on Tollywood: Rituparna Sengupta |url=https://www.deccanherald.com/content/91010/i-dont-want-lose-grip.html |website=www.deccanherald.com |date=24 August 2010}}</ref><ref name=":9">{{Cite web|url=https://www.youtube.com/watch?feature=youtu.be&v=gotsW2zKUuU|title=Interview with Prosenjit and Rituparna|website=[[YouTube]]|publisher=[[ABP Ananda]]|publication-date=14 May 2016}}</ref>
==ආශ්රේයයන්==
{{reflist}}
== External links ==
{{Commons category}}
* {{Official website|http://www.rituparna.com}}
* {{IMDb name|0784292|name=Rituparna Sengupta}}
* {{Bollywood Hungama person|rituparna-sengupta}}
{{National Film Award for Best Actress}}
{{Authority control}}
{{DEFAULTSORT:Sengupta, Rituparna}}
[[Category:Actresses from Kolkata]]
[[Category:Indian film actresses]]
[[Category:Actresses in Bengali cinema]]
[[Category:Actresses in Hindi cinema]]
[[ප්රවර්ගය:ජීවමාන ජනයා]]
[[ප්රවර්ගය:1970 උපත්]]
[[Category:Bengal Film Journalists' Association Award winners]]
[[Category:Best Actress National Film Award winners]]
[[Category:Lady Brabourne College alumni]]
[[Category:University of Calcutta alumni]]
[[Category:Kalakar Awards winners]]
[[ප්රවර්ගය:බෙංගාලි හින්දුවරු]]
t0ln778t30aarz6ldvzx9h825fsyfe9
790961
790960
2026-05-20T11:22:58Z
Yasasuru
23090
790961
wikitext
text/x-wiki
{{short description|ඉන්දියානු නිළිය සහ නිෂ්පාදිකාව}}
{{Use dmy dates|date=August 2020}}
{{Infobox person
| name = ඍතුපර්ණා සේන්ගුප්තා
| image = Rituparna Sengupta - Singapore 2020 - Vhok John.jpg
| caption = සේන්ගුප්තා 2020 දී
| birth_date = {{birth date and age|df=yes|1970|11|7}}<ref>{{cite web|url=https://www.timesofindia.com/entertainment/bengali/movies/did-you-know/did-you-know-acting-wasnt-the-first-choice-for-rituparna/articleshow/76355801.cms|title=Did you know acting wasn't the first choice for Rituparna?|website=The Times of India|access-date=1 November 2020}}</ref>
| birth_place = [[කොල්කතා, බටහිර බෙංගාලය]], ඉන්දියාව
| yearsactive = 1989–වර්තමානය
| organization = භාව්නා ආජ් ඕ කාල්<ref>{{Cite web|url=https://timesofindia.indiatimes.com/entertainment/bengali/movies/news/ed-questions-rituparna-sengupta-over-rose-valley-scam/articleshow/70288827.cms|title=ED questions Rituparna Sengupta over Rose Valley scam - Times of India|website=The Times of India|language=en|access-date=2019-08-08}}</ref>
| occupation = නිළිය සහ [[චිත්රපට නිෂ්පාදක|නිෂ්පාදිකාව]]
| works = [[ඍතුපර්ණා සේන්ගුප්තාගේ දායකත්ව ලැයිස්තුව|සම්පූර්ණ ලැයිස්තුව]]
| alma_mater = [[කල්කටා විශ්වවිද්යාලය]]
| opponents =
| spouse = {{married|සංජේ චක්රබර්තී|1999}}
| children = 2
| birth_name = ඍතුපර්ණා සේන්ගුප්තා
| website = {{URL|http://www.rituparna.com/}}
}}
'''ඍතුපර්ණා සේන්ගුප්තා''' (''ඍතුපොර්ණා ශේන්ගුප්තා''; උපත 1970 නොවැම්බර් 7) යනුවෙන් හැඳින්වෙන්නේ [[බටහිර බෙංගාලයේ සිනමාව|බෙංගාලි]] සහ [[බොලිවුඩ්|හින්දී සිනමාව]] නිසා ප්රසිද්ධියට පත් ඉන්දියානු නිළියක සහ නිෂ්පාදිකාවකි.<ref>{{cite news| url=http://www.telegraphindia.com/1121103/jsp/entertainment/story_16152170.jsp#.UoJjenDPVV4 | location=Calcutta, India | work=The Telegraph | title=She's bold & beautiful | date=3 November 2012}}</ref>
<ref name="Bindloss2009">{{cite book|last=Bindloss|first=Joe|title=Northeast India|url=https://books.google.com/books?id=D_bYWjJOe9cC&pg=PA59|year=2009|publisher=Lonely Planet|isbn=9781741793192|page=59}}</ref> බෙංගාලි සිනමාවේ සාර්ථකම නිළියන්ගෙන් අයකු ලෙස සැළකෙන ඇය පසුකාලීන 1990 දශකයේ සිය රංගන දිවියේ හිනිපෙත්තට ළඟා විය.<ref name=":3">{{Cite web|url=https://wow.outlookbusiness.com/rituparna-sengupta/|title=Why Rituparna Sengupta is the queen of versatility|website=Outlook Business Wow|language=en-US|access-date=6 November 2019}}</ref> ඇය [[ජාතික චිත්රපට සම්මාන]]යක්, [[ෆිල්ම්ෆෙයාර් සම්මාන]] ද්විත්වයක්, [[බෙංගාල චිත්රපට මාධ්යවේදීන්ගේ සංවිධානය - හොඳම නිළිය සම්මානය|BFJA සම්මාන]] හතරක් සහ ආනන්දලෝක් සම්මාන හතරක් ලබා ඇත.<ref>{{cite news|title=Bold & beautiful |url=http://www.newindianexpress.com/entertainment/2013/feb/19/bold--beautiful-451983.html |website=newindianexpress.com |date=19 February 2013}}</ref><ref>{{cite news|title=I don't want to lose grip on Tollywood: Rituparna Sengupta |url=https://www.deccanherald.com/content/91010/i-dont-want-lose-grip.html |website=www.deccanherald.com |date=24 August 2010}}</ref><ref name=":9">{{Cite web|url=https://www.youtube.com/watch?feature=youtu.be&v=gotsW2zKUuU|title=Interview with Prosenjit and Rituparna|website=[[YouTube]]|publisher=[[ABP Ananda]]|publication-date=14 May 2016}}</ref>
==ආශ්රේයයන්==
{{reflist}}
== බාහිර සබැඳි ==
{{Commons category}}
* {{Official website|http://www.rituparna.com}}
* {{IMDb name|0784292|name=Rituparna Sengupta}}
* {{Bollywood Hungama person|rituparna-sengupta}}
{{National Film Award for Best Actress}}
{{Authority control}}
{{DEFAULTSORT:සේන්ගුප්තා, ඍතුපර්ණා}}
[[Category:කොල්කතාවේ නිළියෝ]]
[[Category:Indian film actresses]]
[[Category:Actresses in Bengali cinema]]
[[Category:Actresses in Hindi cinema]]
[[ප්රවර්ගය:ජීවමාන ජනයා]]
[[ප්රවර්ගය:1970 උපත්]]
[[Category:Bengal Film Journalists' Association Award winners]]
[[Category:Best Actress National Film Award winners]]
[[Category:Lady Brabourne College alumni]]
[[Category:University of Calcutta alumni]]
[[Category:Kalakar Awards winners]]
[[ප්රවර්ගය:බෙංගාලි හින්දුවරු]]
5i1gbsfvay9javttp6g1ffyc74v3x96
ශර්මිලා ටාගෝර්
0
91306
790954
659230
2026-05-20T11:02:31Z
Yasasuru
23090
790954
wikitext
text/x-wiki
{{short description|ඉන්දියානු නිළිය}}
{{EngvarB|date=June 2015}}
{{Use dmy dates|date=November 2019}}
{{Infobox person
| name = ශර්මිලා ටාගෝර්
| image = Sharmila T Lux-Award 2016.jpg
| imagesize =
| caption = ටාගෝර් 2016 [[ලක්ස්]] උත්ස්වයක දී
| birth_name =
| birth_date = {{Birth date and age|df=y|1944|12|8}}
| birth_place = [[කාන්පූර්]], [[ඒකාබද්ධ පළාත් (1937–50)|ඒකාබද්ධ පළාත්]], [[බ්රිතාන්ය රාජ්|බ්රිතාන්ය ඉන්දියාව]]<br>{{small|(වර්තමාන[[උත්තර් ප්රදේශ්]])}}<ref>{{cite web|title=Birthday special: Things you may not know about Sharmila Tagore|url=http://www.mid-day.com/photos/birthday-special-things-you-may-not-know-about-sharmila-tagore/4288|website=[[Mid-Day]]|access-date=25 April 2016}}</ref>
| other names = අයේෂා බේගම්<br>බේගම් අයේෂා සුල්තානා ඛාන්
| occupation = [[නළුවා|නිළිය]]
| years_active = 1959–1984<br />1991–2010
| spouse = {{marriage|[[මන්සූර් අලි ඛාන් පටෞඩී Ali Khan Pataudi|Mansoor Ali Khan]]|1968|2011}}
| children = [[Saif Ali Khan]] (son)<br>[[Saba Ali Khan]] (daughter)<br>[[Soha Ali Khan]] (daughter)
| family = {{ublist|[[Tagore family]]|[[Pataudi family]]}}
| awards =
}}
'''Sharmila Tagore''', also known as '''Begum Ayesha Sultana Khan''', (born 8 December 1944) is a retired [[Indian people|Indian]] [[actor|actress]]. Primarily known for her work in [[Hindi cinema|Hindi]] and [[Cinema of West Bengal|Bengali cinema]], Tagore is the recipient of two [[National Film Awards]], a [[Filmfare Awards|Filmfare Award]], and the [[Filmfare Lifetime Achievement Award]] for her contributions to Hindi cinema. In 2013, the [[Government of India]], honoured her with [[Padma Bhushan]], India's third highest civilian honour for her contributions to the Indian culture through performing arts.<ref>{{cite web|url=http://timesofindia.indiatimes.com/entertainment/hindi/bollywood/news/Sharmila-Tagore-Indias-emblem-at-Cannes/articleshow/4513271.cms|title=Sharmila Tagore, India's emblem at Cannes – Times of India}}</ref>
==References==
{{Reflist}}
==External links==
{{Commons category|Sharmila Tagore}}
* {{IMDb name|id=0846616|name=Sharmila Tagore}}
{{PadmaBhushanAwardRecipients 2010–19}}
{{Tagore family}}
{{National Film Award for Best Actress}}
{{NationalFilmAwardBestSupportingActress}}
{{FilmfareBestActressAward}}
{{FilmfareLifetimeAchievementAward}}
{{Authority control}}
{{DEFAULTSORT:Tagore, Sharmila}}
[[ප්රවර්ගය:1944 උපත්]]
[[Category:Actresses in Bengali cinema]]
[[ප්රවර්ගය:21 වන සියවස තුළ ඉන්දියානු නිළියෝ]]
[[Category:Actresses in Hindi cinema]]
[[Category:Actresses in Marathi cinema]]
[[ප්රවර්ගය:මලයාලම් සිනමාවේ නිළියෝ]]
[[ප්රවර්ගය:බෙංගාලි ජනයා]]
[[Category:Best Actress National Film Award winners]]
[[Category:Best Supporting Actress National Film Award winners]]
[[Category:Converts to Islam from Hinduism]]
[[Category:Indian film actresses]]
[[Category:Indian former Hindus]]
[[ප්රවර්ගය:ඉන්දියානු මුස්ලිම්වරු]]
[[ප්රවර්ගය:ජීවමාන ජනයා]]
[[Category:Actresses from Hyderabad, India]]
[[ප්රවර්ගය:මුම්බායිහි නිළියෝ]]
[[Category:Recipients of the Padma Bhushan in arts]]
[[Category:Tagore family|Sharmila]]
[[Category:UNICEF Goodwill Ambassadors]]
[[ප්රවර්ගය:20 වන සියවස තුළ ඉන්දියානු නිළියෝ]]
[[Category:Filmfare Awards winners]]
bbue0ly7lz3vx7rvxyxqligyowq8fye
790955
790954
2026-05-20T11:10:48Z
Yasasuru
23090
/* */
790955
wikitext
text/x-wiki
{{short description|ඉන්දියානු නිළිය}}
{{EngvarB|date=June 2015}}
{{Use dmy dates|date=November 2019}}
{{Infobox person
| name = ශර්මිලා ටාගෝර්
| image = Sharmila T Lux-Award 2016.jpg
| imagesize =
| caption = ටාගෝර් 2016 [[ලක්ස්]] උත්ස්වයක දී
| birth_name =
| birth_date = {{Birth date and age|df=y|1944|12|8}}
| birth_place = [[කාන්පූර්]], [[ඒකාබද්ධ පළාත් (1937–50)|ඒකාබද්ධ පළාත්]], [[බ්රිතාන්ය රාජ්|බ්රිතාන්ය ඉන්දියාව]]<br>{{small|(වර්තමාන[[උත්තර් ප්රදේශ්]])}}<ref>{{cite web|title=Birthday special: Things you may not know about Sharmila Tagore|url=http://www.mid-day.com/photos/birthday-special-things-you-may-not-know-about-sharmila-tagore/4288|website=[[Mid-Day]]|access-date=25 April 2016}}</ref>
| other names = අයේෂා බේගම්<br>බේගම් අයේෂා සුල්තානා ඛාන්
| occupation = [[නළුවා|නිළිය]]
| years_active = 1959–1984<br />1991–2010
| spouse = {{marriage|[[මන්සූර් අලි ඛාන් පටෞඩී|මන්සූර් අලි ඛාන්]]|1968|2011}}
| children = [[සයිෆ් අලි ඛාන්]] (පුත්රයා)<br>[[සබා අලි ඛාන්]] (දියණිය)<br>[[සෝහා අලි ඛාන්]] (දියණිය)
| family = {{ublist|[[ඨාකූර් පවුල]]|[[පටෞඩී පවුල]]}}
| awards =
}}
'''ශර්මිලා ටාගෝර්''', හෙවත් '''බේගම් අයේෂා සුල්තානා ඛාන්''', (උපත 1944 දෙසැම්බර් 8) යනුවෙන් හැඳින්වෙන්නේ විශ්රාමික [[ඉන්දියානු ජනයා|ඉන්දියානු]] [[නළුවා|නිළිය]]කි. ප්රධාන වශයෙන් [[හින්දි සිනමාව|හින්දී]] සහ [[බටහිර බෙංගාලයේ සිනමාව|බෙංගාලි සිනමාව]] නිසා ප්රසිද්ධියට පත් ටාගෝර් [[ජාතික චිත්රපට සම්මාන]] ද්විත්වයක්, [[ෆිල්ම්ෆෙයාර් සම්මාන]]යක්, සහ [[ෆිල්ම්ෆෙයාර් ජීවිතකාලයට වරක් පමණක් පිදෙන ජයග්රහණ සම්මානය]]ක් හිමි කරගෙන ඇත. 2013දී [[ඉන්දියානු රජය]] ඉන්දියාවේ තෙවන ඉහළම මහජන ගෞරවය වන [[පද්ම භූෂණ]] සම්මානය පිරිනමන ලද්දේ ඇය විසින් කලාවට සිදුකරන ලද සේවය නිසායි.<ref>{{cite web|url=http://timesofindia.indiatimes.com/entertainment/hindi/bollywood/news/Sharmila-Tagore-Indias-emblem-at-Cannes/articleshow/4513271.cms|title=Sharmila Tagore, India's emblem at Cannes – Times of India}}</ref>
==References==
{{Reflist}}
==External links==
{{Commons category|Sharmila Tagore}}
* {{IMDb name|id=0846616|name=Sharmila Tagore}}
{{PadmaBhushanAwardRecipients 2010–19}}
{{Tagore family}}
{{National Film Award for Best Actress}}
{{NationalFilmAwardBestSupportingActress}}
{{FilmfareBestActressAward}}
{{FilmfareLifetimeAchievementAward}}
{{Authority control}}
{{DEFAULTSORT:Tagore, Sharmila}}
[[ප්රවර්ගය:1944 උපත්]]
[[Category:Actresses in Bengali cinema]]
[[ප්රවර්ගය:21 වන සියවස තුළ ඉන්දියානු නිළියෝ]]
[[Category:Actresses in Hindi cinema]]
[[Category:Actresses in Marathi cinema]]
[[ප්රවර්ගය:මලයාලම් සිනමාවේ නිළියෝ]]
[[ප්රවර්ගය:බෙංගාලි ජනයා]]
[[Category:Best Actress National Film Award winners]]
[[Category:Best Supporting Actress National Film Award winners]]
[[Category:Converts to Islam from Hinduism]]
[[Category:Indian film actresses]]
[[Category:Indian former Hindus]]
[[ප්රවර්ගය:ඉන්දියානු මුස්ලිම්වරු]]
[[ප්රවර්ගය:ජීවමාන ජනයා]]
[[Category:Actresses from Hyderabad, India]]
[[ප්රවර්ගය:මුම්බායිහි නිළියෝ]]
[[Category:Recipients of the Padma Bhushan in arts]]
[[Category:Tagore family|Sharmila]]
[[Category:UNICEF Goodwill Ambassadors]]
[[ප්රවර්ගය:20 වන සියවස තුළ ඉන්දියානු නිළියෝ]]
[[Category:Filmfare Awards winners]]
izfyjgvhk2gsz08d7gv6d4pjgc0silw
790956
790955
2026-05-20T11:11:02Z
Yasasuru
23090
790956
wikitext
text/x-wiki
{{short description|ඉන්දියානු නිළිය}}
{{EngvarB|date=June 2015}}
{{Use dmy dates|date=November 2019}}
{{Infobox person
| name = ශර්මිලා ටාගෝර්
| image = Sharmila T Lux-Award 2016.jpg
| imagesize =
| caption = ටාගෝර් 2016 [[ලක්ස්]] උත්ස්වයක දී
| birth_name =
| birth_date = {{Birth date and age|df=y|1944|12|8}}
| birth_place = [[කාන්පූර්]], [[ඒකාබද්ධ පළාත් (1937–50)|ඒකාබද්ධ පළාත්]], [[බ්රිතාන්ය රාජ්|බ්රිතාන්ය ඉන්දියාව]]<br>{{small|(වර්තමාන[[උත්තර් ප්රදේශ්]])}}<ref>{{cite web|title=Birthday special: Things you may not know about Sharmila Tagore|url=http://www.mid-day.com/photos/birthday-special-things-you-may-not-know-about-sharmila-tagore/4288|website=[[Mid-Day]]|access-date=25 April 2016}}</ref>
| other names = අයේෂා බේගම්<br>බේගම් අයේෂා සුල්තානා ඛාන්
| occupation = [[නළුවා|නිළිය]]
| years_active = 1959–1984<br />1991–2010
| spouse = {{marriage|[[මන්සූර් අලි ඛාන් පටෞඩී|මන්සූර් අලි ඛාන්]]|1968|2011}}
| children = [[සයිෆ් අලි ඛාන්]] (පුත්රයා)<br>[[සබා අලි ඛාන්]] (දියණිය)<br>[[සෝහා අලි ඛාන්]] (දියණිය)
| family = {{ublist|[[ඨාකූර් පවුල]]|[[පටෞඩී පවුල]]}}
| awards =
}}
'''ශර්මිලා ටාගෝර්''', හෙවත් '''බේගම් අයේෂා සුල්තානා ඛාන්''', (උපත 1944 දෙසැම්බර් 8) යනුවෙන් හැඳින්වෙන්නේ විශ්රාමික [[ඉන්දියානු ජනයා|ඉන්දියානු]] [[නළුවා|නිළිය]]කි. ප්රධාන වශයෙන් [[හින්දි සිනමාව|හින්දී]] සහ [[බටහිර බෙංගාලයේ සිනමාව|බෙංගාලි සිනමාව]] නිසා ප්රසිද්ධියට පත් ටාගෝර් [[ජාතික චිත්රපට සම්මාන]] ද්විත්වයක්, [[ෆිල්ම්ෆෙයාර් සම්මාන]]යක්, සහ [[ෆිල්ම්ෆෙයාර් ජීවිතකාලයට වරක් පමණක් පිදෙන ජයග්රහණ සම්මානය]]ක් හිමි කරගෙන ඇත. 2013දී [[ඉන්දියානු රජය]] ඉන්දියාවේ තෙවන ඉහළම මහජන ගෞරවය වන [[පද්ම භූෂණ]] සම්මානය පිරිනමන ලද්දේ ඇය විසින් කලාවට සිදුකරන ලද සේවය නිසායි.<ref>{{cite web|url=http://timesofindia.indiatimes.com/entertainment/hindi/bollywood/news/Sharmila-Tagore-Indias-emblem-at-Cannes/articleshow/4513271.cms|title=Sharmila Tagore, India's emblem at Cannes – Times of India}}</ref>
==ආශ්රේයයන්==
{{Reflist}}
==External links==
{{Commons category|Sharmila Tagore}}
* {{IMDb name|id=0846616|name=Sharmila Tagore}}
{{PadmaBhushanAwardRecipients 2010–19}}
{{Tagore family}}
{{National Film Award for Best Actress}}
{{NationalFilmAwardBestSupportingActress}}
{{FilmfareBestActressAward}}
{{FilmfareLifetimeAchievementAward}}
{{Authority control}}
{{DEFAULTSORT:Tagore, Sharmila}}
[[ප්රවර්ගය:1944 උපත්]]
[[Category:Actresses in Bengali cinema]]
[[ප්රවර්ගය:21 වන සියවස තුළ ඉන්දියානු නිළියෝ]]
[[Category:Actresses in Hindi cinema]]
[[Category:Actresses in Marathi cinema]]
[[ප්රවර්ගය:මලයාලම් සිනමාවේ නිළියෝ]]
[[ප්රවර්ගය:බෙංගාලි ජනයා]]
[[Category:Best Actress National Film Award winners]]
[[Category:Best Supporting Actress National Film Award winners]]
[[Category:Converts to Islam from Hinduism]]
[[Category:Indian film actresses]]
[[Category:Indian former Hindus]]
[[ප්රවර්ගය:ඉන්දියානු මුස්ලිම්වරු]]
[[ප්රවර්ගය:ජීවමාන ජනයා]]
[[Category:Actresses from Hyderabad, India]]
[[ප්රවර්ගය:මුම්බායිහි නිළියෝ]]
[[Category:Recipients of the Padma Bhushan in arts]]
[[Category:Tagore family|Sharmila]]
[[Category:UNICEF Goodwill Ambassadors]]
[[ප්රවර්ගය:20 වන සියවස තුළ ඉන්දියානු නිළියෝ]]
[[Category:Filmfare Awards winners]]
aib28atzzzlwtc30orpdiiheka2rrsq
790957
790956
2026-05-20T11:11:35Z
Yasasuru
23090
790957
wikitext
text/x-wiki
{{short description|ඉන්දියානු නිළිය}}
{{EngvarB|date=June 2015}}
{{Use dmy dates|date=November 2019}}
{{Infobox person
| name = ශර්මිලා ටාගෝර්
| image = Sharmila T Lux-Award 2016.jpg
| imagesize =
| caption = ටාගෝර් 2016 [[ලක්ස්]] උත්ස්වයක දී
| birth_name =
| birth_date = {{Birth date and age|df=y|1944|12|8}}
| birth_place = [[කාන්පූර්]], [[ඒකාබද්ධ පළාත් (1937–50)|ඒකාබද්ධ පළාත්]], [[බ්රිතාන්ය රාජ්|බ්රිතාන්ය ඉන්දියාව]]<br>{{small|(වර්තමාන[[උත්තර් ප්රදේශ්]])}}<ref>{{cite web|title=Birthday special: Things you may not know about Sharmila Tagore|url=http://www.mid-day.com/photos/birthday-special-things-you-may-not-know-about-sharmila-tagore/4288|website=[[Mid-Day]]|access-date=25 April 2016}}</ref>
| other names = අයේෂා බේගම්<br>බේගම් අයේෂා සුල්තානා ඛාන්
| occupation = [[නළුවා|නිළිය]]
| years_active = 1959–1984<br />1991–2010
| spouse = {{marriage|[[මන්සූර් අලි ඛාන් පටෞඩී|මන්සූර් අලි ඛාන්]]|1968|2011}}
| children = [[සයිෆ් අලි ඛාන්]] (පුත්රයා)<br>[[සබා අලි ඛාන්]] (දියණිය)<br>[[සෝහා අලි ඛාන්]] (දියණිය)
| family = {{ublist|[[ඨාකූර් පවුල]]|[[පටෞඩී පවුල]]}}
| awards =
}}
'''ශර්මිලා ටාගෝර්''', හෙවත් '''බේගම් අයේෂා සුල්තානා ඛාන්''', (උපත 1944 දෙසැම්බර් 8) යනුවෙන් හැඳින්වෙන්නේ විශ්රාමික [[ඉන්දියානු ජනයා|ඉන්දියානු]] [[නළුවා|නිළිය]]කි. ප්රධාන වශයෙන් [[හින්දි සිනමාව|හින්දී]] සහ [[බටහිර බෙංගාලයේ සිනමාව|බෙංගාලි සිනමාව]] නිසා ප්රසිද්ධියට පත් ටාගෝර් [[ජාතික චිත්රපට සම්මාන]] ද්විත්වයක්, [[ෆිල්ම්ෆෙයාර් සම්මාන]]යක්, සහ [[ෆිල්ම්ෆෙයාර් ජීවිතකාලයට වරක් පමණක් පිදෙන ජයග්රහණ සම්මානය]]ක් හිමි කරගෙන ඇත. 2013දී [[ඉන්දියානු රජය]] ඉන්දියාවේ තෙවන ඉහළම මහජන ගෞරවය වන [[පද්ම භූෂණ]] සම්මානය පිරිනමන ලද්දේ ඇය විසින් කලාවට සිදුකරන ලද සේවය නිසායි.<ref>{{cite web|url=http://timesofindia.indiatimes.com/entertainment/hindi/bollywood/news/Sharmila-Tagore-Indias-emblem-at-Cannes/articleshow/4513271.cms|title=Sharmila Tagore, India's emblem at Cannes – Times of India}}</ref>
==ආශ්රේයයන්==
{{Reflist}}
==බාහිර සබැඳි==
{{Commons category|Sharmila Tagore}}
* {{IMDb name|id=0846616|name=Sharmila Tagore}}
{{PadmaBhushanAwardRecipients 2010–19}}
{{Tagore family}}
{{National Film Award for Best Actress}}
{{NationalFilmAwardBestSupportingActress}}
{{FilmfareBestActressAward}}
{{FilmfareLifetimeAchievementAward}}
{{Authority control}}
{{DEFAULTSORT:ටාගෝර්, ශර්මිලා}}
[[ප්රවර්ගය:1944 උපත්]]
[[Category:Actresses in Bengali cinema]]
[[ප්රවර්ගය:21 වන සියවස තුළ ඉන්දියානු නිළියෝ]]
[[Category:Actresses in Hindi cinema]]
[[Category:Actresses in Marathi cinema]]
[[ප්රවර්ගය:මලයාලම් සිනමාවේ නිළියෝ]]
[[ප්රවර්ගය:බෙංගාලි ජනයා]]
[[Category:Best Actress National Film Award winners]]
[[Category:Best Supporting Actress National Film Award winners]]
[[Category:Converts to Islam from Hinduism]]
[[Category:Indian film actresses]]
[[Category:Indian former Hindus]]
[[ප්රවර්ගය:ඉන්දියානු මුස්ලිම්වරු]]
[[ප්රවර්ගය:ජීවමාන ජනයා]]
[[Category:Actresses from Hyderabad, India]]
[[ප්රවර්ගය:මුම්බායිහි නිළියෝ]]
[[Category:Recipients of the Padma Bhushan in arts]]
[[Category:Tagore family|Sharmila]]
[[Category:UNICEF Goodwill Ambassadors]]
[[ප්රවර්ගය:20 වන සියවස තුළ ඉන්දියානු නිළියෝ]]
[[Category:Filmfare Awards winners]]
klldn9slpuadn3bqyb0nzqc5nos4y6t
සැකිල්ල:මිලිටරි සහ යුද්ධ
10
105539
790937
558593
2026-04-11T22:15:50Z
en>Fma12
0
790937
wikitext
text/x-wiki
{{#invoke:navbox|navbox
| name = Military and war
| title =[[Military]] and [[war]]
| listclass = hlist
| state = {{{state|autocollapse}}}
| group1 = Concepts
| list1 =
* [[Military]]
* [[Military service|Service]]
* [[Military history|History]]
* [[History of military technology|Technology]]
* [[Military specialism|Occupational roles]]
* [[Military recruitment|Recruitment]]
* [[National security]]
**[[Computer security|Cyber]]
**[[Data sovereignty|Data]]
**[[Economic security|Economic]]
**[[Energy security|Energy]]
**[[Environmental security|Environmental]]
** [[Food security|Food]]
* ''Roles:''
* [[Soldier]]
* [[Sailor]]
* [[Airman]]
* [[Enlisted rank]]
* [[Officer (armed forces)|Officer]]
* [[Commanding officer]]
* [[Executive officer]]
* ''Protocols and structure:''
* [[Military rank|Ranks]]
** [[List of comparative military ranks|List]]
* [[Military uniform|Uniforms]]
* [[Military awards and decorations|Awards and decorations]]
** [[List of military decorations|By country]]
** [[List of highest military decorations|Highest]]
* ''Categories:''
* [[:Category:Military ranks|Ranks]]
| group2 = Forces
| list2 =
* [[Command and control]]
* [[Ministry of defence|Defense ministry]]
* ''[[Military|Armed Forces]]:''
* [[Army]]
* [[Navy]]
* [[Air force]]
* [[Marines]]
* [[Space force]]
* [[Special forces]]
* [[Airborne forces]]
* [[Commando]]
* [[Frogman]]
* [[Militia]]
* [[Military reserve force|Reserves]]
* ''Functional specialties:''
* [[Military communications|Communications]]
* [[Combat engineer|Engineers]]
* [[Military intelligence|Intelligence]]
* [[Reconnaissance]]
** [[List of reconnaissance units|List]]
* [[Medical corps|Medical]]
* [[Military police]]
* [[Gendarmerie]]
* [[Security forces]]
* [[Border guard]]
* [[Coast guard]]
* [[Military logistics|Logistics]]
** [[:Category:Military logistics units and formations|By country]]
* ''Categories:''
* [[:Category: Combat occupations|Combat occupations]]
* ''Development:''
* [[Military recruit training|Basic training]]
* [[Military exercise|Military maneuvers]]
* [[Combat|Combat training]]
| group3 = [[Military branch|Branches]]
| list3=
* ''Land units:''
* [[Combat arms]]
* [[Infantry]]
* [[Armoured fighting vehicle|Armor]]
** [[Cavalry]]
* [[Artillery]]
* [[Special reconnaissance]]
* [[Signal corps]]
* ''Naval units:''
* [[Warship]]s
** [[Surface combatant|Surface]]
** [[Littoral combat ship|Littoral]]
** [[Patrol boat|Patrol]]
* [[Submarine]]s
* [[Aircraft carrier]]s
* [[Landing craft]]
* [[Auxiliary ship]]
* ''Air units:''
* [[Fighter aircraft|Fighters]]
* [[Bomber]]s
* [[Airborne early warning and control|Command]]
* [[Close air support]]
* [[Electronic-warfare aircraft|Electronic-warfare]]
* [[Reconnaissance aircraft|Reconnaissance]]
| group5= Structure
| list5=
* [[Military organization|Organization]]
** [[:Category:Structure of contemporary armed forces|By country]]
** [[:Category:Structure of contemporary armies|Armies by country]]
* [[Command hierarchy|Chain of command]]
* [[Unified combatant command]]
* [[Staff (military)|General staff]]
* ''Land:''
* [[Army group]]
* [[Field army]]
* [[Corps]]
** [[List of military corps|List]]
* [[Division (military)|Division]]
** [[List of military divisions|List]]
* [[Brigade]]
** [[:Category:Brigades by type|By type]]
* [[Regiment]]
** [[:Category:Regiments by country|By country]]
** [[:Category:Regiments by type|By type]]
* [[Battalion]]
** [[:Category:Battalions by country|By country]]
** [[:Category:Battalions by type|By type]]
* [[Platoon]]
* [[Squad]]
* ''Naval:''
* [[Naval fleet]]
* [[Task force#Naval|Task force]]
* [[Carrier strike group]]
* [[Division (naval)|Division]]
* [[Flotilla]]
* [[Squadron (naval)|Squadron]]
* ''Air:''
* [[Combat box]]
* ''Special units by nation:''
* [[Battle Fleet|Battle Fleet; U.S. Navy]]
*[[Front (military formation)|Front; Russian land forces]]
| group7 = Vehicles
| list7 =
* ''Ground:''
* [[Military vehicle|Ground]]
** [[List of military vehicles|List]]
* [[Combat vehicle|Combat]]
* [[:Category:Tracked military vehicles|Tracked vehicles]]
* [[:Category: Wheeled military vehicles|Wheeled vehicles]]
* [[Armoured fighting vehicle|Armor]]
** [[Tank]]
** [[Infantry fighting vehicle]]
** [[Lists of armoured fighting vehicles|Lists]]
** [[List of armoured fighting vehicles by country|By country]]
* [[Armored car (military)|Armored car]]
* [[Scout car]]
* [[Military vehicle#Military trucks|Truck]]
** [[:Category:Military trucks|List]]
** [[Gun truck]]
* [[Self-propelled artillery]]
**[[List_of_howitzers#Self-propelled_howitzers|List]]
**[[Self-propelled anti-aircraft weapon|Anti-aircraft]]
* [[Military railways|Rail]]
| group10 = Weapons
| list10 = {{#invoke:navbox|navbox |child |groupstyle=padding-left:0.5em;padding-right:0.5em;font-weight:normal;
| group1 = Land
| list1 =
* [[Weapon]]s
** [[Lists of weapons|List]]
* ''Artillery:''
* [[Field artillery|Artillery]]
** [[List of artillery|List]]
** [[List of artillery by country|By country]]
** [[Artillery battery|Battery]]
* [[Field gun]]
** [[List of field guns|List]]
* [[Howitzer]]
** [[List of howitzers|List]]
* [[Rocket artillery|Rocket]]
** [[List of rocket artillery|List]]
* ''[[Small Arms and Light Weapons|Infantry guns]]:''
* [[Service pistol|Pistols]]
* [[Machine gun]]s
** [[List of machine guns|List]]
* ''[[Service rifle]]s:''
* [[Battle rifle]]s
** [[List of battle rifles|List]]
* [[Assault rifle]]
** [[List of assault rifles|List]]
* [[Sniper rifle]]
* ''Other infantry weapons:''
* [[Bazooka]]
* [[Anti-tank gun]]
** [[List of anti-tank guns|List]]
* [[Grenade]]
** [[:Category:Grenades|List]]
* [[Flamethrower]]
* [[Bayonet]]
* [[Combat knife]]
** [[:Category:Military knives|List]]
* ''[[Missile]]s:''
** [[Shoulder-fired missile|Shoulder-fired]]
** [[Anti-tank guided missile|Anti-tank]]
** [[List of missiles|List]]
** [[List of missiles by country|By country]]
* [[Mortar (weapon)|Mortar]]
** ''Lists:''
** [[List of infantry mortars|Infantry]]
** [[List of heavy mortars|Heavy]]
* ''Other:''
* [[Land mine]]
* [[Shell (projectile)|Shells]]
|group20= Sea/Air:
| list20=
* [[Missile|Guided missiles]]
** [[List of missiles|List]]
* ''[[Naval warfare|Naval]]:''
* [[Naval artillery]]
**[[List of naval guns|List]]
* [[Anti-ship missile]]s
* [[Torpedo]]es
* [[Depth charge]]s
* [[Close-in weapon system|Close-in weapons]]
* ''[[Aerial warfare|Aerial]]:''
* [[:category:Aircraft guns|Guns]]
* [[:Category:Air-launched missiles|Missiles]]
* [[Aerial bomb|Bombs]]
}}
| group15 = Equipment
| list15 =
* [[Military technology|Military equipment]]
** [[Lists of military equipment|Lists]]
** [[:Category:Military equipment by country|By country]]
* [[Combat helmet|Helmet]]
** [[List of combat helmets|List]]
* [[Military camouflage|Camouflage]]
** [[List of military clothing camouflage patterns|List]]
* [[Body armor]]
* ''Facilities:''
* [[Military base]]
** [[Lists of military installations|Lists]]
* [[Field hospital]]
| group17 = Combat systems
| list17 =
* [[Fire-control system]]
* [[Fire-control radar]]
* [[Director (military)]]
* [[Combat information center]]
* [[Sonar]]
* [[Radar]]
* ''Historical:''
* [[Ship gun fire-control system|Ship gun fire-control]]
* [[Gun data computer]]
* [[Torpedo Data Computer]]
| group19 = [[War]]fare
| list19 =
* [[War]]
* [[Battle]]
* [[Strategy]]
* [[Military tactics|Tactics]]
* [[Combat]]
* [[Military science]]
* [[Diplomacy]]
* [[International law]]
* ''By era:''
* [[Prehistoric warfare|Prehistoric]]
* [[Ancient warfare|Ancient]]
* [[Medieval warfare|Post-classical]]<!--Does not represent a world-wide view; requires a global history of the period between the 5th and 15th centuries-->
* [[Early modern warfare|Early modern]]
* [[Modern warfare|Late modern]]
** [[Industrial warfare|industrial]]
** [[Fourth-generation warfare|fourth-gen]]
* ''By type:''
* [[Armoured warfare]]
* [[Artillery]]
* [[Barrage (artillery)|Barrage]]
* [[Biological warfare|Biological]]
* [[Military camouflage|Camouflage]]
* [[Cavalry]]
* [[Chemical warfare|Chemical]]
* [[Class conflict|Class]]
* [[Combined arms]]
* [[Conventional warfare|Conventional]]
* [[Cyberweapon|Cyber]]
* [[Area denial weapon|Denial]]
* [[Disinformation]]
* [[Drone warfare|Drone]]
* [[Electronic warfare|Electronic]]
* [[Infantry]]
* [[Lawfare]]
* [[Loitering munition|Loitering]]
* [[Martial music|Music]]
* [[Nuclear warfare|Nuclear]]
* [[Psychological warfare|Psychological]]
* [[Radiological warfare|Radiological]]
* [[Unconventional warfare|Unconventional]]
| group20 = [[Battlespace]]
| list20 =
* Aerospace
** [[Aerial warfare|Air]]
** [[Airborne forces|Airborne]]
** [[Space warfare|Space]]
* [[Land warfare|Land]]
** [[Cold-weather warfare|Cold-region]]
** [[Desert warfare|Desert]]
** [[Jungle warfare|Jungle]]
** [[Mountain warfare|Mountain]]
** [[Urban warfare|Urban]]
* [[Naval warfare|Sea]]
** [[Amphibious warfare|Amphibious]]
** [[Blue-water navy|Blue]]
** [[Brown-water navy|Brown]]
** [[Green-water navy|Green]]
** [[Surface warfare|Surface]]
** [[Underwater warfare|Underwater]]
* [[Subterranean warfare|Subterranean]]
** [[Tunnel warfare|Tunnel]]
* [[Cyberwarfare|Cyber]]
* [[Information warfare|Information]]
| group22 = [[Military tactics|Tactics]]
| list22 =
* [[List of military tactics]]
* [[Air combat manoeuvring|Aerial]]
* [[Airlift]]
** [[Airbridge (logistics)|Airbridge]]
** [[Airdrop]]
* [[Battle]]
* [[Cavalry tactics|Cavalry]]
* [[Charge (warfare)|Charge]]
* [[Counterattack]]
* [[Counterinsurgency]]
* [[Defeat in detail]]
* [[Defensive fighting position|Foxhole]]
* [[Envelopment]]
* [[Guerrilla warfare|Guerrilla]]
* [[Morale]]
* [[Shock and awe|Rapid dominance]]
* [[Siege]]
* [[Swarming (military)|Swarming]]
* [[Tactical objective]]
* [[Saturation attack|Target saturation]]
* [[Trench warfare|Trench]]
* [[Withdrawal (military)|Withdrawal]]
| group24 = [[Operational level of war|Operational]]
| list24 =
* [[Military operation]]
* [[Operations research]]
* [[Blitzkrieg]]
* [[Expeditionary warfare|Expeditionary]]
* [[Deep operation]]
* [[Maneuver warfare|{{#switch:{{{spelling}}}|British=Manoeuvre|Maneuver}}]]
* [[Operational manoeuvre group]]
| group26 = [[Military strategy|Strategy]]
| list26 =
* [[List of military strategies and concepts]]
* [[Military campaign]]
* [[Attrition warfare|Attrition]]
* [[Counter-offensive]]
* [[Culminating point|Culminating]]
* [[Defence in depth]]
* [[Fabian strategy|Fabian]]
* [[Mosaic Warfare|Mosaic]]
* [[Military deception|Deception]]
* [[Strategic defence|Defensive]]
* [[Strategic depth|Depth]]
* [[Strategic goal (military)|Goal]]
* [[Naval strategy|Naval]]
* [[Offensive (military)|Offensive]]
* [[Scorched earth]]
| group30 = [[Policy]]
| list30 =
* ''[[Diplomacy]]:''
* [[Alliance]]s
* [[Peace treaty]]
* [[Cooperation]]
* [[Deterrence theory]]
* [[United Nations]]
* [[Mediation]]
* ''Public policy:''
* [[Conscription]]
* [[Military budget|Defense budget]]
** [[List of countries with highest military expenditures|List]]
** [[List of countries by past military expenditure|Past]]
** [[List of countries with highest military expenditure per capita|Per capita]]
* [[Military policy|Defense policy]]
* ''Related:''
* [[Government]]
* [[Nation]]
| group32 = [[:Category:Military lists|Lists]]
| list32 =
* ''Military lists''
* [[Outline of war#Wars|Wars]]
* [[Lists of weapons|Weapons]]
* [[List of military tactics|Military tactics]]
* ''History lists:''
* [[Lists of wars|Wars]]
* [[Lists of battles|Battles]]
* [[List of military occupations|Military occupations]]
* [[List of military operations|Operations]]
* [[List of sieges|Sieges]]
* ''Related lists:''
* [[List of war crimes|War crimes]]
* [[List of military writers|Writers]]
| group35 = Other<br> namespace
| list35 =
{{#invoke:navbox|navbox |child |groupstyle=padding-left:0.5em;padding-right:0.5em;font-weight:normal;
| group1=Templates
| list1=
* {{tlp|War}}
* {{tlp|Weapons}}
* {{tlp|Military ranks by country|alttext=Ranks}}
* ''Vehicles and weapons''
** {{tlp|Tanks}}
** {{tlp|Weapons}}
** {{tlp|Modern IFV and APC|alttext=Infantry fighting vehicles}}
** {{tlp|Warship types of the 19th & 20th centuries|alttext=Modern warships}}
** {{tlp|Military aircraft types (roles)|alttext=Aircraft}}
* ''Specific modern wars''
** {{tlp|World War I}}
** {{tlp|World War II}}
** {{tlp|Cold War}}
** {{tlp|War on terror}}
|group2=Categories
|list2=
* [[:Category:Lists of wars by country involved|Lists of wars by country]]
* [[:Category: Conflicts by time|Conflicts by time]]
}}
| group40 = Related
| list40 =
* [[Peace]]
* [[Peace and conflict studies]]
* [[Peace movement]]
* [[Peace process]]
* [[Disarmament]]
* [[Pacifism]]
* [[Détente]]
* [[Global studies]]
* [[Conscientious objector]]
* [[Anti-war movement]]
* [[Idealism in international relations]]
* [[Humanitarianism]]
* [[Multilateralism|International cooperation]]
* [[Crimes against humanity]]
* {{tlp|International relations}}
* ''Categories:''
* [[:Category: Peace organizations|Peace organizations]]
<!--
* Internationalism
* Coexistence
* Mutualism
* Reconciliation
--->
| below =
{{#invoke:Icon|main|category}}'''[[:Category:War|Category]]''' {{#invoke:Icon|main|commons}}'''[[commons:CategoryWar|Commons]]'''
}}<noinclude>
{{documentation}}
</noinclude>
q2rlublp1nmlbsrpgzsq0y2obtwl1vu
790938
790937
2026-05-20T03:42:45Z
Lee
85
[[:en:Template:Military_and_war]] වෙතින් එක් සංශෝධනයක්
790937
wikitext
text/x-wiki
{{#invoke:navbox|navbox
| name = Military and war
| title =[[Military]] and [[war]]
| listclass = hlist
| state = {{{state|autocollapse}}}
| group1 = Concepts
| list1 =
* [[Military]]
* [[Military service|Service]]
* [[Military history|History]]
* [[History of military technology|Technology]]
* [[Military specialism|Occupational roles]]
* [[Military recruitment|Recruitment]]
* [[National security]]
**[[Computer security|Cyber]]
**[[Data sovereignty|Data]]
**[[Economic security|Economic]]
**[[Energy security|Energy]]
**[[Environmental security|Environmental]]
** [[Food security|Food]]
* ''Roles:''
* [[Soldier]]
* [[Sailor]]
* [[Airman]]
* [[Enlisted rank]]
* [[Officer (armed forces)|Officer]]
* [[Commanding officer]]
* [[Executive officer]]
* ''Protocols and structure:''
* [[Military rank|Ranks]]
** [[List of comparative military ranks|List]]
* [[Military uniform|Uniforms]]
* [[Military awards and decorations|Awards and decorations]]
** [[List of military decorations|By country]]
** [[List of highest military decorations|Highest]]
* ''Categories:''
* [[:Category:Military ranks|Ranks]]
| group2 = Forces
| list2 =
* [[Command and control]]
* [[Ministry of defence|Defense ministry]]
* ''[[Military|Armed Forces]]:''
* [[Army]]
* [[Navy]]
* [[Air force]]
* [[Marines]]
* [[Space force]]
* [[Special forces]]
* [[Airborne forces]]
* [[Commando]]
* [[Frogman]]
* [[Militia]]
* [[Military reserve force|Reserves]]
* ''Functional specialties:''
* [[Military communications|Communications]]
* [[Combat engineer|Engineers]]
* [[Military intelligence|Intelligence]]
* [[Reconnaissance]]
** [[List of reconnaissance units|List]]
* [[Medical corps|Medical]]
* [[Military police]]
* [[Gendarmerie]]
* [[Security forces]]
* [[Border guard]]
* [[Coast guard]]
* [[Military logistics|Logistics]]
** [[:Category:Military logistics units and formations|By country]]
* ''Categories:''
* [[:Category: Combat occupations|Combat occupations]]
* ''Development:''
* [[Military recruit training|Basic training]]
* [[Military exercise|Military maneuvers]]
* [[Combat|Combat training]]
| group3 = [[Military branch|Branches]]
| list3=
* ''Land units:''
* [[Combat arms]]
* [[Infantry]]
* [[Armoured fighting vehicle|Armor]]
** [[Cavalry]]
* [[Artillery]]
* [[Special reconnaissance]]
* [[Signal corps]]
* ''Naval units:''
* [[Warship]]s
** [[Surface combatant|Surface]]
** [[Littoral combat ship|Littoral]]
** [[Patrol boat|Patrol]]
* [[Submarine]]s
* [[Aircraft carrier]]s
* [[Landing craft]]
* [[Auxiliary ship]]
* ''Air units:''
* [[Fighter aircraft|Fighters]]
* [[Bomber]]s
* [[Airborne early warning and control|Command]]
* [[Close air support]]
* [[Electronic-warfare aircraft|Electronic-warfare]]
* [[Reconnaissance aircraft|Reconnaissance]]
| group5= Structure
| list5=
* [[Military organization|Organization]]
** [[:Category:Structure of contemporary armed forces|By country]]
** [[:Category:Structure of contemporary armies|Armies by country]]
* [[Command hierarchy|Chain of command]]
* [[Unified combatant command]]
* [[Staff (military)|General staff]]
* ''Land:''
* [[Army group]]
* [[Field army]]
* [[Corps]]
** [[List of military corps|List]]
* [[Division (military)|Division]]
** [[List of military divisions|List]]
* [[Brigade]]
** [[:Category:Brigades by type|By type]]
* [[Regiment]]
** [[:Category:Regiments by country|By country]]
** [[:Category:Regiments by type|By type]]
* [[Battalion]]
** [[:Category:Battalions by country|By country]]
** [[:Category:Battalions by type|By type]]
* [[Platoon]]
* [[Squad]]
* ''Naval:''
* [[Naval fleet]]
* [[Task force#Naval|Task force]]
* [[Carrier strike group]]
* [[Division (naval)|Division]]
* [[Flotilla]]
* [[Squadron (naval)|Squadron]]
* ''Air:''
* [[Combat box]]
* ''Special units by nation:''
* [[Battle Fleet|Battle Fleet; U.S. Navy]]
*[[Front (military formation)|Front; Russian land forces]]
| group7 = Vehicles
| list7 =
* ''Ground:''
* [[Military vehicle|Ground]]
** [[List of military vehicles|List]]
* [[Combat vehicle|Combat]]
* [[:Category:Tracked military vehicles|Tracked vehicles]]
* [[:Category: Wheeled military vehicles|Wheeled vehicles]]
* [[Armoured fighting vehicle|Armor]]
** [[Tank]]
** [[Infantry fighting vehicle]]
** [[Lists of armoured fighting vehicles|Lists]]
** [[List of armoured fighting vehicles by country|By country]]
* [[Armored car (military)|Armored car]]
* [[Scout car]]
* [[Military vehicle#Military trucks|Truck]]
** [[:Category:Military trucks|List]]
** [[Gun truck]]
* [[Self-propelled artillery]]
**[[List_of_howitzers#Self-propelled_howitzers|List]]
**[[Self-propelled anti-aircraft weapon|Anti-aircraft]]
* [[Military railways|Rail]]
| group10 = Weapons
| list10 = {{#invoke:navbox|navbox |child |groupstyle=padding-left:0.5em;padding-right:0.5em;font-weight:normal;
| group1 = Land
| list1 =
* [[Weapon]]s
** [[Lists of weapons|List]]
* ''Artillery:''
* [[Field artillery|Artillery]]
** [[List of artillery|List]]
** [[List of artillery by country|By country]]
** [[Artillery battery|Battery]]
* [[Field gun]]
** [[List of field guns|List]]
* [[Howitzer]]
** [[List of howitzers|List]]
* [[Rocket artillery|Rocket]]
** [[List of rocket artillery|List]]
* ''[[Small Arms and Light Weapons|Infantry guns]]:''
* [[Service pistol|Pistols]]
* [[Machine gun]]s
** [[List of machine guns|List]]
* ''[[Service rifle]]s:''
* [[Battle rifle]]s
** [[List of battle rifles|List]]
* [[Assault rifle]]
** [[List of assault rifles|List]]
* [[Sniper rifle]]
* ''Other infantry weapons:''
* [[Bazooka]]
* [[Anti-tank gun]]
** [[List of anti-tank guns|List]]
* [[Grenade]]
** [[:Category:Grenades|List]]
* [[Flamethrower]]
* [[Bayonet]]
* [[Combat knife]]
** [[:Category:Military knives|List]]
* ''[[Missile]]s:''
** [[Shoulder-fired missile|Shoulder-fired]]
** [[Anti-tank guided missile|Anti-tank]]
** [[List of missiles|List]]
** [[List of missiles by country|By country]]
* [[Mortar (weapon)|Mortar]]
** ''Lists:''
** [[List of infantry mortars|Infantry]]
** [[List of heavy mortars|Heavy]]
* ''Other:''
* [[Land mine]]
* [[Shell (projectile)|Shells]]
|group20= Sea/Air:
| list20=
* [[Missile|Guided missiles]]
** [[List of missiles|List]]
* ''[[Naval warfare|Naval]]:''
* [[Naval artillery]]
**[[List of naval guns|List]]
* [[Anti-ship missile]]s
* [[Torpedo]]es
* [[Depth charge]]s
* [[Close-in weapon system|Close-in weapons]]
* ''[[Aerial warfare|Aerial]]:''
* [[:category:Aircraft guns|Guns]]
* [[:Category:Air-launched missiles|Missiles]]
* [[Aerial bomb|Bombs]]
}}
| group15 = Equipment
| list15 =
* [[Military technology|Military equipment]]
** [[Lists of military equipment|Lists]]
** [[:Category:Military equipment by country|By country]]
* [[Combat helmet|Helmet]]
** [[List of combat helmets|List]]
* [[Military camouflage|Camouflage]]
** [[List of military clothing camouflage patterns|List]]
* [[Body armor]]
* ''Facilities:''
* [[Military base]]
** [[Lists of military installations|Lists]]
* [[Field hospital]]
| group17 = Combat systems
| list17 =
* [[Fire-control system]]
* [[Fire-control radar]]
* [[Director (military)]]
* [[Combat information center]]
* [[Sonar]]
* [[Radar]]
* ''Historical:''
* [[Ship gun fire-control system|Ship gun fire-control]]
* [[Gun data computer]]
* [[Torpedo Data Computer]]
| group19 = [[War]]fare
| list19 =
* [[War]]
* [[Battle]]
* [[Strategy]]
* [[Military tactics|Tactics]]
* [[Combat]]
* [[Military science]]
* [[Diplomacy]]
* [[International law]]
* ''By era:''
* [[Prehistoric warfare|Prehistoric]]
* [[Ancient warfare|Ancient]]
* [[Medieval warfare|Post-classical]]<!--Does not represent a world-wide view; requires a global history of the period between the 5th and 15th centuries-->
* [[Early modern warfare|Early modern]]
* [[Modern warfare|Late modern]]
** [[Industrial warfare|industrial]]
** [[Fourth-generation warfare|fourth-gen]]
* ''By type:''
* [[Armoured warfare]]
* [[Artillery]]
* [[Barrage (artillery)|Barrage]]
* [[Biological warfare|Biological]]
* [[Military camouflage|Camouflage]]
* [[Cavalry]]
* [[Chemical warfare|Chemical]]
* [[Class conflict|Class]]
* [[Combined arms]]
* [[Conventional warfare|Conventional]]
* [[Cyberweapon|Cyber]]
* [[Area denial weapon|Denial]]
* [[Disinformation]]
* [[Drone warfare|Drone]]
* [[Electronic warfare|Electronic]]
* [[Infantry]]
* [[Lawfare]]
* [[Loitering munition|Loitering]]
* [[Martial music|Music]]
* [[Nuclear warfare|Nuclear]]
* [[Psychological warfare|Psychological]]
* [[Radiological warfare|Radiological]]
* [[Unconventional warfare|Unconventional]]
| group20 = [[Battlespace]]
| list20 =
* Aerospace
** [[Aerial warfare|Air]]
** [[Airborne forces|Airborne]]
** [[Space warfare|Space]]
* [[Land warfare|Land]]
** [[Cold-weather warfare|Cold-region]]
** [[Desert warfare|Desert]]
** [[Jungle warfare|Jungle]]
** [[Mountain warfare|Mountain]]
** [[Urban warfare|Urban]]
* [[Naval warfare|Sea]]
** [[Amphibious warfare|Amphibious]]
** [[Blue-water navy|Blue]]
** [[Brown-water navy|Brown]]
** [[Green-water navy|Green]]
** [[Surface warfare|Surface]]
** [[Underwater warfare|Underwater]]
* [[Subterranean warfare|Subterranean]]
** [[Tunnel warfare|Tunnel]]
* [[Cyberwarfare|Cyber]]
* [[Information warfare|Information]]
| group22 = [[Military tactics|Tactics]]
| list22 =
* [[List of military tactics]]
* [[Air combat manoeuvring|Aerial]]
* [[Airlift]]
** [[Airbridge (logistics)|Airbridge]]
** [[Airdrop]]
* [[Battle]]
* [[Cavalry tactics|Cavalry]]
* [[Charge (warfare)|Charge]]
* [[Counterattack]]
* [[Counterinsurgency]]
* [[Defeat in detail]]
* [[Defensive fighting position|Foxhole]]
* [[Envelopment]]
* [[Guerrilla warfare|Guerrilla]]
* [[Morale]]
* [[Shock and awe|Rapid dominance]]
* [[Siege]]
* [[Swarming (military)|Swarming]]
* [[Tactical objective]]
* [[Saturation attack|Target saturation]]
* [[Trench warfare|Trench]]
* [[Withdrawal (military)|Withdrawal]]
| group24 = [[Operational level of war|Operational]]
| list24 =
* [[Military operation]]
* [[Operations research]]
* [[Blitzkrieg]]
* [[Expeditionary warfare|Expeditionary]]
* [[Deep operation]]
* [[Maneuver warfare|{{#switch:{{{spelling}}}|British=Manoeuvre|Maneuver}}]]
* [[Operational manoeuvre group]]
| group26 = [[Military strategy|Strategy]]
| list26 =
* [[List of military strategies and concepts]]
* [[Military campaign]]
* [[Attrition warfare|Attrition]]
* [[Counter-offensive]]
* [[Culminating point|Culminating]]
* [[Defence in depth]]
* [[Fabian strategy|Fabian]]
* [[Mosaic Warfare|Mosaic]]
* [[Military deception|Deception]]
* [[Strategic defence|Defensive]]
* [[Strategic depth|Depth]]
* [[Strategic goal (military)|Goal]]
* [[Naval strategy|Naval]]
* [[Offensive (military)|Offensive]]
* [[Scorched earth]]
| group30 = [[Policy]]
| list30 =
* ''[[Diplomacy]]:''
* [[Alliance]]s
* [[Peace treaty]]
* [[Cooperation]]
* [[Deterrence theory]]
* [[United Nations]]
* [[Mediation]]
* ''Public policy:''
* [[Conscription]]
* [[Military budget|Defense budget]]
** [[List of countries with highest military expenditures|List]]
** [[List of countries by past military expenditure|Past]]
** [[List of countries with highest military expenditure per capita|Per capita]]
* [[Military policy|Defense policy]]
* ''Related:''
* [[Government]]
* [[Nation]]
| group32 = [[:Category:Military lists|Lists]]
| list32 =
* ''Military lists''
* [[Outline of war#Wars|Wars]]
* [[Lists of weapons|Weapons]]
* [[List of military tactics|Military tactics]]
* ''History lists:''
* [[Lists of wars|Wars]]
* [[Lists of battles|Battles]]
* [[List of military occupations|Military occupations]]
* [[List of military operations|Operations]]
* [[List of sieges|Sieges]]
* ''Related lists:''
* [[List of war crimes|War crimes]]
* [[List of military writers|Writers]]
| group35 = Other<br> namespace
| list35 =
{{#invoke:navbox|navbox |child |groupstyle=padding-left:0.5em;padding-right:0.5em;font-weight:normal;
| group1=Templates
| list1=
* {{tlp|War}}
* {{tlp|Weapons}}
* {{tlp|Military ranks by country|alttext=Ranks}}
* ''Vehicles and weapons''
** {{tlp|Tanks}}
** {{tlp|Weapons}}
** {{tlp|Modern IFV and APC|alttext=Infantry fighting vehicles}}
** {{tlp|Warship types of the 19th & 20th centuries|alttext=Modern warships}}
** {{tlp|Military aircraft types (roles)|alttext=Aircraft}}
* ''Specific modern wars''
** {{tlp|World War I}}
** {{tlp|World War II}}
** {{tlp|Cold War}}
** {{tlp|War on terror}}
|group2=Categories
|list2=
* [[:Category:Lists of wars by country involved|Lists of wars by country]]
* [[:Category: Conflicts by time|Conflicts by time]]
}}
| group40 = Related
| list40 =
* [[Peace]]
* [[Peace and conflict studies]]
* [[Peace movement]]
* [[Peace process]]
* [[Disarmament]]
* [[Pacifism]]
* [[Détente]]
* [[Global studies]]
* [[Conscientious objector]]
* [[Anti-war movement]]
* [[Idealism in international relations]]
* [[Humanitarianism]]
* [[Multilateralism|International cooperation]]
* [[Crimes against humanity]]
* {{tlp|International relations}}
* ''Categories:''
* [[:Category: Peace organizations|Peace organizations]]
<!--
* Internationalism
* Coexistence
* Mutualism
* Reconciliation
--->
| below =
{{#invoke:Icon|main|category}}'''[[:Category:War|Category]]''' {{#invoke:Icon|main|commons}}'''[[commons:CategoryWar|Commons]]'''
}}<noinclude>
{{documentation}}
</noinclude>
q2rlublp1nmlbsrpgzsq0y2obtwl1vu
790939
790938
2026-05-20T03:43:56Z
Lee
85
790939
wikitext
text/x-wiki
{{#invoke:navbox|navbox
| name = Military and war
| title =[[Military|මිලිටරි]] සහ [[war|යුද්ධ]]
| listclass = hlist
| state = {{{state|autocollapse}}}
| group1 = Concepts
| list1 =
* [[Military]]
* [[Military service|Service]]
* [[Military history|History]]
* [[History of military technology|Technology]]
* [[Military specialism|Occupational roles]]
* [[Military recruitment|Recruitment]]
* [[National security]]
**[[Computer security|Cyber]]
**[[Data sovereignty|Data]]
**[[Economic security|Economic]]
**[[Energy security|Energy]]
**[[Environmental security|Environmental]]
** [[Food security|Food]]
* ''Roles:''
* [[Soldier]]
* [[Sailor]]
* [[Airman]]
* [[Enlisted rank]]
* [[Officer (armed forces)|Officer]]
* [[Commanding officer]]
* [[Executive officer]]
* ''Protocols and structure:''
* [[Military rank|Ranks]]
** [[List of comparative military ranks|List]]
* [[Military uniform|Uniforms]]
* [[Military awards and decorations|Awards and decorations]]
** [[List of military decorations|By country]]
** [[List of highest military decorations|Highest]]
* ''Categories:''
* [[:Category:Military ranks|Ranks]]
| group2 = Forces
| list2 =
* [[Command and control]]
* [[Ministry of defence|Defense ministry]]
* ''[[Military|Armed Forces]]:''
* [[Army]]
* [[Navy]]
* [[Air force]]
* [[Marines]]
* [[Space force]]
* [[Special forces]]
* [[Airborne forces]]
* [[Commando]]
* [[Frogman]]
* [[Militia]]
* [[Military reserve force|Reserves]]
* ''Functional specialties:''
* [[Military communications|Communications]]
* [[Combat engineer|Engineers]]
* [[Military intelligence|Intelligence]]
* [[Reconnaissance]]
** [[List of reconnaissance units|List]]
* [[Medical corps|Medical]]
* [[Military police]]
* [[Gendarmerie]]
* [[Security forces]]
* [[Border guard]]
* [[Coast guard]]
* [[Military logistics|Logistics]]
** [[:Category:Military logistics units and formations|By country]]
* ''Categories:''
* [[:Category: Combat occupations|Combat occupations]]
* ''Development:''
* [[Military recruit training|Basic training]]
* [[Military exercise|Military maneuvers]]
* [[Combat|Combat training]]
| group3 = [[Military branch|Branches]]
| list3=
* ''Land units:''
* [[Combat arms]]
* [[Infantry]]
* [[Armoured fighting vehicle|Armor]]
** [[Cavalry]]
* [[Artillery]]
* [[Special reconnaissance]]
* [[Signal corps]]
* ''Naval units:''
* [[Warship]]s
** [[Surface combatant|Surface]]
** [[Littoral combat ship|Littoral]]
** [[Patrol boat|Patrol]]
* [[Submarine]]s
* [[Aircraft carrier]]s
* [[Landing craft]]
* [[Auxiliary ship]]
* ''Air units:''
* [[Fighter aircraft|Fighters]]
* [[Bomber]]s
* [[Airborne early warning and control|Command]]
* [[Close air support]]
* [[Electronic-warfare aircraft|Electronic-warfare]]
* [[Reconnaissance aircraft|Reconnaissance]]
| group5= Structure
| list5=
* [[Military organization|Organization]]
** [[:Category:Structure of contemporary armed forces|By country]]
** [[:Category:Structure of contemporary armies|Armies by country]]
* [[Command hierarchy|Chain of command]]
* [[Unified combatant command]]
* [[Staff (military)|General staff]]
* ''Land:''
* [[Army group]]
* [[Field army]]
* [[Corps]]
** [[List of military corps|List]]
* [[Division (military)|Division]]
** [[List of military divisions|List]]
* [[Brigade]]
** [[:Category:Brigades by type|By type]]
* [[Regiment]]
** [[:Category:Regiments by country|By country]]
** [[:Category:Regiments by type|By type]]
* [[Battalion]]
** [[:Category:Battalions by country|By country]]
** [[:Category:Battalions by type|By type]]
* [[Platoon]]
* [[Squad]]
* ''Naval:''
* [[Naval fleet]]
* [[Task force#Naval|Task force]]
* [[Carrier strike group]]
* [[Division (naval)|Division]]
* [[Flotilla]]
* [[Squadron (naval)|Squadron]]
* ''Air:''
* [[Combat box]]
* ''Special units by nation:''
* [[Battle Fleet|Battle Fleet; U.S. Navy]]
*[[Front (military formation)|Front; Russian land forces]]
| group7 = Vehicles
| list7 =
* ''Ground:''
* [[Military vehicle|Ground]]
** [[List of military vehicles|List]]
* [[Combat vehicle|Combat]]
* [[:Category:Tracked military vehicles|Tracked vehicles]]
* [[:Category: Wheeled military vehicles|Wheeled vehicles]]
* [[Armoured fighting vehicle|Armor]]
** [[Tank]]
** [[Infantry fighting vehicle]]
** [[Lists of armoured fighting vehicles|Lists]]
** [[List of armoured fighting vehicles by country|By country]]
* [[Armored car (military)|Armored car]]
* [[Scout car]]
* [[Military vehicle#Military trucks|Truck]]
** [[:Category:Military trucks|List]]
** [[Gun truck]]
* [[Self-propelled artillery]]
**[[List_of_howitzers#Self-propelled_howitzers|List]]
**[[Self-propelled anti-aircraft weapon|Anti-aircraft]]
* [[Military railways|Rail]]
| group10 = Weapons
| list10 = {{#invoke:navbox|navbox |child |groupstyle=padding-left:0.5em;padding-right:0.5em;font-weight:normal;
| group1 = Land
| list1 =
* [[Weapon]]s
** [[Lists of weapons|List]]
* ''Artillery:''
* [[Field artillery|Artillery]]
** [[List of artillery|List]]
** [[List of artillery by country|By country]]
** [[Artillery battery|Battery]]
* [[Field gun]]
** [[List of field guns|List]]
* [[Howitzer]]
** [[List of howitzers|List]]
* [[Rocket artillery|Rocket]]
** [[List of rocket artillery|List]]
* ''[[Small Arms and Light Weapons|Infantry guns]]:''
* [[Service pistol|Pistols]]
* [[Machine gun]]s
** [[List of machine guns|List]]
* ''[[Service rifle]]s:''
* [[Battle rifle]]s
** [[List of battle rifles|List]]
* [[Assault rifle]]
** [[List of assault rifles|List]]
* [[Sniper rifle]]
* ''Other infantry weapons:''
* [[Bazooka]]
* [[Anti-tank gun]]
** [[List of anti-tank guns|List]]
* [[Grenade]]
** [[:Category:Grenades|List]]
* [[Flamethrower]]
* [[Bayonet]]
* [[Combat knife]]
** [[:Category:Military knives|List]]
* ''[[Missile]]s:''
** [[Shoulder-fired missile|Shoulder-fired]]
** [[Anti-tank guided missile|Anti-tank]]
** [[List of missiles|List]]
** [[List of missiles by country|By country]]
* [[Mortar (weapon)|Mortar]]
** ''Lists:''
** [[List of infantry mortars|Infantry]]
** [[List of heavy mortars|Heavy]]
* ''Other:''
* [[Land mine]]
* [[Shell (projectile)|Shells]]
|group20= Sea/Air:
| list20=
* [[Missile|Guided missiles]]
** [[List of missiles|List]]
* ''[[Naval warfare|Naval]]:''
* [[Naval artillery]]
**[[List of naval guns|List]]
* [[Anti-ship missile]]s
* [[Torpedo]]es
* [[Depth charge]]s
* [[Close-in weapon system|Close-in weapons]]
* ''[[Aerial warfare|Aerial]]:''
* [[:category:Aircraft guns|Guns]]
* [[:Category:Air-launched missiles|Missiles]]
* [[Aerial bomb|Bombs]]
}}
| group15 = Equipment
| list15 =
* [[Military technology|Military equipment]]
** [[Lists of military equipment|Lists]]
** [[:Category:Military equipment by country|By country]]
* [[Combat helmet|Helmet]]
** [[List of combat helmets|List]]
* [[Military camouflage|Camouflage]]
** [[List of military clothing camouflage patterns|List]]
* [[Body armor]]
* ''Facilities:''
* [[Military base]]
** [[Lists of military installations|Lists]]
* [[Field hospital]]
| group17 = Combat systems
| list17 =
* [[Fire-control system]]
* [[Fire-control radar]]
* [[Director (military)]]
* [[Combat information center]]
* [[Sonar]]
* [[Radar]]
* ''Historical:''
* [[Ship gun fire-control system|Ship gun fire-control]]
* [[Gun data computer]]
* [[Torpedo Data Computer]]
| group19 = [[War]]fare
| list19 =
* [[War]]
* [[Battle]]
* [[Strategy]]
* [[Military tactics|Tactics]]
* [[Combat]]
* [[Military science]]
* [[Diplomacy]]
* [[International law]]
* ''By era:''
* [[Prehistoric warfare|Prehistoric]]
* [[Ancient warfare|Ancient]]
* [[Medieval warfare|Post-classical]]<!--Does not represent a world-wide view; requires a global history of the period between the 5th and 15th centuries-->
* [[Early modern warfare|Early modern]]
* [[Modern warfare|Late modern]]
** [[Industrial warfare|industrial]]
** [[Fourth-generation warfare|fourth-gen]]
* ''By type:''
* [[Armoured warfare]]
* [[Artillery]]
* [[Barrage (artillery)|Barrage]]
* [[Biological warfare|Biological]]
* [[Military camouflage|Camouflage]]
* [[Cavalry]]
* [[Chemical warfare|Chemical]]
* [[Class conflict|Class]]
* [[Combined arms]]
* [[Conventional warfare|Conventional]]
* [[Cyberweapon|Cyber]]
* [[Area denial weapon|Denial]]
* [[Disinformation]]
* [[Drone warfare|Drone]]
* [[Electronic warfare|Electronic]]
* [[Infantry]]
* [[Lawfare]]
* [[Loitering munition|Loitering]]
* [[Martial music|Music]]
* [[Nuclear warfare|Nuclear]]
* [[Psychological warfare|Psychological]]
* [[Radiological warfare|Radiological]]
* [[Unconventional warfare|Unconventional]]
| group20 = [[Battlespace]]
| list20 =
* Aerospace
** [[Aerial warfare|Air]]
** [[Airborne forces|Airborne]]
** [[Space warfare|Space]]
* [[Land warfare|Land]]
** [[Cold-weather warfare|Cold-region]]
** [[Desert warfare|Desert]]
** [[Jungle warfare|Jungle]]
** [[Mountain warfare|Mountain]]
** [[Urban warfare|Urban]]
* [[Naval warfare|Sea]]
** [[Amphibious warfare|Amphibious]]
** [[Blue-water navy|Blue]]
** [[Brown-water navy|Brown]]
** [[Green-water navy|Green]]
** [[Surface warfare|Surface]]
** [[Underwater warfare|Underwater]]
* [[Subterranean warfare|Subterranean]]
** [[Tunnel warfare|Tunnel]]
* [[Cyberwarfare|Cyber]]
* [[Information warfare|Information]]
| group22 = [[Military tactics|Tactics]]
| list22 =
* [[List of military tactics]]
* [[Air combat manoeuvring|Aerial]]
* [[Airlift]]
** [[Airbridge (logistics)|Airbridge]]
** [[Airdrop]]
* [[Battle]]
* [[Cavalry tactics|Cavalry]]
* [[Charge (warfare)|Charge]]
* [[Counterattack]]
* [[Counterinsurgency]]
* [[Defeat in detail]]
* [[Defensive fighting position|Foxhole]]
* [[Envelopment]]
* [[Guerrilla warfare|Guerrilla]]
* [[Morale]]
* [[Shock and awe|Rapid dominance]]
* [[Siege]]
* [[Swarming (military)|Swarming]]
* [[Tactical objective]]
* [[Saturation attack|Target saturation]]
* [[Trench warfare|Trench]]
* [[Withdrawal (military)|Withdrawal]]
| group24 = [[Operational level of war|Operational]]
| list24 =
* [[Military operation]]
* [[Operations research]]
* [[Blitzkrieg]]
* [[Expeditionary warfare|Expeditionary]]
* [[Deep operation]]
* [[Maneuver warfare|{{#switch:{{{spelling}}}|British=Manoeuvre|Maneuver}}]]
* [[Operational manoeuvre group]]
| group26 = [[Military strategy|Strategy]]
| list26 =
* [[List of military strategies and concepts]]
* [[Military campaign]]
* [[Attrition warfare|Attrition]]
* [[Counter-offensive]]
* [[Culminating point|Culminating]]
* [[Defence in depth]]
* [[Fabian strategy|Fabian]]
* [[Mosaic Warfare|Mosaic]]
* [[Military deception|Deception]]
* [[Strategic defence|Defensive]]
* [[Strategic depth|Depth]]
* [[Strategic goal (military)|Goal]]
* [[Naval strategy|Naval]]
* [[Offensive (military)|Offensive]]
* [[Scorched earth]]
| group30 = [[Policy]]
| list30 =
* ''[[Diplomacy]]:''
* [[Alliance]]s
* [[Peace treaty]]
* [[Cooperation]]
* [[Deterrence theory]]
* [[United Nations]]
* [[Mediation]]
* ''Public policy:''
* [[Conscription]]
* [[Military budget|Defense budget]]
** [[List of countries with highest military expenditures|List]]
** [[List of countries by past military expenditure|Past]]
** [[List of countries with highest military expenditure per capita|Per capita]]
* [[Military policy|Defense policy]]
* ''Related:''
* [[Government]]
* [[Nation]]
| group32 = [[:Category:Military lists|Lists]]
| list32 =
* ''Military lists''
* [[Outline of war#Wars|Wars]]
* [[Lists of weapons|Weapons]]
* [[List of military tactics|Military tactics]]
* ''History lists:''
* [[Lists of wars|Wars]]
* [[Lists of battles|Battles]]
* [[List of military occupations|Military occupations]]
* [[List of military operations|Operations]]
* [[List of sieges|Sieges]]
* ''Related lists:''
* [[List of war crimes|War crimes]]
* [[List of military writers|Writers]]
| group35 = Other<br> namespace
| list35 =
{{#invoke:navbox|navbox |child |groupstyle=padding-left:0.5em;padding-right:0.5em;font-weight:normal;
| group1=Templates
| list1=
* {{tlp|War}}
* {{tlp|Weapons}}
* {{tlp|Military ranks by country|alttext=Ranks}}
* ''Vehicles and weapons''
** {{tlp|Tanks}}
** {{tlp|Weapons}}
** {{tlp|Modern IFV and APC|alttext=Infantry fighting vehicles}}
** {{tlp|Warship types of the 19th & 20th centuries|alttext=Modern warships}}
** {{tlp|Military aircraft types (roles)|alttext=Aircraft}}
* ''Specific modern wars''
** {{tlp|World War I}}
** {{tlp|World War II}}
** {{tlp|Cold War}}
** {{tlp|War on terror}}
|group2=Categories
|list2=
* [[:Category:Lists of wars by country involved|Lists of wars by country]]
* [[:Category: Conflicts by time|Conflicts by time]]
}}
| group40 = Related
| list40 =
* [[Peace]]
* [[Peace and conflict studies]]
* [[Peace movement]]
* [[Peace process]]
* [[Disarmament]]
* [[Pacifism]]
* [[Détente]]
* [[Global studies]]
* [[Conscientious objector]]
* [[Anti-war movement]]
* [[Idealism in international relations]]
* [[Humanitarianism]]
* [[Multilateralism|International cooperation]]
* [[Crimes against humanity]]
* {{tlp|International relations}}
* ''Categories:''
* [[:Category: Peace organizations|Peace organizations]]
<!--
* Internationalism
* Coexistence
* Mutualism
* Reconciliation
--->
| below =
{{#invoke:Icon|main|category}}'''[[:Category:War|ප්රවර්ගය]]''' {{#invoke:Icon|main|commons}}'''[[commons:CategoryWar|කොමන්ස්]]'''
}}<noinclude>
{{documentation}}
</noinclude>
jjsqlyjpoi6raw2y0ff41khultrmllq
790942
790939
2026-05-20T03:45:05Z
Lee
85
Lee විසින් [[සැකිල්ල:Military and war]] සිට [[සැකිල්ල:මිලිටරි සහ යුද්ධ]] වෙත පිටුව ගෙන යන ලදී
790939
wikitext
text/x-wiki
{{#invoke:navbox|navbox
| name = Military and war
| title =[[Military|මිලිටරි]] සහ [[war|යුද්ධ]]
| listclass = hlist
| state = {{{state|autocollapse}}}
| group1 = Concepts
| list1 =
* [[Military]]
* [[Military service|Service]]
* [[Military history|History]]
* [[History of military technology|Technology]]
* [[Military specialism|Occupational roles]]
* [[Military recruitment|Recruitment]]
* [[National security]]
**[[Computer security|Cyber]]
**[[Data sovereignty|Data]]
**[[Economic security|Economic]]
**[[Energy security|Energy]]
**[[Environmental security|Environmental]]
** [[Food security|Food]]
* ''Roles:''
* [[Soldier]]
* [[Sailor]]
* [[Airman]]
* [[Enlisted rank]]
* [[Officer (armed forces)|Officer]]
* [[Commanding officer]]
* [[Executive officer]]
* ''Protocols and structure:''
* [[Military rank|Ranks]]
** [[List of comparative military ranks|List]]
* [[Military uniform|Uniforms]]
* [[Military awards and decorations|Awards and decorations]]
** [[List of military decorations|By country]]
** [[List of highest military decorations|Highest]]
* ''Categories:''
* [[:Category:Military ranks|Ranks]]
| group2 = Forces
| list2 =
* [[Command and control]]
* [[Ministry of defence|Defense ministry]]
* ''[[Military|Armed Forces]]:''
* [[Army]]
* [[Navy]]
* [[Air force]]
* [[Marines]]
* [[Space force]]
* [[Special forces]]
* [[Airborne forces]]
* [[Commando]]
* [[Frogman]]
* [[Militia]]
* [[Military reserve force|Reserves]]
* ''Functional specialties:''
* [[Military communications|Communications]]
* [[Combat engineer|Engineers]]
* [[Military intelligence|Intelligence]]
* [[Reconnaissance]]
** [[List of reconnaissance units|List]]
* [[Medical corps|Medical]]
* [[Military police]]
* [[Gendarmerie]]
* [[Security forces]]
* [[Border guard]]
* [[Coast guard]]
* [[Military logistics|Logistics]]
** [[:Category:Military logistics units and formations|By country]]
* ''Categories:''
* [[:Category: Combat occupations|Combat occupations]]
* ''Development:''
* [[Military recruit training|Basic training]]
* [[Military exercise|Military maneuvers]]
* [[Combat|Combat training]]
| group3 = [[Military branch|Branches]]
| list3=
* ''Land units:''
* [[Combat arms]]
* [[Infantry]]
* [[Armoured fighting vehicle|Armor]]
** [[Cavalry]]
* [[Artillery]]
* [[Special reconnaissance]]
* [[Signal corps]]
* ''Naval units:''
* [[Warship]]s
** [[Surface combatant|Surface]]
** [[Littoral combat ship|Littoral]]
** [[Patrol boat|Patrol]]
* [[Submarine]]s
* [[Aircraft carrier]]s
* [[Landing craft]]
* [[Auxiliary ship]]
* ''Air units:''
* [[Fighter aircraft|Fighters]]
* [[Bomber]]s
* [[Airborne early warning and control|Command]]
* [[Close air support]]
* [[Electronic-warfare aircraft|Electronic-warfare]]
* [[Reconnaissance aircraft|Reconnaissance]]
| group5= Structure
| list5=
* [[Military organization|Organization]]
** [[:Category:Structure of contemporary armed forces|By country]]
** [[:Category:Structure of contemporary armies|Armies by country]]
* [[Command hierarchy|Chain of command]]
* [[Unified combatant command]]
* [[Staff (military)|General staff]]
* ''Land:''
* [[Army group]]
* [[Field army]]
* [[Corps]]
** [[List of military corps|List]]
* [[Division (military)|Division]]
** [[List of military divisions|List]]
* [[Brigade]]
** [[:Category:Brigades by type|By type]]
* [[Regiment]]
** [[:Category:Regiments by country|By country]]
** [[:Category:Regiments by type|By type]]
* [[Battalion]]
** [[:Category:Battalions by country|By country]]
** [[:Category:Battalions by type|By type]]
* [[Platoon]]
* [[Squad]]
* ''Naval:''
* [[Naval fleet]]
* [[Task force#Naval|Task force]]
* [[Carrier strike group]]
* [[Division (naval)|Division]]
* [[Flotilla]]
* [[Squadron (naval)|Squadron]]
* ''Air:''
* [[Combat box]]
* ''Special units by nation:''
* [[Battle Fleet|Battle Fleet; U.S. Navy]]
*[[Front (military formation)|Front; Russian land forces]]
| group7 = Vehicles
| list7 =
* ''Ground:''
* [[Military vehicle|Ground]]
** [[List of military vehicles|List]]
* [[Combat vehicle|Combat]]
* [[:Category:Tracked military vehicles|Tracked vehicles]]
* [[:Category: Wheeled military vehicles|Wheeled vehicles]]
* [[Armoured fighting vehicle|Armor]]
** [[Tank]]
** [[Infantry fighting vehicle]]
** [[Lists of armoured fighting vehicles|Lists]]
** [[List of armoured fighting vehicles by country|By country]]
* [[Armored car (military)|Armored car]]
* [[Scout car]]
* [[Military vehicle#Military trucks|Truck]]
** [[:Category:Military trucks|List]]
** [[Gun truck]]
* [[Self-propelled artillery]]
**[[List_of_howitzers#Self-propelled_howitzers|List]]
**[[Self-propelled anti-aircraft weapon|Anti-aircraft]]
* [[Military railways|Rail]]
| group10 = Weapons
| list10 = {{#invoke:navbox|navbox |child |groupstyle=padding-left:0.5em;padding-right:0.5em;font-weight:normal;
| group1 = Land
| list1 =
* [[Weapon]]s
** [[Lists of weapons|List]]
* ''Artillery:''
* [[Field artillery|Artillery]]
** [[List of artillery|List]]
** [[List of artillery by country|By country]]
** [[Artillery battery|Battery]]
* [[Field gun]]
** [[List of field guns|List]]
* [[Howitzer]]
** [[List of howitzers|List]]
* [[Rocket artillery|Rocket]]
** [[List of rocket artillery|List]]
* ''[[Small Arms and Light Weapons|Infantry guns]]:''
* [[Service pistol|Pistols]]
* [[Machine gun]]s
** [[List of machine guns|List]]
* ''[[Service rifle]]s:''
* [[Battle rifle]]s
** [[List of battle rifles|List]]
* [[Assault rifle]]
** [[List of assault rifles|List]]
* [[Sniper rifle]]
* ''Other infantry weapons:''
* [[Bazooka]]
* [[Anti-tank gun]]
** [[List of anti-tank guns|List]]
* [[Grenade]]
** [[:Category:Grenades|List]]
* [[Flamethrower]]
* [[Bayonet]]
* [[Combat knife]]
** [[:Category:Military knives|List]]
* ''[[Missile]]s:''
** [[Shoulder-fired missile|Shoulder-fired]]
** [[Anti-tank guided missile|Anti-tank]]
** [[List of missiles|List]]
** [[List of missiles by country|By country]]
* [[Mortar (weapon)|Mortar]]
** ''Lists:''
** [[List of infantry mortars|Infantry]]
** [[List of heavy mortars|Heavy]]
* ''Other:''
* [[Land mine]]
* [[Shell (projectile)|Shells]]
|group20= Sea/Air:
| list20=
* [[Missile|Guided missiles]]
** [[List of missiles|List]]
* ''[[Naval warfare|Naval]]:''
* [[Naval artillery]]
**[[List of naval guns|List]]
* [[Anti-ship missile]]s
* [[Torpedo]]es
* [[Depth charge]]s
* [[Close-in weapon system|Close-in weapons]]
* ''[[Aerial warfare|Aerial]]:''
* [[:category:Aircraft guns|Guns]]
* [[:Category:Air-launched missiles|Missiles]]
* [[Aerial bomb|Bombs]]
}}
| group15 = Equipment
| list15 =
* [[Military technology|Military equipment]]
** [[Lists of military equipment|Lists]]
** [[:Category:Military equipment by country|By country]]
* [[Combat helmet|Helmet]]
** [[List of combat helmets|List]]
* [[Military camouflage|Camouflage]]
** [[List of military clothing camouflage patterns|List]]
* [[Body armor]]
* ''Facilities:''
* [[Military base]]
** [[Lists of military installations|Lists]]
* [[Field hospital]]
| group17 = Combat systems
| list17 =
* [[Fire-control system]]
* [[Fire-control radar]]
* [[Director (military)]]
* [[Combat information center]]
* [[Sonar]]
* [[Radar]]
* ''Historical:''
* [[Ship gun fire-control system|Ship gun fire-control]]
* [[Gun data computer]]
* [[Torpedo Data Computer]]
| group19 = [[War]]fare
| list19 =
* [[War]]
* [[Battle]]
* [[Strategy]]
* [[Military tactics|Tactics]]
* [[Combat]]
* [[Military science]]
* [[Diplomacy]]
* [[International law]]
* ''By era:''
* [[Prehistoric warfare|Prehistoric]]
* [[Ancient warfare|Ancient]]
* [[Medieval warfare|Post-classical]]<!--Does not represent a world-wide view; requires a global history of the period between the 5th and 15th centuries-->
* [[Early modern warfare|Early modern]]
* [[Modern warfare|Late modern]]
** [[Industrial warfare|industrial]]
** [[Fourth-generation warfare|fourth-gen]]
* ''By type:''
* [[Armoured warfare]]
* [[Artillery]]
* [[Barrage (artillery)|Barrage]]
* [[Biological warfare|Biological]]
* [[Military camouflage|Camouflage]]
* [[Cavalry]]
* [[Chemical warfare|Chemical]]
* [[Class conflict|Class]]
* [[Combined arms]]
* [[Conventional warfare|Conventional]]
* [[Cyberweapon|Cyber]]
* [[Area denial weapon|Denial]]
* [[Disinformation]]
* [[Drone warfare|Drone]]
* [[Electronic warfare|Electronic]]
* [[Infantry]]
* [[Lawfare]]
* [[Loitering munition|Loitering]]
* [[Martial music|Music]]
* [[Nuclear warfare|Nuclear]]
* [[Psychological warfare|Psychological]]
* [[Radiological warfare|Radiological]]
* [[Unconventional warfare|Unconventional]]
| group20 = [[Battlespace]]
| list20 =
* Aerospace
** [[Aerial warfare|Air]]
** [[Airborne forces|Airborne]]
** [[Space warfare|Space]]
* [[Land warfare|Land]]
** [[Cold-weather warfare|Cold-region]]
** [[Desert warfare|Desert]]
** [[Jungle warfare|Jungle]]
** [[Mountain warfare|Mountain]]
** [[Urban warfare|Urban]]
* [[Naval warfare|Sea]]
** [[Amphibious warfare|Amphibious]]
** [[Blue-water navy|Blue]]
** [[Brown-water navy|Brown]]
** [[Green-water navy|Green]]
** [[Surface warfare|Surface]]
** [[Underwater warfare|Underwater]]
* [[Subterranean warfare|Subterranean]]
** [[Tunnel warfare|Tunnel]]
* [[Cyberwarfare|Cyber]]
* [[Information warfare|Information]]
| group22 = [[Military tactics|Tactics]]
| list22 =
* [[List of military tactics]]
* [[Air combat manoeuvring|Aerial]]
* [[Airlift]]
** [[Airbridge (logistics)|Airbridge]]
** [[Airdrop]]
* [[Battle]]
* [[Cavalry tactics|Cavalry]]
* [[Charge (warfare)|Charge]]
* [[Counterattack]]
* [[Counterinsurgency]]
* [[Defeat in detail]]
* [[Defensive fighting position|Foxhole]]
* [[Envelopment]]
* [[Guerrilla warfare|Guerrilla]]
* [[Morale]]
* [[Shock and awe|Rapid dominance]]
* [[Siege]]
* [[Swarming (military)|Swarming]]
* [[Tactical objective]]
* [[Saturation attack|Target saturation]]
* [[Trench warfare|Trench]]
* [[Withdrawal (military)|Withdrawal]]
| group24 = [[Operational level of war|Operational]]
| list24 =
* [[Military operation]]
* [[Operations research]]
* [[Blitzkrieg]]
* [[Expeditionary warfare|Expeditionary]]
* [[Deep operation]]
* [[Maneuver warfare|{{#switch:{{{spelling}}}|British=Manoeuvre|Maneuver}}]]
* [[Operational manoeuvre group]]
| group26 = [[Military strategy|Strategy]]
| list26 =
* [[List of military strategies and concepts]]
* [[Military campaign]]
* [[Attrition warfare|Attrition]]
* [[Counter-offensive]]
* [[Culminating point|Culminating]]
* [[Defence in depth]]
* [[Fabian strategy|Fabian]]
* [[Mosaic Warfare|Mosaic]]
* [[Military deception|Deception]]
* [[Strategic defence|Defensive]]
* [[Strategic depth|Depth]]
* [[Strategic goal (military)|Goal]]
* [[Naval strategy|Naval]]
* [[Offensive (military)|Offensive]]
* [[Scorched earth]]
| group30 = [[Policy]]
| list30 =
* ''[[Diplomacy]]:''
* [[Alliance]]s
* [[Peace treaty]]
* [[Cooperation]]
* [[Deterrence theory]]
* [[United Nations]]
* [[Mediation]]
* ''Public policy:''
* [[Conscription]]
* [[Military budget|Defense budget]]
** [[List of countries with highest military expenditures|List]]
** [[List of countries by past military expenditure|Past]]
** [[List of countries with highest military expenditure per capita|Per capita]]
* [[Military policy|Defense policy]]
* ''Related:''
* [[Government]]
* [[Nation]]
| group32 = [[:Category:Military lists|Lists]]
| list32 =
* ''Military lists''
* [[Outline of war#Wars|Wars]]
* [[Lists of weapons|Weapons]]
* [[List of military tactics|Military tactics]]
* ''History lists:''
* [[Lists of wars|Wars]]
* [[Lists of battles|Battles]]
* [[List of military occupations|Military occupations]]
* [[List of military operations|Operations]]
* [[List of sieges|Sieges]]
* ''Related lists:''
* [[List of war crimes|War crimes]]
* [[List of military writers|Writers]]
| group35 = Other<br> namespace
| list35 =
{{#invoke:navbox|navbox |child |groupstyle=padding-left:0.5em;padding-right:0.5em;font-weight:normal;
| group1=Templates
| list1=
* {{tlp|War}}
* {{tlp|Weapons}}
* {{tlp|Military ranks by country|alttext=Ranks}}
* ''Vehicles and weapons''
** {{tlp|Tanks}}
** {{tlp|Weapons}}
** {{tlp|Modern IFV and APC|alttext=Infantry fighting vehicles}}
** {{tlp|Warship types of the 19th & 20th centuries|alttext=Modern warships}}
** {{tlp|Military aircraft types (roles)|alttext=Aircraft}}
* ''Specific modern wars''
** {{tlp|World War I}}
** {{tlp|World War II}}
** {{tlp|Cold War}}
** {{tlp|War on terror}}
|group2=Categories
|list2=
* [[:Category:Lists of wars by country involved|Lists of wars by country]]
* [[:Category: Conflicts by time|Conflicts by time]]
}}
| group40 = Related
| list40 =
* [[Peace]]
* [[Peace and conflict studies]]
* [[Peace movement]]
* [[Peace process]]
* [[Disarmament]]
* [[Pacifism]]
* [[Détente]]
* [[Global studies]]
* [[Conscientious objector]]
* [[Anti-war movement]]
* [[Idealism in international relations]]
* [[Humanitarianism]]
* [[Multilateralism|International cooperation]]
* [[Crimes against humanity]]
* {{tlp|International relations}}
* ''Categories:''
* [[:Category: Peace organizations|Peace organizations]]
<!--
* Internationalism
* Coexistence
* Mutualism
* Reconciliation
--->
| below =
{{#invoke:Icon|main|category}}'''[[:Category:War|ප්රවර්ගය]]''' {{#invoke:Icon|main|commons}}'''[[commons:CategoryWar|කොමන්ස්]]'''
}}<noinclude>
{{documentation}}
</noinclude>
jjsqlyjpoi6raw2y0ff41khultrmllq
790946
790942
2026-05-20T03:45:28Z
Lee
85
790946
wikitext
text/x-wiki
{{#invoke:navbox|navbox
| name = මිලිටරි සහ යුද්ධ
| title = මිලිටරි සහ [[war|යුද්ධ]]
| listclass = hlist
| state = {{{state|autocollapse}}}
| group1 = Concepts
| list1 =
* [[Military]]
* [[Military service|Service]]
* [[Military history|History]]
* [[History of military technology|Technology]]
* [[Military specialism|Occupational roles]]
* [[Military recruitment|Recruitment]]
* [[National security]]
**[[Computer security|Cyber]]
**[[Data sovereignty|Data]]
**[[Economic security|Economic]]
**[[Energy security|Energy]]
**[[Environmental security|Environmental]]
** [[Food security|Food]]
* ''Roles:''
* [[Soldier]]
* [[Sailor]]
* [[Airman]]
* [[Enlisted rank]]
* [[Officer (armed forces)|Officer]]
* [[Commanding officer]]
* [[Executive officer]]
* ''Protocols and structure:''
* [[Military rank|Ranks]]
** [[List of comparative military ranks|List]]
* [[Military uniform|Uniforms]]
* [[Military awards and decorations|Awards and decorations]]
** [[List of military decorations|By country]]
** [[List of highest military decorations|Highest]]
* ''Categories:''
* [[:Category:Military ranks|Ranks]]
| group2 = Forces
| list2 =
* [[Command and control]]
* [[Ministry of defence|Defense ministry]]
* ''[[Military|Armed Forces]]:''
* [[Army]]
* [[Navy]]
* [[Air force]]
* [[Marines]]
* [[Space force]]
* [[Special forces]]
* [[Airborne forces]]
* [[Commando]]
* [[Frogman]]
* [[Militia]]
* [[Military reserve force|Reserves]]
* ''Functional specialties:''
* [[Military communications|Communications]]
* [[Combat engineer|Engineers]]
* [[Military intelligence|Intelligence]]
* [[Reconnaissance]]
** [[List of reconnaissance units|List]]
* [[Medical corps|Medical]]
* [[Military police]]
* [[Gendarmerie]]
* [[Security forces]]
* [[Border guard]]
* [[Coast guard]]
* [[Military logistics|Logistics]]
** [[:Category:Military logistics units and formations|By country]]
* ''Categories:''
* [[:Category: Combat occupations|Combat occupations]]
* ''Development:''
* [[Military recruit training|Basic training]]
* [[Military exercise|Military maneuvers]]
* [[Combat|Combat training]]
| group3 = [[Military branch|Branches]]
| list3=
* ''Land units:''
* [[Combat arms]]
* [[Infantry]]
* [[Armoured fighting vehicle|Armor]]
** [[Cavalry]]
* [[Artillery]]
* [[Special reconnaissance]]
* [[Signal corps]]
* ''Naval units:''
* [[Warship]]s
** [[Surface combatant|Surface]]
** [[Littoral combat ship|Littoral]]
** [[Patrol boat|Patrol]]
* [[Submarine]]s
* [[Aircraft carrier]]s
* [[Landing craft]]
* [[Auxiliary ship]]
* ''Air units:''
* [[Fighter aircraft|Fighters]]
* [[Bomber]]s
* [[Airborne early warning and control|Command]]
* [[Close air support]]
* [[Electronic-warfare aircraft|Electronic-warfare]]
* [[Reconnaissance aircraft|Reconnaissance]]
| group5= Structure
| list5=
* [[Military organization|Organization]]
** [[:Category:Structure of contemporary armed forces|By country]]
** [[:Category:Structure of contemporary armies|Armies by country]]
* [[Command hierarchy|Chain of command]]
* [[Unified combatant command]]
* [[Staff (military)|General staff]]
* ''Land:''
* [[Army group]]
* [[Field army]]
* [[Corps]]
** [[List of military corps|List]]
* [[Division (military)|Division]]
** [[List of military divisions|List]]
* [[Brigade]]
** [[:Category:Brigades by type|By type]]
* [[Regiment]]
** [[:Category:Regiments by country|By country]]
** [[:Category:Regiments by type|By type]]
* [[Battalion]]
** [[:Category:Battalions by country|By country]]
** [[:Category:Battalions by type|By type]]
* [[Platoon]]
* [[Squad]]
* ''Naval:''
* [[Naval fleet]]
* [[Task force#Naval|Task force]]
* [[Carrier strike group]]
* [[Division (naval)|Division]]
* [[Flotilla]]
* [[Squadron (naval)|Squadron]]
* ''Air:''
* [[Combat box]]
* ''Special units by nation:''
* [[Battle Fleet|Battle Fleet; U.S. Navy]]
*[[Front (military formation)|Front; Russian land forces]]
| group7 = Vehicles
| list7 =
* ''Ground:''
* [[Military vehicle|Ground]]
** [[List of military vehicles|List]]
* [[Combat vehicle|Combat]]
* [[:Category:Tracked military vehicles|Tracked vehicles]]
* [[:Category: Wheeled military vehicles|Wheeled vehicles]]
* [[Armoured fighting vehicle|Armor]]
** [[Tank]]
** [[Infantry fighting vehicle]]
** [[Lists of armoured fighting vehicles|Lists]]
** [[List of armoured fighting vehicles by country|By country]]
* [[Armored car (military)|Armored car]]
* [[Scout car]]
* [[Military vehicle#Military trucks|Truck]]
** [[:Category:Military trucks|List]]
** [[Gun truck]]
* [[Self-propelled artillery]]
**[[List_of_howitzers#Self-propelled_howitzers|List]]
**[[Self-propelled anti-aircraft weapon|Anti-aircraft]]
* [[Military railways|Rail]]
| group10 = Weapons
| list10 = {{#invoke:navbox|navbox |child |groupstyle=padding-left:0.5em;padding-right:0.5em;font-weight:normal;
| group1 = Land
| list1 =
* [[Weapon]]s
** [[Lists of weapons|List]]
* ''Artillery:''
* [[Field artillery|Artillery]]
** [[List of artillery|List]]
** [[List of artillery by country|By country]]
** [[Artillery battery|Battery]]
* [[Field gun]]
** [[List of field guns|List]]
* [[Howitzer]]
** [[List of howitzers|List]]
* [[Rocket artillery|Rocket]]
** [[List of rocket artillery|List]]
* ''[[Small Arms and Light Weapons|Infantry guns]]:''
* [[Service pistol|Pistols]]
* [[Machine gun]]s
** [[List of machine guns|List]]
* ''[[Service rifle]]s:''
* [[Battle rifle]]s
** [[List of battle rifles|List]]
* [[Assault rifle]]
** [[List of assault rifles|List]]
* [[Sniper rifle]]
* ''Other infantry weapons:''
* [[Bazooka]]
* [[Anti-tank gun]]
** [[List of anti-tank guns|List]]
* [[Grenade]]
** [[:Category:Grenades|List]]
* [[Flamethrower]]
* [[Bayonet]]
* [[Combat knife]]
** [[:Category:Military knives|List]]
* ''[[Missile]]s:''
** [[Shoulder-fired missile|Shoulder-fired]]
** [[Anti-tank guided missile|Anti-tank]]
** [[List of missiles|List]]
** [[List of missiles by country|By country]]
* [[Mortar (weapon)|Mortar]]
** ''Lists:''
** [[List of infantry mortars|Infantry]]
** [[List of heavy mortars|Heavy]]
* ''Other:''
* [[Land mine]]
* [[Shell (projectile)|Shells]]
|group20= Sea/Air:
| list20=
* [[Missile|Guided missiles]]
** [[List of missiles|List]]
* ''[[Naval warfare|Naval]]:''
* [[Naval artillery]]
**[[List of naval guns|List]]
* [[Anti-ship missile]]s
* [[Torpedo]]es
* [[Depth charge]]s
* [[Close-in weapon system|Close-in weapons]]
* ''[[Aerial warfare|Aerial]]:''
* [[:category:Aircraft guns|Guns]]
* [[:Category:Air-launched missiles|Missiles]]
* [[Aerial bomb|Bombs]]
}}
| group15 = Equipment
| list15 =
* [[Military technology|Military equipment]]
** [[Lists of military equipment|Lists]]
** [[:Category:Military equipment by country|By country]]
* [[Combat helmet|Helmet]]
** [[List of combat helmets|List]]
* [[Military camouflage|Camouflage]]
** [[List of military clothing camouflage patterns|List]]
* [[Body armor]]
* ''Facilities:''
* [[Military base]]
** [[Lists of military installations|Lists]]
* [[Field hospital]]
| group17 = Combat systems
| list17 =
* [[Fire-control system]]
* [[Fire-control radar]]
* [[Director (military)]]
* [[Combat information center]]
* [[Sonar]]
* [[Radar]]
* ''Historical:''
* [[Ship gun fire-control system|Ship gun fire-control]]
* [[Gun data computer]]
* [[Torpedo Data Computer]]
| group19 = [[War]]fare
| list19 =
* [[War]]
* [[Battle]]
* [[Strategy]]
* [[Military tactics|Tactics]]
* [[Combat]]
* [[Military science]]
* [[Diplomacy]]
* [[International law]]
* ''By era:''
* [[Prehistoric warfare|Prehistoric]]
* [[Ancient warfare|Ancient]]
* [[Medieval warfare|Post-classical]]<!--Does not represent a world-wide view; requires a global history of the period between the 5th and 15th centuries-->
* [[Early modern warfare|Early modern]]
* [[Modern warfare|Late modern]]
** [[Industrial warfare|industrial]]
** [[Fourth-generation warfare|fourth-gen]]
* ''By type:''
* [[Armoured warfare]]
* [[Artillery]]
* [[Barrage (artillery)|Barrage]]
* [[Biological warfare|Biological]]
* [[Military camouflage|Camouflage]]
* [[Cavalry]]
* [[Chemical warfare|Chemical]]
* [[Class conflict|Class]]
* [[Combined arms]]
* [[Conventional warfare|Conventional]]
* [[Cyberweapon|Cyber]]
* [[Area denial weapon|Denial]]
* [[Disinformation]]
* [[Drone warfare|Drone]]
* [[Electronic warfare|Electronic]]
* [[Infantry]]
* [[Lawfare]]
* [[Loitering munition|Loitering]]
* [[Martial music|Music]]
* [[Nuclear warfare|Nuclear]]
* [[Psychological warfare|Psychological]]
* [[Radiological warfare|Radiological]]
* [[Unconventional warfare|Unconventional]]
| group20 = [[Battlespace]]
| list20 =
* Aerospace
** [[Aerial warfare|Air]]
** [[Airborne forces|Airborne]]
** [[Space warfare|Space]]
* [[Land warfare|Land]]
** [[Cold-weather warfare|Cold-region]]
** [[Desert warfare|Desert]]
** [[Jungle warfare|Jungle]]
** [[Mountain warfare|Mountain]]
** [[Urban warfare|Urban]]
* [[Naval warfare|Sea]]
** [[Amphibious warfare|Amphibious]]
** [[Blue-water navy|Blue]]
** [[Brown-water navy|Brown]]
** [[Green-water navy|Green]]
** [[Surface warfare|Surface]]
** [[Underwater warfare|Underwater]]
* [[Subterranean warfare|Subterranean]]
** [[Tunnel warfare|Tunnel]]
* [[Cyberwarfare|Cyber]]
* [[Information warfare|Information]]
| group22 = [[Military tactics|Tactics]]
| list22 =
* [[List of military tactics]]
* [[Air combat manoeuvring|Aerial]]
* [[Airlift]]
** [[Airbridge (logistics)|Airbridge]]
** [[Airdrop]]
* [[Battle]]
* [[Cavalry tactics|Cavalry]]
* [[Charge (warfare)|Charge]]
* [[Counterattack]]
* [[Counterinsurgency]]
* [[Defeat in detail]]
* [[Defensive fighting position|Foxhole]]
* [[Envelopment]]
* [[Guerrilla warfare|Guerrilla]]
* [[Morale]]
* [[Shock and awe|Rapid dominance]]
* [[Siege]]
* [[Swarming (military)|Swarming]]
* [[Tactical objective]]
* [[Saturation attack|Target saturation]]
* [[Trench warfare|Trench]]
* [[Withdrawal (military)|Withdrawal]]
| group24 = [[Operational level of war|Operational]]
| list24 =
* [[Military operation]]
* [[Operations research]]
* [[Blitzkrieg]]
* [[Expeditionary warfare|Expeditionary]]
* [[Deep operation]]
* [[Maneuver warfare|{{#switch:{{{spelling}}}|British=Manoeuvre|Maneuver}}]]
* [[Operational manoeuvre group]]
| group26 = [[Military strategy|Strategy]]
| list26 =
* [[List of military strategies and concepts]]
* [[Military campaign]]
* [[Attrition warfare|Attrition]]
* [[Counter-offensive]]
* [[Culminating point|Culminating]]
* [[Defence in depth]]
* [[Fabian strategy|Fabian]]
* [[Mosaic Warfare|Mosaic]]
* [[Military deception|Deception]]
* [[Strategic defence|Defensive]]
* [[Strategic depth|Depth]]
* [[Strategic goal (military)|Goal]]
* [[Naval strategy|Naval]]
* [[Offensive (military)|Offensive]]
* [[Scorched earth]]
| group30 = [[Policy]]
| list30 =
* ''[[Diplomacy]]:''
* [[Alliance]]s
* [[Peace treaty]]
* [[Cooperation]]
* [[Deterrence theory]]
* [[United Nations]]
* [[Mediation]]
* ''Public policy:''
* [[Conscription]]
* [[Military budget|Defense budget]]
** [[List of countries with highest military expenditures|List]]
** [[List of countries by past military expenditure|Past]]
** [[List of countries with highest military expenditure per capita|Per capita]]
* [[Military policy|Defense policy]]
* ''Related:''
* [[Government]]
* [[Nation]]
| group32 = [[:Category:Military lists|Lists]]
| list32 =
* ''Military lists''
* [[Outline of war#Wars|Wars]]
* [[Lists of weapons|Weapons]]
* [[List of military tactics|Military tactics]]
* ''History lists:''
* [[Lists of wars|Wars]]
* [[Lists of battles|Battles]]
* [[List of military occupations|Military occupations]]
* [[List of military operations|Operations]]
* [[List of sieges|Sieges]]
* ''Related lists:''
* [[List of war crimes|War crimes]]
* [[List of military writers|Writers]]
| group35 = Other<br> namespace
| list35 =
{{#invoke:navbox|navbox |child |groupstyle=padding-left:0.5em;padding-right:0.5em;font-weight:normal;
| group1=Templates
| list1=
* {{tlp|War}}
* {{tlp|Weapons}}
* {{tlp|Military ranks by country|alttext=Ranks}}
* ''Vehicles and weapons''
** {{tlp|Tanks}}
** {{tlp|Weapons}}
** {{tlp|Modern IFV and APC|alttext=Infantry fighting vehicles}}
** {{tlp|Warship types of the 19th & 20th centuries|alttext=Modern warships}}
** {{tlp|Military aircraft types (roles)|alttext=Aircraft}}
* ''Specific modern wars''
** {{tlp|World War I}}
** {{tlp|World War II}}
** {{tlp|Cold War}}
** {{tlp|War on terror}}
|group2=Categories
|list2=
* [[:Category:Lists of wars by country involved|Lists of wars by country]]
* [[:Category: Conflicts by time|Conflicts by time]]
}}
| group40 = Related
| list40 =
* [[Peace]]
* [[Peace and conflict studies]]
* [[Peace movement]]
* [[Peace process]]
* [[Disarmament]]
* [[Pacifism]]
* [[Détente]]
* [[Global studies]]
* [[Conscientious objector]]
* [[Anti-war movement]]
* [[Idealism in international relations]]
* [[Humanitarianism]]
* [[Multilateralism|International cooperation]]
* [[Crimes against humanity]]
* {{tlp|International relations}}
* ''Categories:''
* [[:Category: Peace organizations|Peace organizations]]
<!--
* Internationalism
* Coexistence
* Mutualism
* Reconciliation
--->
| below =
{{#invoke:Icon|main|category}}'''[[:Category:War|ප්රවර්ගය]]''' {{#invoke:Icon|main|commons}}'''[[commons:CategoryWar|කොමන්ස්]]'''
}}<noinclude>
{{documentation}}
</noinclude>
4rf7qw07m6vcnd61jvzleiq4miezckk
790947
790946
2026-05-20T03:45:38Z
Lee
85
790947
wikitext
text/x-wiki
{{#invoke:navbox|navbox
| name = මිලිටරි සහ යුද්ධ
| title = [[මිලිටරි]] සහ [[war|යුද්ධ]]
| listclass = hlist
| state = {{{state|autocollapse}}}
| group1 = Concepts
| list1 =
* [[Military]]
* [[Military service|Service]]
* [[Military history|History]]
* [[History of military technology|Technology]]
* [[Military specialism|Occupational roles]]
* [[Military recruitment|Recruitment]]
* [[National security]]
**[[Computer security|Cyber]]
**[[Data sovereignty|Data]]
**[[Economic security|Economic]]
**[[Energy security|Energy]]
**[[Environmental security|Environmental]]
** [[Food security|Food]]
* ''Roles:''
* [[Soldier]]
* [[Sailor]]
* [[Airman]]
* [[Enlisted rank]]
* [[Officer (armed forces)|Officer]]
* [[Commanding officer]]
* [[Executive officer]]
* ''Protocols and structure:''
* [[Military rank|Ranks]]
** [[List of comparative military ranks|List]]
* [[Military uniform|Uniforms]]
* [[Military awards and decorations|Awards and decorations]]
** [[List of military decorations|By country]]
** [[List of highest military decorations|Highest]]
* ''Categories:''
* [[:Category:Military ranks|Ranks]]
| group2 = Forces
| list2 =
* [[Command and control]]
* [[Ministry of defence|Defense ministry]]
* ''[[Military|Armed Forces]]:''
* [[Army]]
* [[Navy]]
* [[Air force]]
* [[Marines]]
* [[Space force]]
* [[Special forces]]
* [[Airborne forces]]
* [[Commando]]
* [[Frogman]]
* [[Militia]]
* [[Military reserve force|Reserves]]
* ''Functional specialties:''
* [[Military communications|Communications]]
* [[Combat engineer|Engineers]]
* [[Military intelligence|Intelligence]]
* [[Reconnaissance]]
** [[List of reconnaissance units|List]]
* [[Medical corps|Medical]]
* [[Military police]]
* [[Gendarmerie]]
* [[Security forces]]
* [[Border guard]]
* [[Coast guard]]
* [[Military logistics|Logistics]]
** [[:Category:Military logistics units and formations|By country]]
* ''Categories:''
* [[:Category: Combat occupations|Combat occupations]]
* ''Development:''
* [[Military recruit training|Basic training]]
* [[Military exercise|Military maneuvers]]
* [[Combat|Combat training]]
| group3 = [[Military branch|Branches]]
| list3=
* ''Land units:''
* [[Combat arms]]
* [[Infantry]]
* [[Armoured fighting vehicle|Armor]]
** [[Cavalry]]
* [[Artillery]]
* [[Special reconnaissance]]
* [[Signal corps]]
* ''Naval units:''
* [[Warship]]s
** [[Surface combatant|Surface]]
** [[Littoral combat ship|Littoral]]
** [[Patrol boat|Patrol]]
* [[Submarine]]s
* [[Aircraft carrier]]s
* [[Landing craft]]
* [[Auxiliary ship]]
* ''Air units:''
* [[Fighter aircraft|Fighters]]
* [[Bomber]]s
* [[Airborne early warning and control|Command]]
* [[Close air support]]
* [[Electronic-warfare aircraft|Electronic-warfare]]
* [[Reconnaissance aircraft|Reconnaissance]]
| group5= Structure
| list5=
* [[Military organization|Organization]]
** [[:Category:Structure of contemporary armed forces|By country]]
** [[:Category:Structure of contemporary armies|Armies by country]]
* [[Command hierarchy|Chain of command]]
* [[Unified combatant command]]
* [[Staff (military)|General staff]]
* ''Land:''
* [[Army group]]
* [[Field army]]
* [[Corps]]
** [[List of military corps|List]]
* [[Division (military)|Division]]
** [[List of military divisions|List]]
* [[Brigade]]
** [[:Category:Brigades by type|By type]]
* [[Regiment]]
** [[:Category:Regiments by country|By country]]
** [[:Category:Regiments by type|By type]]
* [[Battalion]]
** [[:Category:Battalions by country|By country]]
** [[:Category:Battalions by type|By type]]
* [[Platoon]]
* [[Squad]]
* ''Naval:''
* [[Naval fleet]]
* [[Task force#Naval|Task force]]
* [[Carrier strike group]]
* [[Division (naval)|Division]]
* [[Flotilla]]
* [[Squadron (naval)|Squadron]]
* ''Air:''
* [[Combat box]]
* ''Special units by nation:''
* [[Battle Fleet|Battle Fleet; U.S. Navy]]
*[[Front (military formation)|Front; Russian land forces]]
| group7 = Vehicles
| list7 =
* ''Ground:''
* [[Military vehicle|Ground]]
** [[List of military vehicles|List]]
* [[Combat vehicle|Combat]]
* [[:Category:Tracked military vehicles|Tracked vehicles]]
* [[:Category: Wheeled military vehicles|Wheeled vehicles]]
* [[Armoured fighting vehicle|Armor]]
** [[Tank]]
** [[Infantry fighting vehicle]]
** [[Lists of armoured fighting vehicles|Lists]]
** [[List of armoured fighting vehicles by country|By country]]
* [[Armored car (military)|Armored car]]
* [[Scout car]]
* [[Military vehicle#Military trucks|Truck]]
** [[:Category:Military trucks|List]]
** [[Gun truck]]
* [[Self-propelled artillery]]
**[[List_of_howitzers#Self-propelled_howitzers|List]]
**[[Self-propelled anti-aircraft weapon|Anti-aircraft]]
* [[Military railways|Rail]]
| group10 = Weapons
| list10 = {{#invoke:navbox|navbox |child |groupstyle=padding-left:0.5em;padding-right:0.5em;font-weight:normal;
| group1 = Land
| list1 =
* [[Weapon]]s
** [[Lists of weapons|List]]
* ''Artillery:''
* [[Field artillery|Artillery]]
** [[List of artillery|List]]
** [[List of artillery by country|By country]]
** [[Artillery battery|Battery]]
* [[Field gun]]
** [[List of field guns|List]]
* [[Howitzer]]
** [[List of howitzers|List]]
* [[Rocket artillery|Rocket]]
** [[List of rocket artillery|List]]
* ''[[Small Arms and Light Weapons|Infantry guns]]:''
* [[Service pistol|Pistols]]
* [[Machine gun]]s
** [[List of machine guns|List]]
* ''[[Service rifle]]s:''
* [[Battle rifle]]s
** [[List of battle rifles|List]]
* [[Assault rifle]]
** [[List of assault rifles|List]]
* [[Sniper rifle]]
* ''Other infantry weapons:''
* [[Bazooka]]
* [[Anti-tank gun]]
** [[List of anti-tank guns|List]]
* [[Grenade]]
** [[:Category:Grenades|List]]
* [[Flamethrower]]
* [[Bayonet]]
* [[Combat knife]]
** [[:Category:Military knives|List]]
* ''[[Missile]]s:''
** [[Shoulder-fired missile|Shoulder-fired]]
** [[Anti-tank guided missile|Anti-tank]]
** [[List of missiles|List]]
** [[List of missiles by country|By country]]
* [[Mortar (weapon)|Mortar]]
** ''Lists:''
** [[List of infantry mortars|Infantry]]
** [[List of heavy mortars|Heavy]]
* ''Other:''
* [[Land mine]]
* [[Shell (projectile)|Shells]]
|group20= Sea/Air:
| list20=
* [[Missile|Guided missiles]]
** [[List of missiles|List]]
* ''[[Naval warfare|Naval]]:''
* [[Naval artillery]]
**[[List of naval guns|List]]
* [[Anti-ship missile]]s
* [[Torpedo]]es
* [[Depth charge]]s
* [[Close-in weapon system|Close-in weapons]]
* ''[[Aerial warfare|Aerial]]:''
* [[:category:Aircraft guns|Guns]]
* [[:Category:Air-launched missiles|Missiles]]
* [[Aerial bomb|Bombs]]
}}
| group15 = Equipment
| list15 =
* [[Military technology|Military equipment]]
** [[Lists of military equipment|Lists]]
** [[:Category:Military equipment by country|By country]]
* [[Combat helmet|Helmet]]
** [[List of combat helmets|List]]
* [[Military camouflage|Camouflage]]
** [[List of military clothing camouflage patterns|List]]
* [[Body armor]]
* ''Facilities:''
* [[Military base]]
** [[Lists of military installations|Lists]]
* [[Field hospital]]
| group17 = Combat systems
| list17 =
* [[Fire-control system]]
* [[Fire-control radar]]
* [[Director (military)]]
* [[Combat information center]]
* [[Sonar]]
* [[Radar]]
* ''Historical:''
* [[Ship gun fire-control system|Ship gun fire-control]]
* [[Gun data computer]]
* [[Torpedo Data Computer]]
| group19 = [[War]]fare
| list19 =
* [[War]]
* [[Battle]]
* [[Strategy]]
* [[Military tactics|Tactics]]
* [[Combat]]
* [[Military science]]
* [[Diplomacy]]
* [[International law]]
* ''By era:''
* [[Prehistoric warfare|Prehistoric]]
* [[Ancient warfare|Ancient]]
* [[Medieval warfare|Post-classical]]<!--Does not represent a world-wide view; requires a global history of the period between the 5th and 15th centuries-->
* [[Early modern warfare|Early modern]]
* [[Modern warfare|Late modern]]
** [[Industrial warfare|industrial]]
** [[Fourth-generation warfare|fourth-gen]]
* ''By type:''
* [[Armoured warfare]]
* [[Artillery]]
* [[Barrage (artillery)|Barrage]]
* [[Biological warfare|Biological]]
* [[Military camouflage|Camouflage]]
* [[Cavalry]]
* [[Chemical warfare|Chemical]]
* [[Class conflict|Class]]
* [[Combined arms]]
* [[Conventional warfare|Conventional]]
* [[Cyberweapon|Cyber]]
* [[Area denial weapon|Denial]]
* [[Disinformation]]
* [[Drone warfare|Drone]]
* [[Electronic warfare|Electronic]]
* [[Infantry]]
* [[Lawfare]]
* [[Loitering munition|Loitering]]
* [[Martial music|Music]]
* [[Nuclear warfare|Nuclear]]
* [[Psychological warfare|Psychological]]
* [[Radiological warfare|Radiological]]
* [[Unconventional warfare|Unconventional]]
| group20 = [[Battlespace]]
| list20 =
* Aerospace
** [[Aerial warfare|Air]]
** [[Airborne forces|Airborne]]
** [[Space warfare|Space]]
* [[Land warfare|Land]]
** [[Cold-weather warfare|Cold-region]]
** [[Desert warfare|Desert]]
** [[Jungle warfare|Jungle]]
** [[Mountain warfare|Mountain]]
** [[Urban warfare|Urban]]
* [[Naval warfare|Sea]]
** [[Amphibious warfare|Amphibious]]
** [[Blue-water navy|Blue]]
** [[Brown-water navy|Brown]]
** [[Green-water navy|Green]]
** [[Surface warfare|Surface]]
** [[Underwater warfare|Underwater]]
* [[Subterranean warfare|Subterranean]]
** [[Tunnel warfare|Tunnel]]
* [[Cyberwarfare|Cyber]]
* [[Information warfare|Information]]
| group22 = [[Military tactics|Tactics]]
| list22 =
* [[List of military tactics]]
* [[Air combat manoeuvring|Aerial]]
* [[Airlift]]
** [[Airbridge (logistics)|Airbridge]]
** [[Airdrop]]
* [[Battle]]
* [[Cavalry tactics|Cavalry]]
* [[Charge (warfare)|Charge]]
* [[Counterattack]]
* [[Counterinsurgency]]
* [[Defeat in detail]]
* [[Defensive fighting position|Foxhole]]
* [[Envelopment]]
* [[Guerrilla warfare|Guerrilla]]
* [[Morale]]
* [[Shock and awe|Rapid dominance]]
* [[Siege]]
* [[Swarming (military)|Swarming]]
* [[Tactical objective]]
* [[Saturation attack|Target saturation]]
* [[Trench warfare|Trench]]
* [[Withdrawal (military)|Withdrawal]]
| group24 = [[Operational level of war|Operational]]
| list24 =
* [[Military operation]]
* [[Operations research]]
* [[Blitzkrieg]]
* [[Expeditionary warfare|Expeditionary]]
* [[Deep operation]]
* [[Maneuver warfare|{{#switch:{{{spelling}}}|British=Manoeuvre|Maneuver}}]]
* [[Operational manoeuvre group]]
| group26 = [[Military strategy|Strategy]]
| list26 =
* [[List of military strategies and concepts]]
* [[Military campaign]]
* [[Attrition warfare|Attrition]]
* [[Counter-offensive]]
* [[Culminating point|Culminating]]
* [[Defence in depth]]
* [[Fabian strategy|Fabian]]
* [[Mosaic Warfare|Mosaic]]
* [[Military deception|Deception]]
* [[Strategic defence|Defensive]]
* [[Strategic depth|Depth]]
* [[Strategic goal (military)|Goal]]
* [[Naval strategy|Naval]]
* [[Offensive (military)|Offensive]]
* [[Scorched earth]]
| group30 = [[Policy]]
| list30 =
* ''[[Diplomacy]]:''
* [[Alliance]]s
* [[Peace treaty]]
* [[Cooperation]]
* [[Deterrence theory]]
* [[United Nations]]
* [[Mediation]]
* ''Public policy:''
* [[Conscription]]
* [[Military budget|Defense budget]]
** [[List of countries with highest military expenditures|List]]
** [[List of countries by past military expenditure|Past]]
** [[List of countries with highest military expenditure per capita|Per capita]]
* [[Military policy|Defense policy]]
* ''Related:''
* [[Government]]
* [[Nation]]
| group32 = [[:Category:Military lists|Lists]]
| list32 =
* ''Military lists''
* [[Outline of war#Wars|Wars]]
* [[Lists of weapons|Weapons]]
* [[List of military tactics|Military tactics]]
* ''History lists:''
* [[Lists of wars|Wars]]
* [[Lists of battles|Battles]]
* [[List of military occupations|Military occupations]]
* [[List of military operations|Operations]]
* [[List of sieges|Sieges]]
* ''Related lists:''
* [[List of war crimes|War crimes]]
* [[List of military writers|Writers]]
| group35 = Other<br> namespace
| list35 =
{{#invoke:navbox|navbox |child |groupstyle=padding-left:0.5em;padding-right:0.5em;font-weight:normal;
| group1=Templates
| list1=
* {{tlp|War}}
* {{tlp|Weapons}}
* {{tlp|Military ranks by country|alttext=Ranks}}
* ''Vehicles and weapons''
** {{tlp|Tanks}}
** {{tlp|Weapons}}
** {{tlp|Modern IFV and APC|alttext=Infantry fighting vehicles}}
** {{tlp|Warship types of the 19th & 20th centuries|alttext=Modern warships}}
** {{tlp|Military aircraft types (roles)|alttext=Aircraft}}
* ''Specific modern wars''
** {{tlp|World War I}}
** {{tlp|World War II}}
** {{tlp|Cold War}}
** {{tlp|War on terror}}
|group2=Categories
|list2=
* [[:Category:Lists of wars by country involved|Lists of wars by country]]
* [[:Category: Conflicts by time|Conflicts by time]]
}}
| group40 = Related
| list40 =
* [[Peace]]
* [[Peace and conflict studies]]
* [[Peace movement]]
* [[Peace process]]
* [[Disarmament]]
* [[Pacifism]]
* [[Détente]]
* [[Global studies]]
* [[Conscientious objector]]
* [[Anti-war movement]]
* [[Idealism in international relations]]
* [[Humanitarianism]]
* [[Multilateralism|International cooperation]]
* [[Crimes against humanity]]
* {{tlp|International relations}}
* ''Categories:''
* [[:Category: Peace organizations|Peace organizations]]
<!--
* Internationalism
* Coexistence
* Mutualism
* Reconciliation
--->
| below =
{{#invoke:Icon|main|category}}'''[[:Category:War|ප්රවර්ගය]]''' {{#invoke:Icon|main|commons}}'''[[commons:CategoryWar|කොමන්ස්]]'''
}}<noinclude>
{{documentation}}
</noinclude>
3egfhquipj2pqail2o0rmded500k5bc
790948
790947
2026-05-20T03:46:49Z
Lee
85
790948
wikitext
text/x-wiki
{{#invoke:navbox|navbox
| name = මිලිටරි සහ යුද්ධ
| title = [[මිලිටරි]] සහ [[war|යුද්ධ]]
| listclass = hlist
| state = {{{state|autocollapse}}}
| group1 = සංකල්ප
| list1 =
* [[මිලිටරි]]
* [[Military service|සේවා]]
* [[Military history|ඉතිහාසය]]
* [[History of military technology|තාක්ෂණය]]
* [[Military specialism|Occupational roles]]
* [[Military recruitment|බඳවාගැනීම]]
* [[National security]]
**[[Computer security|සයිබර්]]
**[[Data sovereignty|දත්ත]]
**[[Economic security|Economic]]
**[[Energy security|Energy]]
**[[Environmental security|Environmental]]
** [[Food security|ආහාර]]
* ''Roles:''
* [[Soldier]]
* [[Sailor]]
* [[Airman]]
* [[Enlisted rank]]
* [[Officer (armed forces)|Officer]]
* [[Commanding officer]]
* [[Executive officer]]
* ''Protocols and structure:''
* [[Military rank|Ranks]]
** [[List of comparative military ranks|List]]
* [[Military uniform|Uniforms]]
* [[Military awards and decorations|Awards and decorations]]
** [[List of military decorations|By country]]
** [[List of highest military decorations|Highest]]
* ''Categories:''
* [[:Category:Military ranks|Ranks]]
| group2 = Forces
| list2 =
* [[Command and control]]
* [[Ministry of defence|Defense ministry]]
* ''[[Military|Armed Forces]]:''
* [[Army]]
* [[Navy]]
* [[Air force]]
* [[Marines]]
* [[Space force]]
* [[Special forces]]
* [[Airborne forces]]
* [[Commando]]
* [[Frogman]]
* [[Militia]]
* [[Military reserve force|Reserves]]
* ''Functional specialties:''
* [[Military communications|Communications]]
* [[Combat engineer|Engineers]]
* [[Military intelligence|Intelligence]]
* [[Reconnaissance]]
** [[List of reconnaissance units|List]]
* [[Medical corps|Medical]]
* [[Military police]]
* [[Gendarmerie]]
* [[Security forces]]
* [[Border guard]]
* [[Coast guard]]
* [[Military logistics|Logistics]]
** [[:Category:Military logistics units and formations|By country]]
* ''Categories:''
* [[:Category: Combat occupations|Combat occupations]]
* ''Development:''
* [[Military recruit training|Basic training]]
* [[Military exercise|Military maneuvers]]
* [[Combat|Combat training]]
| group3 = [[Military branch|Branches]]
| list3=
* ''Land units:''
* [[Combat arms]]
* [[Infantry]]
* [[Armoured fighting vehicle|Armor]]
** [[Cavalry]]
* [[Artillery]]
* [[Special reconnaissance]]
* [[Signal corps]]
* ''Naval units:''
* [[Warship]]s
** [[Surface combatant|Surface]]
** [[Littoral combat ship|Littoral]]
** [[Patrol boat|Patrol]]
* [[Submarine]]s
* [[Aircraft carrier]]s
* [[Landing craft]]
* [[Auxiliary ship]]
* ''Air units:''
* [[Fighter aircraft|Fighters]]
* [[Bomber]]s
* [[Airborne early warning and control|Command]]
* [[Close air support]]
* [[Electronic-warfare aircraft|Electronic-warfare]]
* [[Reconnaissance aircraft|Reconnaissance]]
| group5= Structure
| list5=
* [[Military organization|Organization]]
** [[:Category:Structure of contemporary armed forces|By country]]
** [[:Category:Structure of contemporary armies|Armies by country]]
* [[Command hierarchy|Chain of command]]
* [[Unified combatant command]]
* [[Staff (military)|General staff]]
* ''Land:''
* [[Army group]]
* [[Field army]]
* [[Corps]]
** [[List of military corps|List]]
* [[Division (military)|Division]]
** [[List of military divisions|List]]
* [[Brigade]]
** [[:Category:Brigades by type|By type]]
* [[Regiment]]
** [[:Category:Regiments by country|By country]]
** [[:Category:Regiments by type|By type]]
* [[Battalion]]
** [[:Category:Battalions by country|By country]]
** [[:Category:Battalions by type|By type]]
* [[Platoon]]
* [[Squad]]
* ''Naval:''
* [[Naval fleet]]
* [[Task force#Naval|Task force]]
* [[Carrier strike group]]
* [[Division (naval)|Division]]
* [[Flotilla]]
* [[Squadron (naval)|Squadron]]
* ''Air:''
* [[Combat box]]
* ''Special units by nation:''
* [[Battle Fleet|Battle Fleet; U.S. Navy]]
*[[Front (military formation)|Front; Russian land forces]]
| group7 = Vehicles
| list7 =
* ''Ground:''
* [[Military vehicle|Ground]]
** [[List of military vehicles|List]]
* [[Combat vehicle|Combat]]
* [[:Category:Tracked military vehicles|Tracked vehicles]]
* [[:Category: Wheeled military vehicles|Wheeled vehicles]]
* [[Armoured fighting vehicle|Armor]]
** [[Tank]]
** [[Infantry fighting vehicle]]
** [[Lists of armoured fighting vehicles|Lists]]
** [[List of armoured fighting vehicles by country|By country]]
* [[Armored car (military)|Armored car]]
* [[Scout car]]
* [[Military vehicle#Military trucks|Truck]]
** [[:Category:Military trucks|List]]
** [[Gun truck]]
* [[Self-propelled artillery]]
**[[List_of_howitzers#Self-propelled_howitzers|List]]
**[[Self-propelled anti-aircraft weapon|Anti-aircraft]]
* [[Military railways|Rail]]
| group10 = Weapons
| list10 = {{#invoke:navbox|navbox |child |groupstyle=padding-left:0.5em;padding-right:0.5em;font-weight:normal;
| group1 = Land
| list1 =
* [[Weapon]]s
** [[Lists of weapons|List]]
* ''Artillery:''
* [[Field artillery|Artillery]]
** [[List of artillery|List]]
** [[List of artillery by country|By country]]
** [[Artillery battery|Battery]]
* [[Field gun]]
** [[List of field guns|List]]
* [[Howitzer]]
** [[List of howitzers|List]]
* [[Rocket artillery|Rocket]]
** [[List of rocket artillery|List]]
* ''[[Small Arms and Light Weapons|Infantry guns]]:''
* [[Service pistol|Pistols]]
* [[Machine gun]]s
** [[List of machine guns|List]]
* ''[[Service rifle]]s:''
* [[Battle rifle]]s
** [[List of battle rifles|List]]
* [[Assault rifle]]
** [[List of assault rifles|List]]
* [[Sniper rifle]]
* ''Other infantry weapons:''
* [[Bazooka]]
* [[Anti-tank gun]]
** [[List of anti-tank guns|List]]
* [[Grenade]]
** [[:Category:Grenades|List]]
* [[Flamethrower]]
* [[Bayonet]]
* [[Combat knife]]
** [[:Category:Military knives|List]]
* ''[[Missile]]s:''
** [[Shoulder-fired missile|Shoulder-fired]]
** [[Anti-tank guided missile|Anti-tank]]
** [[List of missiles|List]]
** [[List of missiles by country|By country]]
* [[Mortar (weapon)|Mortar]]
** ''Lists:''
** [[List of infantry mortars|Infantry]]
** [[List of heavy mortars|Heavy]]
* ''Other:''
* [[Land mine]]
* [[Shell (projectile)|Shells]]
|group20= Sea/Air:
| list20=
* [[Missile|Guided missiles]]
** [[List of missiles|List]]
* ''[[Naval warfare|Naval]]:''
* [[Naval artillery]]
**[[List of naval guns|List]]
* [[Anti-ship missile]]s
* [[Torpedo]]es
* [[Depth charge]]s
* [[Close-in weapon system|Close-in weapons]]
* ''[[Aerial warfare|Aerial]]:''
* [[:category:Aircraft guns|Guns]]
* [[:Category:Air-launched missiles|Missiles]]
* [[Aerial bomb|Bombs]]
}}
| group15 = Equipment
| list15 =
* [[Military technology|Military equipment]]
** [[Lists of military equipment|Lists]]
** [[:Category:Military equipment by country|By country]]
* [[Combat helmet|Helmet]]
** [[List of combat helmets|List]]
* [[Military camouflage|Camouflage]]
** [[List of military clothing camouflage patterns|List]]
* [[Body armor]]
* ''Facilities:''
* [[Military base]]
** [[Lists of military installations|Lists]]
* [[Field hospital]]
| group17 = Combat systems
| list17 =
* [[Fire-control system]]
* [[Fire-control radar]]
* [[Director (military)]]
* [[Combat information center]]
* [[Sonar]]
* [[Radar]]
* ''Historical:''
* [[Ship gun fire-control system|Ship gun fire-control]]
* [[Gun data computer]]
* [[Torpedo Data Computer]]
| group19 = [[War]]fare
| list19 =
* [[War]]
* [[Battle]]
* [[Strategy]]
* [[Military tactics|Tactics]]
* [[Combat]]
* [[Military science]]
* [[Diplomacy]]
* [[International law]]
* ''By era:''
* [[Prehistoric warfare|Prehistoric]]
* [[Ancient warfare|Ancient]]
* [[Medieval warfare|Post-classical]]<!--Does not represent a world-wide view; requires a global history of the period between the 5th and 15th centuries-->
* [[Early modern warfare|Early modern]]
* [[Modern warfare|Late modern]]
** [[Industrial warfare|industrial]]
** [[Fourth-generation warfare|fourth-gen]]
* ''By type:''
* [[Armoured warfare]]
* [[Artillery]]
* [[Barrage (artillery)|Barrage]]
* [[Biological warfare|Biological]]
* [[Military camouflage|Camouflage]]
* [[Cavalry]]
* [[Chemical warfare|Chemical]]
* [[Class conflict|Class]]
* [[Combined arms]]
* [[Conventional warfare|Conventional]]
* [[Cyberweapon|Cyber]]
* [[Area denial weapon|Denial]]
* [[Disinformation]]
* [[Drone warfare|Drone]]
* [[Electronic warfare|Electronic]]
* [[Infantry]]
* [[Lawfare]]
* [[Loitering munition|Loitering]]
* [[Martial music|Music]]
* [[Nuclear warfare|Nuclear]]
* [[Psychological warfare|Psychological]]
* [[Radiological warfare|Radiological]]
* [[Unconventional warfare|Unconventional]]
| group20 = [[Battlespace]]
| list20 =
* Aerospace
** [[Aerial warfare|Air]]
** [[Airborne forces|Airborne]]
** [[Space warfare|Space]]
* [[Land warfare|Land]]
** [[Cold-weather warfare|Cold-region]]
** [[Desert warfare|Desert]]
** [[Jungle warfare|Jungle]]
** [[Mountain warfare|Mountain]]
** [[Urban warfare|Urban]]
* [[Naval warfare|Sea]]
** [[Amphibious warfare|Amphibious]]
** [[Blue-water navy|Blue]]
** [[Brown-water navy|Brown]]
** [[Green-water navy|Green]]
** [[Surface warfare|Surface]]
** [[Underwater warfare|Underwater]]
* [[Subterranean warfare|Subterranean]]
** [[Tunnel warfare|Tunnel]]
* [[Cyberwarfare|Cyber]]
* [[Information warfare|Information]]
| group22 = [[Military tactics|Tactics]]
| list22 =
* [[List of military tactics]]
* [[Air combat manoeuvring|Aerial]]
* [[Airlift]]
** [[Airbridge (logistics)|Airbridge]]
** [[Airdrop]]
* [[Battle]]
* [[Cavalry tactics|Cavalry]]
* [[Charge (warfare)|Charge]]
* [[Counterattack]]
* [[Counterinsurgency]]
* [[Defeat in detail]]
* [[Defensive fighting position|Foxhole]]
* [[Envelopment]]
* [[Guerrilla warfare|Guerrilla]]
* [[Morale]]
* [[Shock and awe|Rapid dominance]]
* [[Siege]]
* [[Swarming (military)|Swarming]]
* [[Tactical objective]]
* [[Saturation attack|Target saturation]]
* [[Trench warfare|Trench]]
* [[Withdrawal (military)|Withdrawal]]
| group24 = [[Operational level of war|Operational]]
| list24 =
* [[Military operation]]
* [[Operations research]]
* [[Blitzkrieg]]
* [[Expeditionary warfare|Expeditionary]]
* [[Deep operation]]
* [[Maneuver warfare|{{#switch:{{{spelling}}}|British=Manoeuvre|Maneuver}}]]
* [[Operational manoeuvre group]]
| group26 = [[Military strategy|Strategy]]
| list26 =
* [[List of military strategies and concepts]]
* [[Military campaign]]
* [[Attrition warfare|Attrition]]
* [[Counter-offensive]]
* [[Culminating point|Culminating]]
* [[Defence in depth]]
* [[Fabian strategy|Fabian]]
* [[Mosaic Warfare|Mosaic]]
* [[Military deception|Deception]]
* [[Strategic defence|Defensive]]
* [[Strategic depth|Depth]]
* [[Strategic goal (military)|Goal]]
* [[Naval strategy|Naval]]
* [[Offensive (military)|Offensive]]
* [[Scorched earth]]
| group30 = [[Policy]]
| list30 =
* ''[[Diplomacy]]:''
* [[Alliance]]s
* [[Peace treaty]]
* [[Cooperation]]
* [[Deterrence theory]]
* [[United Nations]]
* [[Mediation]]
* ''Public policy:''
* [[Conscription]]
* [[Military budget|Defense budget]]
** [[List of countries with highest military expenditures|List]]
** [[List of countries by past military expenditure|Past]]
** [[List of countries with highest military expenditure per capita|Per capita]]
* [[Military policy|Defense policy]]
* ''Related:''
* [[Government]]
* [[Nation]]
| group32 = [[:Category:Military lists|Lists]]
| list32 =
* ''Military lists''
* [[Outline of war#Wars|Wars]]
* [[Lists of weapons|Weapons]]
* [[List of military tactics|Military tactics]]
* ''History lists:''
* [[Lists of wars|Wars]]
* [[Lists of battles|Battles]]
* [[List of military occupations|Military occupations]]
* [[List of military operations|Operations]]
* [[List of sieges|Sieges]]
* ''Related lists:''
* [[List of war crimes|War crimes]]
* [[List of military writers|Writers]]
| group35 = Other<br> namespace
| list35 =
{{#invoke:navbox|navbox |child |groupstyle=padding-left:0.5em;padding-right:0.5em;font-weight:normal;
| group1=Templates
| list1=
* {{tlp|War}}
* {{tlp|Weapons}}
* {{tlp|Military ranks by country|alttext=Ranks}}
* ''Vehicles and weapons''
** {{tlp|Tanks}}
** {{tlp|Weapons}}
** {{tlp|Modern IFV and APC|alttext=Infantry fighting vehicles}}
** {{tlp|Warship types of the 19th & 20th centuries|alttext=Modern warships}}
** {{tlp|Military aircraft types (roles)|alttext=Aircraft}}
* ''Specific modern wars''
** {{tlp|World War I}}
** {{tlp|World War II}}
** {{tlp|Cold War}}
** {{tlp|War on terror}}
|group2=Categories
|list2=
* [[:Category:Lists of wars by country involved|Lists of wars by country]]
* [[:Category: Conflicts by time|Conflicts by time]]
}}
| group40 = Related
| list40 =
* [[Peace]]
* [[Peace and conflict studies]]
* [[Peace movement]]
* [[Peace process]]
* [[Disarmament]]
* [[Pacifism]]
* [[Détente]]
* [[Global studies]]
* [[Conscientious objector]]
* [[Anti-war movement]]
* [[Idealism in international relations]]
* [[Humanitarianism]]
* [[Multilateralism|International cooperation]]
* [[Crimes against humanity]]
* {{tlp|International relations}}
* ''Categories:''
* [[:Category: Peace organizations|Peace organizations]]
<!--
* Internationalism
* Coexistence
* Mutualism
* Reconciliation
--->
| below =
{{#invoke:Icon|main|category}}'''[[:Category:War|ප්රවර්ගය]]''' {{#invoke:Icon|main|commons}}'''[[commons:CategoryWar|කොමන්ස්]]'''
}}<noinclude>
{{documentation}}
</noinclude>
23ob71u8srerfqjsojtvjjefhy277ih
සැකිල්ල:මිලිටරි සහ යුද්ධ/doc
10
105540
790940
558591
2026-01-21T22:20:47Z
en>RicLightning
0
790940
wikitext
text/x-wiki
{{Documentation subpage}}
{{Collapsible option|default=autocollapse}}
<includeonly>{{Sandbox other||
<!-- Categories below this line -->
[[Category:War and conflict navigational boxes|*]]
[[Category:Military navigational boxes|*]]
}}</includeonly>
fm57ygiw6jhxzob9w0jbm6vp96ecaq7
790941
790940
2026-05-20T03:44:19Z
Lee
85
[[:en:Template:Military_and_war/doc]] වෙතින් එක් සංශෝධනයක්
790940
wikitext
text/x-wiki
{{Documentation subpage}}
{{Collapsible option|default=autocollapse}}
<includeonly>{{Sandbox other||
<!-- Categories below this line -->
[[Category:War and conflict navigational boxes|*]]
[[Category:Military navigational boxes|*]]
}}</includeonly>
fm57ygiw6jhxzob9w0jbm6vp96ecaq7
790944
790941
2026-05-20T03:45:05Z
Lee
85
Lee විසින් [[සැකිල්ල:Military and war/doc]] සිට [[සැකිල්ල:මිලිටරි සහ යුද්ධ/doc]] වෙත පිටුව ගෙන යන ලදී
790940
wikitext
text/x-wiki
{{Documentation subpage}}
{{Collapsible option|default=autocollapse}}
<includeonly>{{Sandbox other||
<!-- Categories below this line -->
[[Category:War and conflict navigational boxes|*]]
[[Category:Military navigational boxes|*]]
}}</includeonly>
fm57ygiw6jhxzob9w0jbm6vp96ecaq7
හරදෝතිස්
0
152053
790951
662966
2026-05-20T08:34:09Z
WrdSrchSi
55524
/*ළමා විය*/ translated 1 paragraph
790951
wikitext
text/x-wiki
{{තොරතුරුකොටුව පුද්ගලයා
| name = හරදෝතිස්
| image = Marble bust of Herodotos MET DT11742 (cropped).jpg
| caption = කි.ව.පෙ 4 වැනි සියවසේ මුල් බෑයේ හරදෝතිස් උඩුකය පිළිමයක රෝම පිටපතක් (කි.ව. 2 වැනි සියවස)
| native_name = Ἡρόδοτος //ඉරෝදොතොස්//
| native_name_lang = grc
| birth_date = {{circa|484 BC }}
| birth_place = [[Halicarnassus]], Caria, Asia Minor, [[Achaemenid Empire|Persian Empire]]<br />(modern-day [[Bodrum]], Turkey)
| death_date = {{circa|425}} BC (aged approximately 60)
| death_place = Thurii, [[Calabria]], or [[Pella]], Macedon
| occupation = ඉතිහස් දතු
| notable_works = ''[[Histories (Herodotus)|Histories]]''
| parents = {{unbulleted list| Lyxes (father) | Dryotus (mother)}}
| relatives = {{unbulleted list| Theodorus (brother) | [[Panyassis]] (uncle or cousin)}}
}}
== දිවිය ==
=== ළමා විය ===
ඔහු ගේ මැ කෘතිය අරඹමින් කළ පැවැස්මට අනුව හරදොතිස් ඇනටෝලියාවේ හැලිකාර්නාසසයේ උපන්නේ වී. කි.පෙ. 485 දී පමණ ඔහු එහි උපන් හ යි සැමැනියෙන් පිළිගැනේ. ඔහු ගේ පවුල බලගතු වූ බවත්, ඔහු ලික්සස් සහ ඩ්රයෝ ගේ පුතු ද තියඩෝරස් ගේ බෑයා ද එ කලැ විසූ විරු කව් පබඳුබකු වූ පන්යාසිස් ගේ නෑයකු ද වූ බවත් සුඩා පවසයි. ලික්සස් සහ පන්යාසිස් යනු කැරියන් නම් බැවින් හරදොතිස් අවම විසින් අඩ හෙලනීකෘත කැරියන් මුලක් ඇත්තකු වීමට ඉඩ ඇත. හැලිකාර්නාසසය එ වකට පාරසි අදිරජය තුළ වූයේ හරදොතිස් පාරසි යටත්වැසියකු කරමිනි.
[[ප්රවර්ගය:ආසියාවේ ඉතිහාසය]]
[[ප්රවර්ගය:ගුටෙන්බර්ග් ව්යාපෘති සබැඳි අඩංගු ලිපි]]
[[ප්රවර්ගය:Wikipedia articles incorporating a citation from EB9]]
[[ප්රවර්ගය:තහවුරු නොකළ ප්රකාශ අඩංගු ලිපි සියල්ල]]
444gkw707vasnf0e08j5novs2rwkrpn
790963
790951
2026-05-20T11:33:00Z
WrdSrchSi
55524
Translated Paragraph #1, added Wiktionary
790963
wikitext
text/x-wiki
{{තොරතුරුකොටුව පුද්ගලයා
| name = හරදෝතිස්
| image = Marble bust of Herodotos MET DT11742 (cropped).jpg
| caption = කි.ව.පෙ 4 වැනි සියවසේ මුල් බෑයේ හරදෝතිස් උඩුකය පිළිමයක රෝම පිටපතක් (කි.ව. 2 වැනි සියවස)
| native_name = Ἡρόδοτος //ඉරෝදොතොස්//
| native_name_lang = grc
| birth_date = {{circa|484 BC }}
| birth_place = [[Halicarnassus]], Caria, Asia Minor, [[Achaemenid Empire|Persian Empire]]<br />(modern-day [[Bodrum]], Turkey)
| death_date = {{circa|425}} BC (aged approximately 60)
| death_place = Thurii, [[Calabria]], or [[Pella]], Macedon
| occupation = ඉතිහස් දතු
| notable_works = ''[[Histories (Herodotus)|Histories]]''
| parents = {{unbulleted list| Lyxes (father) | Dryotus (mother)}}
| relatives = {{unbulleted list| Theodorus (brother) | [[Panyassis]] (uncle or cousin)}}
}}
{{Wiktionary}}
'''හරදෝතිස්''' (පුරාණ ග්රීක: Ἡρόδοτος, රෝමකරණය: හෙරොඩෝටෝස්; කි.පෙ. 484 – කි.පෙ. 425 පමණ) යනු කි.පෙ. 5 වන සියවසේ [[ඉරානය#ඉතිහාසය|පාරසි]] පාලනය යටතේ පැවැති ගරසි නගරයක් වන හැලිකාර්නාසසයේ (දැන් [[තුර්කිය|තුරිකියේ]] බොඩ්රම්) ගරසි ඉතිහස් දතුවකු හා [[භූගෝල විද්යාව|බිම් කොසු කරුවකු]] වූ අතර, ඉතාලියේ නූතන කැලබ්රියාවේ තුරීයේ පසුකැලි පුරවැසියෙකි. හේ සයිරස් ගේ [[ඉරානය#ඉතිහාසය|අකීමෙනිඩ්]] රජවසේ නැඟුම වැනි අනෙකුදු විසවු අතර ගරිසි-පාරසි යුද පිළිබඳ සවිසිතුරු වාර්තාවක් වන ''Histories'' ලී යැ. හේ "ඉතිහයේ පියා" ලෙස වැනී ඇත්තේ යි. එය පුරාණ රෝම දෙසුවකු වූ සිසෙරෝ විසින් ඔහුට පිරිනැමුණු පටයෙකි.
== දිවිය ==
=== ළමා විය ===
ඔහු ගේ මැ කෘතිය අරඹමින් කළ පැවැස්මට අනුව හරදෝතිස් ඇනටෝලියාවේ හැලිකාර්නාසසයේ උපන්නේ වී. කි.පෙ. 485 දී පමණ ඔහු එහි උපන් හ යි සැමැනියෙන් පිළිගැනේ. ඔහු ගේ පවුල බලගතු වූ බවත්, ඔහු ලික්සස් සහ ඩ්රයෝ ගේ පුතු ද තියඩෝරස් ගේ බෑයා ද එ කලැ විසූ විරු කව් පබඳුබකු වූ පන්යාසිස් ගේ නෑයකු ද වූ බවත් සුඩා පවසයි. ලික්සස් සහ පන්යාසිස් යනු කැරියන් නම් බැවින් හරදෝතිස් අවම විසින් අඩ හෙලනීකෘත කැරියන් මුලක් ඇත්තකු වීමට ඉඩ ඇත. හැලිකාර්නාසසය එ වකට පාරසි අදිරජය තුළ වූයේ හරදෝතිස් පාරසි යටත්වැසියකු කරමිනි.
[[ප්රවර්ගය:ආසියාවේ ඉතිහාසය]]
[[ප්රවර්ගය:ගුටෙන්බර්ග් ව්යාපෘති සබැඳි අඩංගු ලිපි]]
[[ප්රවර්ගය:Wikipedia articles incorporating a citation from EB9]]
[[ප්රවර්ගය:තහවුරු නොකළ ප්රකාශ අඩංගු ලිපි සියල්ල]]
obvtwmbsg3wxcdz1j3pb226c85d4fze
උදවු:Lua for beginners
12
176085
790912
790871
2026-05-19T17:10:18Z
Nimmzo
78995
/* Errors */ moved above /* Exasperating bugs */
790912
wikitext
text/x-wiki
{{WikiProject Lua header}}
{{Selfref|This help page is meant to provide some basic orientation for those new to Lua/Scribunto.}}
{{ඉංග්රීසි ව්යාපෘතියේ සිට ආයාත කළ පිටුව}}
== Overview ==
[[WP:Lua|Lua]] is a lightweight scripting language safely available on Wikipedia via [[mw:Extension:Scribunto|Scribunto]]. Its purpose is to allow you to process the data which is available on Wikipedia content pages to allow various sorts of customized display of information.
It runs in a sandboxed environment to protect the stability of Wikipedia while enabling powerful <syntaxhighlight lang="lua" inline>{{template}}</syntaxhighlight> and <syntaxhighlight lang="lua" inline>module:</syntaxhighlight> functionality.
The most important help file is the [[mw:Extension:Scribunto/Lua reference manual|MediaWiki Scribunto Lua reference manual]], which provides a concise summary of the language and standard library calls as implemented on MediaWiki.
The standard [http://www.lua.org/manual/5.1/manual.html Lua reference manual] is well written and comprehensive, but it can be confusing for beginners because some standard features don't work on wiki pages. You cannot call <syntaxhighlight lang="lua" inline>print("Hello, World!")</syntaxhighlight> in a module, but you can preview your User page showing the string <syntaxhighlight lang="lua" inline>"Hello World!"</syntaxhighlight> generated by the Lua [[Module:Example]]. Think of your Lua template as an HTML generator.
=== Generating "Hello World!" ===
You do not need to install or save anything.
# Edit your User page: <code>පරිශීලක:YourUserName</code>
# Paste the following call at the beginning of a new line on your User page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{#invoke:Example|hello}}
</syntaxhighlight></blockquote>
<ol start="3">
<li>Click <code>Preview</code>. The call of the function <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> in the [[Module:Example]] is replaced with the following:</li>
</ol>
<blockquote><syntaxhighlight lang="lua" line>
Hello World!
</syntaxhighlight></blockquote>
<ol start="4">
<li>Click <code>Cancel</code>. When prompted, click <code>Leave</code>.</li>
<li>Your User page remains '''un'''modified.</li>
</ol>
== Debug console: Start learning Lua ==
The Lua Scribunto <code>Debug Console</code> is a safe, interactive tool for learning Lua in Wikipedia.
# Click <code>Edit</code> on the [[Module:Yesno]] page.
# Scroll to the bottom of the page to the <code>Debug console</code> section beneath the Lua editor.
# Paste the comment and the call into the <span style="color:#86888c;">gray</span> input box (above the <code>Clear</code> button).
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
--[[ඔබගේ ආරම්භක Lua "හෙලෝ වර්ල්ඩ්" යන වගේම වැඩසටහන]]--
print("වෙල්කම් වෙයි " .. _VERSION .. "!") -- Lua අනුවාදය .. සමඟ එකතු කරයි
</syntaxhighlight></blockquote>
<ol start="4">
<li>Press {{key press|Enter}} once to execute the two Lua command''s''.</li>
<li>The result will appear below the Lua <syntaxhighlight lang="lua" inline>print</syntaxhighlight> command line:</li>
</ol>
<blockquote><syntaxhighlight lang="lua" line start=3>
වෙල්කම් වෙයි Lua 5.1!
</syntaxhighlight></blockquote>
<ol start="6">
<li>Press <code>Up arrow</code> (↑) to cycle through previous Lua commands.</li>
<li>Optionally, click <code>Clear</code> to clear ''only'' the <code>Debug Console</code>; the Lua editor above will remain '''un'''modified.</li>
</ol>
; HTML generator in the Debug console
Call the function <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> in <code>Module:</code>Example:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local modExample = require('Module:Example') -- load the module in Debug console
local frame = mw.getCurrentFrame(); print(modExample.hello(frame)) -- display "Hello World!"
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
Hello World!
</syntaxhighlight></blockquote>
; Identity function
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local yesno = require('Module:Yesno') -- #if yesno then returns its input parameter
print(mw.getCurrentFrame():callParserFunction("#if", yesno("Yes"), "Yes", 'නැහැ'))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
Yes
</syntaxhighlight></blockquote>
# Close the protected <code>Module:</code>Yesno that remains '''un'''modified.
== Issues with the current implementation ==
Besides the lack of <code>print()</code> in a module, there are other features missing – see [[mw:Extension:Scribunto/Lua reference manual#Differences from standard Lua|Differences from standard Lua]] for a complete list.
At the present time, it is advisable to use ''[[mw:Extension:Scribunto/Lua reference manual#Ustring library|mw.ustring]]'' functions instead of ''[[mw:Extension:Scribunto/Lua reference manual#String library|string]]'', because the latter sometimes fails with Unicode characters.
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local lang = mw.getCurrentFrame():callParserFunction("#language", "si") -- Sinhala
local lenUnicode, lenByte, lenSharp = mw.ustring.len(lang), string.len(lang), #lang
print(("lang: %s Mw.ustring.len = %d String.len = %d Sharp = %d"):format(lang, lenUnicode, lenByte, lenSharp))
</syntaxhighlight></blockquote>
Debug console supports Unicode:
<blockquote><syntaxhighlight lang="lua" line start=4>
lang: සිංහල Mw.ustring.len = 5 String.len = 15 Sharp = 15
</syntaxhighlight></blockquote>
== Input ==
The programs are run only when the page is "parsed" (when it or a page it incorporates is changed or previewed), not every time you view the output. Therefore there can be no convenient Lua module that allows you to type in a Fahrenheit temperature in an input box and get back the corresponding Celsius temperature when you press a button, or allows you to click on a segment of a Mandelbrot set visualization on a page to expand it as often as you like. There has to be an actual Wiki page (or at least a page you have submitted for preview) containing the input data.
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local function toCelsius(tempFahrenheit) return (tempFahrenheit - 32) * 5 / 9 end
print(("toCelsius(32°F) = %s°C. toCelsius(68°F) = %d°C"):format(toCelsius(32), toCelsius(68)))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
toCelsius(32°F) = 0°C. toCelsius(68°F) = 20°C
</syntaxhighlight></blockquote>
However, it is possible to use library functions like [[mw:Extension:Scribunto/Lua reference manual#mw.title.getCurrentTitle|mw.title.getCurrentTitle()]] to import content from any text content page on the Wiki.
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
print(mw.title.getCurrentTitle())
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=2>
Module:Yesno
</syntaxhighlight></blockquote>
You cannot, however, import data from files, not even .svg files which contain XML text data.
== Calling a Lua module ==
Lua calls look much like [[WP:template|template]]s, and consist of a small block of text.
In your User page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{ConvertNumeric|decToHex|73}}
</syntaxhighlight></blockquote>
Click <code>Preview</code> or click <code>Edit</code> this section to see the call then <code>Cancel</code>:
<blockquote>
{{#invoke:ConvertNumeric|decToHex|73}}
</blockquote>
This text calls the Lua script itself, which is housed in the <code>Module:</code> [[WP:namespace|namespace]]. The effect of this call is to send the information within the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> block to the Lua module, and to replace everything within the brackets with a piece of text that it sends back in return. (Literally, in the "return" statement)
Note that the first "parameter", in this case <code>decToHex</code>, is actually a <syntaxhighlight lang="lua" inline>function</syntaxhighlight> called within the Lua module. This field must always be included in any <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight>. To those unfamiliar with modules, especially Wikipedia template coders who expect anything after <code>|</code> to be a parameter, the need for this extra field is surprising, especially if all uses of the module depend on its presence.
In Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local convNum = require('Module:ConvertNumeric')
local frame = mw.getCurrentFrame(); frame.args[1] = "73" -- number always as string
print(("0x%s = %s = %d"):format(convNum.decToHex(frame), string.format("0x%X", 73), 0x49))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=4>
0x49 = 0x49 = 73
</syntaxhighlight></blockquote>
=== Documenting a Lua module ===
When documenting your module, it is useful to include an explicit usage instruction using [[සැකිල්ල:Module link expanded]]:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{mlx|ConvertNumeric|decToHex|73}}
</syntaxhighlight></blockquote>
Hyperlink to the module:
<blockquote>
{{mlx|ConvertNumeric|decToHex|73}}
</blockquote>
For many existing modules, an example <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> of the script (and little else) is provided on the <code>Module talk:</code> page. It is convenient for authors to be able to flip quickly to the talk tab to look at the effects of their changes, but you should never transclude the talk page as a template - people might actually talk on it! Alternatively, the module page can show documentation from a separate /doc-page (as [[Module:WikidataIB]] does).
=== Another example: Using LuaCall to perform a single Lua instruction ===
As a beginner, or in casual talk page conversation, you might only have one little calculation you want to use Lua for but don't want to write a full module. You might find [[Module:LuaCall]] convenient for this. For example, you can test how a greedy [https://www.lua.org/pil/20.1.html Lua pattern] works:
* <syntaxhighlight lang="lua" inline>{{#invoke:LuaCall|main|a=bbbbbbbbbba|b=bb(.*)b(.+)bba|string.match(a,b)}}</syntaxhighlight> → <code>{{#invoke:LuaCall|main|a=bbbbbbbbbba|b=bb(.*)b(.+)bba|string.match(a,b)}}</code>
or count up the length of a [[wikipedia:Did you know|''Did you know'']] hook or the text portion of a ''Did you know'' candidate:
* <syntaxhighlight lang="lua" inline>{{#invoke:LuaCall|main|a=... that you can count the length of your DYK hook with a Lua module?|string.len(a)}}</syntaxhighlight>→ <code>{{#invoke:LuaCall|main|a=... that you can count the length of your DYK hook with a Lua module?|string.len(a)}}</code>
In these specific examples, however, [[Module:String]] could do both of these tasks.
The script at [[Module:LuaCall]] has been written to accept any set of named parameters <code>somename=value</code>, for each one storing the string <code>value</code> in the variable with the name <code>somename</code>, and then allowing you to use these variables as parameters for any function available in Lua. The script then returns only the ''first'' value returned by the function ([https://www.lua.org/pil/5.1.html Lua functions can return multiple values], but in this case, only the first is returned from the module).
== Lua program structure: Output ==
The most fundamental part of a Wikipedia Lua program is a '''return''' statement which carries its output back to the page that had the <code>#invoke</code>. You ''can'' have a Lua function that runs without error even though it doesn't contain a return statement, but on Wikipedia it is pointless, as Lua programs cannot generally have side effects on Wikipedia.
The module itself must return a Lua '''table''' of values. A Lua table is expressed as a list of values separated by commas, within curly braces. When the module is called by <code>#invoke</code>, the '''function''' it names (the first argument after |) is looked for in that table. That function, in turn, is expected to return something that can be represented as a '''string'''.
Therefore, <syntaxhighlight lang="lua" inline>return { mw.ustring.gmatch( "Hello world", "(.*)" ) }</syntaxhighlight> is actually a complete Lua module (though a very strange one) - it returns the function returned by mw.ustring.gmatch (an iterator function listed in the Lua reference cited above) as the one and only element in an array (represented within <code>{}</code>)—which when executed using <syntaxhighlight lang="wikitext" inline>{{#invoke:ModuleName|1}}</syntaxhighlight> yields the string "Hello world". ''However'', things are not usually done this way. Typically we use the overall form:
<syntaxhighlight lang="lua">
local p = {} -- Defines a variable p as an empty table, but *not* nil.
function p.main( frame ) -- This block defines the table element p["main"] as a function.
return "Hello world" -- The string result of the function.
end -- Ends the block defining the function object p["main"] (or p.main).
return p -- This returns the table p, which under the key "main" contains the
-- function above (p.main), which when called returns string "Hello world".
</syntaxhighlight>
Note that <syntaxhighlight lang="lua" inline>function p.main(frame) ... end</syntaxhighlight> is equivalent to <syntaxhighlight lang="lua" inline>p.main = function(frame) ... end</syntaxhighlight> or <syntaxhighlight lang="lua" inline>p["main"] = function(frame) ... end</syntaxhighlight>. The function is just another type of value, retrieved with the key <code>"main"</code> from table <code>p</code>. If you want to allow users to invoke the same module with <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|hello}}</nowiki></code> instead of <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|main}}</nowiki></code>, you can write <code>p.hello = p.main</code> to copy the reference to this function to a new key in the table. You can even write <code>p[""] = p.main</code>, which causes <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|}}</nowiki></code> to produce the same output as <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|main}}</nowiki></code>. Learning to think of functions as a data type becomes very important later on for working with library functions like <code>[[mw:Extension:Scribunto/Lua_reference_manual#string.gsub|mw.ustring.gsub]]</code>, and constructing iterator functions.
== Lua program structure: Input ==
The '''<code>frame</code>''' parameter above (which is pretty much always given this name in Wikipedia Lua modules) receives another table, which is passed ''from'' the page that makes the call ''to'' the Lua module. It contains a surprising amount of stuff, of which just a few things concern the novice.
=== Arguments ===
{{see also|Module:Arguments}}
<code>frame.args</code> contains ''another'' table, namely, all the content sent by the user within the <code>#invoke</code> brackets except the first argument which states the name of the function to be executed. So in {{Mlx|ConvertNumeric|decToHex|3377}}, the string <code>"3377"</code> is the content of <code>frame.args[1]</code> (which is the same as <code>frame["args"][1]</code> but ''not'' the same as <code>frame.args["1"]</code> or <code>frame["args"]["1"]</code>). Unnamed parameters come out with numbers as keys (<code>frame.args[1]</code>, <code>frame.args[2]</code>, etc.), while named parameters come out with the parameter names (strings) as keys (<code>frame.args["count"]</code>, <code>frame.args["style"]</code>, etc.).
''Example:''<blockquote><code><nowiki>{{#invoke:</nowiki>''modulename''|''functionname''<nowiki>|3377|4|count=3|style=bold}}</nowiki></code> </blockquote>results in<blockquote><code>frame.args[1]</code>=3377, <code>frame.args[2]</code>=4, <code>frame.args["count"]</code>=3, <code>frame.args["style"]</code>=<code>"bold"</code>.</blockquote>
=== Parent frame ===
Within <code>frame</code> there is a ''parent'' frame, referring to the page that called the page that gives the script, and you can pull out arguments from that also. Just write
<code>parent=frame.getParent(frame)</code>
and <code>parent.args</code> will contain those arguments.
It is popular in Lua to use the synonymous statement <code>parent=frame''':'''getParent()</code>, cancelling the need to write <code>frame</code> twice. Note the colon (<code>:</code>) instead of the dot (<code>.</code>). <code>parent=frame:getParent()</code> means exactly the same as <code>parent=frame.getParent(frame)</code>. For novices this can be confusing, and it is important to be aware of this idiom. If you use it in the wrong way, though, the script errors are pretty good at pointing out that this was the mistake.
== Basic debugging ==
{{Main|Help:Lua debugging}}
Debugging can start as soon as you write programs, and can be done simply with string concatenation.
Just set up a variable with some recognizable name like "debuglog" in your main function (p.main) with a statement like <syntaxhighlight lang="lua" inline>local debuglog=""</syntaxhighlight>. This initial {{code|""}} definition helps because otherwise it will be '''nil''' and concatenating a string to nil gets you an error. Now whenever you have a variable you'd like to test, say {{tt|x}}, just write <syntaxhighlight lang="lua" inline>debuglog = debuglog .. "x=" .. tostring(x)</syntaxhighlight>, and have at the end of your program <syntaxhighlight lang="lua" inline> return output .. debuglog</syntaxhighlight> The "{{tt|tostring}}" is a function to ensure {{tt|x}} is interpreted as a string, so that if it is an table, nil, etc. it will display as "{{samp|table}}", "{{samp|nil}}", etc. rather than as Script error.
== Format ==
The [[WP:Lua style guide]] gives some basic formatting suggestions expected by the JavaScript module editor, such as using four-space indentations and keeping if, then, else, end at the same level of indentation.
Comments to the end of a line are marked by {{code|--}} . ''Use them.'' Many modules for Wikipedia have a straightforward, linear design, but that doesn't mean it won't help to have your sections clearly labelled when you go back to the code for the hundredth time. The Lua style guide gives additional recommendations for using functions to keep your work more organized.
== Errors ==
Lua errors appear as red "Script error" messages. If Javascript is enabled, '''the red script error message is a link''' which usually allows you to follow it back to the line in the module where the error occurred. There are some exceptions, for example "Module not found", if the name of the module itself is mistyped, or "The function you specified did not exist" if the function name given is invalid.
== Exasperating bugs ==
Some bugs you might want to keep in mind:
* ''Attempt to call a string value.'' It means you forgot the .. between a string and a variable somewhere in a mess of stuff you're concatenating.
* A variable ignores all your efforts to assign stuff to it. You may have inadvertently written ''two'' local statements - the one sets the value of the variable within a limited region, and when the program leaves that region, you're back to the old value.
* A numbered table entry ignores all your efforts to assign to it. This is because {{code|a["50"]}} '''is not''' {{code|a[50]}}. Typically you have processed a parameter (which you may have received from the invoke as a string) with string functions in one place, but performed numeric operations in another, leaving you with two different types of variable to use for an index.
* Some graphics you're trying to display are heading off to the hills. (actually a HTML error) You didn't close your {{tag|div|c}}s, so all the top: and left: styles keep adding up.
* ''{{code|... nil ...}}'' There are all sorts of things you can't do to a nil variable, like assign <code>x.somefield</code> or {{code|x[n]}} if {{tt|x}} is nil, concatenate <code>a .. b</code> if {{tt|a}} or {{tt|b}} is nil, or evaluate {{code|a[x]}} if {{tt|x}} is nil. Initialize such variables with (local) {{tt|1=x={}, a=""}}, etc. Often "global" is mentioned in these errors because you didn't have a {{tt|local}} statement for the nil variable.
* ''string expected, got function.'' Some important things like {{tt|mw.ustring.gmatch}} actually return ''functions'', not strings - see [[#Functions|Functions]] below.
* ''no such module.'' You {{code|#invoked}} a module that didn't exist {{--}} or wrote {{code|#invoke:Module:x}} instead of {{code|#invoke:x}}.
* ''the function specified did not exist.'' You {{code|#invoked}} a module, but the field after the name of the module is wrong. Often this field expects a standard name like "main", and you've forgotten it and gone straight to the first data parameter. If you're unsure of the function name, check the module documentation, or look for what function(s) in the code accept a "frame" parameter.
== Understanding tables and related concepts ==
* An '''expression list''' is a set of values separated by commas. The values can be strings, numbers, tables, functions, etc.
* A '''sequence''' is a set of entries with indices from 1 to N, where N is a positive integer. They can be created by placing brackets around an expression list. For example, if <syntaxhighlight lang="lua" inline>a={1, "quotation", mw.ustring.gmatch("abca","a"), {2,3,4}}</syntaxhighlight> then <code>a[1]</code>=1, <code>a[2]</code>="quotation", <code>a[3]</code> is the function returned by <code>gmatch()</code>, and <code>a[4]</code> is the table <code>{2,3,4}</code>. An expression list can also be recovered from a table using <code>unpack()</code>: <code>b, c, d = unpack(a)</code> will set <code>b</code>=1, <code>c</code>="quotation", and <code>d</code> as the function returned by <code>gmatch()</code>; <code>{2,3,4}</code> will be discarded in this case.
* A '''table''' is a sequence, optionally supplemented by named keys: <code>digit["two"]="2"</code>. Several table functions like <code>table.concat</code> will only work with the numbered values and ignore named keys.
* The '''metatable''' offers a large, optional set of methods for altering table behavior. For example, you can define a table to be callable like a function.
=== Initializing a table ===
It is often useful to create a whole table at once in a statement. There are many equivalent ways to do this, but the shortcuts don't work for every kind of value. To begin with, the most general way is to assign each key and value explicitly:
<syntaxhighlight lang="lua" inline>a = {[0]='zero', [1]='one', ['1']='string for one'}</syntaxhighlight>
If sequence keys (positive integers) are given in order, only the values need to be given, so the following will assign <syntaxhighlight lang="lua" inline>'one'</syntaxhighlight> to <syntaxhighlight lang="lua" inline>a[1]</syntaxhighlight>:
<syntaxhighlight lang="lua" inline>a = {[0]='zero', 'one', ['1']='string for one'}</syntaxhighlight>
If a key has only letters, digits, and underscores, and begins with a non-digit, the brackets and quotation marks can be omitted:
<syntaxhighlight lang="lua" inline>a = {a='one', b='two'}</syntaxhighlight>
This is identical to <syntaxhighlight lang="lua" inline>a = {["a"]='one', ["b"]='two'}</syntaxhighlight>.
However, this will fail for keys that begin with a digit: <syntaxhighlight lang="lua" inline>hex = {7f = 127}</syntaxhighlight> will produce an error; use <syntaxhighlight lang="lua" inline>hex = {['7f'] = 127}</syntaxhighlight> instead.
Note that when given ''within'' brackets, or to the right of the equal sign, quotation marks are needed, or else string values will be taken as variables:
<syntaxhighlight lang="lua" inline> a = {[b] = c}</syntaxhighlight>
assigns the value of variable ''c'' to the key ''contained in variable'' ''b''.
== Functions ==
* Functions can return any kind of value {{--}} ''including a function''. This is a powerful feature that can readily confuse the beginner. If you set <syntaxhighlight lang="lua" inline>a=mw.ustring.gmatch(text, "(.)")</syntaxhighlight>, the result assigned to <code>a</code> will be a '''function''', not a string character! However, assigning <code>b=a()</code> by calling the function stored in <code>a</code> will return the first match (a string). Every time you set <code>b=a()</code> after that you'll get another match (string) into <code>b</code>, until you run out of matches and get <code>nil</code>. Many '''iterator functions''' act this way.
* You can keep separate counts for iterator functions by using different variables. For example, if you set <syntaxhighlight lang="lua" inline>q=mw.ustring.gmatch(text, "(x.)")</syntaxhighlight> in the same module, you can pull characters from the same piece of text (<code>text</code>) by evaluating <code>d=q()</code> without losing your place in <code>a()</code>.
* [[tail call|Tail calls]] offer substantial benefits in performance for those who master the language.
* Function names are often of the form {{code|p.myFunctionName}}, where p is the table from the {{code|return p}} at the bottom of your program. The reason for this is that you can only access functions that are entries in this table from the original {{code|#invoke}} statement. Functions for local use within the program can have any name.
== Understanding patterns ==
''Note:'' Lua patterns are ''not'' [[regular expression|regular expressions]] in the traditional POSIX sense, and they are not even a subset of regular expressions. But they share many constructs with regular expressions (more [[Help:Lua for beginners#regex|below]]).
Lua patterns are used to define, find and handle a ''pattern'' in a string. It can do the common search and replace action in a text, but it has more options that doing plain text only. For example, in one go it can change the errors 'New yorker', 'New-Yorker', and 'NewYorker' into 'New Yorker'.
* To begin with, a pattern works like a plain string so long as it doesn't contain the special characters {{code|^ $ () % . [] * + - ?}}
* Square brackets {{code|[ ]}} are used to match ''one'' ''single character'' in the string from a list of choices. {{code|[abc]}} matches the letters a, b, or c. With {{code|^}} right after {{code|[}} they indicate "anything but": {{code|[^abc]}} = not a, b, or c. Inside brackets and when not the first character, a minus {{code|-}}indicates a range: {{code|[a-z]}} matches one single character from a, b, c, …, z.
* Period {{code|.}} matches any character.
* Percent {{code|%}} indicates a large set (class) of possible character matches when it is followed by a letter. See [https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Character_class] for a full list. <!--- should test/list these empirically to be sure ---> When followed by punctuation (whether a special character above or not) the {{code|%}} is removed and the punctuation is taken as a literal character; {{code|%%}} = literal %. Special classes include a balanced class {{code|%bxy}} and {{code|%f[set]}}; see the link above for more.
* Parentheses {{code|( )}} indicate captures. The captures can be accessed later in the search string or in the string.gsub replacement string as {{code|%1}} to {{code|%9}}, and are returned by string.match as an expression list of results.
* The qualifiers {{code|? - * +}} specify repetitions of a single character (not a longer string).
:* {{code|?}} means 0 or 1 repetitions: {{code|a?}} matches "a" or "".
:* {{code|-}} means 0 or more repetitions, choosing as few as possible to achieve a match ("non-greedy"). For example {{code|2=lua|string.match("bbbb", "(.-)")}} yields "", which is less than useful because there is nothing to root the ends of the expression and prevent it from matching zero characters.
:* {{code|*}} means 0 or more repetitions, choosing as many as possible ("greedy"). For example {{code|2=lua|string.match("bbbb", ".*")}} yields bbbb.
:* {{code|+}} means 1 or more repetitions, choosing as many as possible ("greedy").
Note that the greediness of the ''leftmost'' qualifier rules over all others when there is a choice: {{code|(.*)b(.*)}} when matched on "bbb" will return "bb", "", while {{code|a(.-)b(.-)a}} when matched on "abbba" will return "", "bb".
* {{code|^}} and {{code|$}} indicate the beginning and end of the string if they occur in the appropriate place in the pattern. Otherwise they are literal characters. {{code|^}} is not used in the {{code|string.gmatch}} function.
The reference manual for Lua patterns is at [[:mw:Extension:Scribunto/Lua_reference_manual#Patterns|mediawiki.org]].
== {{anchor|regex}}Note on Lua patterns versus regular expressions ==
Lua patterns are ''loosely based'' on [[regular expression]]s (sometimes shortened to regex or regexp). Lua patterns deliberately lack the most complex regular expression constructs (to avoid bloating the Lua code base), where many other computer languages or libraries use a more complete set. Lua patterns are not even a subset of regular expressions, as there are also discrepancies, like Lua using the escape character <code>%</code> instead of <code>\,</code>, and additions, like Lua providing <code>-</code> as a non-greedy version of <code>*</code>.
Here is a list of some of the things that Lua patterns lack compared to regular expressions:
* You '''cannot''' search for alternations between anything else than single characters (you '''cannot''' say <code>(his|her)</code> to choose between <code>his</code> and <code>her</code>, you can only say <code>[abc]</code> to choose between single characters <code>a</code>, <code>b</code>, or <code>c</code>).
* You '''cannot''' look for multiples of multi-letter constructs such as <code>(choo-)*choo</code> to match <code>choo</code>, <code>choo-choo</code> or <code>choo-choo-choo</code>. There is no way to do this with Lua patterns.
* You '''cannot''' specify the minimum and maximum number of repetitions like <code>[0-9]{3,5}</code> (to match 3 to 5 digits); in Lua you would say <code>%d%d%d%d?%d?</code> instead in this case.
There are Lua libraries that offer more powerful options,<sup>[http://lua-users.org/wiki/PatternsTutorial]</sup> including regular expressions, but the support on Wikipedia is pretty basic.
Wikipedia help for regular expressions (which Lua, as mentioned, does ''not'' support) is at [[Wikipedia:AutoWikiBrowser/Regular expression]].
{{Wikipedia technical help|collapsed}}
[[Category:Module help|*]]
g5cqnut93ow8nlldhshcp1ius10afds
790913
790912
2026-05-19T17:20:03Z
Nimmzo
78995
/* Recurrent bugs */ illustrated each error in Debug console. Added <br> to start the next sentence at column 1.
790913
wikitext
text/x-wiki
{{WikiProject Lua header}}
{{Selfref|This help page is meant to provide some basic orientation for those new to Lua/Scribunto.}}
{{ඉංග්රීසි ව්යාපෘතියේ සිට ආයාත කළ පිටුව}}
== Overview ==
[[WP:Lua|Lua]] is a lightweight scripting language safely available on Wikipedia via [[mw:Extension:Scribunto|Scribunto]]. Its purpose is to allow you to process the data which is available on Wikipedia content pages to allow various sorts of customized display of information.
It runs in a sandboxed environment to protect the stability of Wikipedia while enabling powerful <syntaxhighlight lang="lua" inline>{{template}}</syntaxhighlight> and <syntaxhighlight lang="lua" inline>module:</syntaxhighlight> functionality.
The most important help file is the [[mw:Extension:Scribunto/Lua reference manual|MediaWiki Scribunto Lua reference manual]], which provides a concise summary of the language and standard library calls as implemented on MediaWiki.
The standard [http://www.lua.org/manual/5.1/manual.html Lua reference manual] is well written and comprehensive, but it can be confusing for beginners because some standard features don't work on wiki pages. You cannot call <syntaxhighlight lang="lua" inline>print("Hello, World!")</syntaxhighlight> in a module, but you can preview your User page showing the string <syntaxhighlight lang="lua" inline>"Hello World!"</syntaxhighlight> generated by the Lua [[Module:Example]]. Think of your Lua template as an HTML generator.
=== Generating "Hello World!" ===
You do not need to install or save anything.
# Edit your User page: <code>පරිශීලක:YourUserName</code>
# Paste the following call at the beginning of a new line on your User page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{#invoke:Example|hello}}
</syntaxhighlight></blockquote>
<ol start="3">
<li>Click <code>Preview</code>. The call of the function <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> in the [[Module:Example]] is replaced with the following:</li>
</ol>
<blockquote><syntaxhighlight lang="lua" line>
Hello World!
</syntaxhighlight></blockquote>
<ol start="4">
<li>Click <code>Cancel</code>. When prompted, click <code>Leave</code>.</li>
<li>Your User page remains '''un'''modified.</li>
</ol>
== Debug console: Start learning Lua ==
The Lua Scribunto <code>Debug Console</code> is a safe, interactive tool for learning Lua in Wikipedia.
# Click <code>Edit</code> on the [[Module:Yesno]] page.
# Scroll to the bottom of the page to the <code>Debug console</code> section beneath the Lua editor.
# Paste the comment and the call into the <span style="color:#86888c;">gray</span> input box (above the <code>Clear</code> button).
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
--[[ඔබගේ ආරම්භක Lua "හෙලෝ වර්ල්ඩ්" යන වගේම වැඩසටහන]]--
print("වෙල්කම් වෙයි " .. _VERSION .. "!") -- Lua අනුවාදය .. සමඟ එකතු කරයි
</syntaxhighlight></blockquote>
<ol start="4">
<li>Press {{key press|Enter}} once to execute the two Lua command''s''.</li>
<li>The result will appear below the Lua <syntaxhighlight lang="lua" inline>print</syntaxhighlight> command line:</li>
</ol>
<blockquote><syntaxhighlight lang="lua" line start=3>
වෙල්කම් වෙයි Lua 5.1!
</syntaxhighlight></blockquote>
<ol start="6">
<li>Press <code>Up arrow</code> (↑) to cycle through previous Lua commands.</li>
<li>Optionally, click <code>Clear</code> to clear ''only'' the <code>Debug Console</code>; the Lua editor above will remain '''un'''modified.</li>
</ol>
; HTML generator in the Debug console
Call the function <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> in <code>Module:</code>Example:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local modExample = require('Module:Example') -- load the module in Debug console
local frame = mw.getCurrentFrame(); print(modExample.hello(frame)) -- display "Hello World!"
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
Hello World!
</syntaxhighlight></blockquote>
; Identity function
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local yesno = require('Module:Yesno') -- #if yesno then returns its input parameter
print(mw.getCurrentFrame():callParserFunction("#if", yesno("Yes"), "Yes", 'නැහැ'))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
Yes
</syntaxhighlight></blockquote>
# Close the protected <code>Module:</code>Yesno that remains '''un'''modified.
== Issues with the current implementation ==
Besides the lack of <code>print()</code> in a module, there are other features missing – see [[mw:Extension:Scribunto/Lua reference manual#Differences from standard Lua|Differences from standard Lua]] for a complete list.
At the present time, it is advisable to use ''[[mw:Extension:Scribunto/Lua reference manual#Ustring library|mw.ustring]]'' functions instead of ''[[mw:Extension:Scribunto/Lua reference manual#String library|string]]'', because the latter sometimes fails with Unicode characters.
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local lang = mw.getCurrentFrame():callParserFunction("#language", "si") -- Sinhala
local lenUnicode, lenByte, lenSharp = mw.ustring.len(lang), string.len(lang), #lang
print(("lang: %s Mw.ustring.len = %d String.len = %d Sharp = %d"):format(lang, lenUnicode, lenByte, lenSharp))
</syntaxhighlight></blockquote>
Debug console supports Unicode:
<blockquote><syntaxhighlight lang="lua" line start=4>
lang: සිංහල Mw.ustring.len = 5 String.len = 15 Sharp = 15
</syntaxhighlight></blockquote>
== Input ==
The programs are run only when the page is "parsed" (when it or a page it incorporates is changed or previewed), not every time you view the output. Therefore there can be no convenient Lua module that allows you to type in a Fahrenheit temperature in an input box and get back the corresponding Celsius temperature when you press a button, or allows you to click on a segment of a Mandelbrot set visualization on a page to expand it as often as you like. There has to be an actual Wiki page (or at least a page you have submitted for preview) containing the input data.
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local function toCelsius(tempFahrenheit) return (tempFahrenheit - 32) * 5 / 9 end
print(("toCelsius(32°F) = %s°C. toCelsius(68°F) = %d°C"):format(toCelsius(32), toCelsius(68)))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
toCelsius(32°F) = 0°C. toCelsius(68°F) = 20°C
</syntaxhighlight></blockquote>
However, it is possible to use library functions like [[mw:Extension:Scribunto/Lua reference manual#mw.title.getCurrentTitle|mw.title.getCurrentTitle()]] to import content from any text content page on the Wiki.
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
print(mw.title.getCurrentTitle())
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=2>
Module:Yesno
</syntaxhighlight></blockquote>
You cannot, however, import data from files, not even .svg files which contain XML text data.
== Calling a Lua module ==
Lua calls look much like [[WP:template|template]]s, and consist of a small block of text.
In your User page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{ConvertNumeric|decToHex|73}}
</syntaxhighlight></blockquote>
Click <code>Preview</code> or click <code>Edit</code> this section to see the call then <code>Cancel</code>:
<blockquote>
{{#invoke:ConvertNumeric|decToHex|73}}
</blockquote>
This text calls the Lua script itself, which is housed in the <code>Module:</code> [[WP:namespace|namespace]]. The effect of this call is to send the information within the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> block to the Lua module, and to replace everything within the brackets with a piece of text that it sends back in return. (Literally, in the "return" statement)
Note that the first "parameter", in this case <code>decToHex</code>, is actually a <syntaxhighlight lang="lua" inline>function</syntaxhighlight> called within the Lua module. This field must always be included in any <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight>. To those unfamiliar with modules, especially Wikipedia template coders who expect anything after <code>|</code> to be a parameter, the need for this extra field is surprising, especially if all uses of the module depend on its presence.
In Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local convNum = require('Module:ConvertNumeric')
local frame = mw.getCurrentFrame(); frame.args[1] = "73" -- number always as string
print(("0x%s = %s = %d"):format(convNum.decToHex(frame), string.format("0x%X", 73), 0x49))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=4>
0x49 = 0x49 = 73
</syntaxhighlight></blockquote>
=== Documenting a Lua module ===
When documenting your module, it is useful to include an explicit usage instruction using [[සැකිල්ල:Module link expanded]]:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{mlx|ConvertNumeric|decToHex|73}}
</syntaxhighlight></blockquote>
Hyperlink to the module:
<blockquote>
{{mlx|ConvertNumeric|decToHex|73}}
</blockquote>
For many existing modules, an example <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> of the script (and little else) is provided on the <code>Module talk:</code> page. It is convenient for authors to be able to flip quickly to the talk tab to look at the effects of their changes, but you should never transclude the talk page as a template - people might actually talk on it! Alternatively, the module page can show documentation from a separate /doc-page (as [[Module:WikidataIB]] does).
=== Another example: Using LuaCall to perform a single Lua instruction ===
As a beginner, or in casual talk page conversation, you might only have one little calculation you want to use Lua for but don't want to write a full module. You might find [[Module:LuaCall]] convenient for this. For example, you can test how a greedy [https://www.lua.org/pil/20.1.html Lua pattern] works:
* <syntaxhighlight lang="lua" inline>{{#invoke:LuaCall|main|a=bbbbbbbbbba|b=bb(.*)b(.+)bba|string.match(a,b)}}</syntaxhighlight> → <code>{{#invoke:LuaCall|main|a=bbbbbbbbbba|b=bb(.*)b(.+)bba|string.match(a,b)}}</code>
or count up the length of a [[wikipedia:Did you know|''Did you know'']] hook or the text portion of a ''Did you know'' candidate:
* <syntaxhighlight lang="lua" inline>{{#invoke:LuaCall|main|a=... that you can count the length of your DYK hook with a Lua module?|string.len(a)}}</syntaxhighlight>→ <code>{{#invoke:LuaCall|main|a=... that you can count the length of your DYK hook with a Lua module?|string.len(a)}}</code>
In these specific examples, however, [[Module:String]] could do both of these tasks.
The script at [[Module:LuaCall]] has been written to accept any set of named parameters <code>somename=value</code>, for each one storing the string <code>value</code> in the variable with the name <code>somename</code>, and then allowing you to use these variables as parameters for any function available in Lua. The script then returns only the ''first'' value returned by the function ([https://www.lua.org/pil/5.1.html Lua functions can return multiple values], but in this case, only the first is returned from the module).
== Lua program structure: Output ==
The most fundamental part of a Wikipedia Lua program is a '''return''' statement which carries its output back to the page that had the <code>#invoke</code>. You ''can'' have a Lua function that runs without error even though it doesn't contain a return statement, but on Wikipedia it is pointless, as Lua programs cannot generally have side effects on Wikipedia.
The module itself must return a Lua '''table''' of values. A Lua table is expressed as a list of values separated by commas, within curly braces. When the module is called by <code>#invoke</code>, the '''function''' it names (the first argument after |) is looked for in that table. That function, in turn, is expected to return something that can be represented as a '''string'''.
Therefore, <syntaxhighlight lang="lua" inline>return { mw.ustring.gmatch( "Hello world", "(.*)" ) }</syntaxhighlight> is actually a complete Lua module (though a very strange one) - it returns the function returned by mw.ustring.gmatch (an iterator function listed in the Lua reference cited above) as the one and only element in an array (represented within <code>{}</code>)—which when executed using <syntaxhighlight lang="wikitext" inline>{{#invoke:ModuleName|1}}</syntaxhighlight> yields the string "Hello world". ''However'', things are not usually done this way. Typically we use the overall form:
<syntaxhighlight lang="lua">
local p = {} -- Defines a variable p as an empty table, but *not* nil.
function p.main( frame ) -- This block defines the table element p["main"] as a function.
return "Hello world" -- The string result of the function.
end -- Ends the block defining the function object p["main"] (or p.main).
return p -- This returns the table p, which under the key "main" contains the
-- function above (p.main), which when called returns string "Hello world".
</syntaxhighlight>
Note that <syntaxhighlight lang="lua" inline>function p.main(frame) ... end</syntaxhighlight> is equivalent to <syntaxhighlight lang="lua" inline>p.main = function(frame) ... end</syntaxhighlight> or <syntaxhighlight lang="lua" inline>p["main"] = function(frame) ... end</syntaxhighlight>. The function is just another type of value, retrieved with the key <code>"main"</code> from table <code>p</code>. If you want to allow users to invoke the same module with <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|hello}}</nowiki></code> instead of <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|main}}</nowiki></code>, you can write <code>p.hello = p.main</code> to copy the reference to this function to a new key in the table. You can even write <code>p[""] = p.main</code>, which causes <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|}}</nowiki></code> to produce the same output as <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|main}}</nowiki></code>. Learning to think of functions as a data type becomes very important later on for working with library functions like <code>[[mw:Extension:Scribunto/Lua_reference_manual#string.gsub|mw.ustring.gsub]]</code>, and constructing iterator functions.
== Lua program structure: Input ==
The '''<code>frame</code>''' parameter above (which is pretty much always given this name in Wikipedia Lua modules) receives another table, which is passed ''from'' the page that makes the call ''to'' the Lua module. It contains a surprising amount of stuff, of which just a few things concern the novice.
=== Arguments ===
{{see also|Module:Arguments}}
<code>frame.args</code> contains ''another'' table, namely, all the content sent by the user within the <code>#invoke</code> brackets except the first argument which states the name of the function to be executed. So in {{Mlx|ConvertNumeric|decToHex|3377}}, the string <code>"3377"</code> is the content of <code>frame.args[1]</code> (which is the same as <code>frame["args"][1]</code> but ''not'' the same as <code>frame.args["1"]</code> or <code>frame["args"]["1"]</code>). Unnamed parameters come out with numbers as keys (<code>frame.args[1]</code>, <code>frame.args[2]</code>, etc.), while named parameters come out with the parameter names (strings) as keys (<code>frame.args["count"]</code>, <code>frame.args["style"]</code>, etc.).
''Example:''<blockquote><code><nowiki>{{#invoke:</nowiki>''modulename''|''functionname''<nowiki>|3377|4|count=3|style=bold}}</nowiki></code> </blockquote>results in<blockquote><code>frame.args[1]</code>=3377, <code>frame.args[2]</code>=4, <code>frame.args["count"]</code>=3, <code>frame.args["style"]</code>=<code>"bold"</code>.</blockquote>
=== Parent frame ===
Within <code>frame</code> there is a ''parent'' frame, referring to the page that called the page that gives the script, and you can pull out arguments from that also. Just write
<code>parent=frame.getParent(frame)</code>
and <code>parent.args</code> will contain those arguments.
It is popular in Lua to use the synonymous statement <code>parent=frame''':'''getParent()</code>, cancelling the need to write <code>frame</code> twice. Note the colon (<code>:</code>) instead of the dot (<code>.</code>). <code>parent=frame:getParent()</code> means exactly the same as <code>parent=frame.getParent(frame)</code>. For novices this can be confusing, and it is important to be aware of this idiom. If you use it in the wrong way, though, the script errors are pretty good at pointing out that this was the mistake.
== Basic debugging ==
{{Main|Help:Lua debugging}}
Debugging can start as soon as you write programs, and can be done simply with string concatenation.
Just set up a variable with some recognizable name like "debuglog" in your main function (p.main) with a statement like <syntaxhighlight lang="lua" inline>local debuglog=""</syntaxhighlight>. This initial {{code|""}} definition helps because otherwise it will be '''nil''' and concatenating a string to nil gets you an error. Now whenever you have a variable you'd like to test, say {{tt|x}}, just write <syntaxhighlight lang="lua" inline>debuglog = debuglog .. "x=" .. tostring(x)</syntaxhighlight>, and have at the end of your program <syntaxhighlight lang="lua" inline> return output .. debuglog</syntaxhighlight> The "{{tt|tostring}}" is a function to ensure {{tt|x}} is interpreted as a string, so that if it is an table, nil, etc. it will display as "{{samp|table}}", "{{samp|nil}}", etc. rather than as Script error.
== Format ==
The [[WP:Lua style guide]] gives some basic formatting suggestions expected by the JavaScript module editor, such as using four-space indentations and keeping if, then, else, end at the same level of indentation.
Comments to the end of a line are marked by {{code|--}} . ''Use them.'' Many modules for Wikipedia have a straightforward, linear design, but that doesn't mean it won't help to have your sections clearly labelled when you go back to the code for the hundredth time. The Lua style guide gives additional recommendations for using functions to keep your work more organized.
== Errors ==
Lua errors appear as red "Script error" messages. If Javascript is enabled, '''the <span style="color:#ff0000;">red</span> script error message is a link''' which usually allows you to follow it back to the line in the module where the error occurred. There are some exceptions, for example "Module not found", if the name of the module itself is mistyped, or "The function you specified did not exist" if the function name given is invalid.
=== Recurrent bugs ===
Some bugs you might want to keep in mind:
;Missing operator for concatenation
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=2 copy>
local debugLog = "" -- empty report string
debugLog = debugLog "missing double dot" -- append to the report
</syntaxhighlight></blockquote>
The following means you forgot the <code>..</code> between a string and a variable somewhere in a mess of stuff you're concatenating.
<blockquote><syntaxhighlight lang="lua" line start=9>
Lua error in console input at line 8: attempt to call local 'debugLog' (a string value).
</syntaxhighlight></blockquote>
;String expected, got function
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=3 copy>
local debugLog = "" -- empty report string
local res = mw.ustring.gmatch("Hello World!", "([aeiouAEIOU])") -- iterator of vowels
debugLog = debugLog..res -- populate the report with only strings
</syntaxhighlight></blockquote>
Some important things like <syntaxhighlight lang="lua" inline>mw.ustring.gmatch</syntaxhighlight> actually return ''functions'', not strings - see [[#Functions|Functions]] below.
<blockquote><syntaxhighlight lang="lua" line start=10>
Lua error in console input at line 9: attempt to concatenate local 'res' (a function value).
</syntaxhighlight></blockquote>
;Variable ignores assignment
A variable ignores all your efforts to assign stuff to it:
<blockquote><syntaxhighlight lang="lua" line highlight=1,3 copy>
local debugLog = "top level" -- initial value
do
local debugLog = "nested level" -- set the new value
print("Inside do: "..debugLog)
end
print("Outside do: "..debugLog) -- get the old value
</syntaxhighlight></blockquote>
You may have inadvertently written ''two'' local statements - the one sets the value of the variable within a limited region, and when the program leaves that region, you're back to the old value.
<blockquote><syntaxhighlight lang="lua" line start=7>
Inside do: nested level
Outside do: top level
</syntaxhighlight></blockquote>
A numbered table entry ignores all your efforts to assign to it:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local table = {}; local arg = "50"; local valPrm = tonumber(arg)
table[arg] = "index as string"
table[valPrm] = "index as number"
print(table[arg] == table[valPrm])
</syntaxhighlight></blockquote>
This is because {{code|table["50"]}} '''is not''' {{code|table[50]}}.<br/>
Typically you have processed a parameter (which you may have received from the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> as a string) with string functions in one place,<br>
but performed numeric operations in another, leaving you with two different types of variable to use for an index.
<blockquote><syntaxhighlight lang="lua" line start=5>
false
</syntaxhighlight></blockquote>
;<syntaxhighlight lang="lua" inline>nil</syntaxhighlight> and common pitfalls
There are all sorts of things you can't do with a local variable set to nil, such as: <syntaxhighlight lang="lua" inline>local x = nil</syntaxhighlight>, like:
# Assign <code>x.somefield</code>
# Get value at index {{code|x[idx]}}
# Concatenate <syntaxhighlight lang="lua" inline>x .. "Cannot concatenate with nil"</syntaxhighlight>
# Evaluate <syntaxhighlight lang="lua" inline>table[x]</syntaxhighlight>
Initialize such variables with: <syntaxhighlight lang="lua" inline>local x={}; local table = {}</syntaxhighlight><br>
Often "global" is mentioned in these errors because you didn't have a {{tt|local}} statement for the <syntaxhighlight lang="lua" inline>nil</syntaxhighlight> variable.
;Cannot invoke module
* ''no such module.'' You called <syntaxhighlight lang="lua" inline>#invoke:moduleNameUnknown</syntaxhighlight> that didn't exist or you wrongly kept the prefix <code>Module:</code> writing {{code|#invoke:Module:moduleName}}.
* ''the function specified did not exist.'' You called <syntaxhighlight lang="lua" inline>#invoke:moduleName|functionUnknown</syntaxhighlight>, but the field after the name of the module is wrong.<br>Often this field expects a standard name like "main", and you've forgotten it and gone straight to the first data parameter.<br>If you're unsure of the function name, check the module documentation, or look for what function(s) in the code accept a "frame" parameter.
;Graphics overflow issue
Some graphics you're trying to display are heading off to the hills: actually a HTML error.<br>
You didn't close one <syntaxhighlight lang="html" inline></div></syntaxhighlight>, so all the top: and left: styles keep adding up.
== Understanding tables and related concepts ==
* An '''expression list''' is a set of values separated by commas. The values can be strings, numbers, tables, functions, etc.
* A '''sequence''' is a set of entries with indices from 1 to N, where N is a positive integer. They can be created by placing brackets around an expression list. For example, if <syntaxhighlight lang="lua" inline>a={1, "quotation", mw.ustring.gmatch("abca","a"), {2,3,4}}</syntaxhighlight> then <code>a[1]</code>=1, <code>a[2]</code>="quotation", <code>a[3]</code> is the function returned by <code>gmatch()</code>, and <code>a[4]</code> is the table <code>{2,3,4}</code>. An expression list can also be recovered from a table using <code>unpack()</code>: <code>b, c, d = unpack(a)</code> will set <code>b</code>=1, <code>c</code>="quotation", and <code>d</code> as the function returned by <code>gmatch()</code>; <code>{2,3,4}</code> will be discarded in this case.
* A '''table''' is a sequence, optionally supplemented by named keys: <code>digit["two"]="2"</code>. Several table functions like <code>table.concat</code> will only work with the numbered values and ignore named keys.
* The '''metatable''' offers a large, optional set of methods for altering table behavior. For example, you can define a table to be callable like a function.
=== Initializing a table ===
It is often useful to create a whole table at once in a statement. There are many equivalent ways to do this, but the shortcuts don't work for every kind of value. To begin with, the most general way is to assign each key and value explicitly:
<syntaxhighlight lang="lua" inline>a = {[0]='zero', [1]='one', ['1']='string for one'}</syntaxhighlight>
If sequence keys (positive integers) are given in order, only the values need to be given, so the following will assign <syntaxhighlight lang="lua" inline>'one'</syntaxhighlight> to <syntaxhighlight lang="lua" inline>a[1]</syntaxhighlight>:
<syntaxhighlight lang="lua" inline>a = {[0]='zero', 'one', ['1']='string for one'}</syntaxhighlight>
If a key has only letters, digits, and underscores, and begins with a non-digit, the brackets and quotation marks can be omitted:
<syntaxhighlight lang="lua" inline>a = {a='one', b='two'}</syntaxhighlight>
This is identical to <syntaxhighlight lang="lua" inline>a = {["a"]='one', ["b"]='two'}</syntaxhighlight>.
However, this will fail for keys that begin with a digit: <syntaxhighlight lang="lua" inline>hex = {7f = 127}</syntaxhighlight> will produce an error; use <syntaxhighlight lang="lua" inline>hex = {['7f'] = 127}</syntaxhighlight> instead.
Note that when given ''within'' brackets, or to the right of the equal sign, quotation marks are needed, or else string values will be taken as variables:
<syntaxhighlight lang="lua" inline> a = {[b] = c}</syntaxhighlight>
assigns the value of variable ''c'' to the key ''contained in variable'' ''b''.
== Functions ==
* Functions can return any kind of value {{--}} ''including a function''. This is a powerful feature that can readily confuse the beginner. If you set <syntaxhighlight lang="lua" inline>a=mw.ustring.gmatch(text, "(.)")</syntaxhighlight>, the result assigned to <code>a</code> will be a '''function''', not a string character! However, assigning <code>b=a()</code> by calling the function stored in <code>a</code> will return the first match (a string). Every time you set <code>b=a()</code> after that you'll get another match (string) into <code>b</code>, until you run out of matches and get <code>nil</code>. Many '''iterator functions''' act this way.
* You can keep separate counts for iterator functions by using different variables. For example, if you set <syntaxhighlight lang="lua" inline>q=mw.ustring.gmatch(text, "(x.)")</syntaxhighlight> in the same module, you can pull characters from the same piece of text (<code>text</code>) by evaluating <code>d=q()</code> without losing your place in <code>a()</code>.
* [[tail call|Tail calls]] offer substantial benefits in performance for those who master the language.
* Function names are often of the form {{code|p.myFunctionName}}, where p is the table from the {{code|return p}} at the bottom of your program. The reason for this is that you can only access functions that are entries in this table from the original {{code|#invoke}} statement. Functions for local use within the program can have any name.
== Understanding patterns ==
''Note:'' Lua patterns are ''not'' [[regular expression|regular expressions]] in the traditional POSIX sense, and they are not even a subset of regular expressions. But they share many constructs with regular expressions (more [[Help:Lua for beginners#regex|below]]).
Lua patterns are used to define, find and handle a ''pattern'' in a string. It can do the common search and replace action in a text, but it has more options that doing plain text only. For example, in one go it can change the errors 'New yorker', 'New-Yorker', and 'NewYorker' into 'New Yorker'.
* To begin with, a pattern works like a plain string so long as it doesn't contain the special characters {{code|^ $ () % . [] * + - ?}}
* Square brackets {{code|[ ]}} are used to match ''one'' ''single character'' in the string from a list of choices. {{code|[abc]}} matches the letters a, b, or c. With {{code|^}} right after {{code|[}} they indicate "anything but": {{code|[^abc]}} = not a, b, or c. Inside brackets and when not the first character, a minus {{code|-}}indicates a range: {{code|[a-z]}} matches one single character from a, b, c, …, z.
* Period {{code|.}} matches any character.
* Percent {{code|%}} indicates a large set (class) of possible character matches when it is followed by a letter. See [https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Character_class] for a full list. <!--- should test/list these empirically to be sure ---> When followed by punctuation (whether a special character above or not) the {{code|%}} is removed and the punctuation is taken as a literal character; {{code|%%}} = literal %. Special classes include a balanced class {{code|%bxy}} and {{code|%f[set]}}; see the link above for more.
* Parentheses {{code|( )}} indicate captures. The captures can be accessed later in the search string or in the string.gsub replacement string as {{code|%1}} to {{code|%9}}, and are returned by string.match as an expression list of results.
* The qualifiers {{code|? - * +}} specify repetitions of a single character (not a longer string).
:* {{code|?}} means 0 or 1 repetitions: {{code|a?}} matches "a" or "".
:* {{code|-}} means 0 or more repetitions, choosing as few as possible to achieve a match ("non-greedy"). For example {{code|2=lua|string.match("bbbb", "(.-)")}} yields "", which is less than useful because there is nothing to root the ends of the expression and prevent it from matching zero characters.
:* {{code|*}} means 0 or more repetitions, choosing as many as possible ("greedy"). For example {{code|2=lua|string.match("bbbb", ".*")}} yields bbbb.
:* {{code|+}} means 1 or more repetitions, choosing as many as possible ("greedy").
Note that the greediness of the ''leftmost'' qualifier rules over all others when there is a choice: {{code|(.*)b(.*)}} when matched on "bbb" will return "bb", "", while {{code|a(.-)b(.-)a}} when matched on "abbba" will return "", "bb".
* {{code|^}} and {{code|$}} indicate the beginning and end of the string if they occur in the appropriate place in the pattern. Otherwise they are literal characters. {{code|^}} is not used in the {{code|string.gmatch}} function.
The reference manual for Lua patterns is at [[:mw:Extension:Scribunto/Lua_reference_manual#Patterns|mediawiki.org]].
== {{anchor|regex}}Note on Lua patterns versus regular expressions ==
Lua patterns are ''loosely based'' on [[regular expression]]s (sometimes shortened to regex or regexp). Lua patterns deliberately lack the most complex regular expression constructs (to avoid bloating the Lua code base), where many other computer languages or libraries use a more complete set. Lua patterns are not even a subset of regular expressions, as there are also discrepancies, like Lua using the escape character <code>%</code> instead of <code>\,</code>, and additions, like Lua providing <code>-</code> as a non-greedy version of <code>*</code>.
Here is a list of some of the things that Lua patterns lack compared to regular expressions:
* You '''cannot''' search for alternations between anything else than single characters (you '''cannot''' say <code>(his|her)</code> to choose between <code>his</code> and <code>her</code>, you can only say <code>[abc]</code> to choose between single characters <code>a</code>, <code>b</code>, or <code>c</code>).
* You '''cannot''' look for multiples of multi-letter constructs such as <code>(choo-)*choo</code> to match <code>choo</code>, <code>choo-choo</code> or <code>choo-choo-choo</code>. There is no way to do this with Lua patterns.
* You '''cannot''' specify the minimum and maximum number of repetitions like <code>[0-9]{3,5}</code> (to match 3 to 5 digits); in Lua you would say <code>%d%d%d%d?%d?</code> instead in this case.
There are Lua libraries that offer more powerful options,<sup>[http://lua-users.org/wiki/PatternsTutorial]</sup> including regular expressions, but the support on Wikipedia is pretty basic.
Wikipedia help for regular expressions (which Lua, as mentioned, does ''not'' support) is at [[Wikipedia:AutoWikiBrowser/Regular expression]].
{{Wikipedia technical help|collapsed}}
[[Category:Module help|*]]
iwucgtzw0gw2h2s1huep3z8nhzmn88m
790915
790913
2026-05-19T17:50:57Z
Nimmzo
78995
/* Understanding tables and related concepts */ Added Scribunto tool mw.logObject(seq) to display a table in the Debug console
790915
wikitext
text/x-wiki
{{WikiProject Lua header}}
{{Selfref|This help page is meant to provide some basic orientation for those new to Lua/Scribunto.}}
{{ඉංග්රීසි ව්යාපෘතියේ සිට ආයාත කළ පිටුව}}
== Overview ==
[[WP:Lua|Lua]] is a lightweight scripting language safely available on Wikipedia via [[mw:Extension:Scribunto|Scribunto]]. Its purpose is to allow you to process the data which is available on Wikipedia content pages to allow various sorts of customized display of information.
It runs in a sandboxed environment to protect the stability of Wikipedia while enabling powerful <syntaxhighlight lang="lua" inline>{{template}}</syntaxhighlight> and <syntaxhighlight lang="lua" inline>module:</syntaxhighlight> functionality.
The most important help file is the [[mw:Extension:Scribunto/Lua reference manual|MediaWiki Scribunto Lua reference manual]], which provides a concise summary of the language and standard library calls as implemented on MediaWiki.
The standard [http://www.lua.org/manual/5.1/manual.html Lua reference manual] is well written and comprehensive, but it can be confusing for beginners because some standard features don't work on wiki pages. You cannot call <syntaxhighlight lang="lua" inline>print("Hello, World!")</syntaxhighlight> in a module, but you can preview your User page showing the string <syntaxhighlight lang="lua" inline>"Hello World!"</syntaxhighlight> generated by the Lua [[Module:Example]]. Think of your Lua template as an HTML generator.
=== Generating "Hello World!" ===
You do not need to install or save anything.
# Edit your User page: <code>පරිශීලක:YourUserName</code>
# Paste the following call at the beginning of a new line on your User page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{#invoke:Example|hello}}
</syntaxhighlight></blockquote>
<ol start="3">
<li>Click <code>Preview</code>. The call of the function <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> in the [[Module:Example]] is replaced with the following:</li>
</ol>
<blockquote><syntaxhighlight lang="lua" line>
Hello World!
</syntaxhighlight></blockquote>
<ol start="4">
<li>Click <code>Cancel</code>. When prompted, click <code>Leave</code>.</li>
<li>Your User page remains '''un'''modified.</li>
</ol>
== Debug console: Start learning Lua ==
The Lua Scribunto <code>Debug Console</code> is a safe, interactive tool for learning Lua in Wikipedia.
# Click <code>Edit</code> on the [[Module:Yesno]] page.
# Scroll to the bottom of the page to the <code>Debug console</code> section beneath the Lua editor.
# Paste the comment and the call into the <span style="color:#86888c;">gray</span> input box (above the <code>Clear</code> button).
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
--[[ඔබගේ ආරම්භක Lua "හෙලෝ වර්ල්ඩ්" යන වගේම වැඩසටහන]]--
print("වෙල්කම් වෙයි " .. _VERSION .. "!") -- Lua අනුවාදය .. සමඟ එකතු කරයි
</syntaxhighlight></blockquote>
<ol start="4">
<li>Press {{key press|Enter}} once to execute the two Lua command''s''.</li>
<li>The result will appear below the Lua <syntaxhighlight lang="lua" inline>print</syntaxhighlight> command line:</li>
</ol>
<blockquote><syntaxhighlight lang="lua" line start=3>
වෙල්කම් වෙයි Lua 5.1!
</syntaxhighlight></blockquote>
<ol start="6">
<li>Press <code>Up arrow</code> (↑) to cycle through previous Lua commands.</li>
<li>Optionally, click <code>Clear</code> to clear ''only'' the <code>Debug Console</code>; the Lua editor above will remain '''un'''modified.</li>
</ol>
; HTML generator in the Debug console
Call the function <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> in <code>Module:</code>Example:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local modExample = require('Module:Example') -- load the module in Debug console
local frame = mw.getCurrentFrame(); print(modExample.hello(frame)) -- display "Hello World!"
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
Hello World!
</syntaxhighlight></blockquote>
; Identity function
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local yesno = require('Module:Yesno') -- #if yesno then returns its input parameter
print(mw.getCurrentFrame():callParserFunction("#if", yesno("Yes"), "Yes", 'නැහැ'))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
Yes
</syntaxhighlight></blockquote>
# Close the protected <code>Module:</code>Yesno that remains '''un'''modified.
== Issues with the current implementation ==
Besides the lack of <code>print()</code> in a module, there are other features missing – see [[mw:Extension:Scribunto/Lua reference manual#Differences from standard Lua|Differences from standard Lua]] for a complete list.
At the present time, it is advisable to use ''[[mw:Extension:Scribunto/Lua reference manual#Ustring library|mw.ustring]]'' functions instead of ''[[mw:Extension:Scribunto/Lua reference manual#String library|string]]'', because the latter sometimes fails with Unicode characters.
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local lang = mw.getCurrentFrame():callParserFunction("#language", "si") -- Sinhala
local lenUnicode, lenByte, lenSharp = mw.ustring.len(lang), string.len(lang), #lang
print(("lang: %s Mw.ustring.len = %d String.len = %d Sharp = %d"):format(lang, lenUnicode, lenByte, lenSharp))
</syntaxhighlight></blockquote>
Debug console supports Unicode:
<blockquote><syntaxhighlight lang="lua" line start=4>
lang: සිංහල Mw.ustring.len = 5 String.len = 15 Sharp = 15
</syntaxhighlight></blockquote>
== Input ==
The programs are run only when the page is "parsed" (when it or a page it incorporates is changed or previewed), not every time you view the output. Therefore there can be no convenient Lua module that allows you to type in a Fahrenheit temperature in an input box and get back the corresponding Celsius temperature when you press a button, or allows you to click on a segment of a Mandelbrot set visualization on a page to expand it as often as you like. There has to be an actual Wiki page (or at least a page you have submitted for preview) containing the input data.
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local function toCelsius(tempFahrenheit) return (tempFahrenheit - 32) * 5 / 9 end
print(("toCelsius(32°F) = %s°C. toCelsius(68°F) = %d°C"):format(toCelsius(32), toCelsius(68)))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
toCelsius(32°F) = 0°C. toCelsius(68°F) = 20°C
</syntaxhighlight></blockquote>
However, it is possible to use library functions like [[mw:Extension:Scribunto/Lua reference manual#mw.title.getCurrentTitle|mw.title.getCurrentTitle()]] to import content from any text content page on the Wiki.
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
print(mw.title.getCurrentTitle())
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=2>
Module:Yesno
</syntaxhighlight></blockquote>
You cannot, however, import data from files, not even .svg files which contain XML text data.
== Calling a Lua module ==
Lua calls look much like [[WP:template|template]]s, and consist of a small block of text.
In your User page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{ConvertNumeric|decToHex|73}}
</syntaxhighlight></blockquote>
Click <code>Preview</code> or click <code>Edit</code> this section to see the call then <code>Cancel</code>:
<blockquote>
{{#invoke:ConvertNumeric|decToHex|73}}
</blockquote>
This text calls the Lua script itself, which is housed in the <code>Module:</code> [[WP:namespace|namespace]]. The effect of this call is to send the information within the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> block to the Lua module, and to replace everything within the brackets with a piece of text that it sends back in return. (Literally, in the "return" statement)
Note that the first "parameter", in this case <code>decToHex</code>, is actually a <syntaxhighlight lang="lua" inline>function</syntaxhighlight> called within the Lua module. This field must always be included in any <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight>. To those unfamiliar with modules, especially Wikipedia template coders who expect anything after <code>|</code> to be a parameter, the need for this extra field is surprising, especially if all uses of the module depend on its presence.
In Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local convNum = require('Module:ConvertNumeric')
local frame = mw.getCurrentFrame(); frame.args[1] = "73" -- number always as string
print(("0x%s = %s = %d"):format(convNum.decToHex(frame), string.format("0x%X", 73), 0x49))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=4>
0x49 = 0x49 = 73
</syntaxhighlight></blockquote>
=== Documenting a Lua module ===
When documenting your module, it is useful to include an explicit usage instruction using [[සැකිල්ල:Module link expanded]]:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{mlx|ConvertNumeric|decToHex|73}}
</syntaxhighlight></blockquote>
Hyperlink to the module:
<blockquote>
{{mlx|ConvertNumeric|decToHex|73}}
</blockquote>
For many existing modules, an example <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> of the script (and little else) is provided on the <code>Module talk:</code> page. It is convenient for authors to be able to flip quickly to the talk tab to look at the effects of their changes, but you should never transclude the talk page as a template - people might actually talk on it! Alternatively, the module page can show documentation from a separate /doc-page (as [[Module:WikidataIB]] does).
=== Another example: Using LuaCall to perform a single Lua instruction ===
As a beginner, or in casual talk page conversation, you might only have one little calculation you want to use Lua for but don't want to write a full module. You might find [[Module:LuaCall]] convenient for this. For example, you can test how a greedy [https://www.lua.org/pil/20.1.html Lua pattern] works:
* <syntaxhighlight lang="lua" inline>{{#invoke:LuaCall|main|a=bbbbbbbbbba|b=bb(.*)b(.+)bba|string.match(a,b)}}</syntaxhighlight> → <code>{{#invoke:LuaCall|main|a=bbbbbbbbbba|b=bb(.*)b(.+)bba|string.match(a,b)}}</code>
or count up the length of a [[wikipedia:Did you know|''Did you know'']] hook or the text portion of a ''Did you know'' candidate:
* <syntaxhighlight lang="lua" inline>{{#invoke:LuaCall|main|a=... that you can count the length of your DYK hook with a Lua module?|string.len(a)}}</syntaxhighlight>→ <code>{{#invoke:LuaCall|main|a=... that you can count the length of your DYK hook with a Lua module?|string.len(a)}}</code>
In these specific examples, however, [[Module:String]] could do both of these tasks.
The script at [[Module:LuaCall]] has been written to accept any set of named parameters <code>somename=value</code>, for each one storing the string <code>value</code> in the variable with the name <code>somename</code>, and then allowing you to use these variables as parameters for any function available in Lua. The script then returns only the ''first'' value returned by the function ([https://www.lua.org/pil/5.1.html Lua functions can return multiple values], but in this case, only the first is returned from the module).
== Lua program structure: Output ==
The most fundamental part of a Wikipedia Lua program is a '''return''' statement which carries its output back to the page that had the <code>#invoke</code>. You ''can'' have a Lua function that runs without error even though it doesn't contain a return statement, but on Wikipedia it is pointless, as Lua programs cannot generally have side effects on Wikipedia.
The module itself must return a Lua '''table''' of values. A Lua table is expressed as a list of values separated by commas, within curly braces. When the module is called by <code>#invoke</code>, the '''function''' it names (the first argument after |) is looked for in that table. That function, in turn, is expected to return something that can be represented as a '''string'''.
Therefore, <syntaxhighlight lang="lua" inline>return { mw.ustring.gmatch( "Hello world", "(.*)" ) }</syntaxhighlight> is actually a complete Lua module (though a very strange one) - it returns the function returned by mw.ustring.gmatch (an iterator function listed in the Lua reference cited above) as the one and only element in an array (represented within <code>{}</code>)—which when executed using <syntaxhighlight lang="wikitext" inline>{{#invoke:ModuleName|1}}</syntaxhighlight> yields the string "Hello world". ''However'', things are not usually done this way. Typically we use the overall form:
<syntaxhighlight lang="lua">
local p = {} -- Defines a variable p as an empty table, but *not* nil.
function p.main( frame ) -- This block defines the table element p["main"] as a function.
return "Hello world" -- The string result of the function.
end -- Ends the block defining the function object p["main"] (or p.main).
return p -- This returns the table p, which under the key "main" contains the
-- function above (p.main), which when called returns string "Hello world".
</syntaxhighlight>
Note that <syntaxhighlight lang="lua" inline>function p.main(frame) ... end</syntaxhighlight> is equivalent to <syntaxhighlight lang="lua" inline>p.main = function(frame) ... end</syntaxhighlight> or <syntaxhighlight lang="lua" inline>p["main"] = function(frame) ... end</syntaxhighlight>. The function is just another type of value, retrieved with the key <code>"main"</code> from table <code>p</code>. If you want to allow users to invoke the same module with <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|hello}}</nowiki></code> instead of <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|main}}</nowiki></code>, you can write <code>p.hello = p.main</code> to copy the reference to this function to a new key in the table. You can even write <code>p[""] = p.main</code>, which causes <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|}}</nowiki></code> to produce the same output as <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|main}}</nowiki></code>. Learning to think of functions as a data type becomes very important later on for working with library functions like <code>[[mw:Extension:Scribunto/Lua_reference_manual#string.gsub|mw.ustring.gsub]]</code>, and constructing iterator functions.
== Lua program structure: Input ==
The '''<code>frame</code>''' parameter above (which is pretty much always given this name in Wikipedia Lua modules) receives another table, which is passed ''from'' the page that makes the call ''to'' the Lua module. It contains a surprising amount of stuff, of which just a few things concern the novice.
=== Arguments ===
{{see also|Module:Arguments}}
<code>frame.args</code> contains ''another'' table, namely, all the content sent by the user within the <code>#invoke</code> brackets except the first argument which states the name of the function to be executed. So in {{Mlx|ConvertNumeric|decToHex|3377}}, the string <code>"3377"</code> is the content of <code>frame.args[1]</code> (which is the same as <code>frame["args"][1]</code> but ''not'' the same as <code>frame.args["1"]</code> or <code>frame["args"]["1"]</code>). Unnamed parameters come out with numbers as keys (<code>frame.args[1]</code>, <code>frame.args[2]</code>, etc.), while named parameters come out with the parameter names (strings) as keys (<code>frame.args["count"]</code>, <code>frame.args["style"]</code>, etc.).
''Example:''<blockquote><code><nowiki>{{#invoke:</nowiki>''modulename''|''functionname''<nowiki>|3377|4|count=3|style=bold}}</nowiki></code> </blockquote>results in<blockquote><code>frame.args[1]</code>=3377, <code>frame.args[2]</code>=4, <code>frame.args["count"]</code>=3, <code>frame.args["style"]</code>=<code>"bold"</code>.</blockquote>
=== Parent frame ===
Within <code>frame</code> there is a ''parent'' frame, referring to the page that called the page that gives the script, and you can pull out arguments from that also. Just write
<code>parent=frame.getParent(frame)</code>
and <code>parent.args</code> will contain those arguments.
It is popular in Lua to use the synonymous statement <code>parent=frame''':'''getParent()</code>, cancelling the need to write <code>frame</code> twice. Note the colon (<code>:</code>) instead of the dot (<code>.</code>). <code>parent=frame:getParent()</code> means exactly the same as <code>parent=frame.getParent(frame)</code>. For novices this can be confusing, and it is important to be aware of this idiom. If you use it in the wrong way, though, the script errors are pretty good at pointing out that this was the mistake.
== Basic debugging ==
{{Main|Help:Lua debugging}}
Debugging can start as soon as you write programs, and can be done simply with string concatenation.
Just set up a variable with some recognizable name like "debuglog" in your main function (p.main) with a statement like <syntaxhighlight lang="lua" inline>local debuglog=""</syntaxhighlight>. This initial {{code|""}} definition helps because otherwise it will be '''nil''' and concatenating a string to nil gets you an error. Now whenever you have a variable you'd like to test, say {{tt|x}}, just write <syntaxhighlight lang="lua" inline>debuglog = debuglog .. "x=" .. tostring(x)</syntaxhighlight>, and have at the end of your program <syntaxhighlight lang="lua" inline> return output .. debuglog</syntaxhighlight> The "{{tt|tostring}}" is a function to ensure {{tt|x}} is interpreted as a string, so that if it is an table, nil, etc. it will display as "{{samp|table}}", "{{samp|nil}}", etc. rather than as Script error.
== Format ==
The [[WP:Lua style guide]] gives some basic formatting suggestions expected by the JavaScript module editor, such as using four-space indentations and keeping if, then, else, end at the same level of indentation.
Comments to the end of a line are marked by {{code|--}} . ''Use them.'' Many modules for Wikipedia have a straightforward, linear design, but that doesn't mean it won't help to have your sections clearly labelled when you go back to the code for the hundredth time. The Lua style guide gives additional recommendations for using functions to keep your work more organized.
== Errors ==
Lua errors appear as red "Script error" messages. If Javascript is enabled, '''the <span style="color:#ff0000;">red</span> script error message is a link''' which usually allows you to follow it back to the line in the module where the error occurred. There are some exceptions, for example "Module not found", if the name of the module itself is mistyped, or "The function you specified did not exist" if the function name given is invalid.
=== Recurrent bugs ===
Some bugs you might want to keep in mind:
;Missing operator for concatenation
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=2 copy>
local debugLog = "" -- empty report string
debugLog = debugLog "missing double dot" -- append to the report
</syntaxhighlight></blockquote>
The following means you forgot the <code>..</code> between a string and a variable somewhere in a mess of stuff you're concatenating.
<blockquote><syntaxhighlight lang="lua" line start=9>
Lua error in console input at line 8: attempt to call local 'debugLog' (a string value).
</syntaxhighlight></blockquote>
;String expected, got function
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=3 copy>
local debugLog = "" -- empty report string
local res = mw.ustring.gmatch("Hello World!", "([aeiouAEIOU])") -- iterator of vowels
debugLog = debugLog..res -- populate the report with only strings
</syntaxhighlight></blockquote>
Some important things like <syntaxhighlight lang="lua" inline>mw.ustring.gmatch</syntaxhighlight> actually return ''functions'', not strings - see [[#Functions|Functions]] below.
<blockquote><syntaxhighlight lang="lua" line start=10>
Lua error in console input at line 9: attempt to concatenate local 'res' (a function value).
</syntaxhighlight></blockquote>
;Variable ignores assignment
A variable ignores all your efforts to assign stuff to it:
<blockquote><syntaxhighlight lang="lua" line highlight=1,3 copy>
local debugLog = "top level" -- initial value
do
local debugLog = "nested level" -- set the new value
print("Inside do: "..debugLog)
end
print("Outside do: "..debugLog) -- get the old value
</syntaxhighlight></blockquote>
You may have inadvertently written ''two'' local statements - the one sets the value of the variable within a limited region, and when the program leaves that region, you're back to the old value.
<blockquote><syntaxhighlight lang="lua" line start=7>
Inside do: nested level
Outside do: top level
</syntaxhighlight></blockquote>
A numbered table entry ignores all your efforts to assign to it:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local table = {}; local arg = "50"; local valPrm = tonumber(arg)
table[arg] = "index as string"
table[valPrm] = "index as number"
print(table[arg] == table[valPrm])
</syntaxhighlight></blockquote>
This is because {{code|table["50"]}} '''is not''' {{code|table[50]}}.<br/>
Typically you have processed a parameter (which you may have received from the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> as a string) with string functions in one place,<br>
but performed numeric operations in another, leaving you with two different types of variable to use for an index.
<blockquote><syntaxhighlight lang="lua" line start=5>
false
</syntaxhighlight></blockquote>
;<syntaxhighlight lang="lua" inline>nil</syntaxhighlight> and common pitfalls
There are all sorts of things you can't do with a local variable set to nil, such as: <syntaxhighlight lang="lua" inline>local x = nil</syntaxhighlight>, like:
# Assign <code>x.somefield</code>
# Get value at index {{code|x[idx]}}
# Concatenate <syntaxhighlight lang="lua" inline>x .. "Cannot concatenate with nil"</syntaxhighlight>
# Evaluate <syntaxhighlight lang="lua" inline>table[x]</syntaxhighlight>
Initialize such variables with: <syntaxhighlight lang="lua" inline>local x={}; local table = {}</syntaxhighlight><br>
Often "global" is mentioned in these errors because you didn't have a {{tt|local}} statement for the <syntaxhighlight lang="lua" inline>nil</syntaxhighlight> variable.
;Cannot invoke module
* ''no such module.'' You called <syntaxhighlight lang="lua" inline>#invoke:moduleNameUnknown</syntaxhighlight> that didn't exist or you wrongly kept the prefix <code>Module:</code> writing {{code|#invoke:Module:moduleName}}.
* ''the function specified did not exist.'' You called <syntaxhighlight lang="lua" inline>#invoke:moduleName|functionUnknown</syntaxhighlight>, but the field after the name of the module is wrong.<br>Often this field expects a standard name like "main", and you've forgotten it and gone straight to the first data parameter.<br>If you're unsure of the function name, check the module documentation, or look for what function(s) in the code accept a "frame" parameter.
;Graphics overflow issue
Some graphics you're trying to display are heading off to the hills: actually a HTML error.<br>
You didn't close one <syntaxhighlight lang="html" inline></div></syntaxhighlight>, so all the top: and left: styles keep adding up.
== Understanding tables and related concepts ==
* An '''expression list''' is a set of values separated by commas. The values can be strings, numbers, tables, functions, etc.
* A '''sequence''' is a set of entries with indices from 1 to N, where N is a positive integer. They can be created by placing brackets around an expression list.
For example:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local seq = {1, "quotation", mw.ustring.gmatch("abca","a"), {2,3,4}}
mw.logObject(seq) -- Scribunto tool to display a table
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
table#1 {
1,
"quotation",
function#1,
table#2 {
2,
3,
4,
},
}
</syntaxhighlight></blockquote>
# <code>seq[1]</code> = 1
# <code>seq[2]</code> = <syntaxhighlight lang="lua" inline>"quotation"</syntaxhighlight>
# <code>seq[3]</code> is the <syntaxhighlight lang="lua" inline>function</syntaxhighlight> returned by <code>gmatch()</code>
# <code>seq[4]</code> is the table <code>{2,3,4}</code>.
An expression list can also be recovered from a table using <syntaxhighlight lang="lua" inline>unpack()</syntaxhighlight>:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local seq = {1, "quotation", mw.ustring.gmatch("abca","a"), {2,3,4}}
local var1Nbr, var2Str, var3Fct = unpack(seq)
print(("var1Nbr = %d. var2Str = \"%s\". var3Fct = %s"):format(var1Nbr, var2Str, type(var3Fct)))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=4>
var1Nbr = 1. var2Str = "quotation". var3Fct = function
</syntaxhighlight></blockquote>
This will set:
# <code>var1Nbr</code> = 1
# <code>var2Str</code> = <syntaxhighlight lang="lua" inline>"quotation"</syntaxhighlight>
# <code>var3Fct</code> as the <syntaxhighlight lang="lua" inline>function</syntaxhighlight> returned by <code>gmatch()</code>
# <code>{2,3,4}</code> will be discarded in this case.
* A '''table''' is a sequence, optionally supplemented by named keys: <code>digit["two"]="2"</code>. Several table functions like <code>table.concat</code> will only work with the numbered values and ignore named keys.
* The '''metatable''' offers a large, optional set of methods for altering table behavior. For example, you can define a table to be callable like a function.
=== Initializing a table ===
It is often useful to create a whole table at once in a statement. There are many equivalent ways to do this, but the shortcuts don't work for every kind of value. To begin with, the most general way is to assign each key and value explicitly:
<syntaxhighlight lang="lua" inline>a = {[0]='zero', [1]='one', ['1']='string for one'}</syntaxhighlight>
If sequence keys (positive integers) are given in order, only the values need to be given, so the following will assign <syntaxhighlight lang="lua" inline>'one'</syntaxhighlight> to <syntaxhighlight lang="lua" inline>a[1]</syntaxhighlight>:
<syntaxhighlight lang="lua" inline>a = {[0]='zero', 'one', ['1']='string for one'}</syntaxhighlight>
If a key has only letters, digits, and underscores, and begins with a non-digit, the brackets and quotation marks can be omitted:
<syntaxhighlight lang="lua" inline>a = {a='one', b='two'}</syntaxhighlight>
This is identical to <syntaxhighlight lang="lua" inline>a = {["a"]='one', ["b"]='two'}</syntaxhighlight>.
However, this will fail for keys that begin with a digit: <syntaxhighlight lang="lua" inline>hex = {7f = 127}</syntaxhighlight> will produce an error; use <syntaxhighlight lang="lua" inline>hex = {['7f'] = 127}</syntaxhighlight> instead.
Note that when given ''within'' brackets, or to the right of the equal sign, quotation marks are needed, or else string values will be taken as variables:
<syntaxhighlight lang="lua" inline> a = {[b] = c}</syntaxhighlight>
assigns the value of variable ''c'' to the key ''contained in variable'' ''b''.
== Functions ==
* Functions can return any kind of value {{--}} ''including a function''. This is a powerful feature that can readily confuse the beginner. If you set <syntaxhighlight lang="lua" inline>a=mw.ustring.gmatch(text, "(.)")</syntaxhighlight>, the result assigned to <code>a</code> will be a '''function''', not a string character! However, assigning <code>b=a()</code> by calling the function stored in <code>a</code> will return the first match (a string). Every time you set <code>b=a()</code> after that you'll get another match (string) into <code>b</code>, until you run out of matches and get <code>nil</code>. Many '''iterator functions''' act this way.
* You can keep separate counts for iterator functions by using different variables. For example, if you set <syntaxhighlight lang="lua" inline>q=mw.ustring.gmatch(text, "(x.)")</syntaxhighlight> in the same module, you can pull characters from the same piece of text (<code>text</code>) by evaluating <code>d=q()</code> without losing your place in <code>a()</code>.
* [[tail call|Tail calls]] offer substantial benefits in performance for those who master the language.
* Function names are often of the form {{code|p.myFunctionName}}, where p is the table from the {{code|return p}} at the bottom of your program. The reason for this is that you can only access functions that are entries in this table from the original {{code|#invoke}} statement. Functions for local use within the program can have any name.
== Understanding patterns ==
''Note:'' Lua patterns are ''not'' [[regular expression|regular expressions]] in the traditional POSIX sense, and they are not even a subset of regular expressions. But they share many constructs with regular expressions (more [[Help:Lua for beginners#regex|below]]).
Lua patterns are used to define, find and handle a ''pattern'' in a string. It can do the common search and replace action in a text, but it has more options that doing plain text only. For example, in one go it can change the errors 'New yorker', 'New-Yorker', and 'NewYorker' into 'New Yorker'.
* To begin with, a pattern works like a plain string so long as it doesn't contain the special characters {{code|^ $ () % . [] * + - ?}}
* Square brackets {{code|[ ]}} are used to match ''one'' ''single character'' in the string from a list of choices. {{code|[abc]}} matches the letters a, b, or c. With {{code|^}} right after {{code|[}} they indicate "anything but": {{code|[^abc]}} = not a, b, or c. Inside brackets and when not the first character, a minus {{code|-}}indicates a range: {{code|[a-z]}} matches one single character from a, b, c, …, z.
* Period {{code|.}} matches any character.
* Percent {{code|%}} indicates a large set (class) of possible character matches when it is followed by a letter. See [https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Character_class] for a full list. <!--- should test/list these empirically to be sure ---> When followed by punctuation (whether a special character above or not) the {{code|%}} is removed and the punctuation is taken as a literal character; {{code|%%}} = literal %. Special classes include a balanced class {{code|%bxy}} and {{code|%f[set]}}; see the link above for more.
* Parentheses {{code|( )}} indicate captures. The captures can be accessed later in the search string or in the string.gsub replacement string as {{code|%1}} to {{code|%9}}, and are returned by string.match as an expression list of results.
* The qualifiers {{code|? - * +}} specify repetitions of a single character (not a longer string).
:* {{code|?}} means 0 or 1 repetitions: {{code|a?}} matches "a" or "".
:* {{code|-}} means 0 or more repetitions, choosing as few as possible to achieve a match ("non-greedy"). For example {{code|2=lua|string.match("bbbb", "(.-)")}} yields "", which is less than useful because there is nothing to root the ends of the expression and prevent it from matching zero characters.
:* {{code|*}} means 0 or more repetitions, choosing as many as possible ("greedy"). For example {{code|2=lua|string.match("bbbb", ".*")}} yields bbbb.
:* {{code|+}} means 1 or more repetitions, choosing as many as possible ("greedy").
Note that the greediness of the ''leftmost'' qualifier rules over all others when there is a choice: {{code|(.*)b(.*)}} when matched on "bbb" will return "bb", "", while {{code|a(.-)b(.-)a}} when matched on "abbba" will return "", "bb".
* {{code|^}} and {{code|$}} indicate the beginning and end of the string if they occur in the appropriate place in the pattern. Otherwise they are literal characters. {{code|^}} is not used in the {{code|string.gmatch}} function.
The reference manual for Lua patterns is at [[:mw:Extension:Scribunto/Lua_reference_manual#Patterns|mediawiki.org]].
== {{anchor|regex}}Note on Lua patterns versus regular expressions ==
Lua patterns are ''loosely based'' on [[regular expression]]s (sometimes shortened to regex or regexp). Lua patterns deliberately lack the most complex regular expression constructs (to avoid bloating the Lua code base), where many other computer languages or libraries use a more complete set. Lua patterns are not even a subset of regular expressions, as there are also discrepancies, like Lua using the escape character <code>%</code> instead of <code>\,</code>, and additions, like Lua providing <code>-</code> as a non-greedy version of <code>*</code>.
Here is a list of some of the things that Lua patterns lack compared to regular expressions:
* You '''cannot''' search for alternations between anything else than single characters (you '''cannot''' say <code>(his|her)</code> to choose between <code>his</code> and <code>her</code>, you can only say <code>[abc]</code> to choose between single characters <code>a</code>, <code>b</code>, or <code>c</code>).
* You '''cannot''' look for multiples of multi-letter constructs such as <code>(choo-)*choo</code> to match <code>choo</code>, <code>choo-choo</code> or <code>choo-choo-choo</code>. There is no way to do this with Lua patterns.
* You '''cannot''' specify the minimum and maximum number of repetitions like <code>[0-9]{3,5}</code> (to match 3 to 5 digits); in Lua you would say <code>%d%d%d%d?%d?</code> instead in this case.
There are Lua libraries that offer more powerful options,<sup>[http://lua-users.org/wiki/PatternsTutorial]</sup> including regular expressions, but the support on Wikipedia is pretty basic.
Wikipedia help for regular expressions (which Lua, as mentioned, does ''not'' support) is at [[Wikipedia:AutoWikiBrowser/Regular expression]].
{{Wikipedia technical help|collapsed}}
[[Category:Module help|*]]
padq9cq4gp4q161hpugili6as9r54db
790916
790915
2026-05-19T18:00:07Z
Nimmzo
78995
/* Basic debugging */ How to instrument a function with debugLog. Sample should not be pasted in Debug console but in an existing Module
790916
wikitext
text/x-wiki
{{WikiProject Lua header}}
{{Selfref|This help page is meant to provide some basic orientation for those new to Lua/Scribunto.}}
{{ඉංග්රීසි ව්යාපෘතියේ සිට ආයාත කළ පිටුව}}
== Overview ==
[[WP:Lua|Lua]] is a lightweight scripting language safely available on Wikipedia via [[mw:Extension:Scribunto|Scribunto]]. Its purpose is to allow you to process the data which is available on Wikipedia content pages to allow various sorts of customized display of information.
It runs in a sandboxed environment to protect the stability of Wikipedia while enabling powerful <syntaxhighlight lang="lua" inline>{{template}}</syntaxhighlight> and <syntaxhighlight lang="lua" inline>module:</syntaxhighlight> functionality.
The most important help file is the [[mw:Extension:Scribunto/Lua reference manual|MediaWiki Scribunto Lua reference manual]], which provides a concise summary of the language and standard library calls as implemented on MediaWiki.
The standard [http://www.lua.org/manual/5.1/manual.html Lua reference manual] is well written and comprehensive, but it can be confusing for beginners because some standard features don't work on wiki pages. You cannot call <syntaxhighlight lang="lua" inline>print("Hello, World!")</syntaxhighlight> in a module, but you can preview your User page showing the string <syntaxhighlight lang="lua" inline>"Hello World!"</syntaxhighlight> generated by the Lua [[Module:Example]]. Think of your Lua template as an HTML generator.
=== Generating "Hello World!" ===
You do not need to install or save anything.
# Edit your User page: <code>පරිශීලක:YourUserName</code>
# Paste the following call at the beginning of a new line on your User page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{#invoke:Example|hello}}
</syntaxhighlight></blockquote>
<ol start="3">
<li>Click <code>Preview</code>. The call of the function <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> in the [[Module:Example]] is replaced with the following:</li>
</ol>
<blockquote><syntaxhighlight lang="lua" line>
Hello World!
</syntaxhighlight></blockquote>
<ol start="4">
<li>Click <code>Cancel</code>. When prompted, click <code>Leave</code>.</li>
<li>Your User page remains '''un'''modified.</li>
</ol>
== Debug console: Start learning Lua ==
The Lua Scribunto <code>Debug Console</code> is a safe, interactive tool for learning Lua in Wikipedia.
# Click <code>Edit</code> on the [[Module:Yesno]] page.
# Scroll to the bottom of the page to the <code>Debug console</code> section beneath the Lua editor.
# Paste the comment and the call into the <span style="color:#86888c;">gray</span> input box (above the <code>Clear</code> button).
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
--[[ඔබගේ ආරම්භක Lua "හෙලෝ වර්ල්ඩ්" යන වගේම වැඩසටහන]]--
print("වෙල්කම් වෙයි " .. _VERSION .. "!") -- Lua අනුවාදය .. සමඟ එකතු කරයි
</syntaxhighlight></blockquote>
<ol start="4">
<li>Press {{key press|Enter}} once to execute the two Lua command''s''.</li>
<li>The result will appear below the Lua <syntaxhighlight lang="lua" inline>print</syntaxhighlight> command line:</li>
</ol>
<blockquote><syntaxhighlight lang="lua" line start=3>
වෙල්කම් වෙයි Lua 5.1!
</syntaxhighlight></blockquote>
<ol start="6">
<li>Press <code>Up arrow</code> (↑) to cycle through previous Lua commands.</li>
<li>Optionally, click <code>Clear</code> to clear ''only'' the <code>Debug Console</code>; the Lua editor above will remain '''un'''modified.</li>
</ol>
; HTML generator in the Debug console
Call the function <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> in <code>Module:</code>Example:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local modExample = require('Module:Example') -- load the module in Debug console
local frame = mw.getCurrentFrame(); print(modExample.hello(frame)) -- display "Hello World!"
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
Hello World!
</syntaxhighlight></blockquote>
; Identity function
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local yesno = require('Module:Yesno') -- #if yesno then returns its input parameter
print(mw.getCurrentFrame():callParserFunction("#if", yesno("Yes"), "Yes", 'නැහැ'))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
Yes
</syntaxhighlight></blockquote>
# Close the protected <code>Module:</code>Yesno that remains '''un'''modified.
== Issues with the current implementation ==
Besides the lack of <code>print()</code> in a module, there are other features missing – see [[mw:Extension:Scribunto/Lua reference manual#Differences from standard Lua|Differences from standard Lua]] for a complete list.
At the present time, it is advisable to use ''[[mw:Extension:Scribunto/Lua reference manual#Ustring library|mw.ustring]]'' functions instead of ''[[mw:Extension:Scribunto/Lua reference manual#String library|string]]'', because the latter sometimes fails with Unicode characters.
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local lang = mw.getCurrentFrame():callParserFunction("#language", "si") -- Sinhala
local lenUnicode, lenByte, lenSharp = mw.ustring.len(lang), string.len(lang), #lang
print(("lang: %s Mw.ustring.len = %d String.len = %d Sharp = %d"):format(lang, lenUnicode, lenByte, lenSharp))
</syntaxhighlight></blockquote>
Debug console supports Unicode:
<blockquote><syntaxhighlight lang="lua" line start=4>
lang: සිංහල Mw.ustring.len = 5 String.len = 15 Sharp = 15
</syntaxhighlight></blockquote>
== Input ==
The programs are run only when the page is "parsed" (when it or a page it incorporates is changed or previewed), not every time you view the output. Therefore there can be no convenient Lua module that allows you to type in a Fahrenheit temperature in an input box and get back the corresponding Celsius temperature when you press a button, or allows you to click on a segment of a Mandelbrot set visualization on a page to expand it as often as you like. There has to be an actual Wiki page (or at least a page you have submitted for preview) containing the input data.
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local function toCelsius(tempFahrenheit) return (tempFahrenheit - 32) * 5 / 9 end
print(("toCelsius(32°F) = %s°C. toCelsius(68°F) = %d°C"):format(toCelsius(32), toCelsius(68)))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
toCelsius(32°F) = 0°C. toCelsius(68°F) = 20°C
</syntaxhighlight></blockquote>
However, it is possible to use library functions like [[mw:Extension:Scribunto/Lua reference manual#mw.title.getCurrentTitle|mw.title.getCurrentTitle()]] to import content from any text content page on the Wiki.
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
print(mw.title.getCurrentTitle())
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=2>
Module:Yesno
</syntaxhighlight></blockquote>
You cannot, however, import data from files, not even .svg files which contain XML text data.
== Calling a Lua module ==
Lua calls look much like [[WP:template|template]]s, and consist of a small block of text.
In your User page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{ConvertNumeric|decToHex|73}}
</syntaxhighlight></blockquote>
Click <code>Preview</code> or click <code>Edit</code> this section to see the call then <code>Cancel</code>:
<blockquote>
{{#invoke:ConvertNumeric|decToHex|73}}
</blockquote>
This text calls the Lua script itself, which is housed in the <code>Module:</code> [[WP:namespace|namespace]]. The effect of this call is to send the information within the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> block to the Lua module, and to replace everything within the brackets with a piece of text that it sends back in return. (Literally, in the "return" statement)
Note that the first "parameter", in this case <code>decToHex</code>, is actually a <syntaxhighlight lang="lua" inline>function</syntaxhighlight> called within the Lua module. This field must always be included in any <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight>. To those unfamiliar with modules, especially Wikipedia template coders who expect anything after <code>|</code> to be a parameter, the need for this extra field is surprising, especially if all uses of the module depend on its presence.
In Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local convNum = require('Module:ConvertNumeric')
local frame = mw.getCurrentFrame(); frame.args[1] = "73" -- number always as string
print(("0x%s = %s = %d"):format(convNum.decToHex(frame), string.format("0x%X", 73), 0x49))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=4>
0x49 = 0x49 = 73
</syntaxhighlight></blockquote>
=== Documenting a Lua module ===
When documenting your module, it is useful to include an explicit usage instruction using [[සැකිල්ල:Module link expanded]]:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{mlx|ConvertNumeric|decToHex|73}}
</syntaxhighlight></blockquote>
Hyperlink to the module:
<blockquote>
{{mlx|ConvertNumeric|decToHex|73}}
</blockquote>
For many existing modules, an example <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> of the script (and little else) is provided on the <code>Module talk:</code> page. It is convenient for authors to be able to flip quickly to the talk tab to look at the effects of their changes, but you should never transclude the talk page as a template - people might actually talk on it! Alternatively, the module page can show documentation from a separate /doc-page (as [[Module:WikidataIB]] does).
=== Another example: Using LuaCall to perform a single Lua instruction ===
As a beginner, or in casual talk page conversation, you might only have one little calculation you want to use Lua for but don't want to write a full module. You might find [[Module:LuaCall]] convenient for this. For example, you can test how a greedy [https://www.lua.org/pil/20.1.html Lua pattern] works:
* <syntaxhighlight lang="lua" inline>{{#invoke:LuaCall|main|a=bbbbbbbbbba|b=bb(.*)b(.+)bba|string.match(a,b)}}</syntaxhighlight> → <code>{{#invoke:LuaCall|main|a=bbbbbbbbbba|b=bb(.*)b(.+)bba|string.match(a,b)}}</code>
or count up the length of a [[wikipedia:Did you know|''Did you know'']] hook or the text portion of a ''Did you know'' candidate:
* <syntaxhighlight lang="lua" inline>{{#invoke:LuaCall|main|a=... that you can count the length of your DYK hook with a Lua module?|string.len(a)}}</syntaxhighlight>→ <code>{{#invoke:LuaCall|main|a=... that you can count the length of your DYK hook with a Lua module?|string.len(a)}}</code>
In these specific examples, however, [[Module:String]] could do both of these tasks.
The script at [[Module:LuaCall]] has been written to accept any set of named parameters <code>somename=value</code>, for each one storing the string <code>value</code> in the variable with the name <code>somename</code>, and then allowing you to use these variables as parameters for any function available in Lua. The script then returns only the ''first'' value returned by the function ([https://www.lua.org/pil/5.1.html Lua functions can return multiple values], but in this case, only the first is returned from the module).
== Lua program structure: Output ==
The most fundamental part of a Wikipedia Lua program is a '''return''' statement which carries its output back to the page that had the <code>#invoke</code>. You ''can'' have a Lua function that runs without error even though it doesn't contain a return statement, but on Wikipedia it is pointless, as Lua programs cannot generally have side effects on Wikipedia.
The module itself must return a Lua '''table''' of values. A Lua table is expressed as a list of values separated by commas, within curly braces. When the module is called by <code>#invoke</code>, the '''function''' it names (the first argument after |) is looked for in that table. That function, in turn, is expected to return something that can be represented as a '''string'''.
Therefore, <syntaxhighlight lang="lua" inline>return { mw.ustring.gmatch( "Hello world", "(.*)" ) }</syntaxhighlight> is actually a complete Lua module (though a very strange one) - it returns the function returned by mw.ustring.gmatch (an iterator function listed in the Lua reference cited above) as the one and only element in an array (represented within <code>{}</code>)—which when executed using <syntaxhighlight lang="wikitext" inline>{{#invoke:ModuleName|1}}</syntaxhighlight> yields the string "Hello world". ''However'', things are not usually done this way. Typically we use the overall form:
<syntaxhighlight lang="lua">
local p = {} -- Defines a variable p as an empty table, but *not* nil.
function p.main( frame ) -- This block defines the table element p["main"] as a function.
return "Hello world" -- The string result of the function.
end -- Ends the block defining the function object p["main"] (or p.main).
return p -- This returns the table p, which under the key "main" contains the
-- function above (p.main), which when called returns string "Hello world".
</syntaxhighlight>
Note that <syntaxhighlight lang="lua" inline>function p.main(frame) ... end</syntaxhighlight> is equivalent to <syntaxhighlight lang="lua" inline>p.main = function(frame) ... end</syntaxhighlight> or <syntaxhighlight lang="lua" inline>p["main"] = function(frame) ... end</syntaxhighlight>. The function is just another type of value, retrieved with the key <code>"main"</code> from table <code>p</code>. If you want to allow users to invoke the same module with <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|hello}}</nowiki></code> instead of <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|main}}</nowiki></code>, you can write <code>p.hello = p.main</code> to copy the reference to this function to a new key in the table. You can even write <code>p[""] = p.main</code>, which causes <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|}}</nowiki></code> to produce the same output as <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|main}}</nowiki></code>. Learning to think of functions as a data type becomes very important later on for working with library functions like <code>[[mw:Extension:Scribunto/Lua_reference_manual#string.gsub|mw.ustring.gsub]]</code>, and constructing iterator functions.
== Lua program structure: Input ==
The '''<code>frame</code>''' parameter above (which is pretty much always given this name in Wikipedia Lua modules) receives another table, which is passed ''from'' the page that makes the call ''to'' the Lua module. It contains a surprising amount of stuff, of which just a few things concern the novice.
=== Arguments ===
{{see also|Module:Arguments}}
<code>frame.args</code> contains ''another'' table, namely, all the content sent by the user within the <code>#invoke</code> brackets except the first argument which states the name of the function to be executed. So in {{Mlx|ConvertNumeric|decToHex|3377}}, the string <code>"3377"</code> is the content of <code>frame.args[1]</code> (which is the same as <code>frame["args"][1]</code> but ''not'' the same as <code>frame.args["1"]</code> or <code>frame["args"]["1"]</code>). Unnamed parameters come out with numbers as keys (<code>frame.args[1]</code>, <code>frame.args[2]</code>, etc.), while named parameters come out with the parameter names (strings) as keys (<code>frame.args["count"]</code>, <code>frame.args["style"]</code>, etc.).
''Example:''<blockquote><code><nowiki>{{#invoke:</nowiki>''modulename''|''functionname''<nowiki>|3377|4|count=3|style=bold}}</nowiki></code> </blockquote>results in<blockquote><code>frame.args[1]</code>=3377, <code>frame.args[2]</code>=4, <code>frame.args["count"]</code>=3, <code>frame.args["style"]</code>=<code>"bold"</code>.</blockquote>
=== Parent frame ===
Within <code>frame</code> there is a ''parent'' frame, referring to the page that called the page that gives the script, and you can pull out arguments from that also. Just write
<code>parent=frame.getParent(frame)</code>
and <code>parent.args</code> will contain those arguments.
It is popular in Lua to use the synonymous statement <code>parent=frame''':'''getParent()</code>, cancelling the need to write <code>frame</code> twice. Note the colon (<code>:</code>) instead of the dot (<code>.</code>). <code>parent=frame:getParent()</code> means exactly the same as <code>parent=frame.getParent(frame)</code>. For novices this can be confusing, and it is important to be aware of this idiom. If you use it in the wrong way, though, the script errors are pretty good at pointing out that this was the mistake.
== Basic debugging ==
{{Main|Help:Lua debugging}}
Debugging can start as soon as you write programs, and can be done simply with string concatenation.<br/>
Just set up a variable with some recognizable name like <syntaxhighlight lang="lua" inline>debugLog</syntaxhighlight> in your main <syntaxhighlight lang="lua" inline>function p.main(frame)</syntaxhighlight> with a statement like:
<blockquote><syntaxhighlight lang="lua" line start=3 highlight=1 copy>
local debugLog = "" -- empty report string
</syntaxhighlight></blockquote>
This initial <syntaxhighlight lang="lua" inline>""</syntaxhighlight> definition helps because otherwise it will be <syntaxhighlight lang="lua" inline>nil</syntaxhighlight> and concatenating a string to nil gets you an error.<br/>
Now whenever you have a variable you'd like to test, say {{tt|myVar}}, just write:
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=2 copy>
local myVar = 42; local output = "expected result"
debugLog = debugLog .. " myVar = " .. tostring(myVar) -- append to the report
</syntaxhighlight></blockquote>
At the end of your function (but not the module), complete:
<blockquote><syntaxhighlight lang="lua" line start=16 highlight=1 copy>
return output .. debugLog -- Returns the expected result and the report
</syntaxhighlight></blockquote>
The <syntaxhighlight lang="lua" inline>tostring(myVar)</syntaxhighlight> is a function to ensure {{tt|myVar}} is interpreted as a string.<br>
For a table, it will display as "{{samp|table}}". For nil, "{{samp|nil}}" rather than as Script error.
== Format ==
The [[WP:Lua style guide]] gives some basic formatting suggestions expected by the JavaScript module editor, such as using four-space indentations and keeping if, then, else, end at the same level of indentation.
Comments to the end of a line are marked by {{code|--}} . ''Use them.'' Many modules for Wikipedia have a straightforward, linear design, but that doesn't mean it won't help to have your sections clearly labelled when you go back to the code for the hundredth time. The Lua style guide gives additional recommendations for using functions to keep your work more organized.
== Errors ==
Lua errors appear as red "Script error" messages. If Javascript is enabled, '''the <span style="color:#ff0000;">red</span> script error message is a link''' which usually allows you to follow it back to the line in the module where the error occurred. There are some exceptions, for example "Module not found", if the name of the module itself is mistyped, or "The function you specified did not exist" if the function name given is invalid.
=== Recurrent bugs ===
Some bugs you might want to keep in mind:
;Missing operator for concatenation
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=2 copy>
local debugLog = "" -- empty report string
debugLog = debugLog "missing double dot" -- append to the report
</syntaxhighlight></blockquote>
The following means you forgot the <code>..</code> between a string and a variable somewhere in a mess of stuff you're concatenating.
<blockquote><syntaxhighlight lang="lua" line start=9>
Lua error in console input at line 8: attempt to call local 'debugLog' (a string value).
</syntaxhighlight></blockquote>
;String expected, got function
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=3 copy>
local debugLog = "" -- empty report string
local res = mw.ustring.gmatch("Hello World!", "([aeiouAEIOU])") -- iterator of vowels
debugLog = debugLog..res -- populate the report with only strings
</syntaxhighlight></blockquote>
Some important things like <syntaxhighlight lang="lua" inline>mw.ustring.gmatch</syntaxhighlight> actually return ''functions'', not strings - see [[#Functions|Functions]] below.
<blockquote><syntaxhighlight lang="lua" line start=10>
Lua error in console input at line 9: attempt to concatenate local 'res' (a function value).
</syntaxhighlight></blockquote>
;Variable ignores assignment
A variable ignores all your efforts to assign stuff to it:
<blockquote><syntaxhighlight lang="lua" line highlight=1,3 copy>
local debugLog = "top level" -- initial value
do
local debugLog = "nested level" -- set the new value
print("Inside do: "..debugLog)
end
print("Outside do: "..debugLog) -- get the old value
</syntaxhighlight></blockquote>
You may have inadvertently written ''two'' local statements - the one sets the value of the variable within a limited region, and when the program leaves that region, you're back to the old value.
<blockquote><syntaxhighlight lang="lua" line start=7>
Inside do: nested level
Outside do: top level
</syntaxhighlight></blockquote>
A numbered table entry ignores all your efforts to assign to it:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local table = {}; local arg = "50"; local valPrm = tonumber(arg)
table[arg] = "index as string"
table[valPrm] = "index as number"
print(table[arg] == table[valPrm])
</syntaxhighlight></blockquote>
This is because {{code|table["50"]}} '''is not''' {{code|table[50]}}.<br/>
Typically you have processed a parameter (which you may have received from the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> as a string) with string functions in one place,<br>
but performed numeric operations in another, leaving you with two different types of variable to use for an index.
<blockquote><syntaxhighlight lang="lua" line start=5>
false
</syntaxhighlight></blockquote>
;<syntaxhighlight lang="lua" inline>nil</syntaxhighlight> and common pitfalls
There are all sorts of things you can't do with a local variable set to nil, such as: <syntaxhighlight lang="lua" inline>local x = nil</syntaxhighlight>, like:
# Assign <code>x.somefield</code>
# Get value at index {{code|x[idx]}}
# Concatenate <syntaxhighlight lang="lua" inline>x .. "Cannot concatenate with nil"</syntaxhighlight>
# Evaluate <syntaxhighlight lang="lua" inline>table[x]</syntaxhighlight>
Initialize such variables with: <syntaxhighlight lang="lua" inline>local x={}; local table = {}</syntaxhighlight><br>
Often "global" is mentioned in these errors because you didn't have a {{tt|local}} statement for the <syntaxhighlight lang="lua" inline>nil</syntaxhighlight> variable.
;Cannot invoke module
* ''no such module.'' You called <syntaxhighlight lang="lua" inline>#invoke:moduleNameUnknown</syntaxhighlight> that didn't exist or you wrongly kept the prefix <code>Module:</code> writing {{code|#invoke:Module:moduleName}}.
* ''the function specified did not exist.'' You called <syntaxhighlight lang="lua" inline>#invoke:moduleName|functionUnknown</syntaxhighlight>, but the field after the name of the module is wrong.<br>Often this field expects a standard name like "main", and you've forgotten it and gone straight to the first data parameter.<br>If you're unsure of the function name, check the module documentation, or look for what function(s) in the code accept a "frame" parameter.
;Graphics overflow issue
Some graphics you're trying to display are heading off to the hills: actually a HTML error.<br>
You didn't close one <syntaxhighlight lang="html" inline></div></syntaxhighlight>, so all the top: and left: styles keep adding up.
== Understanding tables and related concepts ==
* An '''expression list''' is a set of values separated by commas. The values can be strings, numbers, tables, functions, etc.
* A '''sequence''' is a set of entries with indices from 1 to N, where N is a positive integer. They can be created by placing brackets around an expression list.
For example:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local seq = {1, "quotation", mw.ustring.gmatch("abca","a"), {2,3,4}}
mw.logObject(seq) -- Scribunto tool to display a table
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
table#1 {
1,
"quotation",
function#1,
table#2 {
2,
3,
4,
},
}
</syntaxhighlight></blockquote>
# <code>seq[1]</code> = 1
# <code>seq[2]</code> = <syntaxhighlight lang="lua" inline>"quotation"</syntaxhighlight>
# <code>seq[3]</code> is the <syntaxhighlight lang="lua" inline>function</syntaxhighlight> returned by <code>gmatch()</code>
# <code>seq[4]</code> is the table <code>{2,3,4}</code>.
An expression list can also be recovered from a table using <syntaxhighlight lang="lua" inline>unpack()</syntaxhighlight>:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local seq = {1, "quotation", mw.ustring.gmatch("abca","a"), {2,3,4}}
local var1Nbr, var2Str, var3Fct = unpack(seq)
print(("var1Nbr = %d. var2Str = \"%s\". var3Fct = %s"):format(var1Nbr, var2Str, type(var3Fct)))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=4>
var1Nbr = 1. var2Str = "quotation". var3Fct = function
</syntaxhighlight></blockquote>
This will set:
# <code>var1Nbr</code> = 1
# <code>var2Str</code> = <syntaxhighlight lang="lua" inline>"quotation"</syntaxhighlight>
# <code>var3Fct</code> as the <syntaxhighlight lang="lua" inline>function</syntaxhighlight> returned by <code>gmatch()</code>
# <code>{2,3,4}</code> will be discarded in this case.
* A '''table''' is a sequence, optionally supplemented by named keys: <code>digit["two"]="2"</code>. Several table functions like <code>table.concat</code> will only work with the numbered values and ignore named keys.
* The '''metatable''' offers a large, optional set of methods for altering table behavior. For example, you can define a table to be callable like a function.
=== Initializing a table ===
It is often useful to create a whole table at once in a statement. There are many equivalent ways to do this, but the shortcuts don't work for every kind of value. To begin with, the most general way is to assign each key and value explicitly:
<syntaxhighlight lang="lua" inline>a = {[0]='zero', [1]='one', ['1']='string for one'}</syntaxhighlight>
If sequence keys (positive integers) are given in order, only the values need to be given, so the following will assign <syntaxhighlight lang="lua" inline>'one'</syntaxhighlight> to <syntaxhighlight lang="lua" inline>a[1]</syntaxhighlight>:
<syntaxhighlight lang="lua" inline>a = {[0]='zero', 'one', ['1']='string for one'}</syntaxhighlight>
If a key has only letters, digits, and underscores, and begins with a non-digit, the brackets and quotation marks can be omitted:
<syntaxhighlight lang="lua" inline>a = {a='one', b='two'}</syntaxhighlight>
This is identical to <syntaxhighlight lang="lua" inline>a = {["a"]='one', ["b"]='two'}</syntaxhighlight>.
However, this will fail for keys that begin with a digit: <syntaxhighlight lang="lua" inline>hex = {7f = 127}</syntaxhighlight> will produce an error; use <syntaxhighlight lang="lua" inline>hex = {['7f'] = 127}</syntaxhighlight> instead.
Note that when given ''within'' brackets, or to the right of the equal sign, quotation marks are needed, or else string values will be taken as variables:
<syntaxhighlight lang="lua" inline> a = {[b] = c}</syntaxhighlight>
assigns the value of variable ''c'' to the key ''contained in variable'' ''b''.
== Functions ==
* Functions can return any kind of value {{--}} ''including a function''. This is a powerful feature that can readily confuse the beginner. If you set <syntaxhighlight lang="lua" inline>a=mw.ustring.gmatch(text, "(.)")</syntaxhighlight>, the result assigned to <code>a</code> will be a '''function''', not a string character! However, assigning <code>b=a()</code> by calling the function stored in <code>a</code> will return the first match (a string). Every time you set <code>b=a()</code> after that you'll get another match (string) into <code>b</code>, until you run out of matches and get <code>nil</code>. Many '''iterator functions''' act this way.
* You can keep separate counts for iterator functions by using different variables. For example, if you set <syntaxhighlight lang="lua" inline>q=mw.ustring.gmatch(text, "(x.)")</syntaxhighlight> in the same module, you can pull characters from the same piece of text (<code>text</code>) by evaluating <code>d=q()</code> without losing your place in <code>a()</code>.
* [[tail call|Tail calls]] offer substantial benefits in performance for those who master the language.
* Function names are often of the form {{code|p.myFunctionName}}, where p is the table from the {{code|return p}} at the bottom of your program. The reason for this is that you can only access functions that are entries in this table from the original {{code|#invoke}} statement. Functions for local use within the program can have any name.
== Understanding patterns ==
''Note:'' Lua patterns are ''not'' [[regular expression|regular expressions]] in the traditional POSIX sense, and they are not even a subset of regular expressions. But they share many constructs with regular expressions (more [[Help:Lua for beginners#regex|below]]).
Lua patterns are used to define, find and handle a ''pattern'' in a string. It can do the common search and replace action in a text, but it has more options that doing plain text only. For example, in one go it can change the errors 'New yorker', 'New-Yorker', and 'NewYorker' into 'New Yorker'.
* To begin with, a pattern works like a plain string so long as it doesn't contain the special characters {{code|^ $ () % . [] * + - ?}}
* Square brackets {{code|[ ]}} are used to match ''one'' ''single character'' in the string from a list of choices. {{code|[abc]}} matches the letters a, b, or c. With {{code|^}} right after {{code|[}} they indicate "anything but": {{code|[^abc]}} = not a, b, or c. Inside brackets and when not the first character, a minus {{code|-}}indicates a range: {{code|[a-z]}} matches one single character from a, b, c, …, z.
* Period {{code|.}} matches any character.
* Percent {{code|%}} indicates a large set (class) of possible character matches when it is followed by a letter. See [https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Character_class] for a full list. <!--- should test/list these empirically to be sure ---> When followed by punctuation (whether a special character above or not) the {{code|%}} is removed and the punctuation is taken as a literal character; {{code|%%}} = literal %. Special classes include a balanced class {{code|%bxy}} and {{code|%f[set]}}; see the link above for more.
* Parentheses {{code|( )}} indicate captures. The captures can be accessed later in the search string or in the string.gsub replacement string as {{code|%1}} to {{code|%9}}, and are returned by string.match as an expression list of results.
* The qualifiers {{code|? - * +}} specify repetitions of a single character (not a longer string).
:* {{code|?}} means 0 or 1 repetitions: {{code|a?}} matches "a" or "".
:* {{code|-}} means 0 or more repetitions, choosing as few as possible to achieve a match ("non-greedy"). For example {{code|2=lua|string.match("bbbb", "(.-)")}} yields "", which is less than useful because there is nothing to root the ends of the expression and prevent it from matching zero characters.
:* {{code|*}} means 0 or more repetitions, choosing as many as possible ("greedy"). For example {{code|2=lua|string.match("bbbb", ".*")}} yields bbbb.
:* {{code|+}} means 1 or more repetitions, choosing as many as possible ("greedy").
Note that the greediness of the ''leftmost'' qualifier rules over all others when there is a choice: {{code|(.*)b(.*)}} when matched on "bbb" will return "bb", "", while {{code|a(.-)b(.-)a}} when matched on "abbba" will return "", "bb".
* {{code|^}} and {{code|$}} indicate the beginning and end of the string if they occur in the appropriate place in the pattern. Otherwise they are literal characters. {{code|^}} is not used in the {{code|string.gmatch}} function.
The reference manual for Lua patterns is at [[:mw:Extension:Scribunto/Lua_reference_manual#Patterns|mediawiki.org]].
== {{anchor|regex}}Note on Lua patterns versus regular expressions ==
Lua patterns are ''loosely based'' on [[regular expression]]s (sometimes shortened to regex or regexp). Lua patterns deliberately lack the most complex regular expression constructs (to avoid bloating the Lua code base), where many other computer languages or libraries use a more complete set. Lua patterns are not even a subset of regular expressions, as there are also discrepancies, like Lua using the escape character <code>%</code> instead of <code>\,</code>, and additions, like Lua providing <code>-</code> as a non-greedy version of <code>*</code>.
Here is a list of some of the things that Lua patterns lack compared to regular expressions:
* You '''cannot''' search for alternations between anything else than single characters (you '''cannot''' say <code>(his|her)</code> to choose between <code>his</code> and <code>her</code>, you can only say <code>[abc]</code> to choose between single characters <code>a</code>, <code>b</code>, or <code>c</code>).
* You '''cannot''' look for multiples of multi-letter constructs such as <code>(choo-)*choo</code> to match <code>choo</code>, <code>choo-choo</code> or <code>choo-choo-choo</code>. There is no way to do this with Lua patterns.
* You '''cannot''' specify the minimum and maximum number of repetitions like <code>[0-9]{3,5}</code> (to match 3 to 5 digits); in Lua you would say <code>%d%d%d%d?%d?</code> instead in this case.
There are Lua libraries that offer more powerful options,<sup>[http://lua-users.org/wiki/PatternsTutorial]</sup> including regular expressions, but the support on Wikipedia is pretty basic.
Wikipedia help for regular expressions (which Lua, as mentioned, does ''not'' support) is at [[Wikipedia:AutoWikiBrowser/Regular expression]].
{{Wikipedia technical help|collapsed}}
[[Category:Module help|*]]
n8mtoy57gpp98mb007mu4c8ybt9wlfm
790917
790916
2026-05-19T18:10:07Z
Nimmzo
78995
/* Parent frame */ getParent() is a more advanced function to retrieve arguments. Detect if a script is running from a Template or the Debug console
790917
wikitext
text/x-wiki
{{WikiProject Lua header}}
{{Selfref|This help page is meant to provide some basic orientation for those new to Lua/Scribunto.}}
{{ඉංග්රීසි ව්යාපෘතියේ සිට ආයාත කළ පිටුව}}
== Overview ==
[[WP:Lua|Lua]] is a lightweight scripting language safely available on Wikipedia via [[mw:Extension:Scribunto|Scribunto]]. Its purpose is to allow you to process the data which is available on Wikipedia content pages to allow various sorts of customized display of information.
It runs in a sandboxed environment to protect the stability of Wikipedia while enabling powerful <syntaxhighlight lang="lua" inline>{{template}}</syntaxhighlight> and <syntaxhighlight lang="lua" inline>module:</syntaxhighlight> functionality.
The most important help file is the [[mw:Extension:Scribunto/Lua reference manual|MediaWiki Scribunto Lua reference manual]], which provides a concise summary of the language and standard library calls as implemented on MediaWiki.
The standard [http://www.lua.org/manual/5.1/manual.html Lua reference manual] is well written and comprehensive, but it can be confusing for beginners because some standard features don't work on wiki pages. You cannot call <syntaxhighlight lang="lua" inline>print("Hello, World!")</syntaxhighlight> in a module, but you can preview your User page showing the string <syntaxhighlight lang="lua" inline>"Hello World!"</syntaxhighlight> generated by the Lua [[Module:Example]]. Think of your Lua template as an HTML generator.
=== Generating "Hello World!" ===
You do not need to install or save anything.
# Edit your User page: <code>පරිශීලක:YourUserName</code>
# Paste the following call at the beginning of a new line on your User page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{#invoke:Example|hello}}
</syntaxhighlight></blockquote>
<ol start="3">
<li>Click <code>Preview</code>. The call of the function <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> in the [[Module:Example]] is replaced with the following:</li>
</ol>
<blockquote><syntaxhighlight lang="lua" line>
Hello World!
</syntaxhighlight></blockquote>
<ol start="4">
<li>Click <code>Cancel</code>. When prompted, click <code>Leave</code>.</li>
<li>Your User page remains '''un'''modified.</li>
</ol>
== Debug console: Start learning Lua ==
The Lua Scribunto <code>Debug Console</code> is a safe, interactive tool for learning Lua in Wikipedia.
# Click <code>Edit</code> on the [[Module:Yesno]] page.
# Scroll to the bottom of the page to the <code>Debug console</code> section beneath the Lua editor.
# Paste the comment and the call into the <span style="color:#86888c;">gray</span> input box (above the <code>Clear</code> button).
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
--[[ඔබගේ ආරම්භක Lua "හෙලෝ වර්ල්ඩ්" යන වගේම වැඩසටහන]]--
print("වෙල්කම් වෙයි " .. _VERSION .. "!") -- Lua අනුවාදය .. සමඟ එකතු කරයි
</syntaxhighlight></blockquote>
<ol start="4">
<li>Press {{key press|Enter}} once to execute the two Lua command''s''.</li>
<li>The result will appear below the Lua <syntaxhighlight lang="lua" inline>print</syntaxhighlight> command line:</li>
</ol>
<blockquote><syntaxhighlight lang="lua" line start=3>
වෙල්කම් වෙයි Lua 5.1!
</syntaxhighlight></blockquote>
<ol start="6">
<li>Press <code>Up arrow</code> (↑) to cycle through previous Lua commands.</li>
<li>Optionally, click <code>Clear</code> to clear ''only'' the <code>Debug Console</code>; the Lua editor above will remain '''un'''modified.</li>
</ol>
; HTML generator in the Debug console
Call the function <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> in <code>Module:</code>Example:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local modExample = require('Module:Example') -- load the module in Debug console
local frame = mw.getCurrentFrame(); print(modExample.hello(frame)) -- display "Hello World!"
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
Hello World!
</syntaxhighlight></blockquote>
; Identity function
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local yesno = require('Module:Yesno') -- #if yesno then returns its input parameter
print(mw.getCurrentFrame():callParserFunction("#if", yesno("Yes"), "Yes", 'නැහැ'))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
Yes
</syntaxhighlight></blockquote>
# Close the protected <code>Module:</code>Yesno that remains '''un'''modified.
== Issues with the current implementation ==
Besides the lack of <code>print()</code> in a module, there are other features missing – see [[mw:Extension:Scribunto/Lua reference manual#Differences from standard Lua|Differences from standard Lua]] for a complete list.
At the present time, it is advisable to use ''[[mw:Extension:Scribunto/Lua reference manual#Ustring library|mw.ustring]]'' functions instead of ''[[mw:Extension:Scribunto/Lua reference manual#String library|string]]'', because the latter sometimes fails with Unicode characters.
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local lang = mw.getCurrentFrame():callParserFunction("#language", "si") -- Sinhala
local lenUnicode, lenByte, lenSharp = mw.ustring.len(lang), string.len(lang), #lang
print(("lang: %s Mw.ustring.len = %d String.len = %d Sharp = %d"):format(lang, lenUnicode, lenByte, lenSharp))
</syntaxhighlight></blockquote>
Debug console supports Unicode:
<blockquote><syntaxhighlight lang="lua" line start=4>
lang: සිංහල Mw.ustring.len = 5 String.len = 15 Sharp = 15
</syntaxhighlight></blockquote>
== Input ==
The programs are run only when the page is "parsed" (when it or a page it incorporates is changed or previewed), not every time you view the output. Therefore there can be no convenient Lua module that allows you to type in a Fahrenheit temperature in an input box and get back the corresponding Celsius temperature when you press a button, or allows you to click on a segment of a Mandelbrot set visualization on a page to expand it as often as you like. There has to be an actual Wiki page (or at least a page you have submitted for preview) containing the input data.
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local function toCelsius(tempFahrenheit) return (tempFahrenheit - 32) * 5 / 9 end
print(("toCelsius(32°F) = %s°C. toCelsius(68°F) = %d°C"):format(toCelsius(32), toCelsius(68)))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
toCelsius(32°F) = 0°C. toCelsius(68°F) = 20°C
</syntaxhighlight></blockquote>
However, it is possible to use library functions like [[mw:Extension:Scribunto/Lua reference manual#mw.title.getCurrentTitle|mw.title.getCurrentTitle()]] to import content from any text content page on the Wiki.
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
print(mw.title.getCurrentTitle())
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=2>
Module:Yesno
</syntaxhighlight></blockquote>
You cannot, however, import data from files, not even .svg files which contain XML text data.
== Calling a Lua module ==
Lua calls look much like [[WP:template|template]]s, and consist of a small block of text.
In your User page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{ConvertNumeric|decToHex|73}}
</syntaxhighlight></blockquote>
Click <code>Preview</code> or click <code>Edit</code> this section to see the call then <code>Cancel</code>:
<blockquote>
{{#invoke:ConvertNumeric|decToHex|73}}
</blockquote>
This text calls the Lua script itself, which is housed in the <code>Module:</code> [[WP:namespace|namespace]]. The effect of this call is to send the information within the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> block to the Lua module, and to replace everything within the brackets with a piece of text that it sends back in return. (Literally, in the "return" statement)
Note that the first "parameter", in this case <code>decToHex</code>, is actually a <syntaxhighlight lang="lua" inline>function</syntaxhighlight> called within the Lua module. This field must always be included in any <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight>. To those unfamiliar with modules, especially Wikipedia template coders who expect anything after <code>|</code> to be a parameter, the need for this extra field is surprising, especially if all uses of the module depend on its presence.
In Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local convNum = require('Module:ConvertNumeric')
local frame = mw.getCurrentFrame(); frame.args[1] = "73" -- number always as string
print(("0x%s = %s = %d"):format(convNum.decToHex(frame), string.format("0x%X", 73), 0x49))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=4>
0x49 = 0x49 = 73
</syntaxhighlight></blockquote>
=== Documenting a Lua module ===
When documenting your module, it is useful to include an explicit usage instruction using [[සැකිල්ල:Module link expanded]]:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{mlx|ConvertNumeric|decToHex|73}}
</syntaxhighlight></blockquote>
Hyperlink to the module:
<blockquote>
{{mlx|ConvertNumeric|decToHex|73}}
</blockquote>
For many existing modules, an example <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> of the script (and little else) is provided on the <code>Module talk:</code> page. It is convenient for authors to be able to flip quickly to the talk tab to look at the effects of their changes, but you should never transclude the talk page as a template - people might actually talk on it! Alternatively, the module page can show documentation from a separate /doc-page (as [[Module:WikidataIB]] does).
=== Another example: Using LuaCall to perform a single Lua instruction ===
As a beginner, or in casual talk page conversation, you might only have one little calculation you want to use Lua for but don't want to write a full module. You might find [[Module:LuaCall]] convenient for this. For example, you can test how a greedy [https://www.lua.org/pil/20.1.html Lua pattern] works:
* <syntaxhighlight lang="lua" inline>{{#invoke:LuaCall|main|a=bbbbbbbbbba|b=bb(.*)b(.+)bba|string.match(a,b)}}</syntaxhighlight> → <code>{{#invoke:LuaCall|main|a=bbbbbbbbbba|b=bb(.*)b(.+)bba|string.match(a,b)}}</code>
or count up the length of a [[wikipedia:Did you know|''Did you know'']] hook or the text portion of a ''Did you know'' candidate:
* <syntaxhighlight lang="lua" inline>{{#invoke:LuaCall|main|a=... that you can count the length of your DYK hook with a Lua module?|string.len(a)}}</syntaxhighlight>→ <code>{{#invoke:LuaCall|main|a=... that you can count the length of your DYK hook with a Lua module?|string.len(a)}}</code>
In these specific examples, however, [[Module:String]] could do both of these tasks.
The script at [[Module:LuaCall]] has been written to accept any set of named parameters <code>somename=value</code>, for each one storing the string <code>value</code> in the variable with the name <code>somename</code>, and then allowing you to use these variables as parameters for any function available in Lua. The script then returns only the ''first'' value returned by the function ([https://www.lua.org/pil/5.1.html Lua functions can return multiple values], but in this case, only the first is returned from the module).
== Lua program structure: Output ==
The most fundamental part of a Wikipedia Lua program is a '''return''' statement which carries its output back to the page that had the <code>#invoke</code>. You ''can'' have a Lua function that runs without error even though it doesn't contain a return statement, but on Wikipedia it is pointless, as Lua programs cannot generally have side effects on Wikipedia.
The module itself must return a Lua '''table''' of values. A Lua table is expressed as a list of values separated by commas, within curly braces. When the module is called by <code>#invoke</code>, the '''function''' it names (the first argument after |) is looked for in that table. That function, in turn, is expected to return something that can be represented as a '''string'''.
Therefore, <syntaxhighlight lang="lua" inline>return { mw.ustring.gmatch( "Hello world", "(.*)" ) }</syntaxhighlight> is actually a complete Lua module (though a very strange one) - it returns the function returned by mw.ustring.gmatch (an iterator function listed in the Lua reference cited above) as the one and only element in an array (represented within <code>{}</code>)—which when executed using <syntaxhighlight lang="wikitext" inline>{{#invoke:ModuleName|1}}</syntaxhighlight> yields the string "Hello world". ''However'', things are not usually done this way. Typically we use the overall form:
<syntaxhighlight lang="lua">
local p = {} -- Defines a variable p as an empty table, but *not* nil.
function p.main( frame ) -- This block defines the table element p["main"] as a function.
return "Hello world" -- The string result of the function.
end -- Ends the block defining the function object p["main"] (or p.main).
return p -- This returns the table p, which under the key "main" contains the
-- function above (p.main), which when called returns string "Hello world".
</syntaxhighlight>
Note that <syntaxhighlight lang="lua" inline>function p.main(frame) ... end</syntaxhighlight> is equivalent to <syntaxhighlight lang="lua" inline>p.main = function(frame) ... end</syntaxhighlight> or <syntaxhighlight lang="lua" inline>p["main"] = function(frame) ... end</syntaxhighlight>. The function is just another type of value, retrieved with the key <code>"main"</code> from table <code>p</code>. If you want to allow users to invoke the same module with <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|hello}}</nowiki></code> instead of <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|main}}</nowiki></code>, you can write <code>p.hello = p.main</code> to copy the reference to this function to a new key in the table. You can even write <code>p[""] = p.main</code>, which causes <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|}}</nowiki></code> to produce the same output as <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|main}}</nowiki></code>. Learning to think of functions as a data type becomes very important later on for working with library functions like <code>[[mw:Extension:Scribunto/Lua_reference_manual#string.gsub|mw.ustring.gsub]]</code>, and constructing iterator functions.
== Lua program structure: Input ==
The '''<code>frame</code>''' parameter above (which is pretty much always given this name in Wikipedia Lua modules) receives another table, which is passed ''from'' the page that makes the call ''to'' the Lua module. It contains a surprising amount of stuff, of which just a few things concern the novice.
=== Arguments ===
{{see also|Module:Arguments}}
<code>frame.args</code> contains ''another'' table, namely, all the content sent by the user within the <code>#invoke</code> brackets except the first argument which states the name of the function to be executed. So in {{Mlx|ConvertNumeric|decToHex|3377}}, the string <code>"3377"</code> is the content of <code>frame.args[1]</code> (which is the same as <code>frame["args"][1]</code> but ''not'' the same as <code>frame.args["1"]</code> or <code>frame["args"]["1"]</code>). Unnamed parameters come out with numbers as keys (<code>frame.args[1]</code>, <code>frame.args[2]</code>, etc.), while named parameters come out with the parameter names (strings) as keys (<code>frame.args["count"]</code>, <code>frame.args["style"]</code>, etc.).
''Example:''<blockquote><code><nowiki>{{#invoke:</nowiki>''modulename''|''functionname''<nowiki>|3377|4|count=3|style=bold}}</nowiki></code> </blockquote>results in<blockquote><code>frame.args[1]</code>=3377, <code>frame.args[2]</code>=4, <code>frame.args["count"]</code>=3, <code>frame.args["style"]</code>=<code>"bold"</code>.</blockquote>
=== Parent frame ===
Within <code>frame</code> there is a ''parent'' frame, referring to the page that called the page that gives the script, and you can pull out arguments from that also. Just write:
<blockquote><syntaxhighlight lang="lua" line highlight=17 copy>
--[[Return true if table-like `tab` contains any non-nil entries]]--
local function has_any_args(tab)
if tab == nil then return false end -- the table is nil
for _, val in pairs(tab) do -- Iterates both numeric (positional) and string (named) keys.
if val ~= nil then -- value not nil?
return true -- one argument exists
end
end
return false -- The table does not have any arguments
end
--[[Debug console or template in wiki page?]]--
local booksPlural = "There are those books."; local pluralMarker = "s."
local globalSub = "mw.ustring.gsub(subjectStr,pattern,replace)" -- no space separator
local prm = {subjectStr=booksPlural, pattern=pluralMarker, replace=".", globalSub, "lua"}
local frame = mw.getCurrentFrame():newChild{title='Module:Lua call', args=prm}
local parent = frame:getParent() or nil
if not parent or not has_any_args(parent.args) then
print("Running from Debug console")
print(mw.text.listToText(frame.args))
else
print("Running from wiki page invoking {{template}}")
end
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=24>
Running from Debug console
mw.ustring.gsub(subjectStr,pattern,replace)
</syntaxhighlight></blockquote>
<syntaxhighlight lang="lua" inline>parent.args</syntaxhighlight> will contain those arguments.
It is popular in Lua to use the synonymous statement <code>parent=frame''':'''getParent()</code>, cancelling the need to write <code>frame</code> twice.<br/>
Note the colon (<code>:</code>) instead of the dot (<code>.</code>).
<syntaxhighlight lang="lua" inline>parent = frame:getParent()</syntaxhighlight> means exactly the same as <code>parent = frame.getParent(frame)</code>.
For novices this can be confusing, and it is important to be aware of this idiom.<br/>
If you use it in the wrong way, though, the script errors are pretty good at pointing out that this was the mistake.
== Basic debugging ==
{{Main|Help:Lua debugging}}
Debugging can start as soon as you write programs, and can be done simply with string concatenation.<br/>
Just set up a variable with some recognizable name like <syntaxhighlight lang="lua" inline>debugLog</syntaxhighlight> in your main <syntaxhighlight lang="lua" inline>function p.main(frame)</syntaxhighlight> with a statement like:
<blockquote><syntaxhighlight lang="lua" line start=3 highlight=1 copy>
local debugLog = "" -- empty report string
</syntaxhighlight></blockquote>
This initial <syntaxhighlight lang="lua" inline>""</syntaxhighlight> definition helps because otherwise it will be <syntaxhighlight lang="lua" inline>nil</syntaxhighlight> and concatenating a string to nil gets you an error.<br/>
Now whenever you have a variable you'd like to test, say {{tt|myVar}}, just write:
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=2 copy>
local myVar = 42; local output = "expected result"
debugLog = debugLog .. " myVar = " .. tostring(myVar) -- append to the report
</syntaxhighlight></blockquote>
At the end of your function (but not the module), complete:
<blockquote><syntaxhighlight lang="lua" line start=16 highlight=1 copy>
return output .. debugLog -- Returns the expected result and the report
</syntaxhighlight></blockquote>
The <syntaxhighlight lang="lua" inline>tostring(myVar)</syntaxhighlight> is a function to ensure {{tt|myVar}} is interpreted as a string.<br>
For a table, it will display as "{{samp|table}}". For nil, "{{samp|nil}}" rather than as Script error.
== Format ==
The [[WP:Lua style guide]] gives some basic formatting suggestions expected by the JavaScript module editor, such as using four-space indentations and keeping if, then, else, end at the same level of indentation.
Comments to the end of a line are marked by {{code|--}} . ''Use them.'' Many modules for Wikipedia have a straightforward, linear design, but that doesn't mean it won't help to have your sections clearly labelled when you go back to the code for the hundredth time. The Lua style guide gives additional recommendations for using functions to keep your work more organized.
== Errors ==
Lua errors appear as red "Script error" messages. If Javascript is enabled, '''the <span style="color:#ff0000;">red</span> script error message is a link''' which usually allows you to follow it back to the line in the module where the error occurred. There are some exceptions, for example "Module not found", if the name of the module itself is mistyped, or "The function you specified did not exist" if the function name given is invalid.
=== Recurrent bugs ===
Some bugs you might want to keep in mind:
;Missing operator for concatenation
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=2 copy>
local debugLog = "" -- empty report string
debugLog = debugLog "missing double dot" -- append to the report
</syntaxhighlight></blockquote>
The following means you forgot the <code>..</code> between a string and a variable somewhere in a mess of stuff you're concatenating.
<blockquote><syntaxhighlight lang="lua" line start=9>
Lua error in console input at line 8: attempt to call local 'debugLog' (a string value).
</syntaxhighlight></blockquote>
;String expected, got function
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=3 copy>
local debugLog = "" -- empty report string
local res = mw.ustring.gmatch("Hello World!", "([aeiouAEIOU])") -- iterator of vowels
debugLog = debugLog..res -- populate the report with only strings
</syntaxhighlight></blockquote>
Some important things like <syntaxhighlight lang="lua" inline>mw.ustring.gmatch</syntaxhighlight> actually return ''functions'', not strings - see [[#Functions|Functions]] below.
<blockquote><syntaxhighlight lang="lua" line start=10>
Lua error in console input at line 9: attempt to concatenate local 'res' (a function value).
</syntaxhighlight></blockquote>
;Variable ignores assignment
A variable ignores all your efforts to assign stuff to it:
<blockquote><syntaxhighlight lang="lua" line highlight=1,3 copy>
local debugLog = "top level" -- initial value
do
local debugLog = "nested level" -- set the new value
print("Inside do: "..debugLog)
end
print("Outside do: "..debugLog) -- get the old value
</syntaxhighlight></blockquote>
You may have inadvertently written ''two'' local statements - the one sets the value of the variable within a limited region, and when the program leaves that region, you're back to the old value.
<blockquote><syntaxhighlight lang="lua" line start=7>
Inside do: nested level
Outside do: top level
</syntaxhighlight></blockquote>
A numbered table entry ignores all your efforts to assign to it:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local table = {}; local arg = "50"; local valPrm = tonumber(arg)
table[arg] = "index as string"
table[valPrm] = "index as number"
print(table[arg] == table[valPrm])
</syntaxhighlight></blockquote>
This is because {{code|table["50"]}} '''is not''' {{code|table[50]}}.<br/>
Typically you have processed a parameter (which you may have received from the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> as a string) with string functions in one place,<br>
but performed numeric operations in another, leaving you with two different types of variable to use for an index.
<blockquote><syntaxhighlight lang="lua" line start=5>
false
</syntaxhighlight></blockquote>
;<syntaxhighlight lang="lua" inline>nil</syntaxhighlight> and common pitfalls
There are all sorts of things you can't do with a local variable set to nil, such as: <syntaxhighlight lang="lua" inline>local x = nil</syntaxhighlight>, like:
# Assign <code>x.somefield</code>
# Get value at index {{code|x[idx]}}
# Concatenate <syntaxhighlight lang="lua" inline>x .. "Cannot concatenate with nil"</syntaxhighlight>
# Evaluate <syntaxhighlight lang="lua" inline>table[x]</syntaxhighlight>
Initialize such variables with: <syntaxhighlight lang="lua" inline>local x={}; local table = {}</syntaxhighlight><br>
Often "global" is mentioned in these errors because you didn't have a {{tt|local}} statement for the <syntaxhighlight lang="lua" inline>nil</syntaxhighlight> variable.
;Cannot invoke module
* ''no such module.'' You called <syntaxhighlight lang="lua" inline>#invoke:moduleNameUnknown</syntaxhighlight> that didn't exist or you wrongly kept the prefix <code>Module:</code> writing {{code|#invoke:Module:moduleName}}.
* ''the function specified did not exist.'' You called <syntaxhighlight lang="lua" inline>#invoke:moduleName|functionUnknown</syntaxhighlight>, but the field after the name of the module is wrong.<br>Often this field expects a standard name like "main", and you've forgotten it and gone straight to the first data parameter.<br>If you're unsure of the function name, check the module documentation, or look for what function(s) in the code accept a "frame" parameter.
;Graphics overflow issue
Some graphics you're trying to display are heading off to the hills: actually a HTML error.<br>
You didn't close one <syntaxhighlight lang="html" inline></div></syntaxhighlight>, so all the top: and left: styles keep adding up.
== Understanding tables and related concepts ==
* An '''expression list''' is a set of values separated by commas. The values can be strings, numbers, tables, functions, etc.
* A '''sequence''' is a set of entries with indices from 1 to N, where N is a positive integer. They can be created by placing brackets around an expression list.
For example:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local seq = {1, "quotation", mw.ustring.gmatch("abca","a"), {2,3,4}}
mw.logObject(seq) -- Scribunto tool to display a table
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
table#1 {
1,
"quotation",
function#1,
table#2 {
2,
3,
4,
},
}
</syntaxhighlight></blockquote>
# <code>seq[1]</code> = 1
# <code>seq[2]</code> = <syntaxhighlight lang="lua" inline>"quotation"</syntaxhighlight>
# <code>seq[3]</code> is the <syntaxhighlight lang="lua" inline>function</syntaxhighlight> returned by <code>gmatch()</code>
# <code>seq[4]</code> is the table <code>{2,3,4}</code>.
An expression list can also be recovered from a table using <syntaxhighlight lang="lua" inline>unpack()</syntaxhighlight>:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local seq = {1, "quotation", mw.ustring.gmatch("abca","a"), {2,3,4}}
local var1Nbr, var2Str, var3Fct = unpack(seq)
print(("var1Nbr = %d. var2Str = \"%s\". var3Fct = %s"):format(var1Nbr, var2Str, type(var3Fct)))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=4>
var1Nbr = 1. var2Str = "quotation". var3Fct = function
</syntaxhighlight></blockquote>
This will set:
# <code>var1Nbr</code> = 1
# <code>var2Str</code> = <syntaxhighlight lang="lua" inline>"quotation"</syntaxhighlight>
# <code>var3Fct</code> as the <syntaxhighlight lang="lua" inline>function</syntaxhighlight> returned by <code>gmatch()</code>
# <code>{2,3,4}</code> will be discarded in this case.
* A '''table''' is a sequence, optionally supplemented by named keys: <code>digit["two"]="2"</code>. Several table functions like <code>table.concat</code> will only work with the numbered values and ignore named keys.
* The '''metatable''' offers a large, optional set of methods for altering table behavior. For example, you can define a table to be callable like a function.
=== Initializing a table ===
It is often useful to create a whole table at once in a statement. There are many equivalent ways to do this, but the shortcuts don't work for every kind of value. To begin with, the most general way is to assign each key and value explicitly:
<syntaxhighlight lang="lua" inline>a = {[0]='zero', [1]='one', ['1']='string for one'}</syntaxhighlight>
If sequence keys (positive integers) are given in order, only the values need to be given, so the following will assign <syntaxhighlight lang="lua" inline>'one'</syntaxhighlight> to <syntaxhighlight lang="lua" inline>a[1]</syntaxhighlight>:
<syntaxhighlight lang="lua" inline>a = {[0]='zero', 'one', ['1']='string for one'}</syntaxhighlight>
If a key has only letters, digits, and underscores, and begins with a non-digit, the brackets and quotation marks can be omitted:
<syntaxhighlight lang="lua" inline>a = {a='one', b='two'}</syntaxhighlight>
This is identical to <syntaxhighlight lang="lua" inline>a = {["a"]='one', ["b"]='two'}</syntaxhighlight>.
However, this will fail for keys that begin with a digit: <syntaxhighlight lang="lua" inline>hex = {7f = 127}</syntaxhighlight> will produce an error; use <syntaxhighlight lang="lua" inline>hex = {['7f'] = 127}</syntaxhighlight> instead.
Note that when given ''within'' brackets, or to the right of the equal sign, quotation marks are needed, or else string values will be taken as variables:
<syntaxhighlight lang="lua" inline> a = {[b] = c}</syntaxhighlight>
assigns the value of variable ''c'' to the key ''contained in variable'' ''b''.
== Functions ==
* Functions can return any kind of value {{--}} ''including a function''. This is a powerful feature that can readily confuse the beginner. If you set <syntaxhighlight lang="lua" inline>a=mw.ustring.gmatch(text, "(.)")</syntaxhighlight>, the result assigned to <code>a</code> will be a '''function''', not a string character! However, assigning <code>b=a()</code> by calling the function stored in <code>a</code> will return the first match (a string). Every time you set <code>b=a()</code> after that you'll get another match (string) into <code>b</code>, until you run out of matches and get <code>nil</code>. Many '''iterator functions''' act this way.
* You can keep separate counts for iterator functions by using different variables. For example, if you set <syntaxhighlight lang="lua" inline>q=mw.ustring.gmatch(text, "(x.)")</syntaxhighlight> in the same module, you can pull characters from the same piece of text (<code>text</code>) by evaluating <code>d=q()</code> without losing your place in <code>a()</code>.
* [[tail call|Tail calls]] offer substantial benefits in performance for those who master the language.
* Function names are often of the form {{code|p.myFunctionName}}, where p is the table from the {{code|return p}} at the bottom of your program. The reason for this is that you can only access functions that are entries in this table from the original {{code|#invoke}} statement. Functions for local use within the program can have any name.
== Understanding patterns ==
''Note:'' Lua patterns are ''not'' [[regular expression|regular expressions]] in the traditional POSIX sense, and they are not even a subset of regular expressions. But they share many constructs with regular expressions (more [[Help:Lua for beginners#regex|below]]).
Lua patterns are used to define, find and handle a ''pattern'' in a string. It can do the common search and replace action in a text, but it has more options that doing plain text only. For example, in one go it can change the errors 'New yorker', 'New-Yorker', and 'NewYorker' into 'New Yorker'.
* To begin with, a pattern works like a plain string so long as it doesn't contain the special characters {{code|^ $ () % . [] * + - ?}}
* Square brackets {{code|[ ]}} are used to match ''one'' ''single character'' in the string from a list of choices. {{code|[abc]}} matches the letters a, b, or c. With {{code|^}} right after {{code|[}} they indicate "anything but": {{code|[^abc]}} = not a, b, or c. Inside brackets and when not the first character, a minus {{code|-}}indicates a range: {{code|[a-z]}} matches one single character from a, b, c, …, z.
* Period {{code|.}} matches any character.
* Percent {{code|%}} indicates a large set (class) of possible character matches when it is followed by a letter. See [https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Character_class] for a full list. <!--- should test/list these empirically to be sure ---> When followed by punctuation (whether a special character above or not) the {{code|%}} is removed and the punctuation is taken as a literal character; {{code|%%}} = literal %. Special classes include a balanced class {{code|%bxy}} and {{code|%f[set]}}; see the link above for more.
* Parentheses {{code|( )}} indicate captures. The captures can be accessed later in the search string or in the string.gsub replacement string as {{code|%1}} to {{code|%9}}, and are returned by string.match as an expression list of results.
* The qualifiers {{code|? - * +}} specify repetitions of a single character (not a longer string).
:* {{code|?}} means 0 or 1 repetitions: {{code|a?}} matches "a" or "".
:* {{code|-}} means 0 or more repetitions, choosing as few as possible to achieve a match ("non-greedy"). For example {{code|2=lua|string.match("bbbb", "(.-)")}} yields "", which is less than useful because there is nothing to root the ends of the expression and prevent it from matching zero characters.
:* {{code|*}} means 0 or more repetitions, choosing as many as possible ("greedy"). For example {{code|2=lua|string.match("bbbb", ".*")}} yields bbbb.
:* {{code|+}} means 1 or more repetitions, choosing as many as possible ("greedy").
Note that the greediness of the ''leftmost'' qualifier rules over all others when there is a choice: {{code|(.*)b(.*)}} when matched on "bbb" will return "bb", "", while {{code|a(.-)b(.-)a}} when matched on "abbba" will return "", "bb".
* {{code|^}} and {{code|$}} indicate the beginning and end of the string if they occur in the appropriate place in the pattern. Otherwise they are literal characters. {{code|^}} is not used in the {{code|string.gmatch}} function.
The reference manual for Lua patterns is at [[:mw:Extension:Scribunto/Lua_reference_manual#Patterns|mediawiki.org]].
== {{anchor|regex}}Note on Lua patterns versus regular expressions ==
Lua patterns are ''loosely based'' on [[regular expression]]s (sometimes shortened to regex or regexp). Lua patterns deliberately lack the most complex regular expression constructs (to avoid bloating the Lua code base), where many other computer languages or libraries use a more complete set. Lua patterns are not even a subset of regular expressions, as there are also discrepancies, like Lua using the escape character <code>%</code> instead of <code>\,</code>, and additions, like Lua providing <code>-</code> as a non-greedy version of <code>*</code>.
Here is a list of some of the things that Lua patterns lack compared to regular expressions:
* You '''cannot''' search for alternations between anything else than single characters (you '''cannot''' say <code>(his|her)</code> to choose between <code>his</code> and <code>her</code>, you can only say <code>[abc]</code> to choose between single characters <code>a</code>, <code>b</code>, or <code>c</code>).
* You '''cannot''' look for multiples of multi-letter constructs such as <code>(choo-)*choo</code> to match <code>choo</code>, <code>choo-choo</code> or <code>choo-choo-choo</code>. There is no way to do this with Lua patterns.
* You '''cannot''' specify the minimum and maximum number of repetitions like <code>[0-9]{3,5}</code> (to match 3 to 5 digits); in Lua you would say <code>%d%d%d%d?%d?</code> instead in this case.
There are Lua libraries that offer more powerful options,<sup>[http://lua-users.org/wiki/PatternsTutorial]</sup> including regular expressions, but the support on Wikipedia is pretty basic.
Wikipedia help for regular expressions (which Lua, as mentioned, does ''not'' support) is at [[Wikipedia:AutoWikiBrowser/Regular expression]].
{{Wikipedia technical help|collapsed}}
[[Category:Module help|*]]
5ha17o8mfjgg9977bm7ck6kk8a71xzb
790918
790917
2026-05-19T18:20:09Z
Nimmzo
78995
/* Format */ syntaxhighlight: +inline
790918
wikitext
text/x-wiki
{{WikiProject Lua header}}
{{Selfref|This help page is meant to provide some basic orientation for those new to Lua/Scribunto.}}
{{ඉංග්රීසි ව්යාපෘතියේ සිට ආයාත කළ පිටුව}}
== Overview ==
[[WP:Lua|Lua]] is a lightweight scripting language safely available on Wikipedia via [[mw:Extension:Scribunto|Scribunto]]. Its purpose is to allow you to process the data which is available on Wikipedia content pages to allow various sorts of customized display of information.
It runs in a sandboxed environment to protect the stability of Wikipedia while enabling powerful <syntaxhighlight lang="lua" inline>{{template}}</syntaxhighlight> and <syntaxhighlight lang="lua" inline>module:</syntaxhighlight> functionality.
The most important help file is the [[mw:Extension:Scribunto/Lua reference manual|MediaWiki Scribunto Lua reference manual]], which provides a concise summary of the language and standard library calls as implemented on MediaWiki.
The standard [http://www.lua.org/manual/5.1/manual.html Lua reference manual] is well written and comprehensive, but it can be confusing for beginners because some standard features don't work on wiki pages. You cannot call <syntaxhighlight lang="lua" inline>print("Hello, World!")</syntaxhighlight> in a module, but you can preview your User page showing the string <syntaxhighlight lang="lua" inline>"Hello World!"</syntaxhighlight> generated by the Lua [[Module:Example]]. Think of your Lua template as an HTML generator.
=== Generating "Hello World!" ===
You do not need to install or save anything.
# Edit your User page: <code>පරිශීලක:YourUserName</code>
# Paste the following call at the beginning of a new line on your User page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{#invoke:Example|hello}}
</syntaxhighlight></blockquote>
<ol start="3">
<li>Click <code>Preview</code>. The call of the function <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> in the [[Module:Example]] is replaced with the following:</li>
</ol>
<blockquote><syntaxhighlight lang="lua" line>
Hello World!
</syntaxhighlight></blockquote>
<ol start="4">
<li>Click <code>Cancel</code>. When prompted, click <code>Leave</code>.</li>
<li>Your User page remains '''un'''modified.</li>
</ol>
== Debug console: Start learning Lua ==
The Lua Scribunto <code>Debug Console</code> is a safe, interactive tool for learning Lua in Wikipedia.
# Click <code>Edit</code> on the [[Module:Yesno]] page.
# Scroll to the bottom of the page to the <code>Debug console</code> section beneath the Lua editor.
# Paste the comment and the call into the <span style="color:#86888c;">gray</span> input box (above the <code>Clear</code> button).
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
--[[ඔබගේ ආරම්භක Lua "හෙලෝ වර්ල්ඩ්" යන වගේම වැඩසටහන]]--
print("වෙල්කම් වෙයි " .. _VERSION .. "!") -- Lua අනුවාදය .. සමඟ එකතු කරයි
</syntaxhighlight></blockquote>
<ol start="4">
<li>Press {{key press|Enter}} once to execute the two Lua command''s''.</li>
<li>The result will appear below the Lua <syntaxhighlight lang="lua" inline>print</syntaxhighlight> command line:</li>
</ol>
<blockquote><syntaxhighlight lang="lua" line start=3>
වෙල්කම් වෙයි Lua 5.1!
</syntaxhighlight></blockquote>
<ol start="6">
<li>Press <code>Up arrow</code> (↑) to cycle through previous Lua commands.</li>
<li>Optionally, click <code>Clear</code> to clear ''only'' the <code>Debug Console</code>; the Lua editor above will remain '''un'''modified.</li>
</ol>
; HTML generator in the Debug console
Call the function <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> in <code>Module:</code>Example:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local modExample = require('Module:Example') -- load the module in Debug console
local frame = mw.getCurrentFrame(); print(modExample.hello(frame)) -- display "Hello World!"
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
Hello World!
</syntaxhighlight></blockquote>
; Identity function
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local yesno = require('Module:Yesno') -- #if yesno then returns its input parameter
print(mw.getCurrentFrame():callParserFunction("#if", yesno("Yes"), "Yes", 'නැහැ'))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
Yes
</syntaxhighlight></blockquote>
# Close the protected <code>Module:</code>Yesno that remains '''un'''modified.
== Issues with the current implementation ==
Besides the lack of <code>print()</code> in a module, there are other features missing – see [[mw:Extension:Scribunto/Lua reference manual#Differences from standard Lua|Differences from standard Lua]] for a complete list.
At the present time, it is advisable to use ''[[mw:Extension:Scribunto/Lua reference manual#Ustring library|mw.ustring]]'' functions instead of ''[[mw:Extension:Scribunto/Lua reference manual#String library|string]]'', because the latter sometimes fails with Unicode characters.
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local lang = mw.getCurrentFrame():callParserFunction("#language", "si") -- Sinhala
local lenUnicode, lenByte, lenSharp = mw.ustring.len(lang), string.len(lang), #lang
print(("lang: %s Mw.ustring.len = %d String.len = %d Sharp = %d"):format(lang, lenUnicode, lenByte, lenSharp))
</syntaxhighlight></blockquote>
Debug console supports Unicode:
<blockquote><syntaxhighlight lang="lua" line start=4>
lang: සිංහල Mw.ustring.len = 5 String.len = 15 Sharp = 15
</syntaxhighlight></blockquote>
== Input ==
The programs are run only when the page is "parsed" (when it or a page it incorporates is changed or previewed), not every time you view the output. Therefore there can be no convenient Lua module that allows you to type in a Fahrenheit temperature in an input box and get back the corresponding Celsius temperature when you press a button, or allows you to click on a segment of a Mandelbrot set visualization on a page to expand it as often as you like. There has to be an actual Wiki page (or at least a page you have submitted for preview) containing the input data.
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local function toCelsius(tempFahrenheit) return (tempFahrenheit - 32) * 5 / 9 end
print(("toCelsius(32°F) = %s°C. toCelsius(68°F) = %d°C"):format(toCelsius(32), toCelsius(68)))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
toCelsius(32°F) = 0°C. toCelsius(68°F) = 20°C
</syntaxhighlight></blockquote>
However, it is possible to use library functions like [[mw:Extension:Scribunto/Lua reference manual#mw.title.getCurrentTitle|mw.title.getCurrentTitle()]] to import content from any text content page on the Wiki.
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
print(mw.title.getCurrentTitle())
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=2>
Module:Yesno
</syntaxhighlight></blockquote>
You cannot, however, import data from files, not even .svg files which contain XML text data.
== Calling a Lua module ==
Lua calls look much like [[WP:template|template]]s, and consist of a small block of text.
In your User page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{ConvertNumeric|decToHex|73}}
</syntaxhighlight></blockquote>
Click <code>Preview</code> or click <code>Edit</code> this section to see the call then <code>Cancel</code>:
<blockquote>
{{#invoke:ConvertNumeric|decToHex|73}}
</blockquote>
This text calls the Lua script itself, which is housed in the <code>Module:</code> [[WP:namespace|namespace]]. The effect of this call is to send the information within the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> block to the Lua module, and to replace everything within the brackets with a piece of text that it sends back in return. (Literally, in the "return" statement)
Note that the first "parameter", in this case <code>decToHex</code>, is actually a <syntaxhighlight lang="lua" inline>function</syntaxhighlight> called within the Lua module. This field must always be included in any <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight>. To those unfamiliar with modules, especially Wikipedia template coders who expect anything after <code>|</code> to be a parameter, the need for this extra field is surprising, especially if all uses of the module depend on its presence.
In Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local convNum = require('Module:ConvertNumeric')
local frame = mw.getCurrentFrame(); frame.args[1] = "73" -- number always as string
print(("0x%s = %s = %d"):format(convNum.decToHex(frame), string.format("0x%X", 73), 0x49))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=4>
0x49 = 0x49 = 73
</syntaxhighlight></blockquote>
=== Documenting a Lua module ===
When documenting your module, it is useful to include an explicit usage instruction using [[සැකිල්ල:Module link expanded]]:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{mlx|ConvertNumeric|decToHex|73}}
</syntaxhighlight></blockquote>
Hyperlink to the module:
<blockquote>
{{mlx|ConvertNumeric|decToHex|73}}
</blockquote>
For many existing modules, an example <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> of the script (and little else) is provided on the <code>Module talk:</code> page. It is convenient for authors to be able to flip quickly to the talk tab to look at the effects of their changes, but you should never transclude the talk page as a template - people might actually talk on it! Alternatively, the module page can show documentation from a separate /doc-page (as [[Module:WikidataIB]] does).
=== Another example: Using LuaCall to perform a single Lua instruction ===
As a beginner, or in casual talk page conversation, you might only have one little calculation you want to use Lua for but don't want to write a full module. You might find [[Module:LuaCall]] convenient for this. For example, you can test how a greedy [https://www.lua.org/pil/20.1.html Lua pattern] works:
* <syntaxhighlight lang="lua" inline>{{#invoke:LuaCall|main|a=bbbbbbbbbba|b=bb(.*)b(.+)bba|string.match(a,b)}}</syntaxhighlight> → <code>{{#invoke:LuaCall|main|a=bbbbbbbbbba|b=bb(.*)b(.+)bba|string.match(a,b)}}</code>
or count up the length of a [[wikipedia:Did you know|''Did you know'']] hook or the text portion of a ''Did you know'' candidate:
* <syntaxhighlight lang="lua" inline>{{#invoke:LuaCall|main|a=... that you can count the length of your DYK hook with a Lua module?|string.len(a)}}</syntaxhighlight>→ <code>{{#invoke:LuaCall|main|a=... that you can count the length of your DYK hook with a Lua module?|string.len(a)}}</code>
In these specific examples, however, [[Module:String]] could do both of these tasks.
The script at [[Module:LuaCall]] has been written to accept any set of named parameters <code>somename=value</code>, for each one storing the string <code>value</code> in the variable with the name <code>somename</code>, and then allowing you to use these variables as parameters for any function available in Lua. The script then returns only the ''first'' value returned by the function ([https://www.lua.org/pil/5.1.html Lua functions can return multiple values], but in this case, only the first is returned from the module).
== Lua program structure: Output ==
The most fundamental part of a Wikipedia Lua program is a '''return''' statement which carries its output back to the page that had the <code>#invoke</code>. You ''can'' have a Lua function that runs without error even though it doesn't contain a return statement, but on Wikipedia it is pointless, as Lua programs cannot generally have side effects on Wikipedia.
The module itself must return a Lua '''table''' of values. A Lua table is expressed as a list of values separated by commas, within curly braces. When the module is called by <code>#invoke</code>, the '''function''' it names (the first argument after |) is looked for in that table. That function, in turn, is expected to return something that can be represented as a '''string'''.
Therefore, <syntaxhighlight lang="lua" inline>return { mw.ustring.gmatch( "Hello world", "(.*)" ) }</syntaxhighlight> is actually a complete Lua module (though a very strange one) - it returns the function returned by mw.ustring.gmatch (an iterator function listed in the Lua reference cited above) as the one and only element in an array (represented within <code>{}</code>)—which when executed using <syntaxhighlight lang="wikitext" inline>{{#invoke:ModuleName|1}}</syntaxhighlight> yields the string "Hello world". ''However'', things are not usually done this way. Typically we use the overall form:
<syntaxhighlight lang="lua">
local p = {} -- Defines a variable p as an empty table, but *not* nil.
function p.main( frame ) -- This block defines the table element p["main"] as a function.
return "Hello world" -- The string result of the function.
end -- Ends the block defining the function object p["main"] (or p.main).
return p -- This returns the table p, which under the key "main" contains the
-- function above (p.main), which when called returns string "Hello world".
</syntaxhighlight>
Note that <syntaxhighlight lang="lua" inline>function p.main(frame) ... end</syntaxhighlight> is equivalent to <syntaxhighlight lang="lua" inline>p.main = function(frame) ... end</syntaxhighlight> or <syntaxhighlight lang="lua" inline>p["main"] = function(frame) ... end</syntaxhighlight>. The function is just another type of value, retrieved with the key <code>"main"</code> from table <code>p</code>. If you want to allow users to invoke the same module with <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|hello}}</nowiki></code> instead of <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|main}}</nowiki></code>, you can write <code>p.hello = p.main</code> to copy the reference to this function to a new key in the table. You can even write <code>p[""] = p.main</code>, which causes <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|}}</nowiki></code> to produce the same output as <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|main}}</nowiki></code>. Learning to think of functions as a data type becomes very important later on for working with library functions like <code>[[mw:Extension:Scribunto/Lua_reference_manual#string.gsub|mw.ustring.gsub]]</code>, and constructing iterator functions.
== Lua program structure: Input ==
The '''<code>frame</code>''' parameter above (which is pretty much always given this name in Wikipedia Lua modules) receives another table, which is passed ''from'' the page that makes the call ''to'' the Lua module. It contains a surprising amount of stuff, of which just a few things concern the novice.
=== Arguments ===
{{see also|Module:Arguments}}
<code>frame.args</code> contains ''another'' table, namely, all the content sent by the user within the <code>#invoke</code> brackets except the first argument which states the name of the function to be executed. So in {{Mlx|ConvertNumeric|decToHex|3377}}, the string <code>"3377"</code> is the content of <code>frame.args[1]</code> (which is the same as <code>frame["args"][1]</code> but ''not'' the same as <code>frame.args["1"]</code> or <code>frame["args"]["1"]</code>). Unnamed parameters come out with numbers as keys (<code>frame.args[1]</code>, <code>frame.args[2]</code>, etc.), while named parameters come out with the parameter names (strings) as keys (<code>frame.args["count"]</code>, <code>frame.args["style"]</code>, etc.).
''Example:''<blockquote><code><nowiki>{{#invoke:</nowiki>''modulename''|''functionname''<nowiki>|3377|4|count=3|style=bold}}</nowiki></code> </blockquote>results in<blockquote><code>frame.args[1]</code>=3377, <code>frame.args[2]</code>=4, <code>frame.args["count"]</code>=3, <code>frame.args["style"]</code>=<code>"bold"</code>.</blockquote>
=== Parent frame ===
Within <code>frame</code> there is a ''parent'' frame, referring to the page that called the page that gives the script, and you can pull out arguments from that also. Just write:
<blockquote><syntaxhighlight lang="lua" line highlight=17 copy>
--[[Return true if table-like `tab` contains any non-nil entries]]--
local function has_any_args(tab)
if tab == nil then return false end -- the table is nil
for _, val in pairs(tab) do -- Iterates both numeric (positional) and string (named) keys.
if val ~= nil then -- value not nil?
return true -- one argument exists
end
end
return false -- The table does not have any arguments
end
--[[Debug console or template in wiki page?]]--
local booksPlural = "There are those books."; local pluralMarker = "s."
local globalSub = "mw.ustring.gsub(subjectStr,pattern,replace)" -- no space separator
local prm = {subjectStr=booksPlural, pattern=pluralMarker, replace=".", globalSub, "lua"}
local frame = mw.getCurrentFrame():newChild{title='Module:Lua call', args=prm}
local parent = frame:getParent() or nil
if not parent or not has_any_args(parent.args) then
print("Running from Debug console")
print(mw.text.listToText(frame.args))
else
print("Running from wiki page invoking {{template}}")
end
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=24>
Running from Debug console
mw.ustring.gsub(subjectStr,pattern,replace)
</syntaxhighlight></blockquote>
<syntaxhighlight lang="lua" inline>parent.args</syntaxhighlight> will contain those arguments.
It is popular in Lua to use the synonymous statement <code>parent=frame''':'''getParent()</code>, cancelling the need to write <code>frame</code> twice.<br/>
Note the colon (<code>:</code>) instead of the dot (<code>.</code>).
<syntaxhighlight lang="lua" inline>parent = frame:getParent()</syntaxhighlight> means exactly the same as <code>parent = frame.getParent(frame)</code>.
For novices this can be confusing, and it is important to be aware of this idiom.<br/>
If you use it in the wrong way, though, the script errors are pretty good at pointing out that this was the mistake.
== Basic debugging ==
{{Main|Help:Lua debugging}}
Debugging can start as soon as you write programs, and can be done simply with string concatenation.<br/>
Just set up a variable with some recognizable name like <syntaxhighlight lang="lua" inline>debugLog</syntaxhighlight> in your main <syntaxhighlight lang="lua" inline>function p.main(frame)</syntaxhighlight> with a statement like:
<blockquote><syntaxhighlight lang="lua" line start=3 highlight=1 copy>
local debugLog = "" -- empty report string
</syntaxhighlight></blockquote>
This initial <syntaxhighlight lang="lua" inline>""</syntaxhighlight> definition helps because otherwise it will be <syntaxhighlight lang="lua" inline>nil</syntaxhighlight> and concatenating a string to nil gets you an error.<br/>
Now whenever you have a variable you'd like to test, say {{tt|myVar}}, just write:
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=2 copy>
local myVar = 42; local output = "expected result"
debugLog = debugLog .. " myVar = " .. tostring(myVar) -- append to the report
</syntaxhighlight></blockquote>
At the end of your function (but not the module), complete:
<blockquote><syntaxhighlight lang="lua" line start=16 highlight=1 copy>
return output .. debugLog -- Returns the expected result and the report
</syntaxhighlight></blockquote>
The <syntaxhighlight lang="lua" inline>tostring(myVar)</syntaxhighlight> is a function to ensure {{tt|myVar}} is interpreted as a string.<br>
For a table, it will display as "{{samp|table}}". For nil, "{{samp|nil}}" rather than as Script error.
== Format ==
The [[WP:Lua style guide]] gives some basic formatting suggestions expected by the JavaScript module editor, such as using four-space indentations and keeping <syntaxhighlight lang="lua" inline>if then else</syntaxhighlight>, <syntaxhighlight lang="lua" inline>end</syntaxhighlight> at the same level of indentation.
Comments to the end of a line are marked by <syntaxhighlight lang="lua" inline>-- green comment</syntaxhighlight>. ''Use them.''
Many modules for Wikipedia have a straightforward, linear design, but that doesn't mean it won't help to have your sections clearly labelled when you go back to the code for the hundredth time. The Lua style guide gives additional recommendations for using functions to keep your work more organized.
== Errors ==
Lua errors appear as red "Script error" messages. If Javascript is enabled, '''the <span style="color:#ff0000;">red</span> script error message is a link''' which usually allows you to follow it back to the line in the module where the error occurred. There are some exceptions, for example "Module not found", if the name of the module itself is mistyped, or "The function you specified did not exist" if the function name given is invalid.
=== Recurrent bugs ===
Some bugs you might want to keep in mind:
;Missing operator for concatenation
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=2 copy>
local debugLog = "" -- empty report string
debugLog = debugLog "missing double dot" -- append to the report
</syntaxhighlight></blockquote>
The following means you forgot the <code>..</code> between a string and a variable somewhere in a mess of stuff you're concatenating.
<blockquote><syntaxhighlight lang="lua" line start=9>
Lua error in console input at line 8: attempt to call local 'debugLog' (a string value).
</syntaxhighlight></blockquote>
;String expected, got function
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=3 copy>
local debugLog = "" -- empty report string
local res = mw.ustring.gmatch("Hello World!", "([aeiouAEIOU])") -- iterator of vowels
debugLog = debugLog..res -- populate the report with only strings
</syntaxhighlight></blockquote>
Some important things like <syntaxhighlight lang="lua" inline>mw.ustring.gmatch</syntaxhighlight> actually return ''functions'', not strings - see [[#Functions|Functions]] below.
<blockquote><syntaxhighlight lang="lua" line start=10>
Lua error in console input at line 9: attempt to concatenate local 'res' (a function value).
</syntaxhighlight></blockquote>
;Variable ignores assignment
A variable ignores all your efforts to assign stuff to it:
<blockquote><syntaxhighlight lang="lua" line highlight=1,3 copy>
local debugLog = "top level" -- initial value
do
local debugLog = "nested level" -- set the new value
print("Inside do: "..debugLog)
end
print("Outside do: "..debugLog) -- get the old value
</syntaxhighlight></blockquote>
You may have inadvertently written ''two'' local statements - the one sets the value of the variable within a limited region, and when the program leaves that region, you're back to the old value.
<blockquote><syntaxhighlight lang="lua" line start=7>
Inside do: nested level
Outside do: top level
</syntaxhighlight></blockquote>
A numbered table entry ignores all your efforts to assign to it:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local table = {}; local arg = "50"; local valPrm = tonumber(arg)
table[arg] = "index as string"
table[valPrm] = "index as number"
print(table[arg] == table[valPrm])
</syntaxhighlight></blockquote>
This is because {{code|table["50"]}} '''is not''' {{code|table[50]}}.<br/>
Typically you have processed a parameter (which you may have received from the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> as a string) with string functions in one place,<br>
but performed numeric operations in another, leaving you with two different types of variable to use for an index.
<blockquote><syntaxhighlight lang="lua" line start=5>
false
</syntaxhighlight></blockquote>
;<syntaxhighlight lang="lua" inline>nil</syntaxhighlight> and common pitfalls
There are all sorts of things you can't do with a local variable set to nil, such as: <syntaxhighlight lang="lua" inline>local x = nil</syntaxhighlight>, like:
# Assign <code>x.somefield</code>
# Get value at index {{code|x[idx]}}
# Concatenate <syntaxhighlight lang="lua" inline>x .. "Cannot concatenate with nil"</syntaxhighlight>
# Evaluate <syntaxhighlight lang="lua" inline>table[x]</syntaxhighlight>
Initialize such variables with: <syntaxhighlight lang="lua" inline>local x={}; local table = {}</syntaxhighlight><br>
Often "global" is mentioned in these errors because you didn't have a {{tt|local}} statement for the <syntaxhighlight lang="lua" inline>nil</syntaxhighlight> variable.
;Cannot invoke module
* ''no such module.'' You called <syntaxhighlight lang="lua" inline>#invoke:moduleNameUnknown</syntaxhighlight> that didn't exist or you wrongly kept the prefix <code>Module:</code> writing {{code|#invoke:Module:moduleName}}.
* ''the function specified did not exist.'' You called <syntaxhighlight lang="lua" inline>#invoke:moduleName|functionUnknown</syntaxhighlight>, but the field after the name of the module is wrong.<br>Often this field expects a standard name like "main", and you've forgotten it and gone straight to the first data parameter.<br>If you're unsure of the function name, check the module documentation, or look for what function(s) in the code accept a "frame" parameter.
;Graphics overflow issue
Some graphics you're trying to display are heading off to the hills: actually a HTML error.<br>
You didn't close one <syntaxhighlight lang="html" inline></div></syntaxhighlight>, so all the top: and left: styles keep adding up.
== Understanding tables and related concepts ==
* An '''expression list''' is a set of values separated by commas. The values can be strings, numbers, tables, functions, etc.
* A '''sequence''' is a set of entries with indices from 1 to N, where N is a positive integer. They can be created by placing brackets around an expression list.
For example:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local seq = {1, "quotation", mw.ustring.gmatch("abca","a"), {2,3,4}}
mw.logObject(seq) -- Scribunto tool to display a table
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
table#1 {
1,
"quotation",
function#1,
table#2 {
2,
3,
4,
},
}
</syntaxhighlight></blockquote>
# <code>seq[1]</code> = 1
# <code>seq[2]</code> = <syntaxhighlight lang="lua" inline>"quotation"</syntaxhighlight>
# <code>seq[3]</code> is the <syntaxhighlight lang="lua" inline>function</syntaxhighlight> returned by <code>gmatch()</code>
# <code>seq[4]</code> is the table <code>{2,3,4}</code>.
An expression list can also be recovered from a table using <syntaxhighlight lang="lua" inline>unpack()</syntaxhighlight>:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local seq = {1, "quotation", mw.ustring.gmatch("abca","a"), {2,3,4}}
local var1Nbr, var2Str, var3Fct = unpack(seq)
print(("var1Nbr = %d. var2Str = \"%s\". var3Fct = %s"):format(var1Nbr, var2Str, type(var3Fct)))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=4>
var1Nbr = 1. var2Str = "quotation". var3Fct = function
</syntaxhighlight></blockquote>
This will set:
# <code>var1Nbr</code> = 1
# <code>var2Str</code> = <syntaxhighlight lang="lua" inline>"quotation"</syntaxhighlight>
# <code>var3Fct</code> as the <syntaxhighlight lang="lua" inline>function</syntaxhighlight> returned by <code>gmatch()</code>
# <code>{2,3,4}</code> will be discarded in this case.
* A '''table''' is a sequence, optionally supplemented by named keys: <code>digit["two"]="2"</code>. Several table functions like <code>table.concat</code> will only work with the numbered values and ignore named keys.
* The '''metatable''' offers a large, optional set of methods for altering table behavior. For example, you can define a table to be callable like a function.
=== Initializing a table ===
It is often useful to create a whole table at once in a statement. There are many equivalent ways to do this, but the shortcuts don't work for every kind of value. To begin with, the most general way is to assign each key and value explicitly:
<syntaxhighlight lang="lua" inline>a = {[0]='zero', [1]='one', ['1']='string for one'}</syntaxhighlight>
If sequence keys (positive integers) are given in order, only the values need to be given, so the following will assign <syntaxhighlight lang="lua" inline>'one'</syntaxhighlight> to <syntaxhighlight lang="lua" inline>a[1]</syntaxhighlight>:
<syntaxhighlight lang="lua" inline>a = {[0]='zero', 'one', ['1']='string for one'}</syntaxhighlight>
If a key has only letters, digits, and underscores, and begins with a non-digit, the brackets and quotation marks can be omitted:
<syntaxhighlight lang="lua" inline>a = {a='one', b='two'}</syntaxhighlight>
This is identical to <syntaxhighlight lang="lua" inline>a = {["a"]='one', ["b"]='two'}</syntaxhighlight>.
However, this will fail for keys that begin with a digit: <syntaxhighlight lang="lua" inline>hex = {7f = 127}</syntaxhighlight> will produce an error; use <syntaxhighlight lang="lua" inline>hex = {['7f'] = 127}</syntaxhighlight> instead.
Note that when given ''within'' brackets, or to the right of the equal sign, quotation marks are needed, or else string values will be taken as variables:
<syntaxhighlight lang="lua" inline> a = {[b] = c}</syntaxhighlight>
assigns the value of variable ''c'' to the key ''contained in variable'' ''b''.
== Functions ==
* Functions can return any kind of value {{--}} ''including a function''. This is a powerful feature that can readily confuse the beginner. If you set <syntaxhighlight lang="lua" inline>a=mw.ustring.gmatch(text, "(.)")</syntaxhighlight>, the result assigned to <code>a</code> will be a '''function''', not a string character! However, assigning <code>b=a()</code> by calling the function stored in <code>a</code> will return the first match (a string). Every time you set <code>b=a()</code> after that you'll get another match (string) into <code>b</code>, until you run out of matches and get <code>nil</code>. Many '''iterator functions''' act this way.
* You can keep separate counts for iterator functions by using different variables. For example, if you set <syntaxhighlight lang="lua" inline>q=mw.ustring.gmatch(text, "(x.)")</syntaxhighlight> in the same module, you can pull characters from the same piece of text (<code>text</code>) by evaluating <code>d=q()</code> without losing your place in <code>a()</code>.
* [[tail call|Tail calls]] offer substantial benefits in performance for those who master the language.
* Function names are often of the form {{code|p.myFunctionName}}, where p is the table from the {{code|return p}} at the bottom of your program. The reason for this is that you can only access functions that are entries in this table from the original {{code|#invoke}} statement. Functions for local use within the program can have any name.
== Understanding patterns ==
''Note:'' Lua patterns are ''not'' [[regular expression|regular expressions]] in the traditional POSIX sense, and they are not even a subset of regular expressions. But they share many constructs with regular expressions (more [[Help:Lua for beginners#regex|below]]).
Lua patterns are used to define, find and handle a ''pattern'' in a string. It can do the common search and replace action in a text, but it has more options that doing plain text only. For example, in one go it can change the errors 'New yorker', 'New-Yorker', and 'NewYorker' into 'New Yorker'.
* To begin with, a pattern works like a plain string so long as it doesn't contain the special characters {{code|^ $ () % . [] * + - ?}}
* Square brackets {{code|[ ]}} are used to match ''one'' ''single character'' in the string from a list of choices. {{code|[abc]}} matches the letters a, b, or c. With {{code|^}} right after {{code|[}} they indicate "anything but": {{code|[^abc]}} = not a, b, or c. Inside brackets and when not the first character, a minus {{code|-}}indicates a range: {{code|[a-z]}} matches one single character from a, b, c, …, z.
* Period {{code|.}} matches any character.
* Percent {{code|%}} indicates a large set (class) of possible character matches when it is followed by a letter. See [https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Character_class] for a full list. <!--- should test/list these empirically to be sure ---> When followed by punctuation (whether a special character above or not) the {{code|%}} is removed and the punctuation is taken as a literal character; {{code|%%}} = literal %. Special classes include a balanced class {{code|%bxy}} and {{code|%f[set]}}; see the link above for more.
* Parentheses {{code|( )}} indicate captures. The captures can be accessed later in the search string or in the string.gsub replacement string as {{code|%1}} to {{code|%9}}, and are returned by string.match as an expression list of results.
* The qualifiers {{code|? - * +}} specify repetitions of a single character (not a longer string).
:* {{code|?}} means 0 or 1 repetitions: {{code|a?}} matches "a" or "".
:* {{code|-}} means 0 or more repetitions, choosing as few as possible to achieve a match ("non-greedy"). For example {{code|2=lua|string.match("bbbb", "(.-)")}} yields "", which is less than useful because there is nothing to root the ends of the expression and prevent it from matching zero characters.
:* {{code|*}} means 0 or more repetitions, choosing as many as possible ("greedy"). For example {{code|2=lua|string.match("bbbb", ".*")}} yields bbbb.
:* {{code|+}} means 1 or more repetitions, choosing as many as possible ("greedy").
Note that the greediness of the ''leftmost'' qualifier rules over all others when there is a choice: {{code|(.*)b(.*)}} when matched on "bbb" will return "bb", "", while {{code|a(.-)b(.-)a}} when matched on "abbba" will return "", "bb".
* {{code|^}} and {{code|$}} indicate the beginning and end of the string if they occur in the appropriate place in the pattern. Otherwise they are literal characters. {{code|^}} is not used in the {{code|string.gmatch}} function.
The reference manual for Lua patterns is at [[:mw:Extension:Scribunto/Lua_reference_manual#Patterns|mediawiki.org]].
== {{anchor|regex}}Note on Lua patterns versus regular expressions ==
Lua patterns are ''loosely based'' on [[regular expression]]s (sometimes shortened to regex or regexp). Lua patterns deliberately lack the most complex regular expression constructs (to avoid bloating the Lua code base), where many other computer languages or libraries use a more complete set. Lua patterns are not even a subset of regular expressions, as there are also discrepancies, like Lua using the escape character <code>%</code> instead of <code>\,</code>, and additions, like Lua providing <code>-</code> as a non-greedy version of <code>*</code>.
Here is a list of some of the things that Lua patterns lack compared to regular expressions:
* You '''cannot''' search for alternations between anything else than single characters (you '''cannot''' say <code>(his|her)</code> to choose between <code>his</code> and <code>her</code>, you can only say <code>[abc]</code> to choose between single characters <code>a</code>, <code>b</code>, or <code>c</code>).
* You '''cannot''' look for multiples of multi-letter constructs such as <code>(choo-)*choo</code> to match <code>choo</code>, <code>choo-choo</code> or <code>choo-choo-choo</code>. There is no way to do this with Lua patterns.
* You '''cannot''' specify the minimum and maximum number of repetitions like <code>[0-9]{3,5}</code> (to match 3 to 5 digits); in Lua you would say <code>%d%d%d%d?%d?</code> instead in this case.
There are Lua libraries that offer more powerful options,<sup>[http://lua-users.org/wiki/PatternsTutorial]</sup> including regular expressions, but the support on Wikipedia is pretty basic.
Wikipedia help for regular expressions (which Lua, as mentioned, does ''not'' support) is at [[Wikipedia:AutoWikiBrowser/Regular expression]].
{{Wikipedia technical help|collapsed}}
[[Category:Module help|*]]
ntl0fzze1eizbj4cuydwn3rioy8126n
790919
790918
2026-05-19T18:30:09Z
Nimmzo
78995
/* Arguments */ Converted a number to letter in Sinhala. Two methods are presented to display a table. Using: 1. Customizable debugLog report table on one line in the Debug console. 2. Multiline mw.logObject(frame.args) provided by Scribunto
790919
wikitext
text/x-wiki
{{WikiProject Lua header}}
{{Selfref|This help page is meant to provide some basic orientation for those new to Lua/Scribunto.}}
{{ඉංග්රීසි ව්යාපෘතියේ සිට ආයාත කළ පිටුව}}
== Overview ==
[[WP:Lua|Lua]] is a lightweight scripting language safely available on Wikipedia via [[mw:Extension:Scribunto|Scribunto]]. Its purpose is to allow you to process the data which is available on Wikipedia content pages to allow various sorts of customized display of information.
It runs in a sandboxed environment to protect the stability of Wikipedia while enabling powerful <syntaxhighlight lang="lua" inline>{{template}}</syntaxhighlight> and <syntaxhighlight lang="lua" inline>module:</syntaxhighlight> functionality.
The most important help file is the [[mw:Extension:Scribunto/Lua reference manual|MediaWiki Scribunto Lua reference manual]], which provides a concise summary of the language and standard library calls as implemented on MediaWiki.
The standard [http://www.lua.org/manual/5.1/manual.html Lua reference manual] is well written and comprehensive, but it can be confusing for beginners because some standard features don't work on wiki pages. You cannot call <syntaxhighlight lang="lua" inline>print("Hello, World!")</syntaxhighlight> in a module, but you can preview your User page showing the string <syntaxhighlight lang="lua" inline>"Hello World!"</syntaxhighlight> generated by the Lua [[Module:Example]]. Think of your Lua template as an HTML generator.
=== Generating "Hello World!" ===
You do not need to install or save anything.
# Edit your User page: <code>පරිශීලක:YourUserName</code>
# Paste the following call at the beginning of a new line on your User page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{#invoke:Example|hello}}
</syntaxhighlight></blockquote>
<ol start="3">
<li>Click <code>Preview</code>. The call of the function <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> in the [[Module:Example]] is replaced with the following:</li>
</ol>
<blockquote><syntaxhighlight lang="lua" line>
Hello World!
</syntaxhighlight></blockquote>
<ol start="4">
<li>Click <code>Cancel</code>. When prompted, click <code>Leave</code>.</li>
<li>Your User page remains '''un'''modified.</li>
</ol>
== Debug console: Start learning Lua ==
The Lua Scribunto <code>Debug Console</code> is a safe, interactive tool for learning Lua in Wikipedia.
# Click <code>Edit</code> on the [[Module:Yesno]] page.
# Scroll to the bottom of the page to the <code>Debug console</code> section beneath the Lua editor.
# Paste the comment and the call into the <span style="color:#86888c;">gray</span> input box (above the <code>Clear</code> button).
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
--[[ඔබගේ ආරම්භක Lua "හෙලෝ වර්ල්ඩ්" යන වගේම වැඩසටහන]]--
print("වෙල්කම් වෙයි " .. _VERSION .. "!") -- Lua අනුවාදය .. සමඟ එකතු කරයි
</syntaxhighlight></blockquote>
<ol start="4">
<li>Press {{key press|Enter}} once to execute the two Lua command''s''.</li>
<li>The result will appear below the Lua <syntaxhighlight lang="lua" inline>print</syntaxhighlight> command line:</li>
</ol>
<blockquote><syntaxhighlight lang="lua" line start=3>
වෙල්කම් වෙයි Lua 5.1!
</syntaxhighlight></blockquote>
<ol start="6">
<li>Press <code>Up arrow</code> (↑) to cycle through previous Lua commands.</li>
<li>Optionally, click <code>Clear</code> to clear ''only'' the <code>Debug Console</code>; the Lua editor above will remain '''un'''modified.</li>
</ol>
; HTML generator in the Debug console
Call the function <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> in <code>Module:</code>Example:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local modExample = require('Module:Example') -- load the module in Debug console
local frame = mw.getCurrentFrame(); print(modExample.hello(frame)) -- display "Hello World!"
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
Hello World!
</syntaxhighlight></blockquote>
; Identity function
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local yesno = require('Module:Yesno') -- #if yesno then returns its input parameter
print(mw.getCurrentFrame():callParserFunction("#if", yesno("Yes"), "Yes", 'නැහැ'))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
Yes
</syntaxhighlight></blockquote>
# Close the protected <code>Module:</code>Yesno that remains '''un'''modified.
== Issues with the current implementation ==
Besides the lack of <code>print()</code> in a module, there are other features missing – see [[mw:Extension:Scribunto/Lua reference manual#Differences from standard Lua|Differences from standard Lua]] for a complete list.
At the present time, it is advisable to use ''[[mw:Extension:Scribunto/Lua reference manual#Ustring library|mw.ustring]]'' functions instead of ''[[mw:Extension:Scribunto/Lua reference manual#String library|string]]'', because the latter sometimes fails with Unicode characters.
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local lang = mw.getCurrentFrame():callParserFunction("#language", "si") -- Sinhala
local lenUnicode, lenByte, lenSharp = mw.ustring.len(lang), string.len(lang), #lang
print(("lang: %s Mw.ustring.len = %d String.len = %d Sharp = %d"):format(lang, lenUnicode, lenByte, lenSharp))
</syntaxhighlight></blockquote>
Debug console supports Unicode:
<blockquote><syntaxhighlight lang="lua" line start=4>
lang: සිංහල Mw.ustring.len = 5 String.len = 15 Sharp = 15
</syntaxhighlight></blockquote>
== Input ==
The programs are run only when the page is "parsed" (when it or a page it incorporates is changed or previewed), not every time you view the output. Therefore there can be no convenient Lua module that allows you to type in a Fahrenheit temperature in an input box and get back the corresponding Celsius temperature when you press a button, or allows you to click on a segment of a Mandelbrot set visualization on a page to expand it as often as you like. There has to be an actual Wiki page (or at least a page you have submitted for preview) containing the input data.
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local function toCelsius(tempFahrenheit) return (tempFahrenheit - 32) * 5 / 9 end
print(("toCelsius(32°F) = %s°C. toCelsius(68°F) = %d°C"):format(toCelsius(32), toCelsius(68)))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
toCelsius(32°F) = 0°C. toCelsius(68°F) = 20°C
</syntaxhighlight></blockquote>
However, it is possible to use library functions like [[mw:Extension:Scribunto/Lua reference manual#mw.title.getCurrentTitle|mw.title.getCurrentTitle()]] to import content from any text content page on the Wiki.
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
print(mw.title.getCurrentTitle())
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=2>
Module:Yesno
</syntaxhighlight></blockquote>
You cannot, however, import data from files, not even .svg files which contain XML text data.
== Calling a Lua module ==
Lua calls look much like [[WP:template|template]]s, and consist of a small block of text.
In your User page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{ConvertNumeric|decToHex|73}}
</syntaxhighlight></blockquote>
Click <code>Preview</code> or click <code>Edit</code> this section to see the call then <code>Cancel</code>:
<blockquote>
{{#invoke:ConvertNumeric|decToHex|73}}
</blockquote>
This text calls the Lua script itself, which is housed in the <code>Module:</code> [[WP:namespace|namespace]]. The effect of this call is to send the information within the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> block to the Lua module, and to replace everything within the brackets with a piece of text that it sends back in return. (Literally, in the "return" statement)
Note that the first "parameter", in this case <code>decToHex</code>, is actually a <syntaxhighlight lang="lua" inline>function</syntaxhighlight> called within the Lua module. This field must always be included in any <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight>. To those unfamiliar with modules, especially Wikipedia template coders who expect anything after <code>|</code> to be a parameter, the need for this extra field is surprising, especially if all uses of the module depend on its presence.
In Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local convNum = require('Module:ConvertNumeric')
local frame = mw.getCurrentFrame(); frame.args[1] = "73" -- number always as string
print(("0x%s = %s = %d"):format(convNum.decToHex(frame), string.format("0x%X", 73), 0x49))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=4>
0x49 = 0x49 = 73
</syntaxhighlight></blockquote>
=== Documenting a Lua module ===
When documenting your module, it is useful to include an explicit usage instruction using [[සැකිල්ල:Module link expanded]]:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{mlx|ConvertNumeric|decToHex|73}}
</syntaxhighlight></blockquote>
Hyperlink to the module:
<blockquote>
{{mlx|ConvertNumeric|decToHex|73}}
</blockquote>
For many existing modules, an example <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> of the script (and little else) is provided on the <code>Module talk:</code> page. It is convenient for authors to be able to flip quickly to the talk tab to look at the effects of their changes, but you should never transclude the talk page as a template - people might actually talk on it! Alternatively, the module page can show documentation from a separate /doc-page (as [[Module:WikidataIB]] does).
=== Another example: Using LuaCall to perform a single Lua instruction ===
As a beginner, or in casual talk page conversation, you might only have one little calculation you want to use Lua for but don't want to write a full module. You might find [[Module:LuaCall]] convenient for this. For example, you can test how a greedy [https://www.lua.org/pil/20.1.html Lua pattern] works:
* <syntaxhighlight lang="lua" inline>{{#invoke:LuaCall|main|a=bbbbbbbbbba|b=bb(.*)b(.+)bba|string.match(a,b)}}</syntaxhighlight> → <code>{{#invoke:LuaCall|main|a=bbbbbbbbbba|b=bb(.*)b(.+)bba|string.match(a,b)}}</code>
or count up the length of a [[wikipedia:Did you know|''Did you know'']] hook or the text portion of a ''Did you know'' candidate:
* <syntaxhighlight lang="lua" inline>{{#invoke:LuaCall|main|a=... that you can count the length of your DYK hook with a Lua module?|string.len(a)}}</syntaxhighlight>→ <code>{{#invoke:LuaCall|main|a=... that you can count the length of your DYK hook with a Lua module?|string.len(a)}}</code>
In these specific examples, however, [[Module:String]] could do both of these tasks.
The script at [[Module:LuaCall]] has been written to accept any set of named parameters <code>somename=value</code>, for each one storing the string <code>value</code> in the variable with the name <code>somename</code>, and then allowing you to use these variables as parameters for any function available in Lua. The script then returns only the ''first'' value returned by the function ([https://www.lua.org/pil/5.1.html Lua functions can return multiple values], but in this case, only the first is returned from the module).
== Lua program structure: Output ==
The most fundamental part of a Wikipedia Lua program is a '''return''' statement which carries its output back to the page that had the <code>#invoke</code>. You ''can'' have a Lua function that runs without error even though it doesn't contain a return statement, but on Wikipedia it is pointless, as Lua programs cannot generally have side effects on Wikipedia.
The module itself must return a Lua '''table''' of values. A Lua table is expressed as a list of values separated by commas, within curly braces. When the module is called by <code>#invoke</code>, the '''function''' it names (the first argument after |) is looked for in that table. That function, in turn, is expected to return something that can be represented as a '''string'''.
Therefore, <syntaxhighlight lang="lua" inline>return { mw.ustring.gmatch( "Hello world", "(.*)" ) }</syntaxhighlight> is actually a complete Lua module (though a very strange one) - it returns the function returned by mw.ustring.gmatch (an iterator function listed in the Lua reference cited above) as the one and only element in an array (represented within <code>{}</code>)—which when executed using <syntaxhighlight lang="wikitext" inline>{{#invoke:ModuleName|1}}</syntaxhighlight> yields the string "Hello world". ''However'', things are not usually done this way. Typically we use the overall form:
<syntaxhighlight lang="lua">
local p = {} -- Defines a variable p as an empty table, but *not* nil.
function p.main( frame ) -- This block defines the table element p["main"] as a function.
return "Hello world" -- The string result of the function.
end -- Ends the block defining the function object p["main"] (or p.main).
return p -- This returns the table p, which under the key "main" contains the
-- function above (p.main), which when called returns string "Hello world".
</syntaxhighlight>
Note that <syntaxhighlight lang="lua" inline>function p.main(frame) ... end</syntaxhighlight> is equivalent to <syntaxhighlight lang="lua" inline>p.main = function(frame) ... end</syntaxhighlight> or <syntaxhighlight lang="lua" inline>p["main"] = function(frame) ... end</syntaxhighlight>. The function is just another type of value, retrieved with the key <code>"main"</code> from table <code>p</code>. If you want to allow users to invoke the same module with <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|hello}}</nowiki></code> instead of <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|main}}</nowiki></code>, you can write <code>p.hello = p.main</code> to copy the reference to this function to a new key in the table. You can even write <code>p[""] = p.main</code>, which causes <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|}}</nowiki></code> to produce the same output as <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|main}}</nowiki></code>. Learning to think of functions as a data type becomes very important later on for working with library functions like <code>[[mw:Extension:Scribunto/Lua_reference_manual#string.gsub|mw.ustring.gsub]]</code>, and constructing iterator functions.
== Lua program structure: Input ==
The '''<code>frame</code>''' parameter above (which is pretty much always given this name in Wikipedia Lua modules) receives another table, which is passed ''from'' the page that makes the call ''to'' the Lua module. It contains a surprising amount of stuff, of which just a few things concern the novice.
=== Arguments ===
{{see also|Module:Arguments}}
<code>frame.args</code> contains ''another'' table, namely, all the content sent by the user within the <code>#invoke</code> brackets except the first argument which states the name of the function to be executed.
In your User page: about [[Module:ConvertNumeric]]
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{#invoke:ConvertNumeric |numeral_to_english |57000 |round=on |plural=on}}
</syntaxhighlight></blockquote>
Click <code>Preview</code> or click <code>Edit</code> this section to see the call then <code>Cancel</code>:
<blockquote>
{{#invoke:ConvertNumeric |numeral_to_english |57000 |round=on |plural=on}}
</blockquote>
There are two types of parameters: numeric (positional) keys and named keys.
# Unnamed parameters come out with numbers as keys: <code>frame.args[1]</code>.<br/>The string <code>"57000"</code> is the content of <code>frame.args[1]</code> which is the same as <code>frame["args"][1]</code><br/>but ''not'' the same as <code>frame.args["1"]</code> or <code>frame["args"]["1"]</code>.
# Named parameters come out with the parameter names (strings) as keys: <code>frame.args["round"]</code>, <code>frame.args["plural"]</code>.
In Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=4 copy>
--[[Convert a number to letter in Sinhala]]--
local convNum = require('Module:ConvertNumeric')
local frame=mw.getCurrentFrame(); frame.args = {"57000", round="on", plural="on"}
print(convNum.numeral_to_english(frame) .. " is rounded from 57,000.")
local debugLog = {} -- empty report table
for key, val in pairs(frame.args) do -- for each arg
debugLog[#debugLog + 1] = ("args[%s] = %s"):format(key, val)
end -- ^length. Adding report is faster than string-based: debugLog = debugLog .. string
print(table.concat(debugLog, ". ")) -- Join with separator
mw.logObject(frame.args) -- Scribunto tool to display table
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=11>
හැට දහස is rounded from 57,000.
args[1] = 57000. args[plural] = on. args[round] = on
table#1 {
"57000",
["plural"] = "on",
["round"] = "on",
}
</syntaxhighlight></blockquote>
=== Parent frame ===
Within <code>frame</code> there is a ''parent'' frame, referring to the page that called the page that gives the script, and you can pull out arguments from that also. Just write:
<blockquote><syntaxhighlight lang="lua" line highlight=17 copy>
--[[Return true if table-like `tab` contains any non-nil entries]]--
local function has_any_args(tab)
if tab == nil then return false end -- the table is nil
for _, val in pairs(tab) do -- Iterates both numeric (positional) and string (named) keys.
if val ~= nil then -- value not nil?
return true -- one argument exists
end
end
return false -- The table does not have any arguments
end
--[[Debug console or template in wiki page?]]--
local booksPlural = "There are those books."; local pluralMarker = "s."
local globalSub = "mw.ustring.gsub(subjectStr,pattern,replace)" -- no space separator
local prm = {subjectStr=booksPlural, pattern=pluralMarker, replace=".", globalSub, "lua"}
local frame = mw.getCurrentFrame():newChild{title='Module:Lua call', args=prm}
local parent = frame:getParent() or nil
if not parent or not has_any_args(parent.args) then
print("Running from Debug console")
print(mw.text.listToText(frame.args))
else
print("Running from wiki page invoking {{template}}")
end
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=24>
Running from Debug console
mw.ustring.gsub(subjectStr,pattern,replace)
</syntaxhighlight></blockquote>
<syntaxhighlight lang="lua" inline>parent.args</syntaxhighlight> will contain those arguments.
It is popular in Lua to use the synonymous statement <code>parent=frame''':'''getParent()</code>, cancelling the need to write <code>frame</code> twice.<br/>
Note the colon (<code>:</code>) instead of the dot (<code>.</code>).
<syntaxhighlight lang="lua" inline>parent = frame:getParent()</syntaxhighlight> means exactly the same as <code>parent = frame.getParent(frame)</code>.
For novices this can be confusing, and it is important to be aware of this idiom.<br/>
If you use it in the wrong way, though, the script errors are pretty good at pointing out that this was the mistake.
== Basic debugging ==
{{Main|Help:Lua debugging}}
Debugging can start as soon as you write programs, and can be done simply with string concatenation.<br/>
Just set up a variable with some recognizable name like <syntaxhighlight lang="lua" inline>debugLog</syntaxhighlight> in your main <syntaxhighlight lang="lua" inline>function p.main(frame)</syntaxhighlight> with a statement like:
<blockquote><syntaxhighlight lang="lua" line start=3 highlight=1 copy>
local debugLog = "" -- empty report string
</syntaxhighlight></blockquote>
This initial <syntaxhighlight lang="lua" inline>""</syntaxhighlight> definition helps because otherwise it will be <syntaxhighlight lang="lua" inline>nil</syntaxhighlight> and concatenating a string to nil gets you an error.<br/>
Now whenever you have a variable you'd like to test, say {{tt|myVar}}, just write:
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=2 copy>
local myVar = 42; local output = "expected result"
debugLog = debugLog .. " myVar = " .. tostring(myVar) -- append to the report
</syntaxhighlight></blockquote>
At the end of your function (but not the module), complete:
<blockquote><syntaxhighlight lang="lua" line start=16 highlight=1 copy>
return output .. debugLog -- Returns the expected result and the report
</syntaxhighlight></blockquote>
The <syntaxhighlight lang="lua" inline>tostring(myVar)</syntaxhighlight> is a function to ensure {{tt|myVar}} is interpreted as a string.<br>
For a table, it will display as "{{samp|table}}". For nil, "{{samp|nil}}" rather than as Script error.
== Format ==
The [[WP:Lua style guide]] gives some basic formatting suggestions expected by the JavaScript module editor, such as using four-space indentations and keeping <syntaxhighlight lang="lua" inline>if then else</syntaxhighlight>, <syntaxhighlight lang="lua" inline>end</syntaxhighlight> at the same level of indentation.
Comments to the end of a line are marked by <syntaxhighlight lang="lua" inline>-- green comment</syntaxhighlight>. ''Use them.''
Many modules for Wikipedia have a straightforward, linear design, but that doesn't mean it won't help to have your sections clearly labelled when you go back to the code for the hundredth time. The Lua style guide gives additional recommendations for using functions to keep your work more organized.
== Errors ==
Lua errors appear as red "Script error" messages. If Javascript is enabled, '''the <span style="color:#ff0000;">red</span> script error message is a link''' which usually allows you to follow it back to the line in the module where the error occurred. There are some exceptions, for example "Module not found", if the name of the module itself is mistyped, or "The function you specified did not exist" if the function name given is invalid.
=== Recurrent bugs ===
Some bugs you might want to keep in mind:
;Missing operator for concatenation
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=2 copy>
local debugLog = "" -- empty report string
debugLog = debugLog "missing double dot" -- append to the report
</syntaxhighlight></blockquote>
The following means you forgot the <code>..</code> between a string and a variable somewhere in a mess of stuff you're concatenating.
<blockquote><syntaxhighlight lang="lua" line start=9>
Lua error in console input at line 8: attempt to call local 'debugLog' (a string value).
</syntaxhighlight></blockquote>
;String expected, got function
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=3 copy>
local debugLog = "" -- empty report string
local res = mw.ustring.gmatch("Hello World!", "([aeiouAEIOU])") -- iterator of vowels
debugLog = debugLog..res -- populate the report with only strings
</syntaxhighlight></blockquote>
Some important things like <syntaxhighlight lang="lua" inline>mw.ustring.gmatch</syntaxhighlight> actually return ''functions'', not strings - see [[#Functions|Functions]] below.
<blockquote><syntaxhighlight lang="lua" line start=10>
Lua error in console input at line 9: attempt to concatenate local 'res' (a function value).
</syntaxhighlight></blockquote>
;Variable ignores assignment
A variable ignores all your efforts to assign stuff to it:
<blockquote><syntaxhighlight lang="lua" line highlight=1,3 copy>
local debugLog = "top level" -- initial value
do
local debugLog = "nested level" -- set the new value
print("Inside do: "..debugLog)
end
print("Outside do: "..debugLog) -- get the old value
</syntaxhighlight></blockquote>
You may have inadvertently written ''two'' local statements - the one sets the value of the variable within a limited region, and when the program leaves that region, you're back to the old value.
<blockquote><syntaxhighlight lang="lua" line start=7>
Inside do: nested level
Outside do: top level
</syntaxhighlight></blockquote>
A numbered table entry ignores all your efforts to assign to it:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local table = {}; local arg = "50"; local valPrm = tonumber(arg)
table[arg] = "index as string"
table[valPrm] = "index as number"
print(table[arg] == table[valPrm])
</syntaxhighlight></blockquote>
This is because {{code|table["50"]}} '''is not''' {{code|table[50]}}.<br/>
Typically you have processed a parameter (which you may have received from the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> as a string) with string functions in one place,<br>
but performed numeric operations in another, leaving you with two different types of variable to use for an index.
<blockquote><syntaxhighlight lang="lua" line start=5>
false
</syntaxhighlight></blockquote>
;<syntaxhighlight lang="lua" inline>nil</syntaxhighlight> and common pitfalls
There are all sorts of things you can't do with a local variable set to nil, such as: <syntaxhighlight lang="lua" inline>local x = nil</syntaxhighlight>, like:
# Assign <code>x.somefield</code>
# Get value at index {{code|x[idx]}}
# Concatenate <syntaxhighlight lang="lua" inline>x .. "Cannot concatenate with nil"</syntaxhighlight>
# Evaluate <syntaxhighlight lang="lua" inline>table[x]</syntaxhighlight>
Initialize such variables with: <syntaxhighlight lang="lua" inline>local x={}; local table = {}</syntaxhighlight><br>
Often "global" is mentioned in these errors because you didn't have a {{tt|local}} statement for the <syntaxhighlight lang="lua" inline>nil</syntaxhighlight> variable.
;Cannot invoke module
* ''no such module.'' You called <syntaxhighlight lang="lua" inline>#invoke:moduleNameUnknown</syntaxhighlight> that didn't exist or you wrongly kept the prefix <code>Module:</code> writing {{code|#invoke:Module:moduleName}}.
* ''the function specified did not exist.'' You called <syntaxhighlight lang="lua" inline>#invoke:moduleName|functionUnknown</syntaxhighlight>, but the field after the name of the module is wrong.<br>Often this field expects a standard name like "main", and you've forgotten it and gone straight to the first data parameter.<br>If you're unsure of the function name, check the module documentation, or look for what function(s) in the code accept a "frame" parameter.
;Graphics overflow issue
Some graphics you're trying to display are heading off to the hills: actually a HTML error.<br>
You didn't close one <syntaxhighlight lang="html" inline></div></syntaxhighlight>, so all the top: and left: styles keep adding up.
== Understanding tables and related concepts ==
* An '''expression list''' is a set of values separated by commas. The values can be strings, numbers, tables, functions, etc.
* A '''sequence''' is a set of entries with indices from 1 to N, where N is a positive integer. They can be created by placing brackets around an expression list.
For example:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local seq = {1, "quotation", mw.ustring.gmatch("abca","a"), {2,3,4}}
mw.logObject(seq) -- Scribunto tool to display a table
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
table#1 {
1,
"quotation",
function#1,
table#2 {
2,
3,
4,
},
}
</syntaxhighlight></blockquote>
# <code>seq[1]</code> = 1
# <code>seq[2]</code> = <syntaxhighlight lang="lua" inline>"quotation"</syntaxhighlight>
# <code>seq[3]</code> is the <syntaxhighlight lang="lua" inline>function</syntaxhighlight> returned by <code>gmatch()</code>
# <code>seq[4]</code> is the table <code>{2,3,4}</code>.
An expression list can also be recovered from a table using <syntaxhighlight lang="lua" inline>unpack()</syntaxhighlight>:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local seq = {1, "quotation", mw.ustring.gmatch("abca","a"), {2,3,4}}
local var1Nbr, var2Str, var3Fct = unpack(seq)
print(("var1Nbr = %d. var2Str = \"%s\". var3Fct = %s"):format(var1Nbr, var2Str, type(var3Fct)))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=4>
var1Nbr = 1. var2Str = "quotation". var3Fct = function
</syntaxhighlight></blockquote>
This will set:
# <code>var1Nbr</code> = 1
# <code>var2Str</code> = <syntaxhighlight lang="lua" inline>"quotation"</syntaxhighlight>
# <code>var3Fct</code> as the <syntaxhighlight lang="lua" inline>function</syntaxhighlight> returned by <code>gmatch()</code>
# <code>{2,3,4}</code> will be discarded in this case.
* A '''table''' is a sequence, optionally supplemented by named keys: <code>digit["two"]="2"</code>. Several table functions like <code>table.concat</code> will only work with the numbered values and ignore named keys.
* The '''metatable''' offers a large, optional set of methods for altering table behavior. For example, you can define a table to be callable like a function.
=== Initializing a table ===
It is often useful to create a whole table at once in a statement. There are many equivalent ways to do this, but the shortcuts don't work for every kind of value. To begin with, the most general way is to assign each key and value explicitly:
<syntaxhighlight lang="lua" inline>a = {[0]='zero', [1]='one', ['1']='string for one'}</syntaxhighlight>
If sequence keys (positive integers) are given in order, only the values need to be given, so the following will assign <syntaxhighlight lang="lua" inline>'one'</syntaxhighlight> to <syntaxhighlight lang="lua" inline>a[1]</syntaxhighlight>:
<syntaxhighlight lang="lua" inline>a = {[0]='zero', 'one', ['1']='string for one'}</syntaxhighlight>
If a key has only letters, digits, and underscores, and begins with a non-digit, the brackets and quotation marks can be omitted:
<syntaxhighlight lang="lua" inline>a = {a='one', b='two'}</syntaxhighlight>
This is identical to <syntaxhighlight lang="lua" inline>a = {["a"]='one', ["b"]='two'}</syntaxhighlight>.
However, this will fail for keys that begin with a digit: <syntaxhighlight lang="lua" inline>hex = {7f = 127}</syntaxhighlight> will produce an error; use <syntaxhighlight lang="lua" inline>hex = {['7f'] = 127}</syntaxhighlight> instead.
Note that when given ''within'' brackets, or to the right of the equal sign, quotation marks are needed, or else string values will be taken as variables:
<syntaxhighlight lang="lua" inline> a = {[b] = c}</syntaxhighlight>
assigns the value of variable ''c'' to the key ''contained in variable'' ''b''.
== Functions ==
* Functions can return any kind of value {{--}} ''including a function''. This is a powerful feature that can readily confuse the beginner. If you set <syntaxhighlight lang="lua" inline>a=mw.ustring.gmatch(text, "(.)")</syntaxhighlight>, the result assigned to <code>a</code> will be a '''function''', not a string character! However, assigning <code>b=a()</code> by calling the function stored in <code>a</code> will return the first match (a string). Every time you set <code>b=a()</code> after that you'll get another match (string) into <code>b</code>, until you run out of matches and get <code>nil</code>. Many '''iterator functions''' act this way.
* You can keep separate counts for iterator functions by using different variables. For example, if you set <syntaxhighlight lang="lua" inline>q=mw.ustring.gmatch(text, "(x.)")</syntaxhighlight> in the same module, you can pull characters from the same piece of text (<code>text</code>) by evaluating <code>d=q()</code> without losing your place in <code>a()</code>.
* [[tail call|Tail calls]] offer substantial benefits in performance for those who master the language.
* Function names are often of the form {{code|p.myFunctionName}}, where p is the table from the {{code|return p}} at the bottom of your program. The reason for this is that you can only access functions that are entries in this table from the original {{code|#invoke}} statement. Functions for local use within the program can have any name.
== Understanding patterns ==
''Note:'' Lua patterns are ''not'' [[regular expression|regular expressions]] in the traditional POSIX sense, and they are not even a subset of regular expressions. But they share many constructs with regular expressions (more [[Help:Lua for beginners#regex|below]]).
Lua patterns are used to define, find and handle a ''pattern'' in a string. It can do the common search and replace action in a text, but it has more options that doing plain text only. For example, in one go it can change the errors 'New yorker', 'New-Yorker', and 'NewYorker' into 'New Yorker'.
* To begin with, a pattern works like a plain string so long as it doesn't contain the special characters {{code|^ $ () % . [] * + - ?}}
* Square brackets {{code|[ ]}} are used to match ''one'' ''single character'' in the string from a list of choices. {{code|[abc]}} matches the letters a, b, or c. With {{code|^}} right after {{code|[}} they indicate "anything but": {{code|[^abc]}} = not a, b, or c. Inside brackets and when not the first character, a minus {{code|-}}indicates a range: {{code|[a-z]}} matches one single character from a, b, c, …, z.
* Period {{code|.}} matches any character.
* Percent {{code|%}} indicates a large set (class) of possible character matches when it is followed by a letter. See [https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Character_class] for a full list. <!--- should test/list these empirically to be sure ---> When followed by punctuation (whether a special character above or not) the {{code|%}} is removed and the punctuation is taken as a literal character; {{code|%%}} = literal %. Special classes include a balanced class {{code|%bxy}} and {{code|%f[set]}}; see the link above for more.
* Parentheses {{code|( )}} indicate captures. The captures can be accessed later in the search string or in the string.gsub replacement string as {{code|%1}} to {{code|%9}}, and are returned by string.match as an expression list of results.
* The qualifiers {{code|? - * +}} specify repetitions of a single character (not a longer string).
:* {{code|?}} means 0 or 1 repetitions: {{code|a?}} matches "a" or "".
:* {{code|-}} means 0 or more repetitions, choosing as few as possible to achieve a match ("non-greedy"). For example {{code|2=lua|string.match("bbbb", "(.-)")}} yields "", which is less than useful because there is nothing to root the ends of the expression and prevent it from matching zero characters.
:* {{code|*}} means 0 or more repetitions, choosing as many as possible ("greedy"). For example {{code|2=lua|string.match("bbbb", ".*")}} yields bbbb.
:* {{code|+}} means 1 or more repetitions, choosing as many as possible ("greedy").
Note that the greediness of the ''leftmost'' qualifier rules over all others when there is a choice: {{code|(.*)b(.*)}} when matched on "bbb" will return "bb", "", while {{code|a(.-)b(.-)a}} when matched on "abbba" will return "", "bb".
* {{code|^}} and {{code|$}} indicate the beginning and end of the string if they occur in the appropriate place in the pattern. Otherwise they are literal characters. {{code|^}} is not used in the {{code|string.gmatch}} function.
The reference manual for Lua patterns is at [[:mw:Extension:Scribunto/Lua_reference_manual#Patterns|mediawiki.org]].
== {{anchor|regex}}Note on Lua patterns versus regular expressions ==
Lua patterns are ''loosely based'' on [[regular expression]]s (sometimes shortened to regex or regexp). Lua patterns deliberately lack the most complex regular expression constructs (to avoid bloating the Lua code base), where many other computer languages or libraries use a more complete set. Lua patterns are not even a subset of regular expressions, as there are also discrepancies, like Lua using the escape character <code>%</code> instead of <code>\,</code>, and additions, like Lua providing <code>-</code> as a non-greedy version of <code>*</code>.
Here is a list of some of the things that Lua patterns lack compared to regular expressions:
* You '''cannot''' search for alternations between anything else than single characters (you '''cannot''' say <code>(his|her)</code> to choose between <code>his</code> and <code>her</code>, you can only say <code>[abc]</code> to choose between single characters <code>a</code>, <code>b</code>, or <code>c</code>).
* You '''cannot''' look for multiples of multi-letter constructs such as <code>(choo-)*choo</code> to match <code>choo</code>, <code>choo-choo</code> or <code>choo-choo-choo</code>. There is no way to do this with Lua patterns.
* You '''cannot''' specify the minimum and maximum number of repetitions like <code>[0-9]{3,5}</code> (to match 3 to 5 digits); in Lua you would say <code>%d%d%d%d?%d?</code> instead in this case.
There are Lua libraries that offer more powerful options,<sup>[http://lua-users.org/wiki/PatternsTutorial]</sup> including regular expressions, but the support on Wikipedia is pretty basic.
Wikipedia help for regular expressions (which Lua, as mentioned, does ''not'' support) is at [[Wikipedia:AutoWikiBrowser/Regular expression]].
{{Wikipedia technical help|collapsed}}
[[Category:Module help|*]]
htrjvyg2zzrczoia01rz404z78i585b
790921
790919
2026-05-19T18:40:09Z
Nimmzo
78995
/* Lua program structure: Output */ Strongly simplified the comments because the main message is that "The input parameter frame is not used". Deleted complex double "which" in "return p" because everything is explained in [[Module:Example]]
790921
wikitext
text/x-wiki
{{WikiProject Lua header}}
{{Selfref|This help page is meant to provide some basic orientation for those new to Lua/Scribunto.}}
{{ඉංග්රීසි ව්යාපෘතියේ සිට ආයාත කළ පිටුව}}
== Overview ==
[[WP:Lua|Lua]] is a lightweight scripting language safely available on Wikipedia via [[mw:Extension:Scribunto|Scribunto]]. Its purpose is to allow you to process the data which is available on Wikipedia content pages to allow various sorts of customized display of information.
It runs in a sandboxed environment to protect the stability of Wikipedia while enabling powerful <syntaxhighlight lang="lua" inline>{{template}}</syntaxhighlight> and <syntaxhighlight lang="lua" inline>module:</syntaxhighlight> functionality.
The most important help file is the [[mw:Extension:Scribunto/Lua reference manual|MediaWiki Scribunto Lua reference manual]], which provides a concise summary of the language and standard library calls as implemented on MediaWiki.
The standard [http://www.lua.org/manual/5.1/manual.html Lua reference manual] is well written and comprehensive, but it can be confusing for beginners because some standard features don't work on wiki pages. You cannot call <syntaxhighlight lang="lua" inline>print("Hello, World!")</syntaxhighlight> in a module, but you can preview your User page showing the string <syntaxhighlight lang="lua" inline>"Hello World!"</syntaxhighlight> generated by the Lua [[Module:Example]]. Think of your Lua template as an HTML generator.
=== Generating "Hello World!" ===
You do not need to install or save anything.
# Edit your User page: <code>පරිශීලක:YourUserName</code>
# Paste the following call at the beginning of a new line on your User page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{#invoke:Example|hello}}
</syntaxhighlight></blockquote>
<ol start="3">
<li>Click <code>Preview</code>. The call of the function <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> in the [[Module:Example]] is replaced with the following:</li>
</ol>
<blockquote><syntaxhighlight lang="lua" line>
Hello World!
</syntaxhighlight></blockquote>
<ol start="4">
<li>Click <code>Cancel</code>. When prompted, click <code>Leave</code>.</li>
<li>Your User page remains '''un'''modified.</li>
</ol>
== Debug console: Start learning Lua ==
The Lua Scribunto <code>Debug Console</code> is a safe, interactive tool for learning Lua in Wikipedia.
# Click <code>Edit</code> on the [[Module:Yesno]] page.
# Scroll to the bottom of the page to the <code>Debug console</code> section beneath the Lua editor.
# Paste the comment and the call into the <span style="color:#86888c;">gray</span> input box (above the <code>Clear</code> button).
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
--[[ඔබගේ ආරම්භක Lua "හෙලෝ වර්ල්ඩ්" යන වගේම වැඩසටහන]]--
print("වෙල්කම් වෙයි " .. _VERSION .. "!") -- Lua අනුවාදය .. සමඟ එකතු කරයි
</syntaxhighlight></blockquote>
<ol start="4">
<li>Press {{key press|Enter}} once to execute the two Lua command''s''.</li>
<li>The result will appear below the Lua <syntaxhighlight lang="lua" inline>print</syntaxhighlight> command line:</li>
</ol>
<blockquote><syntaxhighlight lang="lua" line start=3>
වෙල්කම් වෙයි Lua 5.1!
</syntaxhighlight></blockquote>
<ol start="6">
<li>Press <code>Up arrow</code> (↑) to cycle through previous Lua commands.</li>
<li>Optionally, click <code>Clear</code> to clear ''only'' the <code>Debug Console</code>; the Lua editor above will remain '''un'''modified.</li>
</ol>
; HTML generator in the Debug console
Call the function <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> in <code>Module:</code>Example:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local modExample = require('Module:Example') -- load the module in Debug console
local frame = mw.getCurrentFrame(); print(modExample.hello(frame)) -- display "Hello World!"
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
Hello World!
</syntaxhighlight></blockquote>
; Identity function
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local yesno = require('Module:Yesno') -- #if yesno then returns its input parameter
print(mw.getCurrentFrame():callParserFunction("#if", yesno("Yes"), "Yes", 'නැහැ'))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
Yes
</syntaxhighlight></blockquote>
# Close the protected <code>Module:</code>Yesno that remains '''un'''modified.
== Issues with the current implementation ==
Besides the lack of <code>print()</code> in a module, there are other features missing – see [[mw:Extension:Scribunto/Lua reference manual#Differences from standard Lua|Differences from standard Lua]] for a complete list.
At the present time, it is advisable to use ''[[mw:Extension:Scribunto/Lua reference manual#Ustring library|mw.ustring]]'' functions instead of ''[[mw:Extension:Scribunto/Lua reference manual#String library|string]]'', because the latter sometimes fails with Unicode characters.
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local lang = mw.getCurrentFrame():callParserFunction("#language", "si") -- Sinhala
local lenUnicode, lenByte, lenSharp = mw.ustring.len(lang), string.len(lang), #lang
print(("lang: %s Mw.ustring.len = %d String.len = %d Sharp = %d"):format(lang, lenUnicode, lenByte, lenSharp))
</syntaxhighlight></blockquote>
Debug console supports Unicode:
<blockquote><syntaxhighlight lang="lua" line start=4>
lang: සිංහල Mw.ustring.len = 5 String.len = 15 Sharp = 15
</syntaxhighlight></blockquote>
== Input ==
The programs are run only when the page is "parsed" (when it or a page it incorporates is changed or previewed), not every time you view the output. Therefore there can be no convenient Lua module that allows you to type in a Fahrenheit temperature in an input box and get back the corresponding Celsius temperature when you press a button, or allows you to click on a segment of a Mandelbrot set visualization on a page to expand it as often as you like. There has to be an actual Wiki page (or at least a page you have submitted for preview) containing the input data.
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local function toCelsius(tempFahrenheit) return (tempFahrenheit - 32) * 5 / 9 end
print(("toCelsius(32°F) = %s°C. toCelsius(68°F) = %d°C"):format(toCelsius(32), toCelsius(68)))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
toCelsius(32°F) = 0°C. toCelsius(68°F) = 20°C
</syntaxhighlight></blockquote>
However, it is possible to use library functions like [[mw:Extension:Scribunto/Lua reference manual#mw.title.getCurrentTitle|mw.title.getCurrentTitle()]] to import content from any text content page on the Wiki.
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
print(mw.title.getCurrentTitle())
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=2>
Module:Yesno
</syntaxhighlight></blockquote>
You cannot, however, import data from files, not even .svg files which contain XML text data.
== Calling a Lua module ==
Lua calls look much like [[WP:template|template]]s, and consist of a small block of text.
In your User page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{ConvertNumeric|decToHex|73}}
</syntaxhighlight></blockquote>
Click <code>Preview</code> or click <code>Edit</code> this section to see the call then <code>Cancel</code>:
<blockquote>
{{#invoke:ConvertNumeric|decToHex|73}}
</blockquote>
This text calls the Lua script itself, which is housed in the <code>Module:</code> [[WP:namespace|namespace]]. The effect of this call is to send the information within the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> block to the Lua module, and to replace everything within the brackets with a piece of text that it sends back in return. (Literally, in the "return" statement)
Note that the first "parameter", in this case <code>decToHex</code>, is actually a <syntaxhighlight lang="lua" inline>function</syntaxhighlight> called within the Lua module. This field must always be included in any <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight>. To those unfamiliar with modules, especially Wikipedia template coders who expect anything after <code>|</code> to be a parameter, the need for this extra field is surprising, especially if all uses of the module depend on its presence.
In Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local convNum = require('Module:ConvertNumeric')
local frame = mw.getCurrentFrame(); frame.args[1] = "73" -- number always as string
print(("0x%s = %s = %d"):format(convNum.decToHex(frame), string.format("0x%X", 73), 0x49))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=4>
0x49 = 0x49 = 73
</syntaxhighlight></blockquote>
=== Documenting a Lua module ===
When documenting your module, it is useful to include an explicit usage instruction using [[සැකිල්ල:Module link expanded]]:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{mlx|ConvertNumeric|decToHex|73}}
</syntaxhighlight></blockquote>
Hyperlink to the module:
<blockquote>
{{mlx|ConvertNumeric|decToHex|73}}
</blockquote>
For many existing modules, an example <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> of the script (and little else) is provided on the <code>Module talk:</code> page. It is convenient for authors to be able to flip quickly to the talk tab to look at the effects of their changes, but you should never transclude the talk page as a template - people might actually talk on it! Alternatively, the module page can show documentation from a separate /doc-page (as [[Module:WikidataIB]] does).
=== Another example: Using LuaCall to perform a single Lua instruction ===
As a beginner, or in casual talk page conversation, you might only have one little calculation you want to use Lua for but don't want to write a full module. You might find [[Module:LuaCall]] convenient for this. For example, you can test how a greedy [https://www.lua.org/pil/20.1.html Lua pattern] works:
* <syntaxhighlight lang="lua" inline>{{#invoke:LuaCall|main|a=bbbbbbbbbba|b=bb(.*)b(.+)bba|string.match(a,b)}}</syntaxhighlight> → <code>{{#invoke:LuaCall|main|a=bbbbbbbbbba|b=bb(.*)b(.+)bba|string.match(a,b)}}</code>
or count up the length of a [[wikipedia:Did you know|''Did you know'']] hook or the text portion of a ''Did you know'' candidate:
* <syntaxhighlight lang="lua" inline>{{#invoke:LuaCall|main|a=... that you can count the length of your DYK hook with a Lua module?|string.len(a)}}</syntaxhighlight>→ <code>{{#invoke:LuaCall|main|a=... that you can count the length of your DYK hook with a Lua module?|string.len(a)}}</code>
In these specific examples, however, [[Module:String]] could do both of these tasks.
The script at [[Module:LuaCall]] has been written to accept any set of named parameters <code>somename=value</code>, for each one storing the string <code>value</code> in the variable with the name <code>somename</code>, and then allowing you to use these variables as parameters for any function available in Lua. The script then returns only the ''first'' value returned by the function ([https://www.lua.org/pil/5.1.html Lua functions can return multiple values], but in this case, only the first is returned from the module).
== Lua program structure: Output ==
The most fundamental part of a Wikipedia Lua program is a '''return''' statement which carries its output back to the page that had the <code>#invoke</code>. You ''can'' have a Lua function that runs without error even though it doesn't contain a return statement, but on Wikipedia it is pointless, as Lua programs cannot generally have side effects on Wikipedia.
The module itself must return a Lua '''table''' of values. A Lua table is expressed as a list of values separated by commas, within curly braces. When the module is called by <code>#invoke</code>, the '''function''' it names (the first argument after |) is looked for in that table. That function, in turn, is expected to return something that can be represented as a '''string'''.
Therefore, <syntaxhighlight lang="lua" inline>return { mw.ustring.gmatch( "Hello world", "(.*)" ) }</syntaxhighlight> is actually a complete Lua module (though a very strange one) - it returns the function returned by mw.ustring.gmatch (an iterator function listed in the Lua reference cited above) as the one and only element in an array (represented within <code>{}</code>)—which when executed using <syntaxhighlight lang="wikitext" inline>{{#invoke:ModuleName|1}}</syntaxhighlight> yields the string "Hello world". ''However'', things are not usually done this way.
Typically we use the overall form for [[Module:Example]]:
<syntaxhighlight lang="lua" line highlight=3 copy>
local p = {} -- Defines the empty (non-nil) table package, the only single-letter variable
function p.hello(frame) -- Define the function p.hello. The input parameter frame is not used
return "Hello World!" -- Returns the string result of the function.
end -- Ends the function
return p -- This returns the table package
</syntaxhighlight>
Note that <syntaxhighlight lang="lua" inline>function p.main(frame) ... end</syntaxhighlight> is equivalent to <syntaxhighlight lang="lua" inline>p.main = function(frame) ... end</syntaxhighlight> or <syntaxhighlight lang="lua" inline>p["main"] = function(frame) ... end</syntaxhighlight>. The function is just another type of value, retrieved with the key <code>"main"</code> from table <code>p</code>. If you want to allow users to invoke the same module with <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|hello}}</nowiki></code> instead of <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|main}}</nowiki></code>, you can write <code>p.hello = p.main</code> to copy the reference to this function to a new key in the table. You can even write <code>p[""] = p.main</code>, which causes <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|}}</nowiki></code> to produce the same output as <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|main}}</nowiki></code>. Learning to think of functions as a data type becomes very important later on for working with library functions like <code>[[mw:Extension:Scribunto/Lua_reference_manual#string.gsub|mw.ustring.gsub]]</code>, and constructing iterator functions.
== Lua program structure: Input ==
The '''<code>frame</code>''' parameter above (which is pretty much always given this name in Wikipedia Lua modules) receives another table, which is passed ''from'' the page that makes the call ''to'' the Lua module. It contains a surprising amount of stuff, of which just a few things concern the novice.
=== Arguments ===
{{see also|Module:Arguments}}
<code>frame.args</code> contains ''another'' table, namely, all the content sent by the user within the <code>#invoke</code> brackets except the first argument which states the name of the function to be executed.
In your User page: about [[Module:ConvertNumeric]]
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{#invoke:ConvertNumeric |numeral_to_english |57000 |round=on |plural=on}}
</syntaxhighlight></blockquote>
Click <code>Preview</code> or click <code>Edit</code> this section to see the call then <code>Cancel</code>:
<blockquote>
{{#invoke:ConvertNumeric |numeral_to_english |57000 |round=on |plural=on}}
</blockquote>
There are two types of parameters: numeric (positional) keys and named keys.
# Unnamed parameters come out with numbers as keys: <code>frame.args[1]</code>.<br/>The string <code>"57000"</code> is the content of <code>frame.args[1]</code> which is the same as <code>frame["args"][1]</code><br/>but ''not'' the same as <code>frame.args["1"]</code> or <code>frame["args"]["1"]</code>.
# Named parameters come out with the parameter names (strings) as keys: <code>frame.args["round"]</code>, <code>frame.args["plural"]</code>.
In Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=4 copy>
--[[Convert a number to letter in Sinhala]]--
local convNum = require('Module:ConvertNumeric')
local frame=mw.getCurrentFrame(); frame.args = {"57000", round="on", plural="on"}
print(convNum.numeral_to_english(frame) .. " is rounded from 57,000.")
local debugLog = {} -- empty report table
for key, val in pairs(frame.args) do -- for each arg
debugLog[#debugLog + 1] = ("args[%s] = %s"):format(key, val)
end -- ^length. Adding report is faster than string-based: debugLog = debugLog .. string
print(table.concat(debugLog, ". ")) -- Join with separator
mw.logObject(frame.args) -- Scribunto tool to display table
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=11>
හැට දහස is rounded from 57,000.
args[1] = 57000. args[plural] = on. args[round] = on
table#1 {
"57000",
["plural"] = "on",
["round"] = "on",
}
</syntaxhighlight></blockquote>
=== Parent frame ===
Within <code>frame</code> there is a ''parent'' frame, referring to the page that called the page that gives the script, and you can pull out arguments from that also. Just write:
<blockquote><syntaxhighlight lang="lua" line highlight=17 copy>
--[[Return true if table-like `tab` contains any non-nil entries]]--
local function has_any_args(tab)
if tab == nil then return false end -- the table is nil
for _, val in pairs(tab) do -- Iterates both numeric (positional) and string (named) keys.
if val ~= nil then -- value not nil?
return true -- one argument exists
end
end
return false -- The table does not have any arguments
end
--[[Debug console or template in wiki page?]]--
local booksPlural = "There are those books."; local pluralMarker = "s."
local globalSub = "mw.ustring.gsub(subjectStr,pattern,replace)" -- no space separator
local prm = {subjectStr=booksPlural, pattern=pluralMarker, replace=".", globalSub, "lua"}
local frame = mw.getCurrentFrame():newChild{title='Module:Lua call', args=prm}
local parent = frame:getParent() or nil
if not parent or not has_any_args(parent.args) then
print("Running from Debug console")
print(mw.text.listToText(frame.args))
else
print("Running from wiki page invoking {{template}}")
end
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=24>
Running from Debug console
mw.ustring.gsub(subjectStr,pattern,replace)
</syntaxhighlight></blockquote>
<syntaxhighlight lang="lua" inline>parent.args</syntaxhighlight> will contain those arguments.
It is popular in Lua to use the synonymous statement <code>parent=frame''':'''getParent()</code>, cancelling the need to write <code>frame</code> twice.<br/>
Note the colon (<code>:</code>) instead of the dot (<code>.</code>).
<syntaxhighlight lang="lua" inline>parent = frame:getParent()</syntaxhighlight> means exactly the same as <code>parent = frame.getParent(frame)</code>.
For novices this can be confusing, and it is important to be aware of this idiom.<br/>
If you use it in the wrong way, though, the script errors are pretty good at pointing out that this was the mistake.
== Basic debugging ==
{{Main|Help:Lua debugging}}
Debugging can start as soon as you write programs, and can be done simply with string concatenation.<br/>
Just set up a variable with some recognizable name like <syntaxhighlight lang="lua" inline>debugLog</syntaxhighlight> in your main <syntaxhighlight lang="lua" inline>function p.main(frame)</syntaxhighlight> with a statement like:
<blockquote><syntaxhighlight lang="lua" line start=3 highlight=1 copy>
local debugLog = "" -- empty report string
</syntaxhighlight></blockquote>
This initial <syntaxhighlight lang="lua" inline>""</syntaxhighlight> definition helps because otherwise it will be <syntaxhighlight lang="lua" inline>nil</syntaxhighlight> and concatenating a string to nil gets you an error.<br/>
Now whenever you have a variable you'd like to test, say {{tt|myVar}}, just write:
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=2 copy>
local myVar = 42; local output = "expected result"
debugLog = debugLog .. " myVar = " .. tostring(myVar) -- append to the report
</syntaxhighlight></blockquote>
At the end of your function (but not the module), complete:
<blockquote><syntaxhighlight lang="lua" line start=16 highlight=1 copy>
return output .. debugLog -- Returns the expected result and the report
</syntaxhighlight></blockquote>
The <syntaxhighlight lang="lua" inline>tostring(myVar)</syntaxhighlight> is a function to ensure {{tt|myVar}} is interpreted as a string.<br>
For a table, it will display as "{{samp|table}}". For nil, "{{samp|nil}}" rather than as Script error.
== Format ==
The [[WP:Lua style guide]] gives some basic formatting suggestions expected by the JavaScript module editor, such as using four-space indentations and keeping <syntaxhighlight lang="lua" inline>if then else</syntaxhighlight>, <syntaxhighlight lang="lua" inline>end</syntaxhighlight> at the same level of indentation.
Comments to the end of a line are marked by <syntaxhighlight lang="lua" inline>-- green comment</syntaxhighlight>. ''Use them.''
Many modules for Wikipedia have a straightforward, linear design, but that doesn't mean it won't help to have your sections clearly labelled when you go back to the code for the hundredth time. The Lua style guide gives additional recommendations for using functions to keep your work more organized.
== Errors ==
Lua errors appear as red "Script error" messages. If Javascript is enabled, '''the <span style="color:#ff0000;">red</span> script error message is a link''' which usually allows you to follow it back to the line in the module where the error occurred. There are some exceptions, for example "Module not found", if the name of the module itself is mistyped, or "The function you specified did not exist" if the function name given is invalid.
=== Recurrent bugs ===
Some bugs you might want to keep in mind:
;Missing operator for concatenation
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=2 copy>
local debugLog = "" -- empty report string
debugLog = debugLog "missing double dot" -- append to the report
</syntaxhighlight></blockquote>
The following means you forgot the <code>..</code> between a string and a variable somewhere in a mess of stuff you're concatenating.
<blockquote><syntaxhighlight lang="lua" line start=9>
Lua error in console input at line 8: attempt to call local 'debugLog' (a string value).
</syntaxhighlight></blockquote>
;String expected, got function
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=3 copy>
local debugLog = "" -- empty report string
local res = mw.ustring.gmatch("Hello World!", "([aeiouAEIOU])") -- iterator of vowels
debugLog = debugLog..res -- populate the report with only strings
</syntaxhighlight></blockquote>
Some important things like <syntaxhighlight lang="lua" inline>mw.ustring.gmatch</syntaxhighlight> actually return ''functions'', not strings - see [[#Functions|Functions]] below.
<blockquote><syntaxhighlight lang="lua" line start=10>
Lua error in console input at line 9: attempt to concatenate local 'res' (a function value).
</syntaxhighlight></blockquote>
;Variable ignores assignment
A variable ignores all your efforts to assign stuff to it:
<blockquote><syntaxhighlight lang="lua" line highlight=1,3 copy>
local debugLog = "top level" -- initial value
do
local debugLog = "nested level" -- set the new value
print("Inside do: "..debugLog)
end
print("Outside do: "..debugLog) -- get the old value
</syntaxhighlight></blockquote>
You may have inadvertently written ''two'' local statements - the one sets the value of the variable within a limited region, and when the program leaves that region, you're back to the old value.
<blockquote><syntaxhighlight lang="lua" line start=7>
Inside do: nested level
Outside do: top level
</syntaxhighlight></blockquote>
A numbered table entry ignores all your efforts to assign to it:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local table = {}; local arg = "50"; local valPrm = tonumber(arg)
table[arg] = "index as string"
table[valPrm] = "index as number"
print(table[arg] == table[valPrm])
</syntaxhighlight></blockquote>
This is because {{code|table["50"]}} '''is not''' {{code|table[50]}}.<br/>
Typically you have processed a parameter (which you may have received from the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> as a string) with string functions in one place,<br>
but performed numeric operations in another, leaving you with two different types of variable to use for an index.
<blockquote><syntaxhighlight lang="lua" line start=5>
false
</syntaxhighlight></blockquote>
;<syntaxhighlight lang="lua" inline>nil</syntaxhighlight> and common pitfalls
There are all sorts of things you can't do with a local variable set to nil, such as: <syntaxhighlight lang="lua" inline>local x = nil</syntaxhighlight>, like:
# Assign <code>x.somefield</code>
# Get value at index {{code|x[idx]}}
# Concatenate <syntaxhighlight lang="lua" inline>x .. "Cannot concatenate with nil"</syntaxhighlight>
# Evaluate <syntaxhighlight lang="lua" inline>table[x]</syntaxhighlight>
Initialize such variables with: <syntaxhighlight lang="lua" inline>local x={}; local table = {}</syntaxhighlight><br>
Often "global" is mentioned in these errors because you didn't have a {{tt|local}} statement for the <syntaxhighlight lang="lua" inline>nil</syntaxhighlight> variable.
;Cannot invoke module
* ''no such module.'' You called <syntaxhighlight lang="lua" inline>#invoke:moduleNameUnknown</syntaxhighlight> that didn't exist or you wrongly kept the prefix <code>Module:</code> writing {{code|#invoke:Module:moduleName}}.
* ''the function specified did not exist.'' You called <syntaxhighlight lang="lua" inline>#invoke:moduleName|functionUnknown</syntaxhighlight>, but the field after the name of the module is wrong.<br>Often this field expects a standard name like "main", and you've forgotten it and gone straight to the first data parameter.<br>If you're unsure of the function name, check the module documentation, or look for what function(s) in the code accept a "frame" parameter.
;Graphics overflow issue
Some graphics you're trying to display are heading off to the hills: actually a HTML error.<br>
You didn't close one <syntaxhighlight lang="html" inline></div></syntaxhighlight>, so all the top: and left: styles keep adding up.
== Understanding tables and related concepts ==
* An '''expression list''' is a set of values separated by commas. The values can be strings, numbers, tables, functions, etc.
* A '''sequence''' is a set of entries with indices from 1 to N, where N is a positive integer. They can be created by placing brackets around an expression list.
For example:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local seq = {1, "quotation", mw.ustring.gmatch("abca","a"), {2,3,4}}
mw.logObject(seq) -- Scribunto tool to display a table
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
table#1 {
1,
"quotation",
function#1,
table#2 {
2,
3,
4,
},
}
</syntaxhighlight></blockquote>
# <code>seq[1]</code> = 1
# <code>seq[2]</code> = <syntaxhighlight lang="lua" inline>"quotation"</syntaxhighlight>
# <code>seq[3]</code> is the <syntaxhighlight lang="lua" inline>function</syntaxhighlight> returned by <code>gmatch()</code>
# <code>seq[4]</code> is the table <code>{2,3,4}</code>.
An expression list can also be recovered from a table using <syntaxhighlight lang="lua" inline>unpack()</syntaxhighlight>:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local seq = {1, "quotation", mw.ustring.gmatch("abca","a"), {2,3,4}}
local var1Nbr, var2Str, var3Fct = unpack(seq)
print(("var1Nbr = %d. var2Str = \"%s\". var3Fct = %s"):format(var1Nbr, var2Str, type(var3Fct)))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=4>
var1Nbr = 1. var2Str = "quotation". var3Fct = function
</syntaxhighlight></blockquote>
This will set:
# <code>var1Nbr</code> = 1
# <code>var2Str</code> = <syntaxhighlight lang="lua" inline>"quotation"</syntaxhighlight>
# <code>var3Fct</code> as the <syntaxhighlight lang="lua" inline>function</syntaxhighlight> returned by <code>gmatch()</code>
# <code>{2,3,4}</code> will be discarded in this case.
* A '''table''' is a sequence, optionally supplemented by named keys: <code>digit["two"]="2"</code>. Several table functions like <code>table.concat</code> will only work with the numbered values and ignore named keys.
* The '''metatable''' offers a large, optional set of methods for altering table behavior. For example, you can define a table to be callable like a function.
=== Initializing a table ===
It is often useful to create a whole table at once in a statement. There are many equivalent ways to do this, but the shortcuts don't work for every kind of value. To begin with, the most general way is to assign each key and value explicitly:
<syntaxhighlight lang="lua" inline>a = {[0]='zero', [1]='one', ['1']='string for one'}</syntaxhighlight>
If sequence keys (positive integers) are given in order, only the values need to be given, so the following will assign <syntaxhighlight lang="lua" inline>'one'</syntaxhighlight> to <syntaxhighlight lang="lua" inline>a[1]</syntaxhighlight>:
<syntaxhighlight lang="lua" inline>a = {[0]='zero', 'one', ['1']='string for one'}</syntaxhighlight>
If a key has only letters, digits, and underscores, and begins with a non-digit, the brackets and quotation marks can be omitted:
<syntaxhighlight lang="lua" inline>a = {a='one', b='two'}</syntaxhighlight>
This is identical to <syntaxhighlight lang="lua" inline>a = {["a"]='one', ["b"]='two'}</syntaxhighlight>.
However, this will fail for keys that begin with a digit: <syntaxhighlight lang="lua" inline>hex = {7f = 127}</syntaxhighlight> will produce an error; use <syntaxhighlight lang="lua" inline>hex = {['7f'] = 127}</syntaxhighlight> instead.
Note that when given ''within'' brackets, or to the right of the equal sign, quotation marks are needed, or else string values will be taken as variables:
<syntaxhighlight lang="lua" inline> a = {[b] = c}</syntaxhighlight>
assigns the value of variable ''c'' to the key ''contained in variable'' ''b''.
== Functions ==
* Functions can return any kind of value {{--}} ''including a function''. This is a powerful feature that can readily confuse the beginner. If you set <syntaxhighlight lang="lua" inline>a=mw.ustring.gmatch(text, "(.)")</syntaxhighlight>, the result assigned to <code>a</code> will be a '''function''', not a string character! However, assigning <code>b=a()</code> by calling the function stored in <code>a</code> will return the first match (a string). Every time you set <code>b=a()</code> after that you'll get another match (string) into <code>b</code>, until you run out of matches and get <code>nil</code>. Many '''iterator functions''' act this way.
* You can keep separate counts for iterator functions by using different variables. For example, if you set <syntaxhighlight lang="lua" inline>q=mw.ustring.gmatch(text, "(x.)")</syntaxhighlight> in the same module, you can pull characters from the same piece of text (<code>text</code>) by evaluating <code>d=q()</code> without losing your place in <code>a()</code>.
* [[tail call|Tail calls]] offer substantial benefits in performance for those who master the language.
* Function names are often of the form {{code|p.myFunctionName}}, where p is the table from the {{code|return p}} at the bottom of your program. The reason for this is that you can only access functions that are entries in this table from the original {{code|#invoke}} statement. Functions for local use within the program can have any name.
== Understanding patterns ==
''Note:'' Lua patterns are ''not'' [[regular expression|regular expressions]] in the traditional POSIX sense, and they are not even a subset of regular expressions. But they share many constructs with regular expressions (more [[Help:Lua for beginners#regex|below]]).
Lua patterns are used to define, find and handle a ''pattern'' in a string. It can do the common search and replace action in a text, but it has more options that doing plain text only. For example, in one go it can change the errors 'New yorker', 'New-Yorker', and 'NewYorker' into 'New Yorker'.
* To begin with, a pattern works like a plain string so long as it doesn't contain the special characters {{code|^ $ () % . [] * + - ?}}
* Square brackets {{code|[ ]}} are used to match ''one'' ''single character'' in the string from a list of choices. {{code|[abc]}} matches the letters a, b, or c. With {{code|^}} right after {{code|[}} they indicate "anything but": {{code|[^abc]}} = not a, b, or c. Inside brackets and when not the first character, a minus {{code|-}}indicates a range: {{code|[a-z]}} matches one single character from a, b, c, …, z.
* Period {{code|.}} matches any character.
* Percent {{code|%}} indicates a large set (class) of possible character matches when it is followed by a letter. See [https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Character_class] for a full list. <!--- should test/list these empirically to be sure ---> When followed by punctuation (whether a special character above or not) the {{code|%}} is removed and the punctuation is taken as a literal character; {{code|%%}} = literal %. Special classes include a balanced class {{code|%bxy}} and {{code|%f[set]}}; see the link above for more.
* Parentheses {{code|( )}} indicate captures. The captures can be accessed later in the search string or in the string.gsub replacement string as {{code|%1}} to {{code|%9}}, and are returned by string.match as an expression list of results.
* The qualifiers {{code|? - * +}} specify repetitions of a single character (not a longer string).
:* {{code|?}} means 0 or 1 repetitions: {{code|a?}} matches "a" or "".
:* {{code|-}} means 0 or more repetitions, choosing as few as possible to achieve a match ("non-greedy"). For example {{code|2=lua|string.match("bbbb", "(.-)")}} yields "", which is less than useful because there is nothing to root the ends of the expression and prevent it from matching zero characters.
:* {{code|*}} means 0 or more repetitions, choosing as many as possible ("greedy"). For example {{code|2=lua|string.match("bbbb", ".*")}} yields bbbb.
:* {{code|+}} means 1 or more repetitions, choosing as many as possible ("greedy").
Note that the greediness of the ''leftmost'' qualifier rules over all others when there is a choice: {{code|(.*)b(.*)}} when matched on "bbb" will return "bb", "", while {{code|a(.-)b(.-)a}} when matched on "abbba" will return "", "bb".
* {{code|^}} and {{code|$}} indicate the beginning and end of the string if they occur in the appropriate place in the pattern. Otherwise they are literal characters. {{code|^}} is not used in the {{code|string.gmatch}} function.
The reference manual for Lua patterns is at [[:mw:Extension:Scribunto/Lua_reference_manual#Patterns|mediawiki.org]].
== {{anchor|regex}}Note on Lua patterns versus regular expressions ==
Lua patterns are ''loosely based'' on [[regular expression]]s (sometimes shortened to regex or regexp). Lua patterns deliberately lack the most complex regular expression constructs (to avoid bloating the Lua code base), where many other computer languages or libraries use a more complete set. Lua patterns are not even a subset of regular expressions, as there are also discrepancies, like Lua using the escape character <code>%</code> instead of <code>\,</code>, and additions, like Lua providing <code>-</code> as a non-greedy version of <code>*</code>.
Here is a list of some of the things that Lua patterns lack compared to regular expressions:
* You '''cannot''' search for alternations between anything else than single characters (you '''cannot''' say <code>(his|her)</code> to choose between <code>his</code> and <code>her</code>, you can only say <code>[abc]</code> to choose between single characters <code>a</code>, <code>b</code>, or <code>c</code>).
* You '''cannot''' look for multiples of multi-letter constructs such as <code>(choo-)*choo</code> to match <code>choo</code>, <code>choo-choo</code> or <code>choo-choo-choo</code>. There is no way to do this with Lua patterns.
* You '''cannot''' specify the minimum and maximum number of repetitions like <code>[0-9]{3,5}</code> (to match 3 to 5 digits); in Lua you would say <code>%d%d%d%d?%d?</code> instead in this case.
There are Lua libraries that offer more powerful options,<sup>[http://lua-users.org/wiki/PatternsTutorial]</sup> including regular expressions, but the support on Wikipedia is pretty basic.
Wikipedia help for regular expressions (which Lua, as mentioned, does ''not'' support) is at [[Wikipedia:AutoWikiBrowser/Regular expression]].
{{Wikipedia technical help|collapsed}}
[[Category:Module help|*]]
30ksm117hx0zl4p11j55ee3495cnsoo
790923
790921
2026-05-19T18:50:02Z
Nimmzo
78995
/* Lua program structure: Output */ Moved to the end the complex minimal module return about regex. The goal is to highlight the above simplified structure of [[Module:Example]]. The idea is to delete soon "However, things are *not* usually done this way." because it is an exception.
790923
wikitext
text/x-wiki
{{WikiProject Lua header}}
{{Selfref|This help page is meant to provide some basic orientation for those new to Lua/Scribunto.}}
{{ඉංග්රීසි ව්යාපෘතියේ සිට ආයාත කළ පිටුව}}
== Overview ==
[[WP:Lua|Lua]] is a lightweight scripting language safely available on Wikipedia via [[mw:Extension:Scribunto|Scribunto]]. Its purpose is to allow you to process the data which is available on Wikipedia content pages to allow various sorts of customized display of information.
It runs in a sandboxed environment to protect the stability of Wikipedia while enabling powerful <syntaxhighlight lang="lua" inline>{{template}}</syntaxhighlight> and <syntaxhighlight lang="lua" inline>module:</syntaxhighlight> functionality.
The most important help file is the [[mw:Extension:Scribunto/Lua reference manual|MediaWiki Scribunto Lua reference manual]], which provides a concise summary of the language and standard library calls as implemented on MediaWiki.
The standard [http://www.lua.org/manual/5.1/manual.html Lua reference manual] is well written and comprehensive, but it can be confusing for beginners because some standard features don't work on wiki pages. You cannot call <syntaxhighlight lang="lua" inline>print("Hello, World!")</syntaxhighlight> in a module, but you can preview your User page showing the string <syntaxhighlight lang="lua" inline>"Hello World!"</syntaxhighlight> generated by the Lua [[Module:Example]]. Think of your Lua template as an HTML generator.
=== Generating "Hello World!" ===
You do not need to install or save anything.
# Edit your User page: <code>පරිශීලක:YourUserName</code>
# Paste the following call at the beginning of a new line on your User page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{#invoke:Example|hello}}
</syntaxhighlight></blockquote>
<ol start="3">
<li>Click <code>Preview</code>. The call of the function <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> in the [[Module:Example]] is replaced with the following:</li>
</ol>
<blockquote><syntaxhighlight lang="lua" line>
Hello World!
</syntaxhighlight></blockquote>
<ol start="4">
<li>Click <code>Cancel</code>. When prompted, click <code>Leave</code>.</li>
<li>Your User page remains '''un'''modified.</li>
</ol>
== Debug console: Start learning Lua ==
The Lua Scribunto <code>Debug Console</code> is a safe, interactive tool for learning Lua in Wikipedia.
# Click <code>Edit</code> on the [[Module:Yesno]] page.
# Scroll to the bottom of the page to the <code>Debug console</code> section beneath the Lua editor.
# Paste the comment and the call into the <span style="color:#86888c;">gray</span> input box (above the <code>Clear</code> button).
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
--[[ඔබගේ ආරම්භක Lua "හෙලෝ වර්ල්ඩ්" යන වගේම වැඩසටහන]]--
print("වෙල්කම් වෙයි " .. _VERSION .. "!") -- Lua අනුවාදය .. සමඟ එකතු කරයි
</syntaxhighlight></blockquote>
<ol start="4">
<li>Press {{key press|Enter}} once to execute the two Lua command''s''.</li>
<li>The result will appear below the Lua <syntaxhighlight lang="lua" inline>print</syntaxhighlight> command line:</li>
</ol>
<blockquote><syntaxhighlight lang="lua" line start=3>
වෙල්කම් වෙයි Lua 5.1!
</syntaxhighlight></blockquote>
<ol start="6">
<li>Press <code>Up arrow</code> (↑) to cycle through previous Lua commands.</li>
<li>Optionally, click <code>Clear</code> to clear ''only'' the <code>Debug Console</code>; the Lua editor above will remain '''un'''modified.</li>
</ol>
; HTML generator in the Debug console
Call the function <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> in <code>Module:</code>Example:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local modExample = require('Module:Example') -- load the module in Debug console
local frame = mw.getCurrentFrame(); print(modExample.hello(frame)) -- display "Hello World!"
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
Hello World!
</syntaxhighlight></blockquote>
; Identity function
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local yesno = require('Module:Yesno') -- #if yesno then returns its input parameter
print(mw.getCurrentFrame():callParserFunction("#if", yesno("Yes"), "Yes", 'නැහැ'))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
Yes
</syntaxhighlight></blockquote>
# Close the protected <code>Module:</code>Yesno that remains '''un'''modified.
== Issues with the current implementation ==
Besides the lack of <code>print()</code> in a module, there are other features missing – see [[mw:Extension:Scribunto/Lua reference manual#Differences from standard Lua|Differences from standard Lua]] for a complete list.
At the present time, it is advisable to use ''[[mw:Extension:Scribunto/Lua reference manual#Ustring library|mw.ustring]]'' functions instead of ''[[mw:Extension:Scribunto/Lua reference manual#String library|string]]'', because the latter sometimes fails with Unicode characters.
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local lang = mw.getCurrentFrame():callParserFunction("#language", "si") -- Sinhala
local lenUnicode, lenByte, lenSharp = mw.ustring.len(lang), string.len(lang), #lang
print(("lang: %s Mw.ustring.len = %d String.len = %d Sharp = %d"):format(lang, lenUnicode, lenByte, lenSharp))
</syntaxhighlight></blockquote>
Debug console supports Unicode:
<blockquote><syntaxhighlight lang="lua" line start=4>
lang: සිංහල Mw.ustring.len = 5 String.len = 15 Sharp = 15
</syntaxhighlight></blockquote>
== Input ==
The programs are run only when the page is "parsed" (when it or a page it incorporates is changed or previewed), not every time you view the output. Therefore there can be no convenient Lua module that allows you to type in a Fahrenheit temperature in an input box and get back the corresponding Celsius temperature when you press a button, or allows you to click on a segment of a Mandelbrot set visualization on a page to expand it as often as you like. There has to be an actual Wiki page (or at least a page you have submitted for preview) containing the input data.
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local function toCelsius(tempFahrenheit) return (tempFahrenheit - 32) * 5 / 9 end
print(("toCelsius(32°F) = %s°C. toCelsius(68°F) = %d°C"):format(toCelsius(32), toCelsius(68)))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
toCelsius(32°F) = 0°C. toCelsius(68°F) = 20°C
</syntaxhighlight></blockquote>
However, it is possible to use library functions like [[mw:Extension:Scribunto/Lua reference manual#mw.title.getCurrentTitle|mw.title.getCurrentTitle()]] to import content from any text content page on the Wiki.
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
print(mw.title.getCurrentTitle())
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=2>
Module:Yesno
</syntaxhighlight></blockquote>
You cannot, however, import data from files, not even .svg files which contain XML text data.
== Calling a Lua module ==
Lua calls look much like [[WP:template|template]]s, and consist of a small block of text.
In your User page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{ConvertNumeric|decToHex|73}}
</syntaxhighlight></blockquote>
Click <code>Preview</code> or click <code>Edit</code> this section to see the call then <code>Cancel</code>:
<blockquote>
{{#invoke:ConvertNumeric|decToHex|73}}
</blockquote>
This text calls the Lua script itself, which is housed in the <code>Module:</code> [[WP:namespace|namespace]]. The effect of this call is to send the information within the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> block to the Lua module, and to replace everything within the brackets with a piece of text that it sends back in return. (Literally, in the "return" statement)
Note that the first "parameter", in this case <code>decToHex</code>, is actually a <syntaxhighlight lang="lua" inline>function</syntaxhighlight> called within the Lua module. This field must always be included in any <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight>. To those unfamiliar with modules, especially Wikipedia template coders who expect anything after <code>|</code> to be a parameter, the need for this extra field is surprising, especially if all uses of the module depend on its presence.
In Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local convNum = require('Module:ConvertNumeric')
local frame = mw.getCurrentFrame(); frame.args[1] = "73" -- number always as string
print(("0x%s = %s = %d"):format(convNum.decToHex(frame), string.format("0x%X", 73), 0x49))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=4>
0x49 = 0x49 = 73
</syntaxhighlight></blockquote>
=== Documenting a Lua module ===
When documenting your module, it is useful to include an explicit usage instruction using [[සැකිල්ල:Module link expanded]]:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{mlx|ConvertNumeric|decToHex|73}}
</syntaxhighlight></blockquote>
Hyperlink to the module:
<blockquote>
{{mlx|ConvertNumeric|decToHex|73}}
</blockquote>
For many existing modules, an example <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> of the script (and little else) is provided on the <code>Module talk:</code> page. It is convenient for authors to be able to flip quickly to the talk tab to look at the effects of their changes, but you should never transclude the talk page as a template - people might actually talk on it! Alternatively, the module page can show documentation from a separate /doc-page (as [[Module:WikidataIB]] does).
=== Another example: Using LuaCall to perform a single Lua instruction ===
As a beginner, or in casual talk page conversation, you might only have one little calculation you want to use Lua for but don't want to write a full module. You might find [[Module:LuaCall]] convenient for this. For example, you can test how a greedy [https://www.lua.org/pil/20.1.html Lua pattern] works:
* <syntaxhighlight lang="lua" inline>{{#invoke:LuaCall|main|a=bbbbbbbbbba|b=bb(.*)b(.+)bba|string.match(a,b)}}</syntaxhighlight> → <code>{{#invoke:LuaCall|main|a=bbbbbbbbbba|b=bb(.*)b(.+)bba|string.match(a,b)}}</code>
or count up the length of a [[wikipedia:Did you know|''Did you know'']] hook or the text portion of a ''Did you know'' candidate:
* <syntaxhighlight lang="lua" inline>{{#invoke:LuaCall|main|a=... that you can count the length of your DYK hook with a Lua module?|string.len(a)}}</syntaxhighlight>→ <code>{{#invoke:LuaCall|main|a=... that you can count the length of your DYK hook with a Lua module?|string.len(a)}}</code>
In these specific examples, however, [[Module:String]] could do both of these tasks.
The script at [[Module:LuaCall]] has been written to accept any set of named parameters <code>somename=value</code>, for each one storing the string <code>value</code> in the variable with the name <code>somename</code>, and then allowing you to use these variables as parameters for any function available in Lua. The script then returns only the ''first'' value returned by the function ([https://www.lua.org/pil/5.1.html Lua functions can return multiple values], but in this case, only the first is returned from the module).
== Lua program structure: Output ==
The most fundamental part of a Wikipedia Lua program is a '''return''' statement which carries its output back to the page that had the <code>#invoke</code>. You ''can'' have a Lua function that runs without error even though it doesn't contain a return statement, but on Wikipedia it is pointless, as Lua programs cannot generally have side effects on Wikipedia.
The module itself must return a Lua '''table''' of values. A Lua table is expressed as a list of values separated by commas, within curly braces. When the module is called by <code>#invoke</code>, the '''function''' it names (the first argument after |) is looked for in that table. That function, in turn, is expected to return something that can be represented as a '''string'''.
Typically we use the overall form for [[Module:Example]]:
<syntaxhighlight lang="lua" line highlight=3 copy>
local p = {} -- Defines the empty (non-nil) table package, the only single-letter variable
function p.hello(frame) -- Define the function p.hello. The input parameter frame is not used
return "Hello World!" -- Returns the string result of the function.
end -- Ends the function
return p -- This returns the table package
</syntaxhighlight>
Note that <syntaxhighlight lang="lua" inline>function p.main(frame) ... end</syntaxhighlight> is equivalent to <syntaxhighlight lang="lua" inline>p.main = function(frame) ... end</syntaxhighlight> or <syntaxhighlight lang="lua" inline>p["main"] = function(frame) ... end</syntaxhighlight>. The function is just another type of value, retrieved with the key <code>"main"</code> from table <code>p</code>. If you want to allow users to invoke the same module with <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|hello}}</nowiki></code> instead of <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|main}}</nowiki></code>, you can write <code>p.hello = p.main</code> to copy the reference to this function to a new key in the table. You can even write <code>p[""] = p.main</code>, which causes <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|}}</nowiki></code> to produce the same output as <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|main}}</nowiki></code>. Learning to think of functions as a data type becomes very important later on for working with library functions like <code>[[mw:Extension:Scribunto/Lua_reference_manual#string.gsub|mw.ustring.gsub]]</code>, and constructing iterator functions.
Therefore, <syntaxhighlight lang="lua" inline>return { mw.ustring.gmatch( "Hello world", "(.*)" ) }</syntaxhighlight> is actually a complete Lua module (though a very strange one) - it returns the function returned by mw.ustring.gmatch (an iterator function listed in the Lua reference cited above) as the one and only element in an array (represented within <code>{}</code>)—which when executed using <syntaxhighlight lang="wikitext" inline>{{#invoke:ModuleName|1}}</syntaxhighlight> yields the string "Hello world". ''However'', things are not usually done this way.
== Lua program structure: Input ==
The '''<code>frame</code>''' parameter above (which is pretty much always given this name in Wikipedia Lua modules) receives another table, which is passed ''from'' the page that makes the call ''to'' the Lua module. It contains a surprising amount of stuff, of which just a few things concern the novice.
=== Arguments ===
{{see also|Module:Arguments}}
<code>frame.args</code> contains ''another'' table, namely, all the content sent by the user within the <code>#invoke</code> brackets except the first argument which states the name of the function to be executed.
In your User page: about [[Module:ConvertNumeric]]
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{#invoke:ConvertNumeric |numeral_to_english |57000 |round=on |plural=on}}
</syntaxhighlight></blockquote>
Click <code>Preview</code> or click <code>Edit</code> this section to see the call then <code>Cancel</code>:
<blockquote>
{{#invoke:ConvertNumeric |numeral_to_english |57000 |round=on |plural=on}}
</blockquote>
There are two types of parameters: numeric (positional) keys and named keys.
# Unnamed parameters come out with numbers as keys: <code>frame.args[1]</code>.<br/>The string <code>"57000"</code> is the content of <code>frame.args[1]</code> which is the same as <code>frame["args"][1]</code><br/>but ''not'' the same as <code>frame.args["1"]</code> or <code>frame["args"]["1"]</code>.
# Named parameters come out with the parameter names (strings) as keys: <code>frame.args["round"]</code>, <code>frame.args["plural"]</code>.
In Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=4 copy>
--[[Convert a number to letter in Sinhala]]--
local convNum = require('Module:ConvertNumeric')
local frame=mw.getCurrentFrame(); frame.args = {"57000", round="on", plural="on"}
print(convNum.numeral_to_english(frame) .. " is rounded from 57,000.")
local debugLog = {} -- empty report table
for key, val in pairs(frame.args) do -- for each arg
debugLog[#debugLog + 1] = ("args[%s] = %s"):format(key, val)
end -- ^length. Adding report is faster than string-based: debugLog = debugLog .. string
print(table.concat(debugLog, ". ")) -- Join with separator
mw.logObject(frame.args) -- Scribunto tool to display table
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=11>
හැට දහස is rounded from 57,000.
args[1] = 57000. args[plural] = on. args[round] = on
table#1 {
"57000",
["plural"] = "on",
["round"] = "on",
}
</syntaxhighlight></blockquote>
=== Parent frame ===
Within <code>frame</code> there is a ''parent'' frame, referring to the page that called the page that gives the script, and you can pull out arguments from that also. Just write:
<blockquote><syntaxhighlight lang="lua" line highlight=17 copy>
--[[Return true if table-like `tab` contains any non-nil entries]]--
local function has_any_args(tab)
if tab == nil then return false end -- the table is nil
for _, val in pairs(tab) do -- Iterates both numeric (positional) and string (named) keys.
if val ~= nil then -- value not nil?
return true -- one argument exists
end
end
return false -- The table does not have any arguments
end
--[[Debug console or template in wiki page?]]--
local booksPlural = "There are those books."; local pluralMarker = "s."
local globalSub = "mw.ustring.gsub(subjectStr,pattern,replace)" -- no space separator
local prm = {subjectStr=booksPlural, pattern=pluralMarker, replace=".", globalSub, "lua"}
local frame = mw.getCurrentFrame():newChild{title='Module:Lua call', args=prm}
local parent = frame:getParent() or nil
if not parent or not has_any_args(parent.args) then
print("Running from Debug console")
print(mw.text.listToText(frame.args))
else
print("Running from wiki page invoking {{template}}")
end
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=24>
Running from Debug console
mw.ustring.gsub(subjectStr,pattern,replace)
</syntaxhighlight></blockquote>
<syntaxhighlight lang="lua" inline>parent.args</syntaxhighlight> will contain those arguments.
It is popular in Lua to use the synonymous statement <code>parent=frame''':'''getParent()</code>, cancelling the need to write <code>frame</code> twice.<br/>
Note the colon (<code>:</code>) instead of the dot (<code>.</code>).
<syntaxhighlight lang="lua" inline>parent = frame:getParent()</syntaxhighlight> means exactly the same as <code>parent = frame.getParent(frame)</code>.
For novices this can be confusing, and it is important to be aware of this idiom.<br/>
If you use it in the wrong way, though, the script errors are pretty good at pointing out that this was the mistake.
== Basic debugging ==
{{Main|Help:Lua debugging}}
Debugging can start as soon as you write programs, and can be done simply with string concatenation.<br/>
Just set up a variable with some recognizable name like <syntaxhighlight lang="lua" inline>debugLog</syntaxhighlight> in your main <syntaxhighlight lang="lua" inline>function p.main(frame)</syntaxhighlight> with a statement like:
<blockquote><syntaxhighlight lang="lua" line start=3 highlight=1 copy>
local debugLog = "" -- empty report string
</syntaxhighlight></blockquote>
This initial <syntaxhighlight lang="lua" inline>""</syntaxhighlight> definition helps because otherwise it will be <syntaxhighlight lang="lua" inline>nil</syntaxhighlight> and concatenating a string to nil gets you an error.<br/>
Now whenever you have a variable you'd like to test, say {{tt|myVar}}, just write:
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=2 copy>
local myVar = 42; local output = "expected result"
debugLog = debugLog .. " myVar = " .. tostring(myVar) -- append to the report
</syntaxhighlight></blockquote>
At the end of your function (but not the module), complete:
<blockquote><syntaxhighlight lang="lua" line start=16 highlight=1 copy>
return output .. debugLog -- Returns the expected result and the report
</syntaxhighlight></blockquote>
The <syntaxhighlight lang="lua" inline>tostring(myVar)</syntaxhighlight> is a function to ensure {{tt|myVar}} is interpreted as a string.<br>
For a table, it will display as "{{samp|table}}". For nil, "{{samp|nil}}" rather than as Script error.
== Format ==
The [[WP:Lua style guide]] gives some basic formatting suggestions expected by the JavaScript module editor, such as using four-space indentations and keeping <syntaxhighlight lang="lua" inline>if then else</syntaxhighlight>, <syntaxhighlight lang="lua" inline>end</syntaxhighlight> at the same level of indentation.
Comments to the end of a line are marked by <syntaxhighlight lang="lua" inline>-- green comment</syntaxhighlight>. ''Use them.''
Many modules for Wikipedia have a straightforward, linear design, but that doesn't mean it won't help to have your sections clearly labelled when you go back to the code for the hundredth time. The Lua style guide gives additional recommendations for using functions to keep your work more organized.
== Errors ==
Lua errors appear as red "Script error" messages. If Javascript is enabled, '''the <span style="color:#ff0000;">red</span> script error message is a link''' which usually allows you to follow it back to the line in the module where the error occurred. There are some exceptions, for example "Module not found", if the name of the module itself is mistyped, or "The function you specified did not exist" if the function name given is invalid.
=== Recurrent bugs ===
Some bugs you might want to keep in mind:
;Missing operator for concatenation
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=2 copy>
local debugLog = "" -- empty report string
debugLog = debugLog "missing double dot" -- append to the report
</syntaxhighlight></blockquote>
The following means you forgot the <code>..</code> between a string and a variable somewhere in a mess of stuff you're concatenating.
<blockquote><syntaxhighlight lang="lua" line start=9>
Lua error in console input at line 8: attempt to call local 'debugLog' (a string value).
</syntaxhighlight></blockquote>
;String expected, got function
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=3 copy>
local debugLog = "" -- empty report string
local res = mw.ustring.gmatch("Hello World!", "([aeiouAEIOU])") -- iterator of vowels
debugLog = debugLog..res -- populate the report with only strings
</syntaxhighlight></blockquote>
Some important things like <syntaxhighlight lang="lua" inline>mw.ustring.gmatch</syntaxhighlight> actually return ''functions'', not strings - see [[#Functions|Functions]] below.
<blockquote><syntaxhighlight lang="lua" line start=10>
Lua error in console input at line 9: attempt to concatenate local 'res' (a function value).
</syntaxhighlight></blockquote>
;Variable ignores assignment
A variable ignores all your efforts to assign stuff to it:
<blockquote><syntaxhighlight lang="lua" line highlight=1,3 copy>
local debugLog = "top level" -- initial value
do
local debugLog = "nested level" -- set the new value
print("Inside do: "..debugLog)
end
print("Outside do: "..debugLog) -- get the old value
</syntaxhighlight></blockquote>
You may have inadvertently written ''two'' local statements - the one sets the value of the variable within a limited region, and when the program leaves that region, you're back to the old value.
<blockquote><syntaxhighlight lang="lua" line start=7>
Inside do: nested level
Outside do: top level
</syntaxhighlight></blockquote>
A numbered table entry ignores all your efforts to assign to it:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local table = {}; local arg = "50"; local valPrm = tonumber(arg)
table[arg] = "index as string"
table[valPrm] = "index as number"
print(table[arg] == table[valPrm])
</syntaxhighlight></blockquote>
This is because {{code|table["50"]}} '''is not''' {{code|table[50]}}.<br/>
Typically you have processed a parameter (which you may have received from the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> as a string) with string functions in one place,<br>
but performed numeric operations in another, leaving you with two different types of variable to use for an index.
<blockquote><syntaxhighlight lang="lua" line start=5>
false
</syntaxhighlight></blockquote>
;<syntaxhighlight lang="lua" inline>nil</syntaxhighlight> and common pitfalls
There are all sorts of things you can't do with a local variable set to nil, such as: <syntaxhighlight lang="lua" inline>local x = nil</syntaxhighlight>, like:
# Assign <code>x.somefield</code>
# Get value at index {{code|x[idx]}}
# Concatenate <syntaxhighlight lang="lua" inline>x .. "Cannot concatenate with nil"</syntaxhighlight>
# Evaluate <syntaxhighlight lang="lua" inline>table[x]</syntaxhighlight>
Initialize such variables with: <syntaxhighlight lang="lua" inline>local x={}; local table = {}</syntaxhighlight><br>
Often "global" is mentioned in these errors because you didn't have a {{tt|local}} statement for the <syntaxhighlight lang="lua" inline>nil</syntaxhighlight> variable.
;Cannot invoke module
* ''no such module.'' You called <syntaxhighlight lang="lua" inline>#invoke:moduleNameUnknown</syntaxhighlight> that didn't exist or you wrongly kept the prefix <code>Module:</code> writing {{code|#invoke:Module:moduleName}}.
* ''the function specified did not exist.'' You called <syntaxhighlight lang="lua" inline>#invoke:moduleName|functionUnknown</syntaxhighlight>, but the field after the name of the module is wrong.<br>Often this field expects a standard name like "main", and you've forgotten it and gone straight to the first data parameter.<br>If you're unsure of the function name, check the module documentation, or look for what function(s) in the code accept a "frame" parameter.
;Graphics overflow issue
Some graphics you're trying to display are heading off to the hills: actually a HTML error.<br>
You didn't close one <syntaxhighlight lang="html" inline></div></syntaxhighlight>, so all the top: and left: styles keep adding up.
== Understanding tables and related concepts ==
* An '''expression list''' is a set of values separated by commas. The values can be strings, numbers, tables, functions, etc.
* A '''sequence''' is a set of entries with indices from 1 to N, where N is a positive integer. They can be created by placing brackets around an expression list.
For example:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local seq = {1, "quotation", mw.ustring.gmatch("abca","a"), {2,3,4}}
mw.logObject(seq) -- Scribunto tool to display a table
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
table#1 {
1,
"quotation",
function#1,
table#2 {
2,
3,
4,
},
}
</syntaxhighlight></blockquote>
# <code>seq[1]</code> = 1
# <code>seq[2]</code> = <syntaxhighlight lang="lua" inline>"quotation"</syntaxhighlight>
# <code>seq[3]</code> is the <syntaxhighlight lang="lua" inline>function</syntaxhighlight> returned by <code>gmatch()</code>
# <code>seq[4]</code> is the table <code>{2,3,4}</code>.
An expression list can also be recovered from a table using <syntaxhighlight lang="lua" inline>unpack()</syntaxhighlight>:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local seq = {1, "quotation", mw.ustring.gmatch("abca","a"), {2,3,4}}
local var1Nbr, var2Str, var3Fct = unpack(seq)
print(("var1Nbr = %d. var2Str = \"%s\". var3Fct = %s"):format(var1Nbr, var2Str, type(var3Fct)))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=4>
var1Nbr = 1. var2Str = "quotation". var3Fct = function
</syntaxhighlight></blockquote>
This will set:
# <code>var1Nbr</code> = 1
# <code>var2Str</code> = <syntaxhighlight lang="lua" inline>"quotation"</syntaxhighlight>
# <code>var3Fct</code> as the <syntaxhighlight lang="lua" inline>function</syntaxhighlight> returned by <code>gmatch()</code>
# <code>{2,3,4}</code> will be discarded in this case.
* A '''table''' is a sequence, optionally supplemented by named keys: <code>digit["two"]="2"</code>. Several table functions like <code>table.concat</code> will only work with the numbered values and ignore named keys.
* The '''metatable''' offers a large, optional set of methods for altering table behavior. For example, you can define a table to be callable like a function.
=== Initializing a table ===
It is often useful to create a whole table at once in a statement. There are many equivalent ways to do this, but the shortcuts don't work for every kind of value. To begin with, the most general way is to assign each key and value explicitly:
<syntaxhighlight lang="lua" inline>a = {[0]='zero', [1]='one', ['1']='string for one'}</syntaxhighlight>
If sequence keys (positive integers) are given in order, only the values need to be given, so the following will assign <syntaxhighlight lang="lua" inline>'one'</syntaxhighlight> to <syntaxhighlight lang="lua" inline>a[1]</syntaxhighlight>:
<syntaxhighlight lang="lua" inline>a = {[0]='zero', 'one', ['1']='string for one'}</syntaxhighlight>
If a key has only letters, digits, and underscores, and begins with a non-digit, the brackets and quotation marks can be omitted:
<syntaxhighlight lang="lua" inline>a = {a='one', b='two'}</syntaxhighlight>
This is identical to <syntaxhighlight lang="lua" inline>a = {["a"]='one', ["b"]='two'}</syntaxhighlight>.
However, this will fail for keys that begin with a digit: <syntaxhighlight lang="lua" inline>hex = {7f = 127}</syntaxhighlight> will produce an error; use <syntaxhighlight lang="lua" inline>hex = {['7f'] = 127}</syntaxhighlight> instead.
Note that when given ''within'' brackets, or to the right of the equal sign, quotation marks are needed, or else string values will be taken as variables:
<syntaxhighlight lang="lua" inline> a = {[b] = c}</syntaxhighlight>
assigns the value of variable ''c'' to the key ''contained in variable'' ''b''.
== Functions ==
* Functions can return any kind of value {{--}} ''including a function''. This is a powerful feature that can readily confuse the beginner. If you set <syntaxhighlight lang="lua" inline>a=mw.ustring.gmatch(text, "(.)")</syntaxhighlight>, the result assigned to <code>a</code> will be a '''function''', not a string character! However, assigning <code>b=a()</code> by calling the function stored in <code>a</code> will return the first match (a string). Every time you set <code>b=a()</code> after that you'll get another match (string) into <code>b</code>, until you run out of matches and get <code>nil</code>. Many '''iterator functions''' act this way.
* You can keep separate counts for iterator functions by using different variables. For example, if you set <syntaxhighlight lang="lua" inline>q=mw.ustring.gmatch(text, "(x.)")</syntaxhighlight> in the same module, you can pull characters from the same piece of text (<code>text</code>) by evaluating <code>d=q()</code> without losing your place in <code>a()</code>.
* [[tail call|Tail calls]] offer substantial benefits in performance for those who master the language.
* Function names are often of the form {{code|p.myFunctionName}}, where p is the table from the {{code|return p}} at the bottom of your program. The reason for this is that you can only access functions that are entries in this table from the original {{code|#invoke}} statement. Functions for local use within the program can have any name.
== Understanding patterns ==
''Note:'' Lua patterns are ''not'' [[regular expression|regular expressions]] in the traditional POSIX sense, and they are not even a subset of regular expressions. But they share many constructs with regular expressions (more [[Help:Lua for beginners#regex|below]]).
Lua patterns are used to define, find and handle a ''pattern'' in a string. It can do the common search and replace action in a text, but it has more options that doing plain text only. For example, in one go it can change the errors 'New yorker', 'New-Yorker', and 'NewYorker' into 'New Yorker'.
* To begin with, a pattern works like a plain string so long as it doesn't contain the special characters {{code|^ $ () % . [] * + - ?}}
* Square brackets {{code|[ ]}} are used to match ''one'' ''single character'' in the string from a list of choices. {{code|[abc]}} matches the letters a, b, or c. With {{code|^}} right after {{code|[}} they indicate "anything but": {{code|[^abc]}} = not a, b, or c. Inside brackets and when not the first character, a minus {{code|-}}indicates a range: {{code|[a-z]}} matches one single character from a, b, c, …, z.
* Period {{code|.}} matches any character.
* Percent {{code|%}} indicates a large set (class) of possible character matches when it is followed by a letter. See [https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Character_class] for a full list. <!--- should test/list these empirically to be sure ---> When followed by punctuation (whether a special character above or not) the {{code|%}} is removed and the punctuation is taken as a literal character; {{code|%%}} = literal %. Special classes include a balanced class {{code|%bxy}} and {{code|%f[set]}}; see the link above for more.
* Parentheses {{code|( )}} indicate captures. The captures can be accessed later in the search string or in the string.gsub replacement string as {{code|%1}} to {{code|%9}}, and are returned by string.match as an expression list of results.
* The qualifiers {{code|? - * +}} specify repetitions of a single character (not a longer string).
:* {{code|?}} means 0 or 1 repetitions: {{code|a?}} matches "a" or "".
:* {{code|-}} means 0 or more repetitions, choosing as few as possible to achieve a match ("non-greedy"). For example {{code|2=lua|string.match("bbbb", "(.-)")}} yields "", which is less than useful because there is nothing to root the ends of the expression and prevent it from matching zero characters.
:* {{code|*}} means 0 or more repetitions, choosing as many as possible ("greedy"). For example {{code|2=lua|string.match("bbbb", ".*")}} yields bbbb.
:* {{code|+}} means 1 or more repetitions, choosing as many as possible ("greedy").
Note that the greediness of the ''leftmost'' qualifier rules over all others when there is a choice: {{code|(.*)b(.*)}} when matched on "bbb" will return "bb", "", while {{code|a(.-)b(.-)a}} when matched on "abbba" will return "", "bb".
* {{code|^}} and {{code|$}} indicate the beginning and end of the string if they occur in the appropriate place in the pattern. Otherwise they are literal characters. {{code|^}} is not used in the {{code|string.gmatch}} function.
The reference manual for Lua patterns is at [[:mw:Extension:Scribunto/Lua_reference_manual#Patterns|mediawiki.org]].
== {{anchor|regex}}Note on Lua patterns versus regular expressions ==
Lua patterns are ''loosely based'' on [[regular expression]]s (sometimes shortened to regex or regexp). Lua patterns deliberately lack the most complex regular expression constructs (to avoid bloating the Lua code base), where many other computer languages or libraries use a more complete set. Lua patterns are not even a subset of regular expressions, as there are also discrepancies, like Lua using the escape character <code>%</code> instead of <code>\,</code>, and additions, like Lua providing <code>-</code> as a non-greedy version of <code>*</code>.
Here is a list of some of the things that Lua patterns lack compared to regular expressions:
* You '''cannot''' search for alternations between anything else than single characters (you '''cannot''' say <code>(his|her)</code> to choose between <code>his</code> and <code>her</code>, you can only say <code>[abc]</code> to choose between single characters <code>a</code>, <code>b</code>, or <code>c</code>).
* You '''cannot''' look for multiples of multi-letter constructs such as <code>(choo-)*choo</code> to match <code>choo</code>, <code>choo-choo</code> or <code>choo-choo-choo</code>. There is no way to do this with Lua patterns.
* You '''cannot''' specify the minimum and maximum number of repetitions like <code>[0-9]{3,5}</code> (to match 3 to 5 digits); in Lua you would say <code>%d%d%d%d?%d?</code> instead in this case.
There are Lua libraries that offer more powerful options,<sup>[http://lua-users.org/wiki/PatternsTutorial]</sup> including regular expressions, but the support on Wikipedia is pretty basic.
Wikipedia help for regular expressions (which Lua, as mentioned, does ''not'' support) is at [[Wikipedia:AutoWikiBrowser/Regular expression]].
{{Wikipedia technical help|collapsed}}
[[Category:Module help|*]]
fpxhow7ntzp1dwmaepiljcf9vkyaqd8
790926
790923
2026-05-19T19:00:21Z
Nimmzo
78995
/* Lua program structure: Output */ gmatch-based advanced minimal module iterator of vowels is optional: "Copy" button is no longer supplied because the Module:MatchVowel does not exist. It can be simulated in Debug console
790926
wikitext
text/x-wiki
{{WikiProject Lua header}}
{{Selfref|This help page is meant to provide some basic orientation for those new to Lua/Scribunto.}}
{{ඉංග්රීසි ව්යාපෘතියේ සිට ආයාත කළ පිටුව}}
== Overview ==
[[WP:Lua|Lua]] is a lightweight scripting language safely available on Wikipedia via [[mw:Extension:Scribunto|Scribunto]]. Its purpose is to allow you to process the data which is available on Wikipedia content pages to allow various sorts of customized display of information.
It runs in a sandboxed environment to protect the stability of Wikipedia while enabling powerful <syntaxhighlight lang="lua" inline>{{template}}</syntaxhighlight> and <syntaxhighlight lang="lua" inline>module:</syntaxhighlight> functionality.
The most important help file is the [[mw:Extension:Scribunto/Lua reference manual|MediaWiki Scribunto Lua reference manual]], which provides a concise summary of the language and standard library calls as implemented on MediaWiki.
The standard [http://www.lua.org/manual/5.1/manual.html Lua reference manual] is well written and comprehensive, but it can be confusing for beginners because some standard features don't work on wiki pages. You cannot call <syntaxhighlight lang="lua" inline>print("Hello, World!")</syntaxhighlight> in a module, but you can preview your User page showing the string <syntaxhighlight lang="lua" inline>"Hello World!"</syntaxhighlight> generated by the Lua [[Module:Example]]. Think of your Lua template as an HTML generator.
=== Generating "Hello World!" ===
You do not need to install or save anything.
# Edit your User page: <code>පරිශීලක:YourUserName</code>
# Paste the following call at the beginning of a new line on your User page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{#invoke:Example|hello}}
</syntaxhighlight></blockquote>
<ol start="3">
<li>Click <code>Preview</code>. The call of the function <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> in the [[Module:Example]] is replaced with the following:</li>
</ol>
<blockquote><syntaxhighlight lang="lua" line>
Hello World!
</syntaxhighlight></blockquote>
<ol start="4">
<li>Click <code>Cancel</code>. When prompted, click <code>Leave</code>.</li>
<li>Your User page remains '''un'''modified.</li>
</ol>
== Debug console: Start learning Lua ==
The Lua Scribunto <code>Debug Console</code> is a safe, interactive tool for learning Lua in Wikipedia.
# Click <code>Edit</code> on the [[Module:Yesno]] page.
# Scroll to the bottom of the page to the <code>Debug console</code> section beneath the Lua editor.
# Paste the comment and the call into the <span style="color:#86888c;">gray</span> input box (above the <code>Clear</code> button).
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
--[[ඔබගේ ආරම්භක Lua "හෙලෝ වර්ල්ඩ්" යන වගේම වැඩසටහන]]--
print("වෙල්කම් වෙයි " .. _VERSION .. "!") -- Lua අනුවාදය .. සමඟ එකතු කරයි
</syntaxhighlight></blockquote>
<ol start="4">
<li>Press {{key press|Enter}} once to execute the two Lua command''s''.</li>
<li>The result will appear below the Lua <syntaxhighlight lang="lua" inline>print</syntaxhighlight> command line:</li>
</ol>
<blockquote><syntaxhighlight lang="lua" line start=3>
වෙල්කම් වෙයි Lua 5.1!
</syntaxhighlight></blockquote>
<ol start="6">
<li>Press <code>Up arrow</code> (↑) to cycle through previous Lua commands.</li>
<li>Optionally, click <code>Clear</code> to clear ''only'' the <code>Debug Console</code>; the Lua editor above will remain '''un'''modified.</li>
</ol>
; HTML generator in the Debug console
Call the function <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> in <code>Module:</code>Example:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local modExample = require('Module:Example') -- load the module in Debug console
local frame = mw.getCurrentFrame(); print(modExample.hello(frame)) -- display "Hello World!"
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
Hello World!
</syntaxhighlight></blockquote>
; Identity function
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local yesno = require('Module:Yesno') -- #if yesno then returns its input parameter
print(mw.getCurrentFrame():callParserFunction("#if", yesno("Yes"), "Yes", 'නැහැ'))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
Yes
</syntaxhighlight></blockquote>
# Close the protected <code>Module:</code>Yesno that remains '''un'''modified.
== Issues with the current implementation ==
Besides the lack of <code>print()</code> in a module, there are other features missing – see [[mw:Extension:Scribunto/Lua reference manual#Differences from standard Lua|Differences from standard Lua]] for a complete list.
At the present time, it is advisable to use ''[[mw:Extension:Scribunto/Lua reference manual#Ustring library|mw.ustring]]'' functions instead of ''[[mw:Extension:Scribunto/Lua reference manual#String library|string]]'', because the latter sometimes fails with Unicode characters.
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local lang = mw.getCurrentFrame():callParserFunction("#language", "si") -- Sinhala
local lenUnicode, lenByte, lenSharp = mw.ustring.len(lang), string.len(lang), #lang
print(("lang: %s Mw.ustring.len = %d String.len = %d Sharp = %d"):format(lang, lenUnicode, lenByte, lenSharp))
</syntaxhighlight></blockquote>
Debug console supports Unicode:
<blockquote><syntaxhighlight lang="lua" line start=4>
lang: සිංහල Mw.ustring.len = 5 String.len = 15 Sharp = 15
</syntaxhighlight></blockquote>
== Input ==
The programs are run only when the page is "parsed" (when it or a page it incorporates is changed or previewed), not every time you view the output. Therefore there can be no convenient Lua module that allows you to type in a Fahrenheit temperature in an input box and get back the corresponding Celsius temperature when you press a button, or allows you to click on a segment of a Mandelbrot set visualization on a page to expand it as often as you like. There has to be an actual Wiki page (or at least a page you have submitted for preview) containing the input data.
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local function toCelsius(tempFahrenheit) return (tempFahrenheit - 32) * 5 / 9 end
print(("toCelsius(32°F) = %s°C. toCelsius(68°F) = %d°C"):format(toCelsius(32), toCelsius(68)))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
toCelsius(32°F) = 0°C. toCelsius(68°F) = 20°C
</syntaxhighlight></blockquote>
However, it is possible to use library functions like [[mw:Extension:Scribunto/Lua reference manual#mw.title.getCurrentTitle|mw.title.getCurrentTitle()]] to import content from any text content page on the Wiki.
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
print(mw.title.getCurrentTitle())
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=2>
Module:Yesno
</syntaxhighlight></blockquote>
You cannot, however, import data from files, not even .svg files which contain XML text data.
== Calling a Lua module ==
Lua calls look much like [[WP:template|template]]s, and consist of a small block of text.
In your User page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{ConvertNumeric|decToHex|73}}
</syntaxhighlight></blockquote>
Click <code>Preview</code> or click <code>Edit</code> this section to see the call then <code>Cancel</code>:
<blockquote>
{{#invoke:ConvertNumeric|decToHex|73}}
</blockquote>
This text calls the Lua script itself, which is housed in the <code>Module:</code> [[WP:namespace|namespace]]. The effect of this call is to send the information within the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> block to the Lua module, and to replace everything within the brackets with a piece of text that it sends back in return. (Literally, in the "return" statement)
Note that the first "parameter", in this case <code>decToHex</code>, is actually a <syntaxhighlight lang="lua" inline>function</syntaxhighlight> called within the Lua module. This field must always be included in any <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight>. To those unfamiliar with modules, especially Wikipedia template coders who expect anything after <code>|</code> to be a parameter, the need for this extra field is surprising, especially if all uses of the module depend on its presence.
In Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local convNum = require('Module:ConvertNumeric')
local frame = mw.getCurrentFrame(); frame.args[1] = "73" -- number always as string
print(("0x%s = %s = %d"):format(convNum.decToHex(frame), string.format("0x%X", 73), 0x49))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=4>
0x49 = 0x49 = 73
</syntaxhighlight></blockquote>
=== Documenting a Lua module ===
When documenting your module, it is useful to include an explicit usage instruction using [[සැකිල්ල:Module link expanded]]:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{mlx|ConvertNumeric|decToHex|73}}
</syntaxhighlight></blockquote>
Hyperlink to the module:
<blockquote>
{{mlx|ConvertNumeric|decToHex|73}}
</blockquote>
For many existing modules, an example <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> of the script (and little else) is provided on the <code>Module talk:</code> page. It is convenient for authors to be able to flip quickly to the talk tab to look at the effects of their changes, but you should never transclude the talk page as a template - people might actually talk on it! Alternatively, the module page can show documentation from a separate /doc-page (as [[Module:WikidataIB]] does).
=== Another example: Using LuaCall to perform a single Lua instruction ===
As a beginner, or in casual talk page conversation, you might only have one little calculation you want to use Lua for but don't want to write a full module. You might find [[Module:LuaCall]] convenient for this. For example, you can test how a greedy [https://www.lua.org/pil/20.1.html Lua pattern] works:
* <syntaxhighlight lang="lua" inline>{{#invoke:LuaCall|main|a=bbbbbbbbbba|b=bb(.*)b(.+)bba|string.match(a,b)}}</syntaxhighlight> → <code>{{#invoke:LuaCall|main|a=bbbbbbbbbba|b=bb(.*)b(.+)bba|string.match(a,b)}}</code>
or count up the length of a [[wikipedia:Did you know|''Did you know'']] hook or the text portion of a ''Did you know'' candidate:
* <syntaxhighlight lang="lua" inline>{{#invoke:LuaCall|main|a=... that you can count the length of your DYK hook with a Lua module?|string.len(a)}}</syntaxhighlight>→ <code>{{#invoke:LuaCall|main|a=... that you can count the length of your DYK hook with a Lua module?|string.len(a)}}</code>
In these specific examples, however, [[Module:String]] could do both of these tasks.
The script at [[Module:LuaCall]] has been written to accept any set of named parameters <code>somename=value</code>, for each one storing the string <code>value</code> in the variable with the name <code>somename</code>, and then allowing you to use these variables as parameters for any function available in Lua. The script then returns only the ''first'' value returned by the function ([https://www.lua.org/pil/5.1.html Lua functions can return multiple values], but in this case, only the first is returned from the module).
== Lua program structure: Output ==
The most fundamental part of a Wikipedia Lua program is a <syntaxhighlight lang="lua" inline>return</syntaxhighlight> statement which carries its output back to the page that had the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight>. You ''can'' have a Lua function that runs without error even though it doesn't contain a return statement, but on Wikipedia it is pointless, as Lua programs cannot generally have side effects on Wikipedia.
The module itself must return a Lua '''table''' of values. A Lua table is expressed as a list of values separated by commas, within curly braces. When the module is called by <code>#invoke</code>, the '''function''' it names (the first argument after |) is looked for in that table. That function, in turn, is expected to return something that can be represented as a '''string'''.
Typically we use the overall form for [[Module:Example]]:
<syntaxhighlight lang="lua" line highlight=3 copy>
local p = {} -- Defines the empty (non-nil) table package, the only single-letter variable
function p.hello(frame) -- Define the function p.hello. The input parameter frame is not used
return "Hello World!" -- Returns the string result of the function.
end -- Ends the function
return p -- This returns the table package
</syntaxhighlight>
Note that <syntaxhighlight lang="lua" inline>function p.hello(frame)</syntaxhighlight> is equivalent to anonymous <syntaxhighlight lang="lua" inline>p.hello = function(frame)</syntaxhighlight> or <syntaxhighlight lang="lua" inline>p["hello"] = function(frame)</syntaxhighlight>.
The function is just another '''type''' of value, retrieved with the key <code>"hello"</code> from table <code>p</code>.
If you want to allow users to invoke the same module with <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|main}}</nowiki></code> instead of <syntaxhighlight lang="lua" inline>{{#invoke:Example|hello}}</syntaxhighlight>, you can write:
<syntaxhighlight lang="lua" line start=6>
p.main = p.hello -- to copy the reference to this function to a new key in the table.
</syntaxhighlight>
You can even write <code>p[""] = p.hello</code>, which causes <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|}}</nowiki></code> to produce the same output as <syntaxhighlight lang="lua" inline>{{#invoke:Example|hello}}</syntaxhighlight>.
Learning to think of functions as a data '''type''' becomes very important later on for working with library functions like <code>[[mw:Extension:Scribunto/Lua_reference_manual#string.gsub|mw.ustring.gsub]]</code>, and constructing iterator functions:
;gmatch-based advanced minimal module iterator of vowels
The <code>Module:</code>MatchVowel is actually a complete Lua module (though a very strange one):
<blockquote><syntaxhighlight lang="lua" line highlight=2>
--[[MatchVowel returns a table containing the iterator function of vowels]]--
return { mw.ustring.gmatch( "Hello World!", "([aeiou])" ) } -- returns a table with the iterator
</syntaxhighlight></blockquote>
It returns the iterator function returned by <code>[[mw:Extension:Scribunto/Lua_reference_manual#string.gmatch|mw.ustring.gmatch]]</code> as the one and only element in an array.
If <code>Module:</code>MatchVowel was saved in its own wiki page, when executed in another wiki page:
<blockquote><syntaxhighlight lang="lua" line highlight=1>
{{#invoke:MatchVowel|1}}
</syntaxhighlight></blockquote>
The call yields the vowel from "Hello World!":
<blockquote><syntaxhighlight lang="lua" line start=1>
e
</syntaxhighlight></blockquote>
In Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
--[[iterator function that yields each vowel (case-sensitive) from the string "Hello World!"]]--
local tabMatchVowel = (function() return {mw.ustring.gmatch("Hello World!", "([aeiou])")} end)()
local itv = tabMatchVowel[1] -- iterator function from gmatch as the sole element of the table
local vowel; repeat vowel = itv(); if vowel then print(vowel) end until not (vowel) -- each vowel
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=5>
e
o
o
</syntaxhighlight></blockquote>
== Lua program structure: Input ==
The '''<code>frame</code>''' parameter above (which is pretty much always given this name in Wikipedia Lua modules) receives another table, which is passed ''from'' the page that makes the call ''to'' the Lua module. It contains a surprising amount of stuff, of which just a few things concern the novice.
=== Arguments ===
{{see also|Module:Arguments}}
<code>frame.args</code> contains ''another'' table, namely, all the content sent by the user within the <code>#invoke</code> brackets except the first argument which states the name of the function to be executed.
In your User page: about [[Module:ConvertNumeric]]
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{#invoke:ConvertNumeric |numeral_to_english |57000 |round=on |plural=on}}
</syntaxhighlight></blockquote>
Click <code>Preview</code> or click <code>Edit</code> this section to see the call then <code>Cancel</code>:
<blockquote>
{{#invoke:ConvertNumeric |numeral_to_english |57000 |round=on |plural=on}}
</blockquote>
There are two types of parameters: numeric (positional) keys and named keys.
# Unnamed parameters come out with numbers as keys: <code>frame.args[1]</code>.<br/>The string <code>"57000"</code> is the content of <code>frame.args[1]</code> which is the same as <code>frame["args"][1]</code><br/>but ''not'' the same as <code>frame.args["1"]</code> or <code>frame["args"]["1"]</code>.
# Named parameters come out with the parameter names (strings) as keys: <code>frame.args["round"]</code>, <code>frame.args["plural"]</code>.
In Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=4 copy>
--[[Convert a number to letter in Sinhala]]--
local convNum = require('Module:ConvertNumeric')
local frame=mw.getCurrentFrame(); frame.args = {"57000", round="on", plural="on"}
print(convNum.numeral_to_english(frame) .. " is rounded from 57,000.")
local debugLog = {} -- empty report table
for key, val in pairs(frame.args) do -- for each arg
debugLog[#debugLog + 1] = ("args[%s] = %s"):format(key, val)
end -- ^length. Adding report is faster than string-based: debugLog = debugLog .. string
print(table.concat(debugLog, ". ")) -- Join with separator
mw.logObject(frame.args) -- Scribunto tool to display table
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=11>
හැට දහස is rounded from 57,000.
args[1] = 57000. args[plural] = on. args[round] = on
table#1 {
"57000",
["plural"] = "on",
["round"] = "on",
}
</syntaxhighlight></blockquote>
=== Parent frame ===
Within <code>frame</code> there is a ''parent'' frame, referring to the page that called the page that gives the script, and you can pull out arguments from that also. Just write:
<blockquote><syntaxhighlight lang="lua" line highlight=17 copy>
--[[Return true if table-like `tab` contains any non-nil entries]]--
local function has_any_args(tab)
if tab == nil then return false end -- the table is nil
for _, val in pairs(tab) do -- Iterates both numeric (positional) and string (named) keys.
if val ~= nil then -- value not nil?
return true -- one argument exists
end
end
return false -- The table does not have any arguments
end
--[[Debug console or template in wiki page?]]--
local booksPlural = "There are those books."; local pluralMarker = "s."
local globalSub = "mw.ustring.gsub(subjectStr,pattern,replace)" -- no space separator
local prm = {subjectStr=booksPlural, pattern=pluralMarker, replace=".", globalSub, "lua"}
local frame = mw.getCurrentFrame():newChild{title='Module:Lua call', args=prm}
local parent = frame:getParent() or nil
if not parent or not has_any_args(parent.args) then
print("Running from Debug console")
print(mw.text.listToText(frame.args))
else
print("Running from wiki page invoking {{template}}")
end
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=24>
Running from Debug console
mw.ustring.gsub(subjectStr,pattern,replace)
</syntaxhighlight></blockquote>
<syntaxhighlight lang="lua" inline>parent.args</syntaxhighlight> will contain those arguments.
It is popular in Lua to use the synonymous statement <code>parent=frame''':'''getParent()</code>, cancelling the need to write <code>frame</code> twice.<br/>
Note the colon (<code>:</code>) instead of the dot (<code>.</code>).
<syntaxhighlight lang="lua" inline>parent = frame:getParent()</syntaxhighlight> means exactly the same as <code>parent = frame.getParent(frame)</code>.
For novices this can be confusing, and it is important to be aware of this idiom.<br/>
If you use it in the wrong way, though, the script errors are pretty good at pointing out that this was the mistake.
== Basic debugging ==
{{Main|Help:Lua debugging}}
Debugging can start as soon as you write programs, and can be done simply with string concatenation.<br/>
Just set up a variable with some recognizable name like <syntaxhighlight lang="lua" inline>debugLog</syntaxhighlight> in your main <syntaxhighlight lang="lua" inline>function p.main(frame)</syntaxhighlight> with a statement like:
<blockquote><syntaxhighlight lang="lua" line start=3 highlight=1 copy>
local debugLog = "" -- empty report string
</syntaxhighlight></blockquote>
This initial <syntaxhighlight lang="lua" inline>""</syntaxhighlight> definition helps because otherwise it will be <syntaxhighlight lang="lua" inline>nil</syntaxhighlight> and concatenating a string to nil gets you an error.<br/>
Now whenever you have a variable you'd like to test, say {{tt|myVar}}, just write:
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=2 copy>
local myVar = 42; local output = "expected result"
debugLog = debugLog .. " myVar = " .. tostring(myVar) -- append to the report
</syntaxhighlight></blockquote>
At the end of your function (but not the module), complete:
<blockquote><syntaxhighlight lang="lua" line start=16 highlight=1 copy>
return output .. debugLog -- Returns the expected result and the report
</syntaxhighlight></blockquote>
The <syntaxhighlight lang="lua" inline>tostring(myVar)</syntaxhighlight> is a function to ensure {{tt|myVar}} is interpreted as a string.<br>
For a table, it will display as "{{samp|table}}". For nil, "{{samp|nil}}" rather than as Script error.
== Format ==
The [[WP:Lua style guide]] gives some basic formatting suggestions expected by the JavaScript module editor, such as using four-space indentations and keeping <syntaxhighlight lang="lua" inline>if then else</syntaxhighlight>, <syntaxhighlight lang="lua" inline>end</syntaxhighlight> at the same level of indentation.
Comments to the end of a line are marked by <syntaxhighlight lang="lua" inline>-- green comment</syntaxhighlight>. ''Use them.''
Many modules for Wikipedia have a straightforward, linear design, but that doesn't mean it won't help to have your sections clearly labelled when you go back to the code for the hundredth time. The Lua style guide gives additional recommendations for using functions to keep your work more organized.
== Errors ==
Lua errors appear as red "Script error" messages. If Javascript is enabled, '''the <span style="color:#ff0000;">red</span> script error message is a link''' which usually allows you to follow it back to the line in the module where the error occurred. There are some exceptions, for example "Module not found", if the name of the module itself is mistyped, or "The function you specified did not exist" if the function name given is invalid.
=== Recurrent bugs ===
Some bugs you might want to keep in mind:
;Missing operator for concatenation
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=2 copy>
local debugLog = "" -- empty report string
debugLog = debugLog "missing double dot" -- append to the report
</syntaxhighlight></blockquote>
The following means you forgot the <code>..</code> between a string and a variable somewhere in a mess of stuff you're concatenating.
<blockquote><syntaxhighlight lang="lua" line start=9>
Lua error in console input at line 8: attempt to call local 'debugLog' (a string value).
</syntaxhighlight></blockquote>
;String expected, got function
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=3 copy>
local debugLog = "" -- empty report string
local res = mw.ustring.gmatch("Hello World!", "([aeiouAEIOU])") -- iterator of vowels
debugLog = debugLog..res -- populate the report with only strings
</syntaxhighlight></blockquote>
Some important things like <syntaxhighlight lang="lua" inline>mw.ustring.gmatch</syntaxhighlight> actually return ''functions'', not strings - see [[#Functions|Functions]] below.
<blockquote><syntaxhighlight lang="lua" line start=10>
Lua error in console input at line 9: attempt to concatenate local 'res' (a function value).
</syntaxhighlight></blockquote>
;Variable ignores assignment
A variable ignores all your efforts to assign stuff to it:
<blockquote><syntaxhighlight lang="lua" line highlight=1,3 copy>
local debugLog = "top level" -- initial value
do
local debugLog = "nested level" -- set the new value
print("Inside do: "..debugLog)
end
print("Outside do: "..debugLog) -- get the old value
</syntaxhighlight></blockquote>
You may have inadvertently written ''two'' local statements - the one sets the value of the variable within a limited region, and when the program leaves that region, you're back to the old value.
<blockquote><syntaxhighlight lang="lua" line start=7>
Inside do: nested level
Outside do: top level
</syntaxhighlight></blockquote>
A numbered table entry ignores all your efforts to assign to it:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local table = {}; local arg = "50"; local valPrm = tonumber(arg)
table[arg] = "index as string"
table[valPrm] = "index as number"
print(table[arg] == table[valPrm])
</syntaxhighlight></blockquote>
This is because {{code|table["50"]}} '''is not''' {{code|table[50]}}.<br/>
Typically you have processed a parameter (which you may have received from the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> as a string) with string functions in one place,<br>
but performed numeric operations in another, leaving you with two different types of variable to use for an index.
<blockquote><syntaxhighlight lang="lua" line start=5>
false
</syntaxhighlight></blockquote>
;<syntaxhighlight lang="lua" inline>nil</syntaxhighlight> and common pitfalls
There are all sorts of things you can't do with a local variable set to nil, such as: <syntaxhighlight lang="lua" inline>local x = nil</syntaxhighlight>, like:
# Assign <code>x.somefield</code>
# Get value at index {{code|x[idx]}}
# Concatenate <syntaxhighlight lang="lua" inline>x .. "Cannot concatenate with nil"</syntaxhighlight>
# Evaluate <syntaxhighlight lang="lua" inline>table[x]</syntaxhighlight>
Initialize such variables with: <syntaxhighlight lang="lua" inline>local x={}; local table = {}</syntaxhighlight><br>
Often "global" is mentioned in these errors because you didn't have a {{tt|local}} statement for the <syntaxhighlight lang="lua" inline>nil</syntaxhighlight> variable.
;Cannot invoke module
* ''no such module.'' You called <syntaxhighlight lang="lua" inline>#invoke:moduleNameUnknown</syntaxhighlight> that didn't exist or you wrongly kept the prefix <code>Module:</code> writing {{code|#invoke:Module:moduleName}}.
* ''the function specified did not exist.'' You called <syntaxhighlight lang="lua" inline>#invoke:moduleName|functionUnknown</syntaxhighlight>, but the field after the name of the module is wrong.<br>Often this field expects a standard name like "main", and you've forgotten it and gone straight to the first data parameter.<br>If you're unsure of the function name, check the module documentation, or look for what function(s) in the code accept a "frame" parameter.
;Graphics overflow issue
Some graphics you're trying to display are heading off to the hills: actually a HTML error.<br>
You didn't close one <syntaxhighlight lang="html" inline></div></syntaxhighlight>, so all the top: and left: styles keep adding up.
== Understanding tables and related concepts ==
* An '''expression list''' is a set of values separated by commas. The values can be strings, numbers, tables, functions, etc.
* A '''sequence''' is a set of entries with indices from 1 to N, where N is a positive integer. They can be created by placing brackets around an expression list.
For example:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local seq = {1, "quotation", mw.ustring.gmatch("abca","a"), {2,3,4}}
mw.logObject(seq) -- Scribunto tool to display a table
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
table#1 {
1,
"quotation",
function#1,
table#2 {
2,
3,
4,
},
}
</syntaxhighlight></blockquote>
# <code>seq[1]</code> = 1
# <code>seq[2]</code> = <syntaxhighlight lang="lua" inline>"quotation"</syntaxhighlight>
# <code>seq[3]</code> is the <syntaxhighlight lang="lua" inline>function</syntaxhighlight> returned by <code>gmatch()</code>
# <code>seq[4]</code> is the table <code>{2,3,4}</code>.
An expression list can also be recovered from a table using <syntaxhighlight lang="lua" inline>unpack()</syntaxhighlight>:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local seq = {1, "quotation", mw.ustring.gmatch("abca","a"), {2,3,4}}
local var1Nbr, var2Str, var3Fct = unpack(seq)
print(("var1Nbr = %d. var2Str = \"%s\". var3Fct = %s"):format(var1Nbr, var2Str, type(var3Fct)))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=4>
var1Nbr = 1. var2Str = "quotation". var3Fct = function
</syntaxhighlight></blockquote>
This will set:
# <code>var1Nbr</code> = 1
# <code>var2Str</code> = <syntaxhighlight lang="lua" inline>"quotation"</syntaxhighlight>
# <code>var3Fct</code> as the <syntaxhighlight lang="lua" inline>function</syntaxhighlight> returned by <code>gmatch()</code>
# <code>{2,3,4}</code> will be discarded in this case.
* A '''table''' is a sequence, optionally supplemented by named keys: <code>digit["two"]="2"</code>. Several table functions like <code>table.concat</code> will only work with the numbered values and ignore named keys.
* The '''metatable''' offers a large, optional set of methods for altering table behavior. For example, you can define a table to be callable like a function.
=== Initializing a table ===
It is often useful to create a whole table at once in a statement. There are many equivalent ways to do this, but the shortcuts don't work for every kind of value. To begin with, the most general way is to assign each key and value explicitly:
<syntaxhighlight lang="lua" inline>a = {[0]='zero', [1]='one', ['1']='string for one'}</syntaxhighlight>
If sequence keys (positive integers) are given in order, only the values need to be given, so the following will assign <syntaxhighlight lang="lua" inline>'one'</syntaxhighlight> to <syntaxhighlight lang="lua" inline>a[1]</syntaxhighlight>:
<syntaxhighlight lang="lua" inline>a = {[0]='zero', 'one', ['1']='string for one'}</syntaxhighlight>
If a key has only letters, digits, and underscores, and begins with a non-digit, the brackets and quotation marks can be omitted:
<syntaxhighlight lang="lua" inline>a = {a='one', b='two'}</syntaxhighlight>
This is identical to <syntaxhighlight lang="lua" inline>a = {["a"]='one', ["b"]='two'}</syntaxhighlight>.
However, this will fail for keys that begin with a digit: <syntaxhighlight lang="lua" inline>hex = {7f = 127}</syntaxhighlight> will produce an error; use <syntaxhighlight lang="lua" inline>hex = {['7f'] = 127}</syntaxhighlight> instead.
Note that when given ''within'' brackets, or to the right of the equal sign, quotation marks are needed, or else string values will be taken as variables:
<syntaxhighlight lang="lua" inline> a = {[b] = c}</syntaxhighlight>
assigns the value of variable ''c'' to the key ''contained in variable'' ''b''.
== Functions ==
* Functions can return any kind of value {{--}} ''including a function''. This is a powerful feature that can readily confuse the beginner. If you set <syntaxhighlight lang="lua" inline>a=mw.ustring.gmatch(text, "(.)")</syntaxhighlight>, the result assigned to <code>a</code> will be a '''function''', not a string character! However, assigning <code>b=a()</code> by calling the function stored in <code>a</code> will return the first match (a string). Every time you set <code>b=a()</code> after that you'll get another match (string) into <code>b</code>, until you run out of matches and get <code>nil</code>. Many '''iterator functions''' act this way.
* You can keep separate counts for iterator functions by using different variables. For example, if you set <syntaxhighlight lang="lua" inline>q=mw.ustring.gmatch(text, "(x.)")</syntaxhighlight> in the same module, you can pull characters from the same piece of text (<code>text</code>) by evaluating <code>d=q()</code> without losing your place in <code>a()</code>.
* [[tail call|Tail calls]] offer substantial benefits in performance for those who master the language.
* Function names are often of the form {{code|p.myFunctionName}}, where p is the table from the {{code|return p}} at the bottom of your program. The reason for this is that you can only access functions that are entries in this table from the original {{code|#invoke}} statement. Functions for local use within the program can have any name.
== Understanding patterns ==
''Note:'' Lua patterns are ''not'' [[regular expression|regular expressions]] in the traditional POSIX sense, and they are not even a subset of regular expressions. But they share many constructs with regular expressions (more [[Help:Lua for beginners#regex|below]]).
Lua patterns are used to define, find and handle a ''pattern'' in a string. It can do the common search and replace action in a text, but it has more options that doing plain text only. For example, in one go it can change the errors 'New yorker', 'New-Yorker', and 'NewYorker' into 'New Yorker'.
* To begin with, a pattern works like a plain string so long as it doesn't contain the special characters {{code|^ $ () % . [] * + - ?}}
* Square brackets {{code|[ ]}} are used to match ''one'' ''single character'' in the string from a list of choices. {{code|[abc]}} matches the letters a, b, or c. With {{code|^}} right after {{code|[}} they indicate "anything but": {{code|[^abc]}} = not a, b, or c. Inside brackets and when not the first character, a minus {{code|-}}indicates a range: {{code|[a-z]}} matches one single character from a, b, c, …, z.
* Period {{code|.}} matches any character.
* Percent {{code|%}} indicates a large set (class) of possible character matches when it is followed by a letter. See [https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Character_class] for a full list. <!--- should test/list these empirically to be sure ---> When followed by punctuation (whether a special character above or not) the {{code|%}} is removed and the punctuation is taken as a literal character; {{code|%%}} = literal %. Special classes include a balanced class {{code|%bxy}} and {{code|%f[set]}}; see the link above for more.
* Parentheses {{code|( )}} indicate captures. The captures can be accessed later in the search string or in the string.gsub replacement string as {{code|%1}} to {{code|%9}}, and are returned by string.match as an expression list of results.
* The qualifiers {{code|? - * +}} specify repetitions of a single character (not a longer string).
:* {{code|?}} means 0 or 1 repetitions: {{code|a?}} matches "a" or "".
:* {{code|-}} means 0 or more repetitions, choosing as few as possible to achieve a match ("non-greedy"). For example {{code|2=lua|string.match("bbbb", "(.-)")}} yields "", which is less than useful because there is nothing to root the ends of the expression and prevent it from matching zero characters.
:* {{code|*}} means 0 or more repetitions, choosing as many as possible ("greedy"). For example {{code|2=lua|string.match("bbbb", ".*")}} yields bbbb.
:* {{code|+}} means 1 or more repetitions, choosing as many as possible ("greedy").
Note that the greediness of the ''leftmost'' qualifier rules over all others when there is a choice: {{code|(.*)b(.*)}} when matched on "bbb" will return "bb", "", while {{code|a(.-)b(.-)a}} when matched on "abbba" will return "", "bb".
* {{code|^}} and {{code|$}} indicate the beginning and end of the string if they occur in the appropriate place in the pattern. Otherwise they are literal characters. {{code|^}} is not used in the {{code|string.gmatch}} function.
The reference manual for Lua patterns is at [[:mw:Extension:Scribunto/Lua_reference_manual#Patterns|mediawiki.org]].
== {{anchor|regex}}Note on Lua patterns versus regular expressions ==
Lua patterns are ''loosely based'' on [[regular expression]]s (sometimes shortened to regex or regexp). Lua patterns deliberately lack the most complex regular expression constructs (to avoid bloating the Lua code base), where many other computer languages or libraries use a more complete set. Lua patterns are not even a subset of regular expressions, as there are also discrepancies, like Lua using the escape character <code>%</code> instead of <code>\,</code>, and additions, like Lua providing <code>-</code> as a non-greedy version of <code>*</code>.
Here is a list of some of the things that Lua patterns lack compared to regular expressions:
* You '''cannot''' search for alternations between anything else than single characters (you '''cannot''' say <code>(his|her)</code> to choose between <code>his</code> and <code>her</code>, you can only say <code>[abc]</code> to choose between single characters <code>a</code>, <code>b</code>, or <code>c</code>).
* You '''cannot''' look for multiples of multi-letter constructs such as <code>(choo-)*choo</code> to match <code>choo</code>, <code>choo-choo</code> or <code>choo-choo-choo</code>. There is no way to do this with Lua patterns.
* You '''cannot''' specify the minimum and maximum number of repetitions like <code>[0-9]{3,5}</code> (to match 3 to 5 digits); in Lua you would say <code>%d%d%d%d?%d?</code> instead in this case.
There are Lua libraries that offer more powerful options,<sup>[http://lua-users.org/wiki/PatternsTutorial]</sup> including regular expressions, but the support on Wikipedia is pretty basic.
Wikipedia help for regular expressions (which Lua, as mentioned, does ''not'' support) is at [[Wikipedia:AutoWikiBrowser/Regular expression]].
{{Wikipedia technical help|collapsed}}
[[Category:Module help|*]]
27q4pgiuz1h57jueos47z1jonrmi8zy
790927
790926
2026-05-19T19:10:42Z
Nimmzo
78995
/* Another example: Using LuaCall to perform a single Lua instruction */ Switched "count up the length of a string" first because it is simpler than regex
790927
wikitext
text/x-wiki
{{WikiProject Lua header}}
{{Selfref|This help page is meant to provide some basic orientation for those new to Lua/Scribunto.}}
{{ඉංග්රීසි ව්යාපෘතියේ සිට ආයාත කළ පිටුව}}
== Overview ==
[[WP:Lua|Lua]] is a lightweight scripting language safely available on Wikipedia via [[mw:Extension:Scribunto|Scribunto]]. Its purpose is to allow you to process the data which is available on Wikipedia content pages to allow various sorts of customized display of information.
It runs in a sandboxed environment to protect the stability of Wikipedia while enabling powerful <syntaxhighlight lang="lua" inline>{{template}}</syntaxhighlight> and <syntaxhighlight lang="lua" inline>module:</syntaxhighlight> functionality.
The most important help file is the [[mw:Extension:Scribunto/Lua reference manual|MediaWiki Scribunto Lua reference manual]], which provides a concise summary of the language and standard library calls as implemented on MediaWiki.
The standard [http://www.lua.org/manual/5.1/manual.html Lua reference manual] is well written and comprehensive, but it can be confusing for beginners because some standard features don't work on wiki pages. You cannot call <syntaxhighlight lang="lua" inline>print("Hello, World!")</syntaxhighlight> in a module, but you can preview your User page showing the string <syntaxhighlight lang="lua" inline>"Hello World!"</syntaxhighlight> generated by the Lua [[Module:Example]]. Think of your Lua template as an HTML generator.
=== Generating "Hello World!" ===
You do not need to install or save anything.
# Edit your User page: <code>පරිශීලක:YourUserName</code>
# Paste the following call at the beginning of a new line on your User page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{#invoke:Example|hello}}
</syntaxhighlight></blockquote>
<ol start="3">
<li>Click <code>Preview</code>. The call of the function <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> in the [[Module:Example]] is replaced with the following:</li>
</ol>
<blockquote><syntaxhighlight lang="lua" line>
Hello World!
</syntaxhighlight></blockquote>
<ol start="4">
<li>Click <code>Cancel</code>. When prompted, click <code>Leave</code>.</li>
<li>Your User page remains '''un'''modified.</li>
</ol>
== Debug console: Start learning Lua ==
The Lua Scribunto <code>Debug Console</code> is a safe, interactive tool for learning Lua in Wikipedia.
# Click <code>Edit</code> on the [[Module:Yesno]] page.
# Scroll to the bottom of the page to the <code>Debug console</code> section beneath the Lua editor.
# Paste the comment and the call into the <span style="color:#86888c;">gray</span> input box (above the <code>Clear</code> button).
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
--[[ඔබගේ ආරම්භක Lua "හෙලෝ වර්ල්ඩ්" යන වගේම වැඩසටහන]]--
print("වෙල්කම් වෙයි " .. _VERSION .. "!") -- Lua අනුවාදය .. සමඟ එකතු කරයි
</syntaxhighlight></blockquote>
<ol start="4">
<li>Press {{key press|Enter}} once to execute the two Lua command''s''.</li>
<li>The result will appear below the Lua <syntaxhighlight lang="lua" inline>print</syntaxhighlight> command line:</li>
</ol>
<blockquote><syntaxhighlight lang="lua" line start=3>
වෙල්කම් වෙයි Lua 5.1!
</syntaxhighlight></blockquote>
<ol start="6">
<li>Press <code>Up arrow</code> (↑) to cycle through previous Lua commands.</li>
<li>Optionally, click <code>Clear</code> to clear ''only'' the <code>Debug Console</code>; the Lua editor above will remain '''un'''modified.</li>
</ol>
; HTML generator in the Debug console
Call the function <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> in <code>Module:</code>Example:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local modExample = require('Module:Example') -- load the module in Debug console
local frame = mw.getCurrentFrame(); print(modExample.hello(frame)) -- display "Hello World!"
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
Hello World!
</syntaxhighlight></blockquote>
; Identity function
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local yesno = require('Module:Yesno') -- #if yesno then returns its input parameter
print(mw.getCurrentFrame():callParserFunction("#if", yesno("Yes"), "Yes", 'නැහැ'))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
Yes
</syntaxhighlight></blockquote>
# Close the protected <code>Module:</code>Yesno that remains '''un'''modified.
== Issues with the current implementation ==
Besides the lack of <code>print()</code> in a module, there are other features missing – see [[mw:Extension:Scribunto/Lua reference manual#Differences from standard Lua|Differences from standard Lua]] for a complete list.
At the present time, it is advisable to use ''[[mw:Extension:Scribunto/Lua reference manual#Ustring library|mw.ustring]]'' functions instead of ''[[mw:Extension:Scribunto/Lua reference manual#String library|string]]'', because the latter sometimes fails with Unicode characters.
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local lang = mw.getCurrentFrame():callParserFunction("#language", "si") -- Sinhala
local lenUnicode, lenByte, lenSharp = mw.ustring.len(lang), string.len(lang), #lang
print(("lang: %s Mw.ustring.len = %d String.len = %d Sharp = %d"):format(lang, lenUnicode, lenByte, lenSharp))
</syntaxhighlight></blockquote>
Debug console supports Unicode:
<blockquote><syntaxhighlight lang="lua" line start=4>
lang: සිංහල Mw.ustring.len = 5 String.len = 15 Sharp = 15
</syntaxhighlight></blockquote>
== Input ==
The programs are run only when the page is "parsed" (when it or a page it incorporates is changed or previewed), not every time you view the output. Therefore there can be no convenient Lua module that allows you to type in a Fahrenheit temperature in an input box and get back the corresponding Celsius temperature when you press a button, or allows you to click on a segment of a Mandelbrot set visualization on a page to expand it as often as you like. There has to be an actual Wiki page (or at least a page you have submitted for preview) containing the input data.
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local function toCelsius(tempFahrenheit) return (tempFahrenheit - 32) * 5 / 9 end
print(("toCelsius(32°F) = %s°C. toCelsius(68°F) = %d°C"):format(toCelsius(32), toCelsius(68)))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
toCelsius(32°F) = 0°C. toCelsius(68°F) = 20°C
</syntaxhighlight></blockquote>
However, it is possible to use library functions like [[mw:Extension:Scribunto/Lua reference manual#mw.title.getCurrentTitle|mw.title.getCurrentTitle()]] to import content from any text content page on the Wiki.
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
print(mw.title.getCurrentTitle())
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=2>
Module:Yesno
</syntaxhighlight></blockquote>
You cannot, however, import data from files, not even .svg files which contain XML text data.
== Calling a Lua module ==
Lua calls look much like [[WP:template|template]]s, and consist of a small block of text.
In your User page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{ConvertNumeric|decToHex|73}}
</syntaxhighlight></blockquote>
Click <code>Preview</code> or click <code>Edit</code> this section to see the call then <code>Cancel</code>:
<blockquote>
{{#invoke:ConvertNumeric|decToHex|73}}
</blockquote>
This text calls the Lua script itself, which is housed in the <code>Module:</code> [[WP:namespace|namespace]]. The effect of this call is to send the information within the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> block to the Lua module, and to replace everything within the brackets with a piece of text that it sends back in return. (Literally, in the "return" statement)
Note that the first "parameter", in this case <code>decToHex</code>, is actually a <syntaxhighlight lang="lua" inline>function</syntaxhighlight> called within the Lua module. This field must always be included in any <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight>. To those unfamiliar with modules, especially Wikipedia template coders who expect anything after <code>|</code> to be a parameter, the need for this extra field is surprising, especially if all uses of the module depend on its presence.
In Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local convNum = require('Module:ConvertNumeric')
local frame = mw.getCurrentFrame(); frame.args[1] = "73" -- number always as string
print(("0x%s = %s = %d"):format(convNum.decToHex(frame), string.format("0x%X", 73), 0x49))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=4>
0x49 = 0x49 = 73
</syntaxhighlight></blockquote>
=== Documenting a Lua module ===
When documenting your module, it is useful to include an explicit usage instruction using [[සැකිල්ල:Module link expanded]]:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{mlx|ConvertNumeric|decToHex|73}}
</syntaxhighlight></blockquote>
Hyperlink to the module:
<blockquote>
{{mlx|ConvertNumeric|decToHex|73}}
</blockquote>
For many existing modules, an example <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> of the script (and little else) is provided on the <code>Module talk:</code> page. It is convenient for authors to be able to flip quickly to the talk tab to look at the effects of their changes, but you should never transclude the talk page as a template - people might actually talk on it! Alternatively, the module page can show documentation from a separate /doc-page (as [[Module:WikidataIB]] does).
=== Another example: Using LuaCall to perform a single Lua instruction ===
As a beginner, or in casual talk page conversation, you might only have one little calculation you want to use Lua for but don't want to write a full module. You might find [[Module:LuaCall]] convenient for this.
For example, count up the length of a string.
In your user page:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
{{#invoke:LuaCall|main|strText=count the length of your DYK hook with Lua|string.len(strText)}}
</syntaxhighlight></blockquote>
<blockquote>
{{#invoke:LuaCall|main|strText=count the length of your DYK hook with Lua|string.len(strText)}}
</blockquote>
You can test how a greedy [https://www.lua.org/pil/20.1.html Lua pattern] works: '''reg'''ular '''ex'''pression <code>.*</code> matches zero or more. <code>.+</code> matches one or more.
In your user page:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
{{#invoke:LuaCall|main|strText=bbbbbbbbbba|regex=bb(.*)b(.+)bba|string.match(strText,regex)}}
</syntaxhighlight></blockquote>
LuaCall returns the first match ignoring other results:
<blockquote>
{{#invoke:LuaCall|main|strText=bbbbbbbbbba|regex=bb(.*)b(.+)bba|string.match(strText,regex)}}
</blockquote>
In these specific examples, however, [[Module:String]] could do both of these tasks in Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
--[[Do You Know (DYK)]]--
local strText = "count the length of your DYK hook with Lua"; print(string.len(strText))
strText = "bbbbbbbbbba"; regex = "bb(.*)b(.+)bba" -- greedy pattern as much as possible
local table = {string.match(strText, regex)}; print(table[1]) -- returns the first match
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=5>
42
bbbb
</syntaxhighlight></blockquote>
The script at [[Module:LuaCall]] has been written to accept any set of named parameters <code>somename=value</code>, for each one storing the string <code>value</code> in the variable with the name <code>somename</code>, and then allowing you to use these variables as parameters for any function available in Lua. The script then returns only the ''first'' value returned by the function ([https://www.lua.org/pil/5.1.html Lua functions can return multiple values], but in this case, only the first is returned from the module).
== Lua program structure: Output ==
The most fundamental part of a Wikipedia Lua program is a <syntaxhighlight lang="lua" inline>return</syntaxhighlight> statement which carries its output back to the page that had the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight>. You ''can'' have a Lua function that runs without error even though it doesn't contain a return statement, but on Wikipedia it is pointless, as Lua programs cannot generally have side effects on Wikipedia.
The module itself must return a Lua '''table''' of values. A Lua table is expressed as a list of values separated by commas, within curly braces. When the module is called by <code>#invoke</code>, the '''function''' it names (the first argument after |) is looked for in that table. That function, in turn, is expected to return something that can be represented as a '''string'''.
Typically we use the overall form for [[Module:Example]]:
<syntaxhighlight lang="lua" line highlight=3 copy>
local p = {} -- Defines the empty (non-nil) table package, the only single-letter variable
function p.hello(frame) -- Define the function p.hello. The input parameter frame is not used
return "Hello World!" -- Returns the string result of the function.
end -- Ends the function
return p -- This returns the table package
</syntaxhighlight>
Note that <syntaxhighlight lang="lua" inline>function p.hello(frame)</syntaxhighlight> is equivalent to anonymous <syntaxhighlight lang="lua" inline>p.hello = function(frame)</syntaxhighlight> or <syntaxhighlight lang="lua" inline>p["hello"] = function(frame)</syntaxhighlight>.
The function is just another '''type''' of value, retrieved with the key <code>"hello"</code> from table <code>p</code>.
If you want to allow users to invoke the same module with <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|main}}</nowiki></code> instead of <syntaxhighlight lang="lua" inline>{{#invoke:Example|hello}}</syntaxhighlight>, you can write:
<syntaxhighlight lang="lua" line start=6>
p.main = p.hello -- to copy the reference to this function to a new key in the table.
</syntaxhighlight>
You can even write <code>p[""] = p.hello</code>, which causes <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|}}</nowiki></code> to produce the same output as <syntaxhighlight lang="lua" inline>{{#invoke:Example|hello}}</syntaxhighlight>.
Learning to think of functions as a data '''type''' becomes very important later on for working with library functions like <code>[[mw:Extension:Scribunto/Lua_reference_manual#string.gsub|mw.ustring.gsub]]</code>, and constructing iterator functions:
;gmatch-based advanced minimal module iterator of vowels
The <code>Module:</code>MatchVowel is actually a complete Lua module (though a very strange one):
<blockquote><syntaxhighlight lang="lua" line highlight=2>
--[[MatchVowel returns a table containing the iterator function of vowels]]--
return { mw.ustring.gmatch( "Hello World!", "([aeiou])" ) } -- returns a table with the iterator
</syntaxhighlight></blockquote>
It returns the iterator function returned by <code>[[mw:Extension:Scribunto/Lua_reference_manual#string.gmatch|mw.ustring.gmatch]]</code> as the one and only element in an array.
If <code>Module:</code>MatchVowel was saved in its own wiki page, when executed in another wiki page:
<blockquote><syntaxhighlight lang="lua" line highlight=1>
{{#invoke:MatchVowel|1}}
</syntaxhighlight></blockquote>
The call yields the vowel from "Hello World!":
<blockquote><syntaxhighlight lang="lua" line start=1>
e
</syntaxhighlight></blockquote>
In Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
--[[iterator function that yields each vowel (case-sensitive) from the string "Hello World!"]]--
local tabMatchVowel = (function() return {mw.ustring.gmatch("Hello World!", "([aeiou])")} end)()
local itv = tabMatchVowel[1] -- iterator function from gmatch as the sole element of the table
local vowel; repeat vowel = itv(); if vowel then print(vowel) end until not (vowel) -- each vowel
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=5>
e
o
o
</syntaxhighlight></blockquote>
== Lua program structure: Input ==
The '''<code>frame</code>''' parameter above (which is pretty much always given this name in Wikipedia Lua modules) receives another table, which is passed ''from'' the page that makes the call ''to'' the Lua module. It contains a surprising amount of stuff, of which just a few things concern the novice.
=== Arguments ===
{{see also|Module:Arguments}}
<code>frame.args</code> contains ''another'' table, namely, all the content sent by the user within the <code>#invoke</code> brackets except the first argument which states the name of the function to be executed.
In your User page: about [[Module:ConvertNumeric]]
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{#invoke:ConvertNumeric |numeral_to_english |57000 |round=on |plural=on}}
</syntaxhighlight></blockquote>
Click <code>Preview</code> or click <code>Edit</code> this section to see the call then <code>Cancel</code>:
<blockquote>
{{#invoke:ConvertNumeric |numeral_to_english |57000 |round=on |plural=on}}
</blockquote>
There are two types of parameters: numeric (positional) keys and named keys.
# Unnamed parameters come out with numbers as keys: <code>frame.args[1]</code>.<br/>The string <code>"57000"</code> is the content of <code>frame.args[1]</code> which is the same as <code>frame["args"][1]</code><br/>but ''not'' the same as <code>frame.args["1"]</code> or <code>frame["args"]["1"]</code>.
# Named parameters come out with the parameter names (strings) as keys: <code>frame.args["round"]</code>, <code>frame.args["plural"]</code>.
In Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=4 copy>
--[[Convert a number to letter in Sinhala]]--
local convNum = require('Module:ConvertNumeric')
local frame=mw.getCurrentFrame(); frame.args = {"57000", round="on", plural="on"}
print(convNum.numeral_to_english(frame) .. " is rounded from 57,000.")
local debugLog = {} -- empty report table
for key, val in pairs(frame.args) do -- for each arg
debugLog[#debugLog + 1] = ("args[%s] = %s"):format(key, val)
end -- ^length. Adding report is faster than string-based: debugLog = debugLog .. string
print(table.concat(debugLog, ". ")) -- Join with separator
mw.logObject(frame.args) -- Scribunto tool to display table
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=11>
හැට දහස is rounded from 57,000.
args[1] = 57000. args[plural] = on. args[round] = on
table#1 {
"57000",
["plural"] = "on",
["round"] = "on",
}
</syntaxhighlight></blockquote>
=== Parent frame ===
Within <code>frame</code> there is a ''parent'' frame, referring to the page that called the page that gives the script, and you can pull out arguments from that also. Just write:
<blockquote><syntaxhighlight lang="lua" line highlight=17 copy>
--[[Return true if table-like `tab` contains any non-nil entries]]--
local function has_any_args(tab)
if tab == nil then return false end -- the table is nil
for _, val in pairs(tab) do -- Iterates both numeric (positional) and string (named) keys.
if val ~= nil then -- value not nil?
return true -- one argument exists
end
end
return false -- The table does not have any arguments
end
--[[Debug console or template in wiki page?]]--
local booksPlural = "There are those books."; local pluralMarker = "s."
local globalSub = "mw.ustring.gsub(subjectStr,pattern,replace)" -- no space separator
local prm = {subjectStr=booksPlural, pattern=pluralMarker, replace=".", globalSub, "lua"}
local frame = mw.getCurrentFrame():newChild{title='Module:Lua call', args=prm}
local parent = frame:getParent() or nil
if not parent or not has_any_args(parent.args) then
print("Running from Debug console")
print(mw.text.listToText(frame.args))
else
print("Running from wiki page invoking {{template}}")
end
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=24>
Running from Debug console
mw.ustring.gsub(subjectStr,pattern,replace)
</syntaxhighlight></blockquote>
<syntaxhighlight lang="lua" inline>parent.args</syntaxhighlight> will contain those arguments.
It is popular in Lua to use the synonymous statement <code>parent=frame''':'''getParent()</code>, cancelling the need to write <code>frame</code> twice.<br/>
Note the colon (<code>:</code>) instead of the dot (<code>.</code>).
<syntaxhighlight lang="lua" inline>parent = frame:getParent()</syntaxhighlight> means exactly the same as <code>parent = frame.getParent(frame)</code>.
For novices this can be confusing, and it is important to be aware of this idiom.<br/>
If you use it in the wrong way, though, the script errors are pretty good at pointing out that this was the mistake.
== Basic debugging ==
{{Main|Help:Lua debugging}}
Debugging can start as soon as you write programs, and can be done simply with string concatenation.<br/>
Just set up a variable with some recognizable name like <syntaxhighlight lang="lua" inline>debugLog</syntaxhighlight> in your main <syntaxhighlight lang="lua" inline>function p.main(frame)</syntaxhighlight> with a statement like:
<blockquote><syntaxhighlight lang="lua" line start=3 highlight=1 copy>
local debugLog = "" -- empty report string
</syntaxhighlight></blockquote>
This initial <syntaxhighlight lang="lua" inline>""</syntaxhighlight> definition helps because otherwise it will be <syntaxhighlight lang="lua" inline>nil</syntaxhighlight> and concatenating a string to nil gets you an error.<br/>
Now whenever you have a variable you'd like to test, say {{tt|myVar}}, just write:
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=2 copy>
local myVar = 42; local output = "expected result"
debugLog = debugLog .. " myVar = " .. tostring(myVar) -- append to the report
</syntaxhighlight></blockquote>
At the end of your function (but not the module), complete:
<blockquote><syntaxhighlight lang="lua" line start=16 highlight=1 copy>
return output .. debugLog -- Returns the expected result and the report
</syntaxhighlight></blockquote>
The <syntaxhighlight lang="lua" inline>tostring(myVar)</syntaxhighlight> is a function to ensure {{tt|myVar}} is interpreted as a string.<br>
For a table, it will display as "{{samp|table}}". For nil, "{{samp|nil}}" rather than as Script error.
== Format ==
The [[WP:Lua style guide]] gives some basic formatting suggestions expected by the JavaScript module editor, such as using four-space indentations and keeping <syntaxhighlight lang="lua" inline>if then else</syntaxhighlight>, <syntaxhighlight lang="lua" inline>end</syntaxhighlight> at the same level of indentation.
Comments to the end of a line are marked by <syntaxhighlight lang="lua" inline>-- green comment</syntaxhighlight>. ''Use them.''
Many modules for Wikipedia have a straightforward, linear design, but that doesn't mean it won't help to have your sections clearly labelled when you go back to the code for the hundredth time. The Lua style guide gives additional recommendations for using functions to keep your work more organized.
== Errors ==
Lua errors appear as red "Script error" messages. If Javascript is enabled, '''the <span style="color:#ff0000;">red</span> script error message is a link''' which usually allows you to follow it back to the line in the module where the error occurred. There are some exceptions, for example "Module not found", if the name of the module itself is mistyped, or "The function you specified did not exist" if the function name given is invalid.
=== Recurrent bugs ===
Some bugs you might want to keep in mind:
;Missing operator for concatenation
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=2 copy>
local debugLog = "" -- empty report string
debugLog = debugLog "missing double dot" -- append to the report
</syntaxhighlight></blockquote>
The following means you forgot the <code>..</code> between a string and a variable somewhere in a mess of stuff you're concatenating.
<blockquote><syntaxhighlight lang="lua" line start=9>
Lua error in console input at line 8: attempt to call local 'debugLog' (a string value).
</syntaxhighlight></blockquote>
;String expected, got function
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=3 copy>
local debugLog = "" -- empty report string
local res = mw.ustring.gmatch("Hello World!", "([aeiouAEIOU])") -- iterator of vowels
debugLog = debugLog..res -- populate the report with only strings
</syntaxhighlight></blockquote>
Some important things like <syntaxhighlight lang="lua" inline>mw.ustring.gmatch</syntaxhighlight> actually return ''functions'', not strings - see [[#Functions|Functions]] below.
<blockquote><syntaxhighlight lang="lua" line start=10>
Lua error in console input at line 9: attempt to concatenate local 'res' (a function value).
</syntaxhighlight></blockquote>
;Variable ignores assignment
A variable ignores all your efforts to assign stuff to it:
<blockquote><syntaxhighlight lang="lua" line highlight=1,3 copy>
local debugLog = "top level" -- initial value
do
local debugLog = "nested level" -- set the new value
print("Inside do: "..debugLog)
end
print("Outside do: "..debugLog) -- get the old value
</syntaxhighlight></blockquote>
You may have inadvertently written ''two'' local statements - the one sets the value of the variable within a limited region, and when the program leaves that region, you're back to the old value.
<blockquote><syntaxhighlight lang="lua" line start=7>
Inside do: nested level
Outside do: top level
</syntaxhighlight></blockquote>
A numbered table entry ignores all your efforts to assign to it:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local table = {}; local arg = "50"; local valPrm = tonumber(arg)
table[arg] = "index as string"
table[valPrm] = "index as number"
print(table[arg] == table[valPrm])
</syntaxhighlight></blockquote>
This is because {{code|table["50"]}} '''is not''' {{code|table[50]}}.<br/>
Typically you have processed a parameter (which you may have received from the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> as a string) with string functions in one place,<br>
but performed numeric operations in another, leaving you with two different types of variable to use for an index.
<blockquote><syntaxhighlight lang="lua" line start=5>
false
</syntaxhighlight></blockquote>
;<syntaxhighlight lang="lua" inline>nil</syntaxhighlight> and common pitfalls
There are all sorts of things you can't do with a local variable set to nil, such as: <syntaxhighlight lang="lua" inline>local x = nil</syntaxhighlight>, like:
# Assign <code>x.somefield</code>
# Get value at index {{code|x[idx]}}
# Concatenate <syntaxhighlight lang="lua" inline>x .. "Cannot concatenate with nil"</syntaxhighlight>
# Evaluate <syntaxhighlight lang="lua" inline>table[x]</syntaxhighlight>
Initialize such variables with: <syntaxhighlight lang="lua" inline>local x={}; local table = {}</syntaxhighlight><br>
Often "global" is mentioned in these errors because you didn't have a {{tt|local}} statement for the <syntaxhighlight lang="lua" inline>nil</syntaxhighlight> variable.
;Cannot invoke module
* ''no such module.'' You called <syntaxhighlight lang="lua" inline>#invoke:moduleNameUnknown</syntaxhighlight> that didn't exist or you wrongly kept the prefix <code>Module:</code> writing {{code|#invoke:Module:moduleName}}.
* ''the function specified did not exist.'' You called <syntaxhighlight lang="lua" inline>#invoke:moduleName|functionUnknown</syntaxhighlight>, but the field after the name of the module is wrong.<br>Often this field expects a standard name like "main", and you've forgotten it and gone straight to the first data parameter.<br>If you're unsure of the function name, check the module documentation, or look for what function(s) in the code accept a "frame" parameter.
;Graphics overflow issue
Some graphics you're trying to display are heading off to the hills: actually a HTML error.<br>
You didn't close one <syntaxhighlight lang="html" inline></div></syntaxhighlight>, so all the top: and left: styles keep adding up.
== Understanding tables and related concepts ==
* An '''expression list''' is a set of values separated by commas. The values can be strings, numbers, tables, functions, etc.
* A '''sequence''' is a set of entries with indices from 1 to N, where N is a positive integer. They can be created by placing brackets around an expression list.
For example:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local seq = {1, "quotation", mw.ustring.gmatch("abca","a"), {2,3,4}}
mw.logObject(seq) -- Scribunto tool to display a table
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
table#1 {
1,
"quotation",
function#1,
table#2 {
2,
3,
4,
},
}
</syntaxhighlight></blockquote>
# <code>seq[1]</code> = 1
# <code>seq[2]</code> = <syntaxhighlight lang="lua" inline>"quotation"</syntaxhighlight>
# <code>seq[3]</code> is the <syntaxhighlight lang="lua" inline>function</syntaxhighlight> returned by <code>gmatch()</code>
# <code>seq[4]</code> is the table <code>{2,3,4}</code>.
An expression list can also be recovered from a table using <syntaxhighlight lang="lua" inline>unpack()</syntaxhighlight>:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local seq = {1, "quotation", mw.ustring.gmatch("abca","a"), {2,3,4}}
local var1Nbr, var2Str, var3Fct = unpack(seq)
print(("var1Nbr = %d. var2Str = \"%s\". var3Fct = %s"):format(var1Nbr, var2Str, type(var3Fct)))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=4>
var1Nbr = 1. var2Str = "quotation". var3Fct = function
</syntaxhighlight></blockquote>
This will set:
# <code>var1Nbr</code> = 1
# <code>var2Str</code> = <syntaxhighlight lang="lua" inline>"quotation"</syntaxhighlight>
# <code>var3Fct</code> as the <syntaxhighlight lang="lua" inline>function</syntaxhighlight> returned by <code>gmatch()</code>
# <code>{2,3,4}</code> will be discarded in this case.
* A '''table''' is a sequence, optionally supplemented by named keys: <code>digit["two"]="2"</code>. Several table functions like <code>table.concat</code> will only work with the numbered values and ignore named keys.
* The '''metatable''' offers a large, optional set of methods for altering table behavior. For example, you can define a table to be callable like a function.
=== Initializing a table ===
It is often useful to create a whole table at once in a statement. There are many equivalent ways to do this, but the shortcuts don't work for every kind of value. To begin with, the most general way is to assign each key and value explicitly:
<syntaxhighlight lang="lua" inline>a = {[0]='zero', [1]='one', ['1']='string for one'}</syntaxhighlight>
If sequence keys (positive integers) are given in order, only the values need to be given, so the following will assign <syntaxhighlight lang="lua" inline>'one'</syntaxhighlight> to <syntaxhighlight lang="lua" inline>a[1]</syntaxhighlight>:
<syntaxhighlight lang="lua" inline>a = {[0]='zero', 'one', ['1']='string for one'}</syntaxhighlight>
If a key has only letters, digits, and underscores, and begins with a non-digit, the brackets and quotation marks can be omitted:
<syntaxhighlight lang="lua" inline>a = {a='one', b='two'}</syntaxhighlight>
This is identical to <syntaxhighlight lang="lua" inline>a = {["a"]='one', ["b"]='two'}</syntaxhighlight>.
However, this will fail for keys that begin with a digit: <syntaxhighlight lang="lua" inline>hex = {7f = 127}</syntaxhighlight> will produce an error; use <syntaxhighlight lang="lua" inline>hex = {['7f'] = 127}</syntaxhighlight> instead.
Note that when given ''within'' brackets, or to the right of the equal sign, quotation marks are needed, or else string values will be taken as variables:
<syntaxhighlight lang="lua" inline> a = {[b] = c}</syntaxhighlight>
assigns the value of variable ''c'' to the key ''contained in variable'' ''b''.
== Functions ==
* Functions can return any kind of value {{--}} ''including a function''. This is a powerful feature that can readily confuse the beginner. If you set <syntaxhighlight lang="lua" inline>a=mw.ustring.gmatch(text, "(.)")</syntaxhighlight>, the result assigned to <code>a</code> will be a '''function''', not a string character! However, assigning <code>b=a()</code> by calling the function stored in <code>a</code> will return the first match (a string). Every time you set <code>b=a()</code> after that you'll get another match (string) into <code>b</code>, until you run out of matches and get <code>nil</code>. Many '''iterator functions''' act this way.
* You can keep separate counts for iterator functions by using different variables. For example, if you set <syntaxhighlight lang="lua" inline>q=mw.ustring.gmatch(text, "(x.)")</syntaxhighlight> in the same module, you can pull characters from the same piece of text (<code>text</code>) by evaluating <code>d=q()</code> without losing your place in <code>a()</code>.
* [[tail call|Tail calls]] offer substantial benefits in performance for those who master the language.
* Function names are often of the form {{code|p.myFunctionName}}, where p is the table from the {{code|return p}} at the bottom of your program. The reason for this is that you can only access functions that are entries in this table from the original {{code|#invoke}} statement. Functions for local use within the program can have any name.
== Understanding patterns ==
''Note:'' Lua patterns are ''not'' [[regular expression|regular expressions]] in the traditional POSIX sense, and they are not even a subset of regular expressions. But they share many constructs with regular expressions (more [[Help:Lua for beginners#regex|below]]).
Lua patterns are used to define, find and handle a ''pattern'' in a string. It can do the common search and replace action in a text, but it has more options that doing plain text only. For example, in one go it can change the errors 'New yorker', 'New-Yorker', and 'NewYorker' into 'New Yorker'.
* To begin with, a pattern works like a plain string so long as it doesn't contain the special characters {{code|^ $ () % . [] * + - ?}}
* Square brackets {{code|[ ]}} are used to match ''one'' ''single character'' in the string from a list of choices. {{code|[abc]}} matches the letters a, b, or c. With {{code|^}} right after {{code|[}} they indicate "anything but": {{code|[^abc]}} = not a, b, or c. Inside brackets and when not the first character, a minus {{code|-}}indicates a range: {{code|[a-z]}} matches one single character from a, b, c, …, z.
* Period {{code|.}} matches any character.
* Percent {{code|%}} indicates a large set (class) of possible character matches when it is followed by a letter. See [https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Character_class] for a full list. <!--- should test/list these empirically to be sure ---> When followed by punctuation (whether a special character above or not) the {{code|%}} is removed and the punctuation is taken as a literal character; {{code|%%}} = literal %. Special classes include a balanced class {{code|%bxy}} and {{code|%f[set]}}; see the link above for more.
* Parentheses {{code|( )}} indicate captures. The captures can be accessed later in the search string or in the string.gsub replacement string as {{code|%1}} to {{code|%9}}, and are returned by string.match as an expression list of results.
* The qualifiers {{code|? - * +}} specify repetitions of a single character (not a longer string).
:* {{code|?}} means 0 or 1 repetitions: {{code|a?}} matches "a" or "".
:* {{code|-}} means 0 or more repetitions, choosing as few as possible to achieve a match ("non-greedy"). For example {{code|2=lua|string.match("bbbb", "(.-)")}} yields "", which is less than useful because there is nothing to root the ends of the expression and prevent it from matching zero characters.
:* {{code|*}} means 0 or more repetitions, choosing as many as possible ("greedy"). For example {{code|2=lua|string.match("bbbb", ".*")}} yields bbbb.
:* {{code|+}} means 1 or more repetitions, choosing as many as possible ("greedy").
Note that the greediness of the ''leftmost'' qualifier rules over all others when there is a choice: {{code|(.*)b(.*)}} when matched on "bbb" will return "bb", "", while {{code|a(.-)b(.-)a}} when matched on "abbba" will return "", "bb".
* {{code|^}} and {{code|$}} indicate the beginning and end of the string if they occur in the appropriate place in the pattern. Otherwise they are literal characters. {{code|^}} is not used in the {{code|string.gmatch}} function.
The reference manual for Lua patterns is at [[:mw:Extension:Scribunto/Lua_reference_manual#Patterns|mediawiki.org]].
== {{anchor|regex}}Note on Lua patterns versus regular expressions ==
Lua patterns are ''loosely based'' on [[regular expression]]s (sometimes shortened to regex or regexp). Lua patterns deliberately lack the most complex regular expression constructs (to avoid bloating the Lua code base), where many other computer languages or libraries use a more complete set. Lua patterns are not even a subset of regular expressions, as there are also discrepancies, like Lua using the escape character <code>%</code> instead of <code>\,</code>, and additions, like Lua providing <code>-</code> as a non-greedy version of <code>*</code>.
Here is a list of some of the things that Lua patterns lack compared to regular expressions:
* You '''cannot''' search for alternations between anything else than single characters (you '''cannot''' say <code>(his|her)</code> to choose between <code>his</code> and <code>her</code>, you can only say <code>[abc]</code> to choose between single characters <code>a</code>, <code>b</code>, or <code>c</code>).
* You '''cannot''' look for multiples of multi-letter constructs such as <code>(choo-)*choo</code> to match <code>choo</code>, <code>choo-choo</code> or <code>choo-choo-choo</code>. There is no way to do this with Lua patterns.
* You '''cannot''' specify the minimum and maximum number of repetitions like <code>[0-9]{3,5}</code> (to match 3 to 5 digits); in Lua you would say <code>%d%d%d%d?%d?</code> instead in this case.
There are Lua libraries that offer more powerful options,<sup>[http://lua-users.org/wiki/PatternsTutorial]</sup> including regular expressions, but the support on Wikipedia is pretty basic.
Wikipedia help for regular expressions (which Lua, as mentioned, does ''not'' support) is at [[Wikipedia:AutoWikiBrowser/Regular expression]].
{{Wikipedia technical help|collapsed}}
[[Category:Module help|*]]
ofe344rdhio8iess0ht7drb9rerp2a5
790928
790927
2026-05-19T19:30:25Z
Nimmzo
78995
/* Basic debugging */ "Print the contents of a table" shows how to test Scribunto parser function "#language", "#tag" about isbn book, "plural", and "canonicalurl". "#tag" requires a table of arguments that needs unpack(arg). This more advanced sample indicates how to call safe pcall. "plural" parser function selects singular or plural expression according to the given number 42: this will be also the first part of the final sample before running LuaCall in Debug console.
790928
wikitext
text/x-wiki
{{WikiProject Lua header}}
{{Selfref|This help page is meant to provide some basic orientation for those new to Lua/Scribunto.}}
{{ඉංග්රීසි ව්යාපෘතියේ සිට ආයාත කළ පිටුව}}
== Overview ==
[[WP:Lua|Lua]] is a lightweight scripting language safely available on Wikipedia via [[mw:Extension:Scribunto|Scribunto]]. Its purpose is to allow you to process the data which is available on Wikipedia content pages to allow various sorts of customized display of information.
It runs in a sandboxed environment to protect the stability of Wikipedia while enabling powerful <syntaxhighlight lang="lua" inline>{{template}}</syntaxhighlight> and <syntaxhighlight lang="lua" inline>module:</syntaxhighlight> functionality.
The most important help file is the [[mw:Extension:Scribunto/Lua reference manual|MediaWiki Scribunto Lua reference manual]], which provides a concise summary of the language and standard library calls as implemented on MediaWiki.
The standard [http://www.lua.org/manual/5.1/manual.html Lua reference manual] is well written and comprehensive, but it can be confusing for beginners because some standard features don't work on wiki pages. You cannot call <syntaxhighlight lang="lua" inline>print("Hello, World!")</syntaxhighlight> in a module, but you can preview your User page showing the string <syntaxhighlight lang="lua" inline>"Hello World!"</syntaxhighlight> generated by the Lua [[Module:Example]]. Think of your Lua template as an HTML generator.
=== Generating "Hello World!" ===
You do not need to install or save anything.
# Edit your User page: <code>පරිශීලක:YourUserName</code>
# Paste the following call at the beginning of a new line on your User page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{#invoke:Example|hello}}
</syntaxhighlight></blockquote>
<ol start="3">
<li>Click <code>Preview</code>. The call of the function <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> in the [[Module:Example]] is replaced with the following:</li>
</ol>
<blockquote><syntaxhighlight lang="lua" line>
Hello World!
</syntaxhighlight></blockquote>
<ol start="4">
<li>Click <code>Cancel</code>. When prompted, click <code>Leave</code>.</li>
<li>Your User page remains '''un'''modified.</li>
</ol>
== Debug console: Start learning Lua ==
The Lua Scribunto <code>Debug Console</code> is a safe, interactive tool for learning Lua in Wikipedia.
# Click <code>Edit</code> on the [[Module:Yesno]] page.
# Scroll to the bottom of the page to the <code>Debug console</code> section beneath the Lua editor.
# Paste the comment and the call into the <span style="color:#86888c;">gray</span> input box (above the <code>Clear</code> button).
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
--[[ඔබගේ ආරම්භක Lua "හෙලෝ වර්ල්ඩ්" යන වගේම වැඩසටහන]]--
print("වෙල්කම් වෙයි " .. _VERSION .. "!") -- Lua අනුවාදය .. සමඟ එකතු කරයි
</syntaxhighlight></blockquote>
<ol start="4">
<li>Press {{key press|Enter}} once to execute the two Lua command''s''.</li>
<li>The result will appear below the Lua <syntaxhighlight lang="lua" inline>print</syntaxhighlight> command line:</li>
</ol>
<blockquote><syntaxhighlight lang="lua" line start=3>
වෙල්කම් වෙයි Lua 5.1!
</syntaxhighlight></blockquote>
<ol start="6">
<li>Press <code>Up arrow</code> (↑) to cycle through previous Lua commands.</li>
<li>Optionally, click <code>Clear</code> to clear ''only'' the <code>Debug Console</code>; the Lua editor above will remain '''un'''modified.</li>
</ol>
; HTML generator in the Debug console
Call the function <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> in <code>Module:</code>Example:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local modExample = require('Module:Example') -- load the module in Debug console
local frame = mw.getCurrentFrame(); print(modExample.hello(frame)) -- display "Hello World!"
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
Hello World!
</syntaxhighlight></blockquote>
; Identity function
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local yesno = require('Module:Yesno') -- #if yesno then returns its input parameter
print(mw.getCurrentFrame():callParserFunction("#if", yesno("Yes"), "Yes", 'නැහැ'))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
Yes
</syntaxhighlight></blockquote>
# Close the protected <code>Module:</code>Yesno that remains '''un'''modified.
== Issues with the current implementation ==
Besides the lack of <code>print()</code> in a module, there are other features missing – see [[mw:Extension:Scribunto/Lua reference manual#Differences from standard Lua|Differences from standard Lua]] for a complete list.
At the present time, it is advisable to use ''[[mw:Extension:Scribunto/Lua reference manual#Ustring library|mw.ustring]]'' functions instead of ''[[mw:Extension:Scribunto/Lua reference manual#String library|string]]'', because the latter sometimes fails with Unicode characters.
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local lang = mw.getCurrentFrame():callParserFunction("#language", "si") -- Sinhala
local lenUnicode, lenByte, lenSharp = mw.ustring.len(lang), string.len(lang), #lang
print(("lang: %s Mw.ustring.len = %d String.len = %d Sharp = %d"):format(lang, lenUnicode, lenByte, lenSharp))
</syntaxhighlight></blockquote>
Debug console supports Unicode:
<blockquote><syntaxhighlight lang="lua" line start=4>
lang: සිංහල Mw.ustring.len = 5 String.len = 15 Sharp = 15
</syntaxhighlight></blockquote>
== Input ==
The programs are run only when the page is "parsed" (when it or a page it incorporates is changed or previewed), not every time you view the output. Therefore there can be no convenient Lua module that allows you to type in a Fahrenheit temperature in an input box and get back the corresponding Celsius temperature when you press a button, or allows you to click on a segment of a Mandelbrot set visualization on a page to expand it as often as you like. There has to be an actual Wiki page (or at least a page you have submitted for preview) containing the input data.
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local function toCelsius(tempFahrenheit) return (tempFahrenheit - 32) * 5 / 9 end
print(("toCelsius(32°F) = %s°C. toCelsius(68°F) = %d°C"):format(toCelsius(32), toCelsius(68)))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
toCelsius(32°F) = 0°C. toCelsius(68°F) = 20°C
</syntaxhighlight></blockquote>
However, it is possible to use library functions like [[mw:Extension:Scribunto/Lua reference manual#mw.title.getCurrentTitle|mw.title.getCurrentTitle()]] to import content from any text content page on the Wiki.
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
print(mw.title.getCurrentTitle())
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=2>
Module:Yesno
</syntaxhighlight></blockquote>
You cannot, however, import data from files, not even .svg files which contain XML text data.
== Calling a Lua module ==
Lua calls look much like [[WP:template|template]]s, and consist of a small block of text.
In your User page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{ConvertNumeric|decToHex|73}}
</syntaxhighlight></blockquote>
Click <code>Preview</code> or click <code>Edit</code> this section to see the call then <code>Cancel</code>:
<blockquote>
{{#invoke:ConvertNumeric|decToHex|73}}
</blockquote>
This text calls the Lua script itself, which is housed in the <code>Module:</code> [[WP:namespace|namespace]]. The effect of this call is to send the information within the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> block to the Lua module, and to replace everything within the brackets with a piece of text that it sends back in return. (Literally, in the "return" statement)
Note that the first "parameter", in this case <code>decToHex</code>, is actually a <syntaxhighlight lang="lua" inline>function</syntaxhighlight> called within the Lua module. This field must always be included in any <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight>. To those unfamiliar with modules, especially Wikipedia template coders who expect anything after <code>|</code> to be a parameter, the need for this extra field is surprising, especially if all uses of the module depend on its presence.
In Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local convNum = require('Module:ConvertNumeric')
local frame = mw.getCurrentFrame(); frame.args[1] = "73" -- number always as string
print(("0x%s = %s = %d"):format(convNum.decToHex(frame), string.format("0x%X", 73), 0x49))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=4>
0x49 = 0x49 = 73
</syntaxhighlight></blockquote>
=== Documenting a Lua module ===
When documenting your module, it is useful to include an explicit usage instruction using [[සැකිල්ල:Module link expanded]]:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{mlx|ConvertNumeric|decToHex|73}}
</syntaxhighlight></blockquote>
Hyperlink to the module:
<blockquote>
{{mlx|ConvertNumeric|decToHex|73}}
</blockquote>
For many existing modules, an example <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> of the script (and little else) is provided on the <code>Module talk:</code> page. It is convenient for authors to be able to flip quickly to the talk tab to look at the effects of their changes, but you should never transclude the talk page as a template - people might actually talk on it! Alternatively, the module page can show documentation from a separate /doc-page (as [[Module:WikidataIB]] does).
=== Another example: Using LuaCall to perform a single Lua instruction ===
As a beginner, or in casual talk page conversation, you might only have one little calculation you want to use Lua for but don't want to write a full module. You might find [[Module:LuaCall]] convenient for this.
For example, count up the length of a string.
In your user page:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
{{#invoke:LuaCall|main|strText=count the length of your DYK hook with Lua|string.len(strText)}}
</syntaxhighlight></blockquote>
<blockquote>
{{#invoke:LuaCall|main|strText=count the length of your DYK hook with Lua|string.len(strText)}}
</blockquote>
You can test how a greedy [https://www.lua.org/pil/20.1.html Lua pattern] works: '''reg'''ular '''ex'''pression <code>.*</code> matches zero or more. <code>.+</code> matches one or more.
In your user page:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
{{#invoke:LuaCall|main|strText=bbbbbbbbbba|regex=bb(.*)b(.+)bba|string.match(strText,regex)}}
</syntaxhighlight></blockquote>
LuaCall returns the first match ignoring other results:
<blockquote>
{{#invoke:LuaCall|main|strText=bbbbbbbbbba|regex=bb(.*)b(.+)bba|string.match(strText,regex)}}
</blockquote>
In these specific examples, however, [[Module:String]] could do both of these tasks in Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
--[[Do You Know (DYK)]]--
local strText = "count the length of your DYK hook with Lua"; print(string.len(strText))
strText = "bbbbbbbbbba"; regex = "bb(.*)b(.+)bba" -- greedy pattern as much as possible
local table = {string.match(strText, regex)}; print(table[1]) -- returns the first match
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=5>
42
bbbb
</syntaxhighlight></blockquote>
The script at [[Module:LuaCall]] has been written to accept any set of named parameters <code>somename=value</code>, for each one storing the string <code>value</code> in the variable with the name <code>somename</code>, and then allowing you to use these variables as parameters for any function available in Lua. The script then returns only the ''first'' value returned by the function ([https://www.lua.org/pil/5.1.html Lua functions can return multiple values], but in this case, only the first is returned from the module).
== Lua program structure: Output ==
The most fundamental part of a Wikipedia Lua program is a <syntaxhighlight lang="lua" inline>return</syntaxhighlight> statement which carries its output back to the page that had the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight>. You ''can'' have a Lua function that runs without error even though it doesn't contain a return statement, but on Wikipedia it is pointless, as Lua programs cannot generally have side effects on Wikipedia.
The module itself must return a Lua '''table''' of values. A Lua table is expressed as a list of values separated by commas, within curly braces. When the module is called by <code>#invoke</code>, the '''function''' it names (the first argument after |) is looked for in that table. That function, in turn, is expected to return something that can be represented as a '''string'''.
Typically we use the overall form for [[Module:Example]]:
<syntaxhighlight lang="lua" line highlight=3 copy>
local p = {} -- Defines the empty (non-nil) table package, the only single-letter variable
function p.hello(frame) -- Define the function p.hello. The input parameter frame is not used
return "Hello World!" -- Returns the string result of the function.
end -- Ends the function
return p -- This returns the table package
</syntaxhighlight>
Note that <syntaxhighlight lang="lua" inline>function p.hello(frame)</syntaxhighlight> is equivalent to anonymous <syntaxhighlight lang="lua" inline>p.hello = function(frame)</syntaxhighlight> or <syntaxhighlight lang="lua" inline>p["hello"] = function(frame)</syntaxhighlight>.
The function is just another '''type''' of value, retrieved with the key <code>"hello"</code> from table <code>p</code>.
If you want to allow users to invoke the same module with <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|main}}</nowiki></code> instead of <syntaxhighlight lang="lua" inline>{{#invoke:Example|hello}}</syntaxhighlight>, you can write:
<syntaxhighlight lang="lua" line start=6>
p.main = p.hello -- to copy the reference to this function to a new key in the table.
</syntaxhighlight>
You can even write <code>p[""] = p.hello</code>, which causes <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|}}</nowiki></code> to produce the same output as <syntaxhighlight lang="lua" inline>{{#invoke:Example|hello}}</syntaxhighlight>.
Learning to think of functions as a data '''type''' becomes very important later on for working with library functions like <code>[[mw:Extension:Scribunto/Lua_reference_manual#string.gsub|mw.ustring.gsub]]</code>, and constructing iterator functions:
;gmatch-based advanced minimal module iterator of vowels
The <code>Module:</code>MatchVowel is actually a complete Lua module (though a very strange one):
<blockquote><syntaxhighlight lang="lua" line highlight=2>
--[[MatchVowel returns a table containing the iterator function of vowels]]--
return { mw.ustring.gmatch( "Hello World!", "([aeiou])" ) } -- returns a table with the iterator
</syntaxhighlight></blockquote>
It returns the iterator function returned by <code>[[mw:Extension:Scribunto/Lua_reference_manual#string.gmatch|mw.ustring.gmatch]]</code> as the one and only element in an array.
If <code>Module:</code>MatchVowel was saved in its own wiki page, when executed in another wiki page:
<blockquote><syntaxhighlight lang="lua" line highlight=1>
{{#invoke:MatchVowel|1}}
</syntaxhighlight></blockquote>
The call yields the vowel from "Hello World!":
<blockquote><syntaxhighlight lang="lua" line start=1>
e
</syntaxhighlight></blockquote>
In Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
--[[iterator function that yields each vowel (case-sensitive) from the string "Hello World!"]]--
local tabMatchVowel = (function() return {mw.ustring.gmatch("Hello World!", "([aeiou])")} end)()
local itv = tabMatchVowel[1] -- iterator function from gmatch as the sole element of the table
local vowel; repeat vowel = itv(); if vowel then print(vowel) end until not (vowel) -- each vowel
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=5>
e
o
o
</syntaxhighlight></blockquote>
== Lua program structure: Input ==
The '''<code>frame</code>''' parameter above (which is pretty much always given this name in Wikipedia Lua modules) receives another table, which is passed ''from'' the page that makes the call ''to'' the Lua module. It contains a surprising amount of stuff, of which just a few things concern the novice.
=== Arguments ===
{{see also|Module:Arguments}}
<code>frame.args</code> contains ''another'' table, namely, all the content sent by the user within the <code>#invoke</code> brackets except the first argument which states the name of the function to be executed.
In your User page: about [[Module:ConvertNumeric]]
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{#invoke:ConvertNumeric |numeral_to_english |57000 |round=on |plural=on}}
</syntaxhighlight></blockquote>
Click <code>Preview</code> or click <code>Edit</code> this section to see the call then <code>Cancel</code>:
<blockquote>
{{#invoke:ConvertNumeric |numeral_to_english |57000 |round=on |plural=on}}
</blockquote>
There are two types of parameters: numeric (positional) keys and named keys.
# Unnamed parameters come out with numbers as keys: <code>frame.args[1]</code>.<br/>The string <code>"57000"</code> is the content of <code>frame.args[1]</code> which is the same as <code>frame["args"][1]</code><br/>but ''not'' the same as <code>frame.args["1"]</code> or <code>frame["args"]["1"]</code>.
# Named parameters come out with the parameter names (strings) as keys: <code>frame.args["round"]</code>, <code>frame.args["plural"]</code>.
In Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=4 copy>
--[[Convert a number to letter in Sinhala]]--
local convNum = require('Module:ConvertNumeric')
local frame=mw.getCurrentFrame(); frame.args = {"57000", round="on", plural="on"}
print(convNum.numeral_to_english(frame) .. " is rounded from 57,000.")
local debugLog = {} -- empty report table
for key, val in pairs(frame.args) do -- for each arg
debugLog[#debugLog + 1] = ("args[%s] = %s"):format(key, val)
end -- ^length. Adding report is faster than string-based: debugLog = debugLog .. string
print(table.concat(debugLog, ". ")) -- Join with separator
mw.logObject(frame.args) -- Scribunto tool to display table
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=11>
හැට දහස is rounded from 57,000.
args[1] = 57000. args[plural] = on. args[round] = on
table#1 {
"57000",
["plural"] = "on",
["round"] = "on",
}
</syntaxhighlight></blockquote>
=== Parent frame ===
Within <code>frame</code> there is a ''parent'' frame, referring to the page that called the page that gives the script, and you can pull out arguments from that also. Just write:
<blockquote><syntaxhighlight lang="lua" line highlight=17 copy>
--[[Return true if table-like `tab` contains any non-nil entries]]--
local function has_any_args(tab)
if tab == nil then return false end -- the table is nil
for _, val in pairs(tab) do -- Iterates both numeric (positional) and string (named) keys.
if val ~= nil then -- value not nil?
return true -- one argument exists
end
end
return false -- The table does not have any arguments
end
--[[Debug console or template in wiki page?]]--
local booksPlural = "There are those books."; local pluralMarker = "s."
local globalSub = "mw.ustring.gsub(subjectStr,pattern,replace)" -- no space separator
local prm = {subjectStr=booksPlural, pattern=pluralMarker, replace=".", globalSub, "lua"}
local frame = mw.getCurrentFrame():newChild{title='Module:Lua call', args=prm}
local parent = frame:getParent() or nil
if not parent or not has_any_args(parent.args) then
print("Running from Debug console")
print(mw.text.listToText(frame.args))
else
print("Running from wiki page invoking {{template}}")
end
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=24>
Running from Debug console
mw.ustring.gsub(subjectStr,pattern,replace)
</syntaxhighlight></blockquote>
<syntaxhighlight lang="lua" inline>parent.args</syntaxhighlight> will contain those arguments.
It is popular in Lua to use the synonymous statement <code>parent=frame''':'''getParent()</code>, cancelling the need to write <code>frame</code> twice.<br/>
Note the colon (<code>:</code>) instead of the dot (<code>.</code>).
<syntaxhighlight lang="lua" inline>parent = frame:getParent()</syntaxhighlight> means exactly the same as <code>parent = frame.getParent(frame)</code>.
For novices this can be confusing, and it is important to be aware of this idiom.<br/>
If you use it in the wrong way, though, the script errors are pretty good at pointing out that this was the mistake.
== Basic debugging ==
{{Main|Help:Lua debugging}}
Debugging can start as soon as you write programs, and can be done simply with string concatenation.<br/>
Just set up a variable with some recognizable name like <syntaxhighlight lang="lua" inline>debugLog</syntaxhighlight> in your main <syntaxhighlight lang="lua" inline>function p.main(frame)</syntaxhighlight> with a statement like:
<blockquote><syntaxhighlight lang="lua" line start=3 highlight=1 copy>
local debugLog = "" -- empty report string
</syntaxhighlight></blockquote>
This initial <syntaxhighlight lang="lua" inline>""</syntaxhighlight> definition helps because otherwise it will be <syntaxhighlight lang="lua" inline>nil</syntaxhighlight> and concatenating a string to nil gets you an error.<br/>
Now whenever you have a variable you'd like to test, say {{tt|myVar}}, just write:
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=2 copy>
local myVar = 42; local output = "expected result"
debugLog = debugLog .. " myVar = " .. tostring(myVar) -- append to the report
</syntaxhighlight></blockquote>
At the end of your function (but not the module), complete:
<blockquote><syntaxhighlight lang="lua" line start=16 highlight=1 copy>
return output .. debugLog -- Returns the expected result and the report
</syntaxhighlight></blockquote>
The <syntaxhighlight lang="lua" inline>tostring(myVar)</syntaxhighlight> is a function to ensure {{tt|myVar}} is interpreted as a string.<br>
For a table, it will display as "{{samp|table}}". For nil, "{{samp|nil}}" rather than as Script error.
;Print the contents of a table
<syntaxhighlight lang="lua" line highlight=2,13,18,21 copy>
local frame = mw.getCurrentFrame()
local candidates = {
{"#language", "ja"}, -- #language parser function retrieve (ja)panese language
{"#tag", {'isbn', '978-4-87311-471-2'}}, -- #tag parser function generates <isbn> tag
{"plural", {'42', 'book', 'books'}}, -- plural switches sentences based on number
{"canonicalurl", tostring(mw.title.getCurrentTitle())}, -- canonicalurl returns the URL of the page
}
local function args_to_string(obj)
if type(obj) == "table" then return table.concat(obj, " ") else return tostring(obj or "") end
end
for _, pair in ipairs(candidates) do -- _ = ignored index, pair = value; ipairs iterates each numeric key
local fn, arg = pair[1], pair[2] -- Parser function name to call and its argument, string or table
local ok, res
if type(arg) == "table" then
-- If the argument is a table, unpack it and pass as multiple arguments
ok, res = pcall(function() return frame:callParserFunction(fn, unpack(arg)) end)
else
-- If the argument is a single value (string), pass it as-is
ok, res = pcall(function() return frame:callParserFunction(fn, arg or "") end) -- Safe call (pcall)
end
local out = ok and tostring(res) or ("<error>") -- Convert to string on success, "<error>" on failure
-- Join argument tables for readability. Output is for the Lua console
print(string.format('%s(%q) -> %s', fn, args_to_string(arg), out))
end
</syntaxhighlight>
<syntaxhighlight lang="lua" line start=27>
#language("ja") -> 日本語
#tag("isbn 978-4-87311-471-2") -> <isbn>978-4-87311-471-2</isbn>
plural("42 book books") -> books
canonicalurl("Module:Yesno") -> https://si.wikipedia.org/wiki/Module:Yesno
</syntaxhighlight>
== Format ==
The [[WP:Lua style guide]] gives some basic formatting suggestions expected by the JavaScript module editor, such as using four-space indentations and keeping <syntaxhighlight lang="lua" inline>if then else</syntaxhighlight>, <syntaxhighlight lang="lua" inline>end</syntaxhighlight> at the same level of indentation.
Comments to the end of a line are marked by <syntaxhighlight lang="lua" inline>-- green comment</syntaxhighlight>. ''Use them.''
Many modules for Wikipedia have a straightforward, linear design, but that doesn't mean it won't help to have your sections clearly labelled when you go back to the code for the hundredth time. The Lua style guide gives additional recommendations for using functions to keep your work more organized.
== Errors ==
Lua errors appear as red "Script error" messages. If Javascript is enabled, '''the <span style="color:#ff0000;">red</span> script error message is a link''' which usually allows you to follow it back to the line in the module where the error occurred. There are some exceptions, for example "Module not found", if the name of the module itself is mistyped, or "The function you specified did not exist" if the function name given is invalid.
=== Recurrent bugs ===
Some bugs you might want to keep in mind:
;Missing operator for concatenation
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=2 copy>
local debugLog = "" -- empty report string
debugLog = debugLog "missing double dot" -- append to the report
</syntaxhighlight></blockquote>
The following means you forgot the <code>..</code> between a string and a variable somewhere in a mess of stuff you're concatenating.
<blockquote><syntaxhighlight lang="lua" line start=9>
Lua error in console input at line 8: attempt to call local 'debugLog' (a string value).
</syntaxhighlight></blockquote>
;String expected, got function
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=3 copy>
local debugLog = "" -- empty report string
local res = mw.ustring.gmatch("Hello World!", "([aeiouAEIOU])") -- iterator of vowels
debugLog = debugLog..res -- populate the report with only strings
</syntaxhighlight></blockquote>
Some important things like <syntaxhighlight lang="lua" inline>mw.ustring.gmatch</syntaxhighlight> actually return ''functions'', not strings - see [[#Functions|Functions]] below.
<blockquote><syntaxhighlight lang="lua" line start=10>
Lua error in console input at line 9: attempt to concatenate local 'res' (a function value).
</syntaxhighlight></blockquote>
;Variable ignores assignment
A variable ignores all your efforts to assign stuff to it:
<blockquote><syntaxhighlight lang="lua" line highlight=1,3 copy>
local debugLog = "top level" -- initial value
do
local debugLog = "nested level" -- set the new value
print("Inside do: "..debugLog)
end
print("Outside do: "..debugLog) -- get the old value
</syntaxhighlight></blockquote>
You may have inadvertently written ''two'' local statements - the one sets the value of the variable within a limited region, and when the program leaves that region, you're back to the old value.
<blockquote><syntaxhighlight lang="lua" line start=7>
Inside do: nested level
Outside do: top level
</syntaxhighlight></blockquote>
A numbered table entry ignores all your efforts to assign to it:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local table = {}; local arg = "50"; local valPrm = tonumber(arg)
table[arg] = "index as string"
table[valPrm] = "index as number"
print(table[arg] == table[valPrm])
</syntaxhighlight></blockquote>
This is because {{code|table["50"]}} '''is not''' {{code|table[50]}}.<br/>
Typically you have processed a parameter (which you may have received from the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> as a string) with string functions in one place,<br>
but performed numeric operations in another, leaving you with two different types of variable to use for an index.
<blockquote><syntaxhighlight lang="lua" line start=5>
false
</syntaxhighlight></blockquote>
;<syntaxhighlight lang="lua" inline>nil</syntaxhighlight> and common pitfalls
There are all sorts of things you can't do with a local variable set to nil, such as: <syntaxhighlight lang="lua" inline>local x = nil</syntaxhighlight>, like:
# Assign <code>x.somefield</code>
# Get value at index {{code|x[idx]}}
# Concatenate <syntaxhighlight lang="lua" inline>x .. "Cannot concatenate with nil"</syntaxhighlight>
# Evaluate <syntaxhighlight lang="lua" inline>table[x]</syntaxhighlight>
Initialize such variables with: <syntaxhighlight lang="lua" inline>local x={}; local table = {}</syntaxhighlight><br>
Often "global" is mentioned in these errors because you didn't have a {{tt|local}} statement for the <syntaxhighlight lang="lua" inline>nil</syntaxhighlight> variable.
;Cannot invoke module
* ''no such module.'' You called <syntaxhighlight lang="lua" inline>#invoke:moduleNameUnknown</syntaxhighlight> that didn't exist or you wrongly kept the prefix <code>Module:</code> writing {{code|#invoke:Module:moduleName}}.
* ''the function specified did not exist.'' You called <syntaxhighlight lang="lua" inline>#invoke:moduleName|functionUnknown</syntaxhighlight>, but the field after the name of the module is wrong.<br>Often this field expects a standard name like "main", and you've forgotten it and gone straight to the first data parameter.<br>If you're unsure of the function name, check the module documentation, or look for what function(s) in the code accept a "frame" parameter.
;Graphics overflow issue
Some graphics you're trying to display are heading off to the hills: actually a HTML error.<br>
You didn't close one <syntaxhighlight lang="html" inline></div></syntaxhighlight>, so all the top: and left: styles keep adding up.
== Understanding tables and related concepts ==
* An '''expression list''' is a set of values separated by commas. The values can be strings, numbers, tables, functions, etc.
* A '''sequence''' is a set of entries with indices from 1 to N, where N is a positive integer. They can be created by placing brackets around an expression list.
For example:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local seq = {1, "quotation", mw.ustring.gmatch("abca","a"), {2,3,4}}
mw.logObject(seq) -- Scribunto tool to display a table
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
table#1 {
1,
"quotation",
function#1,
table#2 {
2,
3,
4,
},
}
</syntaxhighlight></blockquote>
# <code>seq[1]</code> = 1
# <code>seq[2]</code> = <syntaxhighlight lang="lua" inline>"quotation"</syntaxhighlight>
# <code>seq[3]</code> is the <syntaxhighlight lang="lua" inline>function</syntaxhighlight> returned by <code>gmatch()</code>
# <code>seq[4]</code> is the table <code>{2,3,4}</code>.
An expression list can also be recovered from a table using <syntaxhighlight lang="lua" inline>unpack()</syntaxhighlight>:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local seq = {1, "quotation", mw.ustring.gmatch("abca","a"), {2,3,4}}
local var1Nbr, var2Str, var3Fct = unpack(seq)
print(("var1Nbr = %d. var2Str = \"%s\". var3Fct = %s"):format(var1Nbr, var2Str, type(var3Fct)))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=4>
var1Nbr = 1. var2Str = "quotation". var3Fct = function
</syntaxhighlight></blockquote>
This will set:
# <code>var1Nbr</code> = 1
# <code>var2Str</code> = <syntaxhighlight lang="lua" inline>"quotation"</syntaxhighlight>
# <code>var3Fct</code> as the <syntaxhighlight lang="lua" inline>function</syntaxhighlight> returned by <code>gmatch()</code>
# <code>{2,3,4}</code> will be discarded in this case.
* A '''table''' is a sequence, optionally supplemented by named keys: <code>digit["two"]="2"</code>. Several table functions like <code>table.concat</code> will only work with the numbered values and ignore named keys.
* The '''metatable''' offers a large, optional set of methods for altering table behavior. For example, you can define a table to be callable like a function.
=== Initializing a table ===
It is often useful to create a whole table at once in a statement. There are many equivalent ways to do this, but the shortcuts don't work for every kind of value. To begin with, the most general way is to assign each key and value explicitly:
<syntaxhighlight lang="lua" inline>a = {[0]='zero', [1]='one', ['1']='string for one'}</syntaxhighlight>
If sequence keys (positive integers) are given in order, only the values need to be given, so the following will assign <syntaxhighlight lang="lua" inline>'one'</syntaxhighlight> to <syntaxhighlight lang="lua" inline>a[1]</syntaxhighlight>:
<syntaxhighlight lang="lua" inline>a = {[0]='zero', 'one', ['1']='string for one'}</syntaxhighlight>
If a key has only letters, digits, and underscores, and begins with a non-digit, the brackets and quotation marks can be omitted:
<syntaxhighlight lang="lua" inline>a = {a='one', b='two'}</syntaxhighlight>
This is identical to <syntaxhighlight lang="lua" inline>a = {["a"]='one', ["b"]='two'}</syntaxhighlight>.
However, this will fail for keys that begin with a digit: <syntaxhighlight lang="lua" inline>hex = {7f = 127}</syntaxhighlight> will produce an error; use <syntaxhighlight lang="lua" inline>hex = {['7f'] = 127}</syntaxhighlight> instead.
Note that when given ''within'' brackets, or to the right of the equal sign, quotation marks are needed, or else string values will be taken as variables:
<syntaxhighlight lang="lua" inline> a = {[b] = c}</syntaxhighlight>
assigns the value of variable ''c'' to the key ''contained in variable'' ''b''.
== Functions ==
* Functions can return any kind of value {{--}} ''including a function''. This is a powerful feature that can readily confuse the beginner. If you set <syntaxhighlight lang="lua" inline>a=mw.ustring.gmatch(text, "(.)")</syntaxhighlight>, the result assigned to <code>a</code> will be a '''function''', not a string character! However, assigning <code>b=a()</code> by calling the function stored in <code>a</code> will return the first match (a string). Every time you set <code>b=a()</code> after that you'll get another match (string) into <code>b</code>, until you run out of matches and get <code>nil</code>. Many '''iterator functions''' act this way.
* You can keep separate counts for iterator functions by using different variables. For example, if you set <syntaxhighlight lang="lua" inline>q=mw.ustring.gmatch(text, "(x.)")</syntaxhighlight> in the same module, you can pull characters from the same piece of text (<code>text</code>) by evaluating <code>d=q()</code> without losing your place in <code>a()</code>.
* [[tail call|Tail calls]] offer substantial benefits in performance for those who master the language.
* Function names are often of the form {{code|p.myFunctionName}}, where p is the table from the {{code|return p}} at the bottom of your program. The reason for this is that you can only access functions that are entries in this table from the original {{code|#invoke}} statement. Functions for local use within the program can have any name.
== Understanding patterns ==
''Note:'' Lua patterns are ''not'' [[regular expression|regular expressions]] in the traditional POSIX sense, and they are not even a subset of regular expressions. But they share many constructs with regular expressions (more [[Help:Lua for beginners#regex|below]]).
Lua patterns are used to define, find and handle a ''pattern'' in a string. It can do the common search and replace action in a text, but it has more options that doing plain text only. For example, in one go it can change the errors 'New yorker', 'New-Yorker', and 'NewYorker' into 'New Yorker'.
* To begin with, a pattern works like a plain string so long as it doesn't contain the special characters {{code|^ $ () % . [] * + - ?}}
* Square brackets {{code|[ ]}} are used to match ''one'' ''single character'' in the string from a list of choices. {{code|[abc]}} matches the letters a, b, or c. With {{code|^}} right after {{code|[}} they indicate "anything but": {{code|[^abc]}} = not a, b, or c. Inside brackets and when not the first character, a minus {{code|-}}indicates a range: {{code|[a-z]}} matches one single character from a, b, c, …, z.
* Period {{code|.}} matches any character.
* Percent {{code|%}} indicates a large set (class) of possible character matches when it is followed by a letter. See [https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Character_class] for a full list. <!--- should test/list these empirically to be sure ---> When followed by punctuation (whether a special character above or not) the {{code|%}} is removed and the punctuation is taken as a literal character; {{code|%%}} = literal %. Special classes include a balanced class {{code|%bxy}} and {{code|%f[set]}}; see the link above for more.
* Parentheses {{code|( )}} indicate captures. The captures can be accessed later in the search string or in the string.gsub replacement string as {{code|%1}} to {{code|%9}}, and are returned by string.match as an expression list of results.
* The qualifiers {{code|? - * +}} specify repetitions of a single character (not a longer string).
:* {{code|?}} means 0 or 1 repetitions: {{code|a?}} matches "a" or "".
:* {{code|-}} means 0 or more repetitions, choosing as few as possible to achieve a match ("non-greedy"). For example {{code|2=lua|string.match("bbbb", "(.-)")}} yields "", which is less than useful because there is nothing to root the ends of the expression and prevent it from matching zero characters.
:* {{code|*}} means 0 or more repetitions, choosing as many as possible ("greedy"). For example {{code|2=lua|string.match("bbbb", ".*")}} yields bbbb.
:* {{code|+}} means 1 or more repetitions, choosing as many as possible ("greedy").
Note that the greediness of the ''leftmost'' qualifier rules over all others when there is a choice: {{code|(.*)b(.*)}} when matched on "bbb" will return "bb", "", while {{code|a(.-)b(.-)a}} when matched on "abbba" will return "", "bb".
* {{code|^}} and {{code|$}} indicate the beginning and end of the string if they occur in the appropriate place in the pattern. Otherwise they are literal characters. {{code|^}} is not used in the {{code|string.gmatch}} function.
The reference manual for Lua patterns is at [[:mw:Extension:Scribunto/Lua_reference_manual#Patterns|mediawiki.org]].
== {{anchor|regex}}Note on Lua patterns versus regular expressions ==
Lua patterns are ''loosely based'' on [[regular expression]]s (sometimes shortened to regex or regexp). Lua patterns deliberately lack the most complex regular expression constructs (to avoid bloating the Lua code base), where many other computer languages or libraries use a more complete set. Lua patterns are not even a subset of regular expressions, as there are also discrepancies, like Lua using the escape character <code>%</code> instead of <code>\,</code>, and additions, like Lua providing <code>-</code> as a non-greedy version of <code>*</code>.
Here is a list of some of the things that Lua patterns lack compared to regular expressions:
* You '''cannot''' search for alternations between anything else than single characters (you '''cannot''' say <code>(his|her)</code> to choose between <code>his</code> and <code>her</code>, you can only say <code>[abc]</code> to choose between single characters <code>a</code>, <code>b</code>, or <code>c</code>).
* You '''cannot''' look for multiples of multi-letter constructs such as <code>(choo-)*choo</code> to match <code>choo</code>, <code>choo-choo</code> or <code>choo-choo-choo</code>. There is no way to do this with Lua patterns.
* You '''cannot''' specify the minimum and maximum number of repetitions like <code>[0-9]{3,5}</code> (to match 3 to 5 digits); in Lua you would say <code>%d%d%d%d?%d?</code> instead in this case.
There are Lua libraries that offer more powerful options,<sup>[http://lua-users.org/wiki/PatternsTutorial]</sup> including regular expressions, but the support on Wikipedia is pretty basic.
Wikipedia help for regular expressions (which Lua, as mentioned, does ''not'' support) is at [[Wikipedia:AutoWikiBrowser/Regular expression]].
{{Wikipedia technical help|collapsed}}
[[Category:Module help|*]]
nhuahrau256o8b00ajqcmk42b8as330
790929
790928
2026-05-19T19:50:33Z
Nimmzo
78995
/* Another example: Using LuaCall to perform a single Lua instruction */ Fixed typo. /* Parent frame */ Fixed typo [[en:Module:Lua call]] with space separator vs. better [[si:Module:LuaCall]] without space separator
790929
wikitext
text/x-wiki
{{WikiProject Lua header}}
{{Selfref|This help page is meant to provide some basic orientation for those new to Lua/Scribunto.}}
{{ඉංග්රීසි ව්යාපෘතියේ සිට ආයාත කළ පිටුව}}
== Overview ==
[[WP:Lua|Lua]] is a lightweight scripting language safely available on Wikipedia via [[mw:Extension:Scribunto|Scribunto]]. Its purpose is to allow you to process the data which is available on Wikipedia content pages to allow various sorts of customized display of information.
It runs in a sandboxed environment to protect the stability of Wikipedia while enabling powerful <syntaxhighlight lang="lua" inline>{{template}}</syntaxhighlight> and <syntaxhighlight lang="lua" inline>module:</syntaxhighlight> functionality.
The most important help file is the [[mw:Extension:Scribunto/Lua reference manual|MediaWiki Scribunto Lua reference manual]], which provides a concise summary of the language and standard library calls as implemented on MediaWiki.
The standard [http://www.lua.org/manual/5.1/manual.html Lua reference manual] is well written and comprehensive, but it can be confusing for beginners because some standard features don't work on wiki pages. You cannot call <syntaxhighlight lang="lua" inline>print("Hello, World!")</syntaxhighlight> in a module, but you can preview your User page showing the string <syntaxhighlight lang="lua" inline>"Hello World!"</syntaxhighlight> generated by the Lua [[Module:Example]]. Think of your Lua template as an HTML generator.
=== Generating "Hello World!" ===
You do not need to install or save anything.
# Edit your User page: <code>පරිශීලක:YourUserName</code>
# Paste the following call at the beginning of a new line on your User page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{#invoke:Example|hello}}
</syntaxhighlight></blockquote>
<ol start="3">
<li>Click <code>Preview</code>. The call of the function <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> in the [[Module:Example]] is replaced with the following:</li>
</ol>
<blockquote><syntaxhighlight lang="lua" line>
Hello World!
</syntaxhighlight></blockquote>
<ol start="4">
<li>Click <code>Cancel</code>. When prompted, click <code>Leave</code>.</li>
<li>Your User page remains '''un'''modified.</li>
</ol>
== Debug console: Start learning Lua ==
The Lua Scribunto <code>Debug Console</code> is a safe, interactive tool for learning Lua in Wikipedia.
# Click <code>Edit</code> on the [[Module:Yesno]] page.
# Scroll to the bottom of the page to the <code>Debug console</code> section beneath the Lua editor.
# Paste the comment and the call into the <span style="color:#86888c;">gray</span> input box (above the <code>Clear</code> button).
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
--[[ඔබගේ ආරම්භක Lua "හෙලෝ වර්ල්ඩ්" යන වගේම වැඩසටහන]]--
print("වෙල්කම් වෙයි " .. _VERSION .. "!") -- Lua අනුවාදය .. සමඟ එකතු කරයි
</syntaxhighlight></blockquote>
<ol start="4">
<li>Press {{key press|Enter}} once to execute the two Lua command''s''.</li>
<li>The result will appear below the Lua <syntaxhighlight lang="lua" inline>print</syntaxhighlight> command line:</li>
</ol>
<blockquote><syntaxhighlight lang="lua" line start=3>
වෙල්කම් වෙයි Lua 5.1!
</syntaxhighlight></blockquote>
<ol start="6">
<li>Press <code>Up arrow</code> (↑) to cycle through previous Lua commands.</li>
<li>Optionally, click <code>Clear</code> to clear ''only'' the <code>Debug Console</code>; the Lua editor above will remain '''un'''modified.</li>
</ol>
; HTML generator in the Debug console
Call the function <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> in <code>Module:</code>Example:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local modExample = require('Module:Example') -- load the module in Debug console
local frame = mw.getCurrentFrame(); print(modExample.hello(frame)) -- display "Hello World!"
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
Hello World!
</syntaxhighlight></blockquote>
; Identity function
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local yesno = require('Module:Yesno') -- #if yesno then returns its input parameter
print(mw.getCurrentFrame():callParserFunction("#if", yesno("Yes"), "Yes", 'නැහැ'))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
Yes
</syntaxhighlight></blockquote>
# Close the protected <code>Module:</code>Yesno that remains '''un'''modified.
== Issues with the current implementation ==
Besides the lack of <code>print()</code> in a module, there are other features missing – see [[mw:Extension:Scribunto/Lua reference manual#Differences from standard Lua|Differences from standard Lua]] for a complete list.
At the present time, it is advisable to use ''[[mw:Extension:Scribunto/Lua reference manual#Ustring library|mw.ustring]]'' functions instead of ''[[mw:Extension:Scribunto/Lua reference manual#String library|string]]'', because the latter sometimes fails with Unicode characters.
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local lang = mw.getCurrentFrame():callParserFunction("#language", "si") -- Sinhala
local lenUnicode, lenByte, lenSharp = mw.ustring.len(lang), string.len(lang), #lang
print(("lang: %s Mw.ustring.len = %d String.len = %d Sharp = %d"):format(lang, lenUnicode, lenByte, lenSharp))
</syntaxhighlight></blockquote>
Debug console supports Unicode:
<blockquote><syntaxhighlight lang="lua" line start=4>
lang: සිංහල Mw.ustring.len = 5 String.len = 15 Sharp = 15
</syntaxhighlight></blockquote>
== Input ==
The programs are run only when the page is "parsed" (when it or a page it incorporates is changed or previewed), not every time you view the output. Therefore there can be no convenient Lua module that allows you to type in a Fahrenheit temperature in an input box and get back the corresponding Celsius temperature when you press a button, or allows you to click on a segment of a Mandelbrot set visualization on a page to expand it as often as you like. There has to be an actual Wiki page (or at least a page you have submitted for preview) containing the input data.
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local function toCelsius(tempFahrenheit) return (tempFahrenheit - 32) * 5 / 9 end
print(("toCelsius(32°F) = %s°C. toCelsius(68°F) = %d°C"):format(toCelsius(32), toCelsius(68)))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
toCelsius(32°F) = 0°C. toCelsius(68°F) = 20°C
</syntaxhighlight></blockquote>
However, it is possible to use library functions like [[mw:Extension:Scribunto/Lua reference manual#mw.title.getCurrentTitle|mw.title.getCurrentTitle()]] to import content from any text content page on the Wiki.
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
print(mw.title.getCurrentTitle())
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=2>
Module:Yesno
</syntaxhighlight></blockquote>
You cannot, however, import data from files, not even .svg files which contain XML text data.
== Calling a Lua module ==
Lua calls look much like [[WP:template|template]]s, and consist of a small block of text.
In your User page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{ConvertNumeric|decToHex|73}}
</syntaxhighlight></blockquote>
Click <code>Preview</code> or click <code>Edit</code> this section to see the call then <code>Cancel</code>:
<blockquote>
{{#invoke:ConvertNumeric|decToHex|73}}
</blockquote>
This text calls the Lua script itself, which is housed in the <code>Module:</code> [[WP:namespace|namespace]]. The effect of this call is to send the information within the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> block to the Lua module, and to replace everything within the brackets with a piece of text that it sends back in return. (Literally, in the "return" statement)
Note that the first "parameter", in this case <code>decToHex</code>, is actually a <syntaxhighlight lang="lua" inline>function</syntaxhighlight> called within the Lua module. This field must always be included in any <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight>. To those unfamiliar with modules, especially Wikipedia template coders who expect anything after <code>|</code> to be a parameter, the need for this extra field is surprising, especially if all uses of the module depend on its presence.
In Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local convNum = require('Module:ConvertNumeric')
local frame = mw.getCurrentFrame(); frame.args[1] = "73" -- number always as string
print(("0x%s = %s = %d"):format(convNum.decToHex(frame), string.format("0x%X", 73), 0x49))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=4>
0x49 = 0x49 = 73
</syntaxhighlight></blockquote>
=== Documenting a Lua module ===
When documenting your module, it is useful to include an explicit usage instruction using [[සැකිල්ල:Module link expanded]]:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{mlx|ConvertNumeric|decToHex|73}}
</syntaxhighlight></blockquote>
Hyperlink to the module:
<blockquote>
{{mlx|ConvertNumeric|decToHex|73}}
</blockquote>
For many existing modules, an example <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> of the script (and little else) is provided on the <code>Module talk:</code> page. It is convenient for authors to be able to flip quickly to the talk tab to look at the effects of their changes, but you should never transclude the talk page as a template - people might actually talk on it! Alternatively, the module page can show documentation from a separate /doc-page (as [[Module:WikidataIB]] does).
=== Another example: Using LuaCall to perform a single Lua instruction ===
As a beginner, or in casual talk page conversation, you might only have one little calculation you want to use Lua for but don't want to write a full module. You might find [[Module:LuaCall]] convenient for this.
For example, count up the length of a string.
In your user page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{#invoke:LuaCall|main|strText=count the length of your DYK hook with Lua|string.len(strText)}}
</syntaxhighlight></blockquote>
<blockquote>
{{#invoke:LuaCall|main|strText=count the length of your DYK hook with Lua|string.len(strText)}}
</blockquote>
You can test how a greedy [https://www.lua.org/pil/20.1.html Lua pattern] works: '''reg'''ular '''ex'''pression <code>.*</code> matches zero or more. <code>.+</code> matches one or more.
In your user page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{#invoke:LuaCall|main|strText=bbbbbbbbbba|regex=bb(.*)b(.+)bba|string.match(strText,regex)}}
</syntaxhighlight></blockquote>
LuaCall returns the first match ignoring other results:
<blockquote>
{{#invoke:LuaCall|main|strText=bbbbbbbbbba|regex=bb(.*)b(.+)bba|string.match(strText,regex)}}
</blockquote>
In these specific examples, however, [[Module:String]] could do both of these tasks in Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
--[[Do You Know (DYK)]]--
local strText = "count the length of your DYK hook with Lua"; print(string.len(strText))
strText = "bbbbbbbbbba"; regex = "bb(.*)b(.+)bba" -- greedy pattern as much as possible
local table = {string.match(strText, regex)}; print(table[1]) -- returns the first match
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=5>
42
bbbb
</syntaxhighlight></blockquote>
The script at [[Module:LuaCall]] has been written to accept any set of named parameters <code>somename=value</code>, for each one storing the string <code>value</code> in the variable with the name <code>somename</code>, and then allowing you to use these variables as parameters for any function available in Lua. The script then returns only the ''first'' value returned by the function ([https://www.lua.org/pil/5.1.html Lua functions can return multiple values], but in this case, only the first is returned from the module).
== Lua program structure: Output ==
The most fundamental part of a Wikipedia Lua program is a <syntaxhighlight lang="lua" inline>return</syntaxhighlight> statement which carries its output back to the page that had the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight>. You ''can'' have a Lua function that runs without error even though it doesn't contain a return statement, but on Wikipedia it is pointless, as Lua programs cannot generally have side effects on Wikipedia.
The module itself must return a Lua '''table''' of values. A Lua table is expressed as a list of values separated by commas, within curly braces. When the module is called by <code>#invoke</code>, the '''function''' it names (the first argument after |) is looked for in that table. That function, in turn, is expected to return something that can be represented as a '''string'''.
Typically we use the overall form for [[Module:Example]]:
<syntaxhighlight lang="lua" line highlight=3 copy>
local p = {} -- Defines the empty (non-nil) table package, the only single-letter variable
function p.hello(frame) -- Define the function p.hello. The input parameter frame is not used
return "Hello World!" -- Returns the string result of the function.
end -- Ends the function
return p -- This returns the table package
</syntaxhighlight>
Note that <syntaxhighlight lang="lua" inline>function p.hello(frame)</syntaxhighlight> is equivalent to anonymous <syntaxhighlight lang="lua" inline>p.hello = function(frame)</syntaxhighlight> or <syntaxhighlight lang="lua" inline>p["hello"] = function(frame)</syntaxhighlight>.
The function is just another '''type''' of value, retrieved with the key <code>"hello"</code> from table <code>p</code>.
If you want to allow users to invoke the same module with <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|main}}</nowiki></code> instead of <syntaxhighlight lang="lua" inline>{{#invoke:Example|hello}}</syntaxhighlight>, you can write:
<syntaxhighlight lang="lua" line start=6>
p.main = p.hello -- to copy the reference to this function to a new key in the table.
</syntaxhighlight>
You can even write <code>p[""] = p.hello</code>, which causes <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|}}</nowiki></code> to produce the same output as <syntaxhighlight lang="lua" inline>{{#invoke:Example|hello}}</syntaxhighlight>.
Learning to think of functions as a data '''type''' becomes very important later on for working with library functions like <code>[[mw:Extension:Scribunto/Lua_reference_manual#string.gsub|mw.ustring.gsub]]</code>, and constructing iterator functions:
;gmatch-based advanced minimal module iterator of vowels
The <code>Module:</code>MatchVowel is actually a complete Lua module (though a very strange one):
<blockquote><syntaxhighlight lang="lua" line highlight=2>
--[[MatchVowel returns a table containing the iterator function of vowels]]--
return { mw.ustring.gmatch( "Hello World!", "([aeiou])" ) } -- returns a table with the iterator
</syntaxhighlight></blockquote>
It returns the iterator function returned by <code>[[mw:Extension:Scribunto/Lua_reference_manual#string.gmatch|mw.ustring.gmatch]]</code> as the one and only element in an array.
If <code>Module:</code>MatchVowel was saved in its own wiki page, when executed in another wiki page:
<blockquote><syntaxhighlight lang="lua" line highlight=1>
{{#invoke:MatchVowel|1}}
</syntaxhighlight></blockquote>
The call yields the vowel from "Hello World!":
<blockquote><syntaxhighlight lang="lua" line start=1>
e
</syntaxhighlight></blockquote>
In Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
--[[iterator function that yields each vowel (case-sensitive) from the string "Hello World!"]]--
local tabMatchVowel = (function() return {mw.ustring.gmatch("Hello World!", "([aeiou])")} end)()
local itv = tabMatchVowel[1] -- iterator function from gmatch as the sole element of the table
local vowel; repeat vowel = itv(); if vowel then print(vowel) end until not (vowel) -- each vowel
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=5>
e
o
o
</syntaxhighlight></blockquote>
== Lua program structure: Input ==
The '''<code>frame</code>''' parameter above (which is pretty much always given this name in Wikipedia Lua modules) receives another table, which is passed ''from'' the page that makes the call ''to'' the Lua module. It contains a surprising amount of stuff, of which just a few things concern the novice.
=== Arguments ===
{{see also|Module:Arguments}}
<code>frame.args</code> contains ''another'' table, namely, all the content sent by the user within the <code>#invoke</code> brackets except the first argument which states the name of the function to be executed.
In your User page: about [[Module:ConvertNumeric]]
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{#invoke:ConvertNumeric |numeral_to_english |57000 |round=on |plural=on}}
</syntaxhighlight></blockquote>
Click <code>Preview</code> or click <code>Edit</code> this section to see the call then <code>Cancel</code>:
<blockquote>
{{#invoke:ConvertNumeric |numeral_to_english |57000 |round=on |plural=on}}
</blockquote>
There are two types of parameters: numeric (positional) keys and named keys.
# Unnamed parameters come out with numbers as keys: <code>frame.args[1]</code>.<br/>The string <code>"57000"</code> is the content of <code>frame.args[1]</code> which is the same as <code>frame["args"][1]</code><br/>but ''not'' the same as <code>frame.args["1"]</code> or <code>frame["args"]["1"]</code>.
# Named parameters come out with the parameter names (strings) as keys: <code>frame.args["round"]</code>, <code>frame.args["plural"]</code>.
In Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=4 copy>
--[[Convert a number to letter in Sinhala]]--
local convNum = require('Module:ConvertNumeric')
local frame=mw.getCurrentFrame(); frame.args = {"57000", round="on", plural="on"}
print(convNum.numeral_to_english(frame) .. " is rounded from 57,000.")
local debugLog = {} -- empty report table
for key, val in pairs(frame.args) do -- for each arg
debugLog[#debugLog + 1] = ("args[%s] = %s"):format(key, val)
end -- ^length. Adding report is faster than string-based: debugLog = debugLog .. string
print(table.concat(debugLog, ". ")) -- Join with separator
mw.logObject(frame.args) -- Scribunto tool to display table
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=11>
හැට දහස is rounded from 57,000.
args[1] = 57000. args[plural] = on. args[round] = on
table#1 {
"57000",
["plural"] = "on",
["round"] = "on",
}
</syntaxhighlight></blockquote>
=== Parent frame ===
Within <code>frame</code> there is a ''parent'' frame, referring to the page that called the page that gives the script, and you can pull out arguments from that also. Just write:
<blockquote><syntaxhighlight lang="lua" line highlight=17 copy>
--[[Return true if table-like `tab` contains any non-nil entries]]--
local function has_any_args(tab)
if tab == nil then return false end -- the table is nil
for _, val in pairs(tab) do -- Iterates both numeric (positional) and string (named) keys.
if val ~= nil then -- value not nil?
return true -- one argument exists
end
end
return false -- The table does not have any arguments
end
--[[Debug console or template in wiki page?]]--
local booksPlural = "There are those books."; local pluralMarker = "s."
local globalSub = "mw.ustring.gsub(subjectStr,pattern,replace)" -- no space separator
local prm = {subjectStr=booksPlural, pattern=pluralMarker, replace=".", globalSub, "lua"}
local frame = mw.getCurrentFrame():newChild{title='Module:LuaCall', args=prm}
local parent = frame:getParent() or nil
if not parent or not has_any_args(parent.args) then
print("Running from Debug console")
print(mw.text.listToText(frame.args))
else
print("Running from wiki page invoking {{template}}")
end
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=24>
Running from Debug console
mw.ustring.gsub(subjectStr,pattern,replace)
</syntaxhighlight></blockquote>
<syntaxhighlight lang="lua" inline>parent.args</syntaxhighlight> will contain those arguments.
It is popular in Lua to use the synonymous statement <code>parent=frame''':'''getParent()</code>, cancelling the need to write <code>frame</code> twice.<br/>
Note the colon (<code>:</code>) instead of the dot (<code>.</code>).
<syntaxhighlight lang="lua" inline>parent = frame:getParent()</syntaxhighlight> means exactly the same as <code>parent = frame.getParent(frame)</code>.
For novices this can be confusing, and it is important to be aware of this idiom.<br/>
If you use it in the wrong way, though, the script errors are pretty good at pointing out that this was the mistake.
== Basic debugging ==
{{Main|Help:Lua debugging}}
Debugging can start as soon as you write programs, and can be done simply with string concatenation.<br/>
Just set up a variable with some recognizable name like <syntaxhighlight lang="lua" inline>debugLog</syntaxhighlight> in your main <syntaxhighlight lang="lua" inline>function p.main(frame)</syntaxhighlight> with a statement like:
<blockquote><syntaxhighlight lang="lua" line start=3 highlight=1 copy>
local debugLog = "" -- empty report string
</syntaxhighlight></blockquote>
This initial <syntaxhighlight lang="lua" inline>""</syntaxhighlight> definition helps because otherwise it will be <syntaxhighlight lang="lua" inline>nil</syntaxhighlight> and concatenating a string to nil gets you an error.<br/>
Now whenever you have a variable you'd like to test, say {{tt|myVar}}, just write:
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=2 copy>
local myVar = 42; local output = "expected result"
debugLog = debugLog .. " myVar = " .. tostring(myVar) -- append to the report
</syntaxhighlight></blockquote>
At the end of your function (but not the module), complete:
<blockquote><syntaxhighlight lang="lua" line start=16 highlight=1 copy>
return output .. debugLog -- Returns the expected result and the report
</syntaxhighlight></blockquote>
The <syntaxhighlight lang="lua" inline>tostring(myVar)</syntaxhighlight> is a function to ensure {{tt|myVar}} is interpreted as a string.<br>
For a table, it will display as "{{samp|table}}". For nil, "{{samp|nil}}" rather than as Script error.
;Print the contents of a table
<syntaxhighlight lang="lua" line highlight=2,13,18,21 copy>
local frame = mw.getCurrentFrame()
local candidates = {
{"#language", "ja"}, -- #language parser function retrieve (ja)panese language
{"#tag", {'isbn', '978-4-87311-471-2'}}, -- #tag parser function generates <isbn> tag
{"plural", {'42', 'book', 'books'}}, -- plural switches sentences based on number
{"canonicalurl", tostring(mw.title.getCurrentTitle())}, -- canonicalurl returns the URL of the page
}
local function args_to_string(obj)
if type(obj) == "table" then return table.concat(obj, " ") else return tostring(obj or "") end
end
for _, pair in ipairs(candidates) do -- _ = ignored index, pair = value; ipairs iterates each numeric key
local fn, arg = pair[1], pair[2] -- Parser function name to call and its argument, string or table
local ok, res
if type(arg) == "table" then
-- If the argument is a table, unpack it and pass as multiple arguments
ok, res = pcall(function() return frame:callParserFunction(fn, unpack(arg)) end)
else
-- If the argument is a single value (string), pass it as-is
ok, res = pcall(function() return frame:callParserFunction(fn, arg or "") end) -- Safe call (pcall)
end
local out = ok and tostring(res) or ("<error>") -- Convert to string on success, "<error>" on failure
-- Join argument tables for readability. Output is for the Lua console
print(string.format('%s(%q) -> %s', fn, args_to_string(arg), out))
end
</syntaxhighlight>
<syntaxhighlight lang="lua" line start=27>
#language("ja") -> 日本語
#tag("isbn 978-4-87311-471-2") -> <isbn>978-4-87311-471-2</isbn>
plural("42 book books") -> books
canonicalurl("Module:Yesno") -> https://si.wikipedia.org/wiki/Module:Yesno
</syntaxhighlight>
== Format ==
The [[WP:Lua style guide]] gives some basic formatting suggestions expected by the JavaScript module editor, such as using four-space indentations and keeping <syntaxhighlight lang="lua" inline>if then else</syntaxhighlight>, <syntaxhighlight lang="lua" inline>end</syntaxhighlight> at the same level of indentation.
Comments to the end of a line are marked by <syntaxhighlight lang="lua" inline>-- green comment</syntaxhighlight>. ''Use them.''
Many modules for Wikipedia have a straightforward, linear design, but that doesn't mean it won't help to have your sections clearly labelled when you go back to the code for the hundredth time. The Lua style guide gives additional recommendations for using functions to keep your work more organized.
== Errors ==
Lua errors appear as red "Script error" messages. If Javascript is enabled, '''the <span style="color:#ff0000;">red</span> script error message is a link''' which usually allows you to follow it back to the line in the module where the error occurred. There are some exceptions, for example "Module not found", if the name of the module itself is mistyped, or "The function you specified did not exist" if the function name given is invalid.
=== Recurrent bugs ===
Some bugs you might want to keep in mind:
;Missing operator for concatenation
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=2 copy>
local debugLog = "" -- empty report string
debugLog = debugLog "missing double dot" -- append to the report
</syntaxhighlight></blockquote>
The following means you forgot the <code>..</code> between a string and a variable somewhere in a mess of stuff you're concatenating.
<blockquote><syntaxhighlight lang="lua" line start=9>
Lua error in console input at line 8: attempt to call local 'debugLog' (a string value).
</syntaxhighlight></blockquote>
;String expected, got function
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=3 copy>
local debugLog = "" -- empty report string
local res = mw.ustring.gmatch("Hello World!", "([aeiouAEIOU])") -- iterator of vowels
debugLog = debugLog..res -- populate the report with only strings
</syntaxhighlight></blockquote>
Some important things like <syntaxhighlight lang="lua" inline>mw.ustring.gmatch</syntaxhighlight> actually return ''functions'', not strings - see [[#Functions|Functions]] below.
<blockquote><syntaxhighlight lang="lua" line start=10>
Lua error in console input at line 9: attempt to concatenate local 'res' (a function value).
</syntaxhighlight></blockquote>
;Variable ignores assignment
A variable ignores all your efforts to assign stuff to it:
<blockquote><syntaxhighlight lang="lua" line highlight=1,3 copy>
local debugLog = "top level" -- initial value
do
local debugLog = "nested level" -- set the new value
print("Inside do: "..debugLog)
end
print("Outside do: "..debugLog) -- get the old value
</syntaxhighlight></blockquote>
You may have inadvertently written ''two'' local statements - the one sets the value of the variable within a limited region, and when the program leaves that region, you're back to the old value.
<blockquote><syntaxhighlight lang="lua" line start=7>
Inside do: nested level
Outside do: top level
</syntaxhighlight></blockquote>
A numbered table entry ignores all your efforts to assign to it:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local table = {}; local arg = "50"; local valPrm = tonumber(arg)
table[arg] = "index as string"
table[valPrm] = "index as number"
print(table[arg] == table[valPrm])
</syntaxhighlight></blockquote>
This is because {{code|table["50"]}} '''is not''' {{code|table[50]}}.<br/>
Typically you have processed a parameter (which you may have received from the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> as a string) with string functions in one place,<br>
but performed numeric operations in another, leaving you with two different types of variable to use for an index.
<blockquote><syntaxhighlight lang="lua" line start=5>
false
</syntaxhighlight></blockquote>
;<syntaxhighlight lang="lua" inline>nil</syntaxhighlight> and common pitfalls
There are all sorts of things you can't do with a local variable set to nil, such as: <syntaxhighlight lang="lua" inline>local x = nil</syntaxhighlight>, like:
# Assign <code>x.somefield</code>
# Get value at index {{code|x[idx]}}
# Concatenate <syntaxhighlight lang="lua" inline>x .. "Cannot concatenate with nil"</syntaxhighlight>
# Evaluate <syntaxhighlight lang="lua" inline>table[x]</syntaxhighlight>
Initialize such variables with: <syntaxhighlight lang="lua" inline>local x={}; local table = {}</syntaxhighlight><br>
Often "global" is mentioned in these errors because you didn't have a {{tt|local}} statement for the <syntaxhighlight lang="lua" inline>nil</syntaxhighlight> variable.
;Cannot invoke module
* ''no such module.'' You called <syntaxhighlight lang="lua" inline>#invoke:moduleNameUnknown</syntaxhighlight> that didn't exist or you wrongly kept the prefix <code>Module:</code> writing {{code|#invoke:Module:moduleName}}.
* ''the function specified did not exist.'' You called <syntaxhighlight lang="lua" inline>#invoke:moduleName|functionUnknown</syntaxhighlight>, but the field after the name of the module is wrong.<br>Often this field expects a standard name like "main", and you've forgotten it and gone straight to the first data parameter.<br>If you're unsure of the function name, check the module documentation, or look for what function(s) in the code accept a "frame" parameter.
;Graphics overflow issue
Some graphics you're trying to display are heading off to the hills: actually a HTML error.<br>
You didn't close one <syntaxhighlight lang="html" inline></div></syntaxhighlight>, so all the top: and left: styles keep adding up.
== Understanding tables and related concepts ==
* An '''expression list''' is a set of values separated by commas. The values can be strings, numbers, tables, functions, etc.
* A '''sequence''' is a set of entries with indices from 1 to N, where N is a positive integer. They can be created by placing brackets around an expression list.
For example:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local seq = {1, "quotation", mw.ustring.gmatch("abca","a"), {2,3,4}}
mw.logObject(seq) -- Scribunto tool to display a table
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
table#1 {
1,
"quotation",
function#1,
table#2 {
2,
3,
4,
},
}
</syntaxhighlight></blockquote>
# <code>seq[1]</code> = 1
# <code>seq[2]</code> = <syntaxhighlight lang="lua" inline>"quotation"</syntaxhighlight>
# <code>seq[3]</code> is the <syntaxhighlight lang="lua" inline>function</syntaxhighlight> returned by <code>gmatch()</code>
# <code>seq[4]</code> is the table <code>{2,3,4}</code>.
An expression list can also be recovered from a table using <syntaxhighlight lang="lua" inline>unpack()</syntaxhighlight>:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local seq = {1, "quotation", mw.ustring.gmatch("abca","a"), {2,3,4}}
local var1Nbr, var2Str, var3Fct = unpack(seq)
print(("var1Nbr = %d. var2Str = \"%s\". var3Fct = %s"):format(var1Nbr, var2Str, type(var3Fct)))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=4>
var1Nbr = 1. var2Str = "quotation". var3Fct = function
</syntaxhighlight></blockquote>
This will set:
# <code>var1Nbr</code> = 1
# <code>var2Str</code> = <syntaxhighlight lang="lua" inline>"quotation"</syntaxhighlight>
# <code>var3Fct</code> as the <syntaxhighlight lang="lua" inline>function</syntaxhighlight> returned by <code>gmatch()</code>
# <code>{2,3,4}</code> will be discarded in this case.
* A '''table''' is a sequence, optionally supplemented by named keys: <code>digit["two"]="2"</code>. Several table functions like <code>table.concat</code> will only work with the numbered values and ignore named keys.
* The '''metatable''' offers a large, optional set of methods for altering table behavior. For example, you can define a table to be callable like a function.
=== Initializing a table ===
It is often useful to create a whole table at once in a statement. There are many equivalent ways to do this, but the shortcuts don't work for every kind of value. To begin with, the most general way is to assign each key and value explicitly:
<syntaxhighlight lang="lua" inline>a = {[0]='zero', [1]='one', ['1']='string for one'}</syntaxhighlight>
If sequence keys (positive integers) are given in order, only the values need to be given, so the following will assign <syntaxhighlight lang="lua" inline>'one'</syntaxhighlight> to <syntaxhighlight lang="lua" inline>a[1]</syntaxhighlight>:
<syntaxhighlight lang="lua" inline>a = {[0]='zero', 'one', ['1']='string for one'}</syntaxhighlight>
If a key has only letters, digits, and underscores, and begins with a non-digit, the brackets and quotation marks can be omitted:
<syntaxhighlight lang="lua" inline>a = {a='one', b='two'}</syntaxhighlight>
This is identical to <syntaxhighlight lang="lua" inline>a = {["a"]='one', ["b"]='two'}</syntaxhighlight>.
However, this will fail for keys that begin with a digit: <syntaxhighlight lang="lua" inline>hex = {7f = 127}</syntaxhighlight> will produce an error; use <syntaxhighlight lang="lua" inline>hex = {['7f'] = 127}</syntaxhighlight> instead.
Note that when given ''within'' brackets, or to the right of the equal sign, quotation marks are needed, or else string values will be taken as variables:
<syntaxhighlight lang="lua" inline> a = {[b] = c}</syntaxhighlight>
assigns the value of variable ''c'' to the key ''contained in variable'' ''b''.
== Functions ==
* Functions can return any kind of value {{--}} ''including a function''. This is a powerful feature that can readily confuse the beginner. If you set <syntaxhighlight lang="lua" inline>a=mw.ustring.gmatch(text, "(.)")</syntaxhighlight>, the result assigned to <code>a</code> will be a '''function''', not a string character! However, assigning <code>b=a()</code> by calling the function stored in <code>a</code> will return the first match (a string). Every time you set <code>b=a()</code> after that you'll get another match (string) into <code>b</code>, until you run out of matches and get <code>nil</code>. Many '''iterator functions''' act this way.
* You can keep separate counts for iterator functions by using different variables. For example, if you set <syntaxhighlight lang="lua" inline>q=mw.ustring.gmatch(text, "(x.)")</syntaxhighlight> in the same module, you can pull characters from the same piece of text (<code>text</code>) by evaluating <code>d=q()</code> without losing your place in <code>a()</code>.
* [[tail call|Tail calls]] offer substantial benefits in performance for those who master the language.
* Function names are often of the form {{code|p.myFunctionName}}, where p is the table from the {{code|return p}} at the bottom of your program. The reason for this is that you can only access functions that are entries in this table from the original {{code|#invoke}} statement. Functions for local use within the program can have any name.
== Understanding patterns ==
''Note:'' Lua patterns are ''not'' [[regular expression|regular expressions]] in the traditional POSIX sense, and they are not even a subset of regular expressions. But they share many constructs with regular expressions (more [[Help:Lua for beginners#regex|below]]).
Lua patterns are used to define, find and handle a ''pattern'' in a string. It can do the common search and replace action in a text, but it has more options that doing plain text only. For example, in one go it can change the errors 'New yorker', 'New-Yorker', and 'NewYorker' into 'New Yorker'.
* To begin with, a pattern works like a plain string so long as it doesn't contain the special characters {{code|^ $ () % . [] * + - ?}}
* Square brackets {{code|[ ]}} are used to match ''one'' ''single character'' in the string from a list of choices. {{code|[abc]}} matches the letters a, b, or c. With {{code|^}} right after {{code|[}} they indicate "anything but": {{code|[^abc]}} = not a, b, or c. Inside brackets and when not the first character, a minus {{code|-}}indicates a range: {{code|[a-z]}} matches one single character from a, b, c, …, z.
* Period {{code|.}} matches any character.
* Percent {{code|%}} indicates a large set (class) of possible character matches when it is followed by a letter. See [https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Character_class] for a full list. <!--- should test/list these empirically to be sure ---> When followed by punctuation (whether a special character above or not) the {{code|%}} is removed and the punctuation is taken as a literal character; {{code|%%}} = literal %. Special classes include a balanced class {{code|%bxy}} and {{code|%f[set]}}; see the link above for more.
* Parentheses {{code|( )}} indicate captures. The captures can be accessed later in the search string or in the string.gsub replacement string as {{code|%1}} to {{code|%9}}, and are returned by string.match as an expression list of results.
* The qualifiers {{code|? - * +}} specify repetitions of a single character (not a longer string).
:* {{code|?}} means 0 or 1 repetitions: {{code|a?}} matches "a" or "".
:* {{code|-}} means 0 or more repetitions, choosing as few as possible to achieve a match ("non-greedy"). For example {{code|2=lua|string.match("bbbb", "(.-)")}} yields "", which is less than useful because there is nothing to root the ends of the expression and prevent it from matching zero characters.
:* {{code|*}} means 0 or more repetitions, choosing as many as possible ("greedy"). For example {{code|2=lua|string.match("bbbb", ".*")}} yields bbbb.
:* {{code|+}} means 1 or more repetitions, choosing as many as possible ("greedy").
Note that the greediness of the ''leftmost'' qualifier rules over all others when there is a choice: {{code|(.*)b(.*)}} when matched on "bbb" will return "bb", "", while {{code|a(.-)b(.-)a}} when matched on "abbba" will return "", "bb".
* {{code|^}} and {{code|$}} indicate the beginning and end of the string if they occur in the appropriate place in the pattern. Otherwise they are literal characters. {{code|^}} is not used in the {{code|string.gmatch}} function.
The reference manual for Lua patterns is at [[:mw:Extension:Scribunto/Lua_reference_manual#Patterns|mediawiki.org]].
== {{anchor|regex}}Note on Lua patterns versus regular expressions ==
Lua patterns are ''loosely based'' on [[regular expression]]s (sometimes shortened to regex or regexp). Lua patterns deliberately lack the most complex regular expression constructs (to avoid bloating the Lua code base), where many other computer languages or libraries use a more complete set. Lua patterns are not even a subset of regular expressions, as there are also discrepancies, like Lua using the escape character <code>%</code> instead of <code>\,</code>, and additions, like Lua providing <code>-</code> as a non-greedy version of <code>*</code>.
Here is a list of some of the things that Lua patterns lack compared to regular expressions:
* You '''cannot''' search for alternations between anything else than single characters (you '''cannot''' say <code>(his|her)</code> to choose between <code>his</code> and <code>her</code>, you can only say <code>[abc]</code> to choose between single characters <code>a</code>, <code>b</code>, or <code>c</code>).
* You '''cannot''' look for multiples of multi-letter constructs such as <code>(choo-)*choo</code> to match <code>choo</code>, <code>choo-choo</code> or <code>choo-choo-choo</code>. There is no way to do this with Lua patterns.
* You '''cannot''' specify the minimum and maximum number of repetitions like <code>[0-9]{3,5}</code> (to match 3 to 5 digits); in Lua you would say <code>%d%d%d%d?%d?</code> instead in this case.
There are Lua libraries that offer more powerful options,<sup>[http://lua-users.org/wiki/PatternsTutorial]</sup> including regular expressions, but the support on Wikipedia is pretty basic.
Wikipedia help for regular expressions (which Lua, as mentioned, does ''not'' support) is at [[Wikipedia:AutoWikiBrowser/Regular expression]].
{{Wikipedia technical help|collapsed}}
[[Category:Module help|*]]
9avngt8sckij47jkkvpkttn1jag3pq9
790930
790929
2026-05-19T20:00:08Z
Nimmzo
78995
/* Another example: Using LuaCall to perform a single Lua instruction */ Introducing Unicode-based [[Module:LuaCall]] in Debug console
790930
wikitext
text/x-wiki
{{WikiProject Lua header}}
{{Selfref|This help page is meant to provide some basic orientation for those new to Lua/Scribunto.}}
{{ඉංග්රීසි ව්යාපෘතියේ සිට ආයාත කළ පිටුව}}
== Overview ==
[[WP:Lua|Lua]] is a lightweight scripting language safely available on Wikipedia via [[mw:Extension:Scribunto|Scribunto]]. Its purpose is to allow you to process the data which is available on Wikipedia content pages to allow various sorts of customized display of information.
It runs in a sandboxed environment to protect the stability of Wikipedia while enabling powerful <syntaxhighlight lang="lua" inline>{{template}}</syntaxhighlight> and <syntaxhighlight lang="lua" inline>module:</syntaxhighlight> functionality.
The most important help file is the [[mw:Extension:Scribunto/Lua reference manual|MediaWiki Scribunto Lua reference manual]], which provides a concise summary of the language and standard library calls as implemented on MediaWiki.
The standard [http://www.lua.org/manual/5.1/manual.html Lua reference manual] is well written and comprehensive, but it can be confusing for beginners because some standard features don't work on wiki pages. You cannot call <syntaxhighlight lang="lua" inline>print("Hello, World!")</syntaxhighlight> in a module, but you can preview your User page showing the string <syntaxhighlight lang="lua" inline>"Hello World!"</syntaxhighlight> generated by the Lua [[Module:Example]]. Think of your Lua template as an HTML generator.
=== Generating "Hello World!" ===
You do not need to install or save anything.
# Edit your User page: <code>පරිශීලක:YourUserName</code>
# Paste the following call at the beginning of a new line on your User page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{#invoke:Example|hello}}
</syntaxhighlight></blockquote>
<ol start="3">
<li>Click <code>Preview</code>. The call of the function <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> in the [[Module:Example]] is replaced with the following:</li>
</ol>
<blockquote><syntaxhighlight lang="lua" line>
Hello World!
</syntaxhighlight></blockquote>
<ol start="4">
<li>Click <code>Cancel</code>. When prompted, click <code>Leave</code>.</li>
<li>Your User page remains '''un'''modified.</li>
</ol>
== Debug console: Start learning Lua ==
The Lua Scribunto <code>Debug Console</code> is a safe, interactive tool for learning Lua in Wikipedia.
# Click <code>Edit</code> on the [[Module:Yesno]] page.
# Scroll to the bottom of the page to the <code>Debug console</code> section beneath the Lua editor.
# Paste the comment and the call into the <span style="color:#86888c;">gray</span> input box (above the <code>Clear</code> button).
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
--[[ඔබගේ ආරම්භක Lua "හෙලෝ වර්ල්ඩ්" යන වගේම වැඩසටහන]]--
print("වෙල්කම් වෙයි " .. _VERSION .. "!") -- Lua අනුවාදය .. සමඟ එකතු කරයි
</syntaxhighlight></blockquote>
<ol start="4">
<li>Press {{key press|Enter}} once to execute the two Lua command''s''.</li>
<li>The result will appear below the Lua <syntaxhighlight lang="lua" inline>print</syntaxhighlight> command line:</li>
</ol>
<blockquote><syntaxhighlight lang="lua" line start=3>
වෙල්කම් වෙයි Lua 5.1!
</syntaxhighlight></blockquote>
<ol start="6">
<li>Press <code>Up arrow</code> (↑) to cycle through previous Lua commands.</li>
<li>Optionally, click <code>Clear</code> to clear ''only'' the <code>Debug Console</code>; the Lua editor above will remain '''un'''modified.</li>
</ol>
; HTML generator in the Debug console
Call the function <syntaxhighlight lang="lua" inline>hello</syntaxhighlight> in <code>Module:</code>Example:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local modExample = require('Module:Example') -- load the module in Debug console
local frame = mw.getCurrentFrame(); print(modExample.hello(frame)) -- display "Hello World!"
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
Hello World!
</syntaxhighlight></blockquote>
; Identity function
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local yesno = require('Module:Yesno') -- #if yesno then returns its input parameter
print(mw.getCurrentFrame():callParserFunction("#if", yesno("Yes"), "Yes", 'නැහැ'))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
Yes
</syntaxhighlight></blockquote>
# Close the protected <code>Module:</code>Yesno that remains '''un'''modified.
== Issues with the current implementation ==
Besides the lack of <code>print()</code> in a module, there are other features missing – see [[mw:Extension:Scribunto/Lua reference manual#Differences from standard Lua|Differences from standard Lua]] for a complete list.
At the present time, it is advisable to use ''[[mw:Extension:Scribunto/Lua reference manual#Ustring library|mw.ustring]]'' functions instead of ''[[mw:Extension:Scribunto/Lua reference manual#String library|string]]'', because the latter sometimes fails with Unicode characters.
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local lang = mw.getCurrentFrame():callParserFunction("#language", "si") -- Sinhala
local lenUnicode, lenByte, lenSharp = mw.ustring.len(lang), string.len(lang), #lang
print(("lang: %s Mw.ustring.len = %d String.len = %d Sharp = %d"):format(lang, lenUnicode, lenByte, lenSharp))
</syntaxhighlight></blockquote>
Debug console supports Unicode:
<blockquote><syntaxhighlight lang="lua" line start=4>
lang: සිංහල Mw.ustring.len = 5 String.len = 15 Sharp = 15
</syntaxhighlight></blockquote>
== Input ==
The programs are run only when the page is "parsed" (when it or a page it incorporates is changed or previewed), not every time you view the output. Therefore there can be no convenient Lua module that allows you to type in a Fahrenheit temperature in an input box and get back the corresponding Celsius temperature when you press a button, or allows you to click on a segment of a Mandelbrot set visualization on a page to expand it as often as you like. There has to be an actual Wiki page (or at least a page you have submitted for preview) containing the input data.
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local function toCelsius(tempFahrenheit) return (tempFahrenheit - 32) * 5 / 9 end
print(("toCelsius(32°F) = %s°C. toCelsius(68°F) = %d°C"):format(toCelsius(32), toCelsius(68)))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
toCelsius(32°F) = 0°C. toCelsius(68°F) = 20°C
</syntaxhighlight></blockquote>
However, it is possible to use library functions like [[mw:Extension:Scribunto/Lua reference manual#mw.title.getCurrentTitle|mw.title.getCurrentTitle()]] to import content from any text content page on the Wiki.
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
print(mw.title.getCurrentTitle())
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=2>
Module:Yesno
</syntaxhighlight></blockquote>
You cannot, however, import data from files, not even .svg files which contain XML text data.
== Calling a Lua module ==
Lua calls look much like [[WP:template|template]]s, and consist of a small block of text.
In your User page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{ConvertNumeric|decToHex|73}}
</syntaxhighlight></blockquote>
Click <code>Preview</code> or click <code>Edit</code> this section to see the call then <code>Cancel</code>:
<blockquote>
{{#invoke:ConvertNumeric|decToHex|73}}
</blockquote>
This text calls the Lua script itself, which is housed in the <code>Module:</code> [[WP:namespace|namespace]]. The effect of this call is to send the information within the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> block to the Lua module, and to replace everything within the brackets with a piece of text that it sends back in return. (Literally, in the "return" statement)
Note that the first "parameter", in this case <code>decToHex</code>, is actually a <syntaxhighlight lang="lua" inline>function</syntaxhighlight> called within the Lua module. This field must always be included in any <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight>. To those unfamiliar with modules, especially Wikipedia template coders who expect anything after <code>|</code> to be a parameter, the need for this extra field is surprising, especially if all uses of the module depend on its presence.
In Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local convNum = require('Module:ConvertNumeric')
local frame = mw.getCurrentFrame(); frame.args[1] = "73" -- number always as string
print(("0x%s = %s = %d"):format(convNum.decToHex(frame), string.format("0x%X", 73), 0x49))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=4>
0x49 = 0x49 = 73
</syntaxhighlight></blockquote>
=== Documenting a Lua module ===
When documenting your module, it is useful to include an explicit usage instruction using [[සැකිල්ල:Module link expanded]]:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{mlx|ConvertNumeric|decToHex|73}}
</syntaxhighlight></blockquote>
Hyperlink to the module:
<blockquote>
{{mlx|ConvertNumeric|decToHex|73}}
</blockquote>
For many existing modules, an example <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> of the script (and little else) is provided on the <code>Module talk:</code> page. It is convenient for authors to be able to flip quickly to the talk tab to look at the effects of their changes, but you should never transclude the talk page as a template - people might actually talk on it! Alternatively, the module page can show documentation from a separate /doc-page (as [[Module:WikidataIB]] does).
=== Another example: Using LuaCall to perform a single Lua instruction ===
As a beginner, or in casual talk page conversation, you might only have one little calculation you want to use Lua for but don't want to write a full module. You might find [[Module:LuaCall]] convenient for this.
For example, count up the length of a string.
In your user page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{#invoke:LuaCall|main|strText=count the length of your DYK hook with Lua|string.len(strText)}}
</syntaxhighlight></blockquote>
<blockquote>
{{#invoke:LuaCall|main|strText=count the length of your DYK hook with Lua|string.len(strText)}}
</blockquote>
You can test how a greedy [https://www.lua.org/pil/20.1.html Lua pattern] works: '''reg'''ular '''ex'''pression <code>.*</code> matches zero or more. <code>.+</code> matches one or more.
In your user page:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{#invoke:LuaCall|main|strText=bbbbbbbbbba|regex=bb(.*)b(.+)bba|string.match(strText,regex)}}
</syntaxhighlight></blockquote>
LuaCall returns the first match ignoring other results:
<blockquote>
{{#invoke:LuaCall|main|strText=bbbbbbbbbba|regex=bb(.*)b(.+)bba|string.match(strText,regex)}}
</blockquote>
In these specific examples, however, [[Module:String]] could do both of these tasks in Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
--[[Do You Know (DYK)]]--
local strText = "count the length of your DYK hook with Lua"; print(string.len(strText))
strText = "bbbbbbbbbba"; regex = "bb(.*)b(.+)bba" -- greedy pattern as much as possible
local table = {string.match(strText, regex)}; print(table[1]) -- returns the first match
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=5>
42
bbbb
</syntaxhighlight></blockquote>
;Unicode <code>[[mw:Extension:Scribunto/Lua_reference_manual#string.gsub|mw.ustring.gsub]]</code>
In Sinhala, both singular and plural forms can end with the virāma (hal) sign <code>්</code> to create final consonants or consonant clusters named ''hal'' kirīma (හා'''ල්''' කිරීම).
On your user page: remove the plural marker "'''ත්'''" after the lexical root <syntaxhighlight lang="lua" inline>"පො"</syntaxhighlight> in "ඒ පො'''ත්''' තියෙනවා." if you want the singular; the plural sentence should be kept as "ඒ පො'''ත්''' තියෙනවා." for <syntaxhighlight lang="lua" inline>"There are books."</syntaxhighlight>
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{#invoke:LuaCall|main|subjectStr=ඒ පොත් තියෙනවා.|pattern=ත්|replace=තක්|mw.ustring.gsub(subjectStr,pattern,replace)|lua}}
</syntaxhighlight></blockquote>
Click <code>Preview</code>. Singular: "There is a book." පො'''තක්''' = ''a'' book. Click <code>Edit</code> this section to see the call then <code>Cancel</code>:
<blockquote>
{{#invoke:LuaCall|main|subjectStr=ඒ පොත් තියෙනවා.|pattern=ත්|replace=තක්|mw.ustring.gsub(subjectStr,pattern,replace)|lua}}
</blockquote>
In Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=4,13,21 copy>
--[[According to the number of books, select singular or plural]]--
local That = "ඒ "; local nounRoot="පො" -- lexical root of "book"
local nounBook = nounRoot.."ත" -- full noun "book" but without Virama hal kirīma vowel killer
-- Virāma ් diacritic is a combining character attached to consonant to create consonant cluster:
local clusterKaVirama = "ක්" -- consonant + sign Virama = final consonant cluster: a or one
local clusterTVirama = "ත්" -- consonant cluster as final part of the noun's plural form
local nounSingle = nounBook..clusterKaVirama -- added indefinite singular postpositive particle
local nounPlural = nounRoot..clusterTVirama -- added plural particle. Shorter than singular
local verbPresent = " තියෙනවා." -- verb does not change for singular vs. plural
local bookSingle = That..nounSingle..verbPresent; -- There is a book.
local bookPlural = That..nounPlural..verbPresent; -- There are books.
print("There are books:") -- plural for 42 books
print(mw.getCurrentFrame():callParserFunction("plural", {'42', bookSingle, bookPlural}))
--[[Replace the plural with the singular]]--
local globalSub = "mw.ustring.gsub(subjectStr,pattern,replace)" -- no space separator
local prm = {subjectStr=bookPlural, pattern=nounPlural, replace=nounSingle, globalSub, "lua"}
local modName = 'Module:LuaCall'; local luaCall = require(modName)
local frame = mw.getCurrentFrame():newChild{title=modName, args=prm} -- newChild for getParent
print("There is a book:")
print(luaCall.main(frame)) -- singular
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=22>
There are books:
ඒ පොත් තියෙනවා.
There is a book:
ඒ පොතක් තියෙනවා.
</syntaxhighlight></blockquote>
The script at [[Module:LuaCall]] has been written to accept any set of named parameters <code>somename=value</code>, for each one storing the string <code>value</code> in the variable with the name <code>somename</code>, and then allowing you to use these variables as parameters for any function available in Lua. The script then returns only the ''first'' value returned by the function ([https://www.lua.org/pil/5.1.html Lua functions can return multiple values], but in this case, only the first is returned from the module).
== Lua program structure: Output ==
The most fundamental part of a Wikipedia Lua program is a <syntaxhighlight lang="lua" inline>return</syntaxhighlight> statement which carries its output back to the page that had the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight>. You ''can'' have a Lua function that runs without error even though it doesn't contain a return statement, but on Wikipedia it is pointless, as Lua programs cannot generally have side effects on Wikipedia.
The module itself must return a Lua '''table''' of values. A Lua table is expressed as a list of values separated by commas, within curly braces. When the module is called by <code>#invoke</code>, the '''function''' it names (the first argument after |) is looked for in that table. That function, in turn, is expected to return something that can be represented as a '''string'''.
Typically we use the overall form for [[Module:Example]]:
<syntaxhighlight lang="lua" line highlight=3 copy>
local p = {} -- Defines the empty (non-nil) table package, the only single-letter variable
function p.hello(frame) -- Define the function p.hello. The input parameter frame is not used
return "Hello World!" -- Returns the string result of the function.
end -- Ends the function
return p -- This returns the table package
</syntaxhighlight>
Note that <syntaxhighlight lang="lua" inline>function p.hello(frame)</syntaxhighlight> is equivalent to anonymous <syntaxhighlight lang="lua" inline>p.hello = function(frame)</syntaxhighlight> or <syntaxhighlight lang="lua" inline>p["hello"] = function(frame)</syntaxhighlight>.
The function is just another '''type''' of value, retrieved with the key <code>"hello"</code> from table <code>p</code>.
If you want to allow users to invoke the same module with <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|main}}</nowiki></code> instead of <syntaxhighlight lang="lua" inline>{{#invoke:Example|hello}}</syntaxhighlight>, you can write:
<syntaxhighlight lang="lua" line start=6>
p.main = p.hello -- to copy the reference to this function to a new key in the table.
</syntaxhighlight>
You can even write <code>p[""] = p.hello</code>, which causes <code><nowiki>{{#invoke:</nowiki>''module-name''<nowiki>|}}</nowiki></code> to produce the same output as <syntaxhighlight lang="lua" inline>{{#invoke:Example|hello}}</syntaxhighlight>.
Learning to think of functions as a data '''type''' becomes very important later on for working with library functions like <code>[[mw:Extension:Scribunto/Lua_reference_manual#string.gsub|mw.ustring.gsub]]</code>, and constructing iterator functions:
;gmatch-based advanced minimal module iterator of vowels
The <code>Module:</code>MatchVowel is actually a complete Lua module (though a very strange one):
<blockquote><syntaxhighlight lang="lua" line highlight=2>
--[[MatchVowel returns a table containing the iterator function of vowels]]--
return { mw.ustring.gmatch( "Hello World!", "([aeiou])" ) } -- returns a table with the iterator
</syntaxhighlight></blockquote>
It returns the iterator function returned by <code>[[mw:Extension:Scribunto/Lua_reference_manual#string.gmatch|mw.ustring.gmatch]]</code> as the one and only element in an array.
If <code>Module:</code>MatchVowel was saved in its own wiki page, when executed in another wiki page:
<blockquote><syntaxhighlight lang="lua" line highlight=1>
{{#invoke:MatchVowel|1}}
</syntaxhighlight></blockquote>
The call yields the vowel from "Hello World!":
<blockquote><syntaxhighlight lang="lua" line start=1>
e
</syntaxhighlight></blockquote>
In Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
--[[iterator function that yields each vowel (case-sensitive) from the string "Hello World!"]]--
local tabMatchVowel = (function() return {mw.ustring.gmatch("Hello World!", "([aeiou])")} end)()
local itv = tabMatchVowel[1] -- iterator function from gmatch as the sole element of the table
local vowel; repeat vowel = itv(); if vowel then print(vowel) end until not (vowel) -- each vowel
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=5>
e
o
o
</syntaxhighlight></blockquote>
== Lua program structure: Input ==
The '''<code>frame</code>''' parameter above (which is pretty much always given this name in Wikipedia Lua modules) receives another table, which is passed ''from'' the page that makes the call ''to'' the Lua module. It contains a surprising amount of stuff, of which just a few things concern the novice.
=== Arguments ===
{{see also|Module:Arguments}}
<code>frame.args</code> contains ''another'' table, namely, all the content sent by the user within the <code>#invoke</code> brackets except the first argument which states the name of the function to be executed.
In your User page: about [[Module:ConvertNumeric]]
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
{{#invoke:ConvertNumeric |numeral_to_english |57000 |round=on |plural=on}}
</syntaxhighlight></blockquote>
Click <code>Preview</code> or click <code>Edit</code> this section to see the call then <code>Cancel</code>:
<blockquote>
{{#invoke:ConvertNumeric |numeral_to_english |57000 |round=on |plural=on}}
</blockquote>
There are two types of parameters: numeric (positional) keys and named keys.
# Unnamed parameters come out with numbers as keys: <code>frame.args[1]</code>.<br/>The string <code>"57000"</code> is the content of <code>frame.args[1]</code> which is the same as <code>frame["args"][1]</code><br/>but ''not'' the same as <code>frame.args["1"]</code> or <code>frame["args"]["1"]</code>.
# Named parameters come out with the parameter names (strings) as keys: <code>frame.args["round"]</code>, <code>frame.args["plural"]</code>.
In Debug console of [[Module:Yesno]]:
<blockquote><syntaxhighlight lang="lua" line highlight=4 copy>
--[[Convert a number to letter in Sinhala]]--
local convNum = require('Module:ConvertNumeric')
local frame=mw.getCurrentFrame(); frame.args = {"57000", round="on", plural="on"}
print(convNum.numeral_to_english(frame) .. " is rounded from 57,000.")
local debugLog = {} -- empty report table
for key, val in pairs(frame.args) do -- for each arg
debugLog[#debugLog + 1] = ("args[%s] = %s"):format(key, val)
end -- ^length. Adding report is faster than string-based: debugLog = debugLog .. string
print(table.concat(debugLog, ". ")) -- Join with separator
mw.logObject(frame.args) -- Scribunto tool to display table
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=11>
හැට දහස is rounded from 57,000.
args[1] = 57000. args[plural] = on. args[round] = on
table#1 {
"57000",
["plural"] = "on",
["round"] = "on",
}
</syntaxhighlight></blockquote>
=== Parent frame ===
Within <code>frame</code> there is a ''parent'' frame, referring to the page that called the page that gives the script, and you can pull out arguments from that also. Just write:
<blockquote><syntaxhighlight lang="lua" line highlight=17 copy>
--[[Return true if table-like `tab` contains any non-nil entries]]--
local function has_any_args(tab)
if tab == nil then return false end -- the table is nil
for _, val in pairs(tab) do -- Iterates both numeric (positional) and string (named) keys.
if val ~= nil then -- value not nil?
return true -- one argument exists
end
end
return false -- The table does not have any arguments
end
--[[Debug console or template in wiki page?]]--
local booksPlural = "There are those books."; local pluralMarker = "s."
local globalSub = "mw.ustring.gsub(subjectStr,pattern,replace)" -- no space separator
local prm = {subjectStr=booksPlural, pattern=pluralMarker, replace=".", globalSub, "lua"}
local frame = mw.getCurrentFrame():newChild{title='Module:LuaCall', args=prm}
local parent = frame:getParent() or nil
if not parent or not has_any_args(parent.args) then
print("Running from Debug console")
print(mw.text.listToText(frame.args))
else
print("Running from wiki page invoking {{template}}")
end
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=24>
Running from Debug console
mw.ustring.gsub(subjectStr,pattern,replace)
</syntaxhighlight></blockquote>
<syntaxhighlight lang="lua" inline>parent.args</syntaxhighlight> will contain those arguments.
It is popular in Lua to use the synonymous statement <code>parent=frame''':'''getParent()</code>, cancelling the need to write <code>frame</code> twice.<br/>
Note the colon (<code>:</code>) instead of the dot (<code>.</code>).
<syntaxhighlight lang="lua" inline>parent = frame:getParent()</syntaxhighlight> means exactly the same as <code>parent = frame.getParent(frame)</code>.
For novices this can be confusing, and it is important to be aware of this idiom.<br/>
If you use it in the wrong way, though, the script errors are pretty good at pointing out that this was the mistake.
== Basic debugging ==
{{Main|Help:Lua debugging}}
Debugging can start as soon as you write programs, and can be done simply with string concatenation.<br/>
Just set up a variable with some recognizable name like <syntaxhighlight lang="lua" inline>debugLog</syntaxhighlight> in your main <syntaxhighlight lang="lua" inline>function p.main(frame)</syntaxhighlight> with a statement like:
<blockquote><syntaxhighlight lang="lua" line start=3 highlight=1 copy>
local debugLog = "" -- empty report string
</syntaxhighlight></blockquote>
This initial <syntaxhighlight lang="lua" inline>""</syntaxhighlight> definition helps because otherwise it will be <syntaxhighlight lang="lua" inline>nil</syntaxhighlight> and concatenating a string to nil gets you an error.<br/>
Now whenever you have a variable you'd like to test, say {{tt|myVar}}, just write:
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=2 copy>
local myVar = 42; local output = "expected result"
debugLog = debugLog .. " myVar = " .. tostring(myVar) -- append to the report
</syntaxhighlight></blockquote>
At the end of your function (but not the module), complete:
<blockquote><syntaxhighlight lang="lua" line start=16 highlight=1 copy>
return output .. debugLog -- Returns the expected result and the report
</syntaxhighlight></blockquote>
The <syntaxhighlight lang="lua" inline>tostring(myVar)</syntaxhighlight> is a function to ensure {{tt|myVar}} is interpreted as a string.<br>
For a table, it will display as "{{samp|table}}". For nil, "{{samp|nil}}" rather than as Script error.
;Print the contents of a table
<syntaxhighlight lang="lua" line highlight=2,13,18,21 copy>
local frame = mw.getCurrentFrame()
local candidates = {
{"#language", "ja"}, -- #language parser function retrieve (ja)panese language
{"#tag", {'isbn', '978-4-87311-471-2'}}, -- #tag parser function generates <isbn> tag
{"plural", {'42', 'book', 'books'}}, -- plural switches sentences based on number
{"canonicalurl", tostring(mw.title.getCurrentTitle())}, -- canonicalurl returns the URL of the page
}
local function args_to_string(obj)
if type(obj) == "table" then return table.concat(obj, " ") else return tostring(obj or "") end
end
for _, pair in ipairs(candidates) do -- _ = ignored index, pair = value; ipairs iterates each numeric key
local fn, arg = pair[1], pair[2] -- Parser function name to call and its argument, string or table
local ok, res
if type(arg) == "table" then
-- If the argument is a table, unpack it and pass as multiple arguments
ok, res = pcall(function() return frame:callParserFunction(fn, unpack(arg)) end)
else
-- If the argument is a single value (string), pass it as-is
ok, res = pcall(function() return frame:callParserFunction(fn, arg or "") end) -- Safe call (pcall)
end
local out = ok and tostring(res) or ("<error>") -- Convert to string on success, "<error>" on failure
-- Join argument tables for readability. Output is for the Lua console
print(string.format('%s(%q) -> %s', fn, args_to_string(arg), out))
end
</syntaxhighlight>
<syntaxhighlight lang="lua" line start=27>
#language("ja") -> 日本語
#tag("isbn 978-4-87311-471-2") -> <isbn>978-4-87311-471-2</isbn>
plural("42 book books") -> books
canonicalurl("Module:Yesno") -> https://si.wikipedia.org/wiki/Module:Yesno
</syntaxhighlight>
== Format ==
The [[WP:Lua style guide]] gives some basic formatting suggestions expected by the JavaScript module editor, such as using four-space indentations and keeping <syntaxhighlight lang="lua" inline>if then else</syntaxhighlight>, <syntaxhighlight lang="lua" inline>end</syntaxhighlight> at the same level of indentation.
Comments to the end of a line are marked by <syntaxhighlight lang="lua" inline>-- green comment</syntaxhighlight>. ''Use them.''
Many modules for Wikipedia have a straightforward, linear design, but that doesn't mean it won't help to have your sections clearly labelled when you go back to the code for the hundredth time. The Lua style guide gives additional recommendations for using functions to keep your work more organized.
== Errors ==
Lua errors appear as red "Script error" messages. If Javascript is enabled, '''the <span style="color:#ff0000;">red</span> script error message is a link''' which usually allows you to follow it back to the line in the module where the error occurred. There are some exceptions, for example "Module not found", if the name of the module itself is mistyped, or "The function you specified did not exist" if the function name given is invalid.
=== Recurrent bugs ===
Some bugs you might want to keep in mind:
;Missing operator for concatenation
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=2 copy>
local debugLog = "" -- empty report string
debugLog = debugLog "missing double dot" -- append to the report
</syntaxhighlight></blockquote>
The following means you forgot the <code>..</code> between a string and a variable somewhere in a mess of stuff you're concatenating.
<blockquote><syntaxhighlight lang="lua" line start=9>
Lua error in console input at line 8: attempt to call local 'debugLog' (a string value).
</syntaxhighlight></blockquote>
;String expected, got function
<blockquote><syntaxhighlight lang="lua" line start=7 highlight=3 copy>
local debugLog = "" -- empty report string
local res = mw.ustring.gmatch("Hello World!", "([aeiouAEIOU])") -- iterator of vowels
debugLog = debugLog..res -- populate the report with only strings
</syntaxhighlight></blockquote>
Some important things like <syntaxhighlight lang="lua" inline>mw.ustring.gmatch</syntaxhighlight> actually return ''functions'', not strings - see [[#Functions|Functions]] below.
<blockquote><syntaxhighlight lang="lua" line start=10>
Lua error in console input at line 9: attempt to concatenate local 'res' (a function value).
</syntaxhighlight></blockquote>
;Variable ignores assignment
A variable ignores all your efforts to assign stuff to it:
<blockquote><syntaxhighlight lang="lua" line highlight=1,3 copy>
local debugLog = "top level" -- initial value
do
local debugLog = "nested level" -- set the new value
print("Inside do: "..debugLog)
end
print("Outside do: "..debugLog) -- get the old value
</syntaxhighlight></blockquote>
You may have inadvertently written ''two'' local statements - the one sets the value of the variable within a limited region, and when the program leaves that region, you're back to the old value.
<blockquote><syntaxhighlight lang="lua" line start=7>
Inside do: nested level
Outside do: top level
</syntaxhighlight></blockquote>
A numbered table entry ignores all your efforts to assign to it:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local table = {}; local arg = "50"; local valPrm = tonumber(arg)
table[arg] = "index as string"
table[valPrm] = "index as number"
print(table[arg] == table[valPrm])
</syntaxhighlight></blockquote>
This is because {{code|table["50"]}} '''is not''' {{code|table[50]}}.<br/>
Typically you have processed a parameter (which you may have received from the <syntaxhighlight lang="lua" inline>#invoke</syntaxhighlight> as a string) with string functions in one place,<br>
but performed numeric operations in another, leaving you with two different types of variable to use for an index.
<blockquote><syntaxhighlight lang="lua" line start=5>
false
</syntaxhighlight></blockquote>
;<syntaxhighlight lang="lua" inline>nil</syntaxhighlight> and common pitfalls
There are all sorts of things you can't do with a local variable set to nil, such as: <syntaxhighlight lang="lua" inline>local x = nil</syntaxhighlight>, like:
# Assign <code>x.somefield</code>
# Get value at index {{code|x[idx]}}
# Concatenate <syntaxhighlight lang="lua" inline>x .. "Cannot concatenate with nil"</syntaxhighlight>
# Evaluate <syntaxhighlight lang="lua" inline>table[x]</syntaxhighlight>
Initialize such variables with: <syntaxhighlight lang="lua" inline>local x={}; local table = {}</syntaxhighlight><br>
Often "global" is mentioned in these errors because you didn't have a {{tt|local}} statement for the <syntaxhighlight lang="lua" inline>nil</syntaxhighlight> variable.
;Cannot invoke module
* ''no such module.'' You called <syntaxhighlight lang="lua" inline>#invoke:moduleNameUnknown</syntaxhighlight> that didn't exist or you wrongly kept the prefix <code>Module:</code> writing {{code|#invoke:Module:moduleName}}.
* ''the function specified did not exist.'' You called <syntaxhighlight lang="lua" inline>#invoke:moduleName|functionUnknown</syntaxhighlight>, but the field after the name of the module is wrong.<br>Often this field expects a standard name like "main", and you've forgotten it and gone straight to the first data parameter.<br>If you're unsure of the function name, check the module documentation, or look for what function(s) in the code accept a "frame" parameter.
;Graphics overflow issue
Some graphics you're trying to display are heading off to the hills: actually a HTML error.<br>
You didn't close one <syntaxhighlight lang="html" inline></div></syntaxhighlight>, so all the top: and left: styles keep adding up.
== Understanding tables and related concepts ==
* An '''expression list''' is a set of values separated by commas. The values can be strings, numbers, tables, functions, etc.
* A '''sequence''' is a set of entries with indices from 1 to N, where N is a positive integer. They can be created by placing brackets around an expression list.
For example:
<blockquote><syntaxhighlight lang="lua" line highlight=1 copy>
local seq = {1, "quotation", mw.ustring.gmatch("abca","a"), {2,3,4}}
mw.logObject(seq) -- Scribunto tool to display a table
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=3>
table#1 {
1,
"quotation",
function#1,
table#2 {
2,
3,
4,
},
}
</syntaxhighlight></blockquote>
# <code>seq[1]</code> = 1
# <code>seq[2]</code> = <syntaxhighlight lang="lua" inline>"quotation"</syntaxhighlight>
# <code>seq[3]</code> is the <syntaxhighlight lang="lua" inline>function</syntaxhighlight> returned by <code>gmatch()</code>
# <code>seq[4]</code> is the table <code>{2,3,4}</code>.
An expression list can also be recovered from a table using <syntaxhighlight lang="lua" inline>unpack()</syntaxhighlight>:
<blockquote><syntaxhighlight lang="lua" line highlight=2 copy>
local seq = {1, "quotation", mw.ustring.gmatch("abca","a"), {2,3,4}}
local var1Nbr, var2Str, var3Fct = unpack(seq)
print(("var1Nbr = %d. var2Str = \"%s\". var3Fct = %s"):format(var1Nbr, var2Str, type(var3Fct)))
</syntaxhighlight></blockquote>
<blockquote><syntaxhighlight lang="lua" line start=4>
var1Nbr = 1. var2Str = "quotation". var3Fct = function
</syntaxhighlight></blockquote>
This will set:
# <code>var1Nbr</code> = 1
# <code>var2Str</code> = <syntaxhighlight lang="lua" inline>"quotation"</syntaxhighlight>
# <code>var3Fct</code> as the <syntaxhighlight lang="lua" inline>function</syntaxhighlight> returned by <code>gmatch()</code>
# <code>{2,3,4}</code> will be discarded in this case.
* A '''table''' is a sequence, optionally supplemented by named keys: <code>digit["two"]="2"</code>. Several table functions like <code>table.concat</code> will only work with the numbered values and ignore named keys.
* The '''metatable''' offers a large, optional set of methods for altering table behavior. For example, you can define a table to be callable like a function.
=== Initializing a table ===
It is often useful to create a whole table at once in a statement. There are many equivalent ways to do this, but the shortcuts don't work for every kind of value. To begin with, the most general way is to assign each key and value explicitly:
<syntaxhighlight lang="lua" inline>a = {[0]='zero', [1]='one', ['1']='string for one'}</syntaxhighlight>
If sequence keys (positive integers) are given in order, only the values need to be given, so the following will assign <syntaxhighlight lang="lua" inline>'one'</syntaxhighlight> to <syntaxhighlight lang="lua" inline>a[1]</syntaxhighlight>:
<syntaxhighlight lang="lua" inline>a = {[0]='zero', 'one', ['1']='string for one'}</syntaxhighlight>
If a key has only letters, digits, and underscores, and begins with a non-digit, the brackets and quotation marks can be omitted:
<syntaxhighlight lang="lua" inline>a = {a='one', b='two'}</syntaxhighlight>
This is identical to <syntaxhighlight lang="lua" inline>a = {["a"]='one', ["b"]='two'}</syntaxhighlight>.
However, this will fail for keys that begin with a digit: <syntaxhighlight lang="lua" inline>hex = {7f = 127}</syntaxhighlight> will produce an error; use <syntaxhighlight lang="lua" inline>hex = {['7f'] = 127}</syntaxhighlight> instead.
Note that when given ''within'' brackets, or to the right of the equal sign, quotation marks are needed, or else string values will be taken as variables:
<syntaxhighlight lang="lua" inline> a = {[b] = c}</syntaxhighlight>
assigns the value of variable ''c'' to the key ''contained in variable'' ''b''.
== Functions ==
* Functions can return any kind of value {{--}} ''including a function''. This is a powerful feature that can readily confuse the beginner. If you set <syntaxhighlight lang="lua" inline>a=mw.ustring.gmatch(text, "(.)")</syntaxhighlight>, the result assigned to <code>a</code> will be a '''function''', not a string character! However, assigning <code>b=a()</code> by calling the function stored in <code>a</code> will return the first match (a string). Every time you set <code>b=a()</code> after that you'll get another match (string) into <code>b</code>, until you run out of matches and get <code>nil</code>. Many '''iterator functions''' act this way.
* You can keep separate counts for iterator functions by using different variables. For example, if you set <syntaxhighlight lang="lua" inline>q=mw.ustring.gmatch(text, "(x.)")</syntaxhighlight> in the same module, you can pull characters from the same piece of text (<code>text</code>) by evaluating <code>d=q()</code> without losing your place in <code>a()</code>.
* [[tail call|Tail calls]] offer substantial benefits in performance for those who master the language.
* Function names are often of the form {{code|p.myFunctionName}}, where p is the table from the {{code|return p}} at the bottom of your program. The reason for this is that you can only access functions that are entries in this table from the original {{code|#invoke}} statement. Functions for local use within the program can have any name.
== Understanding patterns ==
''Note:'' Lua patterns are ''not'' [[regular expression|regular expressions]] in the traditional POSIX sense, and they are not even a subset of regular expressions. But they share many constructs with regular expressions (more [[Help:Lua for beginners#regex|below]]).
Lua patterns are used to define, find and handle a ''pattern'' in a string. It can do the common search and replace action in a text, but it has more options that doing plain text only. For example, in one go it can change the errors 'New yorker', 'New-Yorker', and 'NewYorker' into 'New Yorker'.
* To begin with, a pattern works like a plain string so long as it doesn't contain the special characters {{code|^ $ () % . [] * + - ?}}
* Square brackets {{code|[ ]}} are used to match ''one'' ''single character'' in the string from a list of choices. {{code|[abc]}} matches the letters a, b, or c. With {{code|^}} right after {{code|[}} they indicate "anything but": {{code|[^abc]}} = not a, b, or c. Inside brackets and when not the first character, a minus {{code|-}}indicates a range: {{code|[a-z]}} matches one single character from a, b, c, …, z.
* Period {{code|.}} matches any character.
* Percent {{code|%}} indicates a large set (class) of possible character matches when it is followed by a letter. See [https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Character_class] for a full list. <!--- should test/list these empirically to be sure ---> When followed by punctuation (whether a special character above or not) the {{code|%}} is removed and the punctuation is taken as a literal character; {{code|%%}} = literal %. Special classes include a balanced class {{code|%bxy}} and {{code|%f[set]}}; see the link above for more.
* Parentheses {{code|( )}} indicate captures. The captures can be accessed later in the search string or in the string.gsub replacement string as {{code|%1}} to {{code|%9}}, and are returned by string.match as an expression list of results.
* The qualifiers {{code|? - * +}} specify repetitions of a single character (not a longer string).
:* {{code|?}} means 0 or 1 repetitions: {{code|a?}} matches "a" or "".
:* {{code|-}} means 0 or more repetitions, choosing as few as possible to achieve a match ("non-greedy"). For example {{code|2=lua|string.match("bbbb", "(.-)")}} yields "", which is less than useful because there is nothing to root the ends of the expression and prevent it from matching zero characters.
:* {{code|*}} means 0 or more repetitions, choosing as many as possible ("greedy"). For example {{code|2=lua|string.match("bbbb", ".*")}} yields bbbb.
:* {{code|+}} means 1 or more repetitions, choosing as many as possible ("greedy").
Note that the greediness of the ''leftmost'' qualifier rules over all others when there is a choice: {{code|(.*)b(.*)}} when matched on "bbb" will return "bb", "", while {{code|a(.-)b(.-)a}} when matched on "abbba" will return "", "bb".
* {{code|^}} and {{code|$}} indicate the beginning and end of the string if they occur in the appropriate place in the pattern. Otherwise they are literal characters. {{code|^}} is not used in the {{code|string.gmatch}} function.
The reference manual for Lua patterns is at [[:mw:Extension:Scribunto/Lua_reference_manual#Patterns|mediawiki.org]].
== {{anchor|regex}}Note on Lua patterns versus regular expressions ==
Lua patterns are ''loosely based'' on [[regular expression]]s (sometimes shortened to regex or regexp). Lua patterns deliberately lack the most complex regular expression constructs (to avoid bloating the Lua code base), where many other computer languages or libraries use a more complete set. Lua patterns are not even a subset of regular expressions, as there are also discrepancies, like Lua using the escape character <code>%</code> instead of <code>\,</code>, and additions, like Lua providing <code>-</code> as a non-greedy version of <code>*</code>.
Here is a list of some of the things that Lua patterns lack compared to regular expressions:
* You '''cannot''' search for alternations between anything else than single characters (you '''cannot''' say <code>(his|her)</code> to choose between <code>his</code> and <code>her</code>, you can only say <code>[abc]</code> to choose between single characters <code>a</code>, <code>b</code>, or <code>c</code>).
* You '''cannot''' look for multiples of multi-letter constructs such as <code>(choo-)*choo</code> to match <code>choo</code>, <code>choo-choo</code> or <code>choo-choo-choo</code>. There is no way to do this with Lua patterns.
* You '''cannot''' specify the minimum and maximum number of repetitions like <code>[0-9]{3,5}</code> (to match 3 to 5 digits); in Lua you would say <code>%d%d%d%d?%d?</code> instead in this case.
There are Lua libraries that offer more powerful options,<sup>[http://lua-users.org/wiki/PatternsTutorial]</sup> including regular expressions, but the support on Wikipedia is pretty basic.
Wikipedia help for regular expressions (which Lua, as mentioned, does ''not'' support) is at [[Wikipedia:AutoWikiBrowser/Regular expression]].
{{Wikipedia technical help|collapsed}}
[[Category:Module help|*]]
8l6kngx8grh2qwchefw0h15wgxdsx2c
එස්කල්ඩෙස්-එන්ගොර්ඩෙනි, ඇන්ඩෝරාව
0
185326
790909
770712
2026-05-19T12:19:19Z
CommonsDelinker
157
Recreation of content deleted per community consensus ([[:c:COM:CSD#G4|G4]]), හේතුව ලෙස දක්වා [[c:User:Explicit|Explicit]] විසින් [[c:File:Andorralavella06.jpg|Andorralavella06.jpg]] ගොනුව මකාදමා ඇත.
790909
wikitext
text/x-wiki
{{Infobox settlement
| name = Escaldes-Engordany
| image_skyline =
| image_caption = view of [[Escaldes]]
| image_flag = Hypothetical flag of Escaldes-Engordany.svg
| image_shield = Escut d'Escaldes-Engordany.svg
| shield_size = 80px
| image_map =
| mapsize = 100px
| pushpin_map = Andorra
| pushpin_image = Escaldes-Engordany in Andorra.svg
| pushpin_label_position =
| pushpin_map_caption = Location of Escaldes-Engordany within Andorra
| pushpin_mapsize =
| map_caption = Position of Escaldes-Engordany parish in Andorra
| subdivision_type = [[Countries of the world|Country]]
| subdivision_type1 = [[Parishes of Andorra|Parishes]]
| subdivision_type2 = Villages
| subdivision_name = [[Andorra]]
| subdivision_name1 = Escaldes-Engordany
| subdivision_name2 = [[Les Escaldes|Escaldes]], [[Engordany]], [[El Fener]], [[Els Vilars d'Engordany]], [[Engolasters]]
| leader_party = [[Independent politician|Independent]]
| leader_title = Mayor
| leader_name = [[Rosa Gili Casals]]
| area_magnitude =
| area_total_km2 = 30
| area_land_km2 =
| area_water_km2 =
| population_as_of = 2005
| population_note =
| population_total = 14395
| population_metro =
| population_density_km2 = 479.83
| population_demonym = ''escaldenc, escaldenca''
| timezone =
| utc_offset =
| timezone_DST =
| utc_offset_DST =
| coordinates = {{coord|42|30|32|N|1|32|27|E|region:AD|display=inline,title}}
| coor_pinpoint = Escaldes town
| elevation_m = 1050
| elevation_max_m =
| elevation_min_m =
| postal_code = AD700
| website = [http://www.e-e.ad/ Official site]
| footnotes =
}}
'''එස්කල්ඩ්ස්–එන්ගෝර්ඩනි''' යනු ඇන්ඩෝරා හි පැරිෂි හතෙන් එකකි. එස්කල්ඩ්ස්-එන්ගෝර්ඩනි පැරිෂිය 1978 දී ඇන්ඩෝරා ලා වෙල්ලා වෙතින් වෙන් කිරීමෙන් ආරම්භ කරන ලදී. මෙම පැරිෂිය ලෙස් එස්කල්ඩ්ස්, එන්ගෝර්ඩනි, එල්ස් විලාර්ස් ඩි'එන්ගෝර්ඩනි, එන්ගෝලාස්ටර්ස් සහ එල් ෆෙනර් යන ප්රදේශ වලින් සමන්විත වේ. <ref>{{උපන්යාස වෙබ් |title=les Escaldes i Engordany |url=https://www.enciclopedia.cat/gran-enciclopedia-catalana/les-escaldes-i-engordany |access-date=24 November 2024 |website=Gran Enciclopèdia Catalana |language=ca}}</ref> 2014 වන විට එහි ජනගහනය 13,634 ක් වන අතර එය ඇන්ඩෝරා ලා වෙල්ලාට පසු දෙවන විශාලතම ජනගහනයයි. කැපී පෙනෙන සිදුවීම් අතරට 2025 සිට දේශීය නිවාඩු දිනයක් කිරීමට ජනතාව තීරණය කළ සැන්ට් මිකෙල් ඩි'එන්ගෝලර්ස්ටර්ස්ගේ මැයි 8 වන දින මංගල්යය ඇතුළත් වේ <ref>{{Cite news|url=https://elperiodic.ad/wp-content/uploads/2025/05/elPeriodicNews_10_05_25.pdf|title=The feast of Sant Miquel d’Engolasters is reborn as a symbol of local identity|date=10 May 2025|work=EL Periodic|access-date=10 August 2025|pages=1}}</ref>
එය පැරිෂි හතරකට මායිම් වේ: උතුරින් සහ ඊසාන දෙසින් එන්කෑම්ප්, නිරිත දෙසින් සැන්ට් ජූලියා ඩි ලෝරියා, බටහිරින් ඇන්ඩෝරා ලා වෙල්ලා සහ වයඹ දෙසින් ලා මැසානා . නැගෙනහිර, දකුණින් සහ ගිනිකොන දෙසින් එස්කල්ඩ්ස්–එන්ගෝර්ඩනි [[ස්පාඤ්ඤය|ස්පාඤ්ඤයට]] ද මායිම් වේ.
== යොමු කිරීම් ==
[[ප්රවර්ගය:CS1 ප්රංශ-භාෂා මූලාශ්ර (fr)]]
[[ප්රවර්ගය:Coordinates on Wikidata]]
[[ප්රවර්ගය:Pages using gadget WikiMiniAtlas]]
hkjs6knqnjsjkdohr9xvk47ljdrck8x
ඇම්ස්ටර්ඩෑමයේ ඉතිහස
0
194327
790910
790905
2026-05-19T12:39:57Z
WrdSrchSi
55524
/*පිරිහුම හා නවීකරණය*/ translated 3 paragraphs
790910
wikitext
text/x-wiki
[[ගොනුව:Gezicht_op_Amsterdam_in_vogelvlucht_1538_Cornelis_Anthonisz.jpg|thumb|300x300පික්|IJ වෙතින් 1538 දී කෝර්නෙලිස් ඇන්තනිසූන් විසින් ඇඳුණු ඇම්ස්ටර්ඩෑමය. මෙය ඇම්ස්ටර්ඩෑමයේ පැරැණිතම නගර සිතියමයි. එය ඇරැකි පවුරත් ගේට්ටුත් සහිත සපිරි මැදි-කැලි නගරය පෙන්වයි.]]
ඇම්ස්ටර්ඩෑමයට දිගු හා ඉසවුබර ඉතිහසෙකි. නගරයේ මුල එහි වැසියන් ඇම්ස්ටෙල මුවෙහි විසුම් ගෙන පීට්ලන්ත ගොඩකිරීම ඇරැඹූ කි.ව. 1000 පමණ වෙයි. 1170 දී වූ සියලු සාන්තුවරුන් ගේ ගංවතුරින් පසු, ගංවතුරින් පහත් බිම් පිරිරකිනුව ඇම්ස්ටෙලයේ වේල්ලෙක් බැඳිණි. <ref name="200jaarouder">{{උපන්යාස වෙබ් |date=22 October 2008 |title='Amsterdam 200 jaar ouder dan aangenomen' |url=http://www.nu.nl/news/1801750/80/rss/%27Amsterdam_200_jaar_ouder_dan_aangenomen%27.html |url-status=dead |archive-url=https://web.archive.org/web/20081025045803/http://www.nu.nl/news/1801750/80/rss/%27Amsterdam_200_jaar_ouder_dan_aangenomen%27.html |archive-date=25 October 2008 |access-date=8 September 2024 |website=NU.nl |via=ANP - Algemeen Nederlands Persbureau}}</ref>
1275 දී, කවුන්ට්වර පස්වන ෆ්ලොරිස් විසින් දෙවුණු ගාස්තු වරප්රසාදය හේතුවෙන් ඇම්ස්ටර්ඩෑමය පාලම් ගාස්තුවෙන් නිදහස් විණි. <ref name="toll1">[https://stadsarchief.amsterdam.nl/english/amsterdam_treasures/trade/toll_privilege/index.en.html The toll privilege at the Amsterdam City Archives] {{Webarchive|url=https://web.archive.org/web/20160106010052/http://stadsarchief.amsterdam.nl/english/amsterdam_treasures/trade/toll_privilege/index.en.html|date=6 January 2016}}</ref> මෙය ඇම්ස්ටර්ඩෑමය දෑබැඳි වෙළඳුන් අතර අඩු මිලට බඬු විකිණීම සඳහා ජනප්රිය කළේ යි. <ref name="toll1" /> මධ්යතන යුගයේ දී ලොව විසල්තම වෙළෙඳ පුරවලින් එකක් බවට ඒ දිවැඩිණි. රන්මය යුගයක් වූ 17 වන සියවසේ දී ඇම්ස්ටර්ඩෑමය යුරෝපාවේ වැදැගත් මැ මැදි වෙළෙඳ තැනත් බටහිරි ලොව ප්රමුඛ මූල්ය පොළත් විණි. <ref name="am17">[http://www.uncp.edu/home/rwb/Amsterdam_l.html Amsterdam in the 17th century] {{Webarchive|url=https://web.archive.org/web/20090826132532/http://www.uncp.edu/home/rwb/Amsterdam_l.html|date=26 August 2009}}, The University of [[උතුරු කැරොලිනා|North Carolina]] at Pembroke</ref> ඇම්ස්ටර්ඩෑමය එහි ඇති බොහෝ ඇළ මං නිසා "උතුරේ වැනීසිය" ලෙස වාචිකව හැඳින්වේ. වැඩිහිටි පිනැවුම හේතුවෙන් ඒ ඉහළම පවෙහි නගරයක් ලෙස ද ශ්රේණිගත කෙරී ඇත. නෙදර්ලන්තයේ අගනුවර ලෙස, 2024 දී 930,000 කට අධික ජනගහනයකින් යුත් එහි විසල්ම නගරය එය යි. <ref name="venice1">{{උපන්යාස වෙබ් |last=Ahmed |first=Shamim |date=10 July 2015 |title=Amsterdam {{•}} Venice of the North |url=https://m.theindependentbd.com//magazine/details/7145/Amsterdam-%E2%80%93-Venice-of-the-North |archive-url=https://web.archive.org/web/20220615062341/https://m.theindependentbd.com//magazine/details/7145/Amsterdam-%E2%80%93-Venice-of-the-North |archive-date=15 June 2022 |access-date=15 June 2022 |website=The Independent}}</ref> <ref name="askmen2">{{උපන්යාස වෙබ් |last=Voyer |first=Marc |title=Top 10: Sin Cities |url=https://uk.askmen.com/top_10/travel/top-10-sin-cities.html |archive-url=https://web.archive.org/web/20230111090315/https://uk.askmen.com/top_10/travel/top-10-sin-cities.html |archive-date=11 January 2023 |access-date=19 December 2017 |website=[[Ask Men]]}}</ref> <ref name="dutchreview">{{උපන්යාස වෙබ් |last=Hull |first=Kenneth |date=9 March 2018 |title=Sin City Wars: Amsterdam versus Las Vegas |url=https://dutchreview.com/featured/sin-city-wars-amsterdam-versus-las-vegas/ |archive-url=https://archive.today/20241013122953/https://dutchreview.com/featured/sin-city-wars-amsterdam-versus-las-vegas/ |archive-date=13 October 2024 |access-date=13 October 2024 |website=DutchReview}}</ref> <ref name="bevolking2024">{{උපන්යාස වෙබ් |title=Bevolkingsontwikkeling; regio per maand - 2024 |url=https://opendata.cbs.nl/#/CBS/nl/dataset/37230ned/table |access-date=11 September 2024 |website=Central Bureau of Statistics |quote=Filter region Regio's > Gemeenten per Provincie > Amsterdam}}</ref>
== පෙරැ-ඉතිහස ==
ඇම්ස්ටර්ඩෑමයේ මුල 12 වන සියවසට වඩා බොහෝ පැරැණි බවට 2005 සහ 2012 අතරැ කැරුණු කැණීම්වලින් දෙස් ලැබිණි. මෙට්රෝ ලයින් 52 (නූර්ඩ්/සුයිඩ්ලිජ්න් ලෙස ද හැඳින්වෙන) දැමීමේ දී පුරාවිදුවන් විසින් දැන් දම්රැක් සහ රොකින් පිහිටි ඇම්ස්ටෙල ගං පත්ලෙන් බොහෝ වස්තූන් සොයාගැනිණි. වීදි මට්ටමට මීටර් 30 ක් පමණ පහළින්, පුරාවිදුවෝ රොකින් (කි.පෙ. 2200–2000) යටින් කණු-පොරෝ, ගල් මිටියක්, බෙල් බීකර් හැදියාවේ මැටි බඳුන් කැබැලි සහ දම්රැක් (කි.පෙ. 2700–2750) යටින් ග්රැනයිට් ඇඹරුම් ගලක් සොයාගත් හ. බොහෝ වස්තූන් නව ශිලා යුගයේ (වසර 4600 දක්වා) සහ රෝම යුගයේ (වසර 2000 පමණ පෙර) සිටැ පැවැතෙන්නේ යි. <ref name="steentijd1">{{උපන්යාස වෙබ් |last=Peter-Paul de Baar |date=6 January 2012 |title=Amsterdam al in de steentijd bewoond |url=https://www.onsamsterdam.nl/nieuws/1241-breaking-news-amsterdam-al-in-steentijd-bewoond.html |url-status=dead |archive-url=https://web.archive.org/web/20180926085853/https://www.onsamsterdam.nl/nieuws/1241-breaking-news-amsterdam-al-in-steentijd-bewoond.html |archive-date=2018-09-26 |website=Ons Amsterdam}}</ref> <ref>{{Cite journal|last=Gawronski|first=J|date=2017|title=Ontstaan uit een storm; De vroegste geschiedenis van Amsterdam archeologisch en landschappelijk belicht|trans-title=Born from a storm; The earliest history of Amsterdam from an archaeological and landscape perspective.|url=https://www.theobakker.net/pdf/TX_Gawronski2017JbAmstelodamum_10.pdf|journal=Jaarboek van het Genootschap Amstelodamum|language=Dutch|location=Amsterdam|publisher=University of Amsterdam|volume=109|archive-url=https://web.archive.org/web/20240914204020/https://www.theobakker.net/pdf/TX_Gawronski2017JbAmstelodamum_10.pdf|archive-date=14 September 2024|access-date=5 January 2021}}, pp. 69–71.</ref> <ref>{{උපන්යාස වෙබ් |title=Below the Surface – Archeologische vondsten Noord/Zuidlijn Amsterdam |url=https://belowthesurface.amsterdam/en/vondsten |archive-url=https://web.archive.org/web/20240915045817/https://belowthesurface.amsterdam/en/vondsten |archive-date=15 September 2024 |access-date=25 February 2021 |website=belowthesurface.amsterdam}}</ref> <ref name="steentijd1" />
මින් හැඟවෙන්නේ ඇම්ස්ටර්ඩෑමයේ හෝ එහි පූර්වගාමිකයේ හෝ කි.පෙ. 2600 පමණ සිටැ ජනාවාස තිබූ බව යි. කෙසේ වතදු, මෙ ජනාවාස බොහෝ විට අඩ තිර හෝ උතුමය හෝ වූයේ විය හැකි. මන්ද ඇම්ස්ටෙල ගං මුවත් ඉවුරුත් තිර විසුමට සුදුසු නොවන තරම් තෙත් වීම යි. <ref>{{උපන්යාස වෙබ් |last=Simone Lautenbach |date=5 January 2012 |title='Amsterdam mogelijk 2000 jaar ouder dan gedacht' |url=http://www.parool.nl/parool/nl/4/AMSTERDAM/article/detail/3107442/2012/01/05/Amsterdam-mogelijk-2000-jaar-ouder-dan-gedacht.dhtml |archive-url=https://web.archive.org/web/20120111004829/http://www.parool.nl/parool/nl/4/AMSTERDAM/article/detail/3107442/2012/01/05/Amsterdam-mogelijk-2000-jaar-ouder-dan-gedacht.dhtml |archive-date=11 January 2012 |website=Het Parool}}</ref> <ref>{{උපන්යාස වෙබ් |date=10 January 2012 |title=Ons Amsterdam, no 1, 2012. |url=http://www.onsamsterdam.nl/component/content/article/32-tijdschrift/tijdschrift-jaargang-2012/1237-nummer-1-januari-2012?showall=&start=5 |url-status=dead |archive-url=https://web.archive.org/web/20160313104734/http://www.onsamsterdam.nl/component/content/article/32-tijdschrift/tijdschrift-jaargang-2012/1237-nummer-1-januari-2012?showall=&start=5 |archive-date=13 March 2016}}</ref> <ref>{{Cite journal|last=Gawronski|first=J|date=2017|title=Ontstaan uit een storm; De vroegste geschiedenis van Amsterdam archeologisch en landschappelijk belicht|trans-title=Born from a storm; The earliest history of Amsterdam from an archaeological and landscape perspective.|url=https://www.theobakker.net/pdf/TX_Gawronski2017JbAmstelodamum_10.pdf|journal=Jaarboek van het Genootschap Amstelodamum|language=Dutch|location=Amsterdam|publisher=University of Amsterdam|volume=109|access-date=5 January 2021}}, pp. 62–63.</ref> <ref>{{Cite journal|last=Kranendonk|first=P.|last2=Kluiving|first2=S. J.|last3=Troelstra|first3=S. R.|date=December 2015|title=Chrono- and archaeostratigraphy and development of the River Amstel: results of the North/South underground line excavations, Amsterdam, the Netherlands<!--sic-->|journal=Netherlands Journal of Geosciences|volume=94|issue=4|pages=333–352|bibcode=2015NJGeo..94..333K|doi=10.1017/njg.2014.38|issn=0016-7746|doi-access=free}}</ref>
==පිරිහුම හා නවීකරණය==
18 වන සියවසත් 19 වන සියවසේ මුල් හරියත් ඇම්ස්ටර්ඩෑමයේ ඉසුරුමත් බවෙහිත් ලන්දේසි ජනරජයේත් පිරිහීම දිටි. ඊට ප්රධාන හෙය වූයේ එංගලන්තයෙන්, ප්රංශයෙන්, ප්රෂියාවෙන් හා රුසියාවෙන් ආ තරඟකාරිත්වයේ වැඩීම යි. ෆ්රැන්කෝ-ලන්දේසි යුදයත් ඇන්ග්ලෝ-ලන්දේසි යුදයත්, වෙසෙසින් සිව්වන ඇන්ග්ලෝ-ලන්දේසි යුදයත් (1780–1784) වනසකුරු බලපෑමක් කළේ යි.
19 වන සියවසේ දෙ වන බෑයේ දී, ඇම්ස්ටර්ඩෑමය කෙමෙන් කම්යුරු නගරයක් බවට පත් විය. වැදැගත් නව ආර්ථික අංශ වූයේ දියමන්ති කම්යුරුව, නැව් තැනීම, ඇඳුම් පැළැඳුම් සහ ඇංජිම් කම්හල් සහ පසු වැ [[මෝටර් රථ|සරවු]] සහ [[ගුවන්යානා|අහස්යාන්]] නිපැයුම යි.
1863 දී උතුරු මුහුදු ඇළ සඳහා ප්රමාණවත් සහයකුත් පාර්ලිමේන්තු අනුමැතියකුත් ලැබිණි. විසල් මුහුදු යන දියදුම් නැව් සඳහා පිවිසුම වැඩිදියුණු කිරීමත් ඇම්ස්ටර්ඩෑමයේ තරඟකාරී තතුව වැඩිදියුණු කිරීමත් මෙහි අරමුණ විය. ඉඩම් ගොඩකිරීම් සහ කැණීම් කටයුතු සඳහා තැනැති අරමුදල් සැපැයිණි. මෙ ඇළ ඇම්ස්ටර්ඩෑමය IJmuiden හරහා උතුරු මුහුදට අමුණයි. පෙරදෙවු දෙකම සෙසු යුරෝපාවත් ලොවත් සමඟ සන්නිවේදනය නළුයුරු (නාටකාකාර) ලෙස වැඩිදියුණු කළේ ය. ඒවා ආර්ථිකයට විසල් සවියක් දිනි.
== හැදියාව ==
15 වන සහ 16 වන සියවස්වල දී, ඇම්ස්ටර්ඩෑමයේ සංස්කෘතික දිවිය ප්රධාන විසින් උලෙළුවලින් යුත් වුයේ යි. 16 වන සියවසේ අග හරියේ දී, ඇම්ස්ටර්ඩෑමයේ Rederijkerskamer කවි හා [[නාට්ය|නළු]] හදාරන නන් මඬුලු අතර තරඟ සවිදහන් කළේ යි. ඇම්ස්ටර්ඩෑමයට 1638 දී එහි පළමු රඟහල ලැබිණි. 1642 තරම් මුල් කලැ දී මෙ රඟහලේ දී බැලේ සංදර්ශන පෙන්විණි. 18 වන සියවසේ දී ප්රංශ නළු ජනප්රිය විය. 1677 සිටැ ඇම්ස්ටර්ඩෑමයේ ඔපෙරා දැකියැ හැකි විය. පළමුවෙන් ඉතාලි සහ ප්රංශ ඔපෙරා පමණ ක් වූ නමුත් 18 වන සියවසෙහි ජරමන ඔපෙරා ද විය. 19 වන සියවසේ දී, ජනප්රිය සංස්කෘතිය ඇම්ස්ටර්ඩෑමයේ නෙස් පෙදෙස (ප්රධාන වශයෙන් vaudeville සහ මීයැසි හල) කේන්ද්රගත වැ විය. [[සම්භාව්යය සංගීතය|යුරෝපා කුලවත් මීයැසියේ]] වැදැගත් මැ දියුණුවක් වන මෙට්රොනෝමය 1812 දී ඩියෙට්රික් නිකොලස් වින්කෙල් විසින් බිහි කැරිණි. මෙ සියවස අවසනැ, Rijksmuseum හා Stedelijk ඇම්ස්ටර්ඩෑම කටුගෙය ඉදිකැරිණි. 1888 දී Concertgebouworkest ඇරැඹිණි. 20 වන සියවසත් සමඟ [[චිත්රපට|සලරුවත්]] [[ගුවන් විදුලිය|රෙදෙව්වත්]] [[රූපවාහිනිය|තෙලදසුනත්]] පැමිණි. Hilversum සහ Aalsmeer හි කලාගර තිබුණත් වැඩසටහන්කරණය කෙරෙහි ඇම්ස්ටර්ඩෑමයේ බලපෑම ඉතා සවිමති.[[දෙවන ලෝක යුද්ධය|දෙ වන ලෝ මහ යුදෙන්]] පසු, ජනප්රිය [[සංස්කෘතිය|හැදියාව]] ඇම්ස්ටර්ඩෑමයේ ප්රමුඛ සංස්කෘතික සංසිද්ධිය බවට පත්විය. ලොවැ පළමු නිල සමලිංගික විවාහය ඇම්ස්ටර්ඩෑමයේ පැවැත්විණි.
== මුලාශ්ර ==
{{Reflist}}
btu4zsj5u6bdox5cd4dno1r2e3qu0kz
790949
790910
2026-05-20T04:00:54Z
WrdSrchSi
55524
Fixed. (rephrased)
790949
wikitext
text/x-wiki
[[ගොනුව:Gezicht_op_Amsterdam_in_vogelvlucht_1538_Cornelis_Anthonisz.jpg|thumb|300x300පික්|IJ වෙතින් 1538 දී කෝර්නෙලිස් ඇන්තනිසූන් විසින් ඇඳුණු ඇම්ස්ටර්ඩෑමය. ඇම්ස්ටර්ඩෑමයේ පැරැණිතම නගර සිතියම යි මේ. එය ඇරැකි පවුරත් ගේට්ටුත් සහිත සපිරි මැදි-කැලි නගරය පෙන්වයි.]]
ඇම්ස්ටර්ඩෑමයට දිගු හා ඉසවුබර ඉතිහසෙකි. එහි වැසියන් ඇම්ස්ටැල මුවේ විසුම් ගෙනැ පීට්ලන්ත ගොඩකිරීම ඇරැඹූ කි.ව. 1000 පමණ නගරයේ මුල වෙයි. 1170 දී වූ සියලු සාන්තුවරුන් ගේ ගංවතුරින් පසු, ගංවතුරින් පහත් බිම් පිරිරකිනුව ඇම්ස්ටැලයේ වේල්ලෙක් බැඳිණි.<ref name="200jaarouder">{{උපන්යාස වෙබ් |date=22 October 2008 |title='Amsterdam 200 jaar ouder dan aangenomen' |url=http://www.nu.nl/news/1801750/80/rss/%27Amsterdam_200_jaar_ouder_dan_aangenomen%27.html |url-status=dead |archive-url=https://web.archive.org/web/20081025045803/http://www.nu.nl/news/1801750/80/rss/%27Amsterdam_200_jaar_ouder_dan_aangenomen%27.html |archive-date=25 October 2008 |access-date=8 September 2024 |website=NU.nl |via=ANP - Algemeen Nederlands Persbureau}}</ref>
1275 දී, කවුන්ට්වර පස්වන ෆ්ලොරිස් විසින් පිරිනැමුණු ගාස්තු වරප්රසාදය ඇම්ස්ටර්ඩෑමය පාලම් ගාස්තුවෙන් නිදහස් කළේ යි.<ref name="toll1">[https://stadsarchief.amsterdam.nl/english/amsterdam_treasures/trade/toll_privilege/index.en.html The toll privilege at the Amsterdam City Archives] {{Webarchive|url=https://web.archive.org/web/20160106010052/http://stadsarchief.amsterdam.nl/english/amsterdam_treasures/trade/toll_privilege/index.en.html|date=6 January 2016}}</ref> මෙය අඩු මිලට බඬු විකිණීමෙහි ලා ඇම්ස්ටර්ඩෑමය දෑබැඳි වෙළඳුන් අතර ජනප්රිය කළේ යි.<ref name="toll1" /> මධ්යතන යුගයේ දී ලොව විසල්තම වෙළෙඳ පුරවලින් එකක් බවට ඒ දිවැඩිණි. රන්මය යුගයක් වූ 17 වන සියවසේ දී ඇම්ස්ටර්ඩෑමය යුරෝපාවේ වැදැගත් මැ මැදි වෙළෙඳ තැනත් අවරදිගු ලොවැ ඉදිරියෙන් මැ සිටි මූල්ය පොළත් විය.<ref name="am17">[http://www.uncp.edu/home/rwb/Amsterdam_l.html Amsterdam in the 17th century] {{Webarchive|url=https://web.archive.org/web/20090826132532/http://www.uncp.edu/home/rwb/Amsterdam_l.html|date=26 August 2009}}, The University of [[උතුරු කැරොලිනා|North Carolina]] at Pembroke</ref> එහි ඇති බොහෝ ඇළ නිසා ඇම්ස්ටර්ඩෑමය කට වහරේ "උතුරේ වැනීසිය" ලෙස හැඳින්වේ. වැඩිහිටි පිනැවුම හේතුවෙන් ඒ ඉහළම පවෙහි නගරයක් ලෙස ද ශ්රේණිගත කෙරී ඇත. නෙදර්ලන්තයේ අගනුවර හැටියට, 2024 දී 930,000 කට අධික ජනගහනයක් සමඟ, එය එහි විසල්තම නගරය වෙයි.<ref name="venice1">{{උපන්යාස වෙබ් |last=Ahmed |first=Shamim |date=10 July 2015 |title=Amsterdam {{•}} Venice of the North |url=https://m.theindependentbd.com//magazine/details/7145/Amsterdam-%E2%80%93-Venice-of-the-North |archive-url=https://web.archive.org/web/20220615062341/https://m.theindependentbd.com//magazine/details/7145/Amsterdam-%E2%80%93-Venice-of-the-North |archive-date=15 June 2022 |access-date=15 June 2022 |website=The Independent}}</ref><ref name="askmen2">{{උපන්යාස වෙබ් |last=Voyer |first=Marc |title=Top 10: Sin Cities |url=https://uk.askmen.com/top_10/travel/top-10-sin-cities.html |archive-url=https://web.archive.org/web/20230111090315/https://uk.askmen.com/top_10/travel/top-10-sin-cities.html |archive-date=11 January 2023 |access-date=19 December 2017 |website=[[Ask Men]]}}</ref><ref name="dutchreview">{{උපන්යාස වෙබ් |last=Hull |first=Kenneth |date=9 March 2018 |title=Sin City Wars: Amsterdam versus Las Vegas |url=https://dutchreview.com/featured/sin-city-wars-amsterdam-versus-las-vegas/ |archive-url=https://archive.today/20241013122953/https://dutchreview.com/featured/sin-city-wars-amsterdam-versus-las-vegas/ |archive-date=13 October 2024 |access-date=13 October 2024 |website=DutchReview}}</ref><ref name="bevolking2024">{{උපන්යාස වෙබ් |title=Bevolkingsontwikkeling; regio per maand - 2024 |url=https://opendata.cbs.nl/#/CBS/nl/dataset/37230ned/table |access-date=11 September 2024 |website=Central Bureau of Statistics |quote=Filter region Regio's > Gemeenten per Provincie > Amsterdam}}</ref>
== පෙරැ-ඉතිහස ==
ඇම්ස්ටර්ඩෑමයේ මුල 12 වන සියවසට වඩා බොහෝ පැරැණි බවට 2005ත් 2012ත් අතරැ කැරුණු කැණීම්වලින් දෙස් ලැබිණි. මෙට්රෝ ලයින් 52 (නූර්ඩ්/සුයිඩ්ලිජ්න් ලෙස ද හැඳින්වෙන) දමන විට දැන් දම්රැක් සහ රොකින පිහිටි ඇම්ස්ටැල ගං පත්ලෙන් බොහෝ වස්තු පුරාවිදුවන් විසින් සොයාගැනිණි. පුරාවිදුවෝ රොකිනයෙන් (කි.පෙ. 2200–2000) කණු-පොරෝ මෙන් මැ ගල් මිටියකුත් බෙල් බීකර් හැදියාවේ මැටි බඳුන් කැබැලිත් දම්රැකයෙන් (කි.පෙ. 2700–2750) ග්රැනයිට් ඇඹැරුම් ගලකුත් වීදි මට්ටමට මීටර 30 ක් පමණ යටින් සොයාගතු. බොහෝ වස්තු නව සෙල් (ශිලා) යුගයේ (වසර 4600 දක්වා) සහ රෝම යුගයේ (වසර 2000 පමණ පෙර) සිටැ පැවැතෙන්නේ යි.<ref name="steentijd1">{{උපන්යාස වෙබ් |last=Peter-Paul de Baar |date=6 January 2012 |title=Amsterdam al in de steentijd bewoond |url=https://www.onsamsterdam.nl/nieuws/1241-breaking-news-amsterdam-al-in-steentijd-bewoond.html |url-status=dead |archive-url=https://web.archive.org/web/20180926085853/https://www.onsamsterdam.nl/nieuws/1241-breaking-news-amsterdam-al-in-steentijd-bewoond.html |archive-date=2018-09-26 |website=Ons Amsterdam}}</ref><ref>{{Cite journal|last=Gawronski|first=J|date=2017|title=Ontstaan uit een storm; De vroegste geschiedenis van Amsterdam archeologisch en landschappelijk belicht|trans-title=Born from a storm; The earliest history of Amsterdam from an archaeological and landscape perspective.|url=https://www.theobakker.net/pdf/TX_Gawronski2017JbAmstelodamum_10.pdf|journal=Jaarboek van het Genootschap Amstelodamum|language=Dutch|location=Amsterdam|publisher=University of Amsterdam|volume=109|archive-url=https://web.archive.org/web/20240914204020/https://www.theobakker.net/pdf/TX_Gawronski2017JbAmstelodamum_10.pdf|archive-date=14 September 2024|access-date=5 January 2021}}, pp. 69–71.</ref><ref>{{උපන්යාස වෙබ් |title=Below the Surface – Archeologische vondsten Noord/Zuidlijn Amsterdam |url=https://belowthesurface.amsterdam/en/vondsten |archive-url=https://web.archive.org/web/20240915045817/https://belowthesurface.amsterdam/en/vondsten |archive-date=15 September 2024 |access-date=25 February 2021 |website=belowthesurface.amsterdam}}</ref><ref name="steentijd1" />
මින් හැඟැවෙනුයේ ඇම්ස්ටර්ඩෑමයේ හෝ එහි පූර්වගාමිකයේ හෝ කි.පෙ. 2600 පමණ සිටැ ජනාවාස තුබූ බව යි. කෙසේ වතදු, මේ ජනාවාස බොහෝ විට අඩ තිර හෝ උතුමය හෝ වූයේ විය හැකි. මන්ද ඇම්ස්ටෙල ගං මුවත් ඉවුරුත් තිර විසුමට නො සුදුසු තරමට තෙත් වීම යි.<ref>{{උපන්යාස වෙබ් |last=Simone Lautenbach |date=5 January 2012 |title='Amsterdam mogelijk 2000 jaar ouder dan gedacht' |url=http://www.parool.nl/parool/nl/4/AMSTERDAM/article/detail/3107442/2012/01/05/Amsterdam-mogelijk-2000-jaar-ouder-dan-gedacht.dhtml |archive-url=https://web.archive.org/web/20120111004829/http://www.parool.nl/parool/nl/4/AMSTERDAM/article/detail/3107442/2012/01/05/Amsterdam-mogelijk-2000-jaar-ouder-dan-gedacht.dhtml |archive-date=11 January 2012 |website=Het Parool}}</ref><ref>{{උපන්යාස වෙබ් |date=10 January 2012 |title=Ons Amsterdam, no 1, 2012. |url=http://www.onsamsterdam.nl/component/content/article/32-tijdschrift/tijdschrift-jaargang-2012/1237-nummer-1-januari-2012?showall=&start=5 |url-status=dead |archive-url=https://web.archive.org/web/20160313104734/http://www.onsamsterdam.nl/component/content/article/32-tijdschrift/tijdschrift-jaargang-2012/1237-nummer-1-januari-2012?showall=&start=5 |archive-date=13 March 2016}}</ref><ref>{{Cite journal|last=Gawronski|first=J|date=2017|title=Ontstaan uit een storm; De vroegste geschiedenis van Amsterdam archeologisch en landschappelijk belicht|trans-title=Born from a storm; The earliest history of Amsterdam from an archaeological and landscape perspective.|url=https://www.theobakker.net/pdf/TX_Gawronski2017JbAmstelodamum_10.pdf|journal=Jaarboek van het Genootschap Amstelodamum|language=Dutch|location=Amsterdam|publisher=University of Amsterdam|volume=109|access-date=5 January 2021}}, pp. 62–63.</ref><ref>{{Cite journal|last=Kranendonk|first=P.|last2=Kluiving|first2=S. J.|last3=Troelstra|first3=S. R.|date=December 2015|title=Chrono- and archaeostratigraphy and development of the River Amstel: results of the North/South underground line excavations, Amsterdam, the Netherlands<!--sic-->|journal=Netherlands Journal of Geosciences|volume=94|issue=4|pages=333–352|bibcode=2015NJGeo..94..333K|doi=10.1017/njg.2014.38|issn=0016-7746|doi-access=free}}</ref>
==පිරිහුම හා නවීකරණය==
18 වන සියවසත් 19 වන සියවසේ මුල් හරියත් ඇම්ස්ටර්ඩෑමයේ ඉසුරුමත් බවේත් ලන්දේසි ජනරජයේත් පිරිහුම දිටි. ඊට ප්රධාන හෙය වූයේ එංගලන්තයෙන්, ප්රංශයෙන්, ප්රෂියාවෙන් හා රුසියාවෙන් ආ තරඟකාරිත්වයේ වැඩීම යි. ෆ්රැන්කෝ-ලන්දේසි යුදයත් ඇන්ග්ලෝ-ලන්දේසි යුදයත්, වෙසෙසින් සිව්වන ඇන්ග්ලෝ-ලන්දේසි යුදයත් (1780–1784) වනසකුරු බලපෑමක් කළේ යි.
19 වන සියවසේ දෙ වන බෑයේ දී, කෙමෙන් කම්යුරු නගරයක් බවට ඇම්ස්ටර්ඩෑමය පත් විය. දියමන්ති කම්යුරුව, නැව් තැනීම, ඇඳුම් පැළැඳුම් හා ඇංජිම් කම්හල් ද පසු වැ [[මෝටර් රථ|සරවු]] හා [[ගුවන්යානා|අහස්යානා]] හා නිපැයුම ද වැදැගත් නව ආර්ථික අංශ වූයේ යි.
1863 දී උතුරු මූදු ඇළ සඳහා ප්රමාණවත් සහයකුදු පාර්ලිමේන්තු අනුමැතියකුදු ලැබිණි. මූදේ යන විසල් දියදුම් නැව් සඳහා පිවිසුම වැඩිදියුණු කිරීමත් ඇම්ස්ටර්ඩෑමයේ තරඟකාරී තතුව වැඩිදියුණු කිරීමත් මෙහි අරමුණ විය. ඉඩම් ගොඩකිරීමත් කැණීම් කටයුතුත් සඳහා තැනැති අරමුදල් සැපැයිණි. මෙ ඇළ IJmuiden හරහා ඇම්ස්ටර්ඩෑමය උතුරු මුහුදට අමුණයි. පෙරදෙවු දෙක මැ සෙසු යුරෝපාවත් ඉන් ඔබට සෙසු ලොවත් සමඟ සන්නිවේදනය නළුයුරු (නාටකාකාර) ලෙස වැඩිදියුණු කළේ යි. ඒවා ආර්ථිකයට විසල් සවියක් දිනි.
== හැදියාව ==
15 වන සහ 16 වන සියවස්වල දී, ඇම්ස්ටර්ඩෑමයේ සංස්කෘතික දිවිය ප්රධාන විසින් උලෙළුවලින් යුත් වුයේ යි. 16 වන සියවසේ අග හරියේ දී, ඇම්ස්ටර්ඩෑමයේ Rederijkerskamer කවි හා [[නාට්ය|නළු]] හදාරන නන් මඬුලු අතර තරඟ සවිදහන් කළේ යි. ඇම්ස්ටර්ඩෑමයට 1638 දී එහි පළමු රඟහල ලැබිණි. 1642 තරම් මුල් කලැ දී මෙ රඟහලේ දී බැලේ සංදර්ශන පෙන්විණි. 18 වන සියවසේ දී ප්රංශ නළු ජනප්රිය විය. 1677 සිටැ ඇම්ස්ටර්ඩෑමයේ ඔපෙරා දැකියැ හැකි විය. පළමුවෙන් ඉතාලි සහ ප්රංශ ඔපෙරා පමණ ක් වූ නමුත් 18 වන සියවසෙහි ජරමන ඔපෙරා ද විය. 19 වන සියවසේ දී, ජනප්රිය සංස්කෘතිය ඇම්ස්ටර්ඩෑමයේ නෙස් පෙදෙස (ප්රධාන වශයෙන් vaudeville සහ මීයැසි හල) කේන්ද්රගත වැ විය. [[සම්භාව්යය සංගීතය|යුරෝපා කුලවත් මීයැසියේ]] වැදැගත් මැ දියුණුවක් වන මෙට්රොනෝමය 1812 දී ඩියෙට්රික් නිකොලස් වින්කෙල් විසින් බිහි කැරිණි. මෙ සියවස අවසනැ, Rijksmuseum හා Stedelijk ඇම්ස්ටර්ඩෑම කටුගෙය ඉදිකැරිණි. 1888 දී Concertgebouworkest ඇරැඹිණි. 20 වන සියවසත් සමඟ [[චිත්රපට|සලරුවත්]] [[ගුවන් විදුලිය|රෙදෙව්වත්]] [[රූපවාහිනිය|තෙලදසුනත්]] පැමිණි. Hilversum සහ Aalsmeer හි කලාගර තිබුණත් වැඩසටහන්කරණය කෙරෙහි ඇම්ස්ටර්ඩෑමයේ බලපෑම ඉතා සවිමති.[[දෙවන ලෝක යුද්ධය|දෙ වන ලෝ මහ යුදෙන්]] පසු, ජනප්රිය [[සංස්කෘතිය|හැදියාව]] ඇම්ස්ටර්ඩෑමයේ ප්රමුඛ සංස්කෘතික සංසිද්ධිය බවට පත්විය. ලොවැ පළමු නිල සමලිංගික විවාහය ඇම්ස්ටර්ඩෑමයේ පැවැත්විණි.
== මුලාශ්ර ==
{{Reflist}}
1s2wxuearezs94lcjp80qjmoqtp0qxm
පරිශීලක සාකච්ඡාව:Nimmzo
3
194328
790914
2026-05-19T17:30:12Z
Nimmzo
78995
Created empty Talk page to avoid red wikilink ("Talk" | contribs) in History
790914
wikitext
text/x-wiki
phoiac9h4m842xq45sp7s6u21eteeq1
හිමායා බණ්ඩාර
0
194329
790920
2026-05-19T18:36:07Z
Botempa
70735
Created by translating the page "[[:en:Special:Redirect/revision/1354998186|Himaya Bandara]]"
790920
wikitext
text/x-wiki
හිමායා බණ්ඩාර යනු ශ්රී ලංකාවේ ටෙලි නාට්ය ක්ෂේත්රයේ සහ චිත්රපට ක්ෂේත්රයේ ජනප්රිය නිළියක් මෙන්ම රූපවාහිනී නිවේදිකාවකි. ඇය වඩාත් ප්රසිද්ධියට පත්වූයේ "දෙවෙනි ඉනිම" ටෙලි නාට්යයේ "සොනාලි ටීචර්" ලෙස ඇය නිරූපණය කළ චරිතය හරහාය.<templatestyles src="Module:Infobox/styles.css"></templatestyles>{{තොරතුරුකොටුව පුද්ගලයා
| name = Himaya Bandara
| image =
| caption =
| birth_name = Anjali Himaya Bandara
| birth_date = {{Birth date and age|1990|1|13}}
| birth_place =
| citizenship = Sri Lankan
| occupation = Actress, television presenter
| years_active = 2010–present
| known_for = [[Deveni Inima]] (as Sonali Teacher)
| awards =
}}
== වෘත්තීය ජීවිතය ==
බණ්ඩාර [[ස්වර්ණවාහිනී|ස්වර්ණවාහිනියේ]] ''හද රන්දි පායා'' වැනි වැඩසටහන් සඳහා රූපවාහිනී සත්කාරකවරියක් ලෙස සිය වෘත්තීය ජීවිතය ආරම්භ කළාය. පසුව ඇය රංගනයට පිවිසි අතර ශ්රී ලාංකික ටෙලි නාට්යවල ඇයගේ රංගනයන් සඳහා සැලකිය යුතු පිළිගැනීමක් ලබා ගත්තාය. <ref>{{උපන්යාස වෙබ් |title=මම ආසම අපේ අම්මා හදන රූලං අලුවා කන්න - හිමායා බණ්ඩාර |url=https://www.saaravita.lk/latest_news/%E0%B6%B8%E0%B6%B8-%E0%B6%86%E0%B7%83%E0%B6%B8-%E0%B6%85%E0%B6%B4-%E0%B6%85%E0%B6%B8%E0%B6%B8-%E0%B7%84%E0%B6%AF%E0%B6%B1-%E0%B6%BB%E0%B6%BD-%E0%B6%85%E0%B6%BD%E0%B7%80-%E0%B6%9A%E0%B6%B1%E0%B6%B1-%E0%B7%84%E0%B6%B8%E0%B6%BA-%E0%B6%B6%E0%B6%AB%E0%B6%A9%E0%B6%BB/100-718227 |access-date=2026-05-19 |website=www.saaravita.lk |language=Sinhala}}</ref> <ref>{{උපන්යාස වෙබ් |title=ළමා චිත්රපටයකින් හමුවන හිමායා බණ්ඩාර {{!}}Saaravita.lk |url=https://www.saaravita.lk/latest_news/%E0%B7%85%E0%B6%B8-%E0%B6%A0%E0%B6%AD%E0%B6%BB%E0%B6%B4%E0%B6%A7%E0%B6%BA%E0%B6%9A%E0%B6%B1-%E0%B7%84%E0%B6%B8%E0%B7%80%E0%B6%B1-%E0%B7%84%E0%B6%B8%E0%B6%BA-%E0%B6%B6%E0%B6%AB%E0%B6%A9%E0%B6%BB/100-714281 |access-date=2026-05-19 |website=www.saaravita.lk}}</ref> ඇගේ වඩාත්ම කැපී පෙනෙන කෘතියට ''[[දෙවෙනි ඉනිම (ටෙලි නාට්යය)|දෙවෙනි ඉනිම]]'' සහ ''හදවතේ කතාව යන'' චිත්රපටවල චරිත ඇතුළත් වේ. <ref>{{උපන්යාස වෙබ් |title=“බොහොම පොඩි කාලෙකට අපි මේ ලෝකයට එන්නේ. ඒ නිසා ජීවිතය විඳින්න ඕනේ.” – හිමායා බණ්ඩාර (PHOTOS) - ගගන |url=https://gagana.lk/article/himaya-bandara-sensitive-1633110707 |access-date=2026-05-19 |website=Radio Gagana |language=si}}</ref> <ref>{{උපන්යාස වෙබ් |title=දෙවෙනි ඉනිමේ සොනාලි ටීචර් සුරූපී නිලි හිමායා බණ්ඩාර ඇයගේ උපන්දිනය සැමරුව හැටි (PHOTOS) - පුවත් |url=https://puwath.lk/article/himaya-bandara-dewani-inima-1642251057 |access-date=2026-05-19 |website=Puwath |language=si}}</ref> <ref>{{උපන්යාස වෙබ් |title=ගලෙන් ගලට උඩට නැංගේ පුදුම බයකින් - හිමායා බණ්ඩාර |url=https://www.deshaya.lk/article/51/%E0%B7%84%E0%B6%BB%E0%B6%B6%E0%B6%BB/18535/%E0%B6%9C%E0%B6%BD%E0%B7%99%E0%B6%B1%E0%B7%8A-%E0%B6%9C%E0%B6%BD%E0%B6%A7--%E0%B6%8B%E0%B6%A9%E0%B6%A7-%E0%B6%B1%E0%B7%90%E0%B6%82%E0%B6%9C%E0%B7%9A--%E0%B6%B4%E0%B7%94%E0%B6%AF%E0%B7%94%E0%B6%B8-%E0%B6%B6%E0%B6%BA%E0%B6%9A%E0%B7%92%E0%B6%B1%E0%B7%8A---%E0%B7%84%E0%B7%92%E0%B6%B8%E0%B7%8F%E0%B6%BA%E0%B7%8F-%E0%B6%B6%E0%B6%AB%E0%B7%8A%E0%B6%A9%E0%B7%8F%E0%B6%BB |access-date=2026-05-19 |website=www.deshaya.lk |language=en}}</ref> <ref>{{උපන්යාස වෙබ් |title=ක්ෂේත්රය ගැන කලකිරීමෙන් මම ඉන්නේ |url=https://www.lankadeepa.lk/latest_news/%E0%B6%9A%E0%B7%8A%E0%B7%82%E0%B7%9A%E0%B6%AD%E0%B7%8A%E2%80%8D%E0%B6%BB%E0%B6%BA-%E0%B6%9C%E0%B7%90%E0%B6%B1-%E0%B6%9A%E0%B6%BD%E0%B6%9A%E0%B7%92%E0%B6%BB%E0%B7%93%E0%B6%B8%E0%B7%99%E0%B6%B1%E0%B7%8A-%E0%B6%B8%E0%B6%B8-%E0%B6%89%E0%B6%B1%E0%B7%8A%E0%B6%B1%E0%B7%9A/1-405300 |access-date=2026-05-19 |website=www.lankadeepa.lk |language=en}}</ref> <ref>{{උපන්යාස වෙබ් |title=මං හැම වෙලාවෙම අලුත් වෙන කෙනෙක් |url=https://archives.sarasaviya.lk/2013/06/06/?fn=sa13060622 |access-date=2026-05-19 |website=archives.sarasaviya.lk}}</ref> <ref>{{උපන්යාස වෙබ් |title=ඒකාලේ හරියට මිනිස්සුන්ට රැවටුණා - හිමායා බණ්ඩාර |url=https://www.deshaya.lk/article/52/%E0%B7%84%E0%B6%AF%E0%B7%83%E0%B6%BB/20489/%E0%B6%92%E0%B6%9A%E0%B7%8F%E0%B6%BD%E0%B7%9A-%E0%B7%84%E0%B6%BB%E0%B7%92%E0%B6%BA%E0%B6%A7-%E0%B6%B8%E0%B7%92%E0%B6%B1%E0%B7%92%E0%B7%83%E0%B7%8A%E0%B7%83%E0%B7%94%E0%B6%B1%E0%B7%8A%E0%B6%A7-%E0%B6%BB%E0%B7%90%E0%B7%80%E0%B6%A7%E0%B7%94%E0%B6%AB%E0%B7%8F---%E0%B7%84%E0%B7%92%E0%B6%B8%E0%B7%8F%E0%B6%BA%E0%B7%8F-%E0%B6%B6%E0%B6%AB%E0%B7%8A%E0%B6%A9%E0%B7%8F%E0%B6%BB |access-date=2026-05-19 |website=www.deshaya.lk |language=en}}</ref>
ඇය ශ්රී ලාංකික චිත්රපටවල ද පෙනී සිට ඇති අතර, ඒ අතර ක්රියාදාම චිත්රපටයක් ''වන සූරයා වීරයා ද වේ.''
== රූපවාහිනී කතා මාලා ==
{| class="wikitable sortable"
!වර්ෂය
! ටෙලිනාට්යය
! භූමිකාව
! යොමුව.
|-
| 2017
| ''[[දෙවෙනි ඉනිම (ටෙලි නාට්යය)|දෙවෙනි ඉනිම]]''
| සොනාලි ටීචර්
|
|-
| 2024
| ''හදවතතේ කතාව''
| දුලන්යා ටීචර්
|
|}
== චිත්රපටකරණය ==
{| class="wikitable sortable"
!වර්ෂය
! චිත්රපටය
! භූමිකාව
! යොමුව.
|-
| 2019
| ''සම කුමාරු කතාව''
|
| <ref>{{උපන්යාස වෙබ් |title=‘Sama Kumaru’- Children’s movie with a Buddhist theme |url=http://www.sundaytimes.lk/190602/magazine/sama-kumaru-childrens-movie-with-a-buddhist-theme-351269.html |access-date=2026-05-19 |website=The Sunday Times Sri Lanka}}</ref>
|-
| 2024
| ''සූරය වීරය''
|
| <ref>{{උපන්යාස වෙබ් |last=ltd |first=Zelicade pvt |title=View Sooraya Weeraya full movie details online |url=https://mail.actor.lk/film/sooraya-weeraya |access-date=2026-05-19 |website=https://mail.actor.lk |language=en}}</ref>
|}
== ආශ්රිත ==
<templatestyles src="Reflist/styles.css" />{{ආශ්රලැයිස්තුව}}
* {{IMDb name|10096191|Himaya Bandara}}
* [https://www.facebook.com/himaya.bandara.official Himaya Bandara] on Facebook
* [https://www.instagram.com/himaya_bandara Himaya Bandara] on Instagram
* [https://www.tiktok.com/@himayabandara Himaya Bandara] on TikTok
[[ප්රවර්ගය:ජීවමාන ජනයා]]
[[ප්රවර්ගය:1988 උපත්]]
[[ප්රවර්ගය:Articles with hCards]]
85858rqdhignwcspcgciwtq2m0qgmt8
790922
790920
2026-05-19T18:44:14Z
Botempa
70735
/* */ තොරතුරු කොටුව Infobox සිංහලට පරිවර්තනය කර ලිපිය නිවැරදි කරන ලදී.
790922
wikitext
text/x-wiki
හිමායා බණ්ඩාර යනු ශ්රී ලංකාවේ ටෙලි නාට්ය ක්ෂේත්රයේ සහ චිත්රපට ක්ෂේත්රයේ ජනප්රිය නිළියක් මෙන්ම රූපවාහිනී නිවේදිකාවකි. ඇය වඩාත් ප්රසිද්ධියට පත්වූයේ "දෙවෙනි ඉනිම" ටෙලි නාට්යයේ "සොනාලි ටීචර්" ලෙස ඇය නිරූපණය කළ චරිතය හරහාය.<templatestyles src="Module:Infobox/styles.css"></templatestyles>{{තොරතුරුකොටුව පුද්ගලයා
| name = හිමායා බණ්ඩාර
| image =
| caption =
| birth_name = අංජලී හිමායා බණ්ඩාර
| birth_date = {{Birth date and age|1990|1|13}}
| birth_place =
| citizenship = ශ්රී ලාංකික
| occupation = නිළිය, රූපවාහිනී නිවේදිකා
| years_active = 2010–වර්තමානය
| known_for = [[දෙවෙනි ඉනිම]] (සොනාලෟ ටීචර් ලෙස)
| awards =
}}
== වෘත්තීය ජීවිතය ==
බණ්ඩාර [[ස්වර්ණවාහිනී|ස්වර්ණවාහිනියේ]] ''හද රන්දි පායා'' වැනි වැඩසටහන් සඳහා රූපවාහිනී සත්කාරකවරියක් ලෙස සිය වෘත්තීය ජීවිතය ආරම්භ කළාය. පසුව ඇය රංගනයට පිවිසි අතර ශ්රී ලාංකික ටෙලි නාට්යවල ඇයගේ රංගනයන් සඳහා සැලකිය යුතු පිළිගැනීමක් ලබා ගත්තාය. <ref>{{උපන්යාස වෙබ් |title=මම ආසම අපේ අම්මා හදන රූලං අලුවා කන්න - හිමායා බණ්ඩාර |url=https://www.saaravita.lk/latest_news/%E0%B6%B8%E0%B6%B8-%E0%B6%86%E0%B7%83%E0%B6%B8-%E0%B6%85%E0%B6%B4-%E0%B6%85%E0%B6%B8%E0%B6%B8-%E0%B7%84%E0%B6%AF%E0%B6%B1-%E0%B6%BB%E0%B6%BD-%E0%B6%85%E0%B6%BD%E0%B7%80-%E0%B6%9A%E0%B6%B1%E0%B6%B1-%E0%B7%84%E0%B6%B8%E0%B6%BA-%E0%B6%B6%E0%B6%AB%E0%B6%A9%E0%B6%BB/100-718227 |access-date=2026-05-19 |website=www.saaravita.lk |language=Sinhala}}</ref> <ref>{{උපන්යාස වෙබ් |title=ළමා චිත්රපටයකින් හමුවන හිමායා බණ්ඩාර {{!}}Saaravita.lk |url=https://www.saaravita.lk/latest_news/%E0%B7%85%E0%B6%B8-%E0%B6%A0%E0%B6%AD%E0%B6%BB%E0%B6%B4%E0%B6%A7%E0%B6%BA%E0%B6%9A%E0%B6%B1-%E0%B7%84%E0%B6%B8%E0%B7%80%E0%B6%B1-%E0%B7%84%E0%B6%B8%E0%B6%BA-%E0%B6%B6%E0%B6%AB%E0%B6%A9%E0%B6%BB/100-714281 |access-date=2026-05-19 |website=www.saaravita.lk}}</ref> ඇගේ වඩාත්ම කැපී පෙනෙන කෘතියට ''[[දෙවෙනි ඉනිම (ටෙලි නාට්යය)|දෙවෙනි ඉනිම]]'' සහ ''හදවතේ කතාව යන'' චිත්රපටවල චරිත ඇතුළත් වේ. <ref>{{උපන්යාස වෙබ් |title=“බොහොම පොඩි කාලෙකට අපි මේ ලෝකයට එන්නේ. ඒ නිසා ජීවිතය විඳින්න ඕනේ.” – හිමායා බණ්ඩාර (PHOTOS) - ගගන |url=https://gagana.lk/article/himaya-bandara-sensitive-1633110707 |access-date=2026-05-19 |website=Radio Gagana |language=si}}</ref> <ref>{{උපන්යාස වෙබ් |title=දෙවෙනි ඉනිමේ සොනාලි ටීචර් සුරූපී නිලි හිමායා බණ්ඩාර ඇයගේ උපන්දිනය සැමරුව හැටි (PHOTOS) - පුවත් |url=https://puwath.lk/article/himaya-bandara-dewani-inima-1642251057 |access-date=2026-05-19 |website=Puwath |language=si}}</ref> <ref>{{උපන්යාස වෙබ් |title=ගලෙන් ගලට උඩට නැංගේ පුදුම බයකින් - හිමායා බණ්ඩාර |url=https://www.deshaya.lk/article/51/%E0%B7%84%E0%B6%BB%E0%B6%B6%E0%B6%BB/18535/%E0%B6%9C%E0%B6%BD%E0%B7%99%E0%B6%B1%E0%B7%8A-%E0%B6%9C%E0%B6%BD%E0%B6%A7--%E0%B6%8B%E0%B6%A9%E0%B6%A7-%E0%B6%B1%E0%B7%90%E0%B6%82%E0%B6%9C%E0%B7%9A--%E0%B6%B4%E0%B7%94%E0%B6%AF%E0%B7%94%E0%B6%B8-%E0%B6%B6%E0%B6%BA%E0%B6%9A%E0%B7%92%E0%B6%B1%E0%B7%8A---%E0%B7%84%E0%B7%92%E0%B6%B8%E0%B7%8F%E0%B6%BA%E0%B7%8F-%E0%B6%B6%E0%B6%AB%E0%B7%8A%E0%B6%A9%E0%B7%8F%E0%B6%BB |access-date=2026-05-19 |website=www.deshaya.lk |language=en}}</ref> <ref>{{උපන්යාස වෙබ් |title=ක්ෂේත්රය ගැන කලකිරීමෙන් මම ඉන්නේ |url=https://www.lankadeepa.lk/latest_news/%E0%B6%9A%E0%B7%8A%E0%B7%82%E0%B7%9A%E0%B6%AD%E0%B7%8A%E2%80%8D%E0%B6%BB%E0%B6%BA-%E0%B6%9C%E0%B7%90%E0%B6%B1-%E0%B6%9A%E0%B6%BD%E0%B6%9A%E0%B7%92%E0%B6%BB%E0%B7%93%E0%B6%B8%E0%B7%99%E0%B6%B1%E0%B7%8A-%E0%B6%B8%E0%B6%B8-%E0%B6%89%E0%B6%B1%E0%B7%8A%E0%B6%B1%E0%B7%9A/1-405300 |access-date=2026-05-19 |website=www.lankadeepa.lk |language=en}}</ref> <ref>{{උපන්යාස වෙබ් |title=මං හැම වෙලාවෙම අලුත් වෙන කෙනෙක් |url=https://archives.sarasaviya.lk/2013/06/06/?fn=sa13060622 |access-date=2026-05-19 |website=archives.sarasaviya.lk}}</ref> <ref>{{උපන්යාස වෙබ් |title=ඒකාලේ හරියට මිනිස්සුන්ට රැවටුණා - හිමායා බණ්ඩාර |url=https://www.deshaya.lk/article/52/%E0%B7%84%E0%B6%AF%E0%B7%83%E0%B6%BB/20489/%E0%B6%92%E0%B6%9A%E0%B7%8F%E0%B6%BD%E0%B7%9A-%E0%B7%84%E0%B6%BB%E0%B7%92%E0%B6%BA%E0%B6%A7-%E0%B6%B8%E0%B7%92%E0%B6%B1%E0%B7%92%E0%B7%83%E0%B7%8A%E0%B7%83%E0%B7%94%E0%B6%B1%E0%B7%8A%E0%B6%A7-%E0%B6%BB%E0%B7%90%E0%B7%80%E0%B6%A7%E0%B7%94%E0%B6%AB%E0%B7%8F---%E0%B7%84%E0%B7%92%E0%B6%B8%E0%B7%8F%E0%B6%BA%E0%B7%8F-%E0%B6%B6%E0%B6%AB%E0%B7%8A%E0%B6%A9%E0%B7%8F%E0%B6%BB |access-date=2026-05-19 |website=www.deshaya.lk |language=en}}</ref>
ඇය ශ්රී ලාංකික චිත්රපටවල ද පෙනී සිට ඇති අතර, ඒ අතර ක්රියාදාම චිත්රපටයක් ''වන සූරයා වීරයා ද වේ.''
== රූපවාහිනී කතා මාලා ==
{| class="wikitable sortable"
!වර්ෂය
! ටෙලිනාට්යය
! භූමිකාව
! යොමුව.
|-
| 2017
| ''[[දෙවෙනි ඉනිම (ටෙලි නාට්යය)|දෙවෙනි ඉනිම]]''
| සොනාලි ටීචර්
|
|-
| 2024
| ''හදවතතේ කතාව''
| දුලන්යා ටීචර්
|
|}
== චිත්රපටකරණය ==
{| class="wikitable sortable"
!වර්ෂය
! චිත්රපටය
! භූමිකාව
! යොමුව.
|-
| 2019
| ''සම කුමාරු කතාව''
|
| <ref>{{උපන්යාස වෙබ් |title=‘Sama Kumaru’- Children’s movie with a Buddhist theme |url=http://www.sundaytimes.lk/190602/magazine/sama-kumaru-childrens-movie-with-a-buddhist-theme-351269.html |access-date=2026-05-19 |website=The Sunday Times Sri Lanka}}</ref>
|-
| 2024
| ''සූරය වීරය''
|
| <ref>{{උපන්යාස වෙබ් |last=ltd |first=Zelicade pvt |title=View Sooraya Weeraya full movie details online |url=https://mail.actor.lk/film/sooraya-weeraya |access-date=2026-05-19 |website=https://mail.actor.lk |language=en}}</ref>
|}
== ආශ්රිත ==
<templatestyles src="Reflist/styles.css" />{{ආශ්රලැයිස්තුව}}
* {{IMDb name|10096191|Himaya Bandara}}
* [https://www.facebook.com/himaya.bandara.official Himaya Bandara] on Facebook
* [https://www.instagram.com/himaya_bandara Himaya Bandara] on Instagram
* [https://www.tiktok.com/@himayabandara Himaya Bandara] on TikTok
[[ප්රවර්ගය:ජීවමාන ජනයා]]
[[ප්රවර්ගය:1988 උපත්]]
[[ප්රවර්ගය:Articles with hCards]]
hd7klivx4dp3ajdfui1zt5zrx9yf5qm
790924
790922
2026-05-19T18:55:57Z
~2026-30128-16
79031
fixed small
790924
wikitext
text/x-wiki
හිමායා බණ්ඩාර යනු ශ්රී ලංකාවේ ටෙලි නාට්ය ක්ෂේත්රයේ සහ චිත්රපට ක්ෂේත්රයේ ජනප්රිය නිළියක් මෙන්ම රූපවාහිනී නිවේදිකාවකි. ඇය වඩාත් ප්රසිද්ධියට පත්වූයේ "දෙවෙනි ඉනිම" ටෙලි නාට්යයේ "සොනාලි ටීචර්" ලෙස ඇය නිරූපණය කළ චරිතය හරහාය.<templatestyles src="Module:Infobox/styles.css"></templatestyles>{{තොරතුරුකොටුව පුද්ගලයා
| name = හිමායා බණ්ඩාර
| image =
| caption =
| birth_name = අංජලී හිමායා බණ්ඩාර
| birth_date = {{Birth date and age|1990|1|13}}
| birth_place =
| citizenship = ශ්රී ලාංකික
| occupation = නිළිය, රූපවාහිනී නිවේදිකා
| years_active = 2010–වර්තමානය
| known_for = [[දෙවෙනි ඉනිම]] (සොනාලි ටීචර් ලෙස)
| awards =
}}
== වෘත්තීය ජීවිතය ==
බණ්ඩාර [[ස්වර්ණවාහිනී|ස්වර්ණවාහිනියේ]] ''හද රන්දි පායා'' වැනි වැඩසටහන් සඳහා රූපවාහිනී සත්කාරකවරියක් ලෙස සිය වෘත්තීය ජීවිතය ආරම්භ කළාය. පසුව ඇය රංගනයට පිවිසි අතර ශ්රී ලාංකික ටෙලි නාට්යවල ඇයගේ රංගනයන් සඳහා සැලකිය යුතු පිළිගැනීමක් ලබා ගත්තාය. <ref>{{උපන්යාස වෙබ් |title=මම ආසම අපේ අම්මා හදන රූලං අලුවා කන්න - හිමායා බණ්ඩාර |url=https://www.saaravita.lk/latest_news/%E0%B6%B8%E0%B6%B8-%E0%B6%86%E0%B7%83%E0%B6%B8-%E0%B6%85%E0%B6%B4-%E0%B6%85%E0%B6%B8%E0%B6%B8-%E0%B7%84%E0%B6%AF%E0%B6%B1-%E0%B6%BB%E0%B6%BD-%E0%B6%85%E0%B6%BD%E0%B7%80-%E0%B6%9A%E0%B6%B1%E0%B6%B1-%E0%B7%84%E0%B6%B8%E0%B6%BA-%E0%B6%B6%E0%B6%AB%E0%B6%A9%E0%B6%BB/100-718227 |access-date=2026-05-19 |website=www.saaravita.lk |language=Sinhala}}</ref> <ref>{{උපන්යාස වෙබ් |title=ළමා චිත්රපටයකින් හමුවන හිමායා බණ්ඩාර {{!}}Saaravita.lk |url=https://www.saaravita.lk/latest_news/%E0%B7%85%E0%B6%B8-%E0%B6%A0%E0%B6%AD%E0%B6%BB%E0%B6%B4%E0%B6%A7%E0%B6%BA%E0%B6%9A%E0%B6%B1-%E0%B7%84%E0%B6%B8%E0%B7%80%E0%B6%B1-%E0%B7%84%E0%B6%B8%E0%B6%BA-%E0%B6%B6%E0%B6%AB%E0%B6%A9%E0%B6%BB/100-714281 |access-date=2026-05-19 |website=www.saaravita.lk}}</ref> ඇගේ වඩාත්ම කැපී පෙනෙන කෘතියට ''[[දෙවෙනි ඉනිම (ටෙලි නාට්යය)|දෙවෙනි ඉනිම]]'' සහ ''හදවතේ කතාව යන'' චිත්රපටවල චරිත ඇතුළත් වේ. <ref>{{උපන්යාස වෙබ් |title=“බොහොම පොඩි කාලෙකට අපි මේ ලෝකයට එන්නේ. ඒ නිසා ජීවිතය විඳින්න ඕනේ.” – හිමායා බණ්ඩාර (PHOTOS) - ගගන |url=https://gagana.lk/article/himaya-bandara-sensitive-1633110707 |access-date=2026-05-19 |website=Radio Gagana |language=si}}</ref> <ref>{{උපන්යාස වෙබ් |title=දෙවෙනි ඉනිමේ සොනාලි ටීචර් සුරූපී නිලි හිමායා බණ්ඩාර ඇයගේ උපන්දිනය සැමරුව හැටි (PHOTOS) - පුවත් |url=https://puwath.lk/article/himaya-bandara-dewani-inima-1642251057 |access-date=2026-05-19 |website=Puwath |language=si}}</ref> <ref>{{උපන්යාස වෙබ් |title=ගලෙන් ගලට උඩට නැංගේ පුදුම බයකින් - හිමායා බණ්ඩාර |url=https://www.deshaya.lk/article/51/%E0%B7%84%E0%B6%BB%E0%B6%B6%E0%B6%BB/18535/%E0%B6%9C%E0%B6%BD%E0%B7%99%E0%B6%B1%E0%B7%8A-%E0%B6%9C%E0%B6%BD%E0%B6%A7--%E0%B6%8B%E0%B6%A9%E0%B6%A7-%E0%B6%B1%E0%B7%90%E0%B6%82%E0%B6%9C%E0%B7%9A--%E0%B6%B4%E0%B7%94%E0%B6%AF%E0%B7%94%E0%B6%B8-%E0%B6%B6%E0%B6%BA%E0%B6%9A%E0%B7%92%E0%B6%B1%E0%B7%8A---%E0%B7%84%E0%B7%92%E0%B6%B8%E0%B7%8F%E0%B6%BA%E0%B7%8F-%E0%B6%B6%E0%B6%AB%E0%B7%8A%E0%B6%A9%E0%B7%8F%E0%B6%BB |access-date=2026-05-19 |website=www.deshaya.lk |language=en}}</ref> <ref>{{උපන්යාස වෙබ් |title=ක්ෂේත්රය ගැන කලකිරීමෙන් මම ඉන්නේ |url=https://www.lankadeepa.lk/latest_news/%E0%B6%9A%E0%B7%8A%E0%B7%82%E0%B7%9A%E0%B6%AD%E0%B7%8A%E2%80%8D%E0%B6%BB%E0%B6%BA-%E0%B6%9C%E0%B7%90%E0%B6%B1-%E0%B6%9A%E0%B6%BD%E0%B6%9A%E0%B7%92%E0%B6%BB%E0%B7%93%E0%B6%B8%E0%B7%99%E0%B6%B1%E0%B7%8A-%E0%B6%B8%E0%B6%B8-%E0%B6%89%E0%B6%B1%E0%B7%8A%E0%B6%B1%E0%B7%9A/1-405300 |access-date=2026-05-19 |website=www.lankadeepa.lk |language=en}}</ref> <ref>{{උපන්යාස වෙබ් |title=මං හැම වෙලාවෙම අලුත් වෙන කෙනෙක් |url=https://archives.sarasaviya.lk/2013/06/06/?fn=sa13060622 |access-date=2026-05-19 |website=archives.sarasaviya.lk}}</ref> <ref>{{උපන්යාස වෙබ් |title=ඒකාලේ හරියට මිනිස්සුන්ට රැවටුණා - හිමායා බණ්ඩාර |url=https://www.deshaya.lk/article/52/%E0%B7%84%E0%B6%AF%E0%B7%83%E0%B6%BB/20489/%E0%B6%92%E0%B6%9A%E0%B7%8F%E0%B6%BD%E0%B7%9A-%E0%B7%84%E0%B6%BB%E0%B7%92%E0%B6%BA%E0%B6%A7-%E0%B6%B8%E0%B7%92%E0%B6%B1%E0%B7%92%E0%B7%83%E0%B7%8A%E0%B7%83%E0%B7%94%E0%B6%B1%E0%B7%8A%E0%B6%A7-%E0%B6%BB%E0%B7%90%E0%B7%80%E0%B6%A7%E0%B7%94%E0%B6%AB%E0%B7%8F---%E0%B7%84%E0%B7%92%E0%B6%B8%E0%B7%8F%E0%B6%BA%E0%B7%8F-%E0%B6%B6%E0%B6%AB%E0%B7%8A%E0%B6%A9%E0%B7%8F%E0%B6%BB |access-date=2026-05-19 |website=www.deshaya.lk |language=en}}</ref>
ඇය ශ්රී ලාංකික චිත්රපටවල ද පෙනී සිට ඇති අතර, ඒ අතර ක්රියාදාම චිත්රපටයක් ''වන සූරයා වීරයා ද වේ.''
== රූපවාහිනී කතා මාලා ==
{| class="wikitable sortable"
!වර්ෂය
! ටෙලිනාට්යය
! භූමිකාව
! යොමුව.
|-
| 2017
| ''[[දෙවෙනි ඉනිම (ටෙලි නාට්යය)|දෙවෙනි ඉනිම]]''
| සොනාලි ටීචර්
|
|-
| 2024
| ''හදවතතේ කතාව''
| දුලන්යා ටීචර්
|
|}
== චිත්රපටකරණය ==
{| class="wikitable sortable"
!වර්ෂය
! චිත්රපටය
! භූමිකාව
! යොමුව.
|-
| 2019
| ''සම කුමාරු කතාව''
|
| <ref>{{උපන්යාස වෙබ් |title=‘Sama Kumaru’- Children’s movie with a Buddhist theme |url=http://www.sundaytimes.lk/190602/magazine/sama-kumaru-childrens-movie-with-a-buddhist-theme-351269.html |access-date=2026-05-19 |website=The Sunday Times Sri Lanka}}</ref>
|-
| 2024
| ''සූරය වීරය''
|
| <ref>{{උපන්යාස වෙබ් |last=ltd |first=Zelicade pvt |title=View Sooraya Weeraya full movie details online |url=https://mail.actor.lk/film/sooraya-weeraya |access-date=2026-05-19 |website=https://mail.actor.lk |language=en}}</ref>
|}
== ආශ්රිත ==
<templatestyles src="Reflist/styles.css" />{{ආශ්රලැයිස්තුව}}
* {{IMDb name|10096191|Himaya Bandara}}
* [https://www.facebook.com/himaya.bandara.official Himaya Bandara] on Facebook
* [https://www.instagram.com/himaya_bandara Himaya Bandara] on Instagram
* [https://www.tiktok.com/@himayabandara Himaya Bandara] on TikTok
[[ප්රවර්ගය:ජීවමාන ජනයා]]
[[ප්රවර්ගය:1988 උපත්]]
[[ප්රවර්ගය:Articles with hCards]]
qpwhr0w9tapplbf08byzjkv2mmwunpx
සාකච්ඡාව:මිලිටරි
1
194330
790935
2026-05-20T03:41:06Z
Lee
85
'{{Talk header}}' යොදමින් නව පිටුවක් තනන ලදි
790935
wikitext
text/x-wiki
{{Talk header}}
6ujz0t3lkt6jsf7d1r360l6l7wj3njb
සැකිල්ල:Military and war
10
194331
790943
2026-05-20T03:45:05Z
Lee
85
Lee විසින් [[සැකිල්ල:Military and war]] සිට [[සැකිල්ල:මිලිටරි සහ යුද්ධ]] වෙත පිටුව ගෙන යන ලදී
790943
wikitext
text/x-wiki
#යළියොමුව [[සැකිල්ල:මිලිටරි සහ යුද්ධ]]
3v6vu42jxpr1fx70pav8v9852nvifdj
සැකිල්ල:Military and war/doc
10
194332
790945
2026-05-20T03:45:05Z
Lee
85
Lee විසින් [[සැකිල්ල:Military and war/doc]] සිට [[සැකිල්ල:මිලිටරි සහ යුද්ධ/doc]] වෙත පිටුව ගෙන යන ලදී
790945
wikitext
text/x-wiki
#යළියොමුව [[සැකිල්ල:මිලිටරි සහ යුද්ධ/doc]]
4m44c6zrm5pqo7w9wt6e6urp6jmw9ou
කුළු හෝරාව
0
194333
790950
2026-05-20T05:07:23Z
WrdSrchSi
55524
Created by translating the page "[[:en:Special:Redirect/revision/1349826617|Rush hour]]"
790950
wikitext
text/x-wiki
'''කුළු හෝරාවක්''' හෙවත් '''කඩිනම් වේලාවක්''' ({{en|peak hour}} හෝ rush hour) යනු මාර්ගවල රිය තදබදයත් පොදු ප්රවාහනයේ තදබදයත් දවසේ වැඩිම වන කොටසෙකි. සැමැනියෙන්, සතියේ දිනක මෙය උදාසනැ එක් වරකුත් සවසැ එක් වරකුත් විසින් දෙ වරෙකි. බොහෝ අය සරන වේලාවන් මේවා යි. බොහෝ අය නිවසට යාමට රැකියාවෙන් හෝ පාසලින් හෝ නික්මුම බොහෝ විට කුළු හෝරාවේ වඩාත් සුලබ අවස්ථාව යි. මේ පදය බොහෝ විට පැයක් ඉක්මැ පවතින කුළු තදබද සමයකට යෙදේ.
මෙම පදය ඉපුළුල් යැ. නමුත් බොහෝ විට වෙසෙසින් තැනැති සරවු (පුද්ගලික [[මෝටර් රථ]]) ප්රවාහන ගමනාගමනය සඳහා යෙදේ. මාර්ගයක බොහෝ දෙනෙක් නොමැති නමුත් විශාල සරවු ප්රමාණයක් තිබෙන විට, මෙන් මැ ප්රමාණය සැමැනි වුවත් වෙයට යම් සරසක් ඇති විට පවා යෙදේ. රිය ගමනාගමනයට සමාන ව, දත්ත පැකැට්ටු පමාවන් සහ මන්දගාමී බෙදා හැරීම සිදු වන කුළු දත්ත දැලටි භාවිත සමයන් විස්තර කිරීමට '''Internet rush hour''' යන යෙදුම භාවිතා කෙරී ඇත.
qllfv4vvepke3asgdrftq7f12i96u4w