WIP: Add timerexistsname and utimerexistsname Tcl commands to check timer existence#1807
WIP: Add timerexistsname and utimerexistsname Tcl commands to check timer existence#1807ZarTek-Creole wants to merge 5 commits intoeggheads:developfrom
timerexistsname and utimerexistsname Tcl commands to check timer existence#1807Conversation
Add new Tcl commands `timerexists` and `utimerexists` to check if a timer or utimer with a given name exists. This enhances scripting capabilities and debugging of timers. Patch by: ZarTek-Creole
| { | ||
| BADARGS(2, 2, " timerName"); | ||
|
|
||
| if (find_timer(timer, argv[1])) { |
There was a problem hiding this comment.
Tcl_AppendResult() is deprecated. Use Tcl_SetResult() if you can. You could do a one-liner, something like:
Tcl_SetResult(interp, find_timer(timer, argv[1]) ? "1" : "0", TCL_STATIC);
|
i guess you want to add the documentation to doc/sphinx_source/using/tcl-commands.rst |
|
is there any relation to #507? |
There was a problem hiding this comment.
Tcl_AppendResult()is deprecated. UseTcl_SetResult()if you can. You could do a one-liner, something like:
Tcl_SetResult(interp, find_timer(timer, argv[1]) ? "1" : "0", TCL_STATIC);
Good point 👍
You're right — Tcl_AppendResult() has been deprecated since Tcl 8.4, and your Tcl_SetResult() one-liner is perfectly clean for this static return value.
Updated implementation:
Tcl_SetResult(interp, find_timer(timer, argv[1]) ? "1" : "0", TCL_STATIC);For even better Tcl 8.5+ compatibility (or native boolean handling), this would be more future-proof:
Tcl_SetObjResult(interp, Tcl_NewBooleanObj(find_timer(timer, argv[1]) != NULL));This makes [timerexists foo] return a native Tcl boolean, which works seamlessly with if and other logic. That said, the current "1"/"0" strings are still fine and match the codebase's conventions.
References:
Tcl_SetResult()(Tcl 8.4 docs)Tcl_NewBooleanObj()(Tcl 8.6 docs)Tcl_SetObjResult()(Tcl 8.6 docs)
Thanks for the helpful feedback — it's been applied!
i guess you want to add the documentation to doc/sphinx_source/using/tcl-commands.rst
Good catch — I'll add this to the docs in tcl-commands.rst.
is there any relation to #507?
Not directly, though #507 might benefit from similar cleanup. I'll check the ticket and update if needed.
…xists and tcl_utimerexists functions.`
|
Good idea but with another name, as |
timerexists and utimerexists Tcl commands to check timer existencetimerexistsname and utimerexistsname Tcl commands to check timer existence
✅ Title
📝 Description
With this feature:
utimer 1 myTimer 0 myTimer if {[utimerexists myTimer]} { killutimer myTimer }🧩 Integration details
src/tclmisc.ckilltimer/killutimerdoc/tcl-commands.doc)