Extension:Scribunto/We use Lua

From Linux Web Expert

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

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

Structuring a hierarchy of tables, paragraphs, parentheses

  • 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.
      • Finally, 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 :
 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.

Invoking sub-modules

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 [1] ?

What should works and does not (but will, maybe)

  • 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({{PAGENAME}} 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 {{#ifexist:}} 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 <nowiki> or <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 between the tags. see bug report on bugzilla.

See Extension:Scribunto/Deployment_priorities#Should_have for a more detailled list.

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.

See also

Others