LuaBridge3 is a lightweight and dependency-free library for mapping data, functions, and classes back and forth between C++ and Lua (a powerful, fast, lightweight, embeddable scripting language). LuaBridge has been tested and works with Lua 5.1.5, 5.2.4, 5.3.6 and 5.4.6 as well as LuaJit 2.x onwards and for the first time also with Luau 0.556 onwards and Ravi 1.0-beta11.
LuaBridge3 is usable from a compliant C++17 compiler and offers the following features:
- MIT Licensed, no usage restrictions!
- Headers-only: No Makefile, no .cpp files, just one
#include
and one header file (optional) ! - Works with ANY lua version out there (PUC-Lua, LuaJIT, Luau, Ravi, you name it).
- Simple, light, and nothing else needed.
- Fast to compile (even in release mode), scaling linearly with the size of your binded code.
- No macros, settings, or configuration scripts needed.
- Supports different object lifetime management models.
- Convenient, type-safe access to the Lua stack.
- Automatic function parameter type binding.
- Functions and constructors overloading support.
- Easy access to Lua objects like tables and functions.
- Expose C++ classes allowing them to use the flexibility of lua property lookup.
- Interoperable with most common c++ standard library container types.
- Written in a clear and easy to debug style.
LuaBridge3 offers a set of improvements compared to vanilla LuaBridge:
- The only binder library that works with PUC-Lua as well as LuaJIT, Luau and Ravi, wonderful for game development !
- Can work with both c++ exceptions and without (Works with
-fno-exceptions
and/EHsc-
). - Can safely register and use classes exposed across shared library boundaries.
- Full support for capturing lambdas in all namespace and class methods.
- Overloaded function support in Namespace functions, Class constructors, functions and static functions.
- Supports placement allocation or custom allocations/deallocations of C++ classes exposed to lua.
- Lightweight object creation: allow adding lua tables on the stack and register methods and metamethods in them.
- Allows for fallback
__index
and__newindex
metamethods in exposed C++ classes, to support flexible and dynamic C++ classes ! - Added
std::shared_ptr
to support shared C++/Lua lifetime for types deriving fromstd::enable_shared_from_this
. - Supports conversion to and from
std::nullptr_t
,std::byte
,std::pair
,std::tuple
andstd::reference_wrapper
. - Supports conversion to and from C style arrays of any supported type.
- Transparent support of all signed and unsigned integer types up to
int64_t
. - Consistent numeric handling and conversions (signed, unsigned and floats) across all lua versions.
- Simplified registration of enum types via the
luabridge::Enum
stack wrapper. - Opt-out handling of safe stack space checks (automatically avoids exhausting lua stack space when pushing values!).
Please read the LuaBridge3 Reference Manual for more details on the API.
Plase read the LuaBridge3 Release Notes for more details
You can download and install LuaBridge3 using the vcpkg dependency manager:
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh # The name of the script should be "./bootstrap-vcpkg.bat" for Powershell
./vcpkg integrate install
./vcpkg install luabridge3
The LuaBridge3 port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please create an issue or pull request on the vcpkg repository.
To update the vcpkg port, we need to know the hash of the commit and the sha512 of its downloaded artifact. Starting from the commit hash that needs to be published, download the archived artifact and get the sha512 of it:
COMMIT_HASH="0e17140276d215e98764813078f48731125e4784"
wget https://github.com/kunitoki/LuaBridge3/archive/${COMMIT_HASH}.tar.gz
shasum -a 512 ${COMMIT_HASH}.tar.gz
# fbdf09e3bd0d4e55c27afa314ff231537b57653b7c3d96b51eac2a41de0c302ed093500298f341cb168695bae5d3094fb67e019e93620c11c7d6f8c86d3802e2 0e17140276d215e98764813078f48731125e4784.tar.gz
Now update the version in https://github.com/microsoft/vcpkg/blob/master/ports/luabridge3/vcpkg.json and the commit hash and sha512 in https://github.com/microsoft/vcpkg/blob/master/ports/luabridge3/portfile.cmake then commit the changes. Enter into vcpkg folder and issue:
./vcpkg x-add-version --all
Commit the changed files and create a Pull Request for vcpkg.
Unit test build requires a CMake and C++17 compliant compiler.
There are 11 unit test flavors:
LuaBridgeTests51
- uses Lua 5.1LuaBridgeTests51Noexcept
- uses Lua 5.1 without exceptions enabledLuaBridgeTests52
- uses Lua 5.2LuaBridgeTests52Noexcept
- uses Lua 5.2 without exceptions enabledLuaBridgeTests53
- uses Lua 5.3LuaBridgeTests53Noexcept
- uses Lua 5.3 without exceptions enabledLuaBridgeTests54
- uses Lua 5.4LuaBridgeTests54Noexcept
- uses Lua 5.4 without exceptions enabledLuaBridgeTestsLuaJIT
- uses LuaJIT 2.1LuaBridgeTestsLuaJITNoexcept
- uses LuaJIT 2.1 without exceptions enabledLuaBridgeTestsLuau
- uses LuauLuaBridgeTestsRavi
- uses Ravi
(Luau compiler needs exceptions, so there are no test targets on Luau without exceptions) (Ravi doesn't fully work without exceptions, so there are no test targets on Ravi without exceptions)
Generate Unix Makefiles and build on Linux:
git clone --recursive [email protected]:kunitoki/LuaBridge3.git
mkdir -p LuaBridge3/build
pushd LuaBridge3/build
cmake -G "Unix Makefiles" ../
cmake --build . -DCMAKE_BUILD_TYPE=Debug
# or cmake --build . -DCMAKE_BUILD_TYPE=Release
# or cmake --build . -DCMAKE_BUILD_TYPE=RelWithDebInfo
popd
Generate XCode project and build on MacOS:
git clone --recursive [email protected]:kunitoki/LuaBridge3.git
mkdir -p LuaBridge3/build
pushd LuaBridge3/build
cmake -G Xcode ../ # Generates XCode project build/LuaBridge.xcodeproj
cmake --build . -DCMAKE_BUILD_TYPE=Debug
# or cmake --build . -DCMAKE_BUILD_TYPE=Release
# or cmake --build . -DCMAKE_BUILD_TYPE=RelWithDebInfo
popd
Generate VS2019 solution on Windows:
git clone --recursive git@github.com:kunitoki/LuaBridge3.git
mkdir LuaBridge3/build
pushd LuaBridge3/build
cmake -G "Visual Studio 16" ../ # Generates MSVS solution build/LuaBridge.sln
popd
LuaBridge3 is published under the terms of the MIT License.
The original version of LuaBridge3 was written by Nathan Reed. The project has been taken over by Vinnie Falco, who added new functionality, wrote the new documentation, and incorporated contributions from Nigel Atkinson. Then it has been forked from the original https://github.com/vinniefalco/LuaBridge into its own LuaBridge3 repository by Lucio Asnaghi, and development continued there.
For questions, comments, or bug reports feel free to open a Github issue or contact Lucio Asnaghi directly at the email address indicated below.
Copyright 2020, Lucio Asnaghi ([email protected])
Copyright 2019, Dmitry Tarakanov
Copyright 2012, Vinnie Falco ([email protected])
Copyright 2008, Nigel Atkinson
Copyright 2007, Nathan Reed