Tcl_Obj* objPtr[2]; objPtr[0] = Tcl_NewStringObj( "info", -1 ); objPtr[1] = Tcl_NewStringObj( "commands", -1 ); // I know this function is internal to Tcl, but it seems no other C // functions to get all command names out of Tcl. Tcl_InfoObjCmd( 0, d_interp, 2, objPtr ); return getResult().split( " ", QString::SkipEmptyParts );
2009-06-18
Get a list of all Tcl commands by Tcl_InfoObjCmd
I am combining Tcl library and GNU readline to provide a Tcl line editing environment. One of the problems I have is the command completion of GNU readline library. In order to do command completion, you have to provide a list of currently available Tcl commands to readline. I know it is already there in Tcl language, i.e, info commands. But, it also dumps the list to the console, :(. Imaging that when you press TAB key, the program prints out all commands first and then the commands matched your request. This is not acceptable. This also means calling Tcl_Eval("info commands") to get result back to process is not an option to me.
With hours of searching over Tcl source code, I can't find a public C functionhat does the job. But,
fortunately, an internal function Tcl_InfoObjCmd seems to be the cure (Well, its signature may be changed in the future, I know!!) Just use following code to get result,
Labels:
Programming,
Tcl