make a package for tcl << Tcl/Tk

本文详细介绍了如何使用TCL/Tk在FreeBSD上创建一个简单的包,包括目录结构、源代码文件和pkgIndex.tcl的创建步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

It is very funny. Making a package for tcl is so easy! I am using tcl/tk 8.5 on FreeBSD 9.0. To make a hello world package, it only needs to create two files. One file is the source code, another is pkgIndex.tcl. You can write some functions in the source code file. The pkgIndex.tcl can be created by a tcl command: pkg_mkIndex . *.tcl

Follow these steps to make a package:


1. Make a directory named 3d-egg-1.0. 3d-egg is the package name that will be required by applications, 1.0 is the package version.

$ mkdir 3d-egg-1.0
$ cd 3d-egg-1.0

2. Write your code into 3d-egg.tcl in current directory. My 3d-egg.tcl is:

package provide 3d-egg 1.0
namespace eval 3d-egg {
	namespace export *
}
proc 3d-egg::hello {} {
	puts "hello 3d-egg!"
}
proc 3d-egg::bye {} {
	puts "bye 3d-egg!"
}

3. Run tclsh in current directory, and make the pkgIndex.tcl with a command:

$ tclsh8.5
% pkg_mkIndex . *.tcl


It's done! The package is ready. You maybe want to release the package, then just compress the 3d-egg-1.0 directory and pushlish it on the Internet to give others. I suggest you release your code with BSD style license to share knowledge.

Installing the package is very easy, just copy the directory 3d-egg-1.0 to the path where tcl invoked. On FreeBSD copy 3d-egg-1.0 to /usr/local/lib.

$ cd ..
$ sudo cp -r 3d-egg-1.0 /usr/local/lib/

Use 3d-egg package:

$ tclsh8.5
% package require 3d-egg
1.0
% 3d-egg::hello
hello 3d-egg!
% 3d-egg::bye
bye 3d-egg!

Published at 10:40:41 Mar. 18, 2012 UTC

Updated at 10:44:11 Mar. 18, 2012 UTC

http://glx.me/docs/3d-egg/tcl-tk/index.php?page=tcl-make-a-package


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值