LuaBridge3
LuaBridge3 copied to clipboard
A lightweight, dependency-free library for binding Lua to C++


LuaBridge 3.0
LuaBridge 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 revisions starting from 5.1.5, and also compatibility is provided with lua 5.2.4, 5.3.6 and 5.4.3 as well as LuaJit and Luau.
Features
LuaBridge is usable from a compliant C++17 compiler and offers the following features:
- MIT Licensed
- Headers-only: No Makefile, no .cpp files, just one
#include
and one header file (optional) ! - Simple, light, and nothing else needed.
- 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.
- Easy access to Lua objects like tables and functions.
- Interoperable with most common c++ standard library container types.
- Written in a clear and easy to debug style.
Improvements Over Vanilla LuaBridge
LuaBridge3 offers a set of improvements compared to vanilla LuaBridge:
- Can work with both c++ exceptions and without (Works with
-fno-exceptions
and/EHsc-
). - Supports conversion to and from
std::nullptr_t
,std::byte
,std::tuple
andstd::reference_wrapper
. - Transparent support of all signed and unsigned integer types up to
int64_t
. - Automatic handling of enum types by communicating with lua through
std::underlying_type_t
. - Support for converting to and from C style arrays of any supported type.
- Full support for capturing lambdas in all namespace and class methods.
- Allows creating class instances using non intrusive class factories instead of requiring public constructors.
- Lightweight object creation: allow adding lua tables on the stack and register methods and metamethods in them.
- Consistent numeric handling and conversions (signed, unsigned and floats) across all lua versions.
- Opt-in handling of safe stack space checks (automatically avoids exhausting lua stack space when pushing values!).
- The only binder library that works with both LuaJIT and Luau, wonderful for game development !
Status
Code Coverage
Documentation
Please read the LuaBridge Reference Manual for more details on the API.
Release Notes
Plase read the LuaBridge Release Notes for more details
Unit Tests
Unit test build requires a CMake and C++17 compliant compiler.
There are 9 unit test flavors:
-
LuaBridgeTests51
- uses Lua 5.1 -
LuaBridgeTests51Noexcept
- uses Lua 5.1 without exceptions enabled -
LuaBridgeTests52
- uses Lua 5.2 -
LuaBridgeTests52Noexcept
- uses Lua 5.2 without exceptions enabled -
LuaBridgeTests53
- uses Lua 5.3 -
LuaBridgeTests53Noexcept
- uses Lua 5.3 without exceptions enabled -
LuaBridgeTests54
- uses Lua 5.4 -
LuaBridgeTests54Noexcept
- uses Lua 5.4 without exceptions enabled -
LuaBridgeTestsLuau
- uses Luau
(Luau compiler needs exceptions, so there is no tests that runs on Luau without exceptions)
Generate Unix Makefiles and build on Linux:
git clone --recursive [email protected]:kunitoki/LuaBridge3.git
mkdir -p LuaBridge/build
pushd LuaBridge/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 LuaBridge/build
pushd LuaBridge/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 [email protected]:kunitoki/LuaBridge3.git
mkdir LuaBridge/build
pushd LuaBridge/build
cmake -G "Visual Studio 16" ../ # Generates MSVS solution build/LuaBridge.sln
popd
Official Repository
LuaBridge is published under the terms of the MIT License.
The original version of LuaBridge 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