Extension:Scribunto/We use Lua

Reciprocation page between Lua developers.

We are developers who use Lua to enhance templates, to optimize performance of the wiki servers and to offer a new experience to the final users.

Use Lua, which technical parts of this tool ? How to use it ? Which functions and services to final users ?

Lua is a recent language, simple to read and write, but very complete. And in wikis limited to the local page and adapted to improve the security. The execution speed is another main motivation to implement Scribunto et LUA.

Thanks to mediawiki developers who offer to us this language and these tools.

How to name this page ? Lua reciprocation, Lua metting of users, Developers community, Developers Lua reciprocation ? To talk here or in talk page.

We

 * Here we can share our expertises, our methods and strategies.
 * Report what well run or no, what is more or less efficient.
 * Share generic or basic modules.
 * Now scribunto is in wikisource fr and I shift there but I continue to share here. --Rical (talk) 18:54, 21 February 2013 (UTC)

Use
New possibilities :
 * Vérifier des paramètres, Detect and display errors, like Module:Taxobox-fr erreur.
 * Manage multilingual arguments for flexible template Module:Author argTable.
 * Dialog with final user, based on boite déroulante Dérouler/Enrouler ?
 * Aider à générer la documentation des paramètres. Module:Author argTable voir options et generDoc.
 * Utiliser l'option c=: pour afficher les catégories dans les doc au lieu de catégoriser directement. On peut utiliser ainsi plusieurs exemples d'un modèle dans la même page et voir à chaque fois quelles catégories il a généré. Voir catView.
 * Coté gestion d'erreur j'ai une fonction qui génère une "box" d'erreur (rouge, pour bien la voir) avec un message générique puis une indication de la cause de l'erreur + une catégorie d'erreur. Je trouve ça assez puissant de pouvoir stopper le code quand on rencontre l'erreur et de pouvoir informer le rédacteur directement qu'il y a un problème, et lequel ! Hexasoft Module:Taxobox-fr.
 * coherence testing of the input data is far more powerful than with templates: it is possible to make complex coherence-testing code in order to handle subtle but false situations (and to generate a warning, an error, or − why not − to correct the problem)
 * code abstraction: tables can have data but also functions. It is possible to make code execution switching by finding the right line in a table and calling the corresponding function. Adding new handling (i.e. new language or new feature) is just writing the corresponding function and adding it to the main table → no need to modify the control-structure of the code, execution can become data!

Lua

 * The iterator run across tables in "for" instructions, as pairs and ipairs. example
 * The co-routines ability.
 * The object and class inheriting
 * Lua 5.2 Reference Manual, wikimedia implements mainly 5.1 (2013-01-29).
 * Project and help in french wikipedia.
 * To manage errors, the __index metamethod could detect unknown parameters or values.

News

 * ustring library (same than string library, with UTF-8 support) is now available in mediawiki
 * mw.title object is present in scribunto git but still not merged with mainline. Should be available soon. It will add (at least) access to namespaces and titles. See the gerrit

Mediawiki Lua

 * Extension:Scribunto/Lua reference manual mainly updated about basic mw functions on 2013-02-16.
 * Extension:Scribunto/Lua reference manual/fr − french translation of Lua reference manual (not finished)
 * Other functions adapted to mediawiki : mw.lang, mw.page, mw.query, mw.site, mw.Title, mw.time, mw.text, mw.uri, ustring module to provide UTF-8 strings.
 * 2013-01-29 : reimplementation of Lua's string module with support for UTF-8, probably in next deployment.

Structuring a hierarchy of tables, paragraphs, parentheses
sub_function(level, x, y, z) -- to define a sub_function -- generate the sub_content if level < 30 then -- always limit the re-entrance in case of unwanted code. -- call any others sub_function end -- generate the end of sub_content return level-1, sub_content, errors end sublevel, subcontent, suberrors = sub_function(level + 1, x, y, z) -- to use a sub_function then verify sublevel, and use subcontent and suberrors.
 * for debug it can be useful to see the raw output of a module (i.e. when you track a bad-closed table…). You can do that from the module (with a parameter to switch it on) this way (you know an other way?):
 * put the nowiki flag around the complete code you return (i.e. around the final return of your main function)
 * return the preprocessed version of it (frame:preprocess(my_all_code), with frame the frame parameter of the main function)
 * Like in the recursive programmation, you can :
 * Generate the begin and the end parts in the same function.
 * Between the begin and end parts, implement the include content in a sub_function.
 * And manage an integer value **level** parameter, +1 when you insert the content, and -1 when you return it from the sub_function.
 * Finaly, verify the return **level** before to generate the end part.
 * To do this in Lua, you can return plural values from a sub_function.
 * Example, for any sub-part of the content, into any sub-level you can write :

Invoking sub-modules

 * In which pages put the sub-modules ? Where and when are they usable ? See the bug below.
 * LUA permet les appels entre modules. On peut ranger les sous-modules dans des sous-pages du module principal, c'est plus propre s'ils ne servent qu'au module principal. Voir le test : https://test2.wikipedia.org/wiki/User:Hexasoft/test2, avec le module https://test2.wikipedia.org/wiki/Module:Mainmodule qui importe en premier lieu les fonctions de https://test2.wikipedia.org/wiki/Module:Mainmodulesub et en second lieu les fonctions de https://test2.wikipedia.org/wiki/Module:Mainmodule/sub.
 * 2012-12-11 : En fait il y a un "bug" : si un module est en sous-page ses modifications ne sont pas vues/mises à jour. Donc avec la structure Module:toto qui utilise Module:toto/sub une modif de toto/sub reste invisible tant qu'on ne modifie pas toto lui-même. J'ai signalé le problème aux développeurs. Numéro de bug ? Hexasoft Module:Taxobox-fr. → the bug report on bugzilla

Optimisations

 * How to optimize execution time to build large or complex strings ? From table or step by step ?
 * On peut insérer des textes dans une table puis à la fin "applatir" le tout avec table.concat. Est-ce plus rapide que de concaténer le texte au fur et à mesure ?
 * Comment accéder à la meta-table frame:getParent.args pour en réduire la charge ? Une importation des paramètres guidée par une liste des paramètres connus est-elle efficace ? Voir ?

What should works and does not (but will, maybe)
See Extension:Scribunto/Deployment_priorities for a more detailled list.
 * mw module, part mw.page.title should provides name, namespace and other page-related data. It is still possible to get this using  var = frame:preprocess(  and other special models (is it efficient?)
 * os module should provide various time/date related data (i.e. for maintenance templates)
 * no way exists to simulate parser function (useful for templates used to create/link to pages depending on their existence)
 * Scribunto should provide low-level, high-performance functions for very common templates actions (exemples: building urls, encoding links, …)
 * Lua strings don't work well on parameters that come with tags such as &lt;nowiki> or &lt;pre>: a "magic" string is added around these tags to protect them (and rebuild them when outputed from module). string.len (for example) only see the tag, and functions such as find, gsub and others are not able to access to the content of the string beetween the tags. see bug report on bugzilla.

To do

 * invite other users after "incorporate recent edits" below.
 * ask some improvements to mw developers.
 * unify or diversify multilingual templates/modules. example in debug and test.

Others

 * https://test2.wikipedia.org/wiki/Special:RecentChanges
 * https://test2.wikipedia.org/wiki/User:Uploadwizardtest
 * https://test2.wikipedia.org/wiki/0.5644693458351062
 * https://test2.wikipedia.org/wiki/Special:Log/course
 * https://test2.wikipedia.org/wiki/Module:Author
 * https://fr.wikipedia.org/wiki/Projet:Scribunto