1
votes

When I running my (proprietary) code, I get this:

info object isa class DlgClass is:1
DlgClass does not refer to an object
    while executing
"::oo::Obj6::my Set DlgClass"
    ("uplevel" body line 1)
    invoked from within
"uplevel 1 [list [namespace which my] Set $args]"
    (class "::oo::Slot" method "-set" line 2)
    invoked from within
"::oo::Obj6::my --default-operation DlgClass"
    ("uplevel" body line 1)
    invoked from within
"uplevel 1 [list [namespace which my] $def {*}$args]"
    (class "::oo::Slot" method "unknown" line 6)
    invoked from within
"superclass DlgClass"
    (in definition script

The two lines of code ( 1 which generate the message, and the one before it ) are:

puts "info object isa class DlgClass is:[info object isa class DlgClass]"
superclass DlgClass

I don't understand. Doesn't the first line output (the info object isa class DlgClass is:1one) indicate that the superclass is indeed defined?

2

2 Answers

1
votes

TclOO definitions care very strongly what the current stack frame is because the oo::define command uses a private variable in the internal call frame structure to store the identity of the class being defined. For some reason (that I find a bit surprising) the source command is interfering with this.

The simplest workaround that might possibly work is to write your own. Fortunately, you can just put it in the right namespace and have it work in the place where you really need it:

# Very simple version of the standard [source] command
proc ::oo::define::source {filename} {
    set f [open $filename]
    set script [read $f]
    close $f

    tailcall eval $script
}

On the other hand, your script works for me when I try it even without my special version of source. Something else is going on.

0
votes

Apparently it happens when I do lazy evaluation of the superclass' definition from within the class block. i.e. rather than writing:

oo::class create foo {
   source "DlgClass.tcl" ;# if needed
   superclass DlgClass
}

One needs to do:

source "DlgClass.tcl" ;# if needed
oo::class create foo {
   superclass DlgClass
}

And then it works. I think that it may be a bug in oo::class/tcl engine, but, as it is so easy to workaround, not a major one.