12.07.2015 Views

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

script after making their own changes. Finally, after adding the scripts to ~<strong>ns</strong>/tcl/lib/<strong>ns</strong>-lib.tcl, <strong>and</strong> every time thereafter th<strong>at</strong>they change their script, the user must recompile <strong>ns</strong> for their changes to take effect. Of course, in most cases 4 , the user ca<strong>ns</strong>ource their script to override the embedded code.<strong>The</strong> rest of this subsection illustr<strong>at</strong>e how to integr<strong>at</strong>e individual scripts directly into <strong>ns</strong>. <strong>The</strong> first step is convert the script intoan EmbeddedTcl object. <strong>The</strong> lines below exp<strong>and</strong> <strong>ns</strong>-lib.tcl <strong>and</strong> cre<strong>at</strong>e the EmbeddedTcl object i<strong>ns</strong>tance called et_<strong>ns</strong>_lib:tclsh bin/tcl-exp<strong>and</strong>.tcl tcl/lib/<strong>ns</strong>-lib.tcl | \../Tcl/tcl2c++ et_<strong>ns</strong>_lib > gen/<strong>ns</strong>_tcl.cc<strong>The</strong> script, ~<strong>ns</strong>/bin/tcl-exp<strong>and</strong>.tcl exp<strong>and</strong>s <strong>ns</strong>-lib.tcl by replacing all source lines with the corresponding source files.<strong>The</strong> program, ~tclcl/tcl2cc.c, converts the OTcl code into an equivalent EmbeddedTcl object, et_<strong>ns</strong>_lib.During initializ<strong>at</strong>ion, invoking the method EmbeddedTcl::load explicitly evalu<strong>at</strong>es the array.— ~tclcl/tcl-object.tcl is evalu<strong>at</strong>ed by the method Tcl::init(void); Tcl_AppInit() invokes Tcl::Init(). <strong>The</strong>exact comm<strong>and</strong> syntax for the load is:et_tclobject.load();— Similarly, ~<strong>ns</strong>/tcl/lib/<strong>ns</strong>-lib.tcl is evalu<strong>at</strong>ed directly by Tcl_AppInit in ~<strong>ns</strong>/<strong>ns</strong>_tclsh.cc.et_<strong>ns</strong>_lib.load();3.8 Class I<strong>ns</strong>tVarThis section describes the internals of the class I<strong>ns</strong>tVar. This class defines the methods <strong>and</strong> mechanisms to bind a C++member variable in the compiled shadow object to a specified OTcl i<strong>ns</strong>tance variable in the equivalent interpreted object. <strong>The</strong>binding is set up such th<strong>at</strong> the value of the variable can be set or accessed either from within the interpreter, or from withinthe compiled code <strong>at</strong> all times.<strong>The</strong>re are five i<strong>ns</strong>tance variable classes: class I<strong>ns</strong>tVarReal, class I<strong>ns</strong>tVarTime, class I<strong>ns</strong>tVarB<strong>and</strong>width,class I<strong>ns</strong>tVarInt, <strong>and</strong> class I<strong>ns</strong>tVarBool, corresponding to bindings for real, time, b<strong>and</strong>width, integer, <strong>and</strong>boolean valued variables respectively.We now describe the mechanism by which i<strong>ns</strong>tance variables are set up. We use the class I<strong>ns</strong>tVarReal to illustr<strong>at</strong>e theconcept. However, this mechanism is applicable to all five types of i<strong>ns</strong>tance variables.When setting up an interpreted variable to access a member variable, the member functio<strong>ns</strong> of the class I<strong>ns</strong>tVar assume th<strong>at</strong>they are executing in the appropri<strong>at</strong>e method execution context; therefore, they do not query the interpreter to determine thecontext in which this variable must exist.In order to guarantee the correct method execution context, a variable must only be bound if its class is already establishedwithin the interpreter, <strong>and</strong> the interpreter is currently oper<strong>at</strong>ing on an object in th<strong>at</strong> class. Note th<strong>at</strong> the former requires th<strong>at</strong>when a method in a given class is going to make its variables accessible via the interpreter, there must be an associ<strong>at</strong>ed4 <strong>The</strong> few places where this might not work are when certain variables might have to be defined or undefined, or otherwise the script contai<strong>ns</strong> code otherthan procedure <strong>and</strong> variable definitio<strong>ns</strong> <strong>and</strong> executes actio<strong>ns</strong> directly th<strong>at</strong> might not be reversible.35

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!