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

Re: instantiating Application defined in C++ from tcl



> I have now finally come to the point where I want to integrate the
> application I have been writing(in C++) into ns. But I am having trouble
> instantiating the main class of the application from tcl. The application
> has been written in C++ only, I have created the xxxxClass helping class
> and I have created an entry for it in ns/tcl/lib/ns-source.tcl
> But I am still not able to create an instance of the application, the
> error I get when I try to create an instance is  "  invalid command name
> "..."   ". So it seems that I have not created all the links between the
> C++ and tcl code that is necessary, can anybody be of any help?

You don't need to modify ns/tcl/lib/ns-source.tcl to be able to
instantiate a c++ object from tcl. 

All you need is something like the following

static class MyAppClass : public TclClass {
public:
  SFQClass() : TclClass("Application/MyApp") {}
  TclObject* create(int, const char*const*) {
    return (new MyApp);
  }
} class_myapp;

and, assuminng the MyApp c++ class exists, you can create a new
Application/MyApp Tcl object using

set obj [new Application/MyApp]

Hth,
Sean.
-----
Sean Murphy,			Email: [email protected]
Teltec Ireland,			Phone: +353-1-7045080
DCU, Dublin 9,			Fax:   +353-1-7045092
Ireland.