Nebula2探秘07-使用Tcl脚本服务II

Nebula2探秘07-使用Tcl脚本服务II

happykevins文

在前一节中已经介绍了如何在程序中创建和使用TclServer,在程序中调用Tcl指令;这一节我们将学习如何通过与前一节完全相反的途径来使用Tcl。

Nebula2的程序与脚本联系的纽带是NOH,NOH是Nebula2的程序和脚本可以共同访问的数据结构,因此我们可以通过在脚本中访问NOH来实现与程序的交互。

下面用代码来说明这个交互过程:

下面是创建tcl-server的代码(与上一节相同),"/sys/servers/script"是Nebula2脚本服务在NOH中的固定路径,不能改变:

/// 创建tclserver
nTclServer * tcl = (nTclServer * )ks -> New( " ntclserver " , " /sys/servers/script " );

下面一段代码调用了"T07_UsingTclServerII.tcl"脚本程序:

/// 调用脚本文件,在脚本文件中将会通过NOH系统回调Nebula对象
nStringret;
tcl
-> RunScript( " bin:../../DataFiles/Scripts/T07_UsingTclServerII.tcl " ,ret);

"T07_UsingTclServerII.tcl"的内容如下:

# -------------------------------------------------------------------------------
#T07UsingTclServerII-在Tcl脚本中调用KernelServer对象
#@byhappykevins
#-------------------------------------------------------------------------------

puts " *****BeginScriptFile!***** "
puts
" *****Createnkernelinfo***** "

newnkernelinfohelper
/ sys / servers / ks_info

sel
/ sys / servers / ks_info
puts
" *****Invokelogclscmd***** "
. logcls
puts
" *****Invokelognohcmd***** "
. lognoh " / "

puts
" *****EndScriptFile!***** "

这段tcl脚本首先使用new语句在NOH中的"/sys/servers/ks_info"位置创建了一个nkernelinfohelper的对象,然后通过sel语句将其设置成当前工作对象,接着调用了logcls和lognoh方法。

下面给出Nebula2文档中列出的一些Tcl的简单语法:

CommonCommands (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 <)))<'<br>
-----------------------------------------------------------------------------------------------------------------------------
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及脚本服务的使用方法就介绍到这儿,你现在应该已经掌握了其基本用法,是不是觉得很容易:)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值