Nebula2探秘07-使用Tcl脚本服务II
来源:互联网 发布:内涵段子软件 编辑:程序博客网 时间:2024/06/05 15:34
Nebula2探秘07-使用Tcl脚本服务II
happykevins文
在前一节中已经介绍了如何在程序中创建和使用TclServer,在程序中调用Tcl指令;这一节我们将学习如何通过与前一节完全相反的途径来使用Tcl。
Nebula2的程序与脚本联系的纽带是NOH,NOH是Nebula2的程序和脚本可以共同访问的数据结构,因此我们可以通过在脚本中访问NOH来实现与程序的交互。
下面用代码来说明这个交互过程:
下面是创建tcl-server的代码(与上一节相同),"/sys/servers/script"是Nebula2脚本服务在NOH中的固定路径,不能改变:
nTclServer* tcl = (nTclServer*)ks->New("ntclserver", "/sys/servers/script");
下面一段代码调用了"T07_UsingTclServerII.tcl"脚本程序:
nString ret;
tcl->RunScript("bin:../../DataFiles/Scripts/T07_UsingTclServerII.tcl", ret);
"T07_UsingTclServerII.tcl"的内容如下:
# T07 UsingTclServer II - 在Tcl脚本中调用KernelServer对象
# @by happykevins
#-------------------------------------------------------------------------------
puts "*****Begin Script File!*****"
puts "*****Create nkernelinfo*****"
new nkernelinfohelper /sys/servers/ks_info
sel /sys/servers/ks_info
puts "*****Invoke logcls cmd*****"
.logcls
puts "*****Invoke lognoh cmd*****"
.lognoh "/"
puts "*****End Script File!*****"
这段tcl脚本首先使用new语句在NOH中的"/sys/servers/ks_info"位置创建了一个nkernelinfohelper 的对象,然后通过sel语句将其设置成当前工作对象,接着调用了logcls和lognoh方法。
下面给出Nebula2文档中列出的一些Tcl的简单语法:
Common Commands (Nebula2Docs@nTclServer)
-----------------------------------------------------------------------------------------------------------------------------
new classname path
Create a new object of the specified class at the specified path in the NOH. Returns true on success and nil on failure.
example:
new 'ntransformnode' 'tm'
new 'nd3d9server' '/sys/servers/gfx'
-----------------------------------------------------------------------------------------------------------------------------
delete path
Delete the NOH object at the specified location in the NOH. Returns true on success and nil on failure.
example:
delete '/usr/scene/myobject'
-----------------------------------------------------------------------------------------------------------------------------
sel path
Set the current working directory of the NOH to the specified path. Returns true on success and nil on failure.
example:
sel '/sys/servers/gfx'
-----------------------------------------------------------------------------------------------------------------------------
psel
Returns the full path of the currently selected object.
-----------------------------------------------------------------------------------------------------------------------------
exit
Exit Nebula. Exit does not return a value.
-----------------------------------------------------------------------------------------------------------------------------
puts string
Echo the provided string to the Kernel server's log handler chain.(only on Micro TCL)
example:
puts 'fish <)))<'
-----------------------------------------------------------------------------------------------------------------------------
dir
Return a table containing the names of the children of the current working directory in the NOH.
-----------------------------------------------------------------------------------------------------------------------------
exists path
RCheck whether object exists. Return "1" if yes, return "0" if no.
-----------------------------------------------------------------------------------------------------------------------------
emit object.signal arg1 arg2 arg3
Implement signal emission (emit command).
-----------------------------------------------------------------------------------------------------------------------------
post time object.signal arg1 arg2 arg3
Post signal and commands (post command).
Nebula2还另外提供了luaserver,pythonserver等脚本服务器,创建过程和使用方法与tclserver差不多;关于Nebula2的Tcl及脚本服务的使用方法就介绍到这儿,你现在应该已经掌握了其基本用法,是不是觉得很容易:)
- Nebula2探秘07-使用Tcl脚本服务II
- Nebula2探秘07-使用Tcl脚本服务II
- Nebula2探秘07-使用Tcl脚本服务II
- Nebula2探秘06-使用Tcl脚本服务I
- Nebula2探秘06-使用Tcl脚本服务I
- Nebula2探秘06-使用Tcl脚本服务I
- Nebula2探秘02-使用FileServer2
- Nebula2探秘02-使用FileServer2
- Nebula2探秘02-使用FileServer2
- Nebula2探秘02-使用FileServer2
- Nebula2探秘01-创建KernelServer&使用log
- Nebula2探秘01-创建KernelServer&使用log
- Nebula2探秘01-创建KernelServer&使用log
- Nebula2探秘01-创建KernelServer&使用log
- Nebula2探秘05-RTTI
- Nebula2探秘05-RTTI
- Nebula2探秘05-RTTI
- Nebula2探秘14-nGuiServer的创建与使用
- 网管日志_Feb012005
- EasyJWeb-0.8.0版本发布
- Windows 2003系统优化技巧
- 僕と若手プログラムとの会話(10)
- 玩积木的程序员
- Nebula2探秘07-使用Tcl脚本服务II
- 《给初学者的Windows Vista的补遗手册》之060
- SaaS专题(六)--ERP世界中的SaaS
- 安全信息收集
- Linux NFS服务器性能优化
- Nebula2探秘06-使用Tcl脚本服务I
- realone 启动报错之解决方法
- 适合才是正确的 之 “关于业务逻辑加入存储过程”
- 《给初学者的Windows Vista的补遗手册》之059