welder 0.1.0
Bindings for annotated C++ types, from C++26 reflection
Loading...
Searching...
No Matches
metamethods.hpp
Go to the documentation of this file.
1#pragma once
2#include <meta>
3
4#include <welder/bind_traits.hpp> // is_unary_operator
5#include <welder/rods/lua/metamethods.hpp> // shared operator -> Lua __name map
6
7#include <sol/sol.hpp>
8
23
24namespace welder::inline v0::rods::sol2 {
25
28struct metamethod {
29 ::sol::meta_function fn;
30 const char* name;
31};
32
45consteval metamethod operator_mm(std::meta::info f) {
46 using std::meta::operators;
47 using mf = ::sol::meta_function;
49 if (name == nullptr)
50 return {mf::index, nullptr};
51 const bool unary{::welder::detail::is_unary_operator(f)};
52 switch (std::meta::operator_of(f)) {
53 case operators::op_plus: return {mf::addition, name};
54 case operators::op_minus:
55 return unary ? metamethod{mf::unary_minus, name}
56 : metamethod{mf::subtraction, name};
57 case operators::op_star: return {mf::multiplication, name};
58 case operators::op_slash: return {mf::division, name};
59 case operators::op_percent: return {mf::modulus, name};
60 case operators::op_equals_equals: return {mf::equal_to, name};
61 case operators::op_less: return {mf::less_than, name};
62 case operators::op_less_equals: return {mf::less_than_or_equal_to, name};
63 case operators::op_parentheses: return {mf::call, name};
64 case operators::op_square_brackets: return {mf::index, name};
65#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 503
66 case operators::op_caret: return {mf::bitwise_xor, name};
67 case operators::op_tilde: return {mf::bitwise_not, name};
68 case operators::op_ampersand: return {mf::bitwise_and, name};
69 case operators::op_pipe: return {mf::bitwise_or, name};
70 case operators::op_less_less: return {mf::bitwise_left_shift, name};
71 case operators::op_greater_greater: return {mf::bitwise_right_shift, name};
72#endif
73 default: return {mf::index, nullptr};
74 }
75}
76
77} // namespace welder::rods::sol2
Backend-agnostic selection layer: the reflection predicates and selectors that decide what participat...
The C++-operator → Lua metamethod name map, shared by both Lua runtime rods (sol2 and LuaBridge3).
consteval bool is_unary_operator(std::meta::info f)
Whether a member operator is unary (0 parameters) vs binary (1 parameter).
consteval const char * 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 al...
consteval metamethod operator_mm(std::meta::info f)
Map a member operator to its sol2 metamethod ({…, nullptr} = not exposed).
A member operator's sol2 metamethod, or {…, nullptr} if welder does not expose it.
::sol::meta_function fn
The sol2 metamethod slot.
const char * name
Its __name, or nullptr if not exposed.