Wikipedia talk:Lua

From Wikipedia, the free encyclopedia
  (Redirected from Wikipedia talk:LUA)
Jump to navigation Jump to search
 WP:Lua
WPtalk:Lua
 Help
 
 To do
 
 Resources
mw:reference manual
 

Lua pattern question[edit]

Hey, I can't see how to get an exact match. I am using [Cc]hess in a template, looking to get back only the full-word matches of " Chess " and " chess ", but I of course also get "duchess", "duchesses", "Chessie", etc. What pattern code returns only the selected characters when they are surrounded by spaces, and not part of a larger word? Thanks in advance. UnitedStatesian (talk) 12:53, 20 August 2019 (UTC)

try: %f[%a]([Cc]hess)%f[%A]
Trappist the monk (talk) 13:05, 20 August 2019 (UTC)
Thanks TTM, that worked perfectly. You are the MAN! UnitedStatesian (talk) 14:00, 20 August 2019 (UTC)
@Trappist the monk: for my own edification, why is the first %a lower case and the second %A uppercase? Does it matter? UnitedStatesian (talk) 03:49, 23 August 2019 (UTC)
Yes, it matters. Search for "frontier" at mw:Extension:Scribunto/Lua reference manual and see lua-users. %a matches all letters, while %A does the opposite (it matches all non-letters). Johnuniq (talk) 04:05, 23 August 2019 (UTC)
Please excuse the typo fix, Johnuniq, the reference manual is on mediawiki, not meta (I make that mistake myself all the time).
@UnitedStatesian: The frontier pattern "%f[%a]" matches the transition from non-letters to letters, so "%f[%a]chess" would match "chess" at the beginning of a word (including the beginning of a string). The frontier pattern "%f[%A]" matches the transition from letters to non-letters, so "chess%f[%A]" would match "chess" at the end of a word (including the end of a string). The pattern that Trappist gave you uses both frontier matches to isolate the word alone as a match. HTH --RexxS (talk) 14:01, 23 August 2019 (UTC)
Thanks, both! UnitedStatesian (talk) 14:13, 23 August 2019 (UTC)

InfoboxImage module broken?[edit]

some of the examples on Module:InfoboxImage aren't showing any image at all, and I don't know if it's just my laptop. I tried having a look at the source but I know absolutely nothing about code so I don't know what's wrong or how to fix it... Snizzbut (talk) 15:48, 30 September 2019 (UTC)

@Snizzbut: I see five examples with no image. Two have no image specified; two specify a placeholder image without the |suppressplaceholder=no flag, and one uses an image that doesn't exist. I think that's correct. Do you see more than five examples without images? Certes (talk) 15:54, 30 September 2019 (UTC)
@Certes: Thank you so much for your explanations... I foolishly assumed that a) all the examples would be of how to use the template correctly and b) that all the examples would use the same image to make comparing easier; I hope you can see how they looked broken to someone with those assumptions! ^^; (if each one had text explaining what it is demonstrating that would be extremely helpful imo, especially for non-technical people) — Preceding unsigned comment added by Snizzbut (talkcontribs) 21:56, 4 October 2019 (UTC)

Wikipedia pages' access code[edit]

After mastering "hello world" my next stepping stone is code to get information for a given URL (PageSize for starters). Can some good soul turn my head in the right direction? TiA Vitosmo

