Expand description
Lua scripting support for mdvault.
This module provides a sandboxed Lua environment with access to mdvault’s date math and template rendering engines.
§Overview
The scripting layer allows users to define custom validation logic, type definitions, and automation rules in Lua while having access to mdvault’s core functionality.
§Example
use mdvault_core::scripting::LuaEngine;
let engine = LuaEngine::sandboxed().unwrap();
// Use date math
let date = engine.eval_string(r#"mdv.date("today + 7d")"#).unwrap();
println!("One week from now: {}", date);
// Render templates
let greeting = engine.eval_string(
r#"mdv.render("Hello {{name}}!", { name = "World" })"#
).unwrap();
println!("{}", greeting);§Available Lua Functions
The mdv global table provides:
mdv.date(expr, format?)- Evaluate date math expressionsmdv.render(template, context)- Render templates with variablesmdv.is_date_expr(str)- Check if a string is a date expression
With vault context (via LuaEngine::with_vault_context):
mdv.template(name, vars?)- Render a template by namemdv.capture(name, vars?)- Execute a capture workflowmdv.macro(name, vars?)- Execute a macro workflowmdv.read_note(path)- Read a note’s content and frontmattermdv.current_note()- Get the current note being processedmdv.backlinks(path)- Get notes linking to a pathmdv.outlinks(path)- Get notes a path links tomdv.query(opts)- Query the vault index
§Security
By default, the Lua environment is sandboxed to prevent:
- File system access (
iolibrary removed) - Shell command execution (
oslibrary removed) - Loading external modules (
requireremoved) - Arbitrary code loading (
load,loadfile,dofileremoved) - Debug library access (
debugremoved)
Re-exports§
pub use engine::LuaEngine;pub use hook_runner::UpdateHookResult;pub use hook_runner::run_on_create_hook;pub use hook_runner::run_on_update_hook;pub use hooks::HookError;pub use hooks::NoteContext;pub use types::SandboxConfig;pub use types::ScriptingError;pub use vault_context::CurrentNote;pub use vault_context::VaultContext;
Modules§
- bindings
- Lua bindings for mdvault functionality.
- engine
- Lua scripting engine with sandboxing.
- hook_
runner - Hook execution for lifecycle events.
- hooks
- Hook types and errors.
- index_
bindings - Index query bindings for Lua.
- types
- Scripting types and error definitions.
- vault_
bindings - Vault operation bindings for Lua.
- vault_
context - Vault context for Lua scripting.