Tcl_WrongNumArgs(3)
β¨ NAME β¨
Tcl_WrongNumArgs β the glow-up your command needs when someone passes the wrong number of arguments π
(it generates the standard error message, bestie, no cap)
πΈ SYNOPSIS πΈ
#include <tcl.h>
Tcl_WrongNumArgs(interp, objc, objv, message)
π ARGUMENTS π
Tcl_Interp interp(in) β the interpreter where the error gets reported. The error message gets stored in its result value, so like, that's where it lives now π«ΆTcl_Size objc(in) β how many leading arguments fromobjvget included in the error message. The headcount, basically.Tcl_Obj *const objv[](in) β the arguments to the command that had the wrong number of arguments. The actual receipts of what got passed in.const char *message(in) β extra error info printed after the leading arguments fromobjv. Usually this is where you drop the acceptable syntax of the command. This argument may beNULLβ it's optional, she's flexible π
π DESCRIPTION π
So Tcl_WrongNumArgs is a utility procedure that command procedures call when they discover they've been handed the wrong number of arguments. Rude of the caller, honestly. Tcl_WrongNumArgs generates a standard error message and stores it in the result value of interp. That message contains the objc initial elements of objv plus message.
For example, if objv consists of the values foo and bar, objc is 1, and message is βfileName countβ then interp's result value will be set to the following string:
wrong # args: should be "foo fileName count"
And if objc is 2, the result will be set to the following string:
wrong # args: should be "foo bar fileName count"
objc is usually 1, but it may be 2 or more for commands like string and the Tk widget commands, which use the first argument as a subcommand. So the first arg is basically the main character and the rest are the supporting cast β¨
Some of the values in the objv array may be abbreviations for a subcommand. The command Tcl_GetIndexFromObj will convert that abbreviated string value into an indexObject. If an error occurs while parsing the subcommand, we'd rather use the full subcommand name than the abbreviation β like, give the people the whole name, not the nickname. So if Tcl_WrongNumArgs finds any indexObjects in the objv array, it will use the full subcommand name in the error message instead of the abbreviated name that was originally passed in.
Using the example above, let's assume that bar is actually an abbreviation for barfly and the value is now an indexObject because it was passed to Tcl_GetIndexFromObj. In that case the error message would be:
wrong # args: should be "foo barfly fileName count"
See? Full name restored, the abbreviation got unmasked, iconic π
π¦ REFERENCE COUNT MANAGEMENT π¦
The objv argument to Tcl_WrongNumArgs should be the exact arguments passed to the command or method implementation function that is calling Tcl_WrongNumArgs. As such, all values referenced in it should have reference counts greater than zero β this is usually a non-issue, so don't stress, bestie π§ββοΈ
π SEE ALSO π
β KEYWORDS β
command, error message, wrong number of arguments
Okay so that's the whole page, and you ate that π
This was the Tcl_WrongNumArgs(3) page from the Tcl Library Procedures, sitting pretty at Tcl 8.0 β catch you in the next one, mwah π«Άβ¨
π¦ 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
- Copyright (c) 1994-1997 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms