![]() | To help centralise discussions and keep related topics together, all Wikipedia:Lua subpages' talk pages and Help talk:Lua redirect here. |
![]() | The contents of the Wikipedia:Lua/Requests page were merged into Wikipedia talk:Lua on 5 February 2016. For the contribution history and old versions of the redirected page, please see its history. |
![]() | Wikipedia: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. |
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)
You are invited to join the discussion at
MediaWiki talk:Scribunto-doc-page-header § Category:Module documentation pages. —
andrybak (
talk)
09:27, 14 May 2024 (UTC)
Does anybody know a parsing method to reliably get the first sentence of an article on a Lua module, removing templates such as infoboxes completely? -1ctinus📝 🗨 00:13, 3 June 2024 (UTC)
{{excerpt|Lion|paragraph=1|only=paragraphs|hatnote=no}}
gets the first paragraph of the
Lion article (minus infoboxes, templates, etc). Add |links=no
to get plain text. It should be straightforward to get the first sentence from that. —
Jts1882 |
talk
11:49, 3 June 2024 (UTC)
Module:Params offers the possibility to map or rename parameters using either helper templates or modules or parser functions. Currently, in the case of
mapping_by_invoking
and
renaming_by_invoking
, while iterating, a new child frame gets created for each parameter (
#1,
#2). This means that if the parameters to map or rename are more than about a hundred the code breaks, because,
as the Scribunto-Lua manual says, “The number of frames that may be created at any one time is limited”.
I have tried to solve the problem in
Module:Params/sandbox, but all my attempts at keeping only one child frame throughout the loop failed (
#3,
#4,
#5,
#6). The reason is that once the child frame object gets created I can no longer edit its .args
metatable. Yet, I would need to do that, because each module invocation needs to receive different parameters.
Testcases are available at Module:Params/testcases/tmaps and Module:Params/testcases/tmaps sandbox. Any idea on how to solve the problem and being able to map more than 100 parameters using a module? -- Grufo ( talk) 15:41, 3 June 2024 (UTC)
Is there an existing Lua module like that either (a) takes a page name and converts it into wikitext or (b) takes a page name and regex and returns the result text (something similar to Module:String2#findpagetext)? Don't want to write a new module if one already exists and I thought something like this exists but I can't find it. Gonnym ( talk) 09:20, 6 June 2024 (UTC)
{{
msgnw}}
– you should use the double colon if the page is in the main namespace, as in {{
msgnw::Richard Feynman}}
. That text transcluded in this way can then be passed as a parameter to a template or a module (and this includes {{
#invoke:string|
match}}, if that's what you are looking for). And so
{{#invoke:string|match|s={{msgnw::Richard Feynman}}|pattern=known%s+for%s+([^.]+)|nomatch=}}
getContent
?
Izno (
talk)
15:58, 6 June 2024 (UTC)
Hi. I'm looking for a module that can output 000000 or FFFFFF depending on the color code inputted. Is one available? Thanks. '''[[ User:CanonNi]]''' ( talk • contribs) 04:20, 11 June 2024 (UTC)
{{Greater color contrast ratio|{{If empty|{{{bg_colour|}}}|#CCCCFF}}|black|white}}
(simplified it), if this is can help you.
Gonnym (
talk)
09:36, 11 June 2024 (UTC)
Is a module capable of executing an
WP:Advanced search via a url param that is passed to it, and then processing the output of the search? I would like to be able to pass this url to a Module, have it execute the search, and return the total number of results by scraping it out of the content. For example, it should return value 4
given this url:
The resulting Html contains the following which looks easily scrapable, if a module can access it:
<div class="results-info" data-mw-num-results-offset="0" data-mw-num-results-total="4">Results <strong>1 – 4</strong> of <strong>4</strong></div>
The module should be capable of handling any url that represents an advanced search, and find the total results. Is that possible? Mathglot ( talk) 07:04, 6 July 2024 (UTC)
Reposting this village pump post for visibility: Wikipedia:Village_pump_(technical)#Request_for_Lua_code_review:_New_language_module
Feedback welcome on the talk page here.