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

王朝other·作者佚名  2007-05-16
窄屏简体版  字體: |||超大  

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对象

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 nkernelinfohelper*****"

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

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航