Skip to content

Lua standard library extensions

Lua, being a lightweight language also means that its standard library is tiny. I'd like it if OpenMW would include some helpful, commonly used functions.

Here I compiled a list of the functions that MWSE extends the standard Lua with. I added a link to the MWSE's documentation description of each function. The numbers in the second row indicate the number of uses in all the currently released MWSE-lua mods, which were obtained by using GitHub's search in the morrowind-nexus-lua-dump repository. There can be some false positives. For example, searching "table.size" would also list a file that has the words "table" and "size" in the comments. However, the number of false positives shouldn't be that high to significantly skew the numbers (my estimation, based on a quick scroll-over of the search results). Only for the functions that have a small number of hits, I've counted the real usage myself. So, these statistics show us how useful the modders find each of the functions. Bear in mind that not all the functions listed here were added to MWSE at the same time, so there wasn't the same amount of time for modders to start using each of those.

String library Function, Usage:

Math library Function, Usage:

Table library: Function, Usage:

All of these functions in MWSE are implemented in pure Lua, and I can link them to the implementation if desired.

The motivation to include these:

  • Most of the modders aren't software developers. Having helper functions should make it easier to script something in OpenMW.
  • The ones that have used MWSE will be familiar with these.

I see two important points to discuss:

  1. Which functions to include? Will we define a certain threshold and include all the functions with a number of uses higher than the threshold?
  2. How to name the functions? Will they be exposed in the global namespace or will be inside a package (e.g. openmw_aux.util)?

Note: I opened this for discussion on OpenMW's forums first some time ago, so the numbers above could have increased by now.

Edit (27.7.2023.): The morrowind-nexus-lua-dump repository isn't that large. I downloaded it and used the VSCode's built-in search to update the numbers above. For reference, I'll also put the usage count of some functions in the lua standard library for comparison:

  • require 9301
  • pairs 6060
  • string.format 2679
  • ipairs 2532
  • table.insert 1717
  • math.max 1640
  • math.floor 694
  • math.abs 380
  • string.lower 359
  • string.sub 334
  • table.sort 311
  • setmetatable 206
  • math.rad 181
  • math.sqrt 114
  • table.concat 73
  • string.match 70
  • math.cos 50
Edited by C3pa