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:
#include
and one header file (optional) !LuaBridge3 offers a set of improvements compared to vanilla LuaBridge:
-fno-exceptions
and /EHsc-
).__index
and __newindex
metamethods in exposed C++ classes, to support flexible and dynamic C++ classes !std::shared_ptr
to support shared C++/Lua lifetime for types deriving from std::enable_shared_from_this
.std::nullptr_t
, std::byte
, std::pair
, std::tuple
and std::reference_wrapper
.int64_t
.luabridge::Enum
stack wrapper.
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 git@github.com: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 git@github.com: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 (kunitoki@gmail.com)
Copyright 2019, Dmitry Tarakanov
Copyright 2012, Vinnie Falco (vinnie.falco@gmail.com)
Copyright 2008, Nigel Atkinson
Copyright 2007, Nathan Reed