Current archives:
To help centralise discussions and keep related topics together, all Wiki: Lua subpages' talk pages and Help talk:Lua redirect here. |
The contents of the Wiki: Lua/Requests page were merged into Wiki talk:Lua on 5 February 2016. For the contribution history and old versions of the redirected page, please see its history. |
Wiki: Lua/To do was nominated for deletion on 21 May 2015. The result of the discussion was keep. |
This page has archives. Sections older than 90 days may be automatically archived by ClueBot III when more than 1 section is present. |
Hello!
I'm translated Navbox module into Kazakh Wikipedia, but have one issue. We've already have a kk:Module:Navbox, but I want to upgrade it. Additionally in the some templates we also used English version of Navbox (english parameters). So I need to add english versions of parameters (Aliases?) to new kk:Module:Шолғы exactly to kk:Module:Шолғы/configuration. I've already ask this question on talk page of Module:Navbox, but nobody replied, that's why I'm writing here Thanks--Amangeldi Mukhamejan (talk) 15:15, 27 October 2023 (UTC)
I have a string with a "#" character. When I use the string it produces a numbered list, but I just want to use it as a string. I have tried mw.text.nowiki
without success. I have also tried using \u0023
but it just converts it back to #. Any other suggestions? — Martin (MSGJ · talk) 12:01, 9 February 2024 (UTC)
#
isn't escaped but that a line break is inserted before it where it shouldn't be. Nardog (talk) 12:09, 9 February 2024 (UTC) As Nardog pointed out above, Lua modules seem to return strings which begin with "#" in an unexpected way. Compare below. My sandbox module just returns the string '#1day1woman' and you can see it behaves differently — Martin (MSGJ · talk) 10:38, 10 February 2024 (UTC)
I wanted to port the following templates over to the Afrikaans Wikipedia: Template:Millenniumbox, Template:Centurybox, Template:Decadebox.
After an initial look at how they worked, I was overwhelmed by the sheer amount of nested templates that were used by these templates. I decided to instead copy the look of the templates, but to use Lua Modules instead for the backend logic.
Porting Template:Millenniumbox and Template:Centurybox over to Afrikaans Wikipedia using Lua Modules was easy enough for me and I am happy with the results.
However I am stuck on porting Template:Decadebox. This template has 2 edge cases which do not exist in the Millenniumbox or Centurybox. There is no 0th millennium nor 0th Century. However there is a 0th Decade and 0th Decade BC. See 0s and 0s BC.
I was aware of these edge cases when I was writing my Lua Module, but still the output does not work as I expect.
Here is my ported template af:Sjabloon:Dekadeboks, and here is the Lua Module that it uses : af:Module:Dekadeboks. On the template page documentation, you can see my different "test cases" All the examples work as expected except for my 2 edge cases.
The problem seems to be caused by the Lua not being statically typed.
I am passing the selected decade as an argument. For the 0s the argument value is "0" and for the 0s BC it is "-1".
Most of my calculations read the argument to the function as a number, but for this edge case, I read it as a string instead. So that I can handle "-0" as an argument.
I know it is kinda hacky, but I can't think of a better way to do it. Furthermore when I run my functions in an external IDE, or pass it to a local Lua interpreter, the function behaves as I expect.
For the simplest example see my function to get the category for birth years: "kry_geboortes_kat_str" it is at the very end of the module. Also see my function to get the category for deaths: "kry_sterf_kat_str" which is a slightly different approach, but also doesn't work.
Please can anyone advise how I could get these functions to correctly handle "0" and "-0" as an argument? Am I missing something here?
I would greatly appreciate any feedback/advice on this issue. - Rooiratel (talk) 09:43, 13 February 2024 (UTC)
Hi - I mostly do work on Wiktionary, but wondered if anyone had a use for a powerful recursive backtracking template parser which I've put together, which is designed to scrape large amounts of template data from pages very quickly: wikt:Module:template parser. It's (very loosely) based on mwparserfromhell, and builds a node tree of objects on the page that can then be traversed in order to retrieve data. The two available functions are described in the module, but - in short - parseTemplate
is a function that you feed a rawstring template into, and it'll return the template name and arguments, while findTemplates
is an iterator that returns data about each template it finds in the input text. Some features:
{{ }}
), arguments ({{{ }}}
), headings, wikilinks, HTML comments, parser tags and include tags, and has been designed to be as accurate to the native PHP parser as possible. This includes replicating some of the bugs in the native parser, to ensure full consistency. With one caveat (see below), I haven't yet been able to find a testcase it fails, even with really extreme or bizarre inputs.
,
and
tags are all handled correctly. By default, it assumes that the input text should be treated as transcluded, for the purpose of the include tags. This can be changed with a parameter.mw.title
's :getContent()
method, not the parsing itself (which can be seen in the parse profile on that page).
. It knows that they're there, but it doesn't yet know the various special ways that each one needs to be handled. In some cases this is very straightforward (e.g.
) and in some cases not (e.g.
), so support for these will take some time. At the moment, anything between such tags is treated as raw text (i.e. as though it were in nowiki tags).I'm reasonably confident it's the most powerful wiki markup parser that has yet been written in Lua (though I'm happy to be proven wrong!). Do let me know if you think this could come in handy for anything, and I'm happy to help in designing any implementations. Theknightwho (talk) 16:21, 13 February 2024 (UTC)
Can {{category disambiguation}} be made to use Lua? There has to be a better way than using 50 conditionals. Thanks! HouseBlaster (talk · he/him) 22:49, 13 February 2024 (UTC)
If x is a string why can I use x:lower()
as a shortcut for string.lower(x)
but if y is a table then I can't use y:concat()
as a shortcut for table.concat(y)
? — Martin (MSGJ · talk) 13:01, 22 March 2024 (UTC)
__index
points to the the string
table in the standard library. Tables, by default, do not have a metatable (presumably as programmers often use custom metatables for tables in their programs). To unpack that explanation, you need to know how metatables work; there is a pretty good explanation in chapter 13 in the Programming in Lua book. Also there is a little bit more detailed treatment of the string library metatable here. — Mr. Stradivarius ♪ talk ♪ 13:51, 22 March 2024 (UTC) setmetatable(t, y)
you could then use t:concat()
? — Jts1882 | talk 14:29, 22 March 2024 (UTC) t.concat
is a function.t:concat()
is defined as t.concat(t)
.t.concat
has to be a function.t = { 'abc', 'def', 'z' } y = { __index = { concat = function(x) return string.reverse(table.concat(x)) end } } setmetatable(t, y) z = t:concat() -- z = 'zfedcba'
table
works. I recommend using standard table.concat
and living with it. However, it is possible to muck around with something like this for a single table.t = { 'def', 'abc', 'A' } mt = { __index = { concat = table.concat, sort = table.sort } } setmetatable(t, mt) a = t:concat() -- 'defabcA' t:sort() b = t:concat() -- 'Aabcdef'
Collection
at Module:Age to see how I have sometimes defined a simple list. It's very weird to follow but Module:IPblock has more examples includings :sort()
. Johnuniq (talk) 04:24, 26 March 2024 (UTC)ln: is a small wikipedia with less than 10 active users per month and non of them with lua knowledge. There are some lua errors in templates that were probably copy pasted in the past from fr: The pages can be seen here: https://ln.wikipedia.org/w/index.php?title=Cat%C3%A9gorie:Pages_avec_des_erreurs_de_script&action=edit&redlink=1
Could someone who knows lua have a look to the templates ("modèle") and give us a hand or at least some advice? Thank you for helping. Bombo (talk) 21:35, 18 April 2024 (UTC)
I'm working on a module that let's the user to use some predefined placeholders to add categories/text. For example, on the "Category:144 births" category they can add the following template
{{YearCategory |__DECADE__s births |Births by year |RD(__CENTURY__)-century births |__YEAR__ beginnings |header=In this category you can find people who were born on [[__YEAR__]]. }}
And it will add the 140s births, Births by year, 2nd-century births and 144 beginnings categories to the page and will display a header with "In this category you can find people who were born on 144." content. The code is at hy:Մոդուլ:ԺամանակիԿատեգորիա and an example of usage at hy:Կատեգորիա:1944 ծնունդներ. It work fine except when I want to use those placeholders inside a template or an {{#if: block. As I understand, mediawiki parses the text before sending it to the Lua module. Is there a way to change this? ԱշոտՏՆՂ (talk) 01:26, 21 April 2024 (UTC)
get
. —andrybak (talk) 01:05, 22 April 2024 (UTC){{YearCategory|{{Decade|2024}}
births..
to implement the decade handling. You may need {{PAGENAME}} or something derived from it as the template parameter. Certes (talk) 09:34, 22 April 2024 (UTC) {{{year}}}
to a decade using {{DECADE}}
. —andrybak (talk) 15:44, 22 April 2024 (UTC)I wrote the following function:
local function linkToWikipage(link, text) local page = mw.title.new(link) if page.exists == true then if page.redirectTarget then local redir = page.redirectTarget.fullText or page.redirectTarget.prefixedText return "[[" .. redir .. "|" .. text .. "]]" else return "[[" .. link .. "|" .. text .. "]]" end else return text end end
It works on a small scale, but on a larger scale I'm told "too many expensive function calls." Can anyone help me find something cheaper that still fulfills the goals of:
Eievie (talk) 03:35, 23 April 2024 (UTC)
frame:expandTemplate{title = 'Link if exists', args = link}
This article uses material from the Wikipedia English article Wikipedia talk:Lua, which is released under the Creative Commons Attribution-ShareAlike 3.0 license ("CC BY-SA 3.0"); additional terms may apply (view authors). Content is available under CC BY-SA 4.0 unless otherwise noted. Images, videos and audio are available under their respective licenses.
®Wikipedia is a registered trademark of the Wiki Foundation, Inc. Wiki English (DUHOCTRUNGQUOC.VN) is an independent company and has no affiliation with Wiki Foundation.