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

Full-automation entry point for the LuaBridge3 Lua rod: the expansion behind WELDER_MODULE(ns, luabridge). More...

Include dependency graph for module.hpp:

Go to the source code of this file.

Macros

#define WELDER_DETAIL_LUAOPEN_EXPORT   __attribute__((visibility("default")))
 Export decoration for the emitted luaopen_<ns> symbol (platform-conditional by necessity, like pybind11's/nanobind's own entry-point export macros).
#define WELDER_DETAIL_MODULE_ENTRY_luabridge(ns, ...)
 LuaBridge3's expansion of the backend-agnostic WELDER_MODULE(ns, luabridge).

Detailed Description

Full-automation entry point for the LuaBridge3 Lua rod: the expansion behind WELDER_MODULE(ns, luabridge).

Include this (instead of rod.hpp) when you want welder to emit the module's luaopen_ entry symbol too, so no hand-written glue appears in user code:

#include <LuaBridge/LuaBridge.h>
WELDER_MODULE(mymod, luabridge) {} // luaopen_mymod + namespace ^^mymod bound
#define WELDER_MODULE(ns, rod,...)
Emit a binding module's entry point and weld a namespace into it.
Definition module.hpp:78
Full-automation entry point for the LuaBridge3 Lua rod: the expansion behind WELDER_MODULE(ns,...

Definition in file module.hpp.

Macro Definition Documentation

◆ WELDER_DETAIL_LUAOPEN_EXPORT

#define WELDER_DETAIL_LUAOPEN_EXPORT   __attribute__((visibility("default")))

Export decoration for the emitted luaopen_<ns> symbol (platform-conditional by necessity, like pybind11's/nanobind's own entry-point export macros).

On Windows any explicit dllexport elsewhere in the TU — e.g. nanobind's headers, when a multi-language header is shared across rods — disables MinGW's export-everything default, so the entry symbol must be exported explicitly or require fails with "the specified procedure could not be found". On ELF/Mach-O it pins default visibility, so a TU compiled with -fvisibility=hidden (common in Python-extension builds) still exposes it.

Definition at line 31 of file module.hpp.

◆ WELDER_DETAIL_MODULE_ENTRY_luabridge

#define WELDER_DETAIL_MODULE_ENTRY_luabridge ( ns,
... )
Value:
static void welder_glue_##ns##_luabridge( \
extern "C" WELDER_DETAIL_LUAOPEN_EXPORT int luaopen_##ns( \
lua_State* welder_lua_state_) { \
welder_lua_state_, {#ns}}; \
using welder_weld_ = ::welder::detail::module_welder_t< \
::welder::welder<::welder::rods::luabridge::rod> \
__VA_OPT__(, ) __VA_ARGS__>; \
static_assert( \
::std::is_same_v<typename welder_weld_::module_type, \
::welder::rods::luabridge::rod::module_type>, \
"WELDER_MODULE(ns, luabridge, W): W must be a welder::welder over a " \
"rod whose module handle is the LuaBridge3 rod's module_type"); \
welder_weld_::weld_module<^^ns>( \
welder_module_var_, welder_weld_::noop, \
[](::welder::rods::luabridge::rod::module_type& welder_glue_m_) { \
welder_glue_##ns##_luabridge(welder_glue_m_); \
}); \
lua_getglobal(welder_lua_state_, #ns); /* the module table */ \
lua_pushnil(welder_lua_state_); \
lua_setglobal(welder_lua_state_, #ns); /* keep _G clean */ \
return 1; \
} \
static void welder_glue_##ns##_luabridge( \
typename module_welder< Default, Override... >::type module_welder_t
Definition module.hpp:26
#define WELDER_DETAIL_LUAOPEN_EXPORT
Export decoration for the emitted luaopen_<ns> symbol (platform-conditional by necessity,...
Definition module.hpp:31
module_scope module_type
A Lua module is a named table.
Definition rod.hpp:153

LuaBridge3's expansion of the backend-agnostic WELDER_MODULE(ns, luabridge).

Emits the luaopen_<ns> C entry point Lua's require calls. LuaBridge3 registers into named namespaces under the global table, so welder builds the module under _G["<ns>"], runs the optional trailing { } block as post-glue (the module handle named module in scope), then returns that table to Lua and clears the _G binding (so require yields the table without leaving a global behind). The block is supplied as the body of a forward-declared, internally- linked glue function (the technique the other rods' entry macros use), so both WELDER_MODULE(ns, luabridge) { … } and {} work. Defined at file scope (macros ignore namespaces); see <welder/module.hpp>.

Parameters
nsthe namespace / module name token (doubles as the luaopen_ symbol).
...optionally, the exact welder::welder<…> type to weld with (must be over a LuaBridge3-module rod) — see WELDER_MODULE.

Definition at line 51 of file module.hpp.