welder 0.1.0
Bindings for annotated C++ types, from C++26 reflection
Loading...
Searching...
No Matches
rod.hpp File Reference

welder LuaBridge3 Lua rod (header-only). More...

#include <array>
#include <cstddef>
#include <meta>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
#include <welder/welder.hpp>
#include <welder/rods/lua/metamethods.hpp>
#include <welder/bind_traits.hpp>
#include <lua.hpp>
#include <LuaBridge/LuaBridge.h>
Include dependency graph for rod.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  luabridge::Stack< E, std::enable_if_t< std::is_enum_v< E > > >
struct  welder::rods::luabridge::rod
 The LuaBridge3 rod: a stateless policy type satisfying welder::rod. More...
struct  welder::rods::luabridge::rod::module_scope
 A copyable handle to a welded module (or submodule) table: the borrowed Lua state plus the namespace path from the global table. More...
struct  welder::rods::luabridge::rod::session
 Per-module session — unused: LuaBridge3 registers namespace variables as live properties eagerly (no deferred batch is needed, unlike sol2's live- variable proxy), so this is empty and open_module/close_module are no-ops. More...
struct  welder::rods::luabridge::rod::class_handle< T >
 The class handle threaded from make_class to the add_* hooks: enough to re-open the class (its module, its Lua name) plus the C++ type (via type, recovered by the per-member hooks from decltype). More...
struct  welder::rods::luabridge::rod::enum_handle
 The enum handle threaded from make_enum to add_enumerator: the enclosing module, the enum's Lua name (a nested namespace of values) and whether it is scoped (an unscoped enum also mirrors its names onto the module). More...

Namespaces

namespace  luabridge
namespace  welder
namespace  welder::rods
namespace  welder::rods::luabridge

Typedefs

template<class... A>
using welder::rods::luabridge::ctor_sig = void(A...)
 The alias void(A...) — a LuaBridge3 constructor signature (a function type whose parameters are the constructor arguments; the return type is ignored).

Functions

template<class T, class... A>
welder::rods::luabridge::make_object (A... args)
 A factory that constructs T from the constructor arguments (works for normal constructors and, via C++26 parenthesized init, aggregates).
consteval const char * welder::rods::luabridge::lua_metamethod_name (std::meta::info f)
 Map a member operator to its Lua metamethod __name, or nullptr if welder does not expose it (which also gates operator eligibility in the driver).

Detailed Description

welder LuaBridge3 Lua rod (header-only).

A second Lua runtime rod alongside sol2: it implements welder's rod contract (<welder/welder.hpp>) for LuaBridge3 and hands the traversal/resolution off to welder's generic driver. All the language-agnostic work — deciding which members bind, gating bindability, walking bases and namespaces — lives in the core; only the LuaBridge3 emission primitives are here. Like sol2 it targets a loadable Lua C module entered through luaopen_<name>, but it lays the bindings down with LuaBridge3's fluent registrar instead of sol2's usertypes.

Requires the welder vocabulary first (#include <welder/vocabulary.hpp>). This header exposes exactly one thing to plug into welder::welder: the rod type welder::rods::luabridge::rod.

#include <LuaBridge/LuaBridge.h>
extern "C" int luaopen_mymod(lua_State* L) {
rod::module_type m{L, {"mymod"}};
lua_getglobal(L, "mymod"); // the populated module table
lua_pushnil(L); lua_setglobal(L, "mymod"); // keep _G clean
return 1;
}
welder LuaBridge3 Lua rod (header-only).
The LuaBridge3 rod: a stateless policy type satisfying welder::rod.
Definition rod.hpp:139
static auto weld_type(module_type &m, const char *name=nullptr)
Reflect over T and register it on module m.
Definition welder.hpp:111

or, more simply, via the backend-agnostic entry macro (include this directory's module.hpp instead):

WELDER_MODULE(mymod, luabridge) {} // welds namespace ^^mymod into luaopen_mymod
#define WELDER_MODULE(ns, rod,...)
Emit a binding module's entry point and weld a namespace into it.
Definition module.hpp:78

How this differs from the sol2 rod (both target Lua)

LuaBridge3 is a move-based fluent registrar: beginClass / beginNamespace move-consume their parent, and there may be only one "active" registrar at a time. welder's driver instead holds a stable module handle and mutates class / module handles across many separate add_* calls. The two are bridged with a re-open-by-path** model: welder::rods::luabridge::rod::module_scope is a light, copyable {lua_State*, namespace path}, and every emission primitive re-walks getGlobalNamespace(L).beginNamespace(path…) in a single chained expression and lets it unwind cleanly. beginNamespace reuses an existing namespace table (no wipe) and beginClass<T> re-opens a class preserving prior registrations, so the repeated open/close is correct; it costs a few extra table lookups per member at load time only. Everything else mirrors sol2:

  • Metamethods, not dunders — the same asymmetric Lua set as sol2 (see welder::rods::lua::lua_metamethod_name), registered by their __name string via addFunction("__add", …).
  • Constructors, all at once — LuaBridge3 takes the whole set in one addConstructor<Sig…>(), so this rod gathers them from reflection in welder::rods::luabridge::rod::make_class and the driver's per-constructor hooks are no-ops (aggregates ride C++26 parenthesized init).
  • Multiple / virtual inheritance binds (unlike nanobind): LuaBridge3's deriveClass<T, Base…> records each base with a computed cast offset and its __index chains transitively, so the core's nearest welded-ancestor set is enough (unlike sol2, which needed the full closure).
  • Enums are tables — a welded enum becomes a nested namespace of integer values (an unscoped enum's names are also mirrored onto the enclosing module).
  • No runtime docstringsdoc/returns are ignored (their home is the LuaCATS stub).
  • Namespace variables: snapshot or live — a const variable is copied in as a value; a mutable one becomes a native addProperty get/set over the C++ global (LuaBridge3 has first-class properties, so no metatable proxy is needed).
Note
Overloaded methods, static methods, free functions and operators arrive from the DRIVER as whole groups and register as one variadic addFunction(name, f1, f2, …) — LuaBridge3 dispatches among them by arity/type at call time.

Definition in file rod.hpp.