tags:

views:

112

answers:

2

Hello all,
I'm using NS2 to create some new classes in C++ and then link them to otcl. The linkage and everything works, but when I try to use the otcl variables in an object, I'm having a trouble.

For example, suppose I have a class "Node" with the variable X. In the code I want to set this value and later on use it in some if-statements.

Setting the variable is no problem using this code:

$node1 set x 4

Now the problem I'm having is when I try to use this variable x anywhere. In C++ we could use a general variable (i.e., y) and say "y=node.x" and then use y in some if-statements. I have tried to look for a method to perform the same thing in otcl, but failed.

Any help is appriciated.

Thanks in Advance.

A: 

I think you're looking for OTclSetInstVar and OTclGetInstVar to write and read instance variables respectively. They're defined in otcl.h, which is a plain C header file, and their use should be pretty obvious if you're used to general Tcl APIs.

If you've got a version of NS2 built on top of the newer XOTcl (which I gather exists from the projects that the XOTcl main author is involved with through Google Summer of Code over the past couple of years) then the APIs are XOTclOSetInstVar and OTclGetInstVar in (or rather included off of) xotcl.h. The type signatures are not the same though; they're only logically drop-in replacements, and not actual drop-ins. (OTcl uses pure string-based APIs, XOTcl uses much more efficient – but complex – Tcl_Obj-based APIs.)

Donal Fellows
A: 

Thanks Donal for the answer. But I found what I really needed (and it worked), which is something like this:

set x [$class set y]
Hussain