tcloo | Tcl OO Package | Script Programming library
kandi X-RAY | tcloo Summary
kandi X-RAY | tcloo Summary
TclOO is an object system for Tcl that has been designed to provide high performance while still allowing as much flexibility as possible, and to be a core for other object systems. It supports a single-rooted class-based object system where classes are themselves subclassable objects, with multiple inheritance, mixins, procedure-like and forwarded methods, filter methods, dynamic reconfiguration, etc. It does not come with a large class library, and it does not force its use upon user scripts. Some of the packages in Tcllib use TclOO, but these may be dependent on other Tcl 8.6 features. The heritage of TclOO can be traced back to a number of other object systems, notably including XOTcl, incr Tcl, and Snit. It also draws on experience with object systems in other languages like C++, Java and Ruby (despite being somewhat different from each of them).
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of tcloo
tcloo Key Features
tcloo Examples and Code Snippets
Community Discussions
Trending Discussions on tcloo
QUESTION
I'm wondering if anyone can explain the behind-the-scene details of why I can chain upvars successfully in nested procs, but it does not work in nested TclOO methods (those methods overridden in child classes). (I've been told that calling [next] in a TclOO class method acts a bit like a "temporary tailcall", in that a new stack level is not created. Is it this the case? If so, what is the complete picture?)
For example, the following three approaches do not all give the same result:
...ANSWER
Answered 2021-Feb-15 at 08:39The next
command internally is a bit like uplevel
(specifically uplevel 1
) in that it temporarily removes the stack frame of the method calling next
while running the superclass implementation, restoring the stack frame when next
returns (of course).
This means that you can override methods from superclasses without those superclasses needing to be especially prepared for it. That was a major problem with some other older object systems for Tcl, where you needed a special call to get the depth argument for upvar
and uplevel
, and it was ever so easy to forget that, so I changed things for TclOO. However, a direct consequence of that change means that what you're doing in S1 » addone
won't work; it creates/overwrites an additional variable, xx
, in the calling scope. S2 » addone
is what I'd consider idiomatic.
If you're passing an internal variable around between a method and the method it overrides — which by definition requires the two to cooperate — use a variable in the object's state namespace; your classes have complete control over that. Or invoke a method via my
or [self]
; that's a standard method call (with all that implies).
QUESTION
My objective was to carry out log base 2 in my tcl script but it has raised some questions about how tcl works. I need to do these things:
- Find list of available packages in my tcl environment
- Find list of procedures available in package
- Find "information" or "description" of procedure like we do using -h or --help switch in Shell
- How to add new package into our tcl environment? Are there packages to be download for tcl as they are for Python (where we use pip)?
Now I have tried to carry out some command execution myself and the trace is below:
...ANSWER
Answered 2020-Aug-05 at 14:39Tcl waits to build the package list until you ask for a package whose name it does not currently know.
catch {package require thereisnosuchpackage}
should mostly populate the list.However, there are some packages that are stored as Tcl modules and that never get entered into the list. They use a more efficient loading mechanism, but are somewhat restricted in format.
tcl::tm::path list
will give a list of directories where they can be found, and the package name and version are built from that into a file.I don't like that there isn't a way to get a list of those modules neatly, even if just for maintenance and discovery purposes.
The
expr
command rewrites the call to thelog(1.23)
function from:
QUESTION
Code:
...ANSWER
Answered 2019-Dec-01 at 10:37You can get the name of the object with self object
, or just self
. You can then get the class of the object with info object class
. And finally, you can get the member variables of a class with info class variables
.
Putting it all together results in:
QUESTION
Im attempting to update an old version of the selenium-tcl package to work with the new W3C WebDriver (or Selenium 4.0).
Original packages uses a few mixins for the webdriver class.
So I modeled what I saw and created a mixin file named mixin_action_chains.tcl [1] which has a mixin class called Mixin_Action_Chains.
Whenever I attempt to use it I get the error:
...ANSWER
Answered 2019-Nov-18 at 09:36UpdateIm not sure what else must be done for TclOO. Any thoughts.
pkgIndex.tcl: The placement of the mixin-defining script mixin_action_chains.tcl is wrong, it comes after the mixin has already been required in the previously sourced script webdriver.tcl, like entering directly:
QUESTION
I'm attempting to install gpg-agent
, but I am getting an error that the formula doesn't exist:
ANSWER
Answered 2019-Feb-20 at 20:28The gpg-agent
formula was removed by commit 965e1. The reason is given in the commit message:
QUESTION
What is idiomatic pattern for TclOO object equals
implementation?
Perhaps compare concatenated sorted lists of all properties?
Are there analogs to Scala case classes?
...ANSWER
Answered 2018-May-18 at 20:34TclOO defines no equality system for you by design; as the objects are in general modifiable, there's no automatic notion that would apply other than object identity, and you can just compare the name of the object to get that (or the results of info object namespace $theObj
, if you're being very paranoid; I think Tcl 8.7 will provide more options, but that's not yet accepted).
If you want to define an equality system such as you are proposing, you could do this:
QUESTION
Please recommend TclOO class logger mixin/trait.
Logger included with tcllib 1.19 breaks when used as class logger:
...ANSWER
Answered 2018-May-16 at 13:33This is a bug in ::logger::utils::createLogProc
in loggerUtils.tcl in that the %M
substitution is not aware of TclOO. If it was, it wouldn't be using the name of the object that the method was invoked on, but rather the name of the method. (It appears that it was designed to work with [incr Tcl], which does name methods like you appear to want.)
Ideally you'd be setting up the logger once per class, not once per instance. Here's how you'd do that:
QUESTION
How can one setup TclOO cross-object namespace transfer?
Specifically, in the example below:
runner
object needs to export its method namespace as commands- and
invoker
object needs to importrunner
namespace for use as DSL
The following example in Tcl 8.6:
...ANSWER
Answered 2018-May-15 at 12:21TclOO methods are not commands. (Technically, it's because they have a different C signature.) To make this work, you need to create an extra command in the object that acts as a delegate for the method; the trick to doing this efficiently is to use tailcall my
to do the dispatch.
QUESTION
As a short example of what I can't do:
...ANSWER
Answered 2018-Jan-21 at 15:57The TclOO API, unlike much of the rest of Tcl, only exports itself via a stubs table. You should #define
the symbol USE_TCL_STUBS
to be 1 before you #include
the Tcl header file, and link against the tclstub
library. (This is the recommended way of building extensions anyway.)
[EDIT]: If you're embedding Tcl within your program, you need a more complex procedure. Basically, you need to partition your program into the parts that are an application and the parts that are an internal extension. The parts that call Tcl_CreateInterp
are most likely the application part, and the parts that access the TclOO API are the extension (and will need to call Tcl_InitStubs
and Tcl_OOInitStubs
in an initialisation function).
The extension parts need to be compiled with USE_TCL_STUBS
defined. (As it is critical, you might put that as a #define
at the top of the file. The wiki page mentions USE_TCLOO_STUBS
as well, but that's implied by USE_TCL_STUBS
.) The extension parts need to be built without it. You can call the initialisation function that installs your internal extension immediately after the Tcl_CreateInterp
call, before you start running any (non-built-in) scripts. Then when you link everything you link both against libtclstub
and libtcl
.
The reason for this complexity is that TclOO started out as a separate extension itself, and that never supported external API references. I probably ought to relax those restrictions for Tcl 8.7…
QUESTION
Using Tcloo (self compiled TCL 8.6.7) I implemented a client socket.
I have the folowing issues:
- I how can make a method private when declare using only oo::create class
How can I register the method of the class as the event callback for the socket. I have tried the following:
chan event $sock readable [list readSocket $sock] Error: invalid command name "readSocket"...
chan event $sock readable [list [self] readSocket $sock] Error: invalid command name "self"...
Any help will be appreciated.
...ANSWER
Answered 2017-Nov-28 at 11:54Methods with names that start with a lower-case letter are public, others are private. You can also use export
and unexport
.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install tcloo
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page