Rusty Rules Lua Bindings
This crate provides Lua bindings for the rusty_rules crate, allowing you to create and
evaluate rule-based conditions from within Lua scripts.
Overview
The library exposes two main types:
- [
Engine] - The main rules engine for registering fetchers and compiling rules - [
Rule] - A compiled rule that can be evaluated against context data
Basic Usage
use *;
// Register the Engine type
#
-- Create a new engine instance
local engine = Engine.
-- Register a simple fetcher that extracts values from context
engine:
-- Compile and evaluate a rule
local rule = engine:
local result = rule:
-- `result` will be true
Advanced Features
Custom Matchers
You can specify custom matchers for different data types:
-- Register an IP address fetcher with IP matcher
engine:
-- Use CIDR notation in rules
local rule = engine:
Available matchers:
"bool"- Boolean matching"ip"- IP address and CIDR range matching"number"- Numeric comparison"regex"or"re"- Regular expression matching"string"- String comparison
The default matcher (if unspecified) is a universal matcher for all types.
Raw Arguments
By default, fetcher arguments are split by whitespace and trimmed. You can disable this:
engine:
Rule Validation
When the validation feature is enabled, you can validate rules without compiling them:
local is_valid, error = engine:
-- `error` is: "Additional properties are not allowed ('get_value(key)' was unexpected)"
Validation check the rule structure against the json schema.
JSON Schema
Get the JSON schema for valid rule structures:
-- Returns JSON schema as a string
local schema = engine: