mdvault_core/scripting/mod.rs
1//! Lua scripting support for mdvault.
2//!
3//! This module provides a sandboxed Lua environment with access to
4//! mdvault's date math and template rendering engines.
5//!
6//! # Overview
7//!
8//! The scripting layer allows users to define custom validation logic,
9//! type definitions, and automation rules in Lua while having access
10//! to mdvault's core functionality.
11//!
12//! # Example
13//!
14//! ```rust
15//! use mdvault_core::scripting::LuaEngine;
16//!
17//! let engine = LuaEngine::sandboxed().unwrap();
18//!
19//! // Use date math
20//! let date = engine.eval_string(r#"mdv.date("today + 7d")"#).unwrap();
21//! println!("One week from now: {}", date);
22//!
23//! // Render templates
24//! let greeting = engine.eval_string(
25//! r#"mdv.render("Hello {{name}}!", { name = "World" })"#
26//! ).unwrap();
27//! println!("{}", greeting);
28//! ```
29//!
30//! # Available Lua Functions
31//!
32//! The `mdv` global table provides:
33//!
34//! - `mdv.date(expr, format?)` - Evaluate date math expressions
35//! - `mdv.render(template, context)` - Render templates with variables
36//! - `mdv.is_date_expr(str)` - Check if a string is a date expression
37//!
38//! With vault context (via `LuaEngine::with_vault_context`):
39//! - `mdv.template(name, vars?)` - Render a template by name
40//! - `mdv.capture(name, vars?)` - Execute a capture workflow
41//! - `mdv.macro(name, vars?)` - Execute a macro workflow
42//! - `mdv.read_note(path)` - Read a note's content and frontmatter
43//! - `mdv.current_note()` - Get the current note being processed
44//! - `mdv.backlinks(path)` - Get notes linking to a path
45//! - `mdv.outlinks(path)` - Get notes a path links to
46//! - `mdv.query(opts)` - Query the vault index
47//!
48//! # Security
49//!
50//! By default, the Lua environment is sandboxed to prevent:
51//! - File system access (`io` library removed)
52//! - Shell command execution (`os` library removed)
53//! - Loading external modules (`require` removed)
54//! - Arbitrary code loading (`load`, `loadfile`, `dofile` removed)
55//! - Debug library access (`debug` removed)
56
57pub mod bindings;
58pub mod engine;
59pub mod hook_runner;
60pub mod hooks;
61pub mod index_bindings;
62pub mod types;
63pub mod vault_bindings;
64pub mod vault_context;
65
66pub use engine::LuaEngine;
67pub use hook_runner::{UpdateHookResult, run_on_create_hook, run_on_update_hook};
68pub use hooks::{HookError, NoteContext};
69pub use types::{SandboxConfig, ScriptingError};
70pub use vault_context::{CurrentNote, VaultContext};