mumuhtml/
lib.rs

1// src/lib.rs
2use std::sync::{Arc, Mutex};
3use mumu::parser::interpreter::{Interpreter, DynamicFn, DynamicFnInfo};
4use mumu::parser::types::{FunctionValue, Value};
5
6mod extract;
7pub use extract::*;
8
9/// Register all public functions exported by this plugin.
10/// Call this from the plugin entrypoint, and also from wasm/static builds.
11pub fn register_all(interp: &mut Interpreter) {
12    // html:extract_text
13    let func: DynamicFn = Arc::new(Mutex::new(extract_text_bridge));
14    let info = DynamicFnInfo::new(func, true); // pure
15    interp.register_dynamic_function_ex("html:extract_text", info);
16
17    // Bind a callable variable so identifiers resolve at call sites.
18    interp.set_variable(
19        "html:extract_text",
20        Value::Function(Box::new(FunctionValue::Named("html:extract_text".to_string()))),
21    );
22}
23
24/// Host/dynamic loader entrypoint (extend("html")).
25/// Export **only** in non-wasm builds to keep wasm linking clean.
26#[cfg(not(target_arch = "wasm32"))]
27#[no_mangle]
28pub extern "C" fn Cargo_lock(
29    interp_ptr: *mut ::std::ffi::c_void,
30    _extra: *const ::std::ffi::c_void,
31) -> i32 {
32    if interp_ptr.is_null() {
33        eprintln!("[html plugin] null interpreter pointer");
34        return 1;
35    }
36    let interp = unsafe { &mut *(interp_ptr as *mut Interpreter) };
37    register_all(interp);
38    0
39}