![]() |
rego-cpp 1.0.0
A C++ implementation of the Rego language and runtime
|
Struct which defines a built-in function. More...
#include <rego.hh>
Public Member Functions | |
| BuiltInDef (Location name_, Node decl_, BuiltInBehavior behavior_, bool available_) | |
| Constructor. | |
| virtual void | clear () |
| Called to clear any persistent state or caching. | |
Static Public Member Functions | |
| static BuiltIn | create (const Location &name, Node decl, BuiltInBehavior behavior) |
| Creates a new built-in. | |
| static BuiltIn | create (const Location &name, size_t arity, BuiltInBehavior behavior) |
| Creates a new built-in. | |
| static BuiltIn | placeholder (const Location &name, Node decl, const std::string &message) |
| Creates a placeholder for a built-in which is not available on this platform. | |
Public Attributes | |
| Location | name |
| The name used to match against expression calls in the rego program. | |
| Node | decl |
| The declaration node which adheres to the builtins::wf_decl well-formedness definition. | |
| std::size_t | arity |
| The number of expected arguments. | |
| BuiltInBehavior | behavior |
| The function which will be called when the built-in is evaluated. | |
| bool | available |
| Whether the builtin is available. | |
Struct which defines a built-in function.
You can extend Rego by registering your own built-ins. A built-in is a function which is called by Rego during evaluation. Built-ins are called with a vector of Nodes, and return a Node. The vector of Nodes contains the arguments passed to the built-in. The Node returned by the built-in is the result of the built-in's evaluation.
Here is an example built-in which performs addition:
Note that there are several helper methods and objects to aid in writing managing nodes and wrapping/unwrapping them into basic types. Once a method like the above has been written, use BuiltInDef::create following way:
Then, during evaluation, any call to the built-in myadd will be handled by the myadd function.
|
static |
Creates a new built-in.
The decl node adheres to the builtins::wf_decl well-formedness definition. BuiltIn is a pointer to a BuiltInDef.
| name | The name of the built-in. |
| decl | Metadata and documentation for the built-in. |
| behavior | The function which will be called when the built-in is evaluated. |
|
static |
Creates a new built-in.
An empty decl node with the correct arity and a return type of Any will be automatically created from the arity argument. ///
| name | The name of the built-in. |
| arity | Number of arguments to the builtin |
| behavior | The function which will be called when the built-in is evaluated. |
|
static |
Creates a placeholder for a built-in which is not available on this platform.
The decl node adheres to the builtins::wf_decl well-formedness definition. BuiltIn is a pointer to a BuiltInDef.
| name | The name of the built-in. |
| decl | Metadata and documentation for the built-in. |
| message | The message to include in the error when the built-in is called. |
| std::size_t rego::BuiltInDef::arity |
The number of expected arguments.
If any number of arguments can be provided, use the constant AnyArity.