Tcl_BooleanObj(3tcl)
π¦ Tcl_BooleanObj π¦
okay bestie, welcome to the Tcl Library Procedures page for Tcl_BooleanObj β yes it's a whole manual page whose whole personality is "put a yes/no into a Tcl_Obj and get it back out". No cap, that's the entire plot. π
πΈ NAME πΈ
Tcl_NewBooleanObj, Tcl_SetBooleanObj, Tcl_GetBooleanFromObj, Tcl_GetBoolFromObj β store/retrieve boolean value in a Tcl_Obj π
β¨ SYNOPSIS β¨
#include <tcl.h>
Tcl_Obj *
Tcl_NewBooleanObj(intValue)
Tcl_SetBooleanObj(objPtr, intValue)
int
Tcl_GetBooleanFromObj(interp, objPtr, boolPtr)
int
Tcl_GetBoolFromObj(interp, objPtr, flags. charPtr)
π ARGUMENTS π
int intValue(in) β the integer value you wanna stash as a boolean value inside aTcl_Obj.Tcl_Obj *objPtr(in/out) β points at theTcl_Objyou're storing a boolean value into, or the one you're retrieving a boolean value from. She does both, she contains multitudes. π«ΆTcl_Interp *interp(in/out) β if a boolean value can't be retrieved, an error message gets left in the interpreter's result value β unlessinterpisNULL, in which case, nothing, silence, crickets.bool | int *boolPtr(out) β points to the place whereTcl_GetBooleanFromObjstores the boolean value (0or1) it obtained fromobjPtr.char *charPtr(out) β points to the place whereTcl_GetBoolFromObjstores the boolean value (0or1) it obtained fromobjPtr.int flags(in) β0orTCL_NULL_OK. IfTCL_NULL_OKis used, then the empty string orNULLwill result inTcl_GetBoolFromObjreturnTCL_OK, the*charPtrfilled with the value'\xFF';
π DESCRIPTION π
These procedures are literally the messenger service between you and Tcl when it comes to boolean values, and the messages travel as Tcl_Obj's. When you store a boolean value into a Tcl_Obj, any non-zero integer value in intValue is taken to be the boolean value 1, and the integer value 0 is taken to be the boolean value 0. That's the whole translation table, it's two entries, slay.
Tcl_NewBooleanObj creates a brand new Tcl_Obj, stores the boolean value intValue in it, and hands you back a pointer to the new Tcl_Obj. The new Tcl_Obj has reference count of zero β fresh out the box, zero commitments. β¨
Tcl_SetBooleanObj accepts objPtr, a pointer to an existing Tcl_Obj, and stores in the Tcl_Obj *objPtr the boolean value intValue. This is a write operation on *objPtr, so objPtr must be unshared. Attempts to write to a shared Tcl_Obj will panic. π A successful write of intValue into *objPtr implies the freeing of any former value stored in *objPtr β out with the old, in with the new.
Tcl_GetBooleanFromObj attempts to retrieve a boolean value from the value stored in *objPtr. If objPtr holds a string value recognized by Tcl_GetBoolean, then the recognized boolean value is written at the address given by boolPtr. If objPtr holds any value recognized as a number by Tcl, then if that value is zero a 0 is written at the address given by boolPtr, and if that value is non-zero a 1 is written at the address given by boolPtr. In all cases where a value is written at the address given by boolPtr, Tcl_GetBooleanFromObj returns TCL_OK. If the value of objPtr does not meet any of the conditions above, then TCL_ERROR is returned and an error message is left in the interpreter's result unless interp is NULL. And plot twist: Tcl_GetBooleanFromObj may also make changes to the internal fields of *objPtr so that future calls to Tcl_GetBooleanFromObj on the same objPtr can be performed more efficiently. She's optimizing herself for next time, main character energy. π
Tcl_GetBoolFromObj functions almost the same as Tcl_GetBooleanFromObj, but it has an additional parameter flags, which can be used to specify whether the empty string or NULL is accepted as valid. Basically the same girl with one extra option. π
β οΈ Note that the routinesTcl_GetBooleanFromObjandTcl_GetBooleanare not functional equivalents. The set of values for whichTcl_GetBooleanFromObjwill returnTCL_OKis strictly larger than the set of values for whichTcl_GetBooleanwill do the same. For example, the value β5β passed toTcl_GetBooleanFromObjwill lead to aTCL_OKreturn (and the boolean value1), while the same value passed toTcl_GetBooleanwill lead to aTCL_ERRORreturn. Same value, two completely different reactions. It's giving sibling rivalry. π
π«Ά REFERENCE COUNT MANAGEMENT π«Ά
Tcl_NewBooleanObjalways returns a zero-reference object, much likeTcl_NewObj.Tcl_SetBooleanObjdoes not modify the reference count of itsobjPtrargument, but does require that the object be unshared.Tcl_GetBooleanFromObjdoes not modify the reference count of itsobjPtrargument; it only reads. Note however that this function may set the interpreter result; if that is the only place that is holding a reference to the object, it will be deleted. π³
π SEE ALSO π
Tcl_NewObj, Tcl_IsShared, Tcl_GetBoolean
π KEYWORDS π
boolean, value
okay that's the whole page bestie, you're officially fluent in boolean Tcl_Obj behavior π this one shipped with Tcl 8.5 and it's filed under Tcl_BooleanObj(3tcl) β go forth and store some booleans, you've got this πβ¨
π¦ where this page comes from
- debian trixie: tcl9.0-doc 9.0.1+dfsg-2
- ubuntu questing: tcl9.0-doc 9.0.2+dfsg-1
- ubuntu resolute: tcl9.0-doc 9.0.3+dfsg-1
- ubuntu stonking: tcl9.0-doc 9.0.4+dfsg-1
- Copyright (c) 1996-1997 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms