Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

keywords!!!

Status
Not open for further replies.

sergelaurent

Technical User
May 30, 2005
52
FR
I have some new commands!!!! I want to add them to tcl list of commands so that they can be recognised as such when using them on an interpreter!!!! (ex:tclsh). How can I do that?
 
I don't understand your question exactly. What form are your commands in? Do you have a library (like a DLL)?

_________________
Bob Rashkin
 
In fact, i have special commands which will be used on my application. For exemple, i have: toto <parameters>, where "toto" is the command's name. I want the tclsh interpreter to recognise "toto" as a command.
How can I do this?
 
So these commands are written in Tcl? Are they proc's? If so, the simplest way is to source the file that has the proc's in the script from which you reference them:
Code:
source <[red]script file[/red]>

Alternatively, although it's really the same thing, you can build an index:
Code:
auto_mkindex <[red]library directory[/red]> <[red]script file[/red]>

and then append the location of that index to where Tcl looks for commands:
Code:
lappend auto_path <[red]library directory[/red]>

_________________
Bob Rashkin
 
Thanks for your advice Bong. However my procs are written in c++. Can I apply the same method or is there something special that I should do first?
 
I'm not familiar with the C++ interface for Tcl although there have been several threads on the topic.

You can look here: although it's technically C and not C++. Also, there are more links here:
Alternatively, you can compile your functions as a DLL or SO (depending on platform) and load them in your script.
load - Load machine code and initialize new commands.

SYNOPSIS
load fileName
load fileName packageName
load fileName packageName interp


DESCRIPTION
This command loads binary code from a file into the application's address space and calls an initialization procedure in the package to incorporate it into an interpreter. fileName is the name of the file containing the code; its exact form varies from system to system but on most systems it is a shared library, such as a .so file under Solaris or a DLL under Windows. packageName is the name of the package, and is used to compute the name of an initialization procedure. interp is the path name of the interpreter into which to load the package (see the interp manual entry for details); if interp is omitted, it defaults to the interpreter in which the load command was invoked.

Once the file has been loaded into the application's address space, one of two initialization procedures will be invoked in the new code. Typically the initialization procedure will add new commands to a Tcl interpreter. The name of the initialization procedure is determined by packageName and whether or not the target interpreter is a safe one. For normal interpreters the name of the initialization procedure will have the form pkg_Init, where pkg is the same as packageName except that the first letter is converted to upper case and all other letters are converted to lower case. For example, if packageName is foo or FOo, the initialization procedure's name will be Foo_Init.

_________________
Bob Rashkin
 
Thanks a lot of the hints Bong!!!

I'll try this and i'll inform you of the result!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top