Wikipedia talk:Lua/Archive 11

Template:Image array in Spanish
Is there a way to get Template:Image array made for spanish wikipedia?Kaidros (talk) 00:09, 27 January 2022 (UTC)
 * In what way does it need to be made for spanish wikipedia? Just copying Template:Image array and Module:Image array to es:Template:Image array and es:Module:Image array should work, as the template does not appear to contain any translatable content. * Pppery * it has begun... 00:19, 27 January 2022 (UTC)
 * Thank youKaidros (talk) 02:29, 27 January 2022 (UTC)

Errors on List of Marvel Cinematic Universe films
List of Marvel Cinematic Universe films is currently getting four "Lua error: not enough memory" errors at the bottom of the article. Can someone with knowledge of Lua help investigate where the error is? I feel it might have something to do with the transclusions happening on the article, possibly from Marvel Cinematic Universe: Phase Four. Thanks. - Favre1fan93 (talk) 04:01, 14 February 2022 (UTC)
 * A clue is that previewing an edit to the article without changing anything shows Lua memory usage of 52,428,798/52,428,800 bytes, while previewing after deleting the 12 lines with #section wikitext shows 13,761,835/52,428,800 bytes. I don't think the #section would be contributing to the increase from 13MB to 52MB—something in the included wikitext is doing that. Another clue is that there is a massive amount of Wikidata use and I can't see a reason for it—that might be in the included wikitext.
 * Previewing an edit after replacing the article content with the #section lines, as shown below, gives Lua memory usage 37,592,486/52,428,800 bytes.


 * That's all I have time for now. Johnuniq (talk) 06:20, 14 February 2022 (UTC)
 * It likely could be the "Reception" section, pulling from   , all of which use Wikidata pulls to retrieve their Rotten Tomatoes scores and cite elements. - Favre1fan93 (talk) 12:52, 14 February 2022 (UTC)
 * Yes, that was my conclusion. The section called by { uses 15MB in preview at Marvel Cinematic Universe: Phase One. The expensive memory part seems to be, which adds 2-3MB for each call. This adds the edit wikidata icon to each reference, which isn't necesssary. The important  and  calls are relatively cheap. —  Jts1882 &#124; talk 14:44, 14 February 2022 (UTC)
 * I've given up on Wikidata—it's fragile and templates trying to use it are prone to break (although admittedly I haven't seen such breakage for a while), and it uses too many resources, and it has no effective method of monitoring or fixing vandalism. I would raise the issue at a noticeboard at Wikidata and ask if there is a low-cost method of achieving what is being done with RT data—it's something that needs to be fixed with a redesign. Or, perhaps just remove usage of that template. Johnuniq (talk) 01:53, 15 February 2022 (UTC)
 * I placed in . Labeled section transclusion apparently doesn't honor noinclude inside  so I changed it to #tag:ref in Marvel Cinematic Universe: Phase Three. That worked. List of Marvel Cinematic Universe films now renders fully with Lua memory usage 34,818,590/52,428,800 bytes. I think the list can do without Wikidata links but I haven't changed to #tag:ref in Phase One and Two so they still transclude the links. PrimeHunter (talk) 03:27, 15 February 2022 (UTC)
 * Good result, thanks. Johnuniq (talk) 04:08, 15 February 2022 (UTC)
 * Thank you all. if you don't get to the #tag:ref changes on the Phase One, Two, and Four articles, I can take care of those. - Favre1fan93 (talk) 04:26, 15 February 2022 (UTC)
 * The #tag:ref code is unknown to many editors and may confuse some tools and source searches so I wonder whether there is a better solution. PrimeHunter (talk) 04:44, 15 February 2022 (UTC)
 * Should the edit wikidata icon and link be included in the reference list? What is the purpose? It doesn't help verify the information. —  Jts1882 &#124; talk 07:52, 15 February 2022 (UTC)
 * because the data is coming from Wikidata, and isn't coded directly on the article, it was added in the event an editor was trying to update the score on the article, and realized that they couldn't do it here, that it had to be done at Wikidata. If that isn't foreseen as an issue of someone unfamiliar with Wikidata not knowing that editing can occur there, then the edit icon can be removed and that probably solves this whole thing. - Favre1fan93 (talk) 17:31, 15 February 2022 (UTC)
 * I decided to move the Wikidata edit icons outside the references, which is friendlier for the section transclusion and noinclude tags. An example can be seen with my edit at the Phase One article here. That should solve the original issues, as well as the issue PrimeHunter came across switching to the #tag:ref code. - Favre1fan93 (talk) 20:33, 16 February 2022 (UTC)
 * I made an change to Module:EditAtWikidata, which is responsible for the RT edit link. On the revision prior to the noinclusion of, Special:Diff/1071924802, the Lua memory usage would drop by half from 31 million to 14 million bytes. Edit request pending at Module talk:EditAtWikidata. Snævar (talk) 22:58, 17 February 2022 (UTC)

Tables
I am trying to understand tables in Lua. Please look at my simple example. I am expecting j to be the table {b,2} and I was expecting j[1] to be b. But the output is empty. &mdash; Martin (MSGJ · talk) 14:52, 23 February 2022 (UTC)


 * You need to set the letters as strings. So surround them with " or '. I'm also a bit surprised that the code ran without an error. Gonnym (talk) 15:03, 23 February 2022 (UTC)
 * The b you mentioned is an undefined variable, and it is nil. Lua does not raise errors for undefined vars. Please note the difference between variable name and string. --SolidBlock (talk) 15:10, 23 February 2022 (UTC)
 * Which is why it is always a good idea to require('Module:No globals').
 * —Trappist the monk (talk) 15:38, 23 February 2022 (UTC)
 * Thanks everyone! It was actually Trappist's comment that led me to solve the real problem I was having &mdash; Martin (MSGJ · talk) 17:04, 23 February 2022 (UTC)
 * Bear in mind that since the numbers are in quotes ("1", "2", ...), they are strings and will sort like strings so "10" is before "2". Johnuniq (talk) 23:35, 23 February 2022 (UTC)

Accessing template parameters
I have used the following code to access the first unnamed parameter from a template while also allowing direct use of #invoke local pframe = frame:getParent local input = frame.args[1] or pframe.args[1] Is this a good way to do it? &mdash; Martin (MSGJ · talk) 11:36, 24 February 2022 (UTC)
 * Consider Module:Arguments.
 * —Trappist the monk (talk) 13:31, 24 February 2022 (UTC)
 * Some of us can't get our heads around Module:Arguments which complicates simple work. Using Arguments works, after you decode the documentation, but your method is fine for most cases. See what function dumphtml does to get two arguments at Module:Dump. Johnuniq (talk) 23:35, 24 February 2022 (UTC)
 * Yes that looks straightforward, thanks! &mdash; Martin (MSGJ · talk) 13:04, 25 February 2022 (UTC)

Regex help
Could someone help with the regex for the following? I want to scrape the names of the articles from the wikicode, and ignore piped links, i.e. I settled on  which seems to work but I think there is probably a more efficient way. Thanks &mdash; Martin (MSGJ · talk) 11:44, 24 February 2022 (UTC)
 * Bukhtishu family -> Bukhtishu
 * Ja'far al-Sadiq -> Ja'far al-Sadiq
 * Maybe ? Not sure if   would be better.—  Jts1882 &#124; talk 13:24, 24 February 2022 (UTC)
 * I think I tried that one. The first capture was being too greedy and including the | as well. &mdash; Martin (MSGJ · talk) 14:54, 24 February 2022 (UTC)
 * The greediness was why I wondered if  would work. What about   for anything but the pipe? —  Jts1882 &#124; talk 17:08, 24 February 2022 (UTC)
 * You could try a regexp like .  With a [&#91;piped|link]],   matches and discards "piped|", then   captures "link".  If it's [&#91;unpiped]],   comes back empty and   captures "unpiped".  It isn't clever enough to handle piped text containing vertical bars such as C|T Group, nor File: links with captions etc.  Certes (talk) 01:05, 25 February 2022 (UTC)

Automatic watchlist generator
Is it possible to create a module that automatically generates a list of pages from those listed in User:WP 1.0 bot/Tables/Project/India (for example, one list for Good Low-importance; another for Featured Mid-importance etc.), so that we can then use Special:RelatedChanges to track the changes. Similarly, another page where the list of the accompanying talk pages is generated for the same reason. Thanks! ---CX Zoom(he/him) (let's talk&#124;contribs) 13:56, 25 February 2022 (UTC)


 * Alternatively, a module that takes in pages of a category, for example Category:FA-Class India articles of Mid-importance. Puts them all into a template like the one I created at User:CX Zoom/TestPage5 & thus, creates a related category dependent on the first one. See the template's usage & documentation at User:CX Zoom/TestPage8. This template automatically strips the talk part from the title of the page(s) if any. ---CX Zoom(he/him) (let's talk&#124;contribs) 06:32, 26 February 2022 (UTC)

You already have categories like Category:FA-Class India articles of Mid-importance, etc. &mdash; Martin (MSGJ · talk) 07:20, 26 February 2022 (UTC)
 * These categories only consist of the talk pages of the various articles. Not the content pages. As such, it's possible to track changes happening in those categorised talk pages but it's not possible to track changes in the actual content pages using Special:RelatedChanges. I want to have something to do just that. ---CX Zoom(he/him) (let's talk&#124;contribs) 08:27, 26 February 2022 (UTC)

I realise that I probably wasn't able to make my request clear, and I don't want to waste everyone's time. My request here is superceded by the request below. Thanks! ---CX Zoom(he/him) (let's talk&#124;contribs) 08:38, 26 February 2022 (UTC)

Categories such as Category:FA-Class India articles of Mid-importance only consist of the talk pages of the various articles. Not the content pages. As such, it's possible to track changes happening in those talk pages but it's not possible to track changes in the actual content pages using Special:RelatedChanges. I want to have something to do just that. For example, Talk:Sholay is a member of this category. When I use Special:RelatedChanges for this category, recent edits on Talk:Sholay show up, but it's not possible to track changes happening in Sholay without going to those articles one by one. ---CX Zoom(he/him) (let's talk&#124;contribs) 08:44, 26 February 2022 (UTC)


 * You are in the wrong forum. You would use JavaScript for that, not Lua. Snævar (talk) 18:03, 27 February 2022 (UTC)

Is there any module to create Wikipedia tables from Wikidata items?
Example: I want to create a table of books that has columns title, author, genre, description, date, all taken from Wikidata items. I would specify the type of statements (columns) only once, and specify the IDs of the specific books I want to be included on the table. It would create the table automatically, and I wouldn't need to mess with the Wikipedia table template.Iara Ai (talk) 19:42, 12 January 2022 (UTC)
 * I'm only just getting my head around the possibilities here. Are you aware of Category:Wikidata_tracking_categories? &mdash; Charles Stewart (talk) 23:47, 12 January 2022 (UTC)
 * please see Module:Wikidata table &mdash; Martin (MSGJ · talk) 11:33, 24 February 2022 (UTC)
 * @Iara Ai You could always write your own. I've no previous Lua coding experience but with the help of asking at this page, I managed to create Module:Wdtablerow/listed buildings to use in this article Listed buildings at the University of Leeds. Nthep (talk) 15:53, 24 February 2022 (UTC)
 * I think we should work together to create one module for this, so all editors can benefit from added features &mdash; Martin (MSGJ · talk) 10:50, 25 February 2022 (UTC)
 * a good idea. Nthep (talk) 13:48, 25 February 2022 (UTC)
 * yes I was just doing some research just in case something already existed. If nobody takes the lead for this, I'll look into making a module when time allows. Thanks for the reference.Iara Ai (talk) 17:30, 2 March 2022 (UTC)
 * You clearly didn't read our comments, because there are two already available! (I think one is bespoke for a particular purpose.) &mdash; Martin (MSGJ · talk) 20:58, 2 March 2022 (UTC)

Sorting with accents
Another question. I am using table.sort on Template:French cheeses and I was surprised to see that Époisses is sorted last. I would have expected it come after "E". Is that normal? &mdash; Martin (MSGJ · talk) 11:32, 24 February 2022 (UTC)
 * I assume it sorts on ASCII codes or other encoding. In ASCII, É is 201 so will come after all alphanumerics. —  Jts1882 &#124; talk 13:32, 24 February 2022 (UTC)
 * Yes, you're right. And all the lower case letters are sorted before the uppercase letters. So "z" comes before "A". Arghh! &mdash; Martin (MSGJ · talk) 10:32, 2 March 2022 (UTC)
 * Wikitext uses UTF-8 encoding and É is two bytes, hex C3 89. The C3 means É will sort after all ASCII characters. There are ugly workarounds that work (most of the time) for simple cases such as European accented letters, but they are horrific. Johnuniq (talk) 23:28, 24 February 2022 (UTC)
 * One workaround is to define a table of special characters and where they should be sorted, e.g.  at Module:Goalscorers (line 469). —  Jts1882 &#124; talk 11:04, 2 March 2022 (UTC)
 * In theory, a standard module implementing e.g. azify("Déjà") → "deja" might help. In practice, there are differing opinions on where to sort letters such as ä, even within one language. Certes (talk) 11:52, 2 March 2022 (UTC)

No_globals issue solving
Over at, I have reported an issue (re 'No globals'), and a /sandbox solution. A tech check would be welcome, before pushing it live. -DePiep (talk) 05:18, 12 April 2022 (UTC)
 * Solved. -DePiep (talk) 06:32, 13 April 2022 (UTC)

Error output on a module that should otherwise work
On my creative-venture wiki on Miraheze, I've recently set up a module called "Find", based on the "find" function at WP's Module:String. Minutes ago, I test-ran it through Special:ExpandTemplates with this sample code (and a couple of variants thereof):

On WP itself, this should give out "11" as the result. So far, however, these tests over on Miraheze output the error message "" (Although "_getParameters" isn't referenced anywhere else in this case.)

Sorry, only pinging here because 1) I'm pretty much inexperienced with Scribunto/Lua (being used so much to the old-school style of things with ParserFunctions) and 2) a bit of urgent help is needed. Can someone more qualified troubleshoot this module code and tell me what I missed?

--Slgrandson (How's my egg-throwing coleslaw?) 12:23, 17 April 2022 (UTC)
 * must be defined in you module somewhere or you will get that error. At Module:String, that function is defined at line 524 et seq.  Copy that into you module and see if that fixes your problem.
 * —Trappist the monk (talk) 12:30, 17 April 2022 (UTC)
 * Along with "_getBoolean"--which managed to do the trick. Thanks a dozen! --Slgrandson (How's my egg-throwing coleslaw?) 12:57, 17 April 2022 (UTC)

How do i find specific Module pages?
I was wondering if there was a way to find the module page to templates if they dont link to them directly? i wanted to improve Plantilla:Ficha de comida (spanish wiki) by translating some of the english (Template:Infobox food) but i cant seem to find the module page for it.Kaidros (talk) 04:58, 20 April 2022 (UTC)
 * One useful method is to preview an edit to a page where you replace the contents with a very simple example of using the template. At the bottom, you can view templates used on the previewed page. That includes what modules were called. It's probably es:Module:Ficha. Johnuniq (talk) 05:27, 20 April 2022 (UTC)

How to use a string read as tablename?
I have read a variable as string, say. Now I want that name to be used as a table id:. This produces an error (like "error input variable 1: table expected, got string"). How can I use that string as table-name in there? (note: the table name is known beforehand, from a limited list of five, so is declared as ). In code, essense lines: DePiep (talk) 06:20, 22 April 2022 (UTC)
 * Johnuniq (talk) 07:23, 22 April 2022 (UTC)
 * Hmm, I just read this again. Are you saying you want the name of the table to be determined when the program runs? You can't do that in Scribunto's Lua. You would need to have a series of if...elseif...end tests to work out which table to use. If you describe the problem a bit more I can provide an example. Johnuniq (talk) 07:26, 22 April 2022 (UTC)
 * Actually, line 5 should be using the input / replies unchanged OK
 * Actually, line 5 should be using the input / replies unchanged OK


 * -DePiep (talk) 07:38, 23 April 2022 (UTC)

As Johnuniq said, but to avoid if...elseif...end tests use a table of all five tables like in This returns "4; 5; 6; someValue1". I introduced "operate_on" for the case your sInput does not match any of the tables, but you probably do not need it. Ponor (talk) 08:41, 22 April 2022 (UTC)

if i understood the question (and the documentation) correctly, this can be achieved with _G['tFoo'], so the first example should work like so:

in general it is not a good practice to use globals. if you want a string-indexed table of tables, per the example above, i will only suggest to construct it in a more concise way than the example: one-time variables like the inside tables in the example are just noise. i think it's more readable and maintainable, like so: peace - קיפודנחש (aka kipod) (talk) 02:37, 23 April 2022 (UTC)
 * Using _G is interesting but it is simply a particular case of Ponor's example where _G is used instead of all_tables. Johnuniq (talk) 03:31, 23 April 2022 (UTC)
 * Thanks both. "determined when the program runs" explains it, and the workaround will gently solve it. I prefer not to use _G or more abstracts, as it is too exotic for me (now). btw, it is to handle this set. -DePiep (talk) 06:02, 23 April 2022 (UTC)

Recap

 * Recap; confusion/mistakes fixed:
 * Original post by DePiep: I have read a variable as string, say . Now I want that name to be used as a table id:  . This produces an error (like "error input variable 1: table expected, got string"). How can I use that string as table-name in there? (note: the table name is known beforehand, from a limited list of five, so is declared as  ).
 * Note by Johnuniq: read the name of the table to be determined when the program runs? You can't do that in Scribunto's Lua.
 * Workaround by Ponor (shortened here):
 * Workaround by Ponor (shortened here):


 * User: קיפודנחש notes about availability of.
 * DePiep (talk) 06:25, 24 April 2022 (UTC)

Authority control not recognising accented letters as letters
Please see Template talk:Authority control/Archive 13. We need some regex that will recognise accented letters are being letters. Thanks &mdash; Martin (MSGJ · talk) 15:18, 7 March 2022 (UTC)
 * Consider changing line 823 to
 * local idlen = mw.ustring.len (id)
 * Count unicode characters, not bytes.
 * —Trappist the monk (talk) 15:44, 7 March 2022 (UTC)

Lua Pattern matching help
From the following module call,

I would like to extract as given below.

Bapatla district (2022–) Prakasam district (1970–2022),

In general the following matches are required. 1)start has a value, with end value of 2022 2)a start value of 2022 and no end value 3)start has no value, but end value of 2022 3)Start has no value and end has no value I can get these cases individually as shown below.

case 2

 * with a different qid

Case 4

 * with a different qid

Can you help by giving simple mediawiki template calls to WikidataIB or a complete script to get these values with links and a comma separator, even if the district name has upto three words separate by space? Arjunaraoc (talk) 06:09, 16 April 2022 (UTC)


 * After some research I found wikidata to be a more powerful way to access data from wikidata and used the current parameter to get currently valid data item. Arjunaraoc (talk) 10:32, 2 May 2022 (UTC)

Lua object coding (like mw.html)
I'd like to start programming by object, like building mw.html. Can anyone mention some live modules with good, basic examples? (And more complicated ones maybe). -DePiep (talk) 11:16, 8 May 2022 (UTC)

Lua error with Taxonbar?
Can anyone see what the issue is with this taxonbar for ? When I type, I see:

Lua error: bad argument #1 to 'getEntityIdForTitle' (string expected, got nil).

Thanks! Not sure if I should be asking here or Template talk:Taxonbar so I'm asking both places but will respond in both places when the issue is solved. Umimmak (talk) 04:58, 25 February 2022 (UTC)
 * I don't know why it occurs, but the problem is that the following gives nil
 * and that makes Module:ResolveEntityId crash with the error shown. Johnuniq (talk) 07:01, 25 February 2022 (UTC)
 * Now that I've had a chance to look at Q4281852, the problem is obvious. That item has no entry for enwiki in the "Wikipedia" section near the bottom. Therefore the title at enwiki is nil, and the confusing error results. Module:ResolveEntityId should handle that more gracefully, or at least give an error indicating what the problem is. Hmm, I see Module talk:ResolveEntityId mentions errors in hundreds of articles. The error has temporarily gone away because a recent edit at Module:ResolveEntityId was reverted. Johnuniq (talk) 08:30, 25 February 2022 (UTC)
 * hrm… this didn’t use to be an issue. I’m not sure why there needs to be a Wikipedia article for me to get information from Wikidata; I’ve definitely found it useful to have access to the taxonbar when I’m working on an article in a sandbox or draftspace. … but at least it’s working now? Umimmak (talk) 08:31, 25 February 2022 (UTC)
 * I was reporting the situation from the point of the module: the "obvious" in my comment was referring to how the code in Module:ResolveEntityId would obviously give that error given that there is no enwiki article for that item. However, the code with that problem has been reverted, so yes, it's working now. I'm sure that if the module is updated again there will be some fix. Johnuniq (talk) 08:36, 25 February 2022 (UTC)
 * I was reporting the situation from the point of the module: the "obvious" in my comment was referring to how the code in Module:ResolveEntityId would obviously give that error given that there is no enwiki article for that item. However, the code with that problem has been reverted, so yes, it's working now. I'm sure that if the module is updated again there will be some fix. Johnuniq (talk) 08:36, 25 February 2022 (UTC)

This was caused by a recent edit to Module:ResolveEntityId which I have just reverted &mdash; Martin (MSGJ · talk) 08:37, 25 February 2022 (UTC)

PAGE ]]) 00:16, 26 February 2022 (UTC)
 * I think I resolved the issue at Module:ResolveEntityId/sandbox. Please test out taxonbar/sandbox and let me know. --Ahecht ([[User talk:Ahecht|TALK
 * There is no wikipedia article (yet) for Gea africana and yields:


 * Looks good to me. Umimmak (talk) 00:23, 26 February 2022 (UTC)

Code for regex support
As I type, I'm planning to add real regex support for my creative-venture wiki's "Find" module, an example being:

→ 1

How does one deal with the final part Lua-wise? (Again, keep in mind I have little experience with Scribunto/Lua.) --Slgrandson (How's my egg-throwing coleslaw?) 13:54, 13 May 2022 (UTC)
 * Lua does not do regex. Lua does patterns.  There is a lot of similarity but common regex stuff like   is not supported.  You might look at Module:String for finding something in a string using lua patterns.
 * —Trappist the monk (talk) 14:04, 13 May 2022 (UTC)
 * iiuc, they are talking about their own wiki.
 * @Slgrandson: i think you should ask this on - there must be a way to add a library to scribuntu. personally, i would look for the sources of the "ustring" library, which adds unicode support to scribuntu, and follow their example (TBH, i did not verify, but i assume this lib is written in C).
 * you may want to expand this lib instead of creating a new one, e.g. add mw.ustring.regex function(s) (once you add "true" regex, you may be tempted to add "rmatch, rgsub etc.), and have your module simply pipe this functionality so it's usable by templates.
 * you may also look at doing it purely in lua - i imagine this will be very inefficient, but maybe you don't care about performance - see e.g https://gist.github.com/luiseduardohd/10668729
 * as a side, "real regex" is not as cut and dried as one might imagine, and some tools and libraries discriminate between, e.g., "perl regex", "pure regex", and whatnot. i remember JS regex was missing some features for a long time, specifically "negative lookbehind", which gave the few who really needed it no end of pain - this one was rectified a while ago).
 * peace.  קיפודנחש (aka kipod) (talk) 16:12, 13 May 2022 (UTC)
 * Incidentally: in my regex, the parameters  and   return "t" not "1" -- as I expected.
 * My thoughts: the requested Lua Module:regex could translate (=string change) Regex-code into pattern-code, by replacing regex escape "\" with pattern escaper "%" (first and foremost). Also it c/should check for unsupported code, (eg, "|" for or cannot be patternalised) and return an error. -DePiep (talk) 18:10, 13 May 2022 (UTC)
 * The question needs clarification regarding what "real regex" means. If something like Perl compatible regex is envisaged, forget it—it's not going to happen. If content with Lua's regex, see Module:String. Regarding Scribunto's ustring library, it is entirely written in Lua, including regex handling—an amazing accomplishment. Johnuniq (talk) 23:39, 13 May 2022 (UTC)
 * Source code: https://github.com/wikimedia/mediawiki-extensions-Scribunto/tree/master/includes/engines/LuaCommon/lualib/ustring. Although, on actual Wikipedia, the PHP version of Ustring (source code: https://github.com/wikimedia/mediawiki-extensions-Scribunto/blob/8b707a45a540ebdc7348a97904ffd65ad7bd02ad/includes/engines/LuaCommon/UstringLibrary.php) for performance reasons. Nor is real regex hopeless as Johnuniq describes it, given the pure-Lua implementation that Kipod linked above. Way back in 2016, a since-banned user said that namely that someone will write Module:RegEx as an argument that the developers denying modules programmers a real regex library was counterproductive; perhaps it's time to validate that hypothetical and repeat the circumstances that lead to the installation of Scribunto in the first place . * Pppery * it has begun...  00:14, 14 May 2022 (UTC)

My point was that it should be pretty straightforward for a non-wikimedia wiki to add "true" regex support. I stand corrected regarding ustring implementation, but this only makes it even easier: use the php implementation, and figure out how to hook one or few more functions, which can be implemented as a shim piping inbuilt php regex. For wikimedia wikis, we should limit ourselves to lua pattern matching, and jot this down as "regex envy" which won't be satisfied. Peace - קיפודנחש (aka kipod) (talk) 14:52, 14 May 2022 (UTC)

Could Lua be used to make these templates more efficient?
And perhaps combine them without making the combined template too bulky? Please see the discussion here. Thanks for any help! ··· 日本穣 ·  投稿  · Talk to Nihonjoe ·  Join WP Japan ! 17:29, 27 June 2022 (UTC)
 * Anyone? ··· 日本穣 ·  投稿  · Talk to Nihonjoe ·  Join WP Japan ! 19:49, 1 July 2022 (UTC)

Changing flag icon formats from .svg.png and .png to .svg
Is there anyway to change formats of flag icons from .png and .svg.png to .svg if possible? Any specific code or module? Let me know. FireDragonValo (talk) 19:12, 13 May 2022 (UTC) PAGE ]]) 13:35, 29 July 2022 (UTC)
 * What are you trying to fix? A file cannot be simply converted between formats using Lua modules. NguoiDungKhongDinhDanh 20:12, 13 May 2022 (UTC)
 * There are online converters though (e.g.); perhaps not a Lua module, but a script could semi-automate that (as in adding a 'convert to svg' link next to png images on the page, and maybe even kick-start the upload process, pre-filling the upload form with the details of the converted img). — Guarapiranga ☎ 00:47, 29 July 2022 (UTC)
 * @Guarapiranga Have you actually tried those converters? They do a terrible job, and you end up with something that looks like it was drawn by a 3-year-old. --Ahecht ([[User talk:Ahecht|<span style="color:#FFF;background:#04A;display:inline-block;padding:1px;vertical-align:-.3em;font:bold 50%/1 sans-serif;text-align:center">TALK
 * I did use one; only once, and can't remember which. — Guarapiranga ☎ 22:49, 30 July 2022 (UTC)
 * I did use one; only once, and can't remember which. — Guarapiranga ☎ 22:49, 30 July 2022 (UTC)

Loops, variables and tables
I have a number of variables, let's say: v1, v2, v3 ... v10, which I want to perform the same set of operations on relating to a wikitable and then add each to a table. Now I could write Is there a way of using a function that will take the variable root name v, add an integer and pass that back so in a for...next loop I can use to replace all the table.insert lines? Nthep (talk) 15:38, 20 June 2022 (UTC)
 * If it has global scope then the variable can be addressed as, but should you be using an array   instead of variables  ? Certes (talk) 17:55, 20 June 2022 (UTC)
 * We should see the example you are working on as better procedures might be suggested. However, something like the following would answer the question.

PAGE ]]) 13:57, 21 June 2022 (UTC)
 * Johnuniq (talk) 23:24, 20 June 2022 (UTC)
 * Thanks. I don't have an example as yet but what I am considering is to create a template to create tables similar to the squad lists at 1936–37 Challenge Cup but with a couple more fields dealing with numbers. TBH it is probably solvable using #switch etc but i find LUA easier to understand than expression syntax. What complicates it are things to do with the numbers are also the position names which differ depending on where in the world you are. So my thought was to take each position associate it with 2 names and 2 numbers and create a table row on that. So each row would have 5 parameters, position, home player, home number, away player and away number, then just loop through the required number of rows. Nthep (talk) 08:43, 21 June 2022 (UTC)
 * When you're ready, consider posting sample input and wanted output, keeping it very simple and short. Then there could be ideas on how to achieve that. Johnuniq (talk) 09:02, 21 June 2022 (UTC)
 * That sounds like a case where you want to be using tables, not numbered variables. If I were doing it, I would have the input be something like and then read that into a table:
 * You would probably want a little more data validation than that, but in essence that will create a table containing numbered rows and named columns with the input. You can then use  to iterate over the rows in your table and call out each column by name, e.g.  . --Ahecht ([[User talk:Ahecht|<span style="color:#FFF;background:#04A;display:inline-block;padding:1px;vertical-align:-.3em;font:bold 50%/1 sans-serif;text-align:center">TALK
 * You would probably want a little more data validation than that, but in essence that will create a table containing numbered rows and named columns with the input. You can then use  to iterate over the rows in your table and call out each column by name, e.g.  . --Ahecht ([[User talk:Ahecht|<span style="color:#FFF;background:#04A;display:inline-block;padding:1px;vertical-align:-.3em;font:bold 50%/1 sans-serif;text-align:center">TALK
 * Thanks but I can't get this to work. You can see what I'm trying to achieve at Module:Rugby league match squad/sandbox. User:Nthep/sandbox10 is the page I'm calling it from. Nthep (talk) 22:04, 5 July 2022 (UTC)

Regardless of the specific question asked, I'd like to comment that having a set of variables named v1, v2, v3...v11 is usually not a good practice (this was very common when the leading programming language was fortran 4, thankfully those days are gone). Variables ideally have meaningful names, which indicate what do their values mean. Typically, vX like in the example all mean the same thing (and should better have more meaningful name than "v"), maybe at different data points. If this is the case, it's usually preferable to have one var, of type "table" to hold the values, indexed by some identification of the data point - can be 1,2,3 or 'china', 'russia', 'usa', or whatever.

Peace - קיפודנחש (aka kipod) (talk) 18:29, 31 July 2022 (UTC)


 * Mnemonic, we used to call'em back in the day. — Guarapiranga ☎ 01:13, 1 August 2022 (UTC)

Lua error / running scripts expired - Norodom Sihamoni page
Hello Team, may I please seek team's technical expertise and assistance. King Norodom Sihamoni's wikipedia page is experiencing this error in the references section, with error messages, "The time allocated for running scripts has expired. The time allocated for running scripts has expired. The time allocated for running scripts has expired.The time allocated for running scripts has expired", "The time allocated for running scripts has expired", " Lua error in Module:Citation/CS1/Date_validation at line 946: attempt to index field 'inv_local_long' (a nil value)." On the wikipedia app, the references appear fine, but on desktop version, it appears all strange. I have no idea how to fix it as Im not a technical person :( May I please seek support on this issue so this error is all remedied or will it be auto-remedied? Thanks team. Contributorthewise (talk) 13:22, 1 August 2022 (UTC)

Update 13:23 - oh wow, looks like it all fixed ? Not sure who did the fix - but thank you so much!! — Preceding unsigned comment added by Contributorthewise (talk • contribs) 13:24, 1 August 2022 (UTC)

Extension of Graph:Chart for step function?
I didn't find a possiblity to create a true step function plot with the Template:Graph:Chart.

It is only possible to mimic it by a line plot with steep increases, but that graph has (almost) vertical lines that look "non-mathematican":

Or with his complex workaround:

Myosci (talk) 08:35, 13 August 2022 (UTC)

well, you don't have to twist the values (1.99 instead of 2). it's legit to repeat x values for line graph.

note that i did use one "perverted" x value, for the first data point (1.00001). the reason for this is that the X axis legends behave a bit differently when all values are integers (see below). if any of the data points has non-integer X value, this perversion is not required.

peace - קיפודנחש (aka kipod) (talk) 00:01, 14 August 2022 (UTC)

Chinese date conversion
Does Lua have a library that allow for conversion of dates such that one can enter 2024-01-01 (Gregorian New Year) and receive 2024-02-10 (Chinese New Year)? This is a moveable date based on the lunar cycle. -- Green  C  16:10, 24 August 2022 (UTC)


 * did you look at mw.language:formatDate ?
 * peace קיפודנחש (aka kipod) (talk) 16:28, 24 August 2022 (UTC)
 * I presume that you meant to link to mw.language:formatDate rather than .    uses the same formatting (and so likely is the same code as) the #time parser function.
 * —Trappist the monk (talk) 16:36, 24 August 2022 (UTC)
 * If the #time parser function doesn't have Chinese date conversions (it doesn't) then I doubt that MediaWiki has a separate Lua implementation of such a library. You might search module space; mayhaps someone has written something that will suit or that can be adapted.  You might start with this search.
 * —Trappist the monk (talk) 16:36, 24 August 2022 (UTC)
 * You might also pose this question at zh:Wikipedia talk:Lua.
 * —Trappist the monk (talk) 16:39, 24 August 2022 (UTC)
 * I don't think there is such a library at Wikipedia. The navbox at the bottom of age attempts to show all relevant functions but it's not there. On the other hand, I seem to recall a template like this being deleted as unused. Searching finds Template:New Year's Eve (created February 2015, deleted January 2021). The creator is no longer active. I have no idea what this does, but the wikitext for the template was
 * Johnuniq (talk) 23:57, 24 August 2022 (UTC)
 * Johnuniq (talk) 23:57, 24 August 2022 (UTC)

WP:USRANK 2.0
So I decided to upgrade WP:USRANK, and again bit more than I could chew (who remembers this adventure a year ago?). I thought it would be interesting to bring out data scripters had already documented inside the infobox user script on their scripts' help page (like skins and browsers compatibility, status of development, etc.). So I endeavoured to revamp and overhaul the module:user scripts table (which was the outcome from last year's debacle) in its sandbox. It started to work (preview this version against my sandbox, for instance), until... I flew too high, and MW's Lua memory constraints melted my wings. If you care to look at the code, you'll see I'm fumbling in the dark side of Lua; I'm sure there must be smarter ways of declaring the variables and writing the subroutines. Are there? Cheers. <span id="Guarapiranga:1655359055861:Wikipedia_talkFTTCLNLua" class="FTTCmt">— Guarapiranga ☎ 05:57, 16 June 2022 (UTC)

Using a Module:Wikidata function in Lua
I would like to know how to translate the following line into a Lua command (feel free to refer me to a better method to get the correct data, if this module is inefficient):

Animal lover &#124;666&#124; 10:51, 19 September 2022 (UTC)
 * Does this do what you want?
 * If you are going to use more than this one function there may be better ways of implementing this.
 * —Trappist the monk (talk) 16:39, 19 September 2022 (UTC)
 * I only need to use it once, which I assign to a variable, if blank replace with a different value, and make a single use of this variable. In fact, the bigger context is: . Animal lover &#124;666&#124; 19:20, 19 September 2022 (UTC)
 * Using  to invoke a Lua module is inefficient, use   instead. However,   is essentially just doing , which is much slower than the proper way to get the label:  . See the mw.wikibase docs for more useful Lua functions. Dexxor (talk) 06:43, 20 September 2022 (UTC)
 * Using  to invoke a Lua module is inefficient, use   instead. However,   is essentially just doing , which is much slower than the proper way to get the label:  . See the mw.wikibase docs for more useful Lua functions. Dexxor (talk) 06:43, 20 September 2022 (UTC)

Generating unique IDs
Here is the requirement: some template needs to assign ID attribute (e.g., in order to use mw-customtoggle-<unique-suffix>). Now, this template might appear multiple times in a page, and each one should have a unique ID (for practical reasons, and in order to have valid HTML). Is there a sane way to ensure that consecutive calls (from different invocations) to the same code will return different results? for obvious reasons, having multiple elements with same ID is not only "invalid html", but also dysfunctional. Did anyone encounter similar challenge before? i hope someone can show me i am stupid, and there's safe and simple way to do it. thanks, peace - קיפודנחש (aka kipod) (talk) 17:45, 18 February 2022 (UTC)


 * Use  to get pseudorandom number and modify it for the id. — <span style="font-family:Arial;background:#d6ffe6;border:solid 1px;border-radius:5px;box-shadow:darkcyan 0px 1px 1px;"> Jts1882 &#124; talk 18:00, 18 February 2022 (UTC)
 * thanks for the advice, but unfortunately, it's not really good: the issue revolves around seeding, Math.random reseeds on every call, which practically means it's not "pseudo random". if i could guarantee that each call will be executed in a different timeslice, it would work, but even then, the "pseudo random" is just a screen of smoke, and i could just as well use directly os.clock modulo something.
 * by reseeding every time, random loses its randomness. calling mw.math.random directly also does not work - when not seeded, it always begins at the same spot. to see what i mean, visit User:קיפודנחש/sandbox: i created a tiny Module:Testrand to demonstrate how consecutive calls to math._random can return the same value (when the clock did not tick between calls). this happens because each call re-seeds, using the clock, plus some slow moving counters.
 * admittedly, the parser is (currently) slow enough, such that on consecutive invocations the clock is "guaranteed" to move, but this approach is short-sighted.
 * allow me bore you with "old-timer" story (personal experience, but i searched and found a link which discusses it): somewhere in the 1980s and 90s, there was a popular development tool called Borland Pascal. now, this product was meant to run on ms-dos, IOW, with no operating system whatsoever for anything other than file access.
 * the lack of OS created a need for a "delay" library function (e.g., when you wanted to operate some hardware, like UART and such).
 * BP implemented "delay" in a very naïve and straightforward way, which was reasonable then and would be crazy now: they ran some loop with junk code (or maybe even empty) N number of times, based on the parameter. to translate the parameter of delay in MS to the number of times the loop should run, a factor is needed, which depends on the speed of the machine.
 * so, as part of the initialization of the library, a "delay calibration" code was run: the loop was executed large number of times (~64K iirc), the RT clock was sampled before and after to determine the time it took, and divide 64K by the time to get the "delay factor" (so "delay" would execute the loop ms*factor times).
 * when computers became fast enough, the "delay calibration loop" started executing faster than the clock resolution, and started throwing "divide by zero" exception.
 * this happens only once, but unfortunately, this one time is during initialization, which basically meant that any program written in BP would fail to start on faster computers (at least, "fail to start reliably" - if you get lucky, your loop straddles a tick...). the sad part is the fact that it did not matter if you ever used or wanted to use "delay" - vast majority of programs never did, and programmers who did not deal with hardware were typically not even aware of this !@#$% delay, but the "sudden death" affected everyone anyway.
 * luckily for me, i worked at a large enough company at the time, and we had access to the library source, which allowed me to patch the library (i could not simply remove the calibration, since i needed "delay" to work, as my thing did interface with hardware).
 * this story is only 12% relevant, but i enjoyed telling it, and i hope some of you enjoyed reading it. won't be surprised if some had first-hand acquaintance with it...
 * the moral of the story is, do not rely on clock ticks between calls your program makes - some day someone will build a machine fast enough, and you'll find the clock did not tick between the first and 2nd call. under the surface this means that math.random is deeply flawed, as my sandbox demonstrates (BTW, this can be easily fixed: keep a module-wise local variable and ensure that seeding only happens once per invocation).
 * going back to "random" (not in module math, but in scribuntu: mw.math.random): if it was possible to seed it once per wiki page parsing, such that consecutive calls continue to develop it without seeding, i was fine with going this route, even though there is no guarantee that N consecutve calls will return N distinct value for any N > 1.
 * however, scribuntu creates a fresh "sandbox" for each invocation, which means random should be seeded per each invocation, which only works when the servers are slow enough, or when mw code is inefficient enough to ensure at least one tick between invocations.
 * peace - קיפודנחש (aka kipod) (talk) 20:24, 18 February 2022 (UTC)
 * By design, different calls with the same parameters are supposed to be totally independent of each other so, for example, one section can be parsed without regard for what is in other sections. I think there should be some restricted method of defining page-global variables (for example, to say "use mdy date formats on this page"), but without that I don't think there is any way of guaranteeing different results with the same parameters. Johnuniq (talk) 22:33, 18 February 2022 (UTC)

Module:Random uses both os.time and os.clock to set the random seed on each invocation. os.clock returns the number of seconds of CPU time used so far to build the page, with a precision in microseconds. my test indicates this technique is reliable in generating unique IDs within the same page and will be until CPUs are at least 20x faster than they are now. <span style="border-radius: 3px; padding: 2px; border: 1px solid #808080; font-size: x-small; font-family: Lucida Console, Monaco, monospace">Thparkth (talk) 21:01, 20 September 2022 (UTC)

Get list/array of pages in a category
Is it possible to somehow retrieve a list of pages in a category with Lua?

I am trying to create a dynamic/automatic list for WikiProject participants - currently a userbox exists that adds a user page into a WikiProject participants category. I want to get all the pages within this category and then use Lua to render a list DominusVilicus (talk) 11:52, 17 October 2022 (UTC)
 * Alas, no.
 * —Trappist the monk (talk) 11:57, 17 October 2022 (UTC)
 * You can, perhaps, use awb with the no-limits plugin to get all of the pages in a category and copy/paste that list into a sandbox page that lua can then read...
 * —Trappist the monk (talk) 11:59, 17 October 2022 (UTC)
 * So, WP:AWB can read that list (pages in category; optional: category depth; also in AWB: sort & filter eg mainspace pages only, or "all into talkpage").
 * Then one can save that AWB-list eg "in wiki markup" = -bracketed in a flat file. A full c/p into an enwiki /sandbox page can give the access as requested. HTH. DePiep (talk) 08:11, 23 October 2022 (UTC)
 * Then one can save that AWB-list eg "in wiki markup" = -bracketed in a flat file. A full c/p into an enwiki /sandbox page can give the access as requested. HTH. DePiep (talk) 08:11, 23 October 2022 (UTC)

Split string in Lua
I am trying to parse an article's wikicode to extract a table and split it into columns. Some columns are separated with a double vertical bar "||" and other times it is a new line followed by a single bar "\n|". I have given up using  because I don't think it can handle both possibilities. So any help would be appreciated, thanks &mdash; Martin (MSGJ · talk) 11:39, 30 October 2022 (UTC)
 * I can imagine that parsing a wikitable gets pretty ugly. Have you tried replacing double pipes with some sort of single character that you are unlikely to find in a wikitable and split on that?
 * —Trappist the monk (talk) 11:57, 30 October 2022 (UTC)
 * Replace "||" with "\n|". Then all columns will begin the same. — <span style="font-family:Arial;background:#d6ffe6;border:solid 1px;border-radius:5px;box-shadow:darkcyan 0px 1px 1px;"> Jts1882 &#124; talk 13:19, 30 October 2022 (UTC)
 * Thanks guys. For some reason I couldn't get the ║ to work properly. But Jts solution works perfectly! &mdash; Martin (MSGJ · talk) 16:18, 31 October 2022 (UTC)
 * Thanks guys. For some reason I couldn't get the ║ to work properly. But Jts solution works perfectly! &mdash; Martin (MSGJ · talk) 16:18, 31 October 2022 (UTC)

Lua requests
WP:Lua requests ("requests for Lua-based templates or tasks", according to WP:Lua) redirects here. Is the intention for such requests to be posted on this page? Andy Mabbett ( Pigsonthewing ); Talk to Andy; Andy's edits 21:18, 5 November 2022 (UTC)
 * Yes. I believe the "requests" page was merged to here a long time ago. Johnuniq (talk) 23:09, 5 November 2022 (UTC)
 * Thank you; I've set out my idea in a new section below. Andy Mabbett ( Pigsonthewing ); Talk to Andy; Andy's edits 16:35, 6 November 2022 (UTC)

Directly invoking a module
An editor has suggested at Template talk:Time signature that that template should invoke Module:Su directly instead of going through the template Su to reduce the post-expand include size (PEIS) of pages where Time signature is used extensively, specifically List of musical works in unusual time signatures. This seems a good idea to me, so I tried, but I can't get it to work. Is this a viable way to reduce post-expand size? Can this be done? Can somebody help doing it? -- Michael Bednarek (talk) 13:15, 2 November 2022 (UTC)
 * The post-expand size is based on the output of the template/module. I don't think this should be different if the template is a simple invocation of the module. A quick look at the module suggests it only handles parent frame parameters, so calling main won't work. Not sure if it would work calling _main with the appropriate parameters. — <span style="font-family:Arial;background:#d6ffe6;border:solid 1px;border-radius:5px;box-shadow:darkcyan 0px 1px 1px;"> Jts1882 &#124; talk 13:33, 2 November 2022 (UTC)
 * Directly invoking modules is a valid way to reduce the post-expand include size, although I personally don't like it. That said, the module has to support that method of calling, as as Jts1882 says it doesn't right now. * Pppery * <sub style="color:#800000">it has begun... 13:40, 2 November 2022 (UTC)
 * I've added an entry point for direct invocation to the sandbox. Try . — <span style="font-family:Arial;background:#d6ffe6;border:solid 1px;border-radius:5px;box-shadow:darkcyan 0px 1px 1px;"> Jts1882 &#124; talk 13:47, 2 November 2022 (UTC)
 * Thank you very much. I used Module:Su/sandbox at Template:Time signature/sandbox and Template:Time signature/testcases shows that it works. I leave it to others to decide whether this should be implemented. -- Michael Bednarek (talk) 01:39, 3 November 2022 (UTC)
 * Does it reduce the post expand include size? If it does then I can make the change. If not I don't see the need. — <span style="font-family:Arial;background:#d6ffe6;border:solid 1px;border-radius:5px;box-shadow:darkcyan 0px 1px 1px;"> Jts1882 &#124; talk 10:23, 3 November 2022 (UTC)
 * It does, by a little bit. The current live template has an PEIS of 1588 bytes, reduced for the sandbox version to 1270. The article mentioned above has 761 invocations of  and a further 145 of  which can be converted to .  uses 2638 bytes, so some savings can be had there, even with the current template/module. If there are no downsides, implementing the sandboxes seems like a good idea to me. -- Michael Bednarek (talk) 12:08, 3 November 2022 (UTC)
 * Only for a while. List of musical works in unusual time signatures slammed into the post-expand include size limit in June 2022 and again in October 2022.  If the article continues to grow (seems likely that it will), what will you do when it once again slams into the limit?  It's time to recognize that the problem is not going away.  These kinds of technical hacks are not solutions to the underlying problem – there are only so many hacks that can be applied before there are no more hacks available.  Editors need to exercise editorial control and take the hard decisions about the article's future.
 * —Trappist the monk (talk) 13:40, 3 November 2022 (UTC)
 * Ignoring the to  (or assuming they have already been all done) then just directly calling Su results in a reduction of the PEIS by 288 KB, which is a decent amount. The remaining 145  also would save 152 KB, for a total of 440 KB saved. Seems good (for now), but if I continue contributing too much that might change. Wilh3lmTalk 16:49, 6 November 2022 (UTC)
 * Update: the templates have all been replaced with  . The PEIS is currently 1,905,012 bytes, leaving 192,140 bytes remaining. Some redundant template calls could be culled too.Wilh3lmTalk 17:15, 6 November 2022 (UTC)
 * Update 2: There are currently 868 time signature templates and I am planning on reducing redundant time signatures, but also continuing to contribute which probably will make the article larger. aaaaaa Wilh3lmTalk 23:28, 8 November 2022 (UTC)
 * I did a test with Time signature/sandbox, which directly invokes module Su rather than using the template. The PEIS of List of musical works in unusual time signatures was reduced from 1,808,279 bytes to 1,528,834 bytes. With the other changes, this would leave considerable room for expansion of the list article. Should I make the change to the module? — <span style="font-family:Arial;background:#d6ffe6;border:solid 1px;border-radius:5px;box-shadow:darkcyan 0px 1px 1px;"> Jts1882 &#124; talk 10:19, 9 November 2022 (UTC)
 * I think that's a worthwhile step, and no downside has been mentioned. -- Michael Bednarek (talk) 13:30, 9 November 2022 (UTC)
 * ✅ Module:Su updated with separate entry point for direct use of invoke and Time signature modified to use invoke rather than use template Su. — <span style="font-family:Arial;background:#d6ffe6;border:solid 1px;border-radius:5px;box-shadow:darkcyan 0px 1px 1px;"> Jts1882 &#124; talk 15:28, 9 November 2022 (UTC)

Template proposal: coder needed
I have in mind a template that will produce a "one page" calender for any given year. I have set out details, and the 14 possible permutations, on User:Pigsonthewing/Calendars.

Would anyone like to code this, in Lua? The key requirement will be to programmatically determine, or fetch from Wikidata, the weekday on which 1 January falls in that year, and whether or not the year is a leap year; maybe there is some existing code that can be reused for this?

It might make a good student project. Andy Mabbett ( Pigsonthewing ); Talk to Andy; Andy's edits 16:34, 6 November 2022 (UTC)
 * Not sure that wikidata is needed. The   parser function can tell you if this year is a leap year:
 * and can tell you the day on which January 1 occurs:
 * If you know that, then the rest is figuring out how to format the table.
 * What are the template's parameters? Presumably the template will accept year with an override of the year portion of the article title with a final fallback to the current year.  Are there any others?  What do they do?
 * —Trappist the monk (talk) 17:07, 6 November 2022 (UTC)
 * In that case, It probably doesn't need Lua, either. I'll see what I can do with template code. User:Pigsonthewing/Calendars has suggestions for other parameters, which would be to control styling. Andy Mabbett ( Pigsonthewing ); Talk to Andy; Andy's edits 17:35, 6 November 2022 (UTC)
 * Does Calendar do what you need? Certes (talk) 19:01, 6 November 2022 (UTC)
 * Just because I was curious: Module:Sandbox/trappist the monk/calendar and my sandbox.
 * —Trappist the monk (talk) 20:59, 6 November 2022 (UTC)
 * That does what I wanted with the content; thank you. It renders One page calendar (starts Monday) redundant, so would you like to move and reuse that, and rename your module accordingly? It might also be sensible to include optional parameters for the caption and title. Andy Mabbett ( Pigsonthewing ); Talk to Andy; Andy's edits 12:25, 7 November 2022 (UTC)
 * My sandbox (permalink). Supports these parameters:
 * year – the year for which this calendar is to be rendered; defaults to current year
 * table-style – css style string suitable for use in an html style="" attribute; applies to the whole table; do not use quotes; defaults to empty string
 * caption – a caption that replaces the default caption; default caption automatically inserts day name on which 1 January occurs; this is not possible for custom captions
 * lang-tag – mostly useful for debugging; takes a MediaWiki-supported language tag in which this calendar is to be rendered; defaults to wiki's own language; caveat lector: mw:Help:Extension:ParserFunctions indicates that day names are 'rarely internationalized.'  To use this module on wikis that do not have internationalized day names, will likely require some sort of custom code.
 * You choose the template name (there will be only one).
 * —Trappist the monk (talk) 16:22, 7 November 2022 (UTC)
 * Thank you. Now at One page calendar and Module:One page calendar. Andy Mabbett ( Pigsonthewing ); Talk to Andy; Andy's edits 15:48, 11 November 2022 (UTC)
 * lang-tag – mostly useful for debugging; takes a MediaWiki-supported language tag in which this calendar is to be rendered; defaults to wiki's own language; caveat lector: mw:Help:Extension:ParserFunctions indicates that day names are 'rarely internationalized.'  To use this module on wikis that do not have internationalized day names, will likely require some sort of custom code.
 * You choose the template name (there will be only one).
 * —Trappist the monk (talk) 16:22, 7 November 2022 (UTC)
 * Thank you. Now at One page calendar and Module:One page calendar. Andy Mabbett ( Pigsonthewing ); Talk to Andy; Andy's edits 15:48, 11 November 2022 (UTC)

Lua pattern
Can anyone help me match the following pattern in Lua? [a-z]+(\-[a-z]+)*(_res\-[0-9a-f]{8}(\-[0-9a-f]{4}){3}\-[0-9a-f]{12})?

I got as far as replacing escape character with % and removed finite quantifiers as follows: [a-z]+(%-[a-z]+)*(_res%-[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]%-[0-9a-f][0-9a-f][0-9a-f][0-9a-f]%-[0-9a-f][0-9a-f][0-9a-f][0-9a-f]%-[0-9a-f][0-9a-f][0-9a-f][0-9a-f]%-[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])?

But I still have the brackets with quantifiers e.g.  and I don't know how to deal with that &mdash; Martin (MSGJ · talk) 11:01, 12 November 2022 (UTC)
 * I don't think that what you want to do is directly possible. There are some simplifications:   →   and   →  .  You might try breaking up the target string into appropriate pieces.  You can iterate   with   to create a sequence of captures, etc.
 * —Trappist the monk (talk) 13:19, 12 November 2022 (UTC)
 * Are you sure that your regex does what you want it to do? If I understand (I'm not saying that I do) then this test string should be matched by your regex:
 * and you want captures:
 * and
 * When I give your regex and my test string to regex101.com, it gives me:
 * What is it that you really want from this? Do you have real-life examples of what you want (real life examples are much more better than contrived test strings)
 * —Trappist the monk (talk) 14:36, 12 November 2022 (UTC)
 * Because I was curious, I've hacked a simple module that I think does what I think you want: Module:Sandbox/trappist the monk/MSGJ regex. Use the debug console to run the code:
 * returns:
 * returns:
 * —Trappist the monk (talk) 16:02, 12 November 2022 (UTC)
 * When I give your regex and my test string to regex101.com, it gives me:
 * What is it that you really want from this? Do you have real-life examples of what you want (real life examples are much more better than contrived test strings)
 * —Trappist the monk (talk) 14:36, 12 November 2022 (UTC)
 * Because I was curious, I've hacked a simple module that I think does what I think you want: Module:Sandbox/trappist the monk/MSGJ regex. Use the debug console to run the code:
 * returns:
 * returns:
 * —Trappist the monk (talk) 16:02, 12 November 2022 (UTC)
 * Because I was curious, I've hacked a simple module that I think does what I think you want: Module:Sandbox/trappist the monk/MSGJ regex. Use the debug console to run the code:
 * returns:
 * returns:
 * —Trappist the monk (talk) 16:02, 12 November 2022 (UTC)
 * returns:
 * —Trappist the monk (talk) 16:02, 12 November 2022 (UTC)
 * —Trappist the monk (talk) 16:02, 12 November 2022 (UTC)

Not wanting any captures, just true/false if a string matches the pattern. Thanks, will check your code when back on PC &mdash; Martin (MSGJ · talk) 16:33, 12 November 2022 (UTC)
 * ok, for true/false I've added .  Works the same way as  .  Returns   when   has valid format;   else.
 * —Trappist the monk (talk) 19:02, 12 November 2022 (UTC)
 * Many thanks for your code which seems to be working well. I suspect a lot of people are grateful for your curiosity &mdash; Martin (MSGJ · talk) 22:19, 15 November 2022 (UTC)

What does this do?
I'm trying to understand how the following line of code works as I haven't seen anything constructed like this before: local lccnType = parts[1] ~= 'sh' and 'names' or 'subjects' Is this valid and what does it do? Thanks &mdash; Martin (MSGJ · talk) 13:02, 2 December 2022 (UTC)
 * Is valid. Its a shorthand way of writing
 * —Trappist the monk (talk) 13:13, 2 December 2022 (UTC)
 * Wow! Would never have guessed that. So true and "names" = "names" then &mdash; Martin (MSGJ · talk) 13:38, 2 December 2022 (UTC)
 * If you're familiar with the ?: operator from C, Perl, etc., you could think of this as . Certes (talk) 13:23, 2 December 2022 (UTC)
 * Can I write
 * In this case anything "and" false has to be false, so a is always false, irrespective of the value of b? &mdash; Martin (MSGJ · talk) 23:00, 8 December 2022 (UTC)
 * Yes, a will always be false. The   has no effect.  (Variants such as   could have side-effects or return nil, but we try not to employ coders who write that sort of thing!) Certes (talk) 23:18, 8 December 2022 (UTC)
 * You can, but why would you want to? That simplifies to   regardless of the result from  .  Is there some reason that you think that   is necessary to set   to its proper value?  Or, is   in your example some sort of 'final result' of some other boolean operation so that sometimes the assignment looks like  ?
 * —Trappist the monk (talk) 23:27, 8 December 2022 (UTC)
 * Was just trying to follow the example above to its logical conclusion! But I guess it only works with strings and not booleans. If I want a to be false if b==1 and a to be true if b~=1 then  will not work &mdash; Martin (MSGJ · talk) 11:48, 9 December 2022 (UTC)
 * As mentioned in Ternary conditional operator, that doesn't work because the and...or mechanism has a limitation. It relies on the third operand being short-circuited when the left operand (condition) is true.  That requires the middle operand to be truthy.  It breaks if the middle operand evaluates to false or nil, because the "or" is then evaluated and the right operand returned instead.  You could write , or (much more legibly)  .   Certes (talk) 12:17, 9 December 2022 (UTC)
 * Was just trying to follow the example above to its logical conclusion! But I guess it only works with strings and not booleans. If I want a to be false if b==1 and a to be true if b~=1 then  will not work &mdash; Martin (MSGJ · talk) 11:48, 9 December 2022 (UTC)
 * As mentioned in Ternary conditional operator, that doesn't work because the and...or mechanism has a limitation. It relies on the third operand being short-circuited when the left operand (condition) is true.  That requires the middle operand to be truthy.  It breaks if the middle operand evaluates to false or nil, because the "or" is then evaluated and the right operand returned instead.  You could write , or (much more legibly)  .   Certes (talk) 12:17, 9 December 2022 (UTC)


 * short essay, not mandatory reading
 * so, this is a very common pattern in several languages, and lua is a prime example.
 * one of the easy ways to explain it (or rather, "what is it good for") is with comparison to the "switch" statement available in other languages (but not lua).
 * to demonstrate, let's look at some silly java example, taken from here:


 * using the "boolean pattern", the lua code becomes:


 * this is a made-up sample, and neither is an impressive implementation. to make it more real, let's look at some real code (copied from Module:Pages with authority control identifiers):
 * current code:


 * alternative using boolean shortcur:


 * it's not 100% clear cut which expression is clearer and easier to read (and/or debug), but the latter form is more in "lua spirit" than the former, and personally, i prefer it.
 * peace - קיפודנחש (aka kipod) (talk) 18:39, 10 December 2022 (UTC)
 * one small caveat, though: this patterns works fine when all expressions after the "and" evaluate to true.
 * when some may evaluate to false, it behaves like a "switch" statement omitting the "break" in some of the cases, which considered undesired, and usually produces some compiler or linter warning. if this is the case, probably "traditional" if will do better.
 * peace. קיפודנחש (aka kipod) (talk) 19:50, 10 December 2022 (UTC)
 * Yes – and it's not obvious at a glance that wpfaulty(...) always returns a true value. If it returns false or nil, the idiom quietly breaks. Certes (talk) 20:01, 10 December 2022 (UTC)
 * nitpick: actually, it is obvious at a glance.
 * one small thing that may be confusing is a (yet one more) difference between javascript and lua: in js, empty string and 0 evaluate to "false". in lua, both evaluate to true.
 * my "caveat" comment was meant for using this pattern in general. in this case, it's kosher, as neither wpfaulty nor wp can return false.
 * peace. קיפודנחש (aka kipod) (talk) 01:08, 14 December 2022 (UTC)

Module:Authority control
Can someone fix the script error at the bottom of AbbVie (and many more in Category:Pages with script errors)? I think it's related to the recent changes by User:MSGJ who may be offline right now? Frietjes (talk) 17:22, 9 December 2022 (UTC)


 * Checking now. If it takes more than 10 mins I will roll back changes &mdash; Martin (MSGJ · talk) 18:28, 9 December 2022 (UTC)

The error was caused by the following line: mw.ustring.gsub(conf.link,'%$1',valid_value) In this case the  had a %2 in it, i.e. mw.ustring.gsub('https://www.worldcat.org/identities/$1/','%$1','nc-abbvie%20inc') Somehow it thought the %2 was a capture and it gave an error. Is it possible treat the string as literal or do I need to replace '%' with '%%' first? &mdash; Martin (MSGJ · talk) 22:59, 10 December 2022 (UTC)
 * You have to escape  in valid_value with  . I would try to avoid that because second-guessing regex patterns or replacements leads to spiralling confusion. Instead, I would try to require that valid_value be defined on the assumption that it will be used in a Lua replacement and so, in this case, should be  . Johnuniq (talk) 00:56, 11 December 2022 (UTC)
 * Thanks @Johnuniq. I agree that would be simpler but unfortunately I have no control over the value because it comes from Wikidata and may be used by many other tools/templates. Is there any possible downside to making the substitution you suggested, and are there any other character combinations that I need to look out for? &mdash; Martin (MSGJ · talk) 07:32, 11 December 2022 (UTC)
 * Wikidata, ugh! I believe no other adjustments are needed and the gsub I gave above is all you need. It's fast. Johnuniq (talk) 08:59, 11 December 2022 (UTC)
 * It's working a treat. Thanks for your help! &mdash; Martin (MSGJ · talk) 09:54, 14 December 2022 (UTC)

Module:Political party
How can i write this for Bengali letters?

Here on enwiki, module always returns '1' (Module:Political party/1) if the input is not A-Z letters. For bnwiki i need same thing but in that case if the input is not অ - য় letters. I tried this but doesn't always work, e.g. fails here because input was. আফতাবুজ্জামান (talk) 23:25, 13 December 2022 (UTC)
 * You might try rewriting the function to look like this:
 * That should return  when   is not a character in the range  .  Does Bengali have upper and lower case letters?  If not then   changes to.
 * —Trappist the monk (talk) 00:38, 14 December 2022 (UTC)
 * @Trappist the monk, it works. Thank you. আফতাবুজ্জামান (talk) 00:56, 14 December 2022 (UTC)
 * just curious: shouldn't the original code work as is (almost) simply by replacing  with   ?
 * theoretically, this should work, i think. if this is the case, i think it's preferable, as it should work in any language, instead of having to adjust it for every language separately. the documentation says:
 *  : represents all characters with General Category "Letter".
 * assuming this is the case, it will be nice if the original on enwiki (here) will do this change - it should not affect the functionality here, and will work as is for projects in other languages.
 * peace. קיפודנחש (aka kipod) (talk) 01:26, 14 December 2022 (UTC)
 * OP provided a specific character range. I don't read Bengali so I don't know if that range contains all of the Bengali 'letter' characters.  The Bengali (Unicode block) encompases U+0980–U+09FE.  The OP's range is U+0985–U+09AF (plus an additional combining character U+09BC attached to U+09AF).  The combining character is apparently not a letter so in the debug console:
 * returns  (U+09AF)
 * returns  (U+09BC)
 * Not clear to me that a generic  will work reliably.
 * —Trappist the monk (talk) 01:57, 14 December 2022 (UTC)
 * Thats another problem. For some reason mediawiki doesn't support য় (U+09DF), ঢ় (U+09DD), ড় (U+09DC). After your save, mediawiki decomposes it. Long time ago, i even accidentally broke content translation on bnwiki (phab:T152956) when i submitted translation for ContentTranslation (at that time i didn't knew that mediawiki decompose these latter). আফতাবুজ্জামান (talk) 02:25, 14 December 2022 (UTC)
 * Anyway, in this case we are fine. If any name start with য়, i will add that to য and it will work. আফতাবুজ্জামান (talk) 02:34, 14 December 2022 (UTC)
 * Anyway, in this case we are fine. If any name start with য়, i will add that to য and it will work. আফতাবুজ্জামান (talk) 02:34, 14 December 2022 (UTC)

Module: Series overview
The Template: Series overview which uses this module recently looks so bad in mobile view. It is no longer scrollable from left to right like a normal wikitable but it just go out of bounds of the screen. Can someone take a look at it and fix it? I raised concern on its talk page, but there's no respond. Lulusword  (talk)  06:03, 27 December 2022 (UTC)


 * @User:Alex 21 would you look into this please? &mdash; Martin (MSGJ · talk) 07:07, 27 December 2022 (UTC)
 * I'll take a look as soon as possible. (No promises on how soon, my real world job is extremely demanding during the festive season.) -- Alex_ 21 TALK 21:53, 27 December 2022 (UTC)
 * @Lulusword Can you please an example page where this happens, and perhaps a screenshot of what you're seeing? Thank you. -- Alex_ 21 TALK 08:35, 29 December 2022 (UTC)
 * Here are some screenshots from the template page itself. The second image is the worst offender in my opinion.

Lulusword  (talk)  09:03, 29 December 2022 (UTC)
 * These are screenshots from mainspace. The first example is from List of Running Man episodes while the second one is from Star Trek: The Next Generation. Lulusword   (talk)  09:31, 29 December 2022 (UTC)



PAGESIZE
Is there an equivalent function in Lua to the magic word PAGESIZE? &mdash; Martin (MSGJ · talk) 18:38, 10 February 2023 (UTC)
 * Here are two options:
 * —Trappist the monk (talk) 19:06, 10 February 2023 (UTC)
 * And I think here is the another option:
 * It will get recorded as a transclusion and is expensive but the  parser function is also expensive. I have not tested this to compare the sizes yet.
 * If you go the parser function route you will likely want to use the R since you will likely be wanting to use  on it and do not want to push it through something more complex like:
 * Of course if you want a string and the numeric formatting of  then you can try:
 * —Uzume (talk) 22:06, 10 February 2023 (UTC)
 * is not expensive when given a page title; it is expensive when given a page ID. See .    does count as a transclusion but I doubt that that will cause any problems.  A quick hack in my sandbox suggests that this mechanism returns the same value as the   and   options.
 * —Trappist the monk (talk) 23:16, 10 February 2023 (UTC)
 * Thanks both! &mdash; Martin (MSGJ · talk) 06:42, 11 February 2023 (UTC)
 * @Trappist the monk: Thanks for testing that out. I meant that the  portion was expensive. Typically playing with random pagenames is not expensive, however, anything that has to touch the database on a title that is not already part of the current parse (e.g., the current page being rendered) adds to the expensive count (otherwise we could have a single page rendering that attempts to touch the database for every page in the system which would be prohibitive and thus is explicitly not allowed by incurring expense and having an upper-bound on that). I did notice the documentation did not specifically say   was expensive (but I have found the documentation is often lacking and I keep adding to it). If that is true then one can build a Scribunto module that effectively does the same as the   parser function and avoid the expensive hit. —Uzume (talk) 03:27, 12 February 2023 (UTC)
 * I meant that the portion was expensive.  No.  I have hacked a simple test module in my sandbox: Module:Sandbox/trappist the monk/pgsize and a test that uses it in my other sandbox.  The test allows testing your method (not expensive) and both of the methods that I suggested in my first post to this topic (both expensive).
 * In my 'other' sandbox I used Abraham Lincoln as the target page.   returns  (expensive).
 * —Trappist the monk (talk) 15:55, 12 February 2023 (UTC)
 * @Trappist the monk: Cool! But that seems like more an an oversight by the developers of Scribunto to me. —Uzume (talk) 21:35, 12 February 2023 (UTC)
 * @Trappist the monk: I used your test rig and did a more extensive comparison. In doing so I also fixed a bug in your sandbox testing module (see 1139365276). I did not attempt to make many runs and take averages so I am not sure how accurate these numbers are but I thought I would provide a quick comparison.
 * @Trappist the monk: Thanks for testing that out. I meant that the  portion was expensive. Typically playing with random pagenames is not expensive, however, anything that has to touch the database on a title that is not already part of the current parse (e.g., the current page being rendered) adds to the expensive count (otherwise we could have a single page rendering that attempts to touch the database for every page in the system which would be prohibitive and thus is explicitly not allowed by incurring expense and having an upper-bound on that). I did notice the documentation did not specifically say   was expensive (but I have found the documentation is often lacking and I keep adding to it). If that is true then one can build a Scribunto module that effectively does the same as the   parser function and avoid the expensive hit. —Uzume (talk) 03:27, 12 February 2023 (UTC)
 * I meant that the portion was expensive.  No.  I have hacked a simple test module in my sandbox: Module:Sandbox/trappist the monk/pgsize and a test that uses it in my other sandbox.  The test allows testing your method (not expensive) and both of the methods that I suggested in my first post to this topic (both expensive).
 * In my 'other' sandbox I used Abraham Lincoln as the target page.   returns  (expensive).
 * —Trappist the monk (talk) 15:55, 12 February 2023 (UTC)
 * @Trappist the monk: Cool! But that seems like more an an oversight by the developers of Scribunto to me. —Uzume (talk) 21:35, 12 February 2023 (UTC)
 * @Trappist the monk: I used your test rig and did a more extensive comparison. In doing so I also fixed a bug in your sandbox testing module (see 1139365276). I did not attempt to make many runs and take averages so I am not sure how accurate these numbers are but I thought I would provide a quick comparison.
 * @Trappist the monk: I used your test rig and did a more extensive comparison. In doing so I also fixed a bug in your sandbox testing module (see 1139365276). I did not attempt to make many runs and take averages so I am not sure how accurate these numbers are but I thought I would provide a quick comparison.

2= 3=  CPU time usage 0.014 seconds <td style="background:yellow">0.017 seconds <td style="background:yellow">0.013 seconds Real time usage 0.020 seconds 0.021 seconds 0.017 seconds Preprocessor visited node count 48/1,000,000 <td style="background:yellow">50/1,000,000 48/1,000,000 Post-expand include size 115/2,097,152 bytes <td style="background:yellow">122/2,097,152 bytes 115/2,097,152 bytes Template argument size 22/2,097,152 bytes 22/2,097,152 bytes 22/2,097,152 bytes Highest expansion depth 4/100 4/100  4/100  Expensive parser function count <td style="background:yellow">0/500 1/500 1/500  Unstrip recursion depth 0/20 0/20  0/20  Unstrip post-expand size 256/5,000,000 bytes 256/5,000,000 bytes 256/5,000,000 bytes Lua time usage 0.004/10.000 seconds 0.004/10.000 seconds 0.003/10.000 seconds Lua memory usage <td style="background:yellow">767,345/52,428,800 bytes <td style="background:yellow">558,500/52,428,800 bytes 558,751/52,428,800 bytes Number of Wikibase entities loaded 0/400 0/400  0/400
 * I highlighted some key differences which I shall call out here:
 * Method 1: Is in the middle in terms of CPU time, uses the most Lua memory but does not ping the expensive count
 * Method 2: Uses the most CPU, least Lua memory, and pings both the preprocessor node count and the expensive count
 * Method 3: Uses the least CPU, is in the middle in terms of Lua memory, and pings the expensive count
 * In my personal opinion, one of the more interesting results is that  does not impact the "post-expand include size".
 * I wonder if there is a difference between  with parser function   (which makes a template call) and  . Then there is always   on   but one would have to setup a frame with something like   to pass arguments to such. —Uzume (talk) 20:53, 14 February 2023 (UTC)

Bug report mw.text.decode (U+03B5 epsilon)
Regarding Module:DecodeEncode, see DePiep (talk) 13:52, 4 February 2023 (UTC)

Testcases & sandbox changes: -DePiep (talk) 06:59, 16 February 2023 (UTC)
 * Edit request made . -DePiep (talk) 06:59, 16 February 2023 (UTC)

Wrapper for Module:Graph and Module:Political party
I am attempting to make a wrapper for Module:Graph:Chart and Module:Political party that can get the colors and abbreviations from Module:Political party and use them in Module:Graph:Chart. after figuring out the problem with the wrong "#" symbol being returned by Module:Political party, I have something that works in User:Frietjes/political graph, but it goes through the template interface and not the module interface, which seems less efficient. after stabbing in the dark for awhile and not being able to get it to work, I thought I would ask here. I believe there is some clue to how it has to work in Module:Graph:Chart where a newFrame is created with a particular title for the parent? can anyone help provide some insight? feel free to edit my sandbox / userpage if you want to experiment. thank you! Frietjes (talk) 22:50, 27 February 2023 (UTC)
 * I think you could simply require Module:Graph:Chart then execute it directly. What I am currently very unclear about is what frame to pass when calling it and where the arguments would need to be (frame or frame:getParent). I might get a chance to think more in day or two however the cost of calling the template is probably small although I'm not sure what effect on template limits it might have in tight situations. By the way, the mw.ustring.gsub could be just string.gsub. Also, mw.ustring.match could be string.match and  should be  . Johnuniq (talk) 09:37, 28 February 2023 (UTC)
 * From looking at the code, it would seem that Module:Graph:Chart uses Module:Graph (I'm unclear what it actually adds to it) by calling its chartWrapper function. That function is an entry point for p.chart(frame). If I'm reading the code correctly, that function could be refactored to accept instead p.chart(args) as it seems the only usage of frame is for frame.args.key. Gonnym (talk) 09:38, 28 February 2023 (UTC)
 * thank you for the help, to be more clear about the problem, see User:Frietjes/political graph2 which is the same as User:Frietjes/political graph but attempts to use Module:Graph:Chart directly. this has exposed a typo in line 624 of Module:Graph.  what is puzzling is why this typo is exposed by User:Frietjes/political graph2 and not by User:Frietjes/political graph?  Frietjes (talk) 16:45, 28 February 2023 (UTC)
 * okay, so no idea where the problem is? Frietjes (talk) 23:30, 15 March 2023 (UTC)

Substitution
Is it possible to partially substitute a module? I know this is possible with templates, but how to control it for modules? For example if I use  is it possible that the output would contain   rather than the substituted form of that template? &mdash; Martin (MSGJ · talk) 20:34, 15 March 2023 (UTC)
 * See Module:Template invocation * Pppery * <sub style="color:#800000">it has begun... 22:09, 15 March 2023 (UTC)
 * Okay I looked, but I am not sure how that will answer my question? &mdash; Martin (MSGJ · talk) 22:25, 15 March 2023 (UTC)
 * The basic idea is that the module, when substituted (which you can detect via ) has to return the wikitext of the template call (generated using that module) rather than its expansion. See the expandTemplate function in Special:Diff/1102521258 (ironically to a module you were working on) for an example. * Pppery * <sub style="color:#800000">it has begun...  22:32, 15 March 2023 (UTC)
 * Okay thanks, I can follow that. So "inline" is the default format? &mdash; Martin (MSGJ · talk) 23:10, 15 March 2023 (UTC)
 * No, passing "inline" as a format does nothing (the only supported format is, which you don't want here). I must have misread the docs when I made that edit. The module seems to generate the invocation with no whitespace always, although you could of course include any desired whitespace in the parameters themselves. * Pppery * <sub style="color:#800000">it has begun...  01:14, 16 March 2023 (UTC)
 * That's what I guessed. It's working brilliantly, thanks for your help. &mdash; Martin (MSGJ · talk) 08:03, 16 March 2023 (UTC)

Module:Sports table/CricketWTC
I propose to create a sports module for 2019–2021 & 2021–2023 World Test Championship League table. Abazizfahad (talk) 13:36, 20 March 2023 (UTC)

add require(strict): code check please
About module:DecodeEncode, (my edit request, now paused).

With current live version, I meet script errors (in development situations). I propose to add require('strict'), see sandbox. Could someone who knows about 'strict' check this change? If OK, pls set no or perform the edit right away. DePiep (talk) 14:47, 21 March 2023 (UTC)


 * ✅ DePiep (talk) 19:38, 25 March 2023 (UTC)

Empty string
This came from a previous version of Module:Class mask: ret = args[''] Is it using the empty string as a key to a table? This seems somewhat strange to me. &mdash; Martin (MSGJ · talk) 20:39, 23 March 2023 (UTC)
 * Writing  is valid and means that t.a is 'alpha', t.b is 'beta', and t[&#39;'] is 'empty'. A weird warstory is at Template talk:Val/Archive 5 where I did a confusing workaround following a case where   was accidentally used in a template. That set the empty parameter to 'done' and due to other stuff, that ended up calling done which displayed an image (✅) where that should have been impossible. Your example looks weird but it is plausible and would give 'done' with my example. Johnuniq (talk) 03:05, 24 March 2023 (UTC)
 * Thanks John. I guess I shouldn't have been surprised than an empty string can be a key in Lua. Rather unintuitive in this case though, because these arguments represent template parameters and obviously the name of a parameter can't be empty! &mdash; Martin (MSGJ · talk) 09:33, 26 March 2023 (UTC)
 * I agree that it is very unexpected for the name of a parameter to be empty, but I just gave an example where it can happen . Johnuniq (talk) 05:18, 27 March 2023 (UTC)

Getting the current frame
I am using  in a local function. Is it better to use  to get the current frame, or can I pass the frame as an argument to the function? &mdash; Martin (MSGJ · talk) 09:41, 26 March 2023 (UTC)
 * You can pass the frame object (which is just another table); see.
 * —Trappist the monk (talk) 11:32, 26 March 2023 (UTC)
 * Where not too inconvenient, I prefer passing frame as a parameter because it's always better for the inputs to a function to be spelled out in the parameters. A minor theoretical point is that using a parameter makes the function a little more general because it would be usable with something other than the current frame. Johnuniq (talk) 05:21, 27 March 2023 (UTC)

"Funneling" artificial parent arguments into a module for testcases (Module:ArgRest)
I'm trying to create a  page for the module I've made, Module:ArgRest. However, the rather unusual nature of the module makes this rather difficult; it reads the arguments of its parent AND its own arguments, with the expectation that it has been invoked by a template being transcluded onto another page. As such, I need a way to "feed" the module a set of artificial parent arguments (alongside arguments for the module itself), so that I can make testcases without having to make a separate template for each and every test. How do I do this? {&#123;Lemondoge&#124;Talk&#124;Contributions&#125;} 23:18, 29 March 2023 (UTC)
 * Update: I've managed to get this to be pretty much ✅ (although it's a tad uglier than I would've liked); Module:ArgRest/testCaser now exists for the sole purpose of "spoofing" templates. {&#123;Lemondoge&#124;Talk&#124;Contributions&#125;} 22:45, 30 March 2023 (UTC)
 * Take a look at Module:Arguments/testcases - it does something similar to what you are looking to do. The trick is to use frame:newChild to create artificial parent and child frame objects. The code looks something like this:


 * You can then use the child frame object as a parameter for your functions under test, etc. For example:


 * Best — <span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius  ♪ talk ♪ 08:40, 31 March 2023 (UTC)

Module:Hatnote list
Hello! I want to request a review of a sandbox change I've made for Module:Hatnote list (sandbox). The change allows final punctuation in the hatnote list to merge/collapse even with an italicized (and therefore de-italicized) title, which WP:ITHAT recommends. The current version can be seen in The Super Mario Bros. Movie, where the hatnote (which I edited for the title to be italicized) ends with both an exclamation mark and a full-stop. Without title italicization, only the exclamation mark appears. I didn't add an equivalent change to the module for bolded text (I have not seen bolded text in a hatnote) but I don't mind someone else adding it if they think it's also needed. LightNightLights (talk) 02:54, 6 April 2023 (UTC)
 * The regex looks good. I cleaned the whitespace to indent a line with tabs. It's probably not worth making a change, but I would be inclined to replace the loop with the following which is faster. It also occurs in a defined order, although that doesn't matter in this case. You probably should propose the change at Module talk:Hatnote list. Johnuniq (talk) 06:05, 6 April 2023 (UTC)
 * I wholly forgot to say that I have no knowledge of Lua whatsoever. I don't even know why there are square brackets around what I can assume to be strings. I'm also willing to propose in Module talk:Hatnote list, but it might get stuck in proposal-on-obscure-page limbo, more so that the last edit there is five years ago. This page, however, seems to be a whole lot more active. LightNightLights (talk) 06:55, 6 April 2023 (UTC)
 * I agree that posting here is a good idea. However, it's best to follow standard procedure and also post at the relevant talk page to at least give a chance for anyone interested in that page to contribute. That's particularly true when proposing a change to something used on a zillion pages. The square brackets tell Lua that the thing enclosed is a key for the table. Johnuniq (talk) 07:38, 6 April 2023 (UTC)
 * That's a fair point. I've posted the proposal at . LightNightLights (talk) 10:11, 6 April 2023 (UTC)
 * I have optimized it further (using the pattern, which matches zero or two single quotes):
 * Let's continue this discussion at Module talk:Hatnote list. —Dexxor (talk) 12:56, 6 April 2023 (UTC)

Lua module help - Iterating through a table
I have zero experience with Lua, but have managed to get something working. What I would like to request is someone to take a look at my module and help me optimise it. Brief summary:  has only two records for now but later will be quite large. My module iterates through the loaded data in a truly horrible way. I have tried all the online resources I can find on how to do this better and just run into errors. If there is someone who can take a look for me I'd be grateful. Planning to replace or enhance, , using a central repository of data. The current Module is the bare skeleton, but I would like to get the basics working properly before I continue.

BoonDock (talk) 17:15, 3 April 2023 (UTC)
 * If the thing you call  (line 3) is different for every 'item', build your table as a k/v table and then just do a simple lookup:
 * Then fetch items from the table using  for example.
 * —Trappist the monk (talk) 17:28, 3 April 2023 (UTC)
 * Can I do a substitution? For example,
 * param = frame.args[1]
 * output = data.param.Description
 * I have other questions, but that one strikes me first. Thanks for asnwering. BoonDock (talk) 17:45, 3 April 2023 (UTC)
 * No, but you can do .  Your version doesn't work because there is no   key defined in.
 * —Trappist the monk (talk) 21:32, 3 April 2023 (UTC)
 * I've been mulling this over and finally figured out what you were saying. Please correct me if I've gotten this wrong. Essentially, you are saying that the param passed to the module (code in my case) can be used as the direct access key to the record without iterating through the table ... if so, that's fantastic. I'm not sure how to deal with the case of a non existent key, but I'll figure it out.
 * To be clear, the data will look like this:
 * Given that, when my template invokes the function, it passes the value "MMM" as a parameter. In the module, load that value into a variable and use it to access the record directly without using any sort of loop?
 * BoonDock (talk) 03:47, 4 April 2023 (UTC)
 * A couple of minor points. There's a list of three-letter country codes in ISO 3166-1 alpha-3 (South Africa is ZAF) but many modules prefer ISO 3166-1 alpha-2 (South Africa is ZA).  Beware that param might not be unique, e.g. MMM is also used for Member of the Order of Military Merit (Canada). Certes (talk) 23:43, 3 April 2023 (UTC)
 * Thanks. I had considered using the ISO codes. Would be an improvement.
 * I'm fully aware of the duplication of abbreviations, vs  and haven't come up with a fully realised solution for that. PMM is another problematic one as is GSM. I will tackle it properly once I have a grasp of the skeleton, and have it working efficiently. It's not "clean" but so far the solution could be for when there are dupes to add the country code. I'll see. At the moment, the data is duplicated for each template and is an absolute mess. Doing this will be an opportunity to sort it out to be a lot better. One of the complications is the awarding across countries. For example a lot of senior South African generals, also have the USA Legion of Merit  as well as the ORB  BoonDock (talk) 00:27, 4 April 2023 (UTC)
 * One way is to prefix the decoration with its country, e.g. ZA-MMM. That's a bit long-winded but works well via ISO 3166-2 for country subdivision codes, e.g. BR-AL is Alagoas but US-AL is Alabama. Certes (talk) 12:55, 4 April 2023 (UTC)
 * Good suggestion. Only lissue is the major retcon I would have to do with over 250 each of the templates I want to replace. I think I will have to approach that in an incremental way. BoonDock (talk) 15:51, 4 April 2023 (UTC)
 * Certes,
 * Seeing as you were kind enough to suggest using the ISO country codes I thought you might have some advice. What do I do about the countries which were only partially recognised, for example Transkei, Venda, Bophuthatswana, Ciskei etc?
 * Second problem is what about situations where, for example, there are medals awarded to uMkhonto we Sizwe which were awarded by the ANC? When they amalgamated with the SADF in 1994, they became part of the SANDF. Which country do I use for them? I think you see where I'm struggling with this?
 * On a related note, You don't happen to know where I can look to find out how to access the country data on WP from a Lua module? BoonDock (talk) 19:28, 5 April 2023 (UTC)
 * What country data? Does Module:ISO 3166 and its submodules help?
 * —Trappist the monk (talk) 22:59, 5 April 2023 (UTC)
 * Yes. Thank you. BoonDock (talk) 23:21, 5 April 2023 (UTC)
 * Some places not universally recognised as countries have ISO codes: Antarctica, Réunion, Taiwan, etc. For others, we could use XA–XZ and QM–QZ, which are reserved for local use, e.g. XT for Transkei.  This is non-standard in the sense that another system might use XT for Tanganyika and QT for Transkei, but it's what the series is there for. Certes (talk) 17:02, 7 April 2023 (UTC)
 * My next question is how you can trap an error. At the moment it works with a single unnamed parameter. What if there is rather a named parameter or no parameter at all? It generates a script error when running. Is there a way I can test for that rather? BoonDock (talk) 04:53, 4 April 2023 (UTC)
 * Here is a somewhat rewritten version of  that does some minimal error checking.  I moved the   call outside of any function because it only needs doing once.  I declared the 'working' function   as a   and moved it above the interface function  .  The first positional parameter is forced to uppercase so that a value of 'mmm' will not cause a nil value return.  I simplified both but they could probably be combined unless you plan on calling   from other functions.
 * Similar changes can (should) be made to the other functions.
 * —Trappist the monk (talk) 14:07, 4 April 2023 (UTC)
 * Brilliant. Thank you. I was wondering about recursion. In "RibbonDesc" I'm calling "Ribbon" to avoid duplication of effort. It seems to work pretty well, so I guess it isn't a problem. BoonDock (talk) 15:53, 4 April 2023 (UTC)
 * Done for both Functions. Working very well, thank you again! BoonDock (talk) 19:10, 4 April 2023 (UTC)
 * Similar changes can (should) be made to the other functions.
 * —Trappist the monk (talk) 14:07, 4 April 2023 (UTC)
 * Brilliant. Thank you. I was wondering about recursion. In "RibbonDesc" I'm calling "Ribbon" to avoid duplication of effort. It seems to work pretty well, so I guess it isn't a problem. BoonDock (talk) 15:53, 4 April 2023 (UTC)
 * Done for both Functions. Working very well, thank you again! BoonDock (talk) 19:10, 4 April 2023 (UTC)

Patterns and qualifiers
I found this code in a module  but I was under the impression that   would not work because in the manual it says "Quantifiers may only be applied to individual characters or character classes". But it seems you can mix multiple characters and classes, is that correct? &mdash; Martin (MSGJ · talk) 10:23, 15 April 2023 (UTC)
 * Looking at this section, it appears the  modifiers work in   expressions, with every other character having no special effect. A set is considered a character class (Represents the class which is), so quantifiers should work on them just fine as it suggests regardless of what the set is made of. Aidan9382 (talk) 10:32, 15 April 2023 (UTC)
 * As Aidan9382 said, the Lua manual defines a character class as a set of characters that can be repeated with  or   or   or  . The set can be specified using a code such as   or as   where   can be any characters or any of the codes. So the example works. Johnuniq (talk) 01:42, 16 April 2023 (UTC)
 * Thanks both. Not sure why I misinterpreted, but this is a revelation for me! &mdash; Martin (MSGJ · talk) 13:08, 17 April 2023 (UTC)

Redirect module
Is it possible to make a redirect in module namespace? For example if I redirected Module:A to Module:B then calling {#invoke:A|main} would be the same as {#invoke:B|main} &mdash; Martin (MSGJ · talk) 06:59, 26 April 2023 (UTC)


 * Not trivially. Maybe you could pass the parameters over but it's not going to be perfect I don't think. Galobtter (talk) 07:58, 26 April 2023 (UTC)
 * I believe the closest solution to a redirect for modules is like how Module:CS1 does it, which is to just return the require of the target page. Aidan9382 (talk) 08:03, 26 April 2023 (UTC)
 * Yes, and the reason that is necessary is that a module (in Page information in the left sidebar) has "Page content model Scribunto" and that supports only Lua, not wikitext like #redirect. If Module:A is fairly new and edited by one person, namely the person who also created Module:B, I would be inclined to follow the above advice, then, next day try "What links here". Fix anything referring to Module:A (assuming there are not many) then delete Module:A. I have not seen that as a recommended strategy but if everything happened in a short period, it makes sense to me. Johnuniq (talk) 08:29, 26 April 2023 (UTC)
 * Makes sense, thanks &mdash; Martin (MSGJ · talk) 08:53, 26 April 2023 (UTC)
 * If one day T120794 is implemented, then the MediaWiki software would recognize the redirecting require and internally invoke the target module instead. As far as I know, there is no forecast on this being done, though. isaacl (talk) 17:02, 26 April 2023 (UTC)

Archive 3
Does anyone know what happened to Wikipedia talk:Lua/Archive 3? It seems to have been deleted on April 9, 2022 by User:Liz and now has archived threads from 2022. I had added a link to a relevant thread in a comment for T120794, but with the old content gone, it no longer points to anything. isaacl (talk) 17:08, 26 April 2023 (UTC)
 * I moved the 2022 archive to Wikipedia talk:Lua/Archive 11. One of the admins watching this page should undelete /Archive 3, since it was clearly deleted by mistake (Twinkle deleted the talk page when Lua/Archive 3 was created as a test). * Pppery * <sub style="color:#800000">it has begun... 00:47, 27 April 2023 (UTC)
 * Yes, it's clear that is what happened. I would normally have waited for but since the link is used at phab I undeleted the page now. Johnuniq (talk) 00:59, 27 April 2023 (UTC)
 * Thanks for the undeletion. It wasn't urgent for the ticket (anyone wanting to follow it had years to do so) but nonetheless I appreciate the rapid response! isaacl (talk) 04:24, 27 April 2023 (UTC)
 * Just shows that admins should check the page before pressing delete ... &mdash; Martin (MSGJ · talk) 12:09, 27 April 2023 (UTC)

I just want to see how many arguments are in the frame
table.maxn(frame.args) keeps giving me 0! Help! — swpb T&#8201;•&#8201;beyond&#8201;•&#8201;mutual 19:15, 10 May 2023 (UTC)


 * Per the note at, Most of the normal Lua table tools won't work properly on the args table, and that appears to include . You'll have to either find another way to get the number of arguments (maybe iterate over the arguments yourself), or just avoid using getArgs. Aidan9382 (talk) 19:34, 10 May 2023 (UTC)
 * This is also true for the vanilla frame.args, which also uses a metatable. To find the number of arguments, you will indeed have to iterate over the arguments yourself. The way you should do this depends on what you want to count:
 * If you want to count all arguments, you can iterate over the table with pairs, and keep track of the total. There is already a function for this at Module:TableTools which you can use.
 * If you want to count only positional arguments, and you can assume that there are no gaps in the argument numbers (in other words, you don't think the template will be called as ), then you can iterate over the table with ipairs and use the final index as the count. Or if there may be several arguments, and some of the intermediate arguments may not be used, you could use Module:Exponential search to avoid looking up every single argument.
 * If you want to count only positional arguments, but there may be gaps in the argument numbers, then you need to iterate over the table with pairs, and keep track of the number of arguments that have positive integer keys.
 * Let me know if you need a code example for any of these. Best — <span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius  ♪ talk ♪ 08:04, 11 May 2023 (UTC)
 * Thanks!! — swpb T&#8201;•&#8201;beyond&#8201;•&#8201;mutual 18:26, 11 May 2023 (UTC)

Coding help request
There is discussion here, as well as at this ongoing TfD, about merging the vital article talk page template into WikiProject Banner Shell. To help facilitate those discussions, it would be very helpful to have a working prototype of what this would look like. Making it should be a fairly simple task, but as I don't know how to code Lua, I'd appreciate help.

To lay out the request in a bit more detail, Vital article has four parameters: level (the VA level an article has been designated as, e.g. 3 for the 1000-most-vital list), topic and subpage (which sort the article into a VA category, e.g. People and Sports), and class (the quality rating). These should be merged, keeping their functionality the same other than renaming them to vital_level, vital_topic, etc.

For the display, the banner shell currently has e.g. This article is rated B-class on Wikipedia's content assessment scale. The only change needed here is to make the text e.g. This level-3 vital article is rated B-class on Wikipedia's content assessment scale, linking to the appropriate level.

Would anyone be interested in taking this on? If it's helpful for comparison, for a merge to Talk header that would work similarly; most code added there is just copied from the vital template. &#123;{u&#124; Sdkb  }&#125;  talk 16:45, 15 May 2023 (UTC)


 * I suggest to wait until the TfD is finally closed. Then, let's continue at Template talk:WikiProject banner shell? &mdash; Martin (MSGJ · talk) 20:43, 15 May 2023 (UTC)

How to pass an unlimited number of template arguments, like Babel?
I'm working on a copy of the Babel module and template with minor adjustments, but I can't seem to find out how to pass an unlimited or unspecified number of template arguments with the Invoke call. The source code in the "edit" tab of Template:Babel doesn't seem to pass any at all, but that doesn't work for my port - not even if I simply invoke the Babel module instead of the port; see my sandbox, where I'm currently testing this. This means that the code listed on the Babel template page clearly isn't the code actually used for the template, and that they're using some elusive method to pass the arguments. Does anyone know how to do this? And while we're at it, does anyone know where the actual code of the Babel template is located, and whether it's common practice (or even required) to put that code somewhere other than the template's main page? --110521sgl (talk) 16:26, 8 June 2023 (UTC)


 * @110521sgl: Module:Babel takes care of that in, and there's no other code for Template:Babel. See mw:Extension:Scribunto/Lua_reference_manual, and Module:Arguments. Ponor (talk) 17:36, 8 June 2023 (UTC)
 * found it: I had to replace  by  . I'd taken note of the "wrappers" section in Module:Arguments before, I just didn't know it was important. 110521sgl (talk) 19:18, 8 June 2023 (UTC)
 * Well found! Module:Arguments seems to lay a really horrible trap, making modules effectively unusable from anywhere other than the "authorised" template nominated in the (usually edit-protected) module. Certes (talk) 20:06, 8 June 2023 (UTC)
 * It's a feature not a trap! You can safely leave the wrappers option off anyway &mdash; Martin (MSGJ · talk) 20:46, 8 June 2023 (UTC)
 * Unless I've misunderstood, using wrappers= silently breaks exact copies of the code like the one in 's sandbox, causing coders to bang their heads looking for bugs that don't exist then probably give up. At a minimum, each module using wrappers= needs a large sign in its documentation saying "this code only works from named template(s); don't bother trying to re-use it". Certes (talk) 21:01, 8 June 2023 (UTC)
 * agreed wholeheartedly. 110521sgl (talk) 21:05, 8 June 2023 (UTC)
 * Short answer: you do not need to pass arguments, as they are all passed in the frame by #invoke &mdash; Martin (MSGJ · talk) 19:18, 8 June 2023 (UTC)

Using colon operator
Hi guys. I'm using mw.html to build some stuff in HTML but I don't understand enough about how the colon operator works to do this. If you look at you'll see one of the questions I have ... &mdash; Martin (MSGJ · talk) 20:21, 6 June 2023 (UTC)
 * Are you familiar with object-oriented programming? In Lua,  invokes a class method, and thus no access to the object is available within the method, and   invokes an object method, so the   keyword can be used within the method's body to access the object.
 * The mw.html library is designed so each object method returns the newly appended or modified object, which allows you to keep appending to/modifying the last object in the tree just by chaining method calls together. If you want to write a loop, you can store the return value into a variable and make use of it within the loop. isaacl (talk) 21:06, 6 June 2023 (UTC)
 * I've read the instructions and am familiar with the first paragraph. Would you be able to give me an example of the code I need to "store the return value into a variable and make use of it within the loop"? Thank you &mdash; Martin (MSGJ · talk) 22:34, 6 June 2023 (UTC)
 * The return value at line 515 is a reference to the object representing the HTML table element. Therefore if the chain of method calls ended there, the local variable  would hold a reference to that HTML table element. Although mw:Extension:Scribunto/Lua reference manual doesn't specify, I'm assuming from the code that the method returns a reference to  . Thus you can end the chain at line 515 and have a loop afterwards that repeatedly invokes the   method on the object representing the table element (right now, , but a different name might be helpful). Invoking   on the variable after the loop will give you a reference to the object at the root of the tree, which you could then store in a   variable. isaacl (talk) 23:02, 6 June 2023 (UTC)

Here is an untested code sample: isaacl (talk) 23:02, 6 June 2023 (UTC)
 * I haven't had time to examine this but an example of using mw.html is in the function at Module:Navbox where variable  is defined, then   tests occur to modify   in different ways. Johnuniq (talk) 02:10, 7 June 2023 (UTC)
 * Thanks both, this confirms what I thought but for some reason was not working. So just to check
 * should be equivalent to
 * correct? &mdash; Martin (MSGJ · talk) 07:48, 7 June 2023 (UTC)
 * Based on my understanding of your answers, this should work, but it does not because some of the elements are not being closed. Why do you recommend a new variable finalTable instead of using the banner variable? &mdash; Martin (MSGJ · talk) 12:03, 7 June 2023 (UTC)
 * Yes, based on mw:Extension:Scribunto/Lua reference manual, which mentions the return value of the  method,   returns a reference to itself, namely  . Thus invoking   multiple itmes on the   object is the same as invoking it repeatedly on each returned value from the   method.
 * In your diff, the return value of  is a reference to the object at the root of the tree of HTML objects, but it isn't stored anywhere. Thus   continues to hold the return value for the last method call in the chain, on line 515. This is a reference to the object representing the last table that was created. To update the banner variable, the code will have to store the   return value into it:
 * Variable naming is a matter of personal preference. For this particular circumstance, I suggest using a temporary with a name to describe the object to which it is pointing at the time when it is being used, namely one of the table objects within the banner. My apologies; I haven't gone through the code enough to understand the contents of the table. My inclination would be to name the variable semantically to describe the contents. But either way the functionality will be the same. isaacl (talk) 16:36, 7 June 2023 (UTC)
 * I managed to get it working by using banner = banner (diff). I still don't understand why this is needed, or where exactly it is needed, because I have not used this construction with any other HTML objects, but thanks for giving me the idea. &mdash; Martin (MSGJ · talk) 21:36, 7 June 2023 (UTC)
 * Yes, based on mw:Extension:Scribunto/Lua reference manual, which mentions the return value of the  method,   returns a reference to itself, namely  . Thus invoking   multiple itmes on the   object is the same as invoking it repeatedly on each returned value from the   method.
 * In your diff, the return value of  is a reference to the object at the root of the tree of HTML objects, but it isn't stored anywhere. Thus   continues to hold the return value for the last method call in the chain, on line 515. This is a reference to the object representing the last table that was created. To update the banner variable, the code will have to store the   return value into it:
 * Variable naming is a matter of personal preference. For this particular circumstance, I suggest using a temporary with a name to describe the object to which it is pointing at the time when it is being used, namely one of the table objects within the banner. My apologies; I haven't gone through the code enough to understand the contents of the table. My inclination would be to name the variable semantically to describe the contents. But either way the functionality will be the same. isaacl (talk) 16:36, 7 June 2023 (UTC)
 * I managed to get it working by using banner = banner (diff). I still don't understand why this is needed, or where exactly it is needed, because I have not used this construction with any other HTML objects, but thanks for giving me the idea. &mdash; Martin (MSGJ · talk) 21:36, 7 June 2023 (UTC)

(outdenting to facilitate including code examples) HTML documents are much like an N-ary tree of HTML elements. The mw.html library provides an API to build up a tree of corresponding objects. For generality, it doesn't define a "document" or "tree" class. A reference to any node in the tree can be considered a starting point for the subtree from that node. So to generate the HTML for the full banner, you need a reference to the root node. It might be easier to understand if the reference to the root node is kept at the start: isaacl (talk) 02:14, 8 June 2023 (UTC)
 * Okay I will try that, thank you. But when I built other nodes I did not need to do this. For example this is one of the rows of the table.


 * I am unsure what is the difference between class_row = class_row:node(x) and just class_row:node(x) &mdash; Martin (MSGJ · talk) 07:07, 8 June 2023 (UTC)
 * Do you have any experience with coding a linked list in a non-object-oriented language? To traverse the list, you must specify a starting node. You can store the root node of the list in a variable and keep it for later use. If it's a doubly-linked list, you can go up the chain from an internal node and find the root node. That's what the  method does: it traverses up the tree of mw.html objects and finds the root node, then returns a reference to it. (If you're not already aware, note that in Lua, objects are always stored by reference into variables, so   is like a pointer to the object.)
 * Note in the code fragment for, the same thing is done as in my latest example:   is assigned a reference to a newly created mw.html object representing an HTML element (in the case of  , a  element). The variable is not subsequently modified. The lines of code after the assignment are essentially equivalent to the following:
 * The return value of  is not being stored anywhere. isaacl (talk) 18:06, 8 June 2023 (UTC)
 * Based on what you've said, in my code, all the things I do to class_row are not being stored anywhere. But they definitely are being stored somewhere because in my next line I use  and it works correctly with everything included &mdash; Martin (MSGJ · talk) 19:17, 8 June 2023 (UTC)
 * The return values aren't being stored, but the methods run and do their work to modify the objects, or create new objects and place them in the tree. It's not necessary to store the return values; recall they are just references to the objects in the tree. The actual objects they point to continue to exist even if you don't save the return values. (From an implementation perspective, the running system keeps them alive as long as they are reachable, and since they are within the tree which has links both up and down the tree, they are still reachable.) In the end you only need to have a reference to the root object of the tree you're interested in. The straightforward approach is to just keep that reference at the start. isaacl (talk) 21:37, 8 June 2023 (UTC)

Re "difference between class_row = class_row:node(x) and just class_row:node(x)", consider: After running the above,  is " ".

The difference is that with, something is added to. But if you also assign that to, it gets the value returned by   which may or may not change class_row. In the above example, it does change it ( is different from  ). Johnuniq (talk) 05:19, 9 June 2023 (UTC)


 * They are different because of the last two lines. Would x and t be any different after the first two lines? Is x a reference to a lower node in the tree? &mdash; Martin (MSGJ · talk) 09:41, 9 June 2023 (UTC)
 * The last two lines do not alter x or t (they do alter what x and t contain). Yes, x is a reference to a lower node in the tree as shown by where "Ghi" ends up. Johnuniq (talk) 10:15, 9 June 2023 (UTC)
 * Thanks for being so patient with me :) I'm not going to say I understand it yet, but perhaps slowly getting there ... What blew my mind was your first sentence above. &mdash; Martin (MSGJ · talk) 14:25, 9 June 2023 (UTC)
 * It can be broken down as follows:
 * isaacl (talk) 18:06, 9 June 2023 (UTC)