Extension talk:Scribunto/Lua reference manual

Re : "If named arguments to #invoke are specified, for example " is not a full sentence, so "Then" cannot be with a capital.--Patrick1 (talk) 11:44, 30 August 2012 (UTC)

pattern in which function ?
"the empty capture captures the current string position (a number)." Perhaps a note about "pattern " could be usefull in these functions ? --Rical (talk) 11:51, 23 December 2012 (UTC)
 * string.find (s, pattern [, init [, plain]])
 * string.gmatch (s, pattern)
 * string.gsub (s, pattern, repl [, n])
 * string.match (s, pattern [, init])

What's available on WMF projects?
It seems like a lot of the libraries mentioned in this manual are not available on test2.WP, which I assume means that they won't be available on the WMF projects that Scribunto is about to be deployed on? (For example, mw.language, mw.site, mw.uri, and mw.ustring all appear to be missing.) Could this manual be edited to make clear which modules are available in what Scribunto versions? —Ruakh TALK 05:02, 18 February 2013 (UTC)
 * mw.ustring is available now. Here's a little test: User:Amire80/Scribunto. --Amir E. Aharoni (talk) 04:20, 19 February 2013 (UTC)
 * The hard part about that is idenfitying the versions. There isn't a 1:1 relationship between the version of MediaWiki and the version of Scribunto; for example, until the deploy 9 hours ago wmf9 had a relatively old version, which was upgraded to the newest. This could potentially be done again if warranted, rather than waiting for wmf11 to get the latest updates. Anomie (talk) 13:21, 19 February 2013 (UTC)
 * This is a point of confusion, though. As of right now there is no way to know for sure which functions are available on any given wiki, except by writing test code to see if it works or triggers a script error. At the very least, the documentation should specify the first Scribunto version for which each function became/will become available. CodeCat (talk) 22:19, 5 March 2013 (UTC)
 * Define "Scribunto version"; saying bit32 is first available in 5e548e769a464e3223cd52ffa0f819f6bf1c9924 doesn't help a whole lot. Anomie (talk) 02:34, 7 March 2013 (UTC)
 * It is possible to test existence of stuff by performing ~=nil tests. It is not very nice but it works (I use it in my test module to check functions that appears). Maybe we could write a "What's available module" that shows what is present or not? Hexasoft (talk) 08:59, 7 March 2013 (UTC)

(u)string patterns and PCRE
I believe, for people who know PCRE a special explanation of differences should be written, except that one must use  instead of  this will allow me, e.g., to do things like  or to create a table with some members, some of which may be functions, and construct new "instances" of this table by calling "new" and the table:

peace - קיפודנחש (talk) 18:07, 11 March 2013 (UTC)
 * The usual idiom seems to be to use  rather than  . Also, due to Scribunto's sandboxing, it is not possible for a  d library such as libraryUtils to add global functions as proposed here; it would wind up as , at which point you may as well use the normal idiom. BJorsch (WMF) (talk) 13:19, 12 March 2013 (UTC)
 * regarding your 2nd comment: sure, i meant  (also changed the snippets above to reflect this more correct usage). not a problem.
 * however, my Lua-fu is not that strong, and i'm not sure i understand your "standard idiom" comment. calling  result in an error, as well as  . if you mean i should write a new "new" function in any table i want to construct, then yes, i understand this is possible, but i think what i ask is both more elegant and simpler, while suplying the reuired functionality. of course, it won't stop anyone from creating tailored constructors, and calling them "new" or "construct" or duplicating the object name, or any other name they choose. peace - קיפודנחש (talk) 17:55, 12 March 2013 (UTC)

mw.text.unstrip
Hello, as far as I understand the doc, the  function will allow to "unstrip" incoming strings that include tags such as nowiki. It is fine (I filled the bugreport) because it will allow to read the full content of any kind of parameters. My question: does using  on the unstrip string will produce the same original string? Also, to be sure: unstrip will returns a copy, not modify the original string?

Regards, Hexasoft (talk) 19:31, 11 March 2013 (UTC)
 * No,  on the unstripped string will expand any wikitext in that string. Even if you were to add back the correct extension tag (e.g. wrap the string in , or , or whatever), the result still might not be the same. For example,   might return , but then unstripping might result in  : the HTML for the superscripted footnote, which isn't even valid for return from the Lua module since  is not allowed in wikitext. It's even possible that the text hidden behind   is something completely unexpected such as serialized PHP data, as it may be that the extension is intending to do postprocessing in a ParserAfterParse hook or the like.
 * Yes,  does not modify the original string. Strings in Lua are immutable and primitive values are passed by value, so it is not possible to modify an input string in a normal function call (you can modify the keys/values in an input table, of course). BJorsch (WMF) (talk) 13:38, 12 March 2013 (UTC)
 * Thanks for the clarification. I will play with it when available. Regards, Hexasoft (talk) 17:58, 12 March 2013 (UTC)

In section "mw.language:formatDate"
Hello, in section Extension:Scribunto/Lua reference manual it is said: « Formats a date according to the given format string. If  is omitted, the default is the current time. The value for  must be a boolean or nil; if true, the time is formatted in the server's local time rather than in UTC. » Rather than « server's local time » shouldn't it be « wiki local time »?

Regards, Hexasoft (talk) 16:39, 17 March 2013 (UTC)
 * Yes, it should be. Thanks for pointing out the error. BJorsch (WMF) (talk) 23:10, 17 March 2013 (UTC)

