Skip to main content

Module scripting

Module scripting 

Source
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 expressions
  • mdv.render(template, context) - Render templates with variables
  • mdv.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 name
  • mdv.capture(name, vars?) - Execute a capture workflow
  • mdv.macro(name, vars?) - Execute a macro workflow
  • mdv.read_note(path) - Read a note’s content and frontmatter
  • mdv.current_note() - Get the current note being processed
  • mdv.backlinks(path) - Get notes linking to a path
  • mdv.outlinks(path) - Get notes a path links to
  • mdv.query(opts) - Query the vault index
  • mdv.selector(opts) - Show interactive fuzzy selector for notes of a type

§Security

By default, the Lua environment is sandboxed to prevent:

  • File system access (io library removed)
  • Shell command execution (os library removed)
  • Loading external modules (require removed)
  • Arbitrary code loading (load, loadfile, dofile removed)
  • Debug library access (debug removed)

Re-exports§

pub use engine::LuaEngine;
pub use hook_runner::HookResult;
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 selector::SelectorCallback;
pub use selector::SelectorItem;
pub use selector::SelectorOptions;
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.
selector
Interactive selector types for Lua scripting.
types
Scripting types and error definitions.
vault_bindings
Vault operation bindings for Lua.
vault_context
Vault context for Lua scripting.