welder
0.1.0
Bindings for annotated C++ types, from C++26 reflection
Toggle main menu visibility
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
24
namespace
welder::inline v0::
rods::sol2
{
25
28
struct
metamethod
{
29
::sol::meta_function
fn
;
30
const
char
*
name
;
31
};
32
45
consteval
metamethod
operator_mm
(std::meta::info f) {
46
using
std::meta::operators;
47
using
mf = ::sol::meta_function;
48
const
char
* name{
::welder::rods::lua::lua_metamethod_name
(f)};
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
bind_traits.hpp
Backend-agnostic selection layer: the reflection predicates and selectors that decide what participat...
metamethods.hpp
The C++-operator → Lua metamethod name map, shared by both Lua runtime rods (sol2 and LuaBridge3).
welder::detail::is_unary_operator
consteval bool is_unary_operator(std::meta::info f)
Whether a member operator is unary (0 parameters) vs binary (1 parameter).
Definition
bind_traits.hpp:264
welder::rods::lua::lua_metamethod_name
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...
Definition
metamethods.hpp:49
welder::rods::sol2
Definition
metamethods.hpp:24
welder::rods::sol2::operator_mm
consteval metamethod operator_mm(std::meta::info f)
Map a member operator to its sol2 metamethod ({…, nullptr} = not exposed).
Definition
metamethods.hpp:45
welder::rods::sol2::metamethod
A member operator's sol2 metamethod, or {…, nullptr} if welder does not expose it.
Definition
metamethods.hpp:28
welder::rods::sol2::metamethod::fn
::sol::meta_function fn
The sol2 metamethod slot.
Definition
metamethods.hpp:29
welder::rods::sol2::metamethod::name
const char * name
Its __name, or nullptr if not exposed.
Definition
metamethods.hpp:30
src
welder
rods
lua
sol2
metamethods.hpp
Generated by
1.17.0