stooop(n)
πΈ NAME πΈ
okay bestie, welcome to stooop(n) β it's an object oriented extension, and yes we're doing this π
β¨ SYNOPSIS β¨
package require Tcl 8.5 9
package require stooop ?4.4.2?
::stooop::class name body
::stooop::new class ?arg arg ...?
::stooop::delete object ?object ...?
::stooop::virtual proc name {this ?arg arg ...?} ?body?
::stooop::classof object
::stooop::new object
::stooop::printObjects ?pattern?
::stooop::record
::stooop::report ?pattern?
π¦ DESCRIPTION π¦
so this package gives Tcl a whole glow-up into object oriented territory, using a syntax and behaviour that's giving very familiar C++ energy β¨. stooop only drops a few new commands on you: class, new, delete, virtual and classof. plus a handful of coding conventions, and honestly that's literally all you need to know to use it. the whole point of stooop is to be as simple to use as humanly possible π«Ά
heads up though: this manual is very succinct β it's meant as a quick reminder for the programmer who should already have read the thorough stooop_man.html HTML documentation by now π
::stooop::class name bodyβ this command creates a class π. thebody, whose contents are similar to a Tcl namespace (which a class actually also is, no cap), contains member procedure definitions. member procedures can also be defined outside the class body, by prefixing their name withclass::, exactly like you'd do with namespace procedures.proc class {this ?arg arg ...?} ?base {?arg arg ...?} ...? bodyβ this is the constructor procedure for the class π. it gets invoked after anewinvocation on the class. it must have the same name as the class, and its first argument must be namedthis. you can throw in any number of base class specifications β including arguments to pass to their constructor β before the actual body of the procedure.proc ~class {this} bodyβ the destructor procedure for the class π. it's invoked after adeleteinvocation. its name has to be a single~character concatenated with the class name (just like in C++), and it must have a single argument namedthis.proc name {this ?arg arg ...?} bodyβ a member procedure of the class, since its first argument is namedthis. it lets you access member data real easy for the object referenced bythisinside the procedure. for example:
set ($this,data) 0
proc name {?arg arg ...?} bodyβ a static (as in C++) member procedure of the class, because its first argument is not namedthis. static (global) class data can be accessed like this:
set (data) 0
proc class {this copy} bodyβ the optional copy procedure for the class π. it must have the same name as the class and exactly 2 arguments namedthisandcopy. it's invoked after anewinvocation on an existing object of the class.
::stooop::new class ?arg arg ...?β used to create an object π±. first argument is the class name, followed by the arguments the corresponding class constructor needs. it returns a unique identifier for the object that was just created.::stooop::delete object ?object ...?β used to delete one or several objects ποΈ. takes one or more object identifiers as argument(s).::stooop::virtual proc name {this ?arg arg ...?} ?body?β thevirtualspecifier can be used on member procedures to achieve dynamic binding β¨. a procedure in a base class can then be redefined (overloaded) in the derived class(es). if the base class procedure is invoked on an object, it's actually the derived class procedure that gets invoked, if it exists. and if the base class procedure has no body, it's considered to be a pure virtual, and the derived class procedure is always invoked π::stooop::classof objectβ returns the class of the existing object passed as a single parameter π::stooop::new objectβ used to create an object by copying an existing object π. the copy constructor of the corresponding class gets invoked if it exists, otherwise a simple copy of the copied object's data members is performed.
π₯ DEBUGGING π₯
π Environment variables π
STOOOPCHECKDATAβ set this to any true value and stooop will check for invalid member or class data access πSTOOOPCHECKPROCEDURESβ set this to any true value and stooop will check for invalid member procedure arguments and pure interface classes instanciation.STOOOPCHECKALLβ set this to any true value and stooop activates both procedure and data member checking π―STOOOPCHECKOBJECTSβ set this to any true value and stooop activates object checking. the following stooop namespace procedures then become available for debugging:printObjects,recordandreport.STOOOPTRACEPROCEDURESβ set this environment variable to eitherstdout,stderror a file name, and it activates procedure tracing π‘. the stooop library will then output to the specified channel 1 line of informational text for each member procedure invocation.STOOOPTRACEPROCEDURESFORMATβ defines the trace procedures output format. defaults to"class: %C, procedure: %p, object: %O, arguments: %a".STOOOPTRACEDATAβ set this environment variable to eitherstdout,stderror a file name, and it activates data tracing π‘. the stooop library will then output to the specified channel 1 line of informational text for each member data access.STOOOPTRACEDATAFORMATβ defines the trace data output format. defaults to"class: %C, procedure: %p, array: %A, object: %O, member: %m, operation: %o, value: %v".STOOOPTRACEDATAOPERATIONSβ when tracing data output, by default all read, write and unsetting accesses are reported, but you can set this variable to any combination of the lettersr,w, andufor more specific tracing (please refer to thetraceTcl manual page for more information) πSTOOOPTRACEALLβ set this environment variable to eitherstdout,stderror a file name, and it enables both procedure and data tracing π::stooop::printObjects ?pattern?β prints an ordered list of existing objects, in creation order, oldest first π. each output line contains the class name, object identifier and the procedure within which the creation occurred. the optional pattern argument (as in the Tclstring matchcommand) can be used to limit the output to matching class names.::stooop::recordβ when invoked, a snapshot of all existing stooop objects is taken πΈ. reporting can then be used at a later time to see which objects were created or deleted in the interval.::stooop::report ?pattern?β prints the created and deleted objects since the::stooop::recordprocedure was invoked last. if present, the pattern argument limits the output to matching class names.
π EXAMPLES π
please see the full HTML documentation in stooop_man.html π
π BUGS, IDEAS, FEEDBACK π
this document, and the package it describes, will undoubtedly contain bugs and other problems β it's giving humble, honestly π. please report such in the category stooop of the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist](http://core.tcl.tk/tcllib/reportlist). please also report any ideas for enhancements you may have for either the package and/or the documentation π«Ά
when proposing code changes, please provide unified diffs, i.e the output of diff -u π
note further that attachments are strongly preferred over inlined patches. attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar β¨
π KEYWORDS π
C++, class, object, object oriented
π CATEGORY π
Programming tools
and that's the whole page bestie, no cap π
okay so the sign-off tea: this is from tcllib, version 4.4.2, and it's the stooop(n) page, dated 4.4.2. go be the main character of your own object graph π¦β¨
π¦ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms