welder 0.1.0
Bindings for annotated C++ types, from C++26 reflection
Loading...
Searching...
No Matches
welder::welder< B, Style, Carriage > Struct Template Reference

welder's binding entry point, parameterized on a rod. More...

#include <welder/welder.hpp>

Public Types

using rod_type = B
 The rod this instantiation emits through.
using name_style = Style
 The name style this instantiation renames through.
using carriage_type = Carriage
 The traversal driver (carriage) this instantiation drives through.
using module_type = typename B::module_type
 The rod's module handle (py::module_, sol::table, …).

Static Public Member Functions

template<class T>
static auto weld_type (module_type &m, const char *name=nullptr)
 Reflect over T and register it on module m.
template<std::meta::info Fn>
static auto weld_function (module_type &m, const char *name=nullptr)
 Reflect over free function Fn and register it on module m.
template<std::meta::info Var>
static auto weld_variable (module_type &m, const char *name=nullptr)
 Reflect over global/namespace variable Var and register it on module m.
template<std::meta::info Ns>
static module_typeweld_namespace (module_type &m)
 Reflect over namespace Ns and expose its members on module m.
template<std::meta::info Ns>
static module_type weld_namespace_as_submodule (module_type &m, const char *name=nullptr)
 Define a submodule of m (via the backend) and weld_namespace() Ns into it.
template<std::meta::info Ns, class Pre = decltype(noop), class Post = decltype(noop)>
static module_typeweld_module (module_type &m, Pre pre=noop, Post post=noop)
 Build a whole module out of top-level namespace Ns: run pre, weld the namespace into m (adopting a namespace-level doc as the module docstring), run post.

Static Public Attributes

static constexpr auto noop {[](module_type&) {}}
 A do-nothing module hook; the default for weld_module()'s pre/post.

Detailed Description

template<rod B, class Style = naming::none, class Carriage = carriage>
struct welder::welder< B, Style, Carriage >

welder's binding entry point, parameterized on a rod.

One struct is all a user drives: pick a rod (e.g. welder::rods::pybind11::rod<>, from that rod's header) and call the static member matching the stage of the usual hand-binding flow you want to automate — welder generates the backend-agnostic boilerplate there, and everything around it stays ordinary hand-written binding code.

PYBIND11_MODULE(mymod, m) {
weld::weld_type<MyType>(m); // one type onto an existing module
weld::weld_function<^^my_free_fn>(m);// one free function onto m
weld::weld_variable<^^my_global>(m); // one global/constant onto m
weld::weld_namespace<^^myns>(m); // a namespace's members into m
weld::weld_namespace_as_submodule<^^other>(m); // …or into m.other
}
consteval detail::weld_spec weld(Ls... ls)
Build a weld annotation naming the target languages.
welder pybind11 rod (header-only).
welder's binding entry point, parameterized on a rod.
Definition welder.hpp:85

(For zero hand-written entry-point code at all, each rod also ships a module.hpp with the WELDER_MODULE entry-point macro.)

Composition / subclassing.** Every entry point is a one-line forward to the injected Carriage (the traversal driver), which owns the resolution and the welded/bindability gates. There are two ways to go beyond the stock flow, both without re-deriving any of that: inject a different carriage as the third template argument (e.g. welder::tack_welding_carriage to bind an unmarked library), or subclass welder::welder — the whole class is static and non-virtual, so deriving simply gives a user's own driver type access to the bound Rod / Style / Carriage (via rod_type / name_style / carriage_type) and to the public entry points, to assemble bespoke routines (a hand-picked subset of a namespace, welded and hand-written registrations interleaved) from the carriage's gated building blocks.

Template Parameters
Bthe rod to emit through (any type satisfying welder::rod).
Stylethe name style every generated name flows through — a class, method, field, … is renamed into the target language's convention (see <welder/naming.hpp>). A [[=welder::weld_as]] override on an entity beats the style and is used verbatim (and a call-site name argument beats even that). Defaults to welder::naming::none (bind C++ identifiers unchanged); a Python binding might pass welder::rods::python::pep8.
Carriagethe reflection-driven traversal driver (welder::carriage) — what walks a type/namespace and orchestrates the rod's emission. Defaults to welder::stitch_welding_carriage (marker-directed); inject welder::tack_welding_carriage to bind an unmarked library greedily, or any welder::carriages::basic_carriage<Resolution>.

Definition at line 85 of file welder.hpp.

Member Typedef Documentation

◆ carriage_type

template<rod B, class Style = naming::none, class Carriage = carriage>
using welder::welder< B, Style, Carriage >::carriage_type = Carriage

The traversal driver (carriage) this instantiation drives through.

Definition at line 91 of file welder.hpp.

◆ module_type

template<rod B, class Style = naming::none, class Carriage = carriage>
using welder::welder< B, Style, Carriage >::module_type = typename B::module_type

The rod's module handle (py::module_, sol::table, …).

Definition at line 93 of file welder.hpp.

◆ name_style

template<rod B, class Style = naming::none, class Carriage = carriage>
using welder::welder< B, Style, Carriage >::name_style = Style

The name style this instantiation renames through.

Definition at line 89 of file welder.hpp.

◆ rod_type

template<rod B, class Style = naming::none, class Carriage = carriage>
using welder::welder< B, Style, Carriage >::rod_type = B

The rod this instantiation emits through.

Definition at line 87 of file welder.hpp.

Member Function Documentation

◆ weld_function()

template<rod B, class Style = naming::none, class Carriage = carriage>
template<std::meta::info Fn>
auto welder::welder< B, Style, Carriage >::weld_function ( module_type & m,
const char * name = nullptr )
inlinestatic

Reflect over free function Fn and register it on module m.

The semi-manual analogue of what namespace binding does for a namespace's free functions: bind one hand-picked name directly, without welding the whole enclosing namespace. Fn must reflect a single function (an overload set is ambiguous — reflect a specific overload); under the default (stitch) carriage it must be welded for B::language. Fn's participating same-name overload siblings join the weld (as one group, Fn naming it) — the same set the namespace walk would bind, so the call is consistent on every rod, including the one-value-per-name Lua tables. Shape the set with per-overload marks; Fn itself always welds (the explicit call outranks its own marks).

Template Parameters
Fna reflection of the free function.
Parameters
mthe module handle to register onto.
namethe target name, used verbatim and taking precedence over any [[=welder::weld_as]] on Fn; nullptr (default) resolves the weld_as/styled name.
Returns
whatever the rod's add_function hands back — the bound function object for the Python rods (m.attr(name)) and the sol2 rod (the table entry), for chaining further hand-registration; void where the framework has no per-function handle (LuaBridge3, the text-emitting rods).

Definition at line 142 of file welder.hpp.

◆ weld_module()

template<rod B, class Style = naming::none, class Carriage = carriage>
template<std::meta::info Ns, class Pre = decltype(noop), class Post = decltype(noop)>
module_type & welder::welder< B, Style, Carriage >::weld_module ( module_type & m,
Pre pre = noop,
Post post = noop )
inlinestatic

Build a whole module out of top-level namespace Ns: run pre, weld the namespace into m (adopting a namespace-level doc as the module docstring), run post.

The hooks fold hand-written bindings in around welder's generated body. This fills an existing module handle; pair it with an entry-point macro (the framework's own, or the backend's WELDER_MODULE expansion, which calls this).

Template Parameters
Nsa reflection of the top-level namespace (its name is meant to be the module name).
Prethe pre-hook callable type.
Postthe post-hook callable type.
Parameters
mthe module handle to fill.
preinvoked with m before binding (defaults to noop).
postinvoked with m after binding (defaults to noop).
Returns
m, for chaining.

Definition at line 217 of file welder.hpp.

References noop.

◆ weld_namespace()

template<rod B, class Style = naming::none, class Carriage = carriage>
template<std::meta::info Ns>
module_type & welder::welder< B, Style, Carriage >::weld_namespace ( module_type & m)
inlinestatic

Reflect over namespace Ns and expose its members on module m.

Classes and enums bind via weld_type(), free functions and namespace variables become module attributes, and a nested namespace holding participating content becomes a submodule. Which members participate is the carriage's call (marker-directed by default, greedy under the tack carriage).

Template Parameters
Nsa reflection of the namespace.
Parameters
mthe module handle to fill.
Returns
m, for chaining.

Definition at line 179 of file welder.hpp.

◆ weld_namespace_as_submodule()

template<rod B, class Style = naming::none, class Carriage = carriage>
template<std::meta::info Ns>
module_type welder::welder< B, Style, Carriage >::weld_namespace_as_submodule ( module_type & m,
const char * name = nullptr )
inlinestatic

Define a submodule of m (via the backend) and weld_namespace() Ns into it.

Template Parameters
Nsa reflection of the namespace.
Parameters
mthe parent module handle.
namethe submodule name (verbatim), or nullptr to resolve Ns's styled/weld_as name.
Returns
the new submodule handle, for chaining.

Definition at line 193 of file welder.hpp.

◆ weld_type()

template<rod B, class Style = naming::none, class Carriage = carriage>
template<class T>
auto welder::welder< B, Style, Carriage >::weld_type ( module_type & m,
const char * name = nullptr )
inlinestatic

Reflect over T and register it on module m.

A class type binds with its constructors, fields, methods, operators and native bases; an enum with its enumerators (see the carriage for the full set). Under the default (stitch) carriage T must be welded for B::language.

Template Parameters
Tthe class or enum type to bind.
Parameters
mthe module handle to register onto.
namethe target-language name (verbatim, beats weld_as), or nullptr to resolve T's weld_as/styled name.
Returns
the rod's class/enum handle, for chaining further registrations.

Definition at line 111 of file welder.hpp.

◆ weld_variable()

template<rod B, class Style = naming::none, class Carriage = carriage>
template<std::meta::info Var>
auto welder::welder< B, Style, Carriage >::weld_variable ( module_type & m,
const char * name = nullptr )
inlinestatic

Reflect over global/namespace variable Var and register it on module m.

The semi-manual analogue of what namespace binding does for a namespace's variables: expose one hand-picked global or constant directly. A const/constexpr Var becomes a value snapshot; a mutable one a live get/set property over the C++ global. Under the default (stitch) carriage Var must be welded for B::language.

Template Parameters
Vara reflection of the namespace-scope variable.
Parameters
mthe module handle to register onto.
namethe target name, used verbatim and taking precedence over any [[=welder::weld_as]] on Var; nullptr (default) resolves the weld_as/styled name.
Returns
whatever the rod's add_variable hands back; the shipped rods return void — a bound constant is a value snapshot, a mutable global a module property, neither has a framework object worth returning — but a rod that yields one sees it forwarded.

Definition at line 164 of file welder.hpp.

Member Data Documentation

◆ noop

template<rod B, class Style = naming::none, class Carriage = carriage>
auto welder::welder< B, Style, Carriage >::noop {[](module_type&) {}}
staticconstexpr

A do-nothing module hook; the default for weld_module()'s pre/post.

Definition at line 96 of file welder.hpp.

Referenced by weld_module().


The documentation for this struct was generated from the following file: