stooop(n)

πŸ“¦
version 2.0 Β· 2 versions
, in fedora 43, fedora 44, nixos 26.05, nixpkgs unstable

🌸 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 πŸ‘‘. the body, 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 with class::, 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 a new invocation on the class. it must have the same name as the class, and its first argument must be named this. 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 a delete invocation. its name has to be a single ~ character concatenated with the class name (just like in C++), and it must have a single argument named this.
    • proc name {this ?arg arg ...?} body β€” a member procedure of the class, since its first argument is named this. it lets you access member data real easy for the object referenced by this inside 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 named this. 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 named this and copy. it's invoked after a new invocation 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? β€” the virtual specifier 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, record and report.
  • STOOOPTRACEPROCEDURES β€” set this environment variable to either stdout, stderr or 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 either stdout, stderr or 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 letters r, w, and u for more specific tracing (please refer to the trace Tcl manual page for more information) πŸ”Ž
  • STOOOPTRACEALL β€” set this environment variable to either stdout, stderr or 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 Tcl string match command) 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::record procedure 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