SkillAgentSearch skills...

Luacxx

Lua binding library for modern C++

Install / Use

/learn @dafrito/Luacxx
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

luacxx

Luacxx is a modern C++ library for binding C and C++ code to Lua.

It is designed to work with the Lua C API rather than hide it. You can freely mix raw Lua calls with Luacxx helpers for pushing values, reading values, constructing userdata, and exposing functions.

What It Focuses On

  • Modern C++ and the standard library
  • Direct interop with the Lua C API
  • Low-overhead userdata and conversion support
  • Extensible Push<T>, Store<T>, and Get<T> customizations
  • CMake-first installation and consumption

Examples

The smallest useful example is just moving primitive and standard-library values across the Lua boundary:

#include <cassert>
#include <string>

#include <luacxx/algorithm.hpp>
#include <luacxx/convert/numeric.hpp>
#include <luacxx/convert/string.hpp>
#include <luacxx/load.hpp>
#include <luacxx/thread.hpp>

int main()
{
    auto env = lua::create();

    env["answer"] = 42;
    env["name"] = std::string("luacxx");

    lua::run_string(env, "assert(answer == 42)");

    const auto answer = env["answer"].get<int>();
    const auto name = env["name"].get<std::string>();

    assert(answer == 42);
    assert(name == "luacxx");
}

For a metatable-backed class binding, see the multi-file example in examples/003-counter-binding:

That example shows the usual “real object in userdata + explicit metatable” path that Luacxx uses for non-primitive types.

Build

Luacxx requires:

  • C++20
  • CMake 3.24 or newer
  • Lua 5.2 or newer

Build and install:

cmake -S . -B build
cmake --build build
cmake --install build

To build the test suite:

cmake -S . -B build -DLUACXX_BUILD_TESTS=ON
cmake --build build --target luacxx_test_main
ctest --test-dir build --output-on-failure

Use From CMake

After installation, consume Luacxx with CMake:

find_package(luacxx CONFIG REQUIRED)

add_executable(my_app main.cpp)
target_link_libraries(my_app PRIVATE luacxx::luacxx)

The exported package also declares its Lua dependency.

Use From pkg-config

Luacxx also installs a pkg-config file:

pkg-config --cflags --libs luacxx

Conversions

Built-in conversions include:

  • numbers and characters
  • std::string
  • C strings and std::string_view as push-only string inputs
  • std::vector
  • std::array
  • std::map
  • std::unordered_map
  • std::optional
  • std::tuple
  • std::shared_ptr

Additional types can be integrated by specializing the conversion templates.

If you want to add your own types, start with docs/guide/conversion-templates.md.

Documentation

The user guide and reference live under docs/.

Start here:

Common tasks:

Concepts and policies:

Reference:

License

MIT

View on GitHub
GitHub Stars161
CategoryDevelopment
Updated3d ago
Forks23

Languages

C++

Security Score

100/100

Audited on Mar 28, 2026

No findings