Skip to content
Tcl Source Code History Of Ticket 008773b7a3
Login

History Of Ticket 008773b7a3

Artifacts Associated With Ticket 008773b7a3

  1. Ticket change [c29d6162a0] (rid 243445) by arvind29 on 2025-07-24 08:56:18:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-fossil-plain"
    4. comment initialized to:
      During the execution of a user command I need to report the script file name and line number if the command is inside a script file. The Tcl_Interp errorLine member variable is updated only if the command returns TCL_ERROR code, otherwise I can't see any way to find out the current command, line number and file name.
      
    5. foundin initialized to: "8.6.8"
    6. is_private initialized to: "0"
    7. login: "arvind29"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "24b6332679e5f96732dab3b9d46f1f0d512b2551"
    10. resolution initialized to: "None"
    11. severity initialized to: "Critical"
    12. status initialized to: "Open"
    13. submitter initialized to: "arvind29"
    14. subsystem initialized to: "45. Parsing and Eval"
    15. title initialized to:
      how to log Tcl commands that are executed via the source command using the Tcl C API
      
    16. type initialized to: "Support"
  2. Ticket change [bd56dcce5f] (rid 243446) by sebres on 2025-07-24 10:29:12:

    1. closedate changed to: "2460880.93694851"
    2. closer changed to: "sebres"
    3. icomment:
      At top level in source, you can use `[info script]` or at C-level `((Interp*)interp)->scriptFile`.
      
      Everywhere in script (not at top level only, but also in proc or namespace), you can get a dict with the file and line with `[info frame 0]` or at C-level `TclInfoFrame` (internal only).
      
      You can try this to see how it works:
      
      ```
        puts [info script]
        puts [info frame 0]
        proc test {} {
          puts [info frame 0]
        }
        test
        namespace eval test {
          puts [info frame 0]
        }
        eval [concat apply {{{} {puts [info frame 0]; puts [info frame 1]}}}]
        {*}[list if 1 {puts [info frame 0]; puts [info frame 1]}]
        after 0 {puts [info frame 0]; puts [info frame 1]}
        update
      ```
      
      Calling from C-level of command, you can obtain the frame info either with TclInfoFrame (if you have Tcls internals and it is a bit complex, see Tcls source code),<br/>
      or using `objProc()` of Command `::tcl::info::frame` called with int-object 0, 1, or whatever level you need.
      
      Or with something like this:
      
      ```
        if (Tcl_Eval(interp, "info frame 1") != TCL_OK) return TCL_ERROR;
        Tcl_Obj *res = Tcl_GetObjResult(interp);
      ```
      And then use `Tcl_DictObjGet` to obtain `file` and `line` from result dict.<br/>
      Note that it uses 1 as level to obtain frame from parent (caller), because Tcl_Eval would also insert a frame during its execution.
      
      Also note that this frame info may not contain the source file and line information, if the command is invoked not directly from source, but asynchronously as events or from code dynamically built and evaluated hereafter (see last 3 examples above), so you may need to traverse over upper levels (e. g. `info frame 2` etc) till you'd find the caller frame containing the info.
      However there are cases where obtaining of origin may be impossible at all, because not every "evaluable" tcl-object contains line information with its origin (since the Tcl is JIT compiler, and TEBC compilation, NRE trampoline, etc may make it too difficult or almost impossible for certain constellations).
      
    4. login: "sebres"
    5. mimetype: "text/x-markdown"
    6. status changed to: "Closed"
  3. Ticket change [f7873cdad4] (rid 245410) by arvind29 on 2025-09-15 11:09:37:

    1. closedate changed to: "2460933.9650125"
    2. closer changed to: "arvind29"
    3. icomment:
      I'm not sure how to implement this. Could you please explain it step by step?
      
    4. login: "arvind29"
    5. mimetype: "text/plain"
  4. Ticket change [032827544a] (rid 245411) by arvind29 on 2025-09-15 11:09:46:

    1. closer changed to: "nobody"
    2. login: "arvind29"
    3. mimetype: "text/plain"
    4. status changed to: "Open"