html-mumu 0.1.6

HTML manipulation and tools plugin for the Lava/MuMu language
Documentation
// src/lib.rs
use std::sync::{Arc, Mutex};
use mumu::parser::interpreter::{Interpreter, DynamicFn, DynamicFnInfo};
use mumu::parser::types::{FunctionValue, Value};

mod extract;
pub use extract::*;

/// Register all public functions exported by this plugin.
/// Call this from the plugin entrypoint, and also from wasm/static builds.
pub fn register_all(interp: &mut Interpreter) {
    // html:extract_text
    let func: DynamicFn = Arc::new(Mutex::new(extract_text_bridge));
    let info = DynamicFnInfo::new(func, true); // pure
    interp.register_dynamic_function_ex("html:extract_text", info);

    // Bind a callable variable so identifiers resolve at call sites.
    interp.set_variable(
        "html:extract_text",
        Value::Function(Box::new(FunctionValue::Named("html:extract_text".to_string()))),
    );
}

/// Host/dynamic loader entrypoint (extend("html")).
/// Export **only** in non-wasm builds to keep wasm linking clean.
#[cfg(not(target_arch = "wasm32"))]
#[no_mangle]
pub extern "C" fn Cargo_lock(
    interp_ptr: *mut ::std::ffi::c_void,
    _extra: *const ::std::ffi::c_void,
) -> i32 {
    if interp_ptr.is_null() {
        eprintln!("[html plugin] null interpreter pointer");
        return 1;
    }
    let interp = unsafe { &mut *(interp_ptr as *mut Interpreter) };
    register_all(interp);
    0
}