Home

Awesome

Compat53 Status Bit32 Status

lua-compat-5.3

Lua-5.3-style APIs for Lua 5.2 and 5.1.

What is it

This is a small module that aims to make it easier to write code in a Lua-5.3-style that is compatible with Lua 5.1, Lua 5.2, and Lua 5.3. This does not make Lua 5.2 (or even Lua 5.1) entirely compatible with Lua 5.3, but it brings the API closer to that of Lua 5.3.

It includes:

How to use it

Lua module

require("compat53")

compat53 makes changes to your global environment and does not return a meaningful return value, so the usual idiom of storing the return of require in a local variable makes no sense.

When run under Lua 5.3+, this module does nothing.

When run under Lua 5.2 or 5.1, it replaces some of your standard functions and adds new ones to bring your environment closer to that of Lua 5.3. It also tries to load the backported utf8, table, and string packing modules automatically. If unsuccessful, pure Lua versions of the new table functions are used as a fallback, and Roberto's struct library is tried for string packing.

Lua submodules

local _ENV = require("compat53.module")
if setfenv then setfenv(1, _ENV) end

The compat53.module module does not modify the global environment, and so it is safe to use in modules without affecting other Lua files. It is supposed to be set as the current environment (see above), i.e. cherry picking individual functions from this module is expressly not supported!). Not all features are available when using this module (e.g. yieldable (x)pcall support, string/file methods, etc.), so it is recommended to use plain require("compat53") whenever possible.

C code

There are two ways of adding the C API compatibility functions/macros to your project:

What's implemented

Lua

For Lua 5.1 additionally:

C

For Lua 5.1 additionally:

What's not implemented

See also

Credits

This package contains code written by: