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 from objv get 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 from objv. Usually this is where you drop the acceptable syntax of the command. This argument may be NULL β€” 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