// Package dispatch exposes one helper for PRG code: a dynamic // "call this function by name" hook that pairs with fnode's auto- // renamed Main symbols. Lets the bridge dispatcher route an HTTP // path to the right Main without needing a hard-coded `DO CASE`. // // PRG surface // // cErr := FNODE_CALL(cFuncName) -> "" on success, error text on failure // // The called function runs on the same Thread; output is left in the // bridge_capi per-thread output buffer (use _OUT_GET to read it). // Return values from the called function are discarded — call the // generated symbol directly when you need its return value. package dispatch import ( "strings" "five/hbrt" ) func init() { hbrt.HB_FUNC("FNODE_CALL", fnodeCall) } func fnodeCall(ctx *hbrt.HBContext) { if ctx.PCount() < 1 || !ctx.IsChar(1) { ctx.RetC("FNODE_CALL: function name required") return } name := strings.ToUpper(ctx.ParC(1)) sym := ctx.T.VM().FindSymbol(name) if sym == nil { ctx.RetC("function not found: " + ctx.ParC(1)) return } ctx.T.PushSymbol(sym) ctx.T.PushNil() // self placeholder ctx.T.Function(0) _ = ctx.T.Pop2() // discard return value ctx.RetC("") }