User:Xenwolf/Lua

From Xenharmonic Wiki
Jump to navigation Jump to search

Lua is an easy to learn but powerful scripting language.

MediaWiki supports Modules written in Lua (by the extension Scribunto, bundled with 1.34+) which can simplify writing templates a lot. Especially in cases where a lot of calculations must be done efficiently or when loops are inevitable, Lua is the better choice (if not the only one).

Lua modules are currently (Dec. 2020) evaluated on dev.xen.wiki:

  • Can this feature help us building tables info boxes etc?
  • Is it easy to use and easy to maintain?
  • Is it safe?

... see dev:Category:Lua modules and dev:User:Xenwolf/SandBox for examples

Notes

Performance

The performance is really great, compared to templates.

As far as I know, modules are actually the measure taken by Wikipedia/MediaWiki to deal with the load caused by (nested) templates:

Server-kitty.jpg

Limiting the impact

in mw: Extension:Scribunto#Configuration there are some parameters to limit the impact/load of Lua scripts may have

  • memoryLimit - Specify the memory limit in bytes.
  • cpuLimit - Specify the CPU time limit in seconds.
  • profilerPeriod - Specify the time between polls in sections for the Lua profiler.
  • allowEnvFuncs - Set true to allow use of setfenv and getfenv in modules.

There is also an article about a PHP sandbox for Lua (currently not compatible with PHP8)

See also