user1134991
user1134991

Reputation: 3103

Tcl find if a variable exists in object instance

In a namespace, it is very easy, for the sake of lazy evaluation, find if a namespace variable exists, from within the namespace:

info exists [ namespace current]::<var name>

How can I achieve the same for an instance of class, using Tcl OO?
I use TCL 8.6
Thanks.

Upvotes: 0

Views: 1058

Answers (1)

Peter Lewerin
Peter Lewerin

Reputation: 13252

You can use

info exists [self namespace]::<var name>

or

expr {<var name> in [info class variables <class name>]}

if {<var name> in [info class variables <class name>]} {
    ...
}

Documentation: expr, if, in (operator), info, self (class configuration prefix), self

Upvotes: 1

Related Questions