[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help: how to implement a new protocol?



Hi Xiaogang,

>   1.What should be writen in TCL and what in c++ ?

The general consensus is that TCL is easier to write and maintain, but C++ is 
considerable faster and more economic as far as memory is concerned. So my 
advice is to write the core functions in C++ and the stuff you'd like to 
experiment with in OTCL.

>   2.What are the mean of "$self", "instproc" and "instvar"?

OK, $self is pretty much like "this" in c++. Use $self within object methods 
to refer to the current object. Unlike in c++, in OTCL you always have to use  
$self to call another object method (on the current object), i.e. "$self xyz 
5" would be "this->xyz(5)" in c++ (or just "xyz(5)").

Use "instproc" to define object methods, that's pretty much like "::" in c++. For example, in C++ you write "void XTP::send(char data)" and in otcl you'd write "XTP instproc send {data}".

Finally, instvar is used for variable declaration within an object method (I can't think of any correspondence in c++). Write "$self instvar x" within an object method to declare a variable x.

   -Chris.