Tcl_RecordAndEvalObj(3)
π Tcl_RecordAndEvalObj β bestie, it's a Tcl Library Procedure π
okay so real talk, this one lives in section 3 of the Tcl manual and it's lowkey one of the most useful lil functions in the whole interpreter toolbox. let's get into it π«Ά
β¨ NAME β¨
Tcl_RecordAndEvalObj β save a command on the history list before evaluating it. that's it. that's the whole vibe. π
πΈ SYNOPSIS πΈ
#include <tcl.h>
int
Tcl_RecordAndEvalObj(interp, cmdPtr, flags)
π ARGUMENTS π
Tcl_Interp *interp(in) β the Tcl interpreter where we're gonna go evaluate this command. it's giving "the stage" πTcl_Obj *cmdPtr(in) β points to a Tcl value that holds a command (or honestly a whole sequence of commands, we don't judge) to execute. this is the main character of the function, fr fr πint flags(in) β an OR'ed combination of flag bits. yes, OR'ed, as in you can stack them, we love a flexible girlie:TCL_NO_EVALβ record the command but do not evaluate it. just write it down and move on, no execution, nope πTCL_EVAL_GLOBALβ evaluate the command at the global level instead of at the current stack level. so it's going straight to the top, no local nonsense π
π¦ DESCRIPTION π¦
so you invoke Tcl_RecordAndEvalObj when you wanna do a little two-step: record a command as an event on the history list, then execute it using Tcl_EvalObjEx. it's a combo move. a one-two punch. iconic behavior β¨
it returns a completion code such as TCL_OK, exactly like Tcl_EvalObjEx does, and it also drops a result value containing extra info (could be a result value, could be an error message) that you can grab with Tcl_GetObjResult.
now listen β if you do not want the command recorded on the history list, then bestie you should be calling Tcl_EvalObjEx instead of Tcl_RecordAndEvalObj. that's the whole difference. pick your fighter π₯
normally Tcl_RecordAndEvalObj is only called with top-level commands typed by the user, because the entire point of history is letting the user re-issue commands they recently ran. like, that's the assignment. that's why it exists π
and if the flags argument contains the TCL_NO_EVAL bit? then the command gets recorded without being evaluated. recorded and left alone. noted but not acted upon. very "I saw your text and I'm not replying" energy π
π§ REFERENCE COUNT MANAGEMENT π§
okay this part is IMPORTANT, pay attention, no scrolling past π¨
- the reference count of the
cmdPtrargument toTcl_RecordAndEvalObjmust be at least 1. - this function will modify the interpreter result. so do not use an existing result as
cmdPtrdirectly without incrementing its reference count first.
fr fr, if you skip that increment you are asking for chaos and the chaos will answer. π
π SEE ALSO π
Tcl_EvalObjExTcl_GetObjResult
β KEYWORDS β
command, event, execute, history, interpreter, value, record
and that's the whole page, bestie!! π
this one came straight out of Tcl 8.0, dated with the classic Tcl_RecordAndEvalObj(3) footer energy β go forth and record those commands responsibly ππ
π¦ where this page comes from
- alpine 3.23: tcl9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tcl9-doc 9.0.3-r2 Β· TCL
- fedora 43: tcl-doc 1:9.0.2-1.fc43 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- fedora 44: tcl-doc 1:9.0.2-1.fc44 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- nixos 26.05: tcl 9.0.3
- nixpkgs unstable: tcl 9.1.0
- Copyright (c) 1997 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms