嵌入式Tcl:Tcl是否自动完成命令? [英] Embedded Tcl: Does Tcl autocomplete commands?

查看:100
本文介绍了嵌入式Tcl:Tcl是否自动完成命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在C / C ++应用程序中内置了一个 Tcl ,我在代码中找到了一个地方,如果未找到该命令,则会调用 Tcl_EvalObjv 。我必须承认代码很旧,而且我们的开发人员中很少有人知道此模块中会发生什么。

We have a Tcl built in our C/C++ application, I found the place in our code where Tcl_EvalObjv is called if the command was not found. I have to admit that the code is pretty old and not many of our developers know what happens in this module.

它看起来像这样:

// ... there is some checking if command is registered etc., it fails and the code goes here:
std::vector<Tcl_Obj*> tclArgs = { NULL };
for (int i = 1; i < objc; ++i)
    tclArgs.push_back(objv[i]);
tclArgs.shrink_to_fit();
// ...
tclArgs[0] = ::Tcl_NewStringObj(ORIGINAL_UNKNOWN, ORIGINAL_UNKNOWN_SIZE);
Tcl_IncrRefCount(tclArgs[0]);
::Tcl_ExposeCommand(pInterp, ORIGINAL_UNKNOWN, ORIGINAL_UNKNOWN);
result = ::Tcl_EvalObjv(pInterp, objc, &tclArgs[0], TCL_EVAL_GLOBAL); //<--
::Tcl_HideCommand(pInterp, ORIGINAL_UNKNOWN, ORIGINAL_UNKNOWN);
// ORIGINAL_UNKNOWN is char* it is just "unknown"

我们有命令处理程序在我们的应用程序中,在 CmdUnknown()函数中执行 Tcl_EvalObjv 时,有时 Tcl 会调用不同的命令。下面的示例:

We have handlers for commands in our application, while executing Tcl_EvalObjv in CmdUnknown() function Tcl sometimes calls different commands. Examples below:

现有命令列表:香蕉, applepie,地毯,卡

List of existing commands: "banana", "applepie", "carpet", "card"

命令: apple,Tcl调用 applepie(错误, apple不是 applepie)

命令: blah,Tcl给出错误(

命令: car,Tcl给出了错误(正确,可能是由于2条类似的命令)。


是否有某种类型的机制 Tcl 在搜索命令失败时会执行吗?问题是我找不到与可以完成命令的代码相关的任何东西,所以 Tcl 可以吗?

Command: "apple", Tcl calls "applepie" (wrong, "apple" is not "applepie")
Command: "blah", Tcl gives error (correctly).
Command: "car", Tcl gives error (correctly, maybe because of 2 similar commands).

Is there are some kind of mechanism that Tcl does when it fails in searching for command? The thing is that I can't find anything that is related to our code that would complete the commands so maybe Tcl does?

推荐答案

正如glenn所暗示的那样,Tcl在交互式(REPL)模式下允许使用一些最小但明确的名称前缀来调度命令。我无法告诉您嵌入式Tcl是如何配置,初始化以及最终以交互方式运行的。但是,您可能想尝试通过以下两种方法之一关闭(切换)交互模式:

As glenn hinted at, Tcl in interactive (REPL) mode allows for dispatching commands using some minimal but unambiguous name prefix. I cannot tell how your embedded Tcl is configured, initialised, and ended up being run as in interactive mode. However, you may want to try to "turn off" (toggle) the interactive mode, by either:

unset ::tcl_interactive

set ::tcl_interactive 0

所有这些均通过默认<$ c $实现c>未知处理程序。请注意如何查找 cmds 的列表以及在 tcl_interactive 为真或为假时如何区别对待:

All of this is implemented by the default unknown handler. Watch out for how the list of cmds is looked up and how it is treated differently when tcl_interactive is true or false:

puts [info body unknown]

这篇关于嵌入式Tcl:Tcl是否自动完成命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