Add the ability to require standard libraries by name to Luau

As a Roblox developer, it is currently annoying to run and test code outside of Roblox because they have backported some libraries from later versions of Lua and extended existing ones. It is annoying because there’s no clean way to handle these changes to the standard library while still running Lua 5.1.

In stock Lua you can call require with the various standard library names as arguments and get those libraries. This is so that scripts can ensure that a particular library is loaded before making use of it, but the added bonus is that you can use it to check for a standard library as well as any replacement modules by the same name. For example, if I wanted to look for the bit32 library, I could call require("bit32"), and it would return the bit32 library if it existed, or any modules named bit32 that it found.

This is useful behavior because it lets code that’s designed for multiple versions of Lua not have to worry about the versions and just worry about the libraries. Code that makes use of bit32 or utf8 or even string can be ran without those libraries so long as a module that replicates their behavior and API is available.

In my case, I’m making use of the utf8 library in a project. Given the changes between Lua 5.1 and 5.3, I cannot run 5.3 while still maintaining compatibility. Thus, I’m having to require a replacement module. There’s no clean way to do this without either modifying the code between testing and moving to Roblox, or using some bad code to check for the utf8 library’s existence. I’ve ultimately ended up going with local utf8 = utf8 or require("utf8") but this feels like a hack and should be unnecessary.

This issue also comes up with extensions to the standard library like string.split, which are invasive to insert into a Lua 5.1 runtime without just replacing the string library or “extending it” by modifying the global string table – which isn’t supported by Roblox, thus introducing even more incompatibilities.

It would be much cleaner and easier to test outside of Roblox if the ability to require standard libraries by name was added to Luau. Roblox has not yet eclipsed software like Git and lacks the ability to run code in its environment without opening Studio, so running tests outside of Roblox is necessary.

4 Likes

Seems like the simpler solution would be to change _VERSION to indicate that Luau is running. This really should have been done years ago.