PS comparable functions to wikitext have a blank when it comes to Pagesize (talk) 08:23, 9 October 2019 (UTC)
That's a bit of a jump, but you need to use the title object for article properties. Look through https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Scribunto_libraries for a description. There are some examples at User:RexxS/GCI. I think number 6 does the libraries. --RexxS (talk) 08:43, 9 October 2019 (UTC)
whenever i write yet another hello world code, i get reminded I have done this before. The same (I hope) for the suggested objects and classes;) (Fortran, PL I/opt, Ratfor,cobol, c, R ... c# dyno). THX so much! Vitosmo (talk) 18:33, 9 October 2019 (UTC)

Help for debugging: Module:SimpleDebug[edit]

Because I'm improving a fairly complex module (more than two thousand lines of code). I created this module to make easy the debugging of any other module, because the Debug console is not always useful enough.

Also I added a new chapter: Help:Lua_debugging#How_debug to explain the possibilities of debugging. Maybe it would be interesting to improve and/or correct it (since my English level is intermediate).

--Jmarchn (talk) 21:12, 22 October 2019 (UTC)

Ghost references[edit]

I'm not exactly sure what is going on, so I created a simplified example. I start with the base full table in User:Frietjes/l which transcluded in User:Frietjes/l1, User:Frietjes/l2, and User:Frietjes/l3. The problem appears in User:Frietjes/l1 which has an efn (in the ghost references section) that does not appear in the article. I think I have isolated it to the tracking, since if I turn the tracking off, I get User:Frietjes/l3 which doesn't have any ghost references. any idea how to get the tracking to work without showing the ghost references? feel free to make changes to Module:Sandbox/Frietjes and/or Module:Sports table/argcheck/sandbox if you have ideas on how to fix it. Frietjes (talk) 17:45, 1 November 2019 (UTC)

@Frietjes: Module:Sandbox/Frietjes seems to generate part of the table, showing up to four teams above and below the named team, then (without |notracking=) add notes for the whole table, including one for Ipswich who don't make the table due to finishing more than four places behind Arsenal. Certes (talk) 18:32, 1 November 2019 (UTC)
Certes, yes, that's what the module does. I have isolated the issue further by simplifying the code. as you can now see in Module:Sandbox/Frietjes the only difference between User:Frietjes/l1 and User:Frietjes/l3 is that User:Frietjes/l1 has a "no action" loop over all the args, where User:Frietjes/l3 only observes the args used to generate the table. so, here is my question: Is there a way to loop over all the keys in the args without generating these ghost references? I would like to be able to validate the input, but it's unfortunate that observing the args changes the output! The odd thing is that Module:Arguments seems to be looping over all the args, but doesn't seem to have the same problem. Frietjes (talk) 17:18, 3 November 2019 (UTC)
@Frietjes: It doesn't need a loop. Any access to the Ipswich text argument, e.g. local unused = args.text_IPS, causes the footnote to appear. It seems that the #invoke: magic in mw:Extension:Scribunto only evaluates each parameter when first needed, so |text_IPS={{fb...{{efn...}} }} only produces a footnote if someone looks at the value of args.text_IPS. Footnote f in Wikipedia:Guide to Scribbling provides minimal evidence for this theory. Certes (talk) 18:01, 3 November 2019 (UTC)
... whereas Module:Arguments uses metatables to fetch arguments from #invoke ... without using the pairs() function. Certes (talk) 18:08, 3 November 2019 (UTC)
I haven't had a chance to look at this but that analysis looks correct to me. Module:Navbox reads its arguments before doing anything with the reason in a comment: "Read the arguments in the order they'll be output in, to make references number in the right order". Johnuniq (talk) 01:05, 4 November 2019 (UTC)
Yes, this is correct. If you only use syntax like args.foo or args["foo"] with an argument table output from Module:Arguments, then pairs() isn't called on the original #invoke arguments. However, if you call pairs() on the argument table, each argument from #invoke is fetched using the next() function, which has the same effect as using pairs() on the original #invoke arguments. — Mr. Stradivarius ♪ talk ♪ 01:40, 4 November 2019 (UTC)
This may be obvious but I think it's worth repeating: |text_IPS={{fb...{{efn...}} }} evaluates as as part of the template expansion process; the module only sees the expansion of {{fb|...}}. That expansion has the side effect of creating a footnote but occurs only when Lua needs to determine the value of args.text_IPS during lazy evaluation. I'm not a veteran Lua coder, so please correct me if any of that is wrong! Certes (talk) 11:30, 4 November 2019 (UTC)
interesting. since it looks like Module:Arguments can iterate over the args without creating these ghost references, I tried this to filter out the offending entry, but even that doesn't work. is there any way to remove this arg from the table without creating a ghost reference? Frietjes (talk) 14:40, 4 November 2019 (UTC)
I've done quite a few experiments and I don't think Module:Arguments really iterates over the args at all. What it seems to do is set up a table with a function to access its values. Calling that function has the same side effect of evaluating the footnote as any other type of access to the table value. The apparent magic is that getArgs does not actually call the function but merely associates it with the table so that any attempt to read the value later still triggers the footnote. What we need is a way to get a list of keys of a table without reading their values, so that we can iterate over it with something like if key == "text_IPS" then return nil else return table[key] end. Disappointingly, I can find no way to get a list of keys without evaluating their values, even with heavy metatable manipulation. Certes (talk) 18:48, 4 November 2019 (UTC)
I'm pretty sure it cannot be done. If there were a strong need, we might ask for a Scribunto enhancement so a module could call a function to get a table of parameter names. Scribunto might be able to do that without evaluating each parameter, but I don't know. Johnuniq (talk) 22:39, 4 November 2019 (UTC)

Requested move 8 November 2019[edit]

– Modules that are used solely to implement one template are internal stuff; the actual non-programmer-facing page is the template, so any discussion about the template should happen on the template talk page, not the module talk page. * Pppery * it has begun... 22:10, 8 November 2019 (UTC)