class
FunctionA lua function value.
Contents
A function (in lua or implemented natively in C++).
Notes for implementing native functions:
You get a CallContext
as only argument. You can retrieve the actual arguments and the global environment from the context.
When using lua Value
s you can use the normal C++ operators. Note that ^
performs the pow operation like in lua (and not xor like usually in C++). These operators will track the origin and can be later forced to a different value.
Care must be taken when there are control flow constructs in your native function (e.g. if
, while
, ...). Because this might break the source change mechanism if you use operators on Value
s. If you use control flow constructs you should remove the origin from the returned Value with Value::
.
Is hashable.
Public static variables
- static static const std::string_view TYPE constexpr
- The type of this value as a string.
Constructors, destructors, conversion operators
-
template<typename Fn, typename = std::enable_if_t<std::is_invocable_v<Fn, CallContext>>>Function(Fn fn)
- Create a function from a callable (e.g. lambda, function pointer).
-
template<typename Fn, typename = std::enable_if_t<std::is_invocable_v<Fn, CallContext>>>Function(Fn fn, std::string name)
- Create a function from a callable and the given name.
- operator bool() const explicit
- Convert the value to a bool (always
true
).
Public functions
- auto to_literal() const -> std::string -> auto
- Converts the value to it's literal representation.
- auto call(CallContext) const -> CallResult -> auto
- Calls the function.
Friends
Function documentation
auto minilua:: Function:: to_literal() const -> std::string
Converts the value to it's literal representation.
Always throws an exception. Just here for convenience.