minilua::mt namespace

contains the metatable events.

Contents

That is everything that can be customized using a metamethod.

The functions have the same name as the metamethods (except without leading __). These names don't always match the method names on Value.

If the required metamethod is not present (or the value is not a table) these functions will simply call the corresponding functions on the Value.

Binary events first check the left value for the metamethod and if that is not present they check the right side.

Functions

auto index(const CallContext& ctx) -> CallResult -> auto
Index into a Table or calls __index of the metatable.
auto newindex(const CallContext& ctx) -> CallResult -> auto
Index into a Table or calls __index of the metatable.
auto add(const CallContext& ctx, std::optional<Range> location = std::nullopt) -> CallResult -> auto
Add (binary +) operator. Will call metamethod __add if necessary.
auto sub(const CallContext& ctx, std::optional<Range> location = std::nullopt) -> CallResult -> auto
Sub (binary -) operator. Will call metamethod __sub if necessary.
auto mul(const CallContext& ctx, std::optional<Range> location = std::nullopt) -> CallResult -> auto
Mul (binary *) operator. Will call metamethod __mul if necessary.
auto div(const CallContext& ctx, std::optional<Range> location = std::nullopt) -> CallResult -> auto
Div (binary /) operator. Will call metamethod __div if necessary.
auto mod(const CallContext& ctx, std::optional<Range> location = std::nullopt) -> CallResult -> auto
Mod (binary %) operator. Will call metamethod __mod if necessary.
auto pow(const CallContext& ctx, std::optional<Range> location = std::nullopt) -> CallResult -> auto
Pow (binary ^) operator. Will call metamethod __pow if necessary.
auto idiv(const CallContext& ctx, std::optional<Range> location = std::nullopt) -> CallResult -> auto
Floor division (binary //) operator. Will call metamethod __idiv if necessary.
auto band(const CallContext& ctx, std::optional<Range> location = std::nullopt) -> CallResult -> auto
Bitwise and (binary &) operator. Will call metamethod __band if necessary.
auto bor(const CallContext& ctx, std::optional<Range> location = std::nullopt) -> CallResult -> auto
Bitwise or (binary |) operator. Will call metamethod __bor if necessary.
auto bxor(const CallContext& ctx, std::optional<Range> location = std::nullopt) -> CallResult -> auto
Bitwise xor (binary ~) operator. Will call metamethod __bxor if necessary.
auto shl(const CallContext& ctx, std::optional<Range> location = std::nullopt) -> CallResult -> auto
Bitwise left shift (binary <<) operator. Will call metamethod __shl if necessary.
auto shr(const CallContext& ctx, std::optional<Range> location = std::nullopt) -> CallResult -> auto
Bitwise right shift (binary >>) operator. Will call metamethod __shr if necessary.
auto concat(const CallContext& ctx, std::optional<Range> location = std::nullopt) -> CallResult -> auto
Concatenation (binary ..) operator. Will call metamethod __concat if necessary.
auto eq(const CallContext& ctx, std::optional<Range> location = std::nullopt) -> CallResult -> auto
Equal (binary ==) operator. Will call metamethod __eq if necessary.
auto lt(const CallContext& ctx, std::optional<Range> location = std::nullopt) -> CallResult -> auto
Less than (binary <) operator. Will call metamethod __lt if necessary.
auto le(const CallContext& ctx, std::optional<Range> location = std::nullopt) -> CallResult -> auto
Less than (binary <=) operator. Will call metamethod __le if necessary.
auto unm(const CallContext& ctx, std::optional<Range> location = std::nullopt) -> CallResult -> auto
Negation (unary -) operator. Will call metamethod __unm if necessary.
auto bnot(const CallContext& ctx, std::optional<Range> location = std::nullopt) -> CallResult -> auto
Bitwise not (unary ~) operator. Will call metamethod __bnot if necessary.
auto len(const CallContext& ctx, std::optional<Range> location = std::nullopt) -> CallResult -> auto
Length (unary #) operator. Will call metamethod __len if necessary.
auto call(const CallContext& ctx) -> CallResult -> auto
Call (func(args)) operator. Will call metamethod __call if necessary.
void gc(const CallContext& ctx)
Called when a table is garbage collected. Will call metamethod __gc.

Function documentation

auto minilua::mt::index(const CallContext& ctx) -> CallResult

Index into a Table or calls __index of the metatable.

The metatable is only used if the key is not present in the table.

auto minilua::mt::newindex(const CallContext& ctx) -> CallResult

Index into a Table or calls __index of the metatable.

auto minilua::mt::eq(const CallContext& ctx, std::optional<Range> location = std::nullopt) -> CallResult

Equal (binary ==) operator. Will call metamethod __eq if necessary.

Lua will only try the metamethods if both values are the same type and not trivially equal.

The result is always converted to a bool.

auto minilua::mt::lt(const CallContext& ctx, std::optional<Range> location = std::nullopt) -> CallResult

Less than (binary <) operator. Will call metamethod __lt if necessary.

The result is always converted to a bool.

auto minilua::mt::le(const CallContext& ctx, std::optional<Range> location = std::nullopt) -> CallResult

Less than (binary <=) operator. Will call metamethod __le if necessary.

The lua spec also specifies that if the __le metamethod is not present it will try a __lt metamethod with reversed parameters. But it states that this behaviour might be removed in the future (this assumes that a <= b is equal to b < a).

The result is always converted to a bool.

auto minilua::mt::call(const CallContext& ctx) -> CallResult

Call (func(args)) operator. Will call metamethod __call if necessary.

The metamethod is only searched in func and it will get func and the arguments args as parameters.

This metamethod allows multiple results.

void minilua::mt::gc(const CallContext& ctx)

Called when a table is garbage collected. Will call metamethod __gc.

In our case the tables are all garbage collected at once when the lua program stops running.