Suggestion for mw.text: word distance
Hello, I had the need of a distance function beetween words, and coded en:Levenshtein distance in my module. Don't know if it should be useful (I see few cases where that feature can be useful) but if you think it is it could have its place in mw.text module. Moreover I think it is the kind of algorithm that can be far more efficient in something else than Lua (I guess that a double-looping on characters from two strings is − for example − far more efficient in C or any language that gives direct accès to string elements).

Regards, Hexasoft (talk) 17:21, 21 March 2013 (UTC)
 * There are a lot of things that would be easier done in PHP, but on the other hand we don't want to bloat the Scribunto libraries with too many features that won't be of general use. On this one, I'd personally lean towards "no". But if someone else wants to code it up and put a patch in Gerrit, they can and we'll see what anyone else things. BJorsch (WMF) (talk) 13:28, 22 March 2013 (UTC)

environment for getfenv(function)

 * We can read : "Passing a function returns the environment that will be used when that function is called."
 * Can we say : "Passing a function returns the environment where this calling function is, if any, else nil. In case of recursive function, returns the nearest call of this function." ? --Rical (talk) 18:40, 21 March 2013 (UTC)
 * That would not be accurate. All functions have an environment, it's just that Scribunto may restrict access to some of them. And the environment returned depends on the function, not on the call stack; the "environment" returned is usually the same table that function sees as . BJorsch (WMF) (talk) 13:38, 22 March 2013 (UTC)

Conditionals
The reference doesn’t formally cover if-then-else conditionals. —Michael Z. 2013-03-21 21:55 z 
 * Extension:Scribunto/Lua reference manual seems to cover it. BJorsch (WMF) (talk) 13:39, 22 March 2013 (UTC)

mw.text.tag request
So there is one special property for tags, also known as "style". jQuery acknowledge this, so setting style elements is not done through calling elem.attr('style', something) (although this will also work), but rather, they provide a special api called elem.css.

so here is the request: to provide some mw.text.XXX support for style. this can be done either by augmenting the ma.text.tag somehow, or by creating a whole new mw.text.style(...). if the latter approach is taken, i'd like to make a suggestion: please allow for multiple parameters, and concatenate them using semicolon. so the call should look something like so: this is not meant to be the code itself, necessarily - clearly i did not think of all the possible implications. it's more of a sektch to illustrate the required functionality of helping the lua programmers composing "style" attribute from different bits and pieces of flotsam. either way, some functionality that would best mimic jQuery's ".css" would be greatly appreciated. peace - קיפודנחש (talk) 15:40, 30 March 2013 (UTC)

Fragment
The arguments for  are. Namespace, title, and interwiki are familiar enough to me, but what does fragment mean? Does this refer to the project link? I assume, for example, that the "fragment" in  would be "wikt". Is this correct? — Mr. Stradivarius  ♪ talk ♪ 11:19, 3 April 2013 (UTC)
 * Ah, I see I was wrong after playing around with this for a bit. It seems the fragment is the part that appears after "#" in the URL, and that the "interwiki" part includes both the project name and the language name. If no-one has any objections, I think I'll update the manual to say this. — Mr. Stradivarius  ♪ talk ♪ 12:32, 3 April 2013 (UTC)
 * Feel free. Note that "fragment" (or sometimes "fragment identifier") is the actual name for that part of a URL, see RFC 3986 § 3.5. Anomie (talk) 13:37, 3 April 2013 (UTC)

Access to MediaWiki API; access to page text
Hi. I have two somewhat related questions.


 * 1) Is there any ability currently to access the MediaWiki API from Scribunto? For example, I'd like to get a list of all the subpages of Global message delivery/Targets. This is available in the MediaWiki API, but I'm not sure if Scribunto can retrieve this information right now. It'd be super-helpful to have a Special:PrefixIndex equivalent available (or more generally, access to the MediaWiki API).
 * 2) Is there any ability currently to access page text? For example, I want to count instances of a string within the wikitext of Global message delivery/Targets/Wikidata.

Thanks in advance for any help or pointers here. --MZMcBride (talk) 18:03, 4 April 2013 (UTC)
 * Hello,
 * I can answer to the #2 question: title objects has a getContent method, allowing to get the raw content of the page corresponding the the title object. See Extension:Scribunto/Lua_reference_manual (the last entry). It think it is what you are looking for. Regards, Hexasoft (talk) 19:18, 4 April 2013 (UTC)
 * PS: note that I read somewhere that a Scribunto library exists (or is planed) to access wikidata stuff. Not sure about how advanced it is.
 * note that title object in general, and getContent in particular, do not work for titles on another wiki/site, so if the requirement is, for instance, to get the content of Global message delivery/Targets/Wikidata from any other wiki than meta, it won't help you, and i do not think this is possible. peace - קיפודנחש (talk) 22:37, 4 April 2013 (UTC)
 * The Wikibase Lua API will be deployed as the same time as the #property parser function. So, next Monday for en Wikipedia and, if all is good, Wednesday for the others. Here is the doc. I've already written [//test2.wikipedia.org/wiki/Module:Wikidata a module to test it]. Tpt (talk) 20:05, 5 April 2013 (UTC)
 * Making arbitrary API queries from Scribunto is probably not going to happen; they would be slow and prone to issues with proper data sanitization and accounting of the CPU time. This was discussed in this wikitech-l thread. BJorsch (WMF) (talk) 13:30, 5 April 2013 (UTC)

System messages with "page" or "subpage" ?
Hi.

Do you know what's the diffrence between messages system like Mediawiki:Scribunto-doc-subpage-xxx and Mediawiki:Scribunto-doc-page-xxx ? It seems that the twice exist.

Thanks by advance for your answer, Automatik (talk) 14:53, 5 April 2013 (UTC)