pub fn getmathfunc(
table: &mut modulestab,
name: &str,
autol: i32,
) -> Option<String>Expand description
Port of getmathfunc(const char *name, int autol) from Src/module.c:1283.
C body: linear-search mathfuncs for name; if found and autol
is true and the entry is autoloadable, demand-load via
ensurefeature("f:", name). Returns the resolved entry or NULL.
Rust port returns Some(module_name) on hit, None on miss.
Faithful port of c:1283-1306:
MathFunc
getmathfunc(const char *name, int autol)
{
MathFunc p, q = NULL;
for (p = mathfuncs; p; q = p, p = p->next)
if (!strcmp(name, p->name)) {
if (autol && p->module && !(p->flags & MFF_USERFUNC)) {
char *n = dupstring(p->module);
int flags = p->flags;
removemathfunc(q, p);
(void)ensurefeature(n, "f:",
(flags & MFF_AUTOALL) ? NULL : name);
p = getmathfunc(name, 0);
if (!p) {
zerr("autoloading module %s failed to define math function: %s", n, name);
}
}
return p;
}
return NULL;
}C walks mathfuncs (file-static linked list) — Rust walks
MATHFUNCS (same shape, Vec). The MFF_USERFUNC filter
(functions -M user-defined math) keeps user fns from being
autoloaded out from under the caller. The autoload arm:
- snapshot module name + flags
- removemathfunc(name) — drop the autoload stub
- ensurefeature(module, “f:”, AUTOALL?NULL:name) — load real
- re-query mathfuncs (autol=0) — return the loaded entry
- zerr if still missing (load failed to populate the table) WARNING: param names don’t match C — Rust=(table, name, autol) vs C=(name, autol